Patch "userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK" has been added to the 5.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK

to the 5.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     userfaultfd-require-cap_sys_ptrace-for-uffd_feature_.patch
and it can be found in the queue-5.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 7228e7741b6dd3ecc962c05e0ec3746256f00568
Author: Mike Rapoport <rppt@xxxxxxxxxxxxx>
Date:   Sat Nov 30 17:58:01 2019 -0800

    userfaultfd: require CAP_SYS_PTRACE for UFFD_FEATURE_EVENT_FORK
    
    [ Upstream commit 3c1c24d91ffd536de0a64688a9df7f49e58fadbc ]
    
    A while ago Andy noticed
    (http://lkml.kernel.org/r/CALCETrWY+5ynDct7eU_nDUqx=okQvjm=Y5wJvA4ahBja=CQXGw@xxxxxxxxxxxxxx)
    that UFFD_FEATURE_EVENT_FORK used by an unprivileged user may have
    security implications.
    
    As the first step of the solution the following patch limits the availably
    of UFFD_FEATURE_EVENT_FORK only for those having CAP_SYS_PTRACE.
    
    The usage of CAP_SYS_PTRACE ensures compatibility with CRIU.
    
    Yet, if there are other users of non-cooperative userfaultfd that run
    without CAP_SYS_PTRACE, they would be broken :(
    
    Current implementation of UFFD_FEATURE_EVENT_FORK modifies the file
    descriptor table from the read() implementation of uffd, which may have
    security implications for unprivileged use of the userfaultfd.
    
    Limit availability of UFFD_FEATURE_EVENT_FORK only for callers that have
    CAP_SYS_PTRACE.
    
    Link: http://lkml.kernel.org/r/1572967777-8812-2-git-send-email-rppt@xxxxxxxxxxxxx
    Signed-off-by: Mike Rapoport <rppt@xxxxxxxxxxxxx>
    Reviewed-by: Andrea Arcangeli <aarcange@xxxxxxxxxx>
    Cc: Daniel Colascione <dancol@xxxxxxxxxx>
    Cc: Jann Horn <jannh@xxxxxxxxxx>
    Cc: Lokesh Gidra <lokeshgidra@xxxxxxxxxx>
    Cc: Nick Kralevich <nnk@xxxxxxxxxx>
    Cc: Nosh Minwalla <nosh@xxxxxxxxxx>
    Cc: Pavel Emelyanov <ovzxemul@xxxxxxxxx>
    Cc: Tim Murray <timmurray@xxxxxxxxxx>
    Cc: Aleksa Sarai <cyphar@xxxxxxxxxx>
    Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index f9fd18670e22..d99d166fd892 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -1834,13 +1834,12 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx,
 	if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api)))
 		goto out;
 	features = uffdio_api.features;
-	if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) {
-		memset(&uffdio_api, 0, sizeof(uffdio_api));
-		if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
-			goto out;
-		ret = -EINVAL;
-		goto out;
-	}
+	ret = -EINVAL;
+	if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES))
+		goto err_out;
+	ret = -EPERM;
+	if ((features & UFFD_FEATURE_EVENT_FORK) && !capable(CAP_SYS_PTRACE))
+		goto err_out;
 	/* report all available features and ioctls to userland */
 	uffdio_api.features = UFFD_API_FEATURES;
 	uffdio_api.ioctls = UFFD_API_IOCTLS;
@@ -1853,6 +1852,11 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx,
 	ret = 0;
 out:
 	return ret;
+err_out:
+	memset(&uffdio_api, 0, sizeof(uffdio_api));
+	if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api)))
+		ret = -EFAULT;
+	goto out;
 }
 
 static long userfaultfd_ioctl(struct file *file, unsigned cmd,



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux