linux/drivers/nvme/target
Ming Lei ee10b06980 nvmet: fix race in nvmet_bio_done() leading to NULL pointer dereference
commit 0fcee2cfc4 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-02-06 16:55:45 +01:00
..
admin-cmd.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
auth.c block-6.12-20241101 2024-11-01 13:41:55 -10:00
configfs.c nvmet: Don't overflow subsysnqn 2025-01-09 13:33:40 +01:00
core.c nvmet: exit debugfs after discovery subsystem exits 2025-08-15 12:14:08 +02:00
debugfs.c objtool, nvmet: Fix out-of-bounds stack access in nvmet_ctrl_state_show() 2025-04-10 14:39:26 +02:00
debugfs.h nvmet: add debugfs support 2024-06-24 12:53:42 -07:00
discovery.c nvme: rename CDR/MORE/DNR to NVME_STATUS_* 2024-06-24 12:53:42 -07:00
fabrics-cmd-auth.c for-6.11/block-20240710 2024-07-15 14:20:22 -07:00
fabrics-cmd.c for-6.11/block-20240710 2024-07-15 14:20:22 -07:00
fc.c nvmet-fc: avoid scheduling association deletion twice 2025-11-13 15:34:06 -05:00
fcloop.c nvmet-fcloop: access fcpreq only when holding reqlock 2025-06-19 15:32:32 +02:00
io-cmd-bdev.c nvmet: fix race in nvmet_bio_done() leading to NULL pointer dereference 2026-02-06 16:55:45 +01:00
io-cmd-file.c nvmet: use bvec_set_page to initialize bvecs 2023-02-03 08:20:55 -07:00
Kconfig nvmet-tcp: select CONFIG_TLS from CONFIG_NVME_TARGET_TCP_TLS 2025-05-09 09:50:46 +02:00
loop.c nvme-loop: flush off pending I/O while shutting down loop controller 2024-10-17 11:07:37 -07:00
Makefile nvmet: add debugfs support 2024-06-24 12:53:42 -07:00
nvmet.h nvmet: fix memory leak of bio integrity 2025-07-10 16:04:49 +02:00
passthru.c nvmet-passthru: clear EUID/NGUID/UUID while using loop target 2024-10-01 11:08:40 -07:00
rdma.c nvmet-rdma: recheck queue state is LIVE in state lock in recv done 2025-03-22 12:54:19 -07:00
tcp.c nvme-tcp: fix NULL pointer dereferences in nvmet_tcp_build_pdu_iovec 2026-01-23 11:18:36 +01:00
trace.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
trace.h nvme: trace: avoid memcpy overflow warning 2024-01-05 13:16:18 -08:00
zns.c nvme: rename CDR/MORE/DNR to NVME_STATUS_* 2024-06-24 12:53:42 -07:00