Linux CIFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] cifssmb: use struct_offset in memcpy calculations
@ 2026-04-30 22:06 Rosen Penev
  2026-05-01  0:09 ` Steve French
  2026-05-01  0:47 ` Rosen Penev
  0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2026-04-30 22:06 UTC (permalink / raw)
  To: linux-cifs
  Cc: Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N,
	Tom Talpey, Bharath SM,
	moderated list:COMMON INTERNET FILE SYSTEM CLIENT (CIFS and SMB3),
	open list

It seems W=1/FORTIFY_SOURCE is getting confused about the math here.

Use struct_offset to point FORTIFY_SOURCE to the correct place.

Remove response_data variables and directly apply to memcpy. Simpler
and avoids excess casting.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 fs/smb/client/cifssmb.c | 40 +++++++++++++---------------------------
 1 file changed, 13 insertions(+), 27 deletions(-)

diff --git a/fs/smb/client/cifssmb.c b/fs/smb/client/cifssmb.c
index 3990a9012264..8598cec5ebbd 100644
--- a/fs/smb/client/cifssmb.c
+++ b/fs/smb/client/cifssmb.c
@@ -4090,9 +4090,9 @@ CIFSSMBQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
 				      get_bcc(&pSMBr->hdr), 40);
 		else if (pFindData) {
 			__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-			memcpy((char *) pFindData,
-			       (char *) &pSMBr->hdr.Protocol +
-			       data_offset, sizeof(FILE_ALL_INFO));
+			memcpy(pFindData,
+			       (char *)pSMBr + struct_offset(pSMBr, hdr.Protocol) + data_offset,
+			       sizeof(FILE_ALL_INFO));
 		} else
 		    rc = -ENOMEM;
 	}
@@ -4264,9 +4264,8 @@ CIFSSMBUnixQFileInfo(const unsigned int xid, struct cifs_tcon *tcon,
 				      get_bcc(&pSMBr->hdr), sizeof(FILE_UNIX_BASIC_INFO));
 		} else {
 			__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-			memcpy((char *) pFindData,
-			       (char *) &pSMBr->hdr.Protocol +
-			       data_offset,
+			memcpy(pFindData,
+			       (char *)pSMBr + struct_offset(pSMBr, hdr.Protocol) + data_offset,
 			       sizeof(FILE_UNIX_BASIC_INFO));
 		}
 	}
@@ -4349,9 +4348,8 @@ CIFSSMBUnixQPathInfo(const unsigned int xid, struct cifs_tcon *tcon,
 				      get_bcc(&pSMBr->hdr), sizeof(FILE_UNIX_BASIC_INFO));
 		} else {
 			__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-			memcpy((char *) pFindData,
-			       (char *) &pSMBr->hdr.Protocol +
-			       data_offset,
+			memcpy(pFindData,
+			       (char *)pSMBr + struct_offset(pSMBr, hdr.Protocol) + data_offset,
 			       sizeof(FILE_UNIX_BASIC_INFO));
 		}
 	}
@@ -5079,7 +5077,6 @@ CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon)
 /* level 0x105  SMB_QUERY_FILE_SYSTEM_INFO */
 	TRANSACTION2_QFSI_REQ *pSMB = NULL;
 	TRANSACTION2_QFSI_RSP *pSMBr = NULL;
-	FILE_SYSTEM_ATTRIBUTE_INFO *response_data;
 	unsigned int in_len;
 	int rc = 0;
 	int bytes_returned = 0;
@@ -5130,11 +5127,8 @@ CIFSSMBQFSAttributeInfo(const unsigned int xid, struct cifs_tcon *tcon)
 				      get_bcc(&pSMBr->hdr), 13);
 		} else {
 			__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-			response_data =
-			    (FILE_SYSTEM_ATTRIBUTE_INFO
-			     *) (((char *) &pSMBr->hdr.Protocol) +
-				 data_offset);
-			memcpy(&tcon->fsAttrInfo, response_data,
+			memcpy(&tcon->fsAttrInfo,
+			       (char *)pSMBr + struct_offset(pSMBr, hdr.Protocol) + data_offset,
 			       sizeof(FILE_SYSTEM_ATTRIBUTE_INFO));
 		}
 	}
@@ -5152,7 +5146,6 @@ CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon)
 /* level 0x104 SMB_QUERY_FILE_SYSTEM_INFO */
 	TRANSACTION2_QFSI_REQ *pSMB = NULL;
 	TRANSACTION2_QFSI_RSP *pSMBr = NULL;
-	FILE_SYSTEM_DEVICE_INFO *response_data;
 	unsigned int in_len;
 	int rc = 0;
 	int bytes_returned = 0;
@@ -5205,11 +5198,8 @@ CIFSSMBQFSDeviceInfo(const unsigned int xid, struct cifs_tcon *tcon)
 				      sizeof(FILE_SYSTEM_DEVICE_INFO));
 		else {
 			__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-			response_data =
-			    (FILE_SYSTEM_DEVICE_INFO *)
-				(((char *) &pSMBr->hdr.Protocol) +
-				 data_offset);
-			memcpy(&tcon->fsDevInfo, response_data,
+			memcpy(&tcon->fsDevInfo,
+			       (char *)pSMBr + struct_offset(pSMBr, hdr.Protocol) + data_offset,
 			       sizeof(FILE_SYSTEM_DEVICE_INFO));
 		}
 	}
@@ -5227,7 +5217,6 @@ CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon)
 /* level 0x200  SMB_QUERY_CIFS_UNIX_INFO */
 	TRANSACTION2_QFSI_REQ *pSMB = NULL;
 	TRANSACTION2_QFSI_RSP *pSMBr = NULL;
-	FILE_SYSTEM_UNIX_INFO *response_data;
 	unsigned int in_len;
 	int rc = 0;
 	int bytes_returned = 0;
@@ -5277,11 +5266,8 @@ CIFSSMBQFSUnixInfo(const unsigned int xid, struct cifs_tcon *tcon)
 				      get_bcc(&pSMBr->hdr), 13);
 		} else {
 			__u16 data_offset = le16_to_cpu(pSMBr->t2.DataOffset);
-			response_data =
-			    (FILE_SYSTEM_UNIX_INFO
-			     *) (((char *) &pSMBr->hdr.Protocol) +
-				 data_offset);
-			memcpy(&tcon->fsUnixInfo, response_data,
+			memcpy(&tcon->fsUnixInfo,
+			       (char *)pSMBr + struct_offset(pSMBr, hdr.Protocol) + data_offset,
 			       sizeof(FILE_SYSTEM_UNIX_INFO));
 		}
 	}
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-01  0:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 22:06 [PATCH] cifssmb: use struct_offset in memcpy calculations Rosen Penev
2026-05-01  0:09 ` Steve French
2026-05-01  0:27   ` Rosen Penev
2026-05-01  0:47 ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox