fuse: fix uring race condition for null dereference of fc
Subsystems (3)
Joanne Koong
maintainerPATCH v2 1/1 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.
This fix passes fc to fuse_uring_create_queue() instead of accessing it through ring->fc.
--- fs/fuse/dev_uring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/fuse/dev_uring.c +3 -3
@@ -250,10 +250,10 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)return res; } -static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_ring *ring, +static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_conn *fc, +struct fuse_ring *ring,int qid) { -struct fuse_conn *fc = ring->fc;struct fuse_ring_queue *queue;struct list_head *pq;
@@ -1088,7 +1088,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd, queue = ring->queues[qid];if (!queue) { - queue =fuse_uring_create_queue (ring, qid); + queue =fuse_uring_create_queue (fc, ring, qid);if (!queue)return err; }
Signature · 1 line
2.47.1
Joanne Koong
maintainerQuoted 8 lines · Joanne Koong
There is a race condition leading to a kernel crash from a null dereference when attemping to access
fc->lockinfuse_uring_create_queue(). fc may be NULL in the case where another thread is creating the uring infuse_uring_create()and has setfc->ringbut has not yet setring->fcwhenfuse_uring_create_queue()readsring->fc.
Quoted 5 lines
This fix passes fc to
fuse_uring_create_queue()instead of accessing it throughring->fc.Signed-off-by Joanne Koong <[email protected]>Fixes 24fe962c86f5 ("fuse: {io-uring} Handle SQEs - register commands")
Thought I added the changelog between v1 -> v2 to the patch but I guess not. including it here now:
Changes between v1 -> v2:
* v1 implementation may be reordered by compiler (Bernd)
* link to v1: https://lore.kernel.org/linux-fsdevel/[email protected]/
Thanks,
Joanne
Quoted 33 lines
--- fs/fuse/dev_uring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/fuse/dev_uring.c +3
-4@@ -250,10 +250,10 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)return res; } -static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_ring *ring, +static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_conn *fc, +struct fuse_ring *ring,int qid) { -struct fuse_conn *fc = ring->fc;struct fuse_ring_queue *queue;struct list_head *pq;@@ -1088,7 +1088,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd, queue = ring->queues[qid];if (!queue) { - queue =fuse_uring_create_queue (ring, qid); + queue =fuse_uring_create_queue (fc, ring, qid);if (!queue)return err; } --2.47.1
Quoted 34 lines · Joanne Koong
There is a race condition leading to a kernel crash from a null dereference when attemping to access
fc->lockinfuse_uring_create_queue(). fc may be NULL in the case where another thread is creating the uring infuse_uring_create()and has setfc->ringbut has not yet setring->fcwhenfuse_uring_create_queue()readsring->fc.This fix passes fc to
fuse_uring_create_queue()instead of accessing it throughring->fc.Signed-off-by Joanne Koong <[email protected]>Fixes 24fe962c86f5 ("fuse: {io-uring} Handle SQEs - register commands")--- fs/fuse/dev_uring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/fuse/dev_uring.c +2
-2@@ -250,10 +250,10 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)return res; } -static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_ring *ring, +static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_conn *fc, +struct fuse_ring *ring,int qid) { -struct fuse_conn *fc = ring->fc;struct fuse_ring_queue *queue;struct list_head *pq;
fs/fuse/dev_uring.c static int fuse_uring_register(struct io_uring_cmd *cmd, · line 1094
Quoted 8 lines
fs/fuse/dev_uring.c +1
-1@@ -1088,7 +1088,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd, queue = ring->queues[qid];if (!queue) { - queue =fuse_uring_create_queue (ring, qid); + queue =fuse_uring_create_queue (fc, ring, qid);if (!queue)return err; }
I wonder if we could get more issues,fuse_uring_register()
{
struct fuse_ring *ring = smp_load_acquire(&fc->ring);
...
if (qid >= ring->nr_queues) {...
}
In fuse_uring_create()
{
...
fc->ring = ring; ring->nr_queues = nr_queues; ring->fc = fc; ring->max_payload_sz = max_payload_size;
...
}
I.e. we cannot trust any of the values assigned after fc->ring? Sorry about this, I should have noticed before :(
Thanks,
Bernd
Joanne Koong
maintainerQuoted 62 lines · Bernd Schubert
Quoted 34 lines · Joanne Koong
There is a race condition leading to a kernel crash from a null dereference when attemping to access
fc->lockinfuse_uring_create_queue(). fc may be NULL in the case where another thread is creating the uring infuse_uring_create()and has setfc->ringbut has not yet setring->fcwhenfuse_uring_create_queue()readsring->fc.This fix passes fc to
fuse_uring_create_queue()instead of accessing it throughring->fc.Signed-off-by Joanne Koong <[email protected]>Fixes 24fe962c86f5 ("fuse: {io-uring} Handle SQEs - register commands")--- fs/fuse/dev_uring.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/fuse/dev_uring.c +2
-2@@ -250,10 +250,10 @@ static struct fuse_ring *fuse_uring_create(struct fuse_conn *fc)return res; } -static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_ring *ring, +static struct fuse_ring_queue *fuse_uring_create_queue (struct fuse_conn *fc, +struct fuse_ring *ring,int qid) { -struct fuse_conn *fc = ring->fc;struct fuse_ring_queue *queue;struct list_head *pq;fs/fuse/dev_uring.c static int fuse_uring_register(struct io_uring_cmd *cmd, · line 1094
Quoted 8 lines
fs/fuse/dev_uring.c +1
-1@@ -1088,7 +1088,7 @@ static int fuse_uring_register(struct io_uring_cmd *cmd, queue = ring->queues[qid];if (!queue) { - queue =fuse_uring_create_queue (ring, qid); + queue =fuse_uring_create_queue (fc, ring, qid);if (!queue)return err; }I wonder if we could get more issues,
fuse_uring_register(){ struct fuse_ring *ring = smp_load_acquire(&fc->ring); ... if (qid >= ring->nr_queues) {...
}In
fuse_uring_create()
{
...fc->ring = ring; ring->nr_queues = nr_queues; ring->fc = fc; ring->max_payload_sz = max_payload_size;
Quoted 5 lines
...
}I.e. we cannot trust any of the values assigned after
fc->ring?
Seems like it, great point. I think we'll need to do the smp memory barrier way after all then. I'll send that as v3.
Quoted 1 line
Sorry about this, I should have noticed before :(
No worries at all, I appreciate all the work you've put getting uring into fuse :)
Thanks,
Joanne
Quoted 4 lines
Thanks,
Bernd