Patch "exec: don't WARN for racy path_noexec check" has been added to the 6.1-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

    exec: don't WARN for racy path_noexec check

to the 6.1-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:
     exec-don-t-warn-for-racy-path_noexec-check.patch
and it can be found in the queue-6.1 subdirectory.

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



commit cd6668a0a2be7cafc4417e5f1146f66fd657f6f1
Author: Mateusz Guzik <mjguzik@xxxxxxxxx>
Date:   Tue Oct 22 15:45:25 2024 -0300

    exec: don't WARN for racy path_noexec check
    
    [ Upstream commit 0d196e7589cefe207d5d41f37a0a28a1fdeeb7c6 ]
    
    Both i_mode and noexec checks wrapped in WARN_ON stem from an artifact
    of the previous implementation. They used to legitimately check for the
    condition, but that got moved up in two commits:
    633fb6ac3980 ("exec: move S_ISREG() check earlier")
    0fd338b2d2cd ("exec: move path_noexec() check earlier")
    
    Instead of being removed said checks are WARN_ON'ed instead, which
    has some debug value.
    
    However, the spurious path_noexec check is racy, resulting in
    unwarranted warnings should someone race with setting the noexec flag.
    
    One can note there is more to perm-checking whether execve is allowed
    and none of the conditions are guaranteed to still hold after they were
    tested for.
    
    Additionally this does not validate whether the code path did any perm
    checking to begin with -- it will pass if the inode happens to be
    regular.
    
    Keep the redundant path_noexec() check even though it's mindless
    nonsense checking for guarantee that isn't given so drop the WARN.
    
    Reword the commentary and do small tidy ups while here.
    
    Signed-off-by: Mateusz Guzik <mjguzik@xxxxxxxxx>
    Link: https://lore.kernel.org/r/20240805131721.765484-1-mjguzik@xxxxxxxxx
    [brauner: keep redundant path_noexec() check]
    Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx>
    [cascardo: keep exit label and use it]
    Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@xxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/exec.c b/fs/exec.c
index 65d3ebc24fd34..a42c9b8b070d7 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -141,13 +141,11 @@ SYSCALL_DEFINE1(uselib, const char __user *, library)
 		goto out;
 
 	/*
-	 * may_open() has already checked for this, so it should be
-	 * impossible to trip now. But we need to be extra cautious
-	 * and check again at the very end too.
+	 * Check do_open_execat() for an explanation.
 	 */
 	error = -EACCES;
-	if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode) ||
-			 path_noexec(&file->f_path)))
+	if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode)) ||
+	    path_noexec(&file->f_path))
 		goto exit;
 
 	fsnotify_open(file);
@@ -927,16 +925,16 @@ static struct file *do_open_execat(int fd, struct filename *name, int flags)
 
 	file = do_filp_open(fd, name, &open_exec_flags);
 	if (IS_ERR(file))
-		goto out;
+		return file;
 
 	/*
-	 * may_open() has already checked for this, so it should be
-	 * impossible to trip now. But we need to be extra cautious
-	 * and check again at the very end too.
+	 * In the past the regular type check was here. It moved to may_open() in
+	 * 633fb6ac3980 ("exec: move S_ISREG() check earlier"). Since then it is
+	 * an invariant that all non-regular files error out before we get here.
 	 */
 	err = -EACCES;
-	if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode) ||
-			 path_noexec(&file->f_path)))
+	if (WARN_ON_ONCE(!S_ISREG(file_inode(file)->i_mode)) ||
+	    path_noexec(&file->f_path))
 		goto exit;
 
 	err = deny_write_access(file);
@@ -946,7 +944,6 @@ static struct file *do_open_execat(int fd, struct filename *name, int flags)
 	if (name->name[0] != '\0')
 		fsnotify_open(file);
 
-out:
 	return file;
 
 exit:




[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