sys_poll: Fix negative timeout values for x86 userland on x86_64 kernels v2
Subsystems (3)
PATCH 1/3 sys_poll: Fix negative timeout values for x86 userland on x86_64 kernels v2
size of int and long differs on x86 and x86_64. the ia32 emulation calls directly into the sys_poll function. when the timeout is set to -1 the test for sign will fail in sys_poll as the 64bit register is tested. the timeout timer will be set to 0xffffffff milliseconds, but the timer shouldn't get set at all in this situation.
--- arch/x86/ia32/ia32entry.S | 2 +- fs/compat.c | 6 ++++++ include/linux/compat.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletions(-)
move sys_poll() out of the #ifdef
arch/x86/ia32/ia32entry.S +1 -1
@@ -671,7 +671,7 @@ ia32_sys_call_table: .quad sys_getresuid16 /* 165 */ .quad sys32_vm86_warning /* vm86 */ .quad quiet_ni_syscall /* query_module */ - .quad sys_poll + .quad compat_sys_poll .quad quiet_ni_syscall /* old nfsservctl */ .quad sys_setresgid16 /* 170 */ .quad sys_getresgid16
fs/compat.c +6 -0
@@ -1550,6 +1550,12 @@ asmlinkage long compat_sys_old_select(struct compat_sel_arg_struct __user *arg) compat_ptr(a.exp), compat_ptr(a.tvp)); } +asmlinkage long compat_sys_poll (struct pollfd __user *ufds,unsigned int nfds, +int timeout) +{ +return sys_poll (ufds, nfds, timeout); +} +#ifdef HAVE_SET_RESTORE_SIGMASK static long do_compat_pselect(int n, compat_ulong_t __user *inp, compat_ulong_t __user *outp, compat_ulong_t __user *exp,
include/linux/compat.h +2 -0
@@ -433,6 +433,8 @@ asmlinkage long compat_sys_pselect6(int n, compat_ulong_t __user *inp,compat_ulong_t __user *exp, struct compat_timespec __user *tsp, void __user *sig); +asmlinkage long compat_sys_poll (struct pollfd __user *ufds,unsigned int nfds, +int timeout); asmlinkage long compat_sys_ppoll(struct pollfd __user *ufds, unsigned int nfds, struct compat_timespec __user *tsp,
Signature · 1 line
1.7.6
Quoted 1 line · Thomas Meyer
size of int and long differs on x86 and
x86_64. the ia32 emulation calls
The size of int is the same on x86 and x86_64.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
Quoted 6 lines · Thomas Meyer
size of int and long differs on x86 and
x86_64. the ia32 emulation calls directly into thesys_pollfunction. when the timeout is set to -1 the test for sign will fail insys_pollas the 64bit register is tested. the timeout timer will be set to0xffffffffmilliseconds, but the timer shouldn't get set at all in this situation.
As I said, you should CC [email protected] team on this patch. All previous linux versions had this bug : A program might misbehave because of a spurious poll(..., timeout < 0) wakeup.
Could you please refine this Changelog again ?
On 32bit user program, all negative timeout values should not set a timout at all, not only 0xffffffff (-1)
man poll states :
The timeout argument specifies an upper limit on the time for which poll() will block, in milliseconds. Specifying a negative value in timeout means an infinite timeout.