acrn-kernel/fs/cifs
ZhaoLong Wang 3684a2f6af cifs: Fix use-after-free in rdata->read_into_pages()
commit aa5465aeca upstream.

When the network status is unstable, use-after-free may occur when
read data from the server.

  BUG: KASAN: use-after-free in readpages_fill_pages+0x14c/0x7e0

  Call Trace:
   <TASK>
   dump_stack_lvl+0x38/0x4c
   print_report+0x16f/0x4a6
   kasan_report+0xb7/0x130
   readpages_fill_pages+0x14c/0x7e0
   cifs_readv_receive+0x46d/0xa40
   cifs_demultiplex_thread+0x121c/0x1490
   kthread+0x16b/0x1a0
   ret_from_fork+0x2c/0x50
   </TASK>

  Allocated by task 2535:
   kasan_save_stack+0x22/0x50
   kasan_set_track+0x25/0x30
   __kasan_kmalloc+0x82/0x90
   cifs_readdata_direct_alloc+0x2c/0x110
   cifs_readdata_alloc+0x2d/0x60
   cifs_readahead+0x393/0xfe0
   read_pages+0x12f/0x470
   page_cache_ra_unbounded+0x1b1/0x240
   filemap_get_pages+0x1c8/0x9a0
   filemap_read+0x1c0/0x540
   cifs_strict_readv+0x21b/0x240
   vfs_read+0x395/0x4b0
   ksys_read+0xb8/0x150
   do_syscall_64+0x3f/0x90
   entry_SYSCALL_64_after_hwframe+0x72/0xdc

  Freed by task 79:
   kasan_save_stack+0x22/0x50
   kasan_set_track+0x25/0x30
   kasan_save_free_info+0x2e/0x50
   __kasan_slab_free+0x10e/0x1a0
   __kmem_cache_free+0x7a/0x1a0
   cifs_readdata_release+0x49/0x60
   process_one_work+0x46c/0x760
   worker_thread+0x2a4/0x6f0
   kthread+0x16b/0x1a0
   ret_from_fork+0x2c/0x50

  Last potentially related work creation:
   kasan_save_stack+0x22/0x50
   __kasan_record_aux_stack+0x95/0xb0
   insert_work+0x2b/0x130
   __queue_work+0x1fe/0x660
   queue_work_on+0x4b/0x60
   smb2_readv_callback+0x396/0x800
   cifs_abort_connection+0x474/0x6a0
   cifs_reconnect+0x5cb/0xa50
   cifs_readv_from_socket.cold+0x22/0x6c
   cifs_read_page_from_socket+0xc1/0x100
   readpages_fill_pages.cold+0x2f/0x46
   cifs_readv_receive+0x46d/0xa40
   cifs_demultiplex_thread+0x121c/0x1490
   kthread+0x16b/0x1a0
   ret_from_fork+0x2c/0x50

The following function calls will cause UAF of the rdata pointer.

readpages_fill_pages
 cifs_read_page_from_socket
  cifs_readv_from_socket
   cifs_reconnect
    __cifs_reconnect
     cifs_abort_connection
      mid->callback() --> smb2_readv_callback
       queue_work(&rdata->work)  # if the worker completes first,
                                 # the rdata is freed
          cifs_readv_complete
            kref_put
              cifs_readdata_release
                kfree(rdata)
 return rdata->...               # UAF in readpages_fill_pages()

Similarly, this problem also occurs in the uncache_fill_pages().

Fix this by adjusts the order of condition judgment in the return
statement.

Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
Cc: stable@vger.kernel.org
Acked-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-02-14 19:11:51 +01:00
..
Kconfig
Makefile
asn1.c
cached_dir.c
cached_dir.h
cifs_debug.c
cifs_debug.h
cifs_dfs_ref.c
cifs_fs_sb.h
cifs_ioctl.h
cifs_spnego.c
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 cifs: fix potential memory leaks in session setup 2023-02-01 08:34:32 +01:00
cifsfs.c cifs: fix missing display of three mount options 2023-01-07 11:11:50 +01:00
cifsfs.h
cifsglob.h cifs: fix oops during encryption 2022-12-21 17:48:11 +01:00
cifspdu.h
cifsproto.h cifs: fix oops during encryption 2022-12-21 17:48:11 +01:00
cifsroot.c
cifssmb.c
connect.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
dfs_cache.c cifs: fix return of uninitialized rc in dfs_cache_update_tgthint() 2023-02-06 08:06:33 +01:00
dfs_cache.h
dir.c
dns_resolve.c
dns_resolve.h
export.c
file.c cifs: Fix use-after-free in rdata->read_into_pages() 2023-02-14 19:11:51 +01:00
fs_context.c
fs_context.h
fscache.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
fscache.h
inode.c cifs: reduce roundtrips on create/qinfo requests 2023-01-24 07:24:41 +01:00
ioctl.c
link.c cifs: Fix uninitialized memory read for smb311 posix symlink create 2023-01-18 11:58:14 +01:00
misc.c cifs: reduce roundtrips on create/qinfo requests 2023-01-24 07:24:41 +01:00
netlink.c
netlink.h
netmisc.c
nterr.c
nterr.h
ntlmssp.h
readdir.c
rfc1002pdu.h
sess.c cifs: fix potential memory leaks in session setup 2023-02-01 08:34:32 +01:00
smb1ops.c cifs: fix file info setting in cifs_open_file() 2023-01-18 11:58:14 +01:00
smb2file.c cifs: don't leak -ENOMEM in smb2_open_file() 2022-12-31 13:32:56 +01:00
smb2glob.h
smb2inode.c cifs: reduce roundtrips on create/qinfo requests 2023-01-24 07:24:41 +01:00
smb2maperror.c
smb2misc.c
smb2ops.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
smb2pdu.c cifs: fix potential memory leaks in session setup 2023-02-01 08:34:32 +01:00
smb2pdu.h
smb2proto.h
smb2status.h
smb2transport.c
smbdirect.c cifs: Fix oops due to uncleared server->smbd_conn in reconnect 2023-02-01 08:34:37 +01:00
smbdirect.h
smbencrypt.c
smberr.h
trace.c
trace.h
transport.c use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
unc.c
winucase.c
xattr.c