Skip to content

Commit 02f76c4

Browse files
u1f383Steve French
authored andcommitted
ksmbd: fix global-out-of-bounds in smb2_find_context_vals
Add tag_len argument in smb2_find_context_vals() to avoid out-of-bound read when create_context's name_len is larger than tag length. [ 7.995411] ================================================================== [ 7.995866] BUG: KASAN: global-out-of-bounds in memcmp+0x83/0xa0 [ 7.996248] Read of size 8 at addr ffffffff8258d940 by task kworker/0:0/7 ... [ 7.998191] Call Trace: [ 7.998358] <TASK> [ 7.998503] dump_stack_lvl+0x33/0x50 [ 7.998743] print_report+0xcc/0x620 [ 7.999458] kasan_report+0xae/0xe0 [ 7.999895] kasan_check_range+0x35/0x1b0 [ 8.000152] memcmp+0x83/0xa0 [ 8.000347] smb2_find_context_vals+0xf7/0x1e0 [ 8.000635] smb2_open+0x1df2/0x43a0 [ 8.006398] handle_ksmbd_work+0x274/0x810 [ 8.006666] process_one_work+0x419/0x760 [ 8.006922] worker_thread+0x2a2/0x6f0 [ 8.007429] kthread+0x160/0x190 [ 8.007946] ret_from_fork+0x1f/0x30 [ 8.008181] </TASK> Cc: stable@vger.kernel.org Signed-off-by: Chih-Yen Chang <cc85nod@gmail.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent f1fcbaa commit 02f76c4

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

fs/ksmbd/oplock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,11 +1449,12 @@ struct lease_ctx_info *parse_lease_state(void *open_req)
14491449
* smb2_find_context_vals() - find a particular context info in open request
14501450
* @open_req: buffer containing smb2 file open(create) request
14511451
* @tag: context name to search for
1452+
* @tag_len: the length of tag
14521453
*
14531454
* Return: pointer to requested context, NULL if @str context not found
14541455
* or error pointer if name length is invalid.
14551456
*/
1456-
struct create_context *smb2_find_context_vals(void *open_req, const char *tag)
1457+
struct create_context *smb2_find_context_vals(void *open_req, const char *tag, int tag_len)
14571458
{
14581459
struct create_context *cc;
14591460
unsigned int next = 0;
@@ -1492,7 +1493,7 @@ struct create_context *smb2_find_context_vals(void *open_req, const char *tag)
14921493
return ERR_PTR(-EINVAL);
14931494

14941495
name = (char *)cc + name_off;
1495-
if (memcmp(name, tag, name_len) == 0)
1496+
if (name_len == tag_len && !memcmp(name, tag, name_len))
14961497
return cc;
14971498

14981499
remain_len -= next;

fs/ksmbd/oplock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ void create_durable_v2_rsp_buf(char *cc, struct ksmbd_file *fp);
118118
void create_mxac_rsp_buf(char *cc, int maximal_access);
119119
void create_disk_id_rsp_buf(char *cc, __u64 file_id, __u64 vol_id);
120120
void create_posix_rsp_buf(char *cc, struct ksmbd_file *fp);
121-
struct create_context *smb2_find_context_vals(void *open_req, const char *str);
121+
struct create_context *smb2_find_context_vals(void *open_req, const char *tag, int tag_len);
122122
struct oplock_info *lookup_lease_in_table(struct ksmbd_conn *conn,
123123
char *lease_key);
124124
int find_same_lease_key(struct ksmbd_session *sess, struct ksmbd_inode *ci,

fs/ksmbd/smb2pdu.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ static int smb2_create_sd_buffer(struct ksmbd_work *work,
24642464
return -ENOENT;
24652465

24662466
/* Parse SD BUFFER create contexts */
2467-
context = smb2_find_context_vals(req, SMB2_CREATE_SD_BUFFER);
2467+
context = smb2_find_context_vals(req, SMB2_CREATE_SD_BUFFER, 4);
24682468
if (!context)
24692469
return -ENOENT;
24702470
else if (IS_ERR(context))
@@ -2666,7 +2666,7 @@ int smb2_open(struct ksmbd_work *work)
26662666

26672667
if (req->CreateContextsOffset) {
26682668
/* Parse non-durable handle create contexts */
2669-
context = smb2_find_context_vals(req, SMB2_CREATE_EA_BUFFER);
2669+
context = smb2_find_context_vals(req, SMB2_CREATE_EA_BUFFER, 4);
26702670
if (IS_ERR(context)) {
26712671
rc = PTR_ERR(context);
26722672
goto err_out1;
@@ -2686,7 +2686,7 @@ int smb2_open(struct ksmbd_work *work)
26862686
}
26872687

26882688
context = smb2_find_context_vals(req,
2689-
SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST);
2689+
SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST, 4);
26902690
if (IS_ERR(context)) {
26912691
rc = PTR_ERR(context);
26922692
goto err_out1;
@@ -2697,7 +2697,7 @@ int smb2_open(struct ksmbd_work *work)
26972697
}
26982698

26992699
context = smb2_find_context_vals(req,
2700-
SMB2_CREATE_TIMEWARP_REQUEST);
2700+
SMB2_CREATE_TIMEWARP_REQUEST, 4);
27012701
if (IS_ERR(context)) {
27022702
rc = PTR_ERR(context);
27032703
goto err_out1;
@@ -2709,7 +2709,7 @@ int smb2_open(struct ksmbd_work *work)
27092709

27102710
if (tcon->posix_extensions) {
27112711
context = smb2_find_context_vals(req,
2712-
SMB2_CREATE_TAG_POSIX);
2712+
SMB2_CREATE_TAG_POSIX, 16);
27132713
if (IS_ERR(context)) {
27142714
rc = PTR_ERR(context);
27152715
goto err_out1;
@@ -3107,7 +3107,7 @@ int smb2_open(struct ksmbd_work *work)
31073107
struct create_alloc_size_req *az_req;
31083108

31093109
az_req = (struct create_alloc_size_req *)smb2_find_context_vals(req,
3110-
SMB2_CREATE_ALLOCATION_SIZE);
3110+
SMB2_CREATE_ALLOCATION_SIZE, 4);
31113111
if (IS_ERR(az_req)) {
31123112
rc = PTR_ERR(az_req);
31133113
goto err_out;
@@ -3134,7 +3134,7 @@ int smb2_open(struct ksmbd_work *work)
31343134
err);
31353135
}
31363136

3137-
context = smb2_find_context_vals(req, SMB2_CREATE_QUERY_ON_DISK_ID);
3137+
context = smb2_find_context_vals(req, SMB2_CREATE_QUERY_ON_DISK_ID, 4);
31383138
if (IS_ERR(context)) {
31393139
rc = PTR_ERR(context);
31403140
goto err_out;

0 commit comments

Comments
 (0)