Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs/signalfd.c: fix inconsistent return codes for signalfd4

The kernel signalfd4() syscall returns different error codes when called
either in compat or native mode. This behaviour makes correct emulation
in qemu and testing programs like LTP more complicated.

Fix the code to always return -in both modes- EFAULT for unaccessible user
memory, and EINVAL when called with an invalid signal mask.

Signed-off-by: Helge Deller <deller@gmx.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Laurent Vivier <laurent@vivier.eu>
Link: http://lkml.kernel.org/r/20200530100707.GA10159@ls3530.fritz.box
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Helge Deller and committed by
Linus Torvalds
a089e3fd a090a5a7

+6 -4
+6 -4
fs/signalfd.c
··· 314 314 { 315 315 sigset_t mask; 316 316 317 - if (sizemask != sizeof(sigset_t) || 318 - copy_from_user(&mask, user_mask, sizeof(mask))) 317 + if (sizemask != sizeof(sigset_t)) 319 318 return -EINVAL; 319 + if (copy_from_user(&mask, user_mask, sizeof(mask))) 320 + return -EFAULT; 320 321 return do_signalfd4(ufd, &mask, flags); 321 322 } 322 323 ··· 326 325 { 327 326 sigset_t mask; 328 327 329 - if (sizemask != sizeof(sigset_t) || 330 - copy_from_user(&mask, user_mask, sizeof(mask))) 328 + if (sizemask != sizeof(sigset_t)) 331 329 return -EINVAL; 330 + if (copy_from_user(&mask, user_mask, sizeof(mask))) 331 + return -EFAULT; 332 332 return do_signalfd4(ufd, &mask, 0); 333 333 } 334 334