<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/fs/cifs/readdir.c, branch linux-5.4.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.4.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.4.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2025-06-04T12:32:36Z</updated>
<entry>
<title>smb: client: Reset all search buffer pointers when releasing buffer</title>
<updated>2025-06-04T12:32:36Z</updated>
<author>
<name>Wang Zhaolong</name>
</author>
<published>2025-05-16T09:12:56Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9f5748b6948174ec51d2a8a35598b224e74566d7'/>
<id>urn:sha1:9f5748b6948174ec51d2a8a35598b224e74566d7</id>
<content type='text'>
commit e48f9d849bfdec276eebf782a84fd4dfbe1c14c0 upstream.

Multiple pointers in struct cifs_search_info (ntwrk_buf_start,
srch_entries_start, and last_entry) point to the same allocated buffer.
However, when freeing this buffer, only ntwrk_buf_start was set to NULL,
while the other pointers remained pointing to freed memory.

This is defensive programming to prevent potential issues with stale
pointers. While the active UAF vulnerability is fixed by the previous
patch, this change ensures consistent pointer state and more robust error
handling.

Signed-off-by: Wang Zhaolong &lt;wangzhaolong1@huawei.com&gt;
Cc: stable@vger.kernel.org
Reviewed-by: Paulo Alcantara (Red Hat) &lt;pc@manguebit.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
Signed-off-by: Wang Zhaolong &lt;wangzhaolong1@huawei.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>smb: client: Fix use-after-free in cifs_fill_dirent</title>
<updated>2025-06-04T12:32:36Z</updated>
<author>
<name>Wang Zhaolong</name>
</author>
<published>2025-05-16T09:12:55Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=aee067e88d61eb72e966f094e4749c6b14e7008f'/>
<id>urn:sha1:aee067e88d61eb72e966f094e4749c6b14e7008f</id>
<content type='text'>
commit a7a8fe56e932a36f43e031b398aef92341bf5ea0 upstream.

There is a race condition in the readdir concurrency process, which may
access the rsp buffer after it has been released, triggering the
following KASAN warning.

 ==================================================================
 BUG: KASAN: slab-use-after-free in cifs_fill_dirent+0xb03/0xb60 [cifs]
 Read of size 4 at addr ffff8880099b819c by task a.out/342975

 CPU: 2 UID: 0 PID: 342975 Comm: a.out Not tainted 6.15.0-rc6+ #240 PREEMPT(full)
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.1-2.fc37 04/01/2014
 Call Trace:
  &lt;TASK&gt;
  dump_stack_lvl+0x53/0x70
  print_report+0xce/0x640
  kasan_report+0xb8/0xf0
  cifs_fill_dirent+0xb03/0xb60 [cifs]
  cifs_readdir+0x12cb/0x3190 [cifs]
  iterate_dir+0x1a1/0x520
  __x64_sys_getdents+0x134/0x220
  do_syscall_64+0x4b/0x110
  entry_SYSCALL_64_after_hwframe+0x76/0x7e
 RIP: 0033:0x7f996f64b9f9
 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89
 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 &lt;48&gt; 3d 01
 f0 ff ff  0d f7 c3 0c 00 f7 d8 64 89 8
 RSP: 002b:00007f996f53de78 EFLAGS: 00000207 ORIG_RAX: 000000000000004e
 RAX: ffffffffffffffda RBX: 00007f996f53ecdc RCX: 00007f996f64b9f9
 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003
 RBP: 00007f996f53dea0 R08: 0000000000000000 R09: 0000000000000000
 R10: 0000000000000000 R11: 0000000000000207 R12: ffffffffffffff88
 R13: 0000000000000000 R14: 00007ffc8cd9a500 R15: 00007f996f51e000
  &lt;/TASK&gt;

 Allocated by task 408:
  kasan_save_stack+0x20/0x40
  kasan_save_track+0x14/0x30
  __kasan_slab_alloc+0x6e/0x70
  kmem_cache_alloc_noprof+0x117/0x3d0
  mempool_alloc_noprof+0xf2/0x2c0
  cifs_buf_get+0x36/0x80 [cifs]
  allocate_buffers+0x1d2/0x330 [cifs]
  cifs_demultiplex_thread+0x22b/0x2690 [cifs]
  kthread+0x394/0x720
  ret_from_fork+0x34/0x70
  ret_from_fork_asm+0x1a/0x30

 Freed by task 342979:
  kasan_save_stack+0x20/0x40
  kasan_save_track+0x14/0x30
  kasan_save_free_info+0x3b/0x60
  __kasan_slab_free+0x37/0x50
  kmem_cache_free+0x2b8/0x500
  cifs_buf_release+0x3c/0x70 [cifs]
  cifs_readdir+0x1c97/0x3190 [cifs]
  iterate_dir+0x1a1/0x520
  __x64_sys_getdents64+0x134/0x220
  do_syscall_64+0x4b/0x110
  entry_SYSCALL_64_after_hwframe+0x76/0x7e

 The buggy address belongs to the object at ffff8880099b8000
  which belongs to the cache cifs_request of size 16588
 The buggy address is located 412 bytes inside of
  freed 16588-byte region [ffff8880099b8000, ffff8880099bc0cc)

 The buggy address belongs to the physical page:
 page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x99b8
 head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
 anon flags: 0x80000000000040(head|node=0|zone=1)
 page_type: f5(slab)
 raw: 0080000000000040 ffff888001e03400 0000000000000000 dead000000000001
 raw: 0000000000000000 0000000000010001 00000000f5000000 0000000000000000
 head: 0080000000000040 ffff888001e03400 0000000000000000 dead000000000001
 head: 0000000000000000 0000000000010001 00000000f5000000 0000000000000000
 head: 0080000000000003 ffffea0000266e01 00000000ffffffff 00000000ffffffff
 head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
 page dumped because: kasan: bad access detected

 Memory state around the buggy address:
  ffff8880099b8080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8880099b8100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 &gt;ffff8880099b8180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                             ^
  ffff8880099b8200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
  ffff8880099b8280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ==================================================================

POC is available in the link [1].

The problem triggering process is as follows:

Process 1                       Process 2
-----------------------------------------------------------------
cifs_readdir
  /* file-&gt;private_data == NULL */
  initiate_cifs_search
    cifsFile = kzalloc(sizeof(struct cifsFileInfo), GFP_KERNEL);
    smb2_query_dir_first -&gt;query_dir_first()
      SMB2_query_directory
        SMB2_query_directory_init
        cifs_send_recv
        smb2_parse_query_directory
          srch_inf-&gt;ntwrk_buf_start = (char *)rsp;
          srch_inf-&gt;srch_entries_start = (char *)rsp + ...
          srch_inf-&gt;last_entry = (char *)rsp + ...
          srch_inf-&gt;smallBuf = true;
  find_cifs_entry
    /* if (cfile-&gt;srch_inf.ntwrk_buf_start) */
    cifs_small_buf_release(cfile-&gt;srch_inf // free

                        cifs_readdir  -&gt;iterate_shared()
                          /* file-&gt;private_data != NULL */
                          find_cifs_entry
                            /* in while (...) loop */
                            smb2_query_dir_next  -&gt;query_dir_next()
                              SMB2_query_directory
                                SMB2_query_directory_init
                                cifs_send_recv
                                  compound_send_recv
                                    smb_send_rqst
                                    __smb_send_rqst
                                      rc = -ERESTARTSYS;
                                      /* if (fatal_signal_pending()) */
                                      goto out;
                                      return rc
                            /* if (cfile-&gt;srch_inf.last_entry) */
                            cifs_save_resume_key()
                              cifs_fill_dirent // UAF
                            /* if (rc) */
                            return -ENOENT;

Fix this by ensuring the return code is checked before using pointers
from the srch_inf.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=220131 [1]
Fixes: a364bc0b37f1 ("[CIFS] fix saving of resume key before CIFSFindNext")
Cc: stable@vger.kernel.org
Reviewed-by: Paulo Alcantara (Red Hat) &lt;pc@manguebit.com&gt;
Signed-off-by: Wang Zhaolong &lt;wangzhaolong1@huawei.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
Signed-off-by: Wang Zhaolong &lt;wangzhaolong1@huawei.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>cifs: check ntwrk_buf_start for NULL before dereferencing it</title>
<updated>2018-12-24T04:41:31Z</updated>
<author>
<name>Ronnie Sahlberg</name>
</author>
<published>2018-12-12T22:06:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=59a63e479ce36a3f24444c3a36efe82b78e4a8e0'/>
<id>urn:sha1:59a63e479ce36a3f24444c3a36efe82b78e4a8e0</id>
<content type='text'>
RHBZ: 1021460

There is an issue where when multiple threads open/close the same directory
ntwrk_buf_start might end up being NULL, causing the call to smbCalcSize
later to oops with a NULL deref.

The real bug is why this happens and why this can become NULL for an
open cfile, which should not be allowed.
This patch tries to avoid a oops until the time when we fix the underlying
issue.

Signed-off-by: Ronnie Sahlberg &lt;lsahlber@redhat.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
</content>
</entry>
<entry>
<title>cifs: prevent integer overflow in nxt_dir_entry()</title>
<updated>2018-09-12T14:27:57Z</updated>
<author>
<name>Dan Carpenter</name>
</author>
<published>2018-09-06T09:47:51Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8ad8aa353524d89fa2e09522f3078166ff78ec42'/>
<id>urn:sha1:8ad8aa353524d89fa2e09522f3078166ff78ec42</id>
<content type='text'>
The "old_entry + le32_to_cpu(pDirInfo-&gt;NextEntryOffset)" can wrap
around so I have added a check for integer overflow.

Reported-by: Dr Silvio Cesare of InfoSect &lt;silvio.cesare@gmail.com&gt;
Reviewed-by: Ronnie Sahlberg &lt;lsahlber@redhat.com&gt;
Reviewed-by: Aurelien Aptel &lt;aaptel@suse.com&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Steve French &lt;stfrench@microsoft.com&gt;
CC: Stable &lt;stable@vger.kernel.org&gt;
</content>
</entry>
<entry>
<title>cifs: update calc_size to take a server argument</title>
<updated>2018-05-27T22:56:35Z</updated>
<author>
<name>Ronnie Sahlberg</name>
</author>
<published>2018-04-22T21:30:12Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=9ec672bd17131fe26c966960a573a76fdb1da323'/>
<id>urn:sha1:9ec672bd17131fe26c966960a573a76fdb1da323</id>
<content type='text'>
and change the smb2 version to take heder_preamble_size into account
instead of hardcoding it as 4 bytes.

Signed-off-by: Ronnie Sahlberg &lt;lsahlber@redhat.com&gt;
Signed-off-by: Steve French &lt;smfrench@gmail.com&gt;
</content>
</entry>
<entry>
<title>cifs: initialize file_info_lock</title>
<updated>2017-01-14T20:58:29Z</updated>
<author>
<name>Rabin Vincent</name>
</author>
<published>2017-01-13T14:00:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=81ddd8c0c5e1cb41184d66567140cb48c53eb3d1'/>
<id>urn:sha1:81ddd8c0c5e1cb41184d66567140cb48c53eb3d1</id>
<content type='text'>
Reviewed-by: Jeff Layton &lt;jlayton@redhat.com&gt;
CC: Stable &lt;stable@vger.kernel.org&gt;

file_info_lock is not initalized in initiate_cifs_search(), leading to the
following splat after a simple "mount.cifs ... dir &amp;&amp; ls dir/":

 BUG: spinlock bad magic on CPU#0, ls/486
  lock: 0xffff880009301110, .magic: 00000000, .owner: &lt;none&gt;/-1, .owner_cpu: 0
 CPU: 0 PID: 486 Comm: ls Not tainted 4.9.0 #27
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)
  ffffc900042f3db0 ffffffff81327533 0000000000000000 ffff880009301110
  ffffc900042f3dd0 ffffffff810baf75 ffff880009301110 ffffffff817ae077
  ffffc900042f3df0 ffffffff810baff6 ffff880009301110 ffff880008d69900
 Call Trace:
  [&lt;ffffffff81327533&gt;] dump_stack+0x65/0x92
  [&lt;ffffffff810baf75&gt;] spin_dump+0x85/0xe0
  [&lt;ffffffff810baff6&gt;] spin_bug+0x26/0x30
  [&lt;ffffffff810bb159&gt;] do_raw_spin_lock+0xe9/0x130
  [&lt;ffffffff8159ad2f&gt;] _raw_spin_lock+0x1f/0x30
  [&lt;ffffffff8127e50d&gt;] cifs_closedir+0x4d/0x100
  [&lt;ffffffff81181cfd&gt;] __fput+0x5d/0x160
  [&lt;ffffffff81181e3e&gt;] ____fput+0xe/0x10
  [&lt;ffffffff8109410e&gt;] task_work_run+0x7e/0xa0
  [&lt;ffffffff81002512&gt;] exit_to_usermode_loop+0x92/0xa0
  [&lt;ffffffff810026f9&gt;] syscall_return_slowpath+0x49/0x50
  [&lt;ffffffff8159b484&gt;] entry_SYSCALL_64_fastpath+0xa7/0xa9

Fixes: 3afca265b5f53a0 ("Clarify locking of cifs file and tcon structures and make more granular")
Signed-off-by: Rabin Vincent &lt;rabinv@axis.com&gt;
Signed-off-by: Steve French &lt;smfrench@gmail.com&gt;
</content>
</entry>
<entry>
<title>Clarify locking of cifs file and tcon structures and make more granular</title>
<updated>2016-10-12T17:08:32Z</updated>
<author>
<name>Steve French</name>
</author>
<published>2016-09-22T23:58:16Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3afca265b5f53a0b15b79531c13858049505582d'/>
<id>urn:sha1:3afca265b5f53a0b15b79531c13858049505582d</id>
<content type='text'>
Remove the global file_list_lock to simplify cifs/smb3 locking and
have spinlocks that more closely match the information they are
protecting.

Add new tcon-&gt;open_file_lock and file-&gt;file_info_lock spinlocks.
Locks continue to follow a heirachy,
	cifs_socket --&gt; cifs_ses --&gt; cifs_tcon --&gt; cifs_file
where global tcp_ses_lock still protects socket and cifs_ses, while the
the newer locks protect the lower level structure's information
(tcon and cifs_file respectively).

CC: Stable &lt;stable@vger.kernel.org&gt;
Signed-off-by: Steve French &lt;steve.french@primarydata.com&gt;
Signed-off-by: Pavel Shilovsky &lt;pshilov@microsoft.com&gt;
Reviewed-by: Aurelien Aptel &lt;aaptel@suse.com&gt;
Reviewed-by: Germano Percossi &lt;germano.percossi@citrix.com&gt;
</content>
</entry>
<entry>
<title>cifs: Use file_dentry()</title>
<updated>2016-05-17T19:09:33Z</updated>
<author>
<name>Goldwyn Rodrigues</name>
</author>
<published>2016-04-18T11:41:52Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=1f1735cb75ab31ed948a7fce65beaaa6c0ed4ed4'/>
<id>urn:sha1:1f1735cb75ab31ed948a7fce65beaaa6c0ed4ed4</id>
<content type='text'>
CIFS may be used as lower layer of overlayfs and accessing f_path.dentry can
lead to a crash.

Fix by replacing direct access of file-&gt;f_path.dentry with the
file_dentry() accessor, which will always return a native object.

Signed-off-by: Goldwyn Rodrigues &lt;rgoldwyn@suse.com&gt;
Acked-by: Shirish Pargaonkar &lt;shirishpargaonkar@gmail.com&gt;
Signed-off-by: Steve French &lt;smfrench@gmail.com&gt;
</content>
</entry>
<entry>
<title>cifs: switch to -&gt;iterate_shared()</title>
<updated>2016-05-02T23:49:31Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2016-04-20T21:40:47Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=3125d2650cae97d8f313ab696cd0ed66916e767a'/>
<id>urn:sha1:3125d2650cae97d8f313ab696cd0ed66916e767a</id>
<content type='text'>
Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
</content>
</entry>
<entry>
<title>don't bother with -&gt;d_inode-&gt;i_sb - it's always equal to -&gt;d_sb</title>
<updated>2016-04-10T21:11:51Z</updated>
<author>
<name>Al Viro</name>
</author>
<published>2016-04-10T05:33:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=fc64005c93090c052637f63578d810b037abb1a1'/>
<id>urn:sha1:fc64005c93090c052637f63578d810b037abb1a1</id>
<content type='text'>
... and neither can ever be NULL

Signed-off-by: Al Viro &lt;viro@zeniv.linux.org.uk&gt;
</content>
</entry>
</feed>
