linux/drivers/nvme/target
Ming Lei 0fcee2cfc4 nvmet: fix race in nvmet_bio_done() leading to NULL pointer dereference
There is a race condition in nvmet_bio_done() that can cause a NULL
pointer dereference in blk_cgroup_bio_start():

1. nvmet_bio_done() is called when a bio completes
2. nvmet_req_complete() is called, which invokes req->ops->queue_response(req)
3. The queue_response callback can re-queue and re-submit the same request
4. The re-submission reuses the same inline_bio from nvmet_req
5. Meanwhile, nvmet_req_bio_put() (called after nvmet_req_complete)
   invokes bio_uninit() for inline_bio, which sets bio->bi_blkg to NULL
6. The re-submitted bio enters submit_bio_noacct_nocheck()
7. blk_cgroup_bio_start() dereferences bio->bi_blkg, causing a crash:

  BUG: kernel NULL pointer dereference, address: 0000000000000028
  #PF: supervisor read access in kernel mode
  RIP: 0010:blk_cgroup_bio_start+0x10/0xd0
  Call Trace:
   submit_bio_noacct_nocheck+0x44/0x250
   nvmet_bdev_execute_rw+0x254/0x370 [nvmet]
   process_one_work+0x193/0x3c0
   worker_thread+0x281/0x3a0

Fix this by reordering nvmet_bio_done() to call nvmet_req_bio_put()
BEFORE nvmet_req_complete(). This ensures the bio is cleaned up before
the request can be re-submitted, preventing the race condition.

Fixes: 190f4c2c86 ("nvmet: fix memory leak of bio integrity")
Cc: Dmitry Bogdanov <d.bogdanov@yadro.com>
Cc: stable@vger.kernel.org
Cc: Guangwu Zhang <guazhang@redhat.com>
Link: http://www.mail-archive.com/debian-kernel@lists.debian.org/msg146238.html
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Keith Busch <kbusch@kernel.org>
History 2026-01-21 07:21:19 -08:00
..
admin-cmd.c nvme: fix typo error in nvme target 2025-12-04 14:46:16 -08:00
auth.c nvme updates for Linux 6.19 2025-12-04 20:58:19 -07:00
configfs.c for-6.14/block-20250118 2025-01-20 19:38:46 -08:00
core.c nvme: fix typo error in nvme target 2025-12-04 14:46:16 -08:00
debugfs.c These are objtool fixes and updates by Josh Poimboeuf, centered 2025-04-02 10:30:10 -07:00
debugfs.h nvmet: add debugfs support 2024-06-24 12:53:42 -07:00
discovery.c nvmet: replace strncpy with strscpy 2025-05-20 05:34:25 +02:00
fabrics-cmd-auth.c nvmet-auth: update sc_c in target host hash calculation 2025-11-17 08:05:58 -08:00
fabrics-cmd.c nvmet: fabrics: add CQ init and destroy 2025-05-20 05:34:25 +02:00
fc.c nvmet-fc: use pr_* print macros instead of dev_* 2025-12-04 14:46:13 -08:00
fcloop.c nvmet-fcloop: remove unused lsdir member. 2025-12-04 14:46:11 -08:00
io-cmd-bdev.c nvmet: fix race in nvmet_bio_done() leading to NULL pointer dereference 2026-01-21 07:21:19 -08:00
io-cmd-file.c nvmet: use bvec_set_page to initialize bvecs 2023-02-03 08:20:55 -07:00
Kconfig crash_dump, nvme: select CONFIGFS_FS as built-in 2025-05-27 19:40:33 -07:00
loop.c nvme: remove virtual boundary for sgl capable devices 2025-11-06 18:11:58 -07:00
Makefile nvmet: New NVMe PCI endpoint function target driver 2025-01-10 19:30:49 -08:00
nvmet.h nvme updates for Linux 6.19 2025-12-04 20:58:19 -07:00
passthru.c nvmet: do not copy beyond sybsysnqn string length 2026-01-13 13:50:29 -08:00
pci-epf.c nvmet: pci-epf: fix DMA channel debug print 2025-12-01 13:45:56 -08:00
pr.c nvmet-loop: avoid using mutex in IO hotpath 2024-12-27 13:24:00 -08:00
rdma.c nvmet-rdma: use kvcalloc for commands and responses arrays 2025-12-04 14:46:16 -08:00
tcp.c nvmet-tcp: fixup hang in nvmet_tcp_listen_data_ready() 2026-01-13 07:29:46 -08:00
trace.c nvmet: add tracing of reservation commands 2024-11-13 08:51:24 -08:00
trace.h nvme: trace: avoid memcpy overflow warning 2024-01-05 13:16:18 -08:00
zns.c nvme: fix multiple spelling and grammar issues in host drivers 2025-07-17 13:38:06 +02:00