Skip to contentSkip to conversation

ksmbd: fix O(N^2) DoS in smb2_lock via unbounded LockCount

PATCH Applied Akif Sait 2 participants 2 messages Apr 18 – Apr 20

Subsystems (2)
lore
Share & tools
lore

Akif Sait

author
#0 lore raw

PATCH 1/1 ksmbd: fix O(N^2) DoS in smb2_lock via unbounded LockCount

smb2_lock() performs O(N^2) conflict detection with no cap on LockCount. Cap lock_count at 64 to prevent CPU exhaustion from a single request.

---
Hi Namjae, Steve,

smb2_lock processes LockCount lock elements using a nested loop where each element checks all previous elements for conflicts. With no cap on LockCount a single authenticated request with LockCount=65535 results in roughly 2.1 billion iterations inside a ksmbd worker thread, pinning the CPU completely. A few concurrent requests hang the host entirely.

Cap lock_count at 64. The MS-SMB2 spec defines Open.LockSequenceArray as exactly 64 entries so 64 is the intended ceiling. No real workload comes close to this in a single request.

Let me know if you need more info or a reproducer.

Thanks,
Akif

 fs/smb/server/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +1 -1
index ee32e61b6d3c..012f0c3585a0 100644
@@ -7492,7 +7492,7 @@ int smb2_lock(struct ksmbd_work *work)
 	lock_ele = req->locks;
 
 	ksmbd_debug(SMB, "lock count is %d\n", lock_count);
-	if (!lock_count) {
+	if (!lock_count || lock_count > 64) {
 		err = -EINVAL;
 		goto out2;
 	}
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 5 lines · Akif Sait

smb2_lock() performs O(N^2) conflict detection with no cap on LockCount. Cap lock_count at 64 to prevent CPU exhaustion from a single request.

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