From: Mark W. <ma...@so...> - 2025-08-01 14:11:12
|
https://sourceware.org/cgit/valgrind/commit/?id=34dff50cf304d1d4f0d5a1ad3f55f8b3d85ae701 commit 34dff50cf304d1d4f0d5a1ad3f55f8b3d85ae701 Author: Martin Cermak <mc...@re...> Date: Fri Aug 1 14:04:24 2025 +0200 Wrap linux specific syscall sysfs The sysfs syscall is deprecated, but in some cases it may still be used. The Linux Test Project covers it. The (obsolete) sysfs() system call returns information about the filesystem types currently present in the kernel. The specific form of the sysfs() call and the information returned depends on the option in effect: 1 Translate the filesystem identifier string fsname into a filesystem type index. 2 Translate the filesystem type index fs_index into a null- terminated filesystem identifier string. This string will be written to the buffer pointed to by buf. Make sure that buf has enough space to accept the string. 3 Return the total number of filesystem types currently present in the kernel. Declare a sys_sysfs wrapper in priv_syswrap-linux.h and hook it for {amd64,arm,mips32,mips64,ppc32,ppc64,s390x,x86}-linux using LINXY with PRE and POST handler in syswrap-linux.c https://bugs.kde.org/show_bug.cgi?id=506929 Diff: --- NEWS | 1 + coregrind/m_syswrap/priv_syswrap-linux.h | 1 + coregrind/m_syswrap/syswrap-amd64-linux.c | 2 +- coregrind/m_syswrap/syswrap-arm-linux.c | 2 +- coregrind/m_syswrap/syswrap-linux.c | 36 ++++++++++++++++++++++++++++++ coregrind/m_syswrap/syswrap-mips32-linux.c | 2 +- coregrind/m_syswrap/syswrap-mips64-linux.c | 10 +-------- coregrind/m_syswrap/syswrap-ppc32-linux.c | 2 +- coregrind/m_syswrap/syswrap-ppc64-linux.c | 2 +- coregrind/m_syswrap/syswrap-s390x-linux.c | 2 +- coregrind/m_syswrap/syswrap-x86-linux.c | 2 +- 11 files changed, 46 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index fe9de908f7..32bea93531 100644 --- a/NEWS +++ b/NEWS @@ -60,6 +60,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 506795 Better report which clone flags are problematic 506910 openat2 with RESOLVE_NO_MAGICLINKS succeeds on /proc/self/exe 506928 Wrap (deprecated) linux specific ustat syscall +506929 Wrap (deprecated) linux sysfs syscall 506930 valgrind allows SIGKILL being reset to SIG_DFL 506967 Implement and override mallinfo2 506970 mmap needs an EBADF fd_allowed check diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h index ce10a35f6a..1d5135fc56 100644 --- a/coregrind/m_syswrap/priv_syswrap-linux.h +++ b/coregrind/m_syswrap/priv_syswrap-linux.h @@ -61,6 +61,7 @@ DECL_TEMPLATE(linux, sys_vmsplice); DECL_TEMPLATE(linux, sys_readahead); DECL_TEMPLATE(linux, sys_move_pages); DECL_TEMPLATE(linux, sys_cachestat); +DECL_TEMPLATE(linux, sys_sysfs); // clone is similar enough between linux variants to have a generic // version, but which will call an extern defined in syswrap-<platform>-linux.c diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c index c80286f00b..f15c3dac72 100644 --- a/coregrind/m_syswrap/syswrap-amd64-linux.c +++ b/coregrind/m_syswrap/syswrap-amd64-linux.c @@ -636,7 +636,7 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_ustat, sys_ustat), // 136 GENXY(__NR_statfs, sys_statfs), // 137 GENXY(__NR_fstatfs, sys_fstatfs), // 138 - // (__NR_sysfs, sys_sysfs), // 139 + LINXY(__NR_sysfs, sys_sysfs), // 139 GENX_(__NR_getpriority, sys_getpriority), // 140 GENX_(__NR_setpriority, sys_setpriority), // 141 diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c index c5fb08dcc6..4ba9801cea 100644 --- a/coregrind/m_syswrap/syswrap-arm-linux.c +++ b/coregrind/m_syswrap/syswrap-arm-linux.c @@ -711,7 +711,7 @@ static SyscallTableEntry syscall_main_table[] = { GENX_(__NR_fchdir, sys_fchdir), // 133 //zz // (__NR_bdflush, sys_bdflush), // 134 */Linux //zz -//zz // (__NR_sysfs, sys_sysfs), // 135 SVr4 + LINXY(__NR_sysfs, sys_sysfs), // 135 SVr4 LINX_(__NR_personality, sys_personality), // 136 // GENX_(__NR_afs_syscall, sys_ni_syscall), // 137 LINX_(__NR_setfsuid, sys_setfsuid16), // 138 diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 572a42925d..66e5ca62e7 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -4407,6 +4407,42 @@ PRE(sys_syncfs) PRE_REG_READ1(long, "syncfs", unsigned int, fd); } +PRE(sys_sysfs) +{ + FUSE_COMPATIBLE_MAY_BLOCK(); + switch (ARG1) { + case 1: + PRINT("sys_sysfs ( %lu, %lu )", ARG1, ARG2); + PRE_REG_READ2(long, "sysfs", int, flags, const void *, path); + PRE_MEM_RASCIIZ("sysfs(path)", ARG2); + break; + case 2: + PRINT("sys_sysfs ( %lu, %lu, %#" FMT_REGWORD "x )", + ARG1, ARG2, ARG3); + PRE_REG_READ3(long, "sysfs", int, flags, int, desc, void *, path); + PRE_MEM_WRITE("sysfs(path)", ARG3, 1); + break; + case 3: + PRINT("sys_sysfs ( %lu )", ARG1); + PRE_REG_READ1(long, "sysfs", int, flags); + break; + default: + if (VG_(clo_verbosity) >= 1) { + VG_(message)(Vg_DebugMsg, + "WARNING: unhandled sysfs option %lu\n", ARG1); + } + break; + } +} + +POST(sys_sysfs) +{ + if (ARG1 == 2) { + // For option 2, getting the fsname, there is no way to know how big the buffer needs to be. + POST_MEM_WRITE(ARG3, VG_(strlen)((void *)ARG3)); + } +} + PRE(sys_statx) { FUSE_COMPATIBLE_MAY_BLOCK(); diff --git a/coregrind/m_syswrap/syswrap-mips32-linux.c b/coregrind/m_syswrap/syswrap-mips32-linux.c index 684bda4b9a..13cb5d05bc 100644 --- a/coregrind/m_syswrap/syswrap-mips32-linux.c +++ b/coregrind/m_syswrap/syswrap-mips32-linux.c @@ -899,7 +899,7 @@ static SyscallTableEntry syscall_main_table[] = { GENX_ (__NR_getpgid, sys_getpgid), // 132 GENX_ (__NR_fchdir, sys_fchdir), // 133 //.. // (__NR_bdflush, sys_bdflush), // 134 - //.. // (__NR_sysfs, sys_sysfs), // 135 + LINXY (__NR_sysfs, sys_sysfs), // 135 LINX_ (__NR_personality, sys_personality), // 136 //.. GENX_(__NR_afs_syscall, sys_ni_syscall), // 137 LINX_ (__NR_setfsuid, sys_setfsuid), // 138 diff --git a/coregrind/m_syswrap/syswrap-mips64-linux.c b/coregrind/m_syswrap/syswrap-mips64-linux.c index 8e2dcbe93c..bdfb203837 100644 --- a/coregrind/m_syswrap/syswrap-mips64-linux.c +++ b/coregrind/m_syswrap/syswrap-mips64-linux.c @@ -216,7 +216,6 @@ SysRes sys_set_tls ( ThreadId tid, Addr tlsptr ) DECL_TEMPLATE (mips_linux, sys_set_thread_area); DECL_TEMPLATE (mips_linux, sys_vmsplice); -DECL_TEMPLATE (mips_linux, sys_sysfs); DECL_TEMPLATE (mips_linux, sys_swapon); DECL_TEMPLATE (mips_linux, sys_swapoff); DECL_TEMPLATE (mips_linux, sys_setdomainname); @@ -259,13 +258,6 @@ PRE(sys_swapoff) PRE_REG_READ1(long, "swapoff", const void *, path); } -PRE(sys_sysfs) -{ - PRINT("sys_sysfs ( %ld, %#" FMT_REGWORD "x, %#" FMT_REGWORD "x )", - SARG1, ARG2, ARG3); - PRE_REG_READ3(long, "sysfs", int, flags, int, desc, const void *, path); -} - /* Very much MIPS specific */ PRE(sys_cacheflush) { @@ -645,7 +637,7 @@ static SyscallTableEntry syscall_main_table[] = { LINXY (__NR_ustat, sys_ustat), GENXY (__NR_statfs, sys_statfs), GENXY (__NR_fstatfs, sys_fstatfs), - PLAX_ (__NR_sysfs, sys_sysfs), + LINXY (__NR_sysfs, sys_sysfs), GENX_ (__NR_getpriority, sys_getpriority), GENX_ (__NR_setpriority, sys_setpriority), LINXY (__NR_sched_setparam, sys_sched_setparam), diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c index d2b59786c4..00d0f56d7b 100644 --- a/coregrind/m_syswrap/syswrap-ppc32-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c @@ -774,7 +774,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_fchdir, sys_fchdir), // 133 //.. // (__NR_bdflush, sys_bdflush), // 134 */Linux //.. -//.. // (__NR_sysfs, sys_sysfs), // 135 SVr4 + LINXY(__NR_sysfs, sys_sysfs), // 135 SVr4 LINX_(__NR_personality, sys_personality), // 136 //.. GENX_(__NR_afs_syscall, sys_ni_syscall), // 137 LINX_(__NR_setfsuid, sys_setfsuid), // 138 diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c index 3d6c2e4eda..87a4c4db90 100644 --- a/coregrind/m_syswrap/syswrap-ppc64-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c @@ -762,7 +762,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_fchdir, sys_fchdir), // 133 // _____(__NR_bdflush, sys_bdflush), // 134 -// _____(__NR_sysfs, sys_sysfs), // 135 + LINXY(__NR_sysfs, sys_sysfs), // 135 LINX_(__NR_personality, sys_personality), // 136 // _____(__NR_afs_syscall, sys_afs_syscall), // 137 LINX_(__NR_setfsuid, sys_setfsuid), // 138 diff --git a/coregrind/m_syswrap/syswrap-s390x-linux.c b/coregrind/m_syswrap/syswrap-s390x-linux.c index 65a26a02da..ad35a4ebcf 100644 --- a/coregrind/m_syswrap/syswrap-s390x-linux.c +++ b/coregrind/m_syswrap/syswrap-s390x-linux.c @@ -573,7 +573,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_fchdir, sys_fchdir), // 133 // ?????(__NR_bdflush, ), // 134 -// ?????(__NR_sysfs, ), // 135 + LINXY(__NR_sysfs, sys_sysfs), // 135 LINX_(__NR_personality, sys_personality), // 136 GENX_(137, sys_ni_syscall), /* unimplemented (by the kernel) */ // 137 GENX_(138, sys_ni_syscall), /* unimplemented (by the kernel) */ // 138 diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index 0b8373ffa8..9b8c9d861b 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -1320,7 +1320,7 @@ static SyscallTableEntry syscall_table[] = { GENX_(__NR_fchdir, sys_fchdir), // 133 //zz // (__NR_bdflush, sys_bdflush), // 134 */Linux //zz -//zz // (__NR_sysfs, sys_sysfs), // 135 SVr4 + LINXY(__NR_sysfs, sys_sysfs), // 135 SVr4 LINX_(__NR_personality, sys_personality), // 136 GENX_(__NR_afs_syscall, sys_ni_syscall), // 137 LINX_(__NR_setfsuid, sys_setfsuid16), // 138 |