Skip to contentSkip to conversation

ksmbd: validate share path for batch oplock reconnects

PATCH In review Sung Byeongchan 3 participants 3 messages Oct 7 – Oct 8

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

PATCH 1/1 ksmbd: validate share path for batch oplock reconnects

Durable reconnects backed by a lease reach ksmbd_validate_name_reconnect(), which rejects reconnecting an open through a different share root. Batch oplock reconnects return immediately after checking the oplock level and therefore skip that validation.

An authenticated client which owns a disconnected durable batch-oplock handle can present its valid reconnect context on another tree. The preserved open is then rebound to that tree even when the client can no longer connect to the source share.

Route successful batch-oplock reconnects through the same name and share-root validation as lease reconnects. Keep invalid oplock levels on the existing error path.

This was found by source review with AI assistance. In two independent boots, a same-owner client was denied a new tree connect to the source share, but reconnected its durable handle on an unrelated read-only share and read the source file. Routing the batch-oplock path through the validator rejected the cross-share reconnect and preserved same-share reconnects.

Fixes c8efcc786146 ("ksmbd: add support for durable handles v1/v2")
Assisted-by LLM
---
 fs/smb/server/oplock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
fs/smb/server/oplock.c +3 -1
index 25ff8408f0ba2..70b7b085d4fdc 100644
@@ -2489,9 +2489,10 @@ int smb2_check_durable_oplock(struct ksmbd_conn *conn,
 		if (opinfo->level != SMB2_OPLOCK_LEVEL_BATCH) {
 			pr_err("oplock level is not equal to SMB2_OPLOCK_LEVEL_BATCH\n");
 			ret = -EBADF;
+			goto out;
 		}
 
-		goto out;
+		goto validate_name;
 	}
 
 	if (memcmp(conn->ClientGUID, fp->client_guid,
@@ -2528,6 +2529,7 @@ int smb2_check_durable_oplock(struct ksmbd_conn *conn,
 		goto out;
 	}
 
+validate_name:
 	if (!ksmbd_inode_pending_delete(fp))
 		ret = ksmbd_validate_name_reconnect(share, fp, name);
 out:
Signature · 1 line
2.43.0
maintainer
#1 lore raw

fs/smb/server/oplock.c int smb2_check_durable_oplock(struct ksmbd_conn *conn, · line 2495

Quoted 9 lines
fs/smb/server/oplock.c +2 -1
@@ -2489,9 +2489,10 @@ int smb2_check_durable_oplock(struct ksmbd_conn *conn,
                if (opinfo->level != SMB2_OPLOCK_LEVEL_BATCH) {
                        pr_err("oplock level is not equal to SMB2_OPLOCK_LEVEL_BATCH\n");
                        ret = -EBADF;
+                       goto out;
                }
 
-               goto out;
+               goto validate_name;

SMB specification(MS-SMB2) explicitly skip path name validation. The filename mismatch check applies only to lease-based opens (opinfo->is_lease in ksmbd). This violates the reconnect semantics.

Quoted 14 lines
fs/smb/server/oplock.c +1 -1
        }
 
        if (memcmp(conn->ClientGUID, fp->client_guid,
@@ -2528,6 +2529,7 @@ int smb2_check_durable_oplock(struct ksmbd_conn *conn,
                goto out;
        }
 
+validate_name:
        if (!ksmbd_inode_pending_delete(fp))
                ret = ksmbd_validate_name_reconnect(share, fp, name);
 out:
--

2.43.0

reviewer
#2 lore raw
Quoted 7 lines · Namjae Jeon
Quoted 7 lines
fs/smb/server/oplock.c +1 -0
@@ -2489,9 +2489,10 @@ int smb2_check_durable_oplock(struct ksmbd_conn *conn,
                 if (opinfo->level != SMB2_OPLOCK_LEVEL_BATCH) {
                         pr_err("oplock level is not equal to SMB2_OPLOCK_LEVEL_BATCH\n");
                         ret = -EBADF;
+                       goto out;
                 }
 
Quoted 5 lines

fs/smb/server/oplock.c int smb2_check_durable_oplock(struct ksmbd_conn *conn, · line 2495

Quoted 2 lines
fs/smb/server/oplock.c +1 -1
-               goto out;
+               goto validate_name;

SMB specification(MS-SMB2) explicitly skip path name validation. The filename mismatch check applies only to lease-based opens (opinfo->is_lease in ksmbd). This violates the reconnect semantics.

Yes, see MS-SMB2 3.3.5.9.7

Signature · 3 lines
ChenXiaoSong <[email protected]>
Chinese Homepage: https://chenxiaosong.com
English Homepage: https://chenxiaosong.com/en