diff mbox series

[3/3] cifs: limit amount of data we request for xattrs to CIFSMaxBufSize

Message ID 20190125010219.4561-4-lsahlber@redhat.com
State New
Headers show
Series patches for querying attributes | expand

Commit Message

Ronnie Sahlberg Jan. 25, 2019, 1:02 a.m. UTC
minus the various headers and blobs that will be part of the reply.

or else we might trigger a session reconnect.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 fs/cifs/smb2ops.c |  6 +++++-
 fs/cifs/smb2pdu.h | 14 ++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

Comments

Pavel Shilovsky Jan. 26, 2019, 2:18 a.m. UTC | #1
чт, 24 янв. 2019 г. в 17:02, Ronnie Sahlberg <lsahlber@redhat.com>:
>
> minus the various headers and blobs that will be part of the reply.
>
> or else we might trigger a session reconnect.
>
> Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
> ---
>  fs/cifs/smb2ops.c |  6 +++++-
>  fs/cifs/smb2pdu.h | 14 ++++++++++++--
>  2 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
> index 34f621fe6dc0..66ae218714bd 100644
> --- a/fs/cifs/smb2ops.c
> +++ b/fs/cifs/smb2ops.c
> @@ -905,7 +905,11 @@ smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
>                                       FILE_READ_EA,
>                                       FILE_FULL_EA_INFORMATION,
>                                       SMB2_O_INFO_FILE,
> -                                     SMB2_MAX_EA_BUF,
> +                                     CIFSMaxBufSize - 4 -
> +                                     SMB2_TRANSFORM_HEADER_SIZE -
> +                                     MAX_SMB2_CREATE_RESPONSE_SIZE -
> +                                     72 - /* query info response */
> +                                     MAX_SMB2_CLOSE_RESPONSE_SIZE,
>                                       &rsp_iov, &buftype, cifs_sb);

The bigbuffer is

>  /* 4 len + 52 transform hdr + 64 hdr + 88 create rsp */

plus

CIFSMaxBufSize.

The 1st part (in /* */) can have 4 + SMB2_TRANSFORM_HEADER_SIZE  + 72
(query response). The 2nd (CIFSMaxBufSize) is for
MAX_SMB2_CREATE_RESPONSE_SIZE, MAX_SMB2_CLOSE_RESPONSE_SIZE + query
resp output payload. It seems that output_len argument should be:

output_len = CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE -
MAX_SMB2_CLOSE_RESPONSE_SIZE.

Correct?

--
Best regards,
Pavel Shilovsky
diff mbox series

Patch

diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 34f621fe6dc0..66ae218714bd 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -905,7 +905,11 @@  smb2_query_eas(const unsigned int xid, struct cifs_tcon *tcon,
 				      FILE_READ_EA,
 				      FILE_FULL_EA_INFORMATION,
 				      SMB2_O_INFO_FILE,
-				      SMB2_MAX_EA_BUF,
+				      CIFSMaxBufSize - 4 -
+				      SMB2_TRANSFORM_HEADER_SIZE -
+				      MAX_SMB2_CREATE_RESPONSE_SIZE -
+				      72 - /* query info response */
+				      MAX_SMB2_CLOSE_RESPONSE_SIZE,
 				      &rsp_iov, &buftype, cifs_sb);
 	if (rc) {
 		/*
diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h
index d8944846e6ae..3b2680497508 100644
--- a/fs/cifs/smb2pdu.h
+++ b/fs/cifs/smb2pdu.h
@@ -85,6 +85,7 @@ 
 #define NUMBER_OF_SMB2_COMMANDS	0x0013
 
 /* 4 len + 52 transform hdr + 64 hdr + 88 create rsp */
+#define SMB2_TRANSFORM_HEADER_SIZE 52
 #define MAX_SMB2_HDR_SIZE 208
 
 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
@@ -648,6 +649,12 @@  struct smb2_create_req {
 	__u8   Buffer[0];
 } __packed;
 
+/*
+ * Maximum size of a SMB2_CREATE response is 64 (smb2 header) +
+ * 88 (fixed part of create response) + 520 (path) + 150 (contexts)
+ */
+#define MAX_SMB2_CREATE_RESPONSE_SIZE 822
+
 struct smb2_create_rsp {
 	struct smb2_sync_hdr sync_hdr;
 	__le16 StructureSize;	/* Must be 89 */
@@ -996,6 +1003,11 @@  struct smb2_close_req {
 	__u64  VolatileFileId; /* opaque endianness */
 } __packed;
 
+/*
+ * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
+ */
+#define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
+
 struct smb2_close_rsp {
 	struct smb2_sync_hdr sync_hdr;
 	__le16 StructureSize; /* 60 */
@@ -1398,8 +1410,6 @@  struct smb2_file_link_info { /* encoding of request for level 11 */
 	char   FileName[0];     /* Name to be assigned to new link */
 } __packed; /* level 11 Set */
 
-#define SMB2_MAX_EA_BUF 65536
-
 struct smb2_file_full_ea_info { /* encoding of response for level 15 */
 	__le32 next_entry_offset;
 	__u8   flags;