Skip to content

Commit 1dfe2a2

Browse files
joannekoongMiklos Szeredi
authored andcommitted
fuse: fix uring race condition for null dereference of fc
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. There is another race condition as well where in fuse_uring_register(), ring->nr_queues may still be 0 and not yet set to the new value when we compare qid against it. This fix sets fc->ring only after ring->fc and ring->nr_queues have been set, which guarantees now that ring->fc is a proper pointer when any queues are created and ring->nr_queues reflects the right number of queues if ring is not NULL. We must use smp_store_release() and smp_load_acquire() semantics to ensure the ordering will remain correct where fc->ring is assigned only after ring->fc and ring->nr_queues have been assigned. Signed-off-by: Joanne Koong <joannelkoong@gmail.com> Fixes: 24fe962 ("fuse: {io-uring} Handle SQEs - register commands") Reviewed-by: Bernd Schubert <bschubert@ddn.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 27992ef commit 1dfe2a2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/fuse/dev_uring.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)
235235

236236
init_waitqueue_head(&ring->stop_waitq);
237237

238-
fc->ring = ring;
239238
ring->nr_queues = nr_queues;
240239
ring->fc = fc;
241240
ring->max_payload_sz = max_payload_size;
242241
atomic_set(&ring->queue_refs, 0);
242+
smp_store_release(&fc->ring, ring);
243243

244244
spin_unlock(&fc->lock);
245245
return ring;
@@ -1064,7 +1064,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd,
10641064
unsigned int issue_flags, struct fuse_conn *fc)
10651065
{
10661066
const struct fuse_uring_cmd_req *cmd_req = io_uring_sqe_cmd(cmd->sqe);
1067-
struct fuse_ring *ring = fc->ring;
1067+
struct fuse_ring *ring = smp_load_acquire(&fc->ring);
10681068
struct fuse_ring_queue *queue;
10691069
struct fuse_ring_ent *ent;
10701070
int err;

0 commit comments

Comments
 (0)