Patch "afs: fix __afs_break_callback() / afs_drop_open_mmap() race" 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

    afs: fix __afs_break_callback() / afs_drop_open_mmap() race

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:
     afs-fix-__afs_break_callback-afs_drop_open_mmap-race.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 71ce3bc3a1d73143ddef42caccffbe9a7e1c2a54
Author: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
Date:   Fri Sep 29 20:24:34 2023 -0400

    afs: fix __afs_break_callback() / afs_drop_open_mmap() race
    
    [ Upstream commit 275655d3207b9e65d1561bf21c06a622d9ec1d43 ]
    
    In __afs_break_callback() we might check ->cb_nr_mmap and if it's non-zero
    do queue_work(&vnode->cb_work).  In afs_drop_open_mmap() we decrement
    ->cb_nr_mmap and do flush_work(&vnode->cb_work) if it reaches zero.
    
    The trouble is, there's nothing to prevent __afs_break_callback() from
    seeing ->cb_nr_mmap before the decrement and do queue_work() after both
    the decrement and flush_work().  If that happens, we might be in trouble -
    vnode might get freed before the queued work runs.
    
    __afs_break_callback() is always done under ->cb_lock, so let's make
    sure that ->cb_nr_mmap can change from non-zero to zero while holding
    ->cb_lock (the spinlock component of it - it's a seqlock and we don't
    need to mess with the counter).
    
    Acked-by: Christian Brauner <brauner@xxxxxxxxxx>
    Signed-off-by: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/fs/afs/file.c b/fs/afs/file.c
index 2eeab57df133a..9051ed0085544 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -525,13 +525,17 @@ static void afs_add_open_mmap(struct afs_vnode *vnode)
 
 static void afs_drop_open_mmap(struct afs_vnode *vnode)
 {
-	if (!atomic_dec_and_test(&vnode->cb_nr_mmap))
+	if (atomic_add_unless(&vnode->cb_nr_mmap, -1, 1))
 		return;
 
 	down_write(&vnode->volume->cell->fs_open_mmaps_lock);
 
-	if (atomic_read(&vnode->cb_nr_mmap) == 0)
+	read_seqlock_excl(&vnode->cb_lock);
+	// the only place where ->cb_nr_mmap may hit 0
+	// see __afs_break_callback() for the other side...
+	if (atomic_dec_and_test(&vnode->cb_nr_mmap))
 		list_del_init(&vnode->cb_mmap_link);
+	read_sequnlock_excl(&vnode->cb_lock);
 
 	up_write(&vnode->volume->cell->fs_open_mmaps_lock);
 	flush_work(&vnode->cb_work);




[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