smb: client: fix potential OOBs in smb2_parse_contexts()
PATCH 1/2 smb: client: fix potential OOBs in smb2_parse_contexts()
From: Paulo Alcantara <[email protected]>
[ Upstream commit af1689a9b7701d9907dfc84d2a4b57c4bc907144 ]
Validate offsets and lengths before dereferencing create contexts in smb2_parse_contexts().
This fixes following oops when accessing invalid create contexts from server:
BUG: unable to handle page fault for address: ffff8881178d8cc3 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 4a01067 P4D 4a01067 PUD 0 Oops: 0000 [#1] PREEMPT SMP NOPTI CPU: 3 PID: 1736 Comm: mount.cifs Not tainted 6.7.0-rc4 #1 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014 RIP: 0010:smb2_parse_contexts+0xa0/0x3a0 [cifs] Code: f8 10 75 13 48 b8 93 ad 25 50 9c b4 11 e7 49 39 06 0f 84 d2 00 00 00 8b 45 00 85 c0 74 61 41 29 c5 48 01 c5 41 83 fd 0f 76 55 <0f> b7 7d 04 0f b7 45 06 4c 8d 74 3d 00 66 83 f8 04 75 bc ba 04 00 RSP: 0018:ffffc900007939e0 EFLAGS: 00010216 RAX: ffffc90000793c78 RBX: ffff8880180cc000 RCX: ffffc90000793c90 RDX: ffffc90000793cc0 RSI: ffff8880178d8cc0 RDI: ffff8880180cc000 RBP: ffff8881178d8cbf R08: ffffc90000793c22 R09: 0000000000000000 R10: ffff8880180cc000 R11: 0000000000000024 R12: 0000000000000000 R13: 0000000000000020 R14: 0000000000000000 R15: ffffc90000793c22 FS: 00007f873753cbc0(0000) GS:ffff88806bc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff8881178d8cc3 CR3: 00000000181ca000 CR4: 0000000000750ef0 PKRU: 55555554 Call Trace: <TASK> ? __die+0x23/0x70 ? page_fault_oops+0x181/0x480 ? search_module_extables+0x19/0x60 ? srso_alias_return_thunk+0x5/0xfbef5 ? exc_page_fault+0x1b6/0x1c0 ? asm_exc_page_fault+0x26/0x30 ? smb2_parse_contexts+0xa0/0x3a0 [cifs] SMB2_open+0x38d/0x5f0 [cifs] ? smb2_is_path_accessible+0x138/0x260 [cifs] smb2_is_path_accessible+0x138/0x260 [cifs] cifs_is_path_remote+0x8d/0x230 [cifs] 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:0x7f8737657b1e
--- fs/smb/client/cached_dir.c | 8 ++-- fs/smb/client/smb2pdu.c | 93 +++++++++++++++++++++++--------------- fs/smb/client/smb2proto.h | 12 +++-- 3 files changed, 68 insertions(+), 45 deletions(-)
fs/smb/client/cached_dir.c +5 -3
@@ -268,10 +268,12 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,if (o_rsp->OplockLevel !=SMB2_OPLOCK_LEVEL_LEASE ) goto oshr_free; -smb2_parse_contexts (server, o_rsp, + rc =smb2_parse_contexts (server, rsp_iov, &oparms.fid->epoch, - oparms.fid->lease_key, &oplock, -NULL ,NULL ); + oparms.fid->lease_key, + &oplock,NULL ,NULL ); +if (rc) + goto oshr_free;if (!(oplock &SMB2_LEASE_READ_CACHING_HE )) goto oshr_free; qi_rsp = (struct smb2_query_info_rsp *)rsp_iov[1 ].iov_base;
fs/smb/client/smb2pdu.c +56 -37
126 lines not on this page · raw message
fs/smb/client/smb2proto.h +7 -5
@@ -249,11 +249,13 @@ extern int smb3_validate_negotiate(const unsigned int, struct cifs_tcon *);extern enum securityEnum smb2_select_sectype (struct TCP_Server_Info *,enum securityEnum ); -extern void smb2_parse_contexts (struct TCP_Server_Info *server, -struct smb2_create_rsp *rsp, -unsigned int *epoch,char *lease_key, -__u8 *oplock,struct smb2_file_all_info *buf, -struct create_posix_rsp *posix); +int smb2_parse_contexts (struct TCP_Server_Info *server, +struct kvec *rsp_iov, +unsigned int *epoch, +char *lease_key,__u8 *oplock, +struct smb2_file_all_info *buf, +struct create_posix_rsp *posix); +extern int smb3_encryption_required (const struct cifs_tcon *tcon);extern int smb2_validate_iov (unsigned int offset,unsigned int buffer_length,struct kvec *iov,unsigned int min_buf_size);
Signature · 1 line
2.25.1
PATCH 2/2 smb: client: fix parsing of SMB3.1.1 POSIX create context
From: Paulo Alcantara <[email protected]>
[ Upstream commit 76025cc2285d9ede3d717fe4305d66f8be2d9346 ]
The data offset for the SMB3.1.1 POSIX create context will always be 8-byte aligned so having the check 'noff + nlen >= doff' in smb2_parse_contexts() is wrong as it will lead to -EINVAL because noff
+ nlen == doff.
Fix the sanity check to correctly handle aligned create context data.
--- fs/smb/client/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/smb/client/smb2pdu.c +1 -1
@@ -2184,7 +2184,7 @@ int smb2_parse_contexts(struct TCP_Server_Info *server, noff =le16_to_cpu (cc->NameOffset); nlen =le16_to_cpu (cc->NameLength); -if (noff + nlen >= doff) +if (noff + nlen > doff)return -EINVAL ; name = (char *)cc + noff;
Signature · 1 line
2.25.1
cover Backport Fixes to linux-6.1.y
In reply to Guruswamy BasavaiahHere are the two backported patches aimed at addressing a crash.
Patch 1 fix validate offsets and lengths before dereferencing create contexts in smb2_parse_contexts().
Patch 2 fix issue in patch 1.
The original patches were authored by Paulo Alcantara <[email protected]>. Original Patches:
1. af1689a9b770 ("smb: client: fix potential OOBs in smb2_parse_contexts()")
2. 76025cc2285d ("smb: client: fix parsing of SMB3.1.1 POSIX create context")
Please review and consider applying these patches.
fs/smb/client/cached_dir.c | 8 +++++--- fs/smb/client/smb2pdu.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------- fs/smb/client/smb2proto.h | 12 +++++++----- 3 files changed, 68 insertions(+), 45 deletions(-)
Greg KH
maintainerRe: [PATCH 6.1.y 0/2] Backport Fixes to linux-6.1.y
Quoted 5 lines · Guruswamy Basavaiah
Here are the two backported patches aimed at addressing a crash.
Patch 1 fix validate offsets and lengths before dereferencing create contexts in
smb2_parse_contexts().
Quoted 8 lines
Patch 2 fix issue in patch 1.
The original patches were authored by Paulo Alcantara <[email protected]>. Original Patches:
1.af1689a9b770("smb: client: fix potential OOBs insmb2_parse_contexts()")
2.76025cc2285d("smb: client: fix parsing of SMB3.1.1 POSIX create context")Please review and consider applying these patches.
All now queued up.
And it looks like af1689a9b770 ("smb: client: fix potential OOBs in smb2_parse_contexts()") should get a CVE assignment, right?
thanks,
greg k-h