lkml.org 
[lkml]   [2026]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] cifssmb: use struct_offset in memcpy calculations
On Thu, Apr 30, 2026 at 3:06 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> 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,
On further review, struct_offset might not be needed.

I believe

struct_offset(pSMBr, hdr.Protocol) == 0

since Protocol is the first member of hdr and hdr is the first member of pSMBr.

Not sure if removal is desired.
> 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
>

\
 
 \ /
  Last update: 2026-05-01 02:48    [W:0.057 / U:29.652 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog