ksmbd: fix breaking_cnt leak on early return in oplock_break()
Subsystems (3)
PATCH 1/1 ksmbd: fix breaking_cnt leak on early return in oplock_break()
For leases, oplock_break() increments breaking_cnt before calling oplock_break_pending(), and returns early when the pending check reports nothing to break: the level is already at or below the requested level and, for a lease, the state is not HANDLE|READ caching. Neither early return decrements the counter, and wait_lease_breaking(), the only place that force-clears it, sits below those returns, so breaking_cnt stays elevated for the life of the open.
A stuck breaking_cnt makes same_client_has_lease() skip lease upgrades forever, and every subsequent same-client CREATE on that lease is answered with SMB2_LEASE_FLAG_BREAK_IN_PROGRESS, so the client never resumes caching.
The ordering dates back to the original SMB3 server code, but the early return became routinely reachable for leases already broken to NONE when smb_break_all_levII_oplock() stopped filtering out non-level-II leases in 17699905a381, "ksmbd: fix lease break and ack state handling".
Move the increment below the pending check so the early returns cannot strand the counter. This is the minimal equivalent of the reorder that mainline made in b0148dc5625d, "ksmbd: serialize oplock close with pending break ownership".
--- fs/smb/server/oplock.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/smb/server/oplock.c +6 -1
@@ -903,10 +903,15 @@ static int oplock_break(struct oplock_info *brk_opinfo, int req_op_level,if (brk_opinfo->is_lease) {struct lease *lease = brk_opinfo->o_lease; -atomic_inc (&brk_opinfo->breaking_cnt); err =oplock_break_pending (brk_opinfo, req_op_level);if (err)return err <0 ? err :0 ; +/* +* Increment breaking_cnt only after the pending check +* above: its early returns would otherwise strand the +* counter, as wait_lease_breaking() is never reached. +*/ +atomic_inc (&brk_opinfo->breaking_cnt);if (brk_opinfo->open_trunc) {/*
Signature · 1 line
2.39.3
Sasha Levin
maintainerQuoted 3 lines
For leases,
oplock_break()incrementsbreaking_cntbefore callingoplock_break_pending(), and returns early when the pending check reports nothing to break
This is a stable-only fix, so I need an ack from Namjae Jeon on the list before queueing it. 6.18 and 6.12 have the identical bug and this patch applies there unchanged, so once it is acked I will queue it for 6.18, 6.12 and 6.6 together.
Signature · 2 lines
Thanks, Sasha
Quoted 8 lines · Sasha Levin
Quoted 4 lines
For leases,
oplock_break()incrementsbreaking_cntbefore callingoplock_break_pending(), and returns early when the pending check reports nothing to breakThis is a stable-only fix, so I need an ack from Namjae Jeon on the list before queueing it. 6.18 and 6.12 have the identical bug and this patch applies there unchanged, so once it is acked I will queue it for 6.18, 6.12 and 6.6 together.
I agree this fix should be queued for all three stable branches.
Thanks!
Quoted 4 lines
--
Thanks,
Sasha
Sasha Levin
maintainerQuoted 1 line · Namjae Jeon
I agree this
Thanks Namjae. Queued for 6.18, 6.12 and 6.6.
Signature · 2 lines
Thanks, Sasha