fanotify: Fix fanotify_mark() on 32-bit x86
Subsystems (7)
Jan Kara
maintainerPATCH 1/1 fanotify: Fix fanotify_mark() on 32-bit x86
Commit converting syscalls taking 64-bit arguments to new scheme of compat handlers omitted converting fanotify_mark(2) which then broke the syscall for 32-bit x86 builds. Add missed conversion. It is somewhat cumbersome since we need to keep the original compat handler for all the other 32-bit archs.
--- arch/x86/entry/syscalls/syscall_32.tbl | 2 +- fs/notify/fanotify/fanotify_user.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
I plan to queue this fix into my tree next week. I'd be happy if someone with x86 ABI knowledge checks whether I've got the patch right (especially various config variants) because it was mostly a guesswork of me & Boris ;). Thanks!
arch/x86/entry/syscalls/syscall_32.tbl +1 -1
@@ -350,7 +350,7 @@ 336 i386 perf_event_open sys_perf_event_open 337 i386 recvmmsg sys_recvmmsg_time32 compat_sys_recvmmsg_time32 338 i386 fanotify_init sys_fanotify_init -339 i386 fanotify_mark sys_fanotify_mark compat_sys_fanotify_mark +339 i386 fanotify_mark sys_ia32_fanotify_mark 340 i386 prlimit64 sys_prlimit64 341 i386 name_to_handle_at sys_name_to_handle_at 342 i386 open_by_handle_at sys_open_by_handle_at compat_sys_open_by_handle_at
fs/notify/fanotify/fanotify_user.c +6 -1
@@ -1292,8 +1292,13 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,return do_fanotify_mark (fanotify_fd, flags, mask, dfd, pathname); } -#ifdef CONFIG_COMPAT +#if defined(CONFIG_COMPAT ) || defined(CONFIG_X86_32 ) || \ + defined(CONFIG_IA32_EMULATION ) +#if defined(CONFIG_X86_32 ) || defined(CONFIG_IA32_EMULATION ) +SYSCALL_DEFINE6(ia32_fanotify_mark, +#elif CONFIG_COMPAT COMPAT_SYSCALL_DEFINE6 (fanotify_mark, +#endif int, fanotify_fd, unsigned int, flags, __u32, mask0, __u32, mask1, int, dfd, const char __user *, pathname)
Signature · 1 line
2.16.4
Andy Lutomirski
maintainerQuoted 7 lines · Jan Kara
Commit converting syscalls taking 64-bit arguments to new scheme of compat handlers omitted converting
fanotify_mark(2)which then broke the syscall for 32-bit x86 builds. Add missed conversion. It is somewhat cumbersome since we need to keep the original compat handler for all the other 32-bit archs.
This is stupendously ugly. I'm not really sure how this is supposed to work on any 32-bit arch. I'm also not sure whether we should expect the SYSCALL_DEFINE macros to figure this out by themselves.
At the very least, the native arm 32 and arm64 compat cases should get tested.
Al and Christoph, you're probably a lot more familiar than I am with the nasty details of syscall ABI with 64-bit arguments.
Quoted 51 lines
CC Brian Gerst <[email protected]>Suggested-by Borislav Petkov <[email protected]>Reported-by Paweł Jasiak <[email protected]>Reported-and-tested-by Naresh Kamboju <[email protected]>Fixes 121b32a58a3a ("x86/entry/32: Use IA32-specific wrappers for syscalls taking 64-bit arguments")Signed-off-by Jan Kara <[email protected]>--- arch/x86/entry/syscalls/syscall_32.tbl | 2 +- fs/notify/fanotify/fanotify_user.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)I plan to queue this fix into my tree next week. I'd be happy if someone with x86 ABI knowledge checks whether I've got the patch right (especially various config variants) because it was mostly a guesswork of me & Boris ;). Thanks!
arch/x86/entry/syscalls/syscall_32.tbl +1
-1@@ -350,7 +350,7 @@ 336 i386 perf_event_open sys_perf_event_open 337 i386 recvmmsg sys_recvmmsg_time32 compat_sys_recvmmsg_time32 338 i386 fanotify_init sys_fanotify_init -339 i386 fanotify_mark sys_fanotify_mark compat_sys_fanotify_mark +339 i386 fanotify_mark sys_ia32_fanotify_mark 340 i386 prlimit64 sys_prlimit64 341 i386 name_to_handle_at sys_name_to_handle_at 342 i386 open_by_handle_at sys_open_by_handle_at compat_sys_open_by_handle_atfs/notify/fanotify/fanotify_user.c +6
-2@@ -1292,8 +1292,13 @@ SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,return do_fanotify_mark (fanotify_fd, flags, mask, dfd, pathname); } -#ifdef CONFIG_COMPAT +#if defined(CONFIG_COMPAT ) || defined(CONFIG_X86_32 ) || \ + defined(CONFIG_IA32_EMULATION ) +#if defined(CONFIG_X86_32 ) || defined(CONFIG_IA32_EMULATION ) +SYSCALL_DEFINE6(ia32_fanotify_mark, +#elif CONFIG_COMPAT COMPAT_SYSCALL_DEFINE6 (fanotify_mark, +#endif int, fanotify_fd, unsigned int, flags, __u32, mask0, __u32, mask1, int, dfd, const char __user *, pathname) --2.16.4
Quoted 10 lines · Andy Lutomirski
Quoted 7 lines · Jan Kara
Commit converting syscalls taking 64-bit arguments to new scheme of compat handlers omitted converting
fanotify_mark(2)which then broke the syscall for 32-bit x86 builds. Add missed conversion. It is somewhat cumbersome since we need to keep the original compat handler for all the other 32-bit archs.
Quoted 3 lines
This is stupendously ugly. I'm not really sure how this is supposed to work on any 32-bit arch. I'm also not sure whether we should expect the
SYSCALL_DEFINEmacros to figure this out by themselves.
It works on 32-bit arches because the compiler implicitly uses consecutive input registers or stack slots for 64-bit arguments, and some arches have alignment requirements that result in hidden padding. x86-32 is different now because parameters are passed in via pt_regs, and the 64-bit value has to explicitly be reassembled from the high and low 32-bit values, just like in the compat case.
I think the simplest way to handle this is add a wrapper in arch/x86/kernel/sys_ia32.c with the other fs syscalls that need 64-bit args. That keeps this mess out of general code.
--
Brian Gerst
Andy Lutomirski
maintainerQuoted 16 lines · Brian Gerst
Quoted 10 lines · Andy Lutomirski
Quoted 7 lines · Jan Kara
Commit converting syscalls taking 64-bit arguments to new scheme of compat handlers omitted converting
fanotify_mark(2)which then broke the syscall for 32-bit x86 builds. Add missed conversion. It is somewhat cumbersome since we need to keep the original compat handler for all the other 32-bit archs.Quoted 3 lines
This is stupendously ugly. I'm not really sure how this is supposed to work on any 32-bit arch. I'm also not sure whether we should expect the
SYSCALL_DEFINEmacros to figure this out by themselves.
Quoted 7 lines
It works on 32-bit arches because the compiler implicitly uses consecutive input registers or stack slots for 64-bit arguments, and some arches have alignment requirements that result in hidden padding. x86-32 is different now because parameters are passed in via
pt_regs, and the 64-bit value has to explicitly be reassembled from the high and low 32-bit values, just like in the compat case.
That was my guess.
Quoted 3 lines
I think the simplest way to handle this is add a wrapper in
arch/x86/kernel/sys_ia32.cwith the other fs syscalls that need 64-bit args. That keeps this mess out of general code.
Want to send a patch?
I also wonder if there's a straightforward way to statically check this. Maybe the syscall wrapper macros could be rigged up to avoid emitting the ia32 stubs if there is a u64 or s64 arg, so the build would fail if someone tries to stick one in the syscall tables. I tried to do this, but I got a bit lost in the macro maze and my attempt didn't work.
--Andy
Quoted 26 lines · Andy Lutomirski
Quoted 16 lines · Brian Gerst
Quoted 10 lines · Andy Lutomirski
Quoted 7 lines · Jan Kara
Commit converting syscalls taking 64-bit arguments to new scheme of compat handlers omitted converting
fanotify_mark(2)which then broke the syscall for 32-bit x86 builds. Add missed conversion. It is somewhat cumbersome since we need to keep the original compat handler for all the other 32-bit archs.Quoted 3 lines
This is stupendously ugly. I'm not really sure how this is supposed to work on any 32-bit arch. I'm also not sure whether we should expect the
SYSCALL_DEFINEmacros to figure this out by themselves.Quoted 7 lines
It works on 32-bit arches because the compiler implicitly uses consecutive input registers or stack slots for 64-bit arguments, and some arches have alignment requirements that result in hidden padding. x86-32 is different now because parameters are passed in via
pt_regs, and the 64-bit value has to explicitly be reassembled from the high and low 32-bit values, just like in the compat case.
Quoted 8 lines
That was my guess.
Quoted 3 lines
I think the simplest way to handle this is add a wrapper in
arch/x86/kernel/sys_ia32.cwith the other fs syscalls that need 64-bit args. That keeps this mess out of general code.Want to send a patch?
I settled on doing something along the same line as Jan, but in a more generic way that lays the groundwork for converting more of these arch-specific compat wrappers to a generic wrapper.
Patch coming soon.
--
Brian Gerst
Jan Kara
maintainerQuoted 34 lines · Brian Gerst
Quoted 33 lines · Andy Lutomirski
Quoted 16 lines · Brian Gerst
Quoted 10 lines · Andy Lutomirski
Quoted 7 lines · Jan Kara
Commit converting syscalls taking 64-bit arguments to new scheme of compat handlers omitted converting
fanotify_mark(2)which then broke the syscall for 32-bit x86 builds. Add missed conversion. It is somewhat cumbersome since we need to keep the original compat handler for all the other 32-bit archs.Quoted 3 lines
This is stupendously ugly. I'm not really sure how this is supposed to work on any 32-bit arch. I'm also not sure whether we should expect the
SYSCALL_DEFINEmacros to figure this out by themselves.Quoted 7 lines
It works on 32-bit arches because the compiler implicitly uses consecutive input registers or stack slots for 64-bit arguments, and some arches have alignment requirements that result in hidden padding. x86-32 is different now because parameters are passed in via
pt_regs, and the 64-bit value has to explicitly be reassembled from the high and low 32-bit values, just like in the compat case.That was my guess.
Quoted 3 lines
I think the simplest way to handle this is add a wrapper in
arch/x86/kernel/sys_ia32.cwith the other fs syscalls that need 64-bit args. That keeps this mess out of general code.
Quoted 5 lines
Quoted 1 line
Want to send a patch?
I settled on doing something along the same line as Jan, but in a more generic way that lays the groundwork for converting more of these arch-specific compat wrappers to a generic wrapper.
Cool, thanks for looking into this!
Quoted 1 line
Patch coming soon.
Looking forward to it :)
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
kernel test robot
build botI love your patch! Yet something to improve:
Hi Jan,
I love your patch! Yet something to improve:
[auto build test ERROR on ext3/fsnotify]
[also build test ERROR on tip/x86/asm v5.10-rc6 next-20201201] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jan-Kara/fanotify-Fix-fanotify_mark-on-32-bit-x86/20201126-235659 base: https://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs.git fsnotify config: x86_64-kexec (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0 reproduce (this is a W=1 build): # https://github.com/0day-ci/linux/commit/83512221cb769f80e071541619033b0dad1b8fa6 git remote add linux-review https://github.com/0day-ci/linux git fetch --no-tags linux-review Jan-Kara/fanotify-Fix-fanotify_mark-on-32-bit-x86/20201126-235659 git checkout 83512221cb769f80e071541619033b0dad1b8fa6 # save the attached .config to linux build tree make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> ld: arch/x86/entry/syscall_32.o:(.rodata+0xa98): undefined reference to `__ia32_sys_ia32_fanotify_mark'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org