Skip to contentSkip to conversation

smb: client: memcpy() with surrounding object base address

PATCH Applied Kees Cook 3 participants 3 messages Nov 17, 2024

Subsystems (2)
lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 smb: client: memcpy() with surrounding object base address

Like commit f1f047bd7ce0 ("smb: client: Fix -Wstringop-overflow issues"), adjust the memcpy() destination address to be based off the surrounding object rather than based off the 4-byte "Protocol" member. This avoids a build-time warning when compiling under CONFIG_FORTIFY_SOURCE with GCC 15:

In function 'fortify_memcpy_chk',
inlined from 'CIFSSMBSetPathInfo' at ../fs/smb/client/cifssmb.c:5358:2:
../include/linux/fortify-string.h:571:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]

  571 |                         __write_overflow_field(p_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---
Cc: Steve French <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: Paulo Alcantara <[email protected]>
Cc: Ronnie Sahlberg <[email protected]>
Cc: Shyam Prasad N <[email protected]>
Cc: Tom Talpey <[email protected]>
Cc: Bharath SM <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
 fs/smb/client/cifssmb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifssmb.c +1 -1
index b96ca9be5352..026d6b5f23a9 100644
@@ -5337,7 +5337,7 @@ CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
 	param_offset = offsetof(struct smb_com_transaction2_spi_req,
 				InformationLevel) - 4;
 	offset = param_offset + params;
-	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
+	data_offset = (char *)pSMB + offsetof(typeof(*pSMB), hdr.Protocol) + offset;
 	pSMB->ParameterOffset = cpu_to_le16(param_offset);
 	pSMB->DataOffset = cpu_to_le16(offset);
 	pSMB->SetupCount = 1;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Kees Cook

Like commit f1f047bd7ce0 ("smb: client: Fix -Wstringop-overflow issues"), adjust the memcpy() destination address to be based off the surrounding object rather than based off the 4-byte "Protocol" member. This avoids a build-time warning when compiling under CONFIG_FORTIFY_SOURCE with GCC 15:

Quoted 7 lines

In function 'fortify_memcpy_chk',
inlined from 'CIFSSMBSetPathInfo' at ../fs/smb/client/cifssmb.c:5358:2:
../include/linux/fortify-string.h:571:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]

   571 |                         __write_overflow_field(p_size_field, size);
       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks!
-Gustavo

Quoted 27 lines

---
Cc: Steve French <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: Paulo Alcantara <[email protected]>
Cc: Ronnie Sahlberg <[email protected]>
Cc: Shyam Prasad N <[email protected]>
Cc: Tom Talpey <[email protected]>
Cc: Bharath SM <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
  fs/smb/client/cifssmb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifssmb.c +1 -1
index b96ca9be5352..026d6b5f23a9 100644
@@ -5337,7 +5337,7 @@ CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
  	param_offset = offsetof(struct smb_com_transaction2_spi_req,
  				InformationLevel) - 4;
  	offset = param_offset + params;
-	data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
+	data_offset = (char *)pSMB + offsetof(typeof(*pSMB), hdr.Protocol) + offset;
  	pSMB->ParameterOffset = cpu_to_le16(param_offset);
  	pSMB->DataOffset = cpu_to_le16(offset);
  	pSMB->SetupCount = 1;
Applied
#2 lore raw

merged into cifs-2.6.git for-next

Quoted 51 lines · Gustavo A. R. Silva
Quoted 5 lines · Kees Cook

Like commit f1f047bd7ce0 ("smb: client: Fix -Wstringop-overflow issues"), adjust the memcpy() destination address to be based off the surrounding object rather than based off the 4-byte "Protocol" member. This avoids a build-time warning when compiling under CONFIG_FORTIFY_SOURCE with GCC 15:

Quoted 7 lines

In function 'fortify_memcpy_chk',
inlined from 'CIFSSMBSetPathInfo' at ../fs/smb/client/cifssmb.c:5358:2:
../include/linux/fortify-string.h:571:25: error: call to '__write_overflow_field' declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]

   571 |                         __write_overflow_field(p_size_field, size);
       |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Thanks!
-Gustavo

Quoted 27 lines

---
Cc: Steve French <[email protected]>
Cc: "Gustavo A. R. Silva" <[email protected]>
Cc: Paulo Alcantara <[email protected]>
Cc: Ronnie Sahlberg <[email protected]>
Cc: Shyam Prasad N <[email protected]>
Cc: Tom Talpey <[email protected]>
Cc: Bharath SM <[email protected]>
Cc: [email protected]
Cc: [email protected]

---
  fs/smb/client/cifssmb.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/cifssmb.c +1 -1
index b96ca9be5352..026d6b5f23a9 100644
@@ -5337,7 +5337,7 @@ CIFSSMBSetPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
      param_offset = offsetof(struct smb_com_transaction2_spi_req,
                              InformationLevel) - 4;
      offset = param_offset + params;
-     data_offset = (char *) (&pSMB->hdr.Protocol) + offset;
+     data_offset = (char *)pSMB + offsetof(typeof(*pSMB), hdr.Protocol) + offset;
      pSMB->ParameterOffset = cpu_to_le16(param_offset);
      pSMB->DataOffset = cpu_to_le16(offset);
      pSMB->SetupCount = 1;
Signature · 3 lines
Thanks,

Steve