linux-stable/fs/smb/client
Paulo Alcantara 277832a306 smb: client: fix OOB in cifsd when receiving compounded resps
commit a8f68b1115 upstream.

Validate next header's offset in ->next_header() so that it isn't
smaller than MID_HEADER_SIZE(server) and then standard_receive3() or
->receive() ends up writing off the end of the buffer because
'pdu_length - MID_HEADER_SIZE(server)' wraps up to a huge length:

  BUG: KASAN: slab-out-of-bounds in _copy_to_iter+0x4fc/0x840
  Write of size 701 at addr ffff88800caf407f by task cifsd/1090

  CPU: 0 PID: 1090 Comm: cifsd Not tainted 6.7.0-rc4 #5
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS
  rel-1.16.2-3-gd478f380-rebuilt.opensuse.org 04/01/2014
  Call Trace:
   <TASK>
   dump_stack_lvl+0x4a/0x80
   print_report+0xcf/0x650
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? __phys_addr+0x46/0x90
   kasan_report+0xd8/0x110
   ? _copy_to_iter+0x4fc/0x840
   ? _copy_to_iter+0x4fc/0x840
   kasan_check_range+0x105/0x1b0
   __asan_memcpy+0x3c/0x60
   _copy_to_iter+0x4fc/0x840
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? hlock_class+0x32/0xc0
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? __pfx__copy_to_iter+0x10/0x10
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? lock_is_held_type+0x90/0x100
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? __might_resched+0x278/0x360
   ? __pfx___might_resched+0x10/0x10
   ? srso_alias_return_thunk+0x5/0xfbef5
   __skb_datagram_iter+0x2c2/0x460
   ? __pfx_simple_copy_to_iter+0x10/0x10
   skb_copy_datagram_iter+0x6c/0x110
   tcp_recvmsg_locked+0x9be/0xf40
   ? __pfx_tcp_recvmsg_locked+0x10/0x10
   ? mark_held_locks+0x5d/0x90
   ? srso_alias_return_thunk+0x5/0xfbef5
   tcp_recvmsg+0xe2/0x310
   ? __pfx_tcp_recvmsg+0x10/0x10
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? lock_acquire+0x14a/0x3a0
   ? srso_alias_return_thunk+0x5/0xfbef5
   inet_recvmsg+0xd0/0x370
   ? __pfx_inet_recvmsg+0x10/0x10
   ? __pfx_lock_release+0x10/0x10
   ? do_raw_spin_trylock+0xd1/0x120
   sock_recvmsg+0x10d/0x150
   cifs_readv_from_socket+0x25a/0x490 [cifs]
   ? __pfx_cifs_readv_from_socket+0x10/0x10 [cifs]
   ? srso_alias_return_thunk+0x5/0xfbef5
   cifs_read_from_socket+0xb5/0x100 [cifs]
   ? __pfx_cifs_read_from_socket+0x10/0x10 [cifs]
   ? __pfx_lock_release+0x10/0x10
   ? do_raw_spin_trylock+0xd1/0x120
   ? _raw_spin_unlock+0x23/0x40
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? __smb2_find_mid+0x126/0x230 [cifs]
   cifs_demultiplex_thread+0xd39/0x1270 [cifs]
   ? __pfx_cifs_demultiplex_thread+0x10/0x10 [cifs]
   ? __pfx_lock_release+0x10/0x10
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? mark_held_locks+0x1a/0x90
   ? lockdep_hardirqs_on_prepare+0x136/0x210
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? srso_alias_return_thunk+0x5/0xfbef5
   ? __kthread_parkme+0xce/0xf0
   ? __pfx_cifs_demultiplex_thread+0x10/0x10 [cifs]
   kthread+0x18d/0x1d0
   ? kthread+0xdb/0x1d0
   ? __pfx_kthread+0x10/0x10
   ret_from_fork+0x34/0x60
   ? __pfx_kthread+0x10/0x10
   ret_from_fork_asm+0x1b/0x30
   </TASK>

Fixes: 8ce79ec359 ("cifs: update multiplex loop to handle compounded responses")
Cc: stable@vger.kernel.org
Reported-by: Robert Morris <rtm@csail.mit.edu>
Signed-off-by: Paulo Alcantara (SUSE) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-01 12:39:04 +00:00
..
asn1.c
cached_dir.c cifs: update desired access while requesting for directory lease 2023-09-19 12:27:57 +02:00
cached_dir.h
cifs_debug.c cifs: distribute channels across interfaces based on speed 2023-12-03 07:32:09 +01: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.c cifs: spnego: add ';' in HOST_KEY_LEN 2023-11-28 17:07:06 +00:00
cifs_spnego.h
cifs_spnego_negtokeninit.asn1
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, invalidation and file size with FICLONE 2023-12-13 18:39:28 +01:00
cifsfs.h cifs: minor cleanup of some headers 2023-12-03 07:32:09 +01:00
cifsglob.h smb: client: fix OOB in cifsd when receiving compounded resps 2024-01-01 12:39:04 +00:00
cifspdu.h smb3: fix creating FIFOs when mounting with "sfu" mount option 2023-11-28 17:07:15 +00:00
cifsproto.h smb: client: fix potential deadlock when releasing mids 2023-11-28 17:07:15 +00:00
cifsroot.c
cifssmb.c
connect.c smb: client: fix OOB in cifsd when receiving compounded resps 2024-01-01 12:39:04 +00: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 smb: propagate error code of extract_sharename() 2023-09-19 12:28:00 +02:00
fscache.h
inode.c smb: client: report correct st_size for SMB and NFS symlinks 2023-12-08 08:51:13 +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
netlink.c
netlink.h
netmisc.c
nterr.c
nterr.h
ntlmssp.h
readdir.c
rfc1002pdu.h
sess.c cifs: account for primary channel in the interface list 2023-12-03 07:32:09 +01:00
smb1ops.c
smb2file.c
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 NULL deref in asn1_ber_decoder() 2023-12-20 17:00:27 +01:00
smb2ops.c smb: client: fix OOB in cifsd when receiving compounded resps 2024-01-01 12:39:04 +00:00
smb2pdu.c send channel sequence number in SMB3 requests after reconnects 2023-09-19 12:27:56 +02:00
smb2pdu.h
smb2proto.h
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