* [PATCH v8 0/1] smb: move duplicate definitions to common header file @ 2025-11-16 6:52 chenxiaosong.chenxiaosong 2025-11-16 6:52 ` [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h chenxiaosong.chenxiaosong 0 siblings, 1 reply; 7+ messages in thread From: chenxiaosong.chenxiaosong @ 2025-11-16 6:52 UTC (permalink / raw) To: sfrench, smfrench, linkinjeon, linkinjeon, christophe.jaillet Cc: linux-cifs, linux-kernel, chenxiaosong, ChenXiaoSong From: ChenXiaoSong <chenxiaosong@kylinos.cn> In order to maintain the code more easily, move some duplicate definitions to common header file. Add some MS documentation references for macro and struct definitions. I have tested all patches using xfstests and smbtorture, and no additional test failures were observed in the results. The detailed test results can be found in https://chenxiaosong.com/en/smb-test-20251116.html v3: https://lore.kernel.org/all/20251014071917.3004573-1-chenxiaosong.chenxiaosong@linux.dev/ The following patches from v3 have already been merged into the mainline: - d877470b5991 smb: move some duplicate definitions to common/cifsglob.h - 379510a815cb smb/server: fix possible refcount leak in smb2_sess_setup() - 6fced056d2cc smb/server: fix possible memory leak in smb2_read() v4: https://lore.kernel.org/all/20251027071316.3468472-1-chenxiaosong.chenxiaosong@linux.dev/ v5: https://lore.kernel.org/all/20251102073059.3681026-1-chenxiaosong.chenxiaosong@linux.dev/ v7: https://lore.kernel.org/all/20251113133252.145867-1-chenxiaosong.chenxiaosong@linux.dev/ The following patches from v4 v5 v7 have been applied to the ksmbd-for-next-next branch: https://git.samba.org/?p=ksmbd.git;a=shortlog;h=refs/heads/ksmbd-for-next-next - smb: move create_durable_reconn to common/smb2pdu.h - smb: fix some warnings reported by scripts/checkpatch.pl - smb: do some cleanups - smb: move FILE_SYSTEM_SIZE_INFO to common/fscc.h - smb: move some duplicate struct definitions to common/fscc.h - smb: move list of FileSystemAttributes to common/fscc.h - smb: move SMB_NEGOTIATE_REQ to common/smb2pdu.h - smb: move some duplicate definitions to common/smb2pdu.h - smb: move create_durable_rsp_v2 to common/smb2pdu.h - smb: move create_durable_handle_reconnect_v2 to common/smb2pdu.h - smb: move create_durable_req_v2 to common/smb2pdu.h - smb: move MAX_CIFS_SMALL_BUFFER_SIZE to common/smbglob.h - smb/client: fix CAP_BULK_TRANSFER value - smb: move resume_key_ioctl_rsp to common/smb2pdu.h - smb: move copychunk definitions to common/smb2pdu.h - smb: move smb_sockaddr_in and smb_sockaddr_in6 to common/smb2pdu.h - smb: move SMB1_PROTO_NUMBER to common/smbglob.h - smb: move get_rfc1002_len() to common/smbglob.h - smb: move smb_version_values to common/smbglob.h - smb: rename common/cifsglob.h to common/smbglob.h v7 -> v8: - Introduce MAX_FS_NAME_LEN - max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN - min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) ChenXiaoSong (1): smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h fs/smb/client/cifspdu.h | 10 ---------- fs/smb/client/smb2pdu.c | 4 ++-- fs/smb/common/fscc.h | 9 +++++++++ fs/smb/server/smb2pdu.c | 6 +++--- fs/smb/server/smb_common.h | 7 ------- 5 files changed, 14 insertions(+), 22 deletions(-) -- 2.43.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h 2025-11-16 6:52 [PATCH v8 0/1] smb: move duplicate definitions to common header file chenxiaosong.chenxiaosong @ 2025-11-16 6:52 ` chenxiaosong.chenxiaosong 2025-11-16 23:00 ` Namjae Jeon 0 siblings, 1 reply; 7+ messages in thread From: chenxiaosong.chenxiaosong @ 2025-11-16 6:52 UTC (permalink / raw) To: sfrench, smfrench, linkinjeon, linkinjeon, christophe.jaillet Cc: linux-cifs, linux-kernel, chenxiaosong, ChenXiaoSong From: ChenXiaoSong <chenxiaosong@kylinos.cn> Modify the following places: - struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO - Remove MIN_FS_ATTR_INFO_SIZE definition - Introduce MAX_FS_NAME_LEN - max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN - min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file. Suggested-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> --- fs/smb/client/cifspdu.h | 10 ---------- fs/smb/client/smb2pdu.c | 4 ++-- fs/smb/common/fscc.h | 9 +++++++++ fs/smb/server/smb2pdu.c | 6 +++--- fs/smb/server/smb_common.h | 7 ------- 5 files changed, 14 insertions(+), 22 deletions(-) diff --git a/fs/smb/client/cifspdu.h b/fs/smb/client/cifspdu.h index d84e10b1477f..49f35cb3cf2e 100644 --- a/fs/smb/client/cifspdu.h +++ b/fs/smb/client/cifspdu.h @@ -2068,16 +2068,6 @@ typedef struct { #define FILE_PORTABLE_DEVICE 0x00004000 #define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000 -/* minimum includes first three fields, and empty FS Name */ -#define MIN_FS_ATTR_INFO_SIZE 12 - -typedef struct { - __le32 Attributes; - __le32 MaxPathNameComponentLength; - __le32 FileSystemNameLen; - char FileSystemName[52]; /* do not have to save this - get subset? */ -} __attribute__((packed)) FILE_SYSTEM_ATTRIBUTE_INFO; - /******************************************************************************/ /* QueryFileInfo/QueryPathinfo (also for SetPath/SetFile) data buffer formats */ /******************************************************************************/ diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c index 032b4b037f07..1f40458e2156 100644 --- a/fs/smb/client/smb2pdu.c +++ b/fs/smb/client/smb2pdu.c @@ -5981,8 +5981,8 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon, max_len = sizeof(FILE_SYSTEM_DEVICE_INFO); min_len = sizeof(FILE_SYSTEM_DEVICE_INFO); } else if (level == FS_ATTRIBUTE_INFORMATION) { - max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO); - min_len = MIN_FS_ATTR_INFO_SIZE; + max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN; + min_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO); } else if (level == FS_SECTOR_SIZE_INFORMATION) { max_len = sizeof(struct smb3_fs_ss_info); min_len = sizeof(struct smb3_fs_ss_info); diff --git a/fs/smb/common/fscc.h b/fs/smb/common/fscc.h index a0580a772a41..226dcdba0a09 100644 --- a/fs/smb/common/fscc.h +++ b/fs/smb/common/fscc.h @@ -94,6 +94,15 @@ struct smb2_file_network_open_info { __le32 Reserved; } __packed; /* level 34 Query also similar returned in close rsp and open rsp */ +/* See FS-FSCC 2.5.1 */ +#define MAX_FS_NAME_LEN 52 +typedef struct { + __le32 Attributes; + __le32 MaxPathNameComponentLength; + __le32 FileSystemNameLen; + __le16 FileSystemName[]; /* do not have to save this - get subset? */ +} __packed FILE_SYSTEM_ATTRIBUTE_INFO; + /* List of FileSystemAttributes - see MS-FSCC 2.5.1 */ #define FILE_SUPPORTS_SPARSE_VDL 0x10000000 /* faster nonsparse extend */ #define FILE_SUPPORTS_BLOCK_REFCOUNTING 0x08000000 /* allow ioctl dup extents */ diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index c71f156cc64a..1c8935f61150 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -5492,10 +5492,10 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work, } case FS_ATTRIBUTE_INFORMATION: { - struct filesystem_attribute_info *info; + FILE_SYSTEM_ATTRIBUTE_INFO *info; size_t sz; - info = (struct filesystem_attribute_info *)rsp->Buffer; + info = (FILE_SYSTEM_ATTRIBUTE_INFO *)rsp->Buffer; info->Attributes = cpu_to_le32(FILE_SUPPORTS_OBJECT_IDS | FILE_PERSISTENT_ACLS | FILE_UNICODE_ON_DISK | @@ -5514,7 +5514,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work, "NTFS", PATH_MAX, conn->local_nls, 0); len = len * 2; info->FileSystemNameLen = cpu_to_le32(len); - sz = sizeof(struct filesystem_attribute_info) + len; + sz = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + len; rsp->OutputBufferLength = cpu_to_le32(sz); break; } diff --git a/fs/smb/server/smb_common.h b/fs/smb/server/smb_common.h index 4dd573c5f0b2..6c1607b43eb3 100644 --- a/fs/smb/server/smb_common.h +++ b/fs/smb/server/smb_common.h @@ -90,13 +90,6 @@ struct smb_negotiate_rsp { __le16 ByteCount; } __packed; -struct filesystem_attribute_info { - __le32 Attributes; - __le32 MaxPathNameComponentLength; - __le32 FileSystemNameLen; - __le16 FileSystemName[]; /* do not have to save this - get subset? */ -} __packed; - struct filesystem_vol_info { __le64 VolumeCreationTime; __le32 SerialNumber; -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h 2025-11-16 6:52 ` [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h chenxiaosong.chenxiaosong @ 2025-11-16 23:00 ` Namjae Jeon 2025-11-16 23:47 ` ChenXiaoSong ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Namjae Jeon @ 2025-11-16 23:00 UTC (permalink / raw) To: chenxiaosong.chenxiaosong Cc: sfrench, smfrench, linkinjeon, christophe.jaillet, linux-cifs, linux-kernel, chenxiaosong, ChenXiaoSong On Sun, Nov 16, 2025 at 3:53 PM <chenxiaosong.chenxiaosong@linux.dev> wrote: > > From: ChenXiaoSong <chenxiaosong@kylinos.cn> > > Modify the following places: > > - struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO > - Remove MIN_FS_ATTR_INFO_SIZE definition > - Introduce MAX_FS_NAME_LEN > - max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN > - min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) > > Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file. > > Suggested-by: Namjae Jeon <linkinjeon@kernel.org> > Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> Did you check if it is being used here too? cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h 2025-11-16 23:00 ` Namjae Jeon @ 2025-11-16 23:47 ` ChenXiaoSong 2025-11-17 0:08 ` ChenXiaoSong 2025-11-17 1:04 ` ChenXiaoSong 2025-11-17 1:06 ` ChenXiaoSong 2 siblings, 1 reply; 7+ messages in thread From: ChenXiaoSong @ 2025-11-16 23:47 UTC (permalink / raw) To: Namjae Jeon Cc: sfrench, smfrench, linkinjeon, christophe.jaillet, linux-cifs, linux-kernel, chenxiaosong, ChenXiaoSong Yes, we should also add MAX_FS_NAME_LEN here. This was my mistake. Thanks, ChenXiaoSong. On 11/17/25 7:00 AM, Namjae Jeon wrote: > On Sun, Nov 16, 2025 at 3:53 PM <chenxiaosong.chenxiaosong@linux.dev> wrote: >> >> From: ChenXiaoSong <chenxiaosong@kylinos.cn> >> >> Modify the following places: >> >> - struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO >> - Remove MIN_FS_ATTR_INFO_SIZE definition >> - Introduce MAX_FS_NAME_LEN >> - max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN >> - min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) >> >> Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file. >> >> Suggested-by: Namjae Jeon <linkinjeon@kernel.org> >> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> > > Did you check if it is being used here too? > cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h 2025-11-16 23:47 ` ChenXiaoSong @ 2025-11-17 0:08 ` ChenXiaoSong 0 siblings, 0 replies; 7+ messages in thread From: ChenXiaoSong @ 2025-11-17 0:08 UTC (permalink / raw) To: Namjae Jeon Cc: sfrench, smfrench, linkinjeon, christophe.jaillet, linux-cifs, linux-kernel, chenxiaosong, ChenXiaoSong And in the following part of the SMB2_QFS_attr() function, it also seems that we should change it to `memcpy(..., min_t(..., min_len))`. ```c SMB2_QFS_attr() { ... if (level == FS_ATTRIBUTE_INFORMATION) memcpy(&tcon->fsAttrInfo, offset + (char *)rsp, min_t(unsigned int, rsp_len, max_len)); ... } ``` Thanks, ChenXiaoSong. On 11/17/25 7:47 AM, ChenXiaoSong wrote: > Yes, we should also add MAX_FS_NAME_LEN here. This was my mistake. > > Thanks, > ChenXiaoSong. > > On 11/17/25 7:00 AM, Namjae Jeon wrote: >> On Sun, Nov 16, 2025 at 3:53 PM <chenxiaosong.chenxiaosong@linux.dev> >> wrote: >>> >>> From: ChenXiaoSong <chenxiaosong@kylinos.cn> >>> >>> Modify the following places: >>> >>> - struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO >>> - Remove MIN_FS_ATTR_INFO_SIZE definition >>> - Introduce MAX_FS_NAME_LEN >>> - max_len of FileFsAttributeInformation -> >>> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN >>> - min_len of FileFsAttributeInformation -> >>> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) >>> >>> Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file. >>> >>> Suggested-by: Namjae Jeon <linkinjeon@kernel.org> >>> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> >> >> Did you check if it is being used here too? >> cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h 2025-11-16 23:00 ` Namjae Jeon 2025-11-16 23:47 ` ChenXiaoSong @ 2025-11-17 1:04 ` ChenXiaoSong 2025-11-17 1:06 ` ChenXiaoSong 2 siblings, 0 replies; 7+ messages in thread From: ChenXiaoSong @ 2025-11-17 1:04 UTC (permalink / raw) To: Namjae Jeon, chenxiaosong.chenxiaosong Cc: sfrench, smfrench, linkinjeon, christophe.jaillet, linux-cifs, linux-kernel, chenxiaosong Hi Namjae, I have confirmed that when FileSystemName uses flexible array member, fsAttrInfo in struct cifs_tcon does not include FileSystemName. The following part in the CIFSSMBQFSAttributeInfo() function is correct, we cannot add MAX_FS_NAME_LEN to sizeof(FILE_SYSTEM_ATTRIBUTE_INFO). ```c CIFSSMBQFSAttributeInfo() { ... memcpy(&tcon->fsAttrInfo, response_data, sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); // it's correct here ... } ``` And in the following part of the SMB2_QFS_attr() function, we should change it to `memcpy(..., min_t(..., min_len))`. ```c SMB2_QFS_attr() { ... if (level == FS_ATTRIBUTE_INFORMATION) memcpy(&tcon->fsAttrInfo, offset + (char *)rsp, min_t(unsigned int, rsp_len, max_len)); // should use `min_len` here ... } ``` Thanks, ChenXiaoSong. On 11/17/25 07:00, Namjae Jeon wrote: > On Sun, Nov 16, 2025 at 3:53 PM <chenxiaosong.chenxiaosong@linux.dev> wrote: >> >> From: ChenXiaoSong <chenxiaosong@kylinos.cn> >> >> Modify the following places: >> >> - struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO >> - Remove MIN_FS_ATTR_INFO_SIZE definition >> - Introduce MAX_FS_NAME_LEN >> - max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN >> - min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) >> >> Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file. >> >> Suggested-by: Namjae Jeon <linkinjeon@kernel.org> >> Signed-off-by: ChenXiaoSong <chenxiaosong@kylinos.cn> > > Did you check if it is being used here too? > cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h 2025-11-16 23:00 ` Namjae Jeon 2025-11-16 23:47 ` ChenXiaoSong 2025-11-17 1:04 ` ChenXiaoSong @ 2025-11-17 1:06 ` ChenXiaoSong 2 siblings, 0 replies; 7+ messages in thread From: ChenXiaoSong @ 2025-11-17 1:06 UTC (permalink / raw) To: Namjae Jeon Cc: sfrench, smfrench, linkinjeon, christophe.jaillet, linux-cifs, linux-kernel, chenxiaosong Hi Namjae, I have confirmed that when FileSystemName uses flexible array member, fsAttrInfo in struct cifs_tcon does not include FileSystemName. The following part in the CIFSSMBQFSAttributeInfo() function is correct, we cannot add MAX_FS_NAME_LEN to sizeof(FILE_SYSTEM_ATTRIBUTE_INFO). ```c CIFSSMBQFSAttributeInfo() { ... memcpy(&tcon->fsAttrInfo, response_data, sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); // it's correct here ... } ``` And in the following part of the SMB2_QFS_attr() function, we should change it to `memcpy(..., min_t(..., min_len))`. ```c SMB2_QFS_attr() { ... if (level == FS_ATTRIBUTE_INFORMATION) memcpy(&tcon->fsAttrInfo, offset + (char *)rsp, min_t(unsigned int, rsp_len, max_len)); // should use `min_len` here ... } ``` Thanks, ChenXiaoSong. On 11/17/25 07:00, Namjae Jeon wrote: > Did you check if it is being used here too? > cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-11-17 1:07 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-16 6:52 [PATCH v8 0/1] smb: move duplicate definitions to common header file chenxiaosong.chenxiaosong 2025-11-16 6:52 ` [PATCH v8 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h chenxiaosong.chenxiaosong 2025-11-16 23:00 ` Namjae Jeon 2025-11-16 23:47 ` ChenXiaoSong 2025-11-17 0:08 ` ChenXiaoSong 2025-11-17 1:04 ` ChenXiaoSong 2025-11-17 1:06 ` ChenXiaoSong
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox