cifs: Replace a couple of one-element arrays with flexible-array members
Subsystems (2)
PATCH 1/1 cifs: Replace a couple of one-element arrays with flexible-array members
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array member in structs negotiate_req and extended_response, and refactor the rest of the code, accordingly.
Also, make use of the DECLARE_FLEX_ARRAY() helper to declare flexible array member EncryptionKey in union u. This new helper allows for flexible-array members in unions.
Change pointer notation to proper array notation in a call to memcpy() where flexible-array member DialectsArray is being used as destination argument.
Important to mention is that doing a build before/after this patch results in no binary output differences.
This helps with the ongoing efforts to tighten the FORTIFY_SOURCE routines on memcpy() and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
--- fs/cifs/cifspdu.h | 7 ++++--- fs/cifs/cifssmb.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-)
fs/cifs/cifspdu.h +4 -3
@@ -483,7 +483,7 @@ put_bcc(__u16 count, struct smb_hdr *hdr)typedef struct negotiate_req {struct smb_hdr hdr;/* wct = 0 */ __le16 ByteCount; -unsigned char DialectsArray[1 ]; +unsigned char DialectsArray[]; } __attribute__((packed))NEGOTIATE_REQ ;#define MIN_TZ_ADJ (15 * 60)/* minimum grid for timezones in seconds */
@@ -508,13 +508,14 @@ typedef struct negotiate_rsp {__u8 EncryptionKeyLength;__u16 ByteCount;union { -unsigned char EncryptionKey[1 ];/* cap extended security off */ +/* cap extended security off */ + DECLARE_FLEX_ARRAY(unsigned char, EncryptionKey);/* followed by Domain name - if extended security is off */ /* followed by 16 bytes of server GUID */ /* then security blob if cap_extended_security negotiated */ struct {unsigned char GUID[SMB1_CLIENT_GUID_SIZE ]; -unsigned char SecurityBlob[1 ]; +unsigned char SecurityBlob[]; } __attribute__((packed)) extended_response; } __attribute__((packed)) u; } __attribute__((packed)) NEGOTIATE_RSP;
fs/cifs/cifssmb.c +1 -1
@@ -465,7 +465,7 @@ CIFSSMBNegotiate(const unsigned int xid,for (i =0 ; i <CIFS_NUM_PROT ; i++) {size_t len =strlen (protocols[i].name) +1 ; -memcpy (pSMB->DialectsArray+count, protocols[i].name, len); +memcpy (&pSMB->DialectsArray[count], protocols[i].name, len); count += len; }inc_rfc1001_len (pSMB, count);
Signature · 1 line
2.34.1
Quoted 16 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array member in structs
negotiate_reqandextended_response, and refactor the rest of the code, accordingly.Also, make use of the
DECLARE_FLEX_ARRAY()helper to declare flexible array member EncryptionKey in union u. This new helper allows for flexible-array members in unions.Change pointer notation to proper array notation in a call to
memcpy()where flexible-array member DialectsArray is being used as destination argument.Important to mention is that doing a build before/after this patch results in no binary output differences.
Quoted 8 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].
Looks good to me; thanks!
Signature · 1 line
Kees Cook
ronnie sahlberg
reviewerQuoted 10 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array member in structs
negotiate_reqandextended_response, and refactor the rest of the code, accordingly.Also, make use of the
DECLARE_FLEX_ARRAY()helper to declare flexible array member EncryptionKey in union u. This new helper allows for flexible-array members in unions.
Quoted 6 lines
Change pointer notation to proper array notation in a call to
memcpy()where flexible-array member DialectsArray is being used as destination argument.Important to mention is that doing a build before/after this patch results in no binary output differences.
Looks good to me.
Reviewed-by me
Thanks for verifying that it does not change the binary utput.
Quoted 60 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].Signed-off-by Gustavo A. R. Silva <[email protected]>--- fs/cifs/cifspdu.h | 7 ++++--- fs/cifs/cifssmb.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-)fs/cifs/cifspdu.h +4
-3@@ -483,7 +483,7 @@ put_bcc(__u16 count, struct smb_hdr *hdr)typedef struct negotiate_req {struct smb_hdr hdr;/* wct = 0 */ __le16 ByteCount; -unsigned char DialectsArray[1 ]; +unsigned char DialectsArray[]; } __attribute__((packed))NEGOTIATE_REQ ;#define MIN_TZ_ADJ (15 * 60)/* minimum grid for timezones in seconds */ @@ -508,13 +508,14 @@ typedef struct negotiate_rsp {__u8 EncryptionKeyLength;__u16 ByteCount;union { -unsigned char EncryptionKey[1 ];/* cap extended security off */ +/* cap extended security off */ + DECLARE_FLEX_ARRAY(unsigned char, EncryptionKey);/* followed by Domain name - if extended security is off */ /* followed by 16 bytes of server GUID */ /* then security blob if cap_extended_security negotiated */ struct {unsigned char GUID[SMB1_CLIENT_GUID_SIZE ]; -unsigned char SecurityBlob[1 ]; +unsigned char SecurityBlob[]; } __attribute__((packed)) extended_response; } __attribute__((packed)) u; } __attribute__((packed)) NEGOTIATE_RSP;fs/cifs/cifssmb.c +1
-2@@ -465,7 +465,7 @@ CIFSSMBNegotiate(const unsigned int xid,for (i =0 ; i <CIFS_NUM_PROT ; i++) {size_t len =strlen (protocols[i].name) +1 ; -memcpy (pSMB->DialectsArray+count, protocols[i].name, len); +memcpy (&pSMB->DialectsArray[count], protocols[i].name, len); count += len; }inc_rfc1001_len (pSMB, count); --2.34.1
Steve French
Appliedmerged into cifs-2.6.git for-next
Quoted 33 lines · Kees Cook
Quoted 16 lines · Gustavo A. R. Silva
One-element arrays are deprecated, and we are replacing them with flexible array members instead. So, replace one-element arrays with flexible-array member in structs
negotiate_reqandextended_response, and refactor the rest of the code, accordingly.Also, make use of the
DECLARE_FLEX_ARRAY()helper to declare flexible array member EncryptionKey in union u. This new helper allows for flexible-array members in unions.Change pointer notation to proper array notation in a call to
memcpy()where flexible-array member DialectsArray is being used as destination argument.Important to mention is that doing a build before/after this patch results in no binary output differences.
Quoted 8 lines
This helps with the ongoing efforts to tighten the
FORTIFY_SOURCEroutines onmemcpy()and help us make progress towards globally enabling -fstrict-flex-arrays=3 [1].Looks good to me; thanks!
Reviewed-by Kees Cook <[email protected]>--
Kees Cook
Signature · 3 lines
Thanks, Steve