From: Martin Cermak Date: Tue, 19 Jan 2038 03:36:01 +0000 (+0100) Subject: Provide missing syswraps for file_getattr and file_setattr X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1f124823d4b7de8edc1bde7b5107a07cb6843952;p=thirdparty%2Fvalgrind.git Provide missing syswraps for file_getattr and file_setattr The syscalls take fd and path. If path is absolute, fd is not used. If path is empty, fd can be AT_FDCWD or any valid fd which will be used to get/set attributes on. https://bugs.kde.org/show_bug.cgi?id=510169 --- diff --git a/NEWS b/NEWS index b1b27e815..d00ab0715 100644 --- a/NEWS +++ b/NEWS @@ -165,6 +165,7 @@ are not entered into bugzilla tend to get forgotten about or ignored. 509642 Add missing ppc64-linux syswraps 509643 Add missing s390x-linux syswraps 510169 Update the LTP version in valgrind testsuite to 20250930 +510416 Missing syswraps for file_getattr and file_setattr To see details of a given bug, visit https://bugs.kde.org/show_bug.cgi?id=XXXXXX diff --git a/coregrind/m_syswrap/priv_syswrap-linux.h b/coregrind/m_syswrap/priv_syswrap-linux.h index ca462e896..71a7518f4 100644 --- a/coregrind/m_syswrap/priv_syswrap-linux.h +++ b/coregrind/m_syswrap/priv_syswrap-linux.h @@ -373,6 +373,10 @@ DECL_TEMPLATE(linux, sys_statmount); // Since Linux 6.10 DECL_TEMPLATE(linux, sys_mseal); +// Since Linux 6.17-rc1 +DECL_TEMPLATE(linux, sys_file_getattr); +DECL_TEMPLATE(linux, sys_file_setattr); + /* --------------------------------------------------------------------- Wrappers for sockets and ipc-ery. These are split into standalone procedures because x86-linux hides them inside multiplexors diff --git a/coregrind/m_syswrap/syswrap-amd64-linux.c b/coregrind/m_syswrap/syswrap-amd64-linux.c index 838bf5e84..93fb083e6 100644 --- a/coregrind/m_syswrap/syswrap-amd64-linux.c +++ b/coregrind/m_syswrap/syswrap-amd64-linux.c @@ -910,6 +910,8 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_statmount, sys_statmount), // 457 LINXY(__NR_listmount, sys_listmount), // 458 LINX_(__NR_mseal, sys_mseal), // 462 + LINXY(__NR_file_getattr, sys_file_getattr), // 468 + LINX_(__NR_file_setattr, sys_file_setattr), // 469 }; SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno ) diff --git a/coregrind/m_syswrap/syswrap-arm-linux.c b/coregrind/m_syswrap/syswrap-arm-linux.c index 1fda7ba8a..7a450e94e 100644 --- a/coregrind/m_syswrap/syswrap-arm-linux.c +++ b/coregrind/m_syswrap/syswrap-arm-linux.c @@ -1082,6 +1082,8 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_statmount, sys_statmount), // 457 LINXY(__NR_listmount, sys_listmount), // 458 LINX_(__NR_mseal, sys_mseal), // 462 + LINXY(__NR_file_getattr, sys_file_getattr), // 468 + LINX_(__NR_file_setattr, sys_file_setattr), // 469 }; diff --git a/coregrind/m_syswrap/syswrap-arm64-linux.c b/coregrind/m_syswrap/syswrap-arm64-linux.c index 175002e6b..7b4fce6bd 100644 --- a/coregrind/m_syswrap/syswrap-arm64-linux.c +++ b/coregrind/m_syswrap/syswrap-arm64-linux.c @@ -861,6 +861,8 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_statmount, sys_statmount), // 457 LINXY(__NR_listmount, sys_listmount), // 458 LINX_(__NR_mseal, sys_mseal), // 462 + LINXY(__NR_file_getattr, sys_file_getattr), // 468 + LINX_(__NR_file_setattr, sys_file_setattr), // 469 }; diff --git a/coregrind/m_syswrap/syswrap-linux.c b/coregrind/m_syswrap/syswrap-linux.c index 1402c3d1f..4e7356656 100644 --- a/coregrind/m_syswrap/syswrap-linux.c +++ b/coregrind/m_syswrap/syswrap-linux.c @@ -4482,6 +4482,76 @@ POST(sys_listmount) } } +PRE(sys_file_getattr) +{ + // SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, + // struct file_attr __user *, ufattr, size_t, usize, + // unsigned int, at_flags) + // in: dfd, filename, at_flags + // out: ufattr, usize + *flags |= SfMayBlock; + Int arg_1 = (Int) ARG1; + PRINT("sys_file_getattr ( %ld, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )" , + SARG1, ARG2, (HChar*)(Addr)ARG2, ARG3, ARG4, ARG5); + PRE_REG_READ5(int, "file_getattr", int, dfd, const char*, filename, + struct vki_file_attr *, ufattr, vki_size_t, usize, int, at_flags); + // Per https://lwn.net/Articles/1020992/ : + // >> The syscalls take fd and path. If path is absolute, fd is not used. If path + // is empty, fd can be AT_FDCWD or any valid fd which will be used to get/set + // attributes on. << That said, we can't use ML_(fd_at_check_allowed)() here, + // because there is nothing special about relative path. + if (ARG1 == 0) + { + if (arg_1 != VKI_AT_FDCWD && !ML_(fd_allowed)(arg_1, "file_getattr", tid, False)) + { + SET_STATUS_Failure( VKI_EBADF ); + } + } + else + { + PRE_MEM_RASCIIZ("file_getattr(filename)", ARG2); + } + PRE_MEM_WRITE("file_getattr(ufattr)", ARG3, sizeof(struct vki_file_attr)); + PRE_MEM_WRITE("file_getattr(usize)", ARG4, sizeof(vki_size_t)); +} + +POST(sys_file_getattr) +{ + // POST_MEM_WRITE(ARG3, sizeof(struct vki_file_attr)); + // POST_MEM_WRITE(ARG4, sizeof(vki_size_t)); +} + +PRE(sys_file_setattr) +{ + // SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, + // struct file_attr __user *, ufattr, size_t, usize, + // unsigned int, at_flags) + // in: dfd, filename, ufattr, usize, at_flags + *flags |= SfMayBlock; + Int arg_1 = (Int) ARG1; + PRINT("sys_file_getattr ( %ld, %#" FMT_REGWORD "x(%s), %#" FMT_REGWORD "x, %" FMT_REGWORD "u, %#" FMT_REGWORD "x )" , + SARG1, ARG2, (HChar*)(Addr)ARG2, ARG3, ARG4, ARG5); + PRE_REG_READ5(int, "file_setattr", int, dfd, const char*, filename, + struct vki_file_attr *, ufattr, vki_size_t, usize, int, at_flags); + // Per https://lwn.net/Articles/1020992/ : + // >> The syscalls take fd and path. If path is absolute, fd is not used. If path + // is empty, fd can be AT_FDCWD or any valid fd which will be used to get/set + // attributes on. << That said, we can't use ML_(fd_at_check_allowed)() here, + // because there is nothing special about relative path. + if (ARG1 == 0) + { + if (arg_1 != VKI_AT_FDCWD && !ML_(fd_allowed)(arg_1, "file_setattr", tid, False)) + { + SET_STATUS_Failure( VKI_EBADF ); + } + } + else + { + PRE_MEM_RASCIIZ("file_setattr(filename)", ARG2); + } + PRE_MEM_READ("file_setattr(ufattr)", ARG3, sizeof(struct vki_file_attr)); +} + PRE(sys_syncfs) { *flags |= SfMayBlock; diff --git a/coregrind/m_syswrap/syswrap-mips32-linux.c b/coregrind/m_syswrap/syswrap-mips32-linux.c index 4edfe8a70..fc8b83d03 100644 --- a/coregrind/m_syswrap/syswrap-mips32-linux.c +++ b/coregrind/m_syswrap/syswrap-mips32-linux.c @@ -1189,6 +1189,8 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_statmount, sys_statmount), // 457 LINXY(__NR_listmount, sys_listmount), // 458 LINX_(__NR_mseal, sys_mseal), // 462 + LINXY(__NR_file_getattr, sys_file_getattr), // 468 + LINX_(__NR_file_setattr, sys_file_setattr), // 469 }; SyscallTableEntry* ML_(get_linux_syscall_entry) (UInt sysno) diff --git a/coregrind/m_syswrap/syswrap-mips64-linux.c b/coregrind/m_syswrap/syswrap-mips64-linux.c index 4fb6f060e..8ed8ea7b3 100644 --- a/coregrind/m_syswrap/syswrap-mips64-linux.c +++ b/coregrind/m_syswrap/syswrap-mips64-linux.c @@ -800,6 +800,8 @@ static SyscallTableEntry syscall_main_table[] = { LINX_ (__NR_mseal, sys_mseal), LINX_ (__NR_futex_waitv, sys_futex_waitv), LINX_ (__NR_quotactl_fd, sys_quotactl_fd), + LINXY(__NR_file_getattr, sys_file_getattr), + LINX_(__NR_file_setattr, sys_file_setattr), }; SyscallTableEntry * ML_(get_linux_syscall_entry) ( UInt sysno ) diff --git a/coregrind/m_syswrap/syswrap-nanomips-linux.c b/coregrind/m_syswrap/syswrap-nanomips-linux.c index f1a0b3c59..20446d2e0 100644 --- a/coregrind/m_syswrap/syswrap-nanomips-linux.c +++ b/coregrind/m_syswrap/syswrap-nanomips-linux.c @@ -825,6 +825,8 @@ static SyscallTableEntry syscall_main_table[] = { LINXY (__NR_listmount, sys_listmount), LINX_ (__NR_mseal, sys_mseal), LINX_ (__NR_futex_waitv, sys_futex_waitv), + LINXY (__NR_file_getattr, sys_file_getattr), + LINX_ (__NR_file_setattr, sys_file_setattr), }; SyscallTableEntry* ML_(get_linux_syscall_entry) (UInt sysno) diff --git a/coregrind/m_syswrap/syswrap-ppc32-linux.c b/coregrind/m_syswrap/syswrap-ppc32-linux.c index b1390f3ab..b4d8ddfbc 100644 --- a/coregrind/m_syswrap/syswrap-ppc32-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc32-linux.c @@ -1088,6 +1088,8 @@ static SyscallTableEntry syscall_table[] = { LINXY (__NR_statmount, sys_statmount), // 457 LINXY (__NR_listmount, sys_listmount), // 458 LINX_ (__NR_mseal, sys_mseal), // 462 + LINXY (__NR_file_getattr, sys_file_getattr), // 468 + LINX_ (__NR_file_setattr, sys_file_setattr), // 469 }; SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno ) diff --git a/coregrind/m_syswrap/syswrap-ppc64-linux.c b/coregrind/m_syswrap/syswrap-ppc64-linux.c index 4a0865084..993179034 100644 --- a/coregrind/m_syswrap/syswrap-ppc64-linux.c +++ b/coregrind/m_syswrap/syswrap-ppc64-linux.c @@ -1066,6 +1066,8 @@ static SyscallTableEntry syscall_table[] = { LINXY (__NR_statmount, sys_statmount), // 457 LINXY (__NR_listmount, sys_listmount), // 458 LINX_ (__NR_mseal, sys_mseal), // 462 + LINXY (__NR_file_getattr, sys_file_getattr), // 468 + LINX_ (__NR_file_setattr, sys_file_setattr), // 469 }; SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno ) diff --git a/coregrind/m_syswrap/syswrap-riscv64-linux.c b/coregrind/m_syswrap/syswrap-riscv64-linux.c index 5a1ea2553..fce0f23fd 100644 --- a/coregrind/m_syswrap/syswrap-riscv64-linux.c +++ b/coregrind/m_syswrap/syswrap-riscv64-linux.c @@ -609,6 +609,8 @@ static SyscallTableEntry syscall_main_table[] = { LINXY(__NR_statmount, sys_statmount), /* 457 */ LINXY(__NR_listmount, sys_listmount), /* 458 */ LINX_(__NR_mseal, sys_mseal), /* 462 */ + LINXY(__NR_file_getattr, sys_file_getattr), /* 468 */ + LINX_(__NR_file_setattr, sys_file_setattr), /* 469 */ }; SyscallTableEntry* ML_(get_linux_syscall_entry)(UInt sysno) diff --git a/coregrind/m_syswrap/syswrap-s390x-linux.c b/coregrind/m_syswrap/syswrap-s390x-linux.c index acb4aefee..1164200fd 100644 --- a/coregrind/m_syswrap/syswrap-s390x-linux.c +++ b/coregrind/m_syswrap/syswrap-s390x-linux.c @@ -901,6 +901,8 @@ static SyscallTableEntry syscall_table[] = { LINXY (__NR_statmount, sys_statmount), // 457 LINXY (__NR_listmount, sys_listmount), // 458 LINX_ (__NR_mseal, sys_mseal), // 462 + LINXY (__NR_file_getattr, sys_file_getattr), // 468 + LINX_ (__NR_file_setattr, sys_file_setattr), // 469 }; SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno ) diff --git a/coregrind/m_syswrap/syswrap-x86-linux.c b/coregrind/m_syswrap/syswrap-x86-linux.c index f697a9e19..d765b7624 100644 --- a/coregrind/m_syswrap/syswrap-x86-linux.c +++ b/coregrind/m_syswrap/syswrap-x86-linux.c @@ -1683,6 +1683,8 @@ static SyscallTableEntry syscall_table[] = { LINXY(__NR_statmount, sys_statmount), // 457 LINXY(__NR_listmount, sys_listmount), // 458 LINX_(__NR_mseal, sys_mseal), // 462 + LINXY(__NR_file_getattr, sys_file_getattr), // 468 + LINX_(__NR_file_setattr, sys_file_setattr), // 469 }; SyscallTableEntry* ML_(get_linux_syscall_entry) ( UInt sysno ) diff --git a/include/vki/vki-linux.h b/include/vki/vki-linux.h index 1b32295bf..e3c5fccb1 100644 --- a/include/vki/vki-linux.h +++ b/include/vki/vki-linux.h @@ -5574,6 +5574,18 @@ struct vki_statmount { char str[]; /* Variable size part containing strings */ }; +//---------------------------------------------------------------------- +// From uapi/linux/fs.h +//---------------------------------------------------------------------- + +struct vki_file_attr { + __vki_u64 fa_xflags; /* xflags field value (get/set) */ + __vki_u32 fa_extsize; /* extsize field value (get/set)*/ + __vki_u32 fa_nextents; /* nextents field value (get) */ + __vki_u32 fa_projid; /* project identifier (get/set) */ + __vki_u32 fa_cowextsize; /* CoW extsize field value (get/set) */ +}; + /*--------------------------------------------------------------------*/ /*--- end ---*/ /*--------------------------------------------------------------------*/ diff --git a/include/vki/vki-scnums-shared-linux.h b/include/vki/vki-scnums-shared-linux.h index 518131a1f..1750f592f 100644 --- a/include/vki/vki-scnums-shared-linux.h +++ b/include/vki/vki-scnums-shared-linux.h @@ -61,5 +61,7 @@ #define __NR_statmount 457 #define __NR_listmount 458 #define __NR_mseal 462 +#define __NR_file_getattr 468 +#define __NR_file_setattr 469 #endif