Skip to content

Commit 7c89e40

Browse files
hdellergregkh
authored andcommitted
fs/signalfd.c: fix inconsistent return codes for signalfd4
[ Upstream commit a089e3f ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6afcb8b commit 7c89e40

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

fs/signalfd.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,10 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
313313
{
314314
sigset_t mask;
315315

316-
if (sizemask != sizeof(sigset_t) ||
317-
copy_from_user(&mask, user_mask, sizeof(mask)))
316+
if (sizemask != sizeof(sigset_t))
318317
return -EINVAL;
318+
if (copy_from_user(&mask, user_mask, sizeof(mask)))
319+
return -EFAULT;
319320
return do_signalfd4(ufd, &mask, flags);
320321
}
321322

@@ -324,9 +325,10 @@ SYSCALL_DEFINE3(signalfd, int, ufd, sigset_t __user *, user_mask,
324325
{
325326
sigset_t mask;
326327

327-
if (sizemask != sizeof(sigset_t) ||
328-
copy_from_user(&mask, user_mask, sizeof(mask)))
328+
if (sizemask != sizeof(sigset_t))
329329
return -EINVAL;
330+
if (copy_from_user(&mask, user_mask, sizeof(mask)))
331+
return -EFAULT;
330332
return do_signalfd4(ufd, &mask, 0);
331333
}
332334

0 commit comments

Comments
 (0)