Bug 465435 - m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed.
Summary: m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' fa...
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.20.0
Platform: Debian stable Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
: 196335 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-02-07 17:58 UTC by Corentin Noël
Modified: 2023-02-24 20:46 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch to replace assert with more helpful message and exit. (1.18 KB, patch)
2023-02-10 20:24 UTC, Paul Floyd
Details
156134: Patch to replace assert with more helpful message and exit. (1.65 KB, patch)
2023-02-11 07:12 UTC, Paul Floyd
Details
better message if safe_fd fails (1.95 KB, patch)
2023-02-16 20:59 UTC, Paul Floyd
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Corentin Noël 2023-02-07 17:58:43 UTC
When running crosvm under valgrind, I'm hitting the following assertion:

m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed.


STEPS TO REPRODUCE
1. I'm using the mesa CI container in Docker as privileged, and I'm running crosvm in valgrind with crosvm --no-syslog run --gpu vulkan=true,gles=false,backend=virglrenderer,egl=true,surfaceless=true,width=1024,height=768 --gpu-render-server path=/usr/local/libexec/virgl_render_server -m 4096 -c 2 --disable-sandbox --shared-dir /:my_root:type=fs:writeback=true:timeout=60:cache=always --host-ip=192.168.30.1 --netmask=255.255.255.0 --mac AA:BB:CC:00:00:12 -p quiet console=null root=my_root rw rootfstype=virtiofs ip=192.168.30.2::192.168.30.1:255.255.255.0:crosvm:eth0 init=/mesa/crosvm-init.sh

OBSERVED RESULT
Valgrind stops with ab assert

EXPECTED RESULT
Crosvm to continue to run

SOFTWARE/OS VERSIONS

Linux 78aae9de313f 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64 GNU/Linux

ADDITIONAL INFORMATION

==283== 
--283-- Valgrind options:
--283--    -v
--283-- Contents of /proc/version:
--283--   Linux version 5.15.0-58-generic (buildd@lcy02-amd64-033) (gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, GNU ld (GNU Binutils for Ubuntu) 2.34) #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023
--283-- 
--283-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-ssse3-avx-avx2-bmi-f16c-rdrand-rdseed
--283-- Page sizes: currently 4096, max supported 4096
--283-- Valgrind library directory: /usr/libexec/valgrind
--283-- Reading syms from /usr/local/bin/crosvm
--283-- Reading syms from /lib/x86_64-linux-gnu/ld-2.31.so
--283--   Considering /usr/lib/debug/.build-id/e2/5570740d590e5cb7b1a20d86332a8d1bb3b65f.debug ..
--283--   .. build-id is valid
--283-- Reading syms from /usr/libexec/valgrind/memcheck-amd64-linux
--283--   Considering /usr/lib/debug/.build-id/31/b12880cc55b577063de0457f6dbfffd17ebed4.debug ..
--283--   .. build-id is valid
--283--    object doesn't have a dynamic symbol table
--283-- Scheduler: using generic scheduler lock implementation.
--283-- Reading suppressions file: /usr/libexec/valgrind/default.supp
==283== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-283-by-???-on-78aae9de313f
==283== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-283-by-???-on-78aae9de313f
==283== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-283-by-???-on-78aae9de313f
==283== 
==283== TO CONTROL THIS PROCESS USING vgdb (which you probably
==283== don't want to do, unless you know exactly what you're doing,
==283== or are doing some strange experiment):
==283==   /usr/bin/vgdb --pid=283 ...command...
==283== 
==283== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==283==   /path/to/gdb crosvm
==283== and then give GDB the following command
==283==   target remote | /usr/bin/vgdb --pid=283
==283== --pid is optional if only one valgrind process is running
==283== 
--283-- REDIR: 0x401fa70 (ld-linux-x86-64.so.2:strlen) redirected to 0x580bc6a2 (vgPlain_amd64_linux_REDIR_FOR_strlen)
--283-- REDIR: 0x401f850 (ld-linux-x86-64.so.2:index) redirected to 0x580bc6bc (vgPlain_amd64_linux_REDIR_FOR_index)
--283-- Reading syms from /usr/libexec/valgrind/vgpreload_core-amd64-linux.so
--283--   Considering /usr/lib/debug/.build-id/c0/82d431d9afeb5607de0aad7fc1ae7269254c4c.debug ..
--283--   .. build-id is valid
--283-- Reading syms from /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so
--283--   Considering /usr/lib/debug/.build-id/30/32ca2a6a9aa36d4c02d7c8e09830f31028f0b7.debug ..
--283--   .. build-id is valid
==283== WARNING: new redirection conflicts with existing -- ignoring it
--283--     old: 0x0401fa70 (strlen              ) R-> (0000.0) 0x580bc6a2 vgPlain_amd64_linux_REDIR_FOR_strlen
--283--     new: 0x0401fa70 (strlen              ) R-> (2007.0) 0x0483f8c0 strlen
--283-- REDIR: 0x401c290 (ld-linux-x86-64.so.2:strcmp) redirected to 0x4840870 (strcmp)
--283-- REDIR: 0x401ffb0 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4844400 (mempcpy)
--283-- Reading syms from /lib/x86_64-linux-gnu/libcap.so.2.44
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libX11.so.6.4.0
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libXext.so.6.4.0
--283--   Considering /usr/lib/x86_64-linux-gnu/libXext.so.6.4.0 ..
--283--   .. CRC mismatch (computed fee28fcb wanted ccf52917)
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/local/lib/libwayland-client.so.0.3.0
--283-- Reading syms from /usr/local/lib/libvirglrenderer.so.1.7.7
--283-- Reading syms from /lib/x86_64-linux-gnu/libc-2.31.so
--283--   Considering /usr/lib/debug/.build-id/b5/03275bf9fee51581fdceef97533b194035b4f7.debug ..
--283--   .. build-id is valid
==283== WARNING: new redirection conflicts with existing -- ignoring it
--283--     old: 0x04c1bda0 (memalign            ) R-> (1011.0) 0x0483eb80 memalign
--283--     new: 0x04c1bda0 (memalign            ) R-> (1017.0) 0x0483eb50 aligned_alloc
==283== WARNING: new redirection conflicts with existing -- ignoring it
--283--     old: 0x04c1bda0 (memalign            ) R-> (1011.0) 0x0483eb80 memalign
--283--     new: 0x04c1bda0 (memalign            ) R-> (1017.0) 0x0483eb20 aligned_alloc
==283== WARNING: new redirection conflicts with existing -- ignoring it
--283--     old: 0x04c1bda0 (memalign            ) R-> (1011.0) 0x0483eb80 memalign
--283--     new: 0x04c1bda0 (memalign            ) R-> (1017.0) 0x0483eb50 aligned_alloc
==283== WARNING: new redirection conflicts with existing -- ignoring it
--283--     old: 0x04c1bda0 (memalign            ) R-> (1011.0) 0x0483eb80 memalign
--283--     new: 0x04c1bda0 (memalign            ) R-> (1017.0) 0x0483eb20 aligned_alloc
--283-- Reading syms from /lib/x86_64-linux-gnu/libgcc_s.so.1
--283--    object doesn't have a symbol table
--283-- Reading syms from /lib/x86_64-linux-gnu/libpthread-2.31.so
--283--   Considering /usr/lib/debug/.build-id/25/5e355c207aba91a59ae1f808e3b4da443abf0c.debug ..
--283--   .. build-id is valid
--283-- Reading syms from /lib/x86_64-linux-gnu/libm-2.31.so
--283--   Considering /usr/lib/debug/.build-id/1d/6ff6c4c69f3572486bc27b8290ee932b0b9f39.debug ..
--283--   .. build-id is valid
--283-- Reading syms from /lib/x86_64-linux-gnu/libdl-2.31.so
--283--   Considering /usr/lib/debug/.build-id/46/b3bf3f9b9eb092a5c0cf5575e89092f768054c.debug ..
--283--   .. build-id is valid
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libxcb.so.1.1.0
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libffi.so.7.1.0
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libepoxy.so.0.0.0
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/local/lib/libdrm.so.2.4.0
--283-- Reading syms from /builds/tintou/mesa/install/lib/libgbm.so.1.0.0
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libvulkan.so.1.2.162
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libXau.so.6.0.0
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libXdmcp.so.6.0.0
--283--    object doesn't have a symbol table
--283-- Reading syms from /lib/x86_64-linux-gnu/libexpat.so.1.6.12
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libbsd.so.0.11.3
--283--    object doesn't have a symbol table
--283-- Reading syms from /usr/lib/x86_64-linux-gnu/libmd.so.0.0.4
--283--    object doesn't have a symbol table
--283-- REDIR: 0x4c20120 (libc.so.6:memmove) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
==283== Preferring higher priority redirection:
--283--     old: 0x04cf5290 (__memcpy_avx_unalign) R-> (2018.0) 0x04841b40 __memcpy_avx_unaligned_erms
--283--     new: 0x04cf5290 (__memcpy_avx_unalign) R-> (2018.1) 0x04843460 memmove
--283-- REDIR: 0x4c1f420 (libc.so.6:strncpy) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c205f0 (libc.so.6:strcasecmp) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1eb70 (libc.so.6:strcat) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1f4b0 (libc.so.6:rindex) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c219f0 (libc.so.6:rawmemchr) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c39d40 (libc.so.6:wmemchr) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c39810 (libc.so.6:wcscmp) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20360 (libc.so.6:mempcpy) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20090 (libc.so.6:bcmp) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1f370 (libc.so.6:strncmp) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1ec90 (libc.so.6:strcmp) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20250 (libc.so.6:memset) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c397a0 (libc.so.6:wcschr) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1f270 (libc.so.6:strnlen) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1ede0 (libc.so.6:strcspn) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20640 (libc.so.6:strncasecmp) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1ed50 (libc.so.6:strcpy) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20790 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c3afb0 (libc.so.6:wcsnlen) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c39880 (libc.so.6:wcscpy) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1f520 (libc.so.6:strpbrk) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1ec00 (libc.so.6:index) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1f200 (libc.so.6:strlen) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c25db0 (libc.so.6:memrchr) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20690 (libc.so.6:strcasecmp_l) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20020 (libc.so.6:memchr) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c39920 (libc.so.6:wcslen) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1f7c0 (libc.so.6:strspn) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c20560 (libc.so.6:stpncpy) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c204d0 (libc.so.6:stpcpy) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c21a60 (libc.so.6:strchrnul) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c206e0 (libc.so.6:strncasecmp_l) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4c1ff50 (libc.so.6:strstr) redirected to 0x482e1b0 (_vgnU_ifunc_wrapper)
--283-- REDIR: 0x4cf2130 (libc.so.6:__strrchr_avx2) redirected to 0x483f300 (rindex)
--283-- REDIR: 0x4cf2300 (libc.so.6:__strlen_avx2) redirected to 0x483f7a0 (strlen)
--283-- REDIR: 0x4cedc60 (libc.so.6:__strncmp_avx2) redirected to 0x483fe70 (strncmp)
--283-- REDIR: 0x4c1b0f0 (libc.so.6:malloc) redirected to 0x4839740 (malloc)
--283-- REDIR: 0x4c1fc60 (libc.so.6:__GI_strstr) redirected to 0x48446a0 (__strstr_sse2)
--283-- REDIR: 0x4cee180 (libc.so.6:__memchr_avx2) redirected to 0x48408f0 (memchr)
--283-- REDIR: 0x4cf5290 (libc.so.6:__memcpy_avx_unaligned_erms) redirected to 0x4843460 (memmove)
--283-- REDIR: 0x4cee430 (libc.so.6:__rawmemchr_avx2) redirected to 0x4843f20 (rawmemchr)
--283-- REDIR: 0x4c1b980 (libc.so.6:realloc) redirected to 0x483e750 (realloc)
--283-- REDIR: 0x4c1b720 (libc.so.6:free) redirected to 0x483c090 (free)
--283-- REDIR: 0x4cf5720 (libc.so.6:__memset_avx2_unaligned_erms) redirected to 0x4843360 (memset)
--283-- REDIR: 0x4c1be50 (libc.so.6:calloc) redirected to 0x483e4d0 (calloc)
syslog init failed: guess of fd for syslog connection was invalid
--283-- REDIR: 0x4cee910 (libc.so.6:__memcmp_avx2_movbe) redirected to 0x4842c00 (bcmp)
--283-- REDIR: 0x4ced820 (libc.so.6:__strcmp_avx2) redirected to 0x4840770 (strcmp)
[2023-02-07T17:55:27.924295456+00:00 INFO  crosvm] crosvm started.
[2023-02-07T17:55:28.115588802+00:00 INFO  crosvm] CLI arguments parsed.
--283-- WARNING: Serious error when reading debug info
--283-- When reading debug info from /memfd:crosvm_guest (deleted):
--283-- failed to stat64/stat this file
==283== Warning: set address range perms: large range [0x59c94000, 0x129c94000) (defined)
--283-- WARNING: Serious error when reading debug info
--283-- When reading debug info from /memfd:crosvm_guest (deleted):
--283-- failed to stat64/stat this file
==283== Warning: set address range perms: large range [0x5740000, 0x35740000) (defined)
--283-- REDIR: 0x4cf1f40 (libc.so.6:__strchrnul_avx2) redirected to 0x4843ef0 (strchrnul)
--283-- REDIR: 0x4cf5270 (libc.so.6:__mempcpy_avx_unaligned_erms) redirected to 0x4844000 (mempcpy)
==284== Warning: invalid file descriptor 1012 in syscall close()
==284==    at 0x4C80FC3: close (close.c:27)
==284==    by 0x72030B: close_open_fds (libminijail.c:2666)
==284==    by 0x72030B: minijail_run_internal (libminijail.c:3412)
==284==    by 0x72030B: minijail_run_config_internal (libminijail.c:3546)
==284==    by 0x72111E: minijail_run_env_pid_pipes (libminijail.c:3028)
==284==    by 0x71AF4F: <&std::path::Path as minijail::Runnable>::run_command (in /usr/local/bin/crosvm)
==284==    by 0x719F6A: minijail::Minijail::run_internal (in /usr/local/bin/crosvm)
==284==    by 0x719CC9: minijail::Minijail::run_command (in /usr/local/bin/crosvm)
==284==    by 0x534F4AF: ???
==284==    by 0x25: ???
==284==    by 0x25: ???
==284==    by 0x534F51F: ???
==284==    by 0x2: ???
==284==    by 0x2: ???
==284== Warning: invalid file descriptor 1013 in syscall close()
==284==    at 0x4C80FC3: close (close.c:27)
==284==    by 0x72030B: close_open_fds (libminijail.c:2666)
==284==    by 0x72030B: minijail_run_internal (libminijail.c:3412)
==284==    by 0x72030B: minijail_run_config_internal (libminijail.c:3546)
==284==    by 0x72111E: minijail_run_env_pid_pipes (libminijail.c:3028)
==284==    by 0x71AF4F: <&std::path::Path as minijail::Runnable>::run_command (in /usr/local/bin/crosvm)
==284==    by 0x719F6A: minijail::Minijail::run_internal (in /usr/local/bin/crosvm)
==284==    by 0x719CC9: minijail::Minijail::run_command (in /usr/local/bin/crosvm)
==284==    by 0x534F4AF: ???
==284==    by 0x25: ???
==284==    by 0x25: ???
==284==    by 0x534F51F: ???
==284==    by 0x2: ???
==284==    by 0x2: ???
==284== Warning: invalid file descriptor 1014 in syscall close()
==284==    at 0x4C80FC3: close (close.c:27)
==284==    by 0x72030B: close_open_fds (libminijail.c:2666)
==284==    by 0x72030B: minijail_run_internal (libminijail.c:3412)
==284==    by 0x72030B: minijail_run_config_internal (libminijail.c:3546)
==284==    by 0x72111E: minijail_run_env_pid_pipes (libminijail.c:3028)
==284==    by 0x71AF4F: <&std::path::Path as minijail::Runnable>::run_command (in /usr/local/bin/crosvm)
==284==    by 0x719F6A: minijail::Minijail::run_internal (in /usr/local/bin/crosvm)
==284==    by 0x719CC9: minijail::Minijail::run_command (in /usr/local/bin/crosvm)
==284==    by 0x534F4AF: ???
==284==    by 0x25: ???
==284==    by 0x25: ???
==284==    by 0x534F51F: ???
==284==    by 0x2: ???
==284==    by 0x2: ???
==284== Warning: invalid file descriptor 1015 in syscall close()
==284==    Use --log-fd=<number> to select an alternative log fd.
==284==    at 0x4C80FC3: close (close.c:27)
==284==    by 0x72030B: close_open_fds (libminijail.c:2666)
==284==    by 0x72030B: minijail_run_internal (libminijail.c:3412)
==284==    by 0x72030B: minijail_run_config_internal (libminijail.c:3546)
==284==    by 0x72111E: minijail_run_env_pid_pipes (libminijail.c:3028)
==284==    by 0x71AF4F: <&std::path::Path as minijail::Runnable>::run_command (in /usr/local/bin/crosvm)
==284==    by 0x719F6A: minijail::Minijail::run_internal (in /usr/local/bin/crosvm)
==284==    by 0x719CC9: minijail::Minijail::run_command (in /usr/local/bin/crosvm)
==284==    by 0x534F4AF: ???
==284==    by 0x25: ???
==284==    by 0x25: ???
==284==    by 0x534F51F: ???
==284==    by 0x2: ???
==284==    by 0x2: ???
==284== Warning: invalid file descriptor 1016 in syscall close()
==284==    at 0x4C80FC3: close (close.c:27)
==284==    by 0x72030B: close_open_fds (libminijail.c:2666)
==284==    by 0x72030B: minijail_run_internal (libminijail.c:3412)
==284==    by 0x72030B: minijail_run_config_internal (libminijail.c:3546)
==284==    by 0x72111E: minijail_run_env_pid_pipes (libminijail.c:3028)
==284==    by 0x71AF4F: <&std::path::Path as minijail::Runnable>::run_command (in /usr/local/bin/crosvm)
==284==    by 0x719F6A: minijail::Minijail::run_internal (in /usr/local/bin/crosvm)
==284==    by 0x719CC9: minijail::Minijail::run_command (in /usr/local/bin/crosvm)
==284==    by 0x534F4AF: ???
==284==    by 0x25: ???
==284==    by 0x25: ???
==284==    by 0x534F51F: ???
==284==    by 0x2: ???
==284==    by 0x2: ???
==284== Warning: invalid file descriptor 1017 in syscall close()
==284==    at 0x4C80FC3: close (close.c:27)
==284==    by 0x72030B: close_open_fds (libminijail.c:2666)
==284==    by 0x72030B: minijail_run_internal (libminijail.c:3412)
==284==    by 0x72030B: minijail_run_config_internal (libminijail.c:3546)
==284==    by 0x72111E: minijail_run_env_pid_pipes (libminijail.c:3028)
==284==    by 0x71AF4F: <&std::path::Path as minijail::Runnable>::run_command (in /usr/local/bin/crosvm)
==284==    by 0x719F6A: minijail::Minijail::run_internal (in /usr/local/bin/crosvm)
==284==    by 0x719CC9: minijail::Minijail::run_command (in /usr/local/bin/crosvm)
==284==    by 0x534F4AF: ???
==284==    by 0x25: ???
==284==    by 0x25: ???
==284==    by 0x534F51F: ???
==284==    by 0x2: ???
==284==    by 0x2: ???
--283-- REDIR: 0x4c1cb10 (libc.so.6:posix_memalign) redirected to 0x483ea60 (posix_memalign)

valgrind: m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed.
Comment 1 Paul Floyd 2023-02-08 09:25:08 UTC
A similar question was recently asked on SO:
https://stackoverflow.com/questions/75292406/memchk-valgrind-reporting-inconsistent-results-in-different-docker-hosts

Could you check that you have a sensible value for the limit of file descriptors? For instance on RHEL 7.6 I have a limit of 65535. For now I'm assuming it is the same problem.

We're not going to change Valgrind to handle insane rlimits that Docker presents. I suggest that either you log a bug with Docker or else try using (r)limit to set the descriptor limit to something more sensible.
Comment 2 Paul Floyd 2023-02-09 10:09:22 UTC
Marking as NEEDSINFO
Comment 3 Corentin Noël 2023-02-09 10:38:12 UTC
Thank you for your answer that was really useful, it was indeed an issue with both Docker and Crosvm:

Docker set a limit to 1048576 so I've added "--ulimit nofile=1024:4096" to the docker arguments to have decent default configuration.

I've also had to modify Crosvm (more precisely minijail that it is using) by preventing it to change the nofile limit in https://github.com/google/minijail/blob/c30d299f93f94a4ee4b786d15e1fb194f8709b9f/libminijail.c#L2183

I hope it will be useful to anyone having the same issue.
Comment 4 Paul Floyd 2023-02-09 10:50:16 UTC
Well one thing that I could do is to change the assert into a message + exit.

Something like

Valgrind does not support very high file descriptor limits (e.g., as seen when running in Docker).
Please consider lowering this limit with the shell built-in command limit command.

with a bit more information on the fd requested and the hard limit that it is using.
Comment 5 Paul Floyd 2023-02-10 08:59:50 UTC
Also, if I upload a patch here will you be able to test it (clone the Valgrind source repo and build Valgrind)?
Comment 6 Corentin Noël 2023-02-10 09:04:37 UTC
(In reply to Paul Floyd from comment #5)
> Also, if I upload a patch here will you be able to test it (clone the
> Valgrind source repo and build Valgrind)?

Sure I can do that
Comment 7 Paul Floyd 2023-02-10 20:24:47 UTC
Created attachment 156134 [details]
Patch to replace assert with more helpful message and exit.

Please could you try this and let me know if it is more helpful?
Comment 8 Paul Floyd 2023-02-11 07:12:17 UTC
Created attachment 156143 [details]
156134: Patch to replace assert with more helpful message and exit.

Condition was wrong and I'd left in a True to check the message.
Comment 9 Corentin Noël 2023-02-15 11:30:32 UTC
Comment on attachment 156143 [details]
156134: Patch to replace assert with more helpful message and exit.

Just tested the patch and I'm indeed getting a:

--88:0:libcfile Valgrind: FATAL: Duplicated file descriptor -1
   is not in the range of reserved values starting at 1048564.
   Valgrind does not support very high file descriptor limits
   (e.g., as seen when running in Docker).
   Please consider lowering this limit with the shell built-in
   limit command.
--88:0:libcfile Exiting now.

In this case it seems that I'm getting an error on file descriptor duplication so having a errno/errmsg would also help understanding it a bit.
Comment 10 Paul Floyd 2023-02-15 15:54:55 UTC
(In reply to Corentin Noël from comment #9)

> In this case it seems that I'm getting an error on file descriptor
> duplication so having a errno/errmsg would also help understanding it a bit.

We can't provide anything from errno as we don't have it. Valgrind does not link with libc and makes system calls like

   SysRes res = VG_(do_syscall3)(__NR_fcntl, fd, cmd, arg);

directly itself.

I really think that the problem is with Docker. It's advertising some ridiculously high value for ulimit -n like 1048576. Valgrind wants to put its own files in the top 12 of those slots, and is trying to to a fcntl(oldfd, F_DUPFD, 1048576-12) - note that 1048576-12 matches the 1048564 that you get from the patch message. Then Docker fails to honour its promised file descriptor limit and the fcntl fails.

man fcntl says there are 3 possible causes: negative oldfd (no) max nb file descriptors already open (no) and oldfd greater than the rlimit (I think that this is the case).

Here is an example.

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <errno.h>

int main(void)
{
   struct rlimit rlim;
   getrlimit(RLIMIT_NOFILE, &rlim);
   
   printf("nofile soft limit %ld hard limit %ld\n", (long)rlim.rlim_cur, (long)rlim.rlim_max);
   
   for (long i = 4; i <= rlim.rlim_cur; ++i)
   {
      int newFd = fcntl(1, F_DUPFD, i);
      if (newFd != -1)
      {
         close(newFd);
      }
      else
      {
         fprintf(stderr, "default soft limit failed to DUPFD %ld\n", i);
         perror("");
         break;
      }
   }
   rlim.rlim_cur = rlim.rlim_max;
   setrlimit(RLIMIT_NOFILE, &rlim);
   
   for (long i = 4; i <= rlim.rlim_cur; ++i)
   {
      int newFd = fcntl(1, F_DUPFD, i);
      if (newFd != -1)
      {
         close(newFd);
      }
      else
      {
         fprintf(stderr, "maximum soft limit failed to DUPFD %ld\n", i);
         perror("");
         break;
      }
   }
}

Compiling and running this on RHEL 7.6 I get

nofile soft limit 65535 hard limit 65535
default soft limit failed to DUPFD 65535
Invalid argument
maximum soft limit failed to DUPFD 65535
Invalid argument

Could you try it and report back whether you also see the first failing dup being equal to the limits?
Comment 11 Mark Wielaard 2023-02-15 18:11:03 UTC
(In reply to Paul Floyd from comment #10)
> (In reply to Corentin Noël from comment #9)
> 
> > In this case it seems that I'm getting an error on file descriptor
> > duplication so having a errno/errmsg would also help understanding it a bit.
> 
> We can't provide anything from errno as we don't have it. Valgrind does not
> link with libc and makes system calls like
> 
>    SysRes res = VG_(do_syscall3)(__NR_fcntl, fd, cmd, arg);
> 
> directly itself.

We cannot use errno (which is indeed a glibc concept), but we can extract the kernel error from the SysRes with something like:

   if (sr_isError (res))
      VG_(umsg) ("fcntl error %lu %s\n", sr_Err(res), VG_(strerror) (sr_Err(res)));
Comment 12 Paul Floyd 2023-02-16 20:59:53 UTC
Created attachment 156323 [details]
better message if safe_fd fails

Change message as it looks like failure rather than fd not in safe range.
Also add a debug log for fcntl.
Comment 13 Paul Floyd 2023-02-22 07:47:29 UTC
*** Bug 196335 has been marked as a duplicate of this bug. ***
Comment 14 Paul Floyd 2023-02-24 20:46:56 UTC
commit e61a04babcc3de8c1c86638f8ccdb4ef1b74a4d0 (HEAD -> master, origin/master, origin/HEAD)
Author: Paul Floyd <pjfloyd@wanadoo.fr>
Date:   Fri Feb 24 21:31:35 2023 +0100

    bug465435 - m_libcfile.c:66 (vgPlain_safe_fd): Assertion 'newfd >= VG_(fd_hard_limit)' failed.