fuse: fix NULL pointer dereference in fuse_request_find
PATCH 1/1 fuse: fix NULL pointer dereference in fuse_request_find
fuse_dev_install_with_pq() publishes fud->chan before it stores fud->pq.processing. The write/splice_write and read paths treat a non-NULL fud->chan as "installed" and then walk fpq->processing[] without taking fch->lock, so they can see the new chan while processing is still NULL and oops in fuse_request_find().
Fix by checking the value of fud->pq.processing before dereferencing.
Fixes 48649c0603bd ("fuse: alloc pqueue before installing fch in fuse_dev")
Reported-by 马云龙 <[email protected]>
Signed-off-by Miklos Szeredi <[email protected]>
--- fs/fuse/dev.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
fs/fuse/dev.c +7 -2
@@ -483,7 +483,7 @@ static bool fuse_dev_install_with_pq(struct fuse_dev *fud, struct fuse_chan *fch }if (pq) {WARN_ON (fud->pq.processing); - fud->pq.processing = pq; +WRITE_ONCE (fud->pq.processing, pq); }list_add_tail (&fud->entry, &fch->devices);fuse_conn_get (fch->conn);
@@ -1839,8 +1839,13 @@ struct fuse_req *fuse_request_find(struct fuse_pqueue *fpq, u64 unique) {unsigned int hash =fuse_req_hash (unique);struct fuse_req *req; +struct list_head *pq =READ_ONCE (fpq->processing); -list_for_each_entry (req, &fpq->processing[hash], list) { +/* Race with fuse_dev_install_with_pq() */ +if (!pq) +return NULL ; + +list_for_each_entry (req, &pq[hash], list) {if (req->in.h.unique == unique)return req; }
Signature · 1 line
2.54.0