cifs: log session id when a matching ses is not found
Subsystems (2)
PATCH 1/3 cifs: log session id when a matching ses is not found
We do not log the session id in crypt_setup when a matching session is not found. Printing the session id helps debugging here. This change does just that.
--- fs/smb/client/smb2ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/smb/client/smb2ops.c +2 -2
@@ -4439,8 +4439,8 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, rc =smb2_get_enc_key (server,le64_to_cpu (tr_hdr->SessionId), enc, key);if (rc) { -cifs_server_dbg (VFS ,"%s: Could not get %scryption key\n" , __func__, - enc ?"en" :"de" ); +cifs_server_dbg (VFS ,"%s: Could not get %scryption key. sid: 0x%llx\n" , __func__, + enc ?"en" :"de" ,le64_to_cpu (tr_hdr->SessionId));return rc; }
Signature · 1 line
2.34.1
PATCH 2/3 cifs: prevent use-after-free by freeing the cfile later
In smb2_compound_op we have a possible use-after-free which can cause hard to debug problems later on.
This was revealed during stress testing with KASAN enabled kernel. Fixing it by moving the cfile free call to a few lines below, after the usage.
--- fs/smb/client/smb2inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2inode.c +3 -3
@@ -398,9 +398,6 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, rsp_iov); finished: -if (cfile) -cifsFileInfo_put (cfile); -SMB2_open_free (&rqst[0 ]);if (rc == -EREMCHG ) {pr_warn_once ("server share %s deleted\n" , tcon->tree_name);
@@ -529,6 +526,9 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon,break ; } +if (cfile) +cifsFileInfo_put (cfile); +if (rc && err_iov && err_buftype) {memcpy (err_iov, rsp_iov,3 *sizeof (*err_iov));memcpy (err_buftype, resp_buftype,3 *sizeof (*err_buftype));
Signature · 1 line
2.34.1
PATCH 3/3 cifs: do all necessary checks for credits within or before locking
In reply to Shyam Prasad NAll the server credits and in-flight info is protected by req_lock. Once the req_lock is held, and we've determined that we have enough credits to continue, this lock cannot be dropped till we've made the changes to credits and in-flight count.
However, we used to drop the lock in order to avoid deadlock with the recent srv_lock. This could cause the checks already made to be invalidated.
Fixed it by moving the server status check to before locking req_lock.
--- fs/smb/client/smb2ops.c | 19 ++++++++++--------- fs/smb/client/transport.c | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-)
fs/smb/client/smb2ops.c +10 -9
@@ -211,6 +211,16 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,spin_lock (&server->req_lock);while (1 ) { +spin_unlock (&server->req_lock); + +spin_lock (&server->srv_lock); +if (server->tcpStatus == CifsExiting) { +spin_unlock (&server->srv_lock); +return -ENOENT ; + } +spin_unlock (&server->srv_lock); + +spin_lock (&server->req_lock);if (server->credits <=0 ) {spin_unlock (&server->req_lock);cifs_num_waiters_inc (server);
@@ -221,15 +231,6 @@ smb2_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,return rc;spin_lock (&server->req_lock); }else { -spin_unlock (&server->req_lock); -spin_lock (&server->srv_lock); -if (server->tcpStatus == CifsExiting) { -spin_unlock (&server->srv_lock); -return -ENOENT ; - } -spin_unlock (&server->srv_lock); - -spin_lock (&server->req_lock); scredits = server->credits;/* can deadlock with reopen */ if (scredits <=8 ) {
fs/smb/client/transport.c +10 -10
@@ -522,6 +522,16 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits, }while (1 ) { +spin_unlock (&server->req_lock); + +spin_lock (&server->srv_lock); +if (server->tcpStatus == CifsExiting) { +spin_unlock (&server->srv_lock); +return -ENOENT ; + } +spin_unlock (&server->srv_lock); + +spin_lock (&server->req_lock);if (*credits < num_credits) { scredits = *credits;spin_unlock (&server->req_lock);
@@ -547,15 +557,6 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,return -ERESTARTSYS ;spin_lock (&server->req_lock); }else { -spin_unlock (&server->req_lock); - -spin_lock (&server->srv_lock); -if (server->tcpStatus == CifsExiting) { -spin_unlock (&server->srv_lock); -return -ENOENT ; - } -spin_unlock (&server->srv_lock); -/* * For normal commands, reserve the last MAX_COMPOUND * credits to compound requests.
@@ -569,7 +570,6 @@ wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,* for servers that are slow to hand out credits on * new sessions. */ -spin_lock (&server->req_lock);if (!optype && num_credits ==1 && server->in_flight >2 *MAX_COMPOUND && *credits <=MAX_COMPOUND ) {
Signature · 1 line
2.34.1
Quoted 14 lines · Shyam Prasad N
We do not log the session id in
crypt_setupwhen a matching session is not found. Printing the session id helps debugging here. This change does just that.Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/smb2ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/smb/client/smb2ops.c +0
-0
fs/smb/client/smb2ops.c crypt_message(struct TCP_Server_Info *server, int num_rqst, · line 4443
Quoted 7 lines
fs/smb/client/smb2ops.c +2
-2@@ -4439,8 +4439,8 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, rc =smb2_get_enc_key (server,le64_to_cpu (tr_hdr->SessionId), enc, key);if (rc) { -cifs_server_dbg (VFS ,"%s: Could not get %scryption key\n" , __func__, - enc ?"en" :"de" ); +cifs_server_dbg (VFS ,"%s: Could not get %scryption key. sid: 0x%llx\n" , __func__, + enc ?"en" :"de" ,le64_to_cpu (tr_hdr->SessionId));
I think this should be FYI rather than VFS as it is usually fine to fail on smb2_get_enc_key() while the session was reconnected, since the I/O would be retried later and the current value of @tr_hdr->SessionId would no longer match any existing session ids. I have seen such messages while running reconnect tests with 'seal' mount option.
Other than that, looks good.
Re: [PATCH 2/3] cifs: prevent use-after-free by freeing the cfile later
In reply to Shyam Prasad NQuoted 7 lines · Shyam Prasad N
In
smb2_compound_opwe have a possible use-after-free which can cause hard to debug problems later on.This was revealed during stress testing with KASAN enabled kernel. Fixing it by moving the cfile free call to a few lines below, after the usage.
Quoted 6 lines
Fixes 76894f3e2f71 ("cifs: improve symlink handling for smb2+")CC Paulo Alcantara (SUSE) <[email protected]>Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/smb2inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Steve French
AppliedRe: [PATCH 2/3] cifs: prevent use-after-free by freeing the cfile later
merged into cifs-2.6.git for-next
Quoted 18 lines · Paulo Alcantara
Quoted 7 lines · Shyam Prasad N
In
smb2_compound_opwe have a possible use-after-free which can cause hard to debug problems later on.This was revealed during stress testing with KASAN enabled kernel. Fixing it by moving the cfile free call to a few lines below, after the usage.
Quoted 6 lines
Fixes 76894f3e2f71 ("cifs: improve symlink handling for smb2+")CC Paulo Alcantara (SUSE) <[email protected]>Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/smb2inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)Reviewed-by Paulo Alcantara (SUSE) <[email protected]>
Signature · 3 lines
Thanks, Steve
Quoted 31 lines · Paulo Alcantara
Quoted 14 lines · Shyam Prasad N
We do not log the session id in
crypt_setupwhen a matching session is not found. Printing the session id helps debugging here. This change does just that.Signed-off-by Shyam Prasad N <[email protected]>--- fs/smb/client/smb2ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/smb/client/smb2ops.c +0
-0fs/smb/client/smb2ops.c crypt_message(struct TCP_Server_Info *server, int num_rqst, · line 4443
Quoted 7 lines
fs/smb/client/smb2ops.c +2
-2@@ -4439,8 +4439,8 @@ crypt_message(struct TCP_Server_Info *server, int num_rqst, rc =smb2_get_enc_key (server,le64_to_cpu (tr_hdr->SessionId), enc, key);if (rc) { -cifs_server_dbg (VFS ,"%s: Could not get %scryption key\n" , __func__, - enc ?"en" :"de" ); +cifs_server_dbg (VFS ,"%s: Could not get %scryption key. sid: 0x%llx\n" , __func__, + enc ?"en" :"de" ,le64_to_cpu (tr_hdr->SessionId));I think this should be FYI rather than VFS as it is usually fine to fail on
smb2_get_enc_key()while the session was reconnected, since the I/O would be retried later and the current value of @tr_hdr->SessionId would no longer match any existing session ids. I have seen such messages while running reconnect tests with 'seal' mount option.
Quoted 1 line
Other than that, looks good.
Ack Paulo.
I'll send an updated patch after reducing this to FYI log.
Signature · 2 lines
Regards, Shyam