Skip to content

Commit 05946d4

Browse files
vwaxsmfrench
authored andcommitted
cifs: Fix preauth hash corruption
smb311_update_preauth_hash() uses the shash in server->secmech without appropriate locking, and this can lead to sessions corrupting each other's preauth hashes. The following script can easily trigger the problem: #!/bin/sh -e NMOUNTS=10 for i in $(seq $NMOUNTS); mkdir -p /tmp/mnt$i umount /tmp/mnt$i 2>/dev/null || : done while :; do for i in $(seq $NMOUNTS); do mount -t cifs //192.168.0.1/test /tmp/mnt$i -o ... & done wait for i in $(seq $NMOUNTS); do umount /tmp/mnt$i done done Usually within seconds this leads to one or more of the mounts failing with the following errors, and a "Bad SMB2 signature for message" is seen in the server logs: CIFS: VFS: \\192.168.0.1 failed to connect to IPC (rc=-13) CIFS: VFS: cifs_mount failed w/return code = -13 Fix it by holding the server mutex just like in the other places where the shashes are used. Fixes: 8bd68c6 ("CIFS: implement v3.11 preauth integrity") Signed-off-by: Vincent Whitchurch <[email protected]> CC: <[email protected]> Reviewed-by: Aurelien Aptel <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 5171317 commit 05946d4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

fs/cifs/transport.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,12 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
11961196
/*
11971197
* Compounding is never used during session establish.
11981198
*/
1199-
if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP) || (optype & CIFS_SESS_OP))
1199+
if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP) || (optype & CIFS_SESS_OP)) {
1200+
mutex_lock(&server->srv_mutex);
12001201
smb311_update_preauth_hash(ses, rqst[0].rq_iov,
12011202
rqst[0].rq_nvec);
1203+
mutex_unlock(&server->srv_mutex);
1204+
}
12021205

12031206
for (i = 0; i < num_rqst; i++) {
12041207
rc = wait_for_response(server, midQ[i]);
@@ -1266,7 +1269,9 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
12661269
.iov_base = resp_iov[0].iov_base,
12671270
.iov_len = resp_iov[0].iov_len
12681271
};
1272+
mutex_lock(&server->srv_mutex);
12691273
smb311_update_preauth_hash(ses, &iov, 1);
1274+
mutex_unlock(&server->srv_mutex);
12701275
}
12711276

12721277
out:

0 commit comments

Comments
 (0)