waitid(): Avoid unbalanced user_access_end() on access_ok() error
authorKees Cook <keescook@chromium.org>
Fri, 20 Oct 2017 14:36:05 +0000 (07:36 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 Oct 2017 19:32:54 +0000 (15:32 -0400)
As pointed out by Linus and David, the earlier waitid() fix resulted in
a (currently harmless) unbalanced user_access_end() call.  This fixes it
to just directly return EFAULT on access_ok() failure.

Fixes: 96ca579a1ecc ("waitid(): Add missing access_ok() checks")
Acked-by: David Daney <david.daney@cavium.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/exit.c

index cf28528842bcf54f4125517fd6c7521b3c79685c..f6cad39f35dfbe441abc5fc740458a6574e7d529 100644 (file)
@@ -1611,7 +1611,7 @@ SYSCALL_DEFINE5(waitid, int, which, pid_t, upid, struct siginfo __user *,
                return err;
 
        if (!access_ok(VERIFY_WRITE, infop, sizeof(*infop)))
-               goto Efault;
+               return -EFAULT;
 
        user_access_begin();
        unsafe_put_user(signo, &infop->si_signo, Efault);
@@ -1739,7 +1739,7 @@ COMPAT_SYSCALL_DEFINE5(waitid,
                return err;
 
        if (!access_ok(VERIFY_WRITE, infop, sizeof(*infop)))
-               goto Efault;
+               return -EFAULT;
 
        user_access_begin();
        unsafe_put_user(signo, &infop->si_signo, Efault);