Skip to content

Commit 169c11c

Browse files
Steve Frenchnukelet
authored andcommitted
smb: client: fix NULL deref in asn1_ber_decoder()
BugLink: https://bugs.launchpad.net/bugs/2082641 If server replied SMB2_NEGOTIATE with a zero SecurityBufferOffset, smb2_get_data_area() sets @len to non-zero but return NULL, so decode_negTokeninit() ends up being called with a NULL @security_blob: BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 2 PID: 871 Comm: mount.cifs Not tainted 6.7.0-rc4 #2 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 RIP: 0010:asn1_ber_decoder+0x173/0xc80 Code: 01 4c 39 2c 24 75 09 45 84 c9 0f 85 2f 03 00 00 48 8b 14 24 4c 29 ea 48 83 fa 01 0f 86 1e 07 00 00 48 8b 74 24 28 4d 8d 5d 01 <42> 0f b6 3c 2e 89 fa 40 88 7c 24 5c f7 d2 83 e2 1f 0f 84 3d 07 00 RSP: 0018:ffffc9000063f950 EFLAGS: 00010202 RAX: 0000000000000002 RBX: 0000000000000000 RCX: 000000000000004a RDX: 000000000000004a RSI: 0000000000000000 RDI: 0000000000000000 RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000002 R11: 0000000000000001 R12: 0000000000000000 R13: 0000000000000000 R14: 000000000000004d R15: 0000000000000000 FS: 00007fce52b0fbc0(0000) GS:ffff88806ba00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 000000001ae64000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: <TASK> ? __die+0x23/0x70 ? page_fault_oops+0x181/0x480 ? __stack_depot_save+0x1e6/0x480 ? exc_page_fault+0x6f/0x1c0 ? asm_exc_page_fault+0x26/0x30 ? asn1_ber_decoder+0x173/0xc80 ? check_object+0x40/0x340 decode_negTokenInit+0x1e/0x30 [cifs] SMB2_negotiate+0xc99/0x17c0 [cifs] ? smb2_negotiate+0x46/0x60 [cifs] ? srso_alias_return_thunk+0x5/0xfbef5 smb2_negotiate+0x46/0x60 [cifs] cifs_negotiate_protocol+0xae/0x130 [cifs] cifs_get_smb_ses+0x517/0x1040 [cifs] ? srso_alias_return_thunk+0x5/0xfbef5 ? srso_alias_return_thunk+0x5/0xfbef5 ? queue_delayed_work_on+0x5d/0x90 cifs_mount_get_session+0x78/0x200 [cifs] dfs_mount_share+0x13a/0x9f0 [cifs] ? srso_alias_return_thunk+0x5/0xfbef5 ? lock_acquire+0xbf/0x2b0 ? find_nls+0x16/0x80 ? srso_alias_return_thunk+0x5/0xfbef5 cifs_mount+0x7e/0x350 [cifs] cifs_smb3_do_mount+0x128/0x780 [cifs] smb3_get_tree+0xd9/0x290 [cifs] vfs_get_tree+0x2c/0x100 ? capable+0x37/0x70 path_mount+0x2d7/0xb80 ? srso_alias_return_thunk+0x5/0xfbef5 ? _raw_spin_unlock_irqrestore+0x44/0x60 __x64_sys_mount+0x11a/0x150 do_syscall_64+0x47/0xf0 entry_SYSCALL_64_after_hwframe+0x6f/0x77 RIP: 0033:0x7fce52c2ab1e Fix this by setting @len to zero when @off == 0 so callers won't attempt to dereference non-existing data areas. Reported-by: Robert Morris <[email protected]> Cc: [email protected] Signed-off-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Steve French <[email protected]> (cherry picked from commit 90d025c) Signed-off-by: John Cabaj <[email protected]> Acked-by: Magali Lemes <[email protected]> Acked-by: Guoqing Jiang <[email protected]> Signed-off-by: John Cabaj <[email protected]>
1 parent 7cd9fe2 commit 169c11c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

fs/cifs/smb2misc.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,9 @@ static const bool has_smb2_data_area[NUMBER_OF_SMB2_COMMANDS] = {
313313
char *
314314
smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr)
315315
{
316+
const int max_off = 4096;
317+
const int max_len = 128 * 1024;
318+
316319
*off = 0;
317320
*len = 0;
318321

@@ -384,29 +387,20 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr)
384387
* Invalid length or offset probably means data area is invalid, but
385388
* we have little choice but to ignore the data area in this case.
386389
*/
387-
if (*off > 4096) {
388-
cifs_dbg(VFS, "offset %d too large, data area ignored\n", *off);
389-
*len = 0;
390-
*off = 0;
391-
} else if (*off < 0) {
392-
cifs_dbg(VFS, "negative offset %d to data invalid ignore data area\n",
393-
*off);
390+
if (unlikely(*off < 0 || *off > max_off ||
391+
*len < 0 || *len > max_len)) {
392+
cifs_dbg(VFS, "%s: invalid data area (off=%d len=%d)\n",
393+
__func__, *off, *len);
394394
*off = 0;
395395
*len = 0;
396-
} else if (*len < 0) {
397-
cifs_dbg(VFS, "negative data length %d invalid, data area ignored\n",
398-
*len);
399-
*len = 0;
400-
} else if (*len > 128 * 1024) {
401-
cifs_dbg(VFS, "data area larger than 128K: %d\n", *len);
396+
} else if (*off == 0) {
402397
*len = 0;
403398
}
404399

405400
/* return pointer to beginning of data area, ie offset from SMB start */
406-
if ((*off != 0) && (*len != 0))
401+
if (*off > 0 && *len > 0)
407402
return (char *)shdr + *off;
408-
else
409-
return NULL;
403+
return NULL;
410404
}
411405

412406
/*

0 commit comments

Comments
 (0)