Re: [PATCH] fuse: fix uring race condition for null dereference of fc

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

 



Hi Joanne,

On 3/14/25 20:13, Joanne Koong wrote:
> There is a race condition leading to a kernel crash from a null
> dereference when attemping to access fc->lock in
> fuse_uring_create_queue(). fc may be NULL in the case where another
> thread is creating the uring in fuse_uring_create() and has set
> fc->ring but has not yet set ring->fc when fuse_uring_create_queue()
> reads ring->fc.
> 
> This fix sets fc->ring only after ring->fc has been set, which
> guarantees now that ring->fc is a proper pointer when any queues are
> created.
> 
> Signed-off-by: Joanne Koong <joannelkoong@xxxxxxxxx>
> Fixes: 24fe962c86f5 ("fuse: {io-uring} Handle SQEs - register commands")
> ---
>  fs/fuse/dev_uring.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
> index ab8c26042aa8..618a413ef400 100644
> --- a/fs/fuse/dev_uring.c
> +++ b/fs/fuse/dev_uring.c
> @@ -235,9 +235,9 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)
>  
>  	init_waitqueue_head(&ring->stop_waitq);
>  
> -	fc->ring = ring;
>  	ring->nr_queues = nr_queues;
>  	ring->fc = fc;
> +	fc->ring = ring;
>  	ring->max_payload_sz = max_payload_size;
>  	atomic_set(&ring->queue_refs, 0);
>  

oh, I  didn't get that and even KCSAN didn't complain. But I see that it
would be possible. I'm just a bit scared that the compiler might 
re-order things on its own.

What about this?

diff --git a/fs/fuse/dev_uring.c b/fs/fuse/dev_uring.c
index 9d78c9f29a09..f33a7e6f5ec3 100644
--- a/fs/fuse/dev_uring.c
+++ b/fs/fuse/dev_uring.c
@@ -241,11 +241,12 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)
 
        init_waitqueue_head(&ring->stop_waitq);
 
-       fc->ring = ring;
        ring->nr_queues = nr_queues;
        ring->fc = fc;
        ring->max_payload_sz = max_payload_size;
        atomic_set(&ring->queue_refs, 0);
+       /* Ensures initialization is visible before ring pointer */
+       smp_store_release(&fc->ring, ring);
 
        spin_unlock(&fc->lock);
        return ring;



Thanks,
Bernd




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux