Skip to content

Commit 55bc056

Browse files
committed
ksmbd: fix potencial OOB in get_file_all_info() for compound requests
When a compound request consists of QUERY_DIRECTORY + QUERY_INFO (FILE_ALL_INFORMATION) and the first command consumes nearly the entire max_trans_size, get_file_all_info() would blindly call smbConvertToUTF16() with PATH_MAX, causing out-of-bounds write beyond the response buffer. In get_file_all_info(), there was a missing validation check for the client-provided OutputBufferLength before copying the filename into FileName field of the smb2_file_all_info structure. If the filename length exceeds the available buffer space, it could lead to potential buffer overflows or memory corruption during smbConvertToUTF16 conversion. This calculating the actual free buffer size using smb2_calc_max_out_buf_len() and returning -EINVAL if the buffer is insufficient and updating smbConvertToUTF16 to use the actual filename length (clamped by PATH_MAX) to ensure a safe copy operation. Cc: stable@vger.kernel.org Fixes: e2b76ab8b5c9 ("ksmbd: add support for read compound") Reported-by: Asim Viladi Oglu Manizada <manizada@pm.me> Signed-off-by: Namjae Jeon <linkinjeon@kernel.org>
1 parent 9132bfd commit 55bc056

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

smb2pdu.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5181,7 +5181,8 @@ static int get_file_all_info(struct ksmbd_work *work,
51815181
int conv_len;
51825182
char *filename;
51835183
u64 time;
5184-
int ret;
5184+
int ret, buf_free_len, filename_len;
5185+
struct smb2_query_info_req *req = ksmbd_req_buf_next(work);
51855186

51865187
if (!(fp->daccess & FILE_READ_ATTRIBUTES_LE)) {
51875188
ksmbd_debug(SMB, "no right to read the attributes : 0x%x\n",
@@ -5193,6 +5194,16 @@ static int get_file_all_info(struct ksmbd_work *work,
51935194
if (IS_ERR(filename))
51945195
return PTR_ERR(filename);
51955196

5197+
filename_len = strlen(filename);
5198+
buf_free_len = smb2_calc_max_out_buf_len(work,
5199+
offsetof(struct smb2_query_info_rsp, Buffer) +
5200+
offsetof(struct smb2_file_all_info, FileName),
5201+
le32_to_cpu(req->OutputBufferLength));
5202+
if (buf_free_len < (filename_len + 1) * 2) {
5203+
kfree(filename);
5204+
return -EINVAL;
5205+
}
5206+
51965207
ret = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS,
51975208
AT_STATX_SYNC_AS_STAT);
51985209
if (ret)
@@ -5234,7 +5245,8 @@ static int get_file_all_info(struct ksmbd_work *work,
52345245
file_info->Mode = fp->coption;
52355246
file_info->AlignmentRequirement = 0;
52365247
conv_len = smbConvertToUTF16((__le16 *)file_info->FileName, filename,
5237-
PATH_MAX, conn->local_nls, 0);
5248+
min(filename_len, PATH_MAX),
5249+
conn->local_nls, 0);
52385250
conv_len *= 2;
52395251
file_info->FileNameLength = cpu_to_le32(conv_len);
52405252
rsp->OutputBufferLength =

0 commit comments

Comments
 (0)