Skip to contentSkip to conversation

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

RFC PATCH Superseded Helge Deller 1 participant 1 message Apr 25, 2020 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 fs/signalfd.c: Fix inconsistent return codes for signalfd4

The kernel provides a native and a compat implementation for the signalfd4() syscall.

While looking into the qemu user emulation code, I noticed that in the kernel compat case, EFAULT is returned if the given user mask can't be accessed, while the native path returns EINVAL on such failure.

For the sake of consistency, this patch adjusts the native path to return the same error code (EFAULT) as the compat case.

fs/signalfd.c +6 -4
index 44b6845b071c..5b78719be445 100644
@@ -314,9 +314,10 @@ SYSCALL_DEFINE4(signalfd4, int, ufd, sigset_t __user *, user_mask,
 {
 	sigset_t mask;
 
-	if (sizemask != sizeof(sigset_t) ||
-	    copy_from_user(&mask, user_mask, sizeof(mask)))
+	if (sizemask != sizeof(sigset_t))
 		return -EINVAL;
+	if (copy_from_user(&mask, user_mask, sizeof(mask)))
+		return -EFAULT;
 	return do_signalfd4(ufd, &mask, flags);
 }
 
@@ -325,9 +326,10 @@ SYSCALL_DEFINE3(signalfd, int, ufd, sigset_t __user *, user_mask,
 {
 	sigset_t mask;
 
-	if (sizemask != sizeof(sigset_t) ||
-	    copy_from_user(&mask, user_mask, sizeof(mask)))
+	if (sizemask != sizeof(sigset_t))
 		return -EINVAL;
+	if (copy_from_user(&mask, user_mask, sizeof(mask)))
+		return -EFAULT;
 	return do_signalfd4(ufd, &mask, 0);
 }