Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [BUG] nvmet: configfs string lifetime errors in local reads and discovery Identify
@ 2026-12-03 16:33 Rahul Priolkar
  0 siblings, 0 replies; only message in thread
From: Rahul Priolkar @ 2026-12-03 16:33 UTC (permalink / raw)
  To: Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni; +Cc: linux-nvme

Hello,

We first saw these KASAN reports on Linux v7.4-rc4 while configuring an
NVMe target as root. We repeated the tests on v7.4-rc5 (fe6ff8d5d675)
in an x86_64 KVM guest. We used nvme-loop for the host connection.

On rc5, configfs reads of the model, firmware revision, device path and
discovery NQN produced 68, 67, 66 and 175 KASAN reports respectively.
These included use-after-free and out-of-bounds reads. The discovery
controller also copied freed string data into its Identify response.
KASAN reported 64 use-after-free reads in that test.

We saw a separate use-after-free in nvmet_root_discovery_nqn_store()
during subsystem removal, followed by a general protection fault and a
guest panic. Each control ran for 60 seconds with the operations
serialized and produced no KASAN report.

The original rc4 traces below show a one-byte read while formatting the
model string, a one-byte read from a freed 96-byte region during
Identify, and an eight-byte read from a freed 1,024-byte region in the
NQN writer. The writer's log also shows the general protection fault.
Some of the saved logs end partway through a report.

Model string read in configfs

[   19.790059][ T4404] BUG: KASAN: slab-use-after-free in string+0x216/0x2d0
[   19.790082][ T4404] Read of size 1 at addr ffff88801eb89280 by task control-r4-nvme/4404
[   19.790092][ T4404] 
[   19.790099][ T4404] CPU: 1 UID: 0 PID: 4404 Comm: control-r4-nvme Not tainted 7.4.0-rc4 #2 PREEMPT(full) 
[   19.790112][ T4404] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[   19.790120][ T4404] Call Trace:
[   19.790130][ T4404]  <TASK>
[   19.790135][ T4404]  dump_stack_lvl+0xe8/0x150
[   19.790183][ T4404]  print_address_description+0x55/0x1e0
[   19.790218][ T4404]  print_report+0x58/0x70
[   19.790239][ T4404]  kasan_report+0x117/0x150
[   19.790294][ T4404]  string+0x216/0x2d0
[   19.790309][ T4404]  vsnprintf+0x74a/0xef0
[   19.790328][ T4404]  snprintf+0xe8/0x140
[   19.790401][ T4404]  nvmet_subsys_attr_model_show+0x54/0x60
[   19.790445][ T4404]  configfs_read_iter+0x2bc/0x630
[   19.790472][ T4404]  vfs_read+0x59a/0xa80
[   19.790624][ T4404]  ksys_read+0x155/0x270
[   19.790670][ T4404]  do_syscall_64+0x171/0x540
[   19.790701][ T4404]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[   19.790712][ T4404] RIP: 0033:0x457a82
[   19.790726][ T4404] Code: 08 0f 85 11 e3 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 55 48 89 e5
[   19.790735][ T4404] RSP: 002b:00007ff19dd60118 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
[   19.790749][ T4404] RAX: ffffffffffffffda RBX: 0000000000000005 RCX: 0000000000457a82
[   19.790757][ T4404] RDX: 0000000000000fff RSI: 00007ff19dd60150 RDI: 0000000000000005
[   19.790764][ T4404] RBP: 00007ff19dd60140 R08: 0000000000000000 R09: 0000000000000000
[   19.790772][ T4404] R10: 0000000000000000 R11: 0000000000000246 R12: 000000000049c0cc
[   19.790779][ T4404] R13: 00007ff19dd6014f R14: 0000000000000006 R15: 000000000049e778
[   19.790798][ T4404]  </TASK>
[   19.790802][ T4404] 
[   19.790804][ T4404] Allocated by task 4406:
[   19.790812][ T4404]  kasan_save_track+0x3f/0x90
[   19.790822][ T4404]  __kasan_kmalloc+0x93/0xb0
[   19.790832][ T4404]  __kmalloc_node_track_caller_noprof+0x4db/0x750
[   19.790855][ T4404]  kmemdup_nul+0x3b/0x100
[   19.790876][ T4404]  nvmet_subsys_attr_model_store+0x172/0x290
[   19.790888][ T4404]  configfs_write_iter+0x33c/0x430
[   19.790900][ T4404]  vfs_write+0x617/0xba0
[   19.790917][ T4404]  __x64_sys_pwrite64+0x215/0x2d0
[   19.790934][ T4404]  do_syscall_64+0x171/0x540
[   19.790947][ T4404]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[   19.790958][ T4404] 
[   19.790960][ T4404] Freed by task 4406:
[   19.790965][ T4404]  kasan_save_track+0x3f/0x90
[   19.790975][ T4404]  kasan_save_free_info+0x40/0x50
[   19.790990][ T4404]  __kasan_slab_free+0x70/0x90

Discovery controller Identify response

[   22.099068][   T46] BUG: KASAN: slab-use-after-free in strnlen+0x66/0x90
[   22.099090][   T46] Read of size 1 at addr ffff888023e248ab by task kworker/u16:2/46
[   22.099099][   T46] 
[   22.099104][   T46] CPU: 0 UID: 0 PID: 46 Comm: kworker/u16:2 Tainted: G    B               7.4.0-rc4 #2 PREEMPT(full) 
[   22.099120][   T46] Tainted: [B]=BAD_PAGE
[   22.099124][   T46] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[   22.099133][   T46] Workqueue: nvmet-wq nvme_loop_execute_work
[   22.099149][   T46] Call Trace:
[   22.099153][   T46]  <TASK>
[   22.099158][   T46]  dump_stack_lvl+0xe8/0x150
[   22.099177][   T46]  print_address_description+0x55/0x1e0
[   22.099215][   T46]  print_report+0x58/0x70
[   22.099230][   T46]  kasan_report+0x117/0x150
[   22.099271][   T46]  strnlen+0x66/0x90
[   22.099292][   T46]  nvmet_execute_disc_identify+0x508/0x7a0
[   22.099329][   T46]  process_scheduled_works+0xc42/0x1630
[   22.099437][   T46]  worker_thread+0xa4c/0xfb0
[   22.099467][   T46]  kthread+0x390/0x480
[   22.099515][   T46]  ret_from_fork+0x519/0xb70
[   22.099608][   T46]  ret_from_fork_asm+0x1a/0x30
[   22.099632][   T46]  </TASK>
[   22.099636][   T46] 
[   22.099639][   T46] Allocated by task 4397:
[   22.099644][   T46]  kasan_save_track+0x3f/0x90
[   22.099654][   T46]  __kasan_kmalloc+0x93/0xb0
[   22.099665][   T46]  __kmalloc_node_track_caller_noprof+0x4db/0x750
[   22.099683][   T46]  kstrndup+0x83/0x160
[   22.099698][   T46]  nvmet_root_discovery_nqn_store+0x6d/0x1a0
[   22.099718][   T46]  configfs_write_iter+0x33c/0x430
[   22.099731][   T46]  vfs_write+0x617/0xba0
[   22.099747][   T46]  __x64_sys_pwrite64+0x215/0x2d0
[   22.099765][   T46]  do_syscall_64+0x171/0x540
[   22.099779][   T46]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[   22.099790][   T46] 
[   22.099793][   T46] Freed by task 4397:
[   22.099798][   T46]  kasan_save_track+0x3f/0x90
[   22.099808][   T46]  kasan_save_free_info+0x40/0x50
[   22.099824][   T46]  __kasan_slab_free+0x70/0x90
[   22.099835][   T46]  kfree+0x1cc/0x650
[   22.099849][   T46]  nvmet_root_discovery_nqn_store+0x154/0x1a0
[   22.099868][   T46]  configfs_write_iter+0x33c/0x430
[   22.099882][   T46]  vfs_write+0x617/0xba0
[   22.099902][   T46]  __x64_sys_pwrite64+0x215/0x2d0
[   22.099920][   T46]  do_syscall_64+0x171/0x540
[   22.099934][   T46]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[   22.099945][   T46] 
[   22.099948][   T46] The buggy address belongs to the object at ffff888023e24880
[   22.099948][   T46]  which belongs to the cache kmalloc-96 of size 96
[   22.099957][   T46] The buggy address is located 43 bytes inside of
[   22.099957][   T46]  freed 96-byte region [ffff888023e24880, ffff888023e248e0)
[   22.099969][   T46] 
[   22.099972][   T46] The buggy address belongs to the physical page:
[   22.099977][   T46] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x23e24
[   22.099986][   T46] flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
[   22.099995][   T46] page_type: f5(slab)
[   22.100005][   T46] raw: 00fff00000000000 ffff88801bc42280 dead000000000100 dead000000000122
[   22.100015][   T46] raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
[   22.100022][   T46] page dumped because: kasan: bad access detected
[   22.100027][   T46] 
[   22.100029][   T46] Memory state around the buggy address:
[   22.100035][   T46]  ffff888023e24780: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
[   22.100046][   T46]  ffff888023e24800: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
[   22.100054][   T46] >ffff888023e24880: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
[   22.100061][   T46]                                   ^
[   22.100067][   T46]  ffff888023e24900: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
[   22.100075][   T46]  ffff888023e24980: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
[   22.100081][   T46] ==================================================================
[   22.100086][   T46] ==================================================================

Discovery NQN update during subsystem removal

[  266.571996][ T4531] BUG: KASAN: slab-use-after-free in nvmet_root_discovery_nqn_store+0xab/0x1a0
[  266.572017][ T4531] Read of size 8 at addr ffff88802cd5a970 by task control-r4-nvme/4531
[  266.572027][ T4531] 
[  266.572033][ T4531] CPU: 1 UID: 0 PID: 4531 Comm: control-r4-nvme Tainted: G    B               7.4.0-rc4 #2 PREEMPT(full) 
[  266.572048][ T4531] Tainted: [B]=BAD_PAGE
[  266.572053][ T4531] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[  266.572062][ T4531] Call Trace:
[  266.572066][ T4531]  <TASK>
[  266.572071][ T4531]  dump_stack_lvl+0xe8/0x150
[  266.572094][ T4531]  print_address_description+0x55/0x1e0
[  266.572130][ T4531]  print_report+0x58/0x70
[  266.572145][ T4531]  kasan_report+0x117/0x150
[  266.572187][ T4531]  nvmet_root_discovery_nqn_store+0xab/0x1a0
[  266.572229][ T4531]  configfs_write_iter+0x33c/0x430
[  266.572246][ T4531]  vfs_write+0x617/0xba0
[  266.572360][ T4531]  __x64_sys_pwrite64+0x215/0x2d0
[  266.572450][ T4531]  do_syscall_64+0x171/0x540
[  266.572482][ T4531]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  266.572495][ T4531] RIP: 0033:0x457a82
[  266.572504][ T4531] Code: 08 0f 85 11 e3 ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 <c3> 
[  266.572514][ T4531] RSP: 002b:00007fbb4ae10138 EFLAGS: 00000246 ORIG_RAX: 0000000000000012
[  266.572526][ T4531] RAX: ffffffffffffffda RBX: 000000000000415d RCX: 0000000000457a82
[  266.572535][ T4531] RDX: 000000000000005c RSI: 000000000049e928 RDI: 0000000000000004
[  266.572543][ T4531] RBP: 00007fbb4ae10160 R08: 0000000000000000 R09: 0000000000000000
[  266.572551][ T4531] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000004
[  266.572558][ T4531] R13: 00000000004dec40 R14: 0000000000000011 R15: 00007ffe749667f7
[  266.572577][ T4531]  </TASK>
[  266.572582][ T4531] 
[  266.572585][ T4531] Allocated by task 4530:
[  266.572592][ T4531]  kasan_save_track+0x3f/0x90
[  266.572603][ T4531]  __kasan_kmalloc+0x93/0xb0
[  266.572614][ T4531]  __kmalloc_cache_noprof+0x343/0x620
[  266.572631][ T4531]  nvmet_subsys_alloc+0xb4/0x6a0
[  266.572648][ T4531]  nvmet_subsys_make+0x9c/0x2d0
[  266.572666][ T4531]  configfs_mkdir+0x4fb/0x9e0
[  266.572679][ T4531]  vfs_mkdir+0x416/0x660
[  266.572689][ T4531]  filename_mkdirat+0x289/0x550
[  266.572699][ T4531]  __se_sys_mkdir+0x39/0x150
[  266.572710][ T4531]  do_syscall_64+0x171/0x540
[  266.572728][ T4531]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  266.572740][ T4531] 
[  266.572743][ T4531] Freed by task 4530:
[  266.572748][ T4531]  kasan_save_track+0x3f/0x90
[  266.572758][ T4531]  kasan_save_free_info+0x40/0x50
[  266.572774][ T4531]  __kasan_slab_free+0x70/0x90
[  266.572785][ T4531]  kfree+0x1cc/0x650
[  266.572799][ T4531]  config_item_release+0x13f/0x2e0
[  266.572816][ T4531]  configfs_rmdir+0x88a/0x950
[  266.572830][ T4531]  vfs_rmdir+0x3eb/0x6f0
[  266.572840][ T4531]  filename_rmdir+0x27b/0x500
[  266.572851][ T4531]  __se_sys_rmdir+0x33/0x150
[  266.572862][ T4531]  do_syscall_64+0x171/0x540
[  266.572876][ T4531]  entry_SYSCALL_64_after_hwframe+0x77/0x7f
[  266.572888][ T4531] 
[  266.572891][ T4531] The buggy address belongs to the object at ffff88802cd5a800
[  266.572891][ T4531]  which belongs to the cache kmalloc-1k of size 1024
[  266.572901][ T4531] The buggy address is located 368 bytes inside of
[  266.572901][ T4531]  freed 1024-byte region [ffff88802cd5a800, ffff88802cd5ac00)
[  266.572913][ T4531] 
[  266.572917][ T4531] The buggy address belongs to the physical page:
[  266.572922][ T4531] page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x2cd58
[  266.572932][ T4531] head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
[  266.572941][ T4531] flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)
[  266.572954][ T4531] page_type: f5(slab)
[  266.572964][ T4531] raw: 00fff00000000040 ffff88801bc42dc0 dead000000000100 dead000000000122
[  266.572974][ T4531] raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
[  266.572986][ T4531] head: 00fff00000000040 ffff88801bc42dc0 dead000000000100 dead000000000122
[  266.572997][ T4531] head: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
[  266.573008][ T4531] head: 00fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
[  266.573019][ T4531] head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
[  266.573026][ T4531] page dumped because: kasan: bad access detected
[  266.573031][ T4531] 
[  266.573034][ T4531] Memory state around the buggy address:
[  266.573040][ T4531]  ffff88802cd5a800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[  266.573048][ T4531]  ffff88802cd5a880: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[  266.573056][ T4531] >ffff88802cd5a900: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[  266.573063][ T4531]                                                              ^
[  266.573070][ T4531]  ffff88802cd5a980: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[  266.573078][ T4531]  ffff88802cd5aa00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
[  266.573085][ T4531] ==================================================================
[  266.573090][ T4531] ==================================================================
[  266.574247][ T4531] Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] SMP KASAN NOPTI
[  266.794766][ T4531] KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
[  266.795877][ T4531] CPU: 1 UID: 0 PID: 4531 Comm: control-r4-nvme Tainted: G    B               7.4.0-rc4 #2 PREEMPT(full) 
[  266.797358][ T4531] Tainted: [B]=BAD_PAGE
[  266.797922][ T4531] Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
[  266.799523][ T4531] RIP: 0010:strncmp+0x32/0xe0
[  266.800172][ T4531] Code: 56 41 55 41 54 53 48 85 d2 0f 84 a3 00 00 00 48 bb 00 00 00 00 00 fc ff df 48 ff ca 45 31 f6 4a 8d 04 37 48 89 c1 48 c1 e9 03 <0f> 
[  266.802714][ T4531] RSP: 0018:ffffc9000367fbe8 EFLAGS: 00010256
[  266.803532][ T4531] RAX: 0000000000000000 RBX: dffffc0000000000 RCX: 0000000000000000
[  266.804699][ T4531] RDX: 000000000000005b RSI: ffff88802d852000 RDI: 0000000000000000
[  266.805753][ T4531] RBP: dffffc0000000000 R08: ffffffff943330c7 R09: 1ffffffff2866618
[  266.806796][ T4531] R10: dffffc0000000000 R11: fffffbfff2866619 R12: ffff88802cd5a970
[  266.807840][ T4531] R13: 0000000000000000 R14: 0000000000000000 R15: ffff88802d852000
[  266.808889][ T4531] FS:  00007fbb4ae106c0(0000) GS:ffff88810d5b4000(0000) knlGS:0000000000000000
[  266.810069][ T4531] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  266.810938][ T4531] CR2: 000000000060d106 CR3: 0000000028400000 CR4: 0000000000750ef0
[  266.811985][ T4531] PKRU: 55555554
[  266.812464][ T4531] Call Trace:
[  266.812914][ T4531]  <TASK>
[  266.813315][ T4531]  nvmet_root_discovery_nqn_store+0xe4/0x1a0
[  266.815014][ T4531]  configfs_write_iter+0x33c/0x430
[  266.815707][ T4531]  vfs_write+0x617/0xba0
[  266.819654][ T4531]  __x64_sys_pwrite64+0x215/0x2d0
[  266.823265][ T4531]  do_syscall_64+0x171/0x540

Additional Identify and discovery NQN traces

BUG: KASAN: slab-use-after-free in strnlen+0x66/0x90
Read of size 1 at addr ffff888028d8841f by task kworker/u16:1/4550
CPU: 1 UID: 0 PID: 4550 Comm: kworker/u16:1 Tainted: G    B               7.4.0-rc4 #2 PREEMPT(full) 
Tainted: [B]=BAD_PAGE
Workqueue: nvmet-wq nvme_loop_execute_work
Call Trace:
 strnlen+0x66/0x90
 nvmet_execute_disc_identify+0x508/0x7a0
 process_scheduled_works+0xc42/0x1630
 worker_thread+0xa4c/0xfb0
 kthread+0x390/0x480
 ret_from_fork+0x519/0xb70
 ret_from_fork_asm+0x1a/0x30
Allocated by task 4570:
 __kmalloc_node_track_caller_noprof+0x4db/0x750
 kstrndup+0x83/0x160
 nvmet_root_discovery_nqn_store+0x6d/0x1a0
 configfs_write_iter+0x33c/0x430
 vfs_write+0x617/0xba0
 __x64_sys_pwrite64+0x215/0x2d0
 do_syscall_64+0x171/0x540
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 4570:
 kfree+0x1cc/0x650
 nvmet_root_discovery_nqn_store+0x154/0x1a0
 configfs_write_iter+0x33c/0x430
 vfs_write+0x617/0xba0
 __x64_sys_pwrite64+0x215/0x2d0
 do_syscall_64+0x171/0x540
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

BUG: KASAN: slab-use-after-free in nvmet_root_discovery_nqn_store+0xab/0x1a0
Read of size 8 at addr ffff88802b1ad170 by task control-nvmet-c/4410
CPU: 3 UID: 0 PID: 4410 Comm: control-nvmet-c Tainted: G    B               7.4.0-rc4 #2 PREEMPT(full) 
Tainted: [B]=BAD_PAGE
Call Trace:
 nvmet_root_discovery_nqn_store+0xab/0x1a0
 configfs_write_iter+0x33c/0x430
 vfs_write+0x617/0xba0
 __x64_sys_pwrite64+0x215/0x2d0
 do_syscall_64+0x171/0x540
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Allocated by task 4409:
 __kmalloc_cache_noprof+0x343/0x620
 nvmet_subsys_alloc+0xb4/0x6a0
 nvmet_subsys_make+0x9c/0x2d0
 configfs_mkdir+0x4fb/0x9e0
 vfs_mkdir+0x416/0x660
 filename_mkdirat+0x289/0x550
 __se_sys_mkdir+0x39/0x150
 do_syscall_64+0x171/0x540
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 4409:

Can you confirm these findings in nvmet?

Thanks,
Rahul Priolkar


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-12-03 16:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 16:33 [BUG] nvmet: configfs string lifetime errors in local reads and discovery Identify Rahul Priolkar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox