mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namjae Jeon <linkinjeon@kernel.org>
To: Jaegyun Lee <dreams200260@gmail.com>
Cc: Paulo Alcantara <pc@manguebit.org>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>,
	 Shyam Prasad N <sprasad@microsoft.com>,
	Tom Talpey <tom@talpey.com>,
	 Bharath SM <bharathsm@microsoft.com>,
	linux-cifs@vger.kernel.org,  samba-technical@lists.samba.org,
	linux-kernel@vger.kernel.org,  stable@vger.kernel.org
Subject: Re: [PATCH] smb: client: fix use-after-free read of nativeFileSystem
Date: Sat, 5 Dec 2026 16:19:53 +0900	[thread overview]
Message-ID: <CAKYAXd-i8YxxdBCvec4iCMtbw9SoqELW7SibAXhN5PqMBafcXQ@mail.gmail.com> (raw)
In-Reply-To: <20261205035632.1328739-1-dreams200260@gmail.com>

On Sat, Dec 5, 2026 at 12:56 PM Jaegyun Lee <dreams200260@gmail.com> wrote:
>
> CIFSTCon() replaces the share's nativeFileSystem string on every tree
> connect, including the ones a reconnect does, and frees the old string
> before the new one is stored:
>
>         kfree(tcon->nativeFileSystem);
>         tcon->nativeFileSystem = cifs_strndup_from_utf16(bcc_ptr,
>                                                       bytes_left, is_unicode,
>                                                       ses->local_nls);
>
> cifs_debug_tcon() prints that string with %s from
> /proc/fs/cifs/DebugData under cifs_tcp_ses_lock, a lock CIFSTCon() does
> not take. A reader of DebugData that runs while a reconnect is between
> the kfree() and the new assignment prints freed memory:
>
> Trigger: an SMB1 mount whose server answers every read with
> STATUS_NETWORK_NAME_DELETED, so each read reconnects the share, while
> another process reads /proc/fs/cifs/DebugData.
> [   43.408061][ T9575] BUG: KASAN: slab-use-after-free in string+0x4a9/0x4f0
> [   43.408077][ T9575] Read of size 1 at addr ffff88801dff5800 by task smb1cli/9575
> [   43.408086][ T9575]
> [   43.408091][ T9575] CPU: 0 UID: 0 PID: 9575 Comm: smb1cli Not tainted 7.4.0-rc5-1492227-gc3500c5ef648 #1 PREEMPT(full)
> [   43.408105][ T9575] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
> [   43.408111][ T9575] Call Trace:
> [   43.408115][ T9575]  <TASK>
> [   43.408119][ T9575]  dump_stack_lvl+0x116/0x1b0
> [   43.408137][ T9575]  print_report+0xf1/0x5c0
> [   43.408149][ T9575]  ? __virt_addr_valid+0x238/0x430
> [   43.408163][ T9575]  ? string+0x4a9/0x4f0
> [   43.408174][ T9575]  kasan_report+0xca/0x100
> [   43.408185][ T9575]  ? string+0x4a9/0x4f0
> [   43.408197][ T9575]  string+0x4a9/0x4f0
> [   43.408209][ T9575]  ? __pfx_string+0x10/0x10
> [   43.408220][ T9575]  ? __pfx_convert_num_spec+0x10/0x10
> [   43.408233][ T9575]  vsnprintf+0x654/0x1250
> [   43.408247][ T9575]  ? __pfx_vsnprintf+0x10/0x10
> [   43.408261][ T9575]  seq_printf+0x19b/0x250
> [   43.408273][ T9575]  ? __pfx_seq_printf+0x10/0x10
> [   43.408284][ T9575]  ? __pfx_seq_printf+0x10/0x10
> [   43.408296][ T9575]  ? seq_printf+0x1e1/0x250
> [   43.408307][ T9575]  cifs_debug_tcon+0xd4/0x830
> [   43.408326][ T9575]  ? seq_putc+0x62/0xf0
> [   43.408336][ T9575]  cifs_debug_data_proc_show+0xef4/0x2690
> [   43.408349][ T9575]  ? __kvmalloc_node_noprof+0x3a7/0x980
> [   43.408366][ T9575]  seq_read_iter+0x516/0x12e0
> [   43.408380][ T9575]  proc_reg_read_iter+0x20e/0x2e0
> [   43.408392][ T9575]  vfs_read+0x865/0xc70
> [   43.408404][ T9575]  ? __pfx_vfs_read+0x10/0x10
> [   43.408418][ T9575]  ksys_read+0x121/0x240
> [   43.408429][ T9575]  ? __pfx_ksys_read+0x10/0x10
> [   43.408441][ T9575]  do_syscall_64+0x132/0x7c0
> [   43.408455][ T9575]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> [   43.408467][ T9575] RIP: 0033:0x44decc
> [   43.408475][ T9575] Code: ec 28 48 89 54 24 18 48 89 74 24 10 89 7c 24 08 e8 b9 b1 02 00 48 8b 54 24 18 48 8b 74 24 10 41 89 c0 8b 7c 24 08 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 34 44 89 c7 48 89 44 24 08 e8 ff b1 02 00 48
> [   43.408486][ T9575] RSP: 002b:00007f9f2cbfa190 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
> [   43.408497][ T9575] RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 000000000044decc
> [   43.408504][ T9575] RDX: 0000000000020000 RSI: 0000000000526320 RDI: 0000000000000004
> [   43.408511][ T9575] RBP: 0000000000526320 R08: 0000000000000000 R09: 00007ffecd26103f
> [   43.408518][ T9575] R10: 0000000000000000 R11: 0000000000000246 R12: 00000000004b302e
> [   43.408524][ T9575] R13: 000000000000000b R14: 0000000000416d70 R15: 00007f9f2c3fa000
> [   43.408534][ T9575]  </TASK>
> [   43.408537][ T9575]
> [   43.408539][ T9575] Allocated by task 9572:
> [   43.408544][ T9575]  kasan_save_stack+0x24/0x50
> [   43.408553][ T9575]  kasan_save_track+0x14/0x40
> [   43.408562][ T9575]  __kasan_kmalloc+0xaa/0xb0
> [   43.408570][ T9575]  __kmalloc_noprof+0x357/0x810
> [   43.408582][ T9575]  cifs_strndup_from_utf16+0xe2/0x170
> [   43.408594][ T9575]  CIFSTCon+0x935/0x1590
> [   43.408608][ T9575]  cifs_tree_connect+0x41b/0x1690
> [   43.408619][ T9575]  cifs_reconnect_tcon.part.0+0x889/0xd30
> [   43.408632][ T9575]  small_smb_init+0x30/0x130
> [   43.408644][ T9575]  cifs_async_readv+0x25b/0x1230
> [   43.408652][ T9575]  cifs_issue_read+0x3e7/0x930
> [   43.408663][ T9575]  netfs_unbuffered_read_iter_locked+0x5dc/0x1230
> [   43.408678][ T9575]  netfs_unbuffered_read_iter+0xca/0x100
> [   43.408692][ T9575]  cifs_strict_readv+0x1c8/0x940
> [   43.408706][ T9575]  vfs_read+0x865/0xc70
> [   43.408715][ T9575]  ksys_read+0x121/0x240
> [   43.408724][ T9575]  do_syscall_64+0x132/0x7c0
> [   43.408736][ T9575]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> [   43.408745][ T9575]
> [   43.408747][ T9575] Freed by task 9572:
> [   43.408752][ T9575]  kasan_save_stack+0x24/0x50
> [   43.408761][ T9575]  kasan_save_track+0x14/0x40
> [   43.408769][ T9575]  kasan_save_free_info+0x3b/0x60
> [   43.408781][ T9575]  __kasan_slab_free+0x75/0x90
> [   43.408790][ T9575]  kfree+0x2cc/0x6e0
> [   43.408800][ T9575]  CIFSTCon+0x8fb/0x1590
> [   43.408812][ T9575]  cifs_tree_connect+0x41b/0x1690
> [   43.408823][ T9575]  cifs_reconnect_tcon.part.0+0x889/0xd30
> [   43.408836][ T9575]  small_smb_init+0x30/0x130
> [   43.408848][ T9575]  cifs_async_readv+0x25b/0x1230
> [   43.408856][ T9575]  cifs_issue_read+0x3e7/0x930
> [   43.408866][ T9575]  netfs_unbuffered_read_iter_locked+0x5dc/0x1230
> [   43.408880][ T9575]  netfs_unbuffered_read_iter+0xca/0x100
> [   43.408894][ T9575]  cifs_strict_readv+0x1c8/0x940
> [   43.408906][ T9575]  vfs_read+0x865/0xc70
> [   43.408915][ T9575]  ksys_read+0x121/0x240
> [   43.408924][ T9575]  do_syscall_64+0x132/0x7c0
> [   43.408936][ T9575]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
> [   43.408945][ T9575]
> [   43.408947][ T9575] The buggy address belongs to the object at ffff88801dff5800
> [   43.408947][ T9575]  which belongs to the cache kmalloc-1k of size 1024
> [   43.408955][ T9575] The buggy address is located 0 bytes inside of
> [   43.408955][ T9575]  freed 1024-byte region [ffff88801dff5800, ffff88801dff5c00)
> [   43.408966][ T9575]
> [   43.408968][ T9575] The buggy address belongs to the physical page:
> [   43.408972][ T9575] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1dff0
> [   43.408981][ T9575] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
> [   43.408989][ T9575] flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
> [   43.408999][ T9575] page_type: f5(slab)
> [   43.409008][ T9575] raw: 00fff00000000040 ffff88801d041dc0 dead000000000100 dead000000000122
> [   43.409018][ T9575] raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
> [   43.409030][ T9575] head: 00fff00000000040 ffff88801d041dc0 dead000000000100 dead000000000122
> [   43.409040][ T9575] head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
> [   43.409051][ T9575] head: 00fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
> [   43.409060][ T9575] head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
> [   43.409066][ T9575] page dumped because: kasan: bad access detected
> [   43.409072][ T9575] page_owner tracks the page as allocated
> [   43.409076][ T9575] page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 1009045606
> [   43.409093][ T9575]  post_alloc_hook+0xff/0x130
> [   43.409104][ T9575]  get_page_from_freelist+0xdf0/0x2a10
> [   43.409116][ T9575]  __alloc_frozen_pages_noprof+0x28b/0x2dd0
> [   43.409127][ T9575]  new_slab+0xb9/0x6b0
> [   43.409138][ T9575]  refill_objects+0x10e/0x3d0
> [   43.409149][ T9575]  __pcs_replace_empty_main+0x35a/0x680
> [   43.409160][ T9575]  __kvmalloc_node_noprof+0x75a/0x980
> [   43.409174][ T9575]  bucket_table_alloc+0x98/0x4e0
> [   43.409187][ T9575]  __rhashtable_init_noprof+0x468/0x9d0
> [   43.409199][ T9575]  netlink_proto_init+0xf3/0x360
> [   43.409210][ T9575]  do_one_initcall+0x107/0x6d0
> [   43.409222][ T9575]  kernel_init_freeable+0x5b4/0x8e0
> [   43.409235][ T9575]  kernel_init+0x23/0x2d0
> [   43.409244][ T9575]  ret_from_fork+0xb0c/0xdb0
> [   43.409257][ T9575]  ret_from_fork_asm+0x1a/0x30
> [   43.409268][ T9575] page_owner free stack trace missing
> [   43.409271][ T9575]
> [   43.409273][ T9575] Memory state around the buggy address:
> [   43.409278][ T9575]  ffff88801dff5700: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> [   43.409285][ T9575]  ffff88801dff5780: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> [   43.409292][ T9575] >ffff88801dff5800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [   43.409297][ T9575]                    ^
> [   43.409302][ T9575]  ffff88801dff5880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [   43.409309][ T9575]  ffff88801dff5900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> [   43.409314][ T9575] ==================================================================
>
> Replace the pointer under cifs_tcp_ses_lock and free the old string
> afterwards.
>
> Fixes: 90a98b2f3f36 ("cifs: free nativeFileSystem field before allocating a new one")
> Cc: stable@vger.kernel.org
> Assisted-by: ZCode:GLM-5.4
> Signed-off-by: Jaegyun Lee <dreams200260@gmail.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Thanks.

      reply	other threads:[~2026-12-05  7:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:56 Jaegyun Lee
2026-12-05  7:19 ` Namjae Jeon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKYAXd-i8YxxdBCvec4iCMtbw9SoqELW7SibAXhN5PqMBafcXQ@mail.gmail.com \
    --to=linkinjeon@kernel.org \
    --cc=bharathsm@microsoft.com \
    --cc=dreams200260@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pc@manguebit.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=samba-technical@lists.samba.org \
    --cc=sprasad@microsoft.com \
    --cc=stable@vger.kernel.org \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®