Patch "fs: use acquire ordering in __fget_light()" has been added to the 6.0-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

    fs: use acquire ordering in __fget_light()

to the 6.0-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:
     fs-use-acquire-ordering-in-__fget_light.patch
and it can be found in the queue-6.0 subdirectory.

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



commit a8487750046d4db36d58938e1b2a4fc805761be9
Author: Jann Horn <jannh@xxxxxxxxxx>
Date:   Mon Oct 31 18:52:56 2022 +0100

    fs: use acquire ordering in __fget_light()
    
    [ Upstream commit 7ee47dcfff1835ff75a794d1075b6b5f5462cfed ]
    
    We must prevent the CPU from reordering the files->count read with the
    FD table access like this, on architectures where read-read reordering is
    possible:
    
        files_lookup_fd_raw()
                                      close_fd()
                                      put_files_struct()
        atomic_read(&files->count)
    
    I would like to mark this for stable, but the stable rules explicitly say
    "no theoretical races", and given that the FD table pointer and
    files->count are explicitly stored in the same cacheline, this sort of
    reordering seems quite unlikely in practice...
    
    Signed-off-by: Jann Horn <jannh@xxxxxxxxxx>
    Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/file.c b/fs/file.c
index 3bcc1ecc314a..57af5f8375fd 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -1002,7 +1002,16 @@ static unsigned long __fget_light(unsigned int fd, fmode_t mask)
 	struct files_struct *files = current->files;
 	struct file *file;
 
-	if (atomic_read(&files->count) == 1) {
+	/*
+	 * If another thread is concurrently calling close_fd() followed
+	 * by put_files_struct(), we must not observe the old table
+	 * entry combined with the new refcount - otherwise we could
+	 * return a file that is concurrently being freed.
+	 *
+	 * atomic_read_acquire() pairs with atomic_dec_and_test() in
+	 * put_files_struct().
+	 */
+	if (atomic_read_acquire(&files->count) == 1) {
 		file = files_lookup_fd_raw(files, fd);
 		if (!file || unlikely(file->f_mode & mask))
 			return 0;



[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