mirror of
https://github.com/Dasharo/linux.git
synced 2026-03-06 15:25:10 -08:00
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>
Link: https://lore.kernel.org/r/20250318003028.3330599-1-joannelkoong@gmail.com
Fixes: 24fe962c86 ("fuse: {io-uring} Handle SQEs - register commands")
Acked-by: Miklos Szeredi <mszeredi@redhat.com>
Reviewed-by: Bernd Schubert <bschubert@ddn.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
committed by
Christian Brauner
parent
0307d16f36
commit
d9ecc77193
@@ -208,11 +208,11 @@ 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);
|
||||
smp_store_release(&fc->ring, ring);
|
||||
|
||||
spin_unlock(&fc->lock);
|
||||
return ring;
|
||||
@@ -1041,7 +1041,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd,
|
||||
unsigned int issue_flags, struct fuse_conn *fc)
|
||||
{
|
||||
const struct fuse_uring_cmd_req *cmd_req = io_uring_sqe_cmd(cmd->sqe);
|
||||
struct fuse_ring *ring = fc->ring;
|
||||
struct fuse_ring *ring = smp_load_acquire(&fc->ring);
|
||||
struct fuse_ring_queue *queue;
|
||||
struct fuse_ring_ent *ent;
|
||||
int err;
|
||||
|
||||
Reference in New Issue
Block a user