Re: [PATCH] ksmbd: unblock a deferred byte-range lock before freeing it
From: Namjae Jeon
Date: Sat Dec 05 2026 - 01:52:42 EST
On Sat, Dec 5, 2026 at 1:30 PM Piyus Kedia <piyus@xxxxxxxxxxx> wrote:
>
> When smb2_lock() has to wait for a byte-range lock, its file_lock is on
> the posix blocker tree while the work sleeps in
> ksmbd_vfs_posix_lock_wait(), and a later request that conflicts with it
> is queued under it, on its flc_blocked_requests list. The holder's
> unlock wakes the waiter but leaves those requests queued on it. If the
> work is then no longer KSMBD_WORK_ACTIVE, smb2_lock() frees the
> file_lock without unblocking it:
>
> kernel BUG at fs/locks.c:312!
> Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
> Workqueue: ksmbd-io handle_ksmbd_work
> RIP: 0010:locks_release_private+0x19a/0x1b0 fs/locks.c:312
> locks_free_lock+0x15/0x30 fs/locks.c:362
> smb2_lock+0x2809/0x2f40 fs/smb/server/smb2pdu.c:11486
> handle_ksmbd_work+0x4d7/0x13d0 fs/smb/server/server.c:223
> process_one_work+0x6f7/0x11a0 kernel/workqueue.c:3497
> worker_thread+0x417/0x7b0 kernel/workqueue.c:3580
> kthread+0x23c/0x290 kernel/kthread.c:436
>
> The work's cancel_fn, smb2_remove_blocked_lock(), does unblock it, but
> a CANCEL can set KSMBD_WORK_CANCELLED while no cancel_fn is installed.
> smb2_cancel() matches a synchronous CANCEL by MessageId on
> conn->requests and calls cancel_fn only if one is set, and smb2_lock()
> clears it in release_async_work() after every wake-up, before it tests
> work->state for the retry; it is not set yet either between a deferring
> vfs_lock_file() and setup_async_work(). A CLOSE after such a CANCEL
> does not call cancel_fn, since set_close_state_blocked_works() calls it
> only for an ACTIVE work. A retry that fails, with -EDEADLK for
> instance, frees the woken file_lock the same way.
>
> Unblock it on each exit that frees it, as do_lock_file_wait() does with
> locks_delete_block() after its wait loop. That wakes the requests
> queued on it, which retry against the locks that remain. For a request
> that never waited, which can take the error exit too, the call finds
> nothing to do.
>
> We found this with a syzkaller-based fuzzing harness driven by an AI tool.
>
> Fixes: e2f34481b24d ("cifsd: add server-side procedures for SMB3")
> Closes: https://lore.kernel.org/linux-cifs/ksmbd-lock-cancel-unblock.20261205@xxxxxxxxxxx/
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Kapil Vaswani <kapil@xxxxxxxxxxxxxxx>
> Signed-off-by: Piyus Kedia <piyus@xxxxxxxxxxx>
Applied it to #ksmbd-for-next.
If you're going to submit a patch, you don't need to send a separate bug report.
Thanks.