cifs: don't always drop malformed replies on the floor
Subsystems (2)
Looking at this comment in the patch:
+ * FIXME: why 48 bytes?
+ */
+ length = checkSMB(smb_buffer, smb_buffer->Mid, total_read);
+ if (length != 0)
cifs_dump_mem("Bad SMB: ", smb_buffer,
total_read < 48 ? total_read : 48);
got me thinking, if you prefer a longer length that is fine. To
avoid huge log entries, while still dumping the most useful info, the original length dumped was limited. 48 bytes was chosen because it printed 3 lines of 16 to log and thus would include the most important parts of the SMB (past wct). It is large enough to fit a close request and response, although about 10 bytes to small for getting all
of a SMB ReadX request. It would probably be fine to make that 64
bytes if you prefer. If we made it smaller (e.g. 32 instead of 48)
IIRC we wouldn't get wct.
Signature · 3 lines
Thanks, Steve
A message that is not in the archive (sent off-list or not yet received): AANLkTim4p3fT4Sa6aoqqr1sBAFv8a6_7RLYOi2j2fP8s-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 10 lines · On Thu, 3 Feb 2011 23:01:45 -0600 Steve French…
Looking at this comment in the patch:
(quoted diff) +4
-0+ * FIXME: why 48 bytes? + */ + length = checkSMB(smb_buffer, smb_buffer->Mid, total_read); + if (length != 0) cifs_dump_mem("Bad SMB: ", smb_buffer, total_read < 48 ? total_read : 48);
Quoted 9 lines
got me thinking, if you prefer a longer length that is fine. To
avoid huge log entries, while still dumping the most useful info, the original length dumped was limited. 48 bytes was chosen because it printed 3 lines of 16 to log and thus would include the most important parts of the SMB (past wct). It is large enough to fit a close request and response, although about 10 bytes to small for getting all
of a SMB ReadX request. It would probably be fine to make that 64
bytes if you prefer. If we made it smaller (e.g. 32 instead of 48)
IIRC we wouldn't get wct.
The length doesn't much matter to me. What does matter is that this would do a cifs_dump_mem for 48 bytes even when the client received less than 48 bytes. Granted, the buffers are larger than that so I don't think there's any danger of a buffer overrun or anything, but the stuff at the end could just be garbage or zeroed out.
Signature · 1 line
Jeff Layton <[email protected]>
A message that is not in the archive (sent off-list or not yet received): 20110204071659.448565ba-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org
Quoted 23 lines · Jeff Layton
Quoted 10 lines · On Thu, 3 Feb 2011 23:01:45 -0600 Steve French…
Looking at this comment in the patch:
+ * FIXME: why 48 bytes?
+ */
+ length =checkSMB(smb_buffer, smb_buffer->Mid, total_read);
+ if (length != 0)
cifs_dump_mem("Bad SMB: ", smb_buffer, total_read < 48 ? total_read : 48);Quoted 9 lines
got me thinking, if you prefer a longer length that is fine. To avoid huge log entries, while still dumping the most useful info, the original length dumped was limited. 48 bytes was chosen because it printed 3 lines of 16 to log and thus would include the most important parts of the SMB (past wct). It is large enough to fit a close request and response, although about 10 bytes to small for getting all of a SMB ReadX request. It would probably be fine to make that 64 bytes if you prefer. If we made it smaller (e.g. 32 instead of 48) IIRC we wouldn't get wct.
Quoted 5 lines
The length doesn't much matter to me. What does matter is that this would do a
cifs_dump_memfor 48 bytes even when the client received less than 48 bytes. Granted, the buffers are larger than that so I don't think there's any danger of a buffer overrun or anything, but the stuff at the end could just be garbage or zeroed out.
Yes, agreed. I liked that change. It improves
readability of debug info.
Signature · 3 lines
Thanks, Steve
A message that is not in the archive (sent off-list or not yet received): AANLkTiniSV+ys2nnTjiBtncr3QccppbFVXEHWiiUxpXX-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
PATCH 1/1 cifs: don't always drop malformed replies on the floor (try #3)
Slight revision to this patch...use min_t() instead of conditional assignment. Also, remove the FIXME comment and replace it with the explanation that Steve gave earlier.
After receiving a packet, we currently check the header. If it's no good, then we toss it out and continue the loop, leaving the caller waiting on that response.
In cases where the packet has length inconsistencies, but the MID is valid, this leads to unneeded delays. That's especially problematic now that the client waits indefinitely for responses.
Instead, don't immediately discard the packet if checkSMB fails. Try to find a matching mid_q_entry, mark it as having a malformed response and issue the callback.
--- fs/cifs/cifsglob.h | 2 +- fs/cifs/connect.c | 30 ++++++++++++++++++++++++------ fs/cifs/transport.c | 3 +++ 3 files changed, 28 insertions(+), 7 deletions(-)
fs/cifs/cifsglob.h +1 -1
@@ -654,7 +654,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param,#define MID_REQUEST_SUBMITTED 2#define MID_RESPONSE_RECEIVED 4#define MID_RETRY_NEEDED 8/* session closed while this request out */ -#define MID_NO_RESP_NEEDED 0x10 +#define MID_RESPONSE_MALFORMED 0x10/* Types of response buffer returned from SendReceive2 */ #define CIFS_NO_BUFFER 0/* Response buffer not returned */
fs/cifs/connect.c +24 -6
@@ -586,11 +586,20 @@ incomplete_rcv: total_read +=4 ;/* account for rfc1002 hdr */ dump_smb (smb_buffer, total_read); -if (checkSMB (smb_buffer, smb_buffer->Mid, total_read)) { + +/* +* We know that we received enough to get to the MID as we +* checked the pdu_length earlier. Now check to see +* if the rest of the header is OK. We borrow the length +* var for the rest of the loop to avoid a new stack var. +* +* 48 bytes is enough to display the header and a little bit +* into the payload for debugging purposes. +*/ + length =checkSMB (smb_buffer, smb_buffer->Mid, total_read); +if (length !=0 )cifs_dump_mem ("Bad SMB: " , smb_buffer, - total_read <48 ? total_read :48 ); -continue ; - } + min_t(unsigned int, total_read, 48)); mid_entry =NULL ; server->lstrp = jiffies;
@@ -602,7 +611,8 @@ incomplete_rcv:if ((mid_entry->mid == smb_buffer->Mid) && (mid_entry->midState ==MID_REQUEST_SUBMITTED ) && (mid_entry->command == smb_buffer->Command)) { -if (check2ndT2 (smb_buffer,server->maxBuf) >0 ) { +if (length ==0 && +check2ndT2 (smb_buffer,server->maxBuf) >0 ) {/* We have a multipart transact2 resp */ isMultiRsp = true;if (mid_entry->resp_buf) {
@@ -637,7 +647,12 @@ incomplete_rcv: mid_entry->resp_buf = smb_buffer; mid_entry->largeBuf = isLargeBuf; multi_t2_fnd: - mid_entry->midState =MID_RESPONSE_RECEIVED ; +if (length ==0 ) + mid_entry->midState = +MID_RESPONSE_RECEIVED ; +else + mid_entry->midState = +MID_RESPONSE_MALFORMED ;#ifdef CONFIG_CIFS_STATS2 mid_entry->when_received = jiffies;#endif
@@ -658,6 +673,9 @@ multi_t2_fnd:else smallbuf =NULL ; } + }else if (length !=0 ) { +/* response sanity checks failed */ +continue ; }else if (!is_valid_oplock_break (smb_buffer, server) && !isMultiRsp) { cERROR(1, "No task to wake, unknown frame received! "
fs/cifs/transport.c +3 -0
@@ -457,6 +457,9 @@ sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)case MID_RETRY_NEEDED : rc = -EAGAIN ;break ; +case MID_RESPONSE_MALFORMED : + rc = -EIO ; +break ;default :cERROR (1 ,"%s: invalid mid state mid=%d state=%d" , __func__, mid->mid, mid->midState);
Signature · 1 line
1.7.4
A message that is not in the archive (sent off-list or not yet received): 1297343128-29236-1-git-send-email-jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org
Re: [PATCH] cifs: don't always drop malformed replies on the floor (try #3)
merged with minor fix to remove checkpatch warning
Quoted 117 lines · Jeff Layton
Slight revision to this patch...use
min_t()instead of conditional assignment. Also, remove the FIXME comment and replace it with the explanation that Steve gave earlier.After receiving a packet, we currently check the header. If it's no good, then we toss it out and continue the loop, leaving the caller waiting on that response.
In cases where the packet has length inconsistencies, but the MID is valid, this leads to unneeded delays. That's especially problematic now that the client waits indefinitely for responses.
Instead, don't immediately discard the packet if checkSMB fails. Try to find a matching
mid_q_entry, mark it as having a malformed response and issue the callback.Signed-off-by Jeff Layton <[email protected]>---
fs/cifs/cifsglob.h | 2 +-
fs/cifs/connect.c | 30 ++++++++++++++++++++++++------fs/cifs/transport.c| 3 +++3 files changed, 28 insertions(+), 7 deletions(-)fs/cifs/cifsglob.h +1
-1@@ -654,7 +654,7 @@ static inline void free_dfs_info_array(struct dfs_info3_param *param, #define MID_REQUEST_SUBMITTED 2 #define MID_RESPONSE_RECEIVED 4 #define MID_RETRY_NEEDED 8 /* session closed while this request out */ -#define MID_NO_RESP_NEEDED 0x10 +#define MID_RESPONSE_MALFORMED 0x10 /* Types of response buffer returned from SendReceive2 */ #define CIFS_NO_BUFFER 0 /* Response buffer not returned */fs/cifs/connect.c +0
-0@@ -586,11 +586,20 @@ incomplete_rcv:total_read += 4; /* account for rfc1002 hdr */
dump_smb(smb_buffer,
total_read);
- if (checkSMB(smb_buffer, smb_buffer->Mid, total_read)) { +
+ /*
+ * We know that we received enough to get to the MID as we
+ * checked thepdu_lengthearlier. Now check to see
+ * if the rest of the header is OK. We borrow the length
+ * var for the rest of the loop to avoid a new stack var.
+ *
+ * 48 bytes is enough to display the header and a little bit
+ * into the payload for debugging purposes.
+ */
+ length =checkSMB(smb_buffer, smb_buffer->Mid, total_read);
+ if (length != 0)
cifs_dump_mem("Bad SMB: ",smb_buffer,
-total_read< 48 ?total_read: 48);
- continue;
- }
+min_t(unsigned int, total_read, 48));mid_entry = NULL;
server->lstrp = jiffies;fs/cifs/connect.c +0
-0@@ -602,7 +611,8 @@ incomplete_rcv:if ((
mid_entry->mid==smb_buffer->Mid) && (mid_entry->midState==MID_REQUEST_SUBMITTED) && (mid_entry->command==smb_buffer->Command)) {
- if (check2ndT2(smb_buffer,server->maxBuf)> 0) {
+ if (length == 0 &&
+check2ndT2(smb_buffer,server->maxBuf)> 0) { /* We have a multipart transact2 resp */ isMultiRsp = true;
if (mid_entry->resp_buf) {fs/cifs/connect.c +0
-0@@ -637,7 +647,12 @@ incomplete_rcv: mid_entry->resp_buf = smb_buffer; mid_entry->largeBuf = isLargeBuf;multi_t2_fnd:
-mid_entry->midState=MID_RESPONSE_RECEIVED;
+ if (length == 0)
+mid_entry->midState=
+MID_RESPONSE_RECEIVED;
+ else
+mid_entry->midState=
+MID_RESPONSE_MALFORMED; #ifdefCONFIG_CIFS_STATS2
mid_entry->when_received = jiffies; #endiffs/cifs/connect.c +0
-0@@ -658,6 +673,9 @@ multi_t2_fnd:else
smallbuf = NULL;
}
+ } else if (length != 0) {
+ /* response sanity checks failed */
+ continue;
} else if (!is_valid_oplock_break(smb_buffer, server) && !isMultiRsp) {
cERROR(1, "No task to wake, unknown frame received! "fs/cifs/transport.c +0
-0@@ -457,6 +457,9 @@ sync_mid_result(struct mid_q_entry *mid, struct TCP_Server_Info *server)case
MID_RETRY_NEEDED:
rc =-EAGAIN;
break;
+ caseMID_RESPONSE_MALFORMED:
+ rc =-EIO;
+ break;
default:
cERROR(1, "%s: invalid mid state mid=%d state=%d",__func__,mid->mid,mid->midState);
--
1.7.4
Signature · 3 lines
Thanks, Steve