Skip to contentSkip to conversation

ksmbd: fix AsyncId zeroed before use in smb2_lock() cancel response

PATCH Applied Gaël Blivet-Bailly 2 participants 2 messages Jul 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ksmbd: fix AsyncId zeroed before use in smb2_lock() cancel response

From: Gael Blivet <[email protected]>

release_async_work() zeroes work->async_id before the CANCELLED path calls smb2_send_interim_resp(work, STATUS_CANCELLED), which reads work->async_id to build the response's AsyncId field. The cancellation response for a cancelled blocked-lock request is sent with AsyncId=0 instead of the id the client received in the original STATUS_PENDING response for this request.

Checked against every other release_async_work() call site in this
file: smb2_read()/smb2_write() don't send a further async response afterward (their status goes out on the synchronous path instead), and smb2_notify()'s two async paths already transfer the id to a separate struct before releasing, so this reordering is scoped to smb2_lock() only.

Send the STATUS_CANCELLED response while work->async_id is still valid, then release the async work afterward.

Assisted-by Claude:claude-sonnet-5
---
 fs/smb/server/smb2pdu.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
fs/smb/server/smb2pdu.c +9 -6
index 602b60417..d55f8a328 100644
@@ -9307,22 +9307,25 @@ int smb2_lock(struct ksmbd_work *work)
 				spin_unlock(&fp->f_lock);
 
 				list_del(&smb_lock->llist);
-				release_async_work(work);
-
-				if (work->state == KSMBD_WORK_ACTIVE)
-					goto retry;
-
-				locks_free_lock(flock);
 
 				if (work->state == KSMBD_WORK_CANCELLED) {
 					rsp->hdr.Status = STATUS_CANCELLED;
 					kfree(smb_lock);
 					smb2_send_interim_resp(work,
 							STATUS_CANCELLED);
+					release_async_work(work);
+					locks_free_lock(flock);
 					work->send_no_response = 1;
 					goto out;
 				}
 
+				release_async_work(work);
+
+				if (work->state == KSMBD_WORK_ACTIVE)
+					goto retry;
+
+				locks_free_lock(flock);
+
 				rsp->hdr.Status =
 					STATUS_RANGE_NOT_LOCKED;
 				kfree(smb_lock);

base-commit: b0532660f76e08c75143d9d030a9e8c4f2e2bb1e

Signature · 1 line
2.43.0
maintainer Applied
#1 lore raw
Quoted 17 lines · Gaël Blivet-Bailly

From: Gael Blivet <[email protected]>

release_async_work() zeroes work->async_id before the CANCELLED path calls smb2_send_interim_resp(work, STATUS_CANCELLED), which reads work->async_id to build the response's AsyncId field. The cancellation response for a cancelled blocked-lock request is sent with AsyncId=0 instead of the id the client received in the original STATUS_PENDING response for this request.

Checked against every other release_async_work() call site in this
file: smb2_read()/smb2_write() don't send a further async response afterward (their status goes out on the synchronous path instead), and smb2_notify()'s two async paths already transfer the id to a separate struct before releasing, so this reordering is scoped to smb2_lock() only.

Quoted 5 lines

Send the STATUS_CANCELLED response while work->async_id is still valid, then release the async work afterward.

Assisted-by Claude:claude-sonnet-5

Applied it to #ksmbd-for-next-next.
Thanks!