From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18F243101BF; Thu, 16 Jul 2026 13:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784210302; cv=none; b=h91rwJiIGsksQUYlxjzaBdiBiOFcTa0fBn+DEtpumRa+yTMExGvbJoVRJ5aUDWVwC6Y5Rf+gb/ljcjHKuaR7lpsyNuuee852DaxNbix8c59Yyr+JVzKZeFMsOzFqObzNtuyi8R2aw3z3IFWoFFyZ8fNHOXwjQsq8o3+B13RP7Ds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784210302; c=relaxed/simple; bh=WE7L+TUa5RbSbRjo2PfGO0aHnxRKfadLyREIo93fTKM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QhE0UUEVK2Bnoh0znR4c4hDIIOH0uXZGwx8ByXjSiZGzlSznplU0cbLCUOuLka2hcU6jhaC16Gd5FBkNxyXk1WCOksZL+P/sXpmWUGvZK7fTaUqDB7Hbe+3uCvCJ6xVPJipHJKQRh2hmWkEdoGQAr+FtzI5C4AdA6YlXrdYxqcE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AE/yAAgr; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="AE/yAAgr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CB8B1F000E9; Thu, 16 Jul 2026 13:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784210300; bh=Ug6y+7YfgQIv3p8ELKldICzYJqfuiPaumIZltwK/t/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AE/yAAgr47N/hdeEbQqla0Yis0N9KDh/gkt30RYo3TkPdyCWuQeKRtU0M8CoN/NVD jYAv78eV6h/f9fLDZpPO68UmK1XM9UXNsnKgtPwF5vk1eEjdYbhfRcpTnvztjqih+X YkJfS2TZuKjAHQP1v1vF7HlkyOco5MjIw/e/+VHw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, xlabai , Berkant Koc , Bernd Schubert , Joanne Koong , Miklos Szeredi , stable@kernel.org Subject: [PATCH 7.1 514/518] fuse-uring: make a fuse_req on SQE commit only findable after memcpy Date: Thu, 16 Jul 2026 15:33:02 +0200 Message-ID: <20260716133059.086073068@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133047.772246337@linuxfoundation.org> References: <20260716133047.772246337@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Bernd Schubert commit 1efd3d474fc0ba74dfd984249bca78807d739812 upstream. Bad userspace might try to trick us and send commit SQEs request unique / commit-id of requests that are not even send to fuse-server (io_uring_cmd_done() not called) yet. fuse_uring_commit_fetch() ends the fuse request when the ring entry has a wrong state, but that could have caused a use-after-free with the memcpy operations in fuse_uring_send_in_task(). In order to avoid such races the call of fuse_uring_add_to_pq() is moved after the copy operations and just before completing the io-uring request - malicious userspace cannot find the request anymore until all prepration work in fuse-client/kernel is completed. This also moves fuse_uring_add_to_pq() a bit up in the code to avoid a forward declaration. Also not with a preparation commit, to make it easier to back port to older kernels. Reported-by: xlabai Reported-by: Berkant Koc Fixes: c090c8abae4b6b ("fuse: Add io-uring sqe commit and fetch support") Cc: stable@kernel.org # 6.14 Signed-off-by: Bernd Schubert Reviewed-by: Joanne Koong Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dev_uring.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) --- a/fs/fuse/dev_uring.c +++ b/fs/fuse/dev_uring.c @@ -714,6 +714,19 @@ static int fuse_uring_prepare_send(struc return err; } +/* Used to find the request on SQE commit */ +static void fuse_uring_add_to_pq(struct fuse_ring_ent *ent) +{ + struct fuse_ring_queue *queue = ent->queue; + struct fuse_pqueue *fpq = &queue->fpq; + unsigned int hash; + struct fuse_req *req = ent->fuse_req; + + req->ring_entry = ent; + hash = fuse_req_hash(req->in.h.unique); + list_move_tail(&req->list, &fpq->processing[hash]); +} + /* * Write data to the ring buffer and send the request to userspace, * userspace will read it @@ -736,6 +749,7 @@ static int fuse_uring_send_next_to_ring( ent->cmd = NULL; ent->state = FRRS_USERSPACE; list_move_tail(&ent->list, &queue->ent_in_userspace); + fuse_uring_add_to_pq(ent); spin_unlock(&queue->lock); io_uring_cmd_done(cmd, 0, issue_flags); @@ -753,19 +767,6 @@ static void fuse_uring_ent_avail(struct ent->state = FRRS_AVAILABLE; } -/* Used to find the request on SQE commit */ -static void fuse_uring_add_to_pq(struct fuse_ring_ent *ent, - struct fuse_req *req) -{ - struct fuse_ring_queue *queue = ent->queue; - struct fuse_pqueue *fpq = &queue->fpq; - unsigned int hash; - - req->ring_entry = ent; - hash = fuse_req_hash(req->in.h.unique); - list_move_tail(&req->list, &fpq->processing[hash]); -} - /* * Assign a fuse queue entry to the given entry */ @@ -783,10 +784,13 @@ static void fuse_uring_add_req_to_ring_e } clear_bit(FR_PENDING, &req->flags); + + /* Until fuse_uring_add_to_pq() the req is not attached to any list */ + list_del_init(&req->list); + ent->fuse_req = req; ent->state = FRRS_FUSE_REQ; list_move_tail(&ent->list, &queue->ent_w_req_queue); - fuse_uring_add_to_pq(ent, req); } /* Fetch the next fuse request if available */ @@ -1207,6 +1211,7 @@ static void fuse_uring_send(struct fuse_ ent->state = FRRS_USERSPACE; list_move_tail(&ent->list, &queue->ent_in_userspace); ent->cmd = NULL; + fuse_uring_add_to_pq(ent); spin_unlock(&queue->lock); io_uring_cmd_done(cmd, ret, issue_flags);