linux-rockchip/fs/smb/client
Paulo Alcantara 2ef632bfb8 smb: client: fix OOBs when building SMB2_IOCTL request
[ Upstream commit 1ab60323c5201bef25f2a3dc0ccc404d9aca77f1 ]

When using encryption, either enforced by the server or when using
'seal' mount option, the client will squash all compound request buffers
down for encryption into a single iov in smb2_set_next_command().

SMB2_ioctl_init() allocates a small buffer (448 bytes) to hold the
SMB2_IOCTL request in the first iov, and if the user passes an input
buffer that is greater than 328 bytes, smb2_set_next_command() will
end up writing off the end of @rqst->iov[0].iov_base as shown below:

  mount.cifs //srv/share /mnt -o ...,seal
  ln -s $(perl -e "print('a')for 1..1024") /mnt/link

  BUG: KASAN: slab-out-of-bounds in
  smb2_set_next_command.cold+0x1d6/0x24c [cifs]
  Write of size 4116 at addr ffff8881148fcab8 by task ln/859

  CPU: 1 UID: 0 PID: 859 Comm: ln Not tainted 6.12.0-rc3 #1
  Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS
  1.16.3-2.fc40 04/01/2014
  Call Trace:
   <TASK>
   dump_stack_lvl+0x5d/0x80
   ? smb2_set_next_command.cold+0x1d6/0x24c [cifs]
   print_report+0x156/0x4d9
   ? smb2_set_next_command.cold+0x1d6/0x24c [cifs]
   ? __virt_addr_valid+0x145/0x310
   ? __phys_addr+0x46/0x90
   ? smb2_set_next_command.cold+0x1d6/0x24c [cifs]
   kasan_report+0xda/0x110
   ? smb2_set_next_command.cold+0x1d6/0x24c [cifs]
   kasan_check_range+0x10f/0x1f0
   __asan_memcpy+0x3c/0x60
   smb2_set_next_command.cold+0x1d6/0x24c [cifs]
   smb2_compound_op+0x238c/0x3840 [cifs]
   ? kasan_save_track+0x14/0x30
   ? kasan_save_free_info+0x3b/0x70
   ? vfs_symlink+0x1a1/0x2c0
   ? do_symlinkat+0x108/0x1c0
   ? __pfx_smb2_compound_op+0x10/0x10 [cifs]
   ? kmem_cache_free+0x118/0x3e0
   ? cifs_get_writable_path+0xeb/0x1a0 [cifs]
   smb2_get_reparse_inode+0x423/0x540 [cifs]
   ? __pfx_smb2_get_reparse_inode+0x10/0x10 [cifs]
   ? rcu_is_watching+0x20/0x50
   ? __kmalloc_noprof+0x37c/0x480
   ? smb2_create_reparse_symlink+0x257/0x490 [cifs]
   ? smb2_create_reparse_symlink+0x38f/0x490 [cifs]
   smb2_create_reparse_symlink+0x38f/0x490 [cifs]
   ? __pfx_smb2_create_reparse_symlink+0x10/0x10 [cifs]
   ? find_held_lock+0x8a/0xa0
   ? hlock_class+0x32/0xb0
   ? __build_path_from_dentry_optional_prefix+0x19d/0x2e0 [cifs]
   cifs_symlink+0x24f/0x960 [cifs]
   ? __pfx_make_vfsuid+0x10/0x10
   ? __pfx_cifs_symlink+0x10/0x10 [cifs]
   ? make_vfsgid+0x6b/0xc0
   ? generic_permission+0x96/0x2d0
   vfs_symlink+0x1a1/0x2c0
   do_symlinkat+0x108/0x1c0
   ? __pfx_do_symlinkat+0x10/0x10
   ? strncpy_from_user+0xaa/0x160
   __x64_sys_symlinkat+0xb9/0xf0
   do_syscall_64+0xbb/0x1d0
   entry_SYSCALL_64_after_hwframe+0x77/0x7f
  RIP: 0033:0x7f08d75c13bb

Reported-by: David Howells <dhowells@redhat.com>
Fixes: e77fe73c7e ("cifs: we can not use small padding iovs together with encryption")
Signed-off-by: Paulo Alcantara (Red Hat) <pc@manguebit.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-11-01 01:56:00 +01:00
..
asn1.c
cached_dir.c smb3: fix Open files on server counter going negative 2024-04-17 11:18:22 +02:00
cached_dir.h
cifs_debug.c smb3: fix setting SecurityFlags when encryption is required 2024-08-14 13:52:59 +02:00
cifs_debug.h
cifs_dfs_ref.c
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.h cifs: Replace remaining 1-element arrays 2024-05-02 16:29:27 +02:00
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 smb: Work around Clang __bdos() type confusion 2024-03-01 13:26:26 +01:00
cifsfs.c smb: client: use actual path when queryfs 2024-10-17 15:22:00 +02:00
cifsfs.h cifs: minor cleanup of some headers 2023-12-03 07:32:09 +01:00
cifsglob.h smb: client: use actual path when queryfs 2024-10-17 15:22:00 +02:00
cifspdu.h smb: client: Fix struct_group() usage in __packed structs 2024-05-02 16:29:28 +02: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 smb: client: fix hang in wait_for_response() for negproto 2024-09-30 16:23:49 +02:00
dfs_cache.c
dfs_cache.h
dir.c cifs: Fix caching to try to do open O_WRONLY as rdwr on server 2024-04-10 16:28:31 +02:00
dns_resolve.c
dns_resolve.h
export.c
file.c smb3: retrying on failed server close 2024-04-10 16:28:33 +02:00
fs_context.c cifs: reinstate original behavior again for forceuid/forcegid 2024-05-02 16:29:21 +02:00
fs_context.h cifs: reinstate original behavior again for forceuid/forcegid 2024-05-02 16:29:21 +02:00
fscache.c cifs: Fix duplicate fscache cookie warnings 2024-04-10 16:28:23 +02:00
fscache.h cifs: Fix caching to try to do open O_WRONLY as rdwr on server 2024-04-10 16:28:31 +02:00
inode.c cifs: Fix duplicate fscache cookie warnings 2024-04-10 16:28:23 +02: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 potential UAF in is_valid_oplock_break() 2024-04-10 16:28:34 +02:00
netlink.c
netlink.h
netmisc.c
nterr.c
nterr.h
ntlmssp.h
readdir.c cifs: Replace remaining 1-element arrays 2024-05-02 16:29:27 +02:00
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 smb: client: use actual path when queryfs 2024-10-17 15:22:00 +02:00
smb2file.c smb3: Replace smb2pdu 1-element arrays with flex-arrays 2024-01-10 17:10:37 +01:00
smb2glob.h
smb2inode.c
smb2maperror.c
smb2misc.c smb: client: fix potential UAF in smb2_is_valid_lease_break() 2024-04-10 16:28:34 +02:00
smb2ops.c smb: client: use actual path when queryfs 2024-10-17 15:22:00 +02:00
smb2pdu.c smb: client: fix OOBs when building SMB2_IOCTL request 2024-11-01 01:56:00 +01:00
smb2pdu.h smb: client: Fix struct_group() usage in __packed structs 2024-05-02 16:29:28 +02:00
smb2proto.h smb: client: fix potential OOBs in smb2_parse_contexts() 2024-02-23 09:12:50 +01:00
smb2status.h
smb2transport.c smb: client: fix deadlock in smb2_find_smb_tcon() 2024-06-16 13:41:42 +02:00
smbdirect.c
smbdirect.h
smbencrypt.c
smberr.h
trace.c
trace.h
transport.c smb3: missing lock when picking channel 2024-05-17 11:55:53 +02:00
unc.c
winucase.c
xattr.c smb3: fix caching of ctime on setxattr 2023-11-28 17:07:15 +00:00