cifs: fix credits leak for SMB1 oplock breaks
Subsystems (2)
cover cifs: fix credits leak for SMB1 oplock breaks
Pavel, List
Here is an update after the email discussions.
This is minimal patch that adds a new flag to specifically indicate that there will not be a response to this PDU and thus we can immediately add the credits back after sending in compound_send_recv()
This flag is only set for SMB1 oplock breaks so this will not affect anything else.
Additionally, we no longer need to check the CIFS_ASYNC_OP flag in compound_send_recv() so we can remove that conditional.
This is the smallest patch which fixes the actual smb1 oplock bug thus we should be able to get it into an rc, and stable.
But we need more but that should wait until the next merge window.
The next steps we should do is:
Remove CIFSSMBNotify() completely and with that also the check for CIFS_ASYNC_OP in SendReceive()
When that is done, the only thing that CIFS_ASYNC_OP does is make sure we do not block in wait_for_credits().
Which means we could rename this flag to CIFS_NON_BLOCKING.
We should also rename CIFS_NO_RSP to CIFS_NO_RSP_BUF to make it more clear that
there will be a response status code but there won't be any or we don't care about any response buffer.
Thus the semantics will become:
* cifs_call_async() : if you want async handling of responses
* CIFS_NO_SRV_RSP: There won't be a response so do not wait for a reply. (only used by SMB1 oplocks)
* CIFS_ASYNC_OP/CIFS_NON_BLOCKING: do not block waiting for available credits.
PATCH 1/1 cifs: fix credits leak for SMB1 oplock breaks
--- fs/cifs/cifsglob.h | 1 + fs/cifs/cifssmb.c | 2 +- fs/cifs/transport.c | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-)
fs/cifs/cifsglob.h +1 -0
@@ -1701,6 +1701,7 @@ static inline bool is_retryable_error(int error)#define CIFS_HAS_CREDITS 0x0400/* already has credits */ #define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ +#define CIFS_NO_SRV_RSP 0x1000/* there is no server response */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001
fs/cifs/cifssmb.c +1 -1
@@ -2540,7 +2540,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,if (lockType ==LOCKING_ANDX_OPLOCK_RELEASE ) {/* no response expected */ - flags =CIFS_ASYNC_OP |CIFS_OBREAK_OP ; + flags =CIFS_NO_SRV_RSP |CIFS_ASYNC_OP |CIFS_OBREAK_OP ; pSMB->Timeout =0 ; }else if (waitFlag) { flags =CIFS_BLOCKING_OP ;/* blocking operation, no timeout */
fs/cifs/transport.c +5 -5
@@ -1073,8 +1073,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,mutex_unlock (&ses->server->srv_mutex); -if (rc <0 ) { -/* Sending failed for some reason - return credits back */ +/* +* If sending failed for some reason or it is an oplock break that we +* will not receive a response to - return credits back +*/ +if (rc <0 || (flags &CIFS_NO_SRV_RSP )) {for (i =0 ; i < num_rqst; i++)add_credits (ses->server, &credits[i], optype); goto out;
@@ -1095,9 +1098,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,smb311_update_preauth_hash (ses, rqst[0 ].rq_iov, rqst[0 ].rq_nvec); -if ((flags &CIFS_TIMEOUT_MASK ) ==CIFS_ASYNC_OP ) - goto out; -for (i =0 ; i < num_rqst; i++) { rc =wait_for_response (ses->server, midQ[i]);if (rc !=0 )
Signature · 1 line
2.13.6
чт, 25 апр. 2019 г. в 18:43, Ronnie Sahlberg <[email protected]>:
Quoted 38 lines
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/cifsglob.h | 1 + fs/cifs/cifssmb.c | 2 +- fs/cifs/transport.c | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-)fs/cifs/cifsglob.h +1
-0@@ -1701,6 +1701,7 @@ static inline bool is_retryable_error(int error)#define CIFS_HAS_CREDITS 0x0400/* already has credits */ #define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ +#define CIFS_NO_SRV_RSP 0x1000/* there is no server response */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001fs/cifs/cifssmb.c +1
-1@@ -2540,7 +2540,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,if (lockType ==LOCKING_ANDX_OPLOCK_RELEASE ) {/* no response expected */ - flags =CIFS_ASYNC_OP |CIFS_OBREAK_OP ; + flags =CIFS_NO_SRV_RSP |CIFS_ASYNC_OP |CIFS_OBREAK_OP ; pSMB->Timeout =0 ; }else if (waitFlag) { flags =CIFS_BLOCKING_OP ;/* blocking operation, no timeout */ fs/cifs/transport.c +0
-0
fs/cifs/transport.c compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · line 1077
Quoted 7 lines
fs/cifs/transport.c +2
-2@@ -1073,8 +1073,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,mutex_unlock (&ses->server->srv_mutex); -if (rc <0 ) { -/* Sending failed for some reason - return credits back */ +/* +* If sending failed for some reason or it is an oplock break that we
probably indicate that it is SMB1 oplock break?
fs/cifs/transport.c compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · line 1082
Quoted 5 lines
fs/cifs/transport.c +3
-0+* will not receive a response to - return credits back +*/ +if (rc <0 || (flags &CIFS_NO_SRV_RSP )) {for (i =0 ; i < num_rqst; i++)add_credits (ses->server, &credits[i], optype);
A no-op callback is still needed to be set here or above for CIFS_NO_SRV_RSP requests. Otherwise we may end up adding credits
twice: here and in the demultiplex thread.
Quoted 12 lines
fs/cifs/transport.c +0
-4goto out;@@ -1095,9 +1098,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,smb311_update_preauth_hash (ses, rqst[0 ].rq_iov, rqst[0 ].rq_nvec); -if ((flags &CIFS_TIMEOUT_MASK ) ==CIFS_ASYNC_OP ) - goto out; -for (i =0 ; i < num_rqst; i++) { rc =wait_for_response (ses->server, midQ[i]);if (rc !=0 ) --
Quoted 2 lines
2.13.6
--
Best regards,
Pavel Shilovsky
ronnie sahlberg
reviewerQuoted 56 lines · Pavel Shilovsky
чт, 25 апр. 2019 г. в 18:43, Ronnie Sahlberg <[email protected]>:
Quoted 38 lines
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/cifsglob.h | 1 + fs/cifs/cifssmb.c | 2 +- fs/cifs/transport.c | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-)fs/cifs/cifsglob.h +1
-0@@ -1701,6 +1701,7 @@ static inline bool is_retryable_error(int error)#define CIFS_HAS_CREDITS 0x0400/* already has credits */ #define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ +#define CIFS_NO_SRV_RSP 0x1000/* there is no server response */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001fs/cifs/cifssmb.c +1
-1@@ -2540,7 +2540,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,if (lockType ==LOCKING_ANDX_OPLOCK_RELEASE ) {/* no response expected */ - flags =CIFS_ASYNC_OP |CIFS_OBREAK_OP ; + flags =CIFS_NO_SRV_RSP |CIFS_ASYNC_OP |CIFS_OBREAK_OP ; pSMB->Timeout =0 ; }else if (waitFlag) { flags =CIFS_BLOCKING_OP ;/* blocking operation, no timeout */ fs/cifs/transport.c +0
-0fs/cifs/transport.c compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · line 1077
Quoted 7 lines
fs/cifs/transport.c +2
-2@@ -1073,8 +1073,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,mutex_unlock (&ses->server->srv_mutex); -if (rc <0 ) { -/* Sending failed for some reason - return credits back */ +/* +* If sending failed for some reason or it is an oplock break that we probably indicate that it is SMB1 oplock break?
fs/cifs/transport.c compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · line 1082
Quoted 5 lines
fs/cifs/transport.c +3
-0+* will not receive a response to - return credits back +*/ +if (rc <0 || (flags &CIFS_NO_SRV_RSP )) {for (i =0 ; i < num_rqst; i++)add_credits (ses->server, &credits[i], optype);
Quoted 3 lines
A no-op callback is still needed to be set here or above for
CIFS_NO_SRV_RSPrequests. Otherwise we may end up adding credits
twice: here and in the demultiplex thread.
I don't think we need one. Since there will never be a reply we will never invoke the callback from the demultiplex thread.
Quoted 20 lines
Quoted 13 lines
fs/cifs/transport.c +0
-4goto out;@@ -1095,9 +1098,6 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,smb311_update_preauth_hash (ses, rqst[0 ].rq_iov, rqst[0 ].rq_nvec); -if ((flags &CIFS_TIMEOUT_MASK ) ==CIFS_ASYNC_OP ) - goto out; -for (i =0 ; i < num_rqst; i++) { rc =wait_for_response (ses->server, midQ[i]);if (rc !=0 ) --Quoted 2 lines
2.13.6
--
Best regards,
Pavel Shilovsky
Pavel Shilovsky
Reviewed-byсб, 27 апр. 2019 г. в 01:08, ronnie sahlberg <[email protected]>:
Quoted 58 lines · Pavel Shilovsky
Quoted 56 lines
чт, 25 апр. 2019 г. в 18:43, Ronnie Sahlberg <[email protected]>:
Quoted 38 lines
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/cifsglob.h | 1 + fs/cifs/cifssmb.c | 2 +- fs/cifs/transport.c | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-)fs/cifs/cifsglob.h +1
-0@@ -1701,6 +1701,7 @@ static inline bool is_retryable_error(int error)#define CIFS_HAS_CREDITS 0x0400/* already has credits */ #define CIFS_TRANSFORM_REQ 0x0800/* transform request before sending */ +#define CIFS_NO_SRV_RSP 0x1000/* there is no server response */ /* Security Flags: indicate type of session setup needed */ #define CIFSSEC_MAY_SIGN 0x00001fs/cifs/cifssmb.c +1
-1@@ -2540,7 +2540,7 @@ CIFSSMBLock(const unsigned int xid, struct cifs_tcon *tcon,if (lockType ==LOCKING_ANDX_OPLOCK_RELEASE ) {/* no response expected */ - flags =CIFS_ASYNC_OP |CIFS_OBREAK_OP ; + flags =CIFS_NO_SRV_RSP |CIFS_ASYNC_OP |CIFS_OBREAK_OP ; pSMB->Timeout =0 ; }else if (waitFlag) { flags =CIFS_BLOCKING_OP ;/* blocking operation, no timeout */ fs/cifs/transport.c +0
-0fs/cifs/transport.c compound_send_recv(const unsigned int xid, struct cifs_ses *ses, · line 1077
Quoted 7 lines
fs/cifs/transport.c +2
-2@@ -1073,8 +1073,11 @@ compound_send_recv(const unsigned int xid, struct cifs_ses *ses,mutex_unlock (&ses->server->srv_mutex); -if (rc <0 ) { -/* Sending failed for some reason - return credits back */ +/* +* If sending failed for some reason or it is an oplock break that we probably indicate that it is SMB1 oplock break?
Quoted 5 lines
fs/cifs/transport.c +3
-0+* will not receive a response to - return credits back +*/ +if (rc <0 || (flags &CIFS_NO_SRV_RSP )) {for (i =0 ; i < num_rqst; i++)add_credits (ses->server, &credits[i], optype);
Quoted 6 lines
Quoted 3 lines
A no-op callback is still needed to be set here or above for
CIFS_NO_SRV_RSPrequests. Otherwise we may end up adding credits
twice: here and in the demultiplex thread.I don't think we need one. Since there will never be a reply we will never invoke the callback from the demultiplex thread.
Ok, this is according to the spec. Having a no-op callback would save us from the server error but it's probably not worth the attention.
I think this patch belongs to stable because the bug exists in 5.0. Could you please add a description together with a stable tag and resend?
--
Best regards,
Pavel Shilovsky
чт, 25 апр. 2019 г. в 18:42, Ronnie Sahlberg <[email protected]>:
Quoted 26 lines
Pavel, List
Here is an update after the email discussions.
This is minimal patch that adds a new flag to specifically indicate that there will not be a response to this PDU and thus we can immediately add the credits back after sending incompound_send_recv()
This flag is only set for SMB1 oplock breaks so this will not affect anything else.Additionally, we no longer need to check the
CIFS_ASYNC_OPflag incompound_send_recv()so we can remove that conditional.This is the smallest patch which fixes the actual smb1 oplock bug thus we should be able to get it into an rc, and stable.
But we need more but that should wait until the next merge window.The next steps we should do is:
RemoveCIFSSMBNotify()completely and with that also the check forCIFS_ASYNC_OPinSendReceive()When that is done, the only thing that
CIFS_ASYNC_OPdoes is make sure we do not block inwait_for_credits().
Which means we could rename this flag toCIFS_NON_BLOCKING.
Quoted 9 lines
We should also rename
CIFS_NO_RSPtoCIFS_NO_RSP_BUFto make it more clear that
there will be a response status code but there won't be any or we don't care about any response buffer.Thus the semantics will become:
*cifs_call_async(): if you want async handling of responses
*CIFS_NO_SRV_RSP: There won't be a response so do not wait for a reply. (only used by SMB1 oplocks)
* CIFS_ASYNC_OP/CIFS_NON_BLOCKING: do not block waiting for available credits.
Agree, sounds like a good plan. Thanks for summarizing!
--
Best regards,
Pavel Shilovsky