linux/fs/smb/client
Paulo Alcantara 1ae3c59355 smb: client: fix potential OOBs in smb2_parse_contexts()
commit af1689a9b7 upstream.

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

Reported-by: Robert Morris <rtm@csail.mit.edu>
Cc: stable@vger.kernel.org
Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
[Guru: Modified the patch to be applicable to the cached_dir.c file.]
Signed-off-by: Guruswamy Basavaiah <guruswamy.basavaiah@broadcom.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 09:12:50 +01:00
..
asn1.c
cached_dir.c smb: client: fix potential OOBs in smb2_parse_contexts() 2024-02-23 09:12:50 +01:00
cached_dir.h
cifs_debug.c smb: client: fix potential OOB in cifs_dump_detail() 2024-01-01 12:39:04 +00:00
cifs_debug.h
cifs_dfs_ref.c cifs: use fs_context for automounts 2023-09-19 12:28:00 +02:00
cifs_fs_sb.h
cifs_ioctl.h smb3: allow dumping session and tcon id to improve stats analysis and debugging 2023-12-03 07:32:09 +01:00
cifs_spnego_negtokeninit.asn1
cifs_spnego.c cifs: spnego: add ';' in HOST_KEY_LEN 2023-11-28 17:07:06 +00:00
cifs_spnego.h
cifs_swn.c
cifs_swn.h
cifs_unicode.c
cifs_unicode.h
cifs_uniupr.h
cifsacl.c
cifsacl.h
cifsencrypt.c
cifsfs.c cifs: fix flushing folio regression for 6.1 backport 2024-01-15 18:54:51 +01:00
cifsfs.h cifs: minor cleanup of some headers 2023-12-03 07:32:09 +01:00
cifsglob.h cifs: do not depend on release_iface for maintaining iface_list 2024-01-10 17:10:21 +01:00
cifspdu.h smb: client, common: fix fortify warnings 2024-01-20 11:50:04 +01:00
cifsproto.h smb: client: fix potential deadlock when releasing mids 2023-11-28 17:07:15 +00:00
cifsroot.c
cifssmb.c smb: client, common: fix fortify warnings 2024-01-20 11:50:04 +01:00
connect.c cifs: cifs_chan_is_iface_active should be called with chan_lock held 2024-01-10 17:10:21 +01:00
dfs_cache.c
dfs_cache.h
dir.c
dns_resolve.c
dns_resolve.h
export.c
file.c cifs: Release folio lock on fscache read hit. 2023-08-23 17:52:39 +02:00
fs_context.c fs/smb/client: Reset password pointer to NULL 2023-10-06 14:57:05 +02:00
fs_context.h
fscache.c mm, netfs, fscache: stop read optimisation when folio removed from pagecache 2024-01-10 17:10:31 +01:00
fscache.h
inode.c smb: client: fix missing mode bits for SMB symlinks 2024-01-10 17:10:32 +01:00
ioctl.c smb3: allow dumping session and tcon id to improve stats analysis and debugging 2023-12-03 07:32:09 +01:00
Kconfig
link.c
Makefile
misc.c smb: client: fix OOB in smbCalcSize() 2024-01-01 12:39:05 +00:00
netlink.c
netlink.h
netmisc.c
nterr.c
nterr.h
ntlmssp.h
readdir.c
rfc1002pdu.h
sess.c cifs: failure to add channel on iface should bump up weight 2024-02-16 19:06:25 +01:00
smb1ops.c
smb2file.c smb3: Replace smb2pdu 1-element arrays with flex-arrays 2024-01-10 17:10:37 +01:00
smb2glob.h
smb2inode.c smb: client: fix broken file attrs with nodfs mounts 2023-07-19 16:21:44 +02:00
smb2maperror.c
smb2misc.c smb: client: fix potential OOB in smb2_dump_detail() 2024-01-20 11:50:09 +01:00
smb2ops.c cifs: fix underflow in parse_server_interfaces() 2024-02-23 09:12:35 +01:00
smb2pdu.c smb: client: fix potential OOBs in smb2_parse_contexts() 2024-02-23 09:12:50 +01:00
smb2pdu.h smb: client, common: fix fortify warnings 2024-01-20 11:50:04 +01:00
smb2proto.h smb: client: fix potential OOBs in smb2_parse_contexts() 2024-02-23 09:12:50 +01:00
smb2status.h
smb2transport.c cifs: fix check of rc in function generate_smb3signingkey 2023-11-28 17:07:07 +00:00
smbdirect.c
smbdirect.h
smbencrypt.c
smberr.h
trace.c
trace.h
transport.c smb: client: fix potential deadlock when releasing mids 2023-11-28 17:07:15 +00:00
unc.c
winucase.c
xattr.c smb3: fix caching of ctime on setxattr 2023-11-28 17:07:15 +00:00