mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rohinthan P <rokinthanp03@gmail.com>
To: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+95fdab36405e5ffdb680@syzkaller.appspotmail.com
Cc: Rohinthan P <rokinthanp03@gmail.com>
Subject: [PATCH] null_blk: reject blocking/memory-backed devices sharing non-blocking tag set
Date: Wed, 23 Sep 2026 12:31:26 +0530	[thread overview]
Message-ID: <20260923070126.21936-1-rokinthanp03@gmail.com> (raw)

When a null_blk device is configured via configfs with shared_tags=1
and memory_backed=1 (or blocking=1), null_validate_conf() sets
dev->blocking = true because memory-backed devices allocate memory
during request handling.

However, when dev->shared_tags is enabled, the device uses the global
tag_set. The global tag_set is initialized by null_init_global_tag_set()
according to the module parameter g_blocking. If the module was loaded
without blocking=1 (g_blocking == false, the default), the global
tag_set does not have BLK_MQ_F_BLOCKING set in tag_set.flags.

Consequently, blk_mq_run_dispatch_ops() dispatches requests holding an
RCU read lock (rcu_read_lock()) rather than SRCU. During I/O execution,
null_queue_rq() -> null_handle_memory_backed() -> null_insert_page()
calls null_alloc_page(), which invokes kmalloc(..., GFP_NOIO),
alloc_pages(GFP_NOIO, 0), and radix_tree_preload(GFP_NOIO). Because
GFP_NOIO can sleep, this triggers a sleeping-in-invalid-context bug:

    BUG: sleeping function called from invalid context at include/linux/sched/mm.h:322
    in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 6031
    RCU nest depth: 1, expected: 0
    1 lock held by syz-executor:
     #0: rcu_read_lock at blk_mq_dispatch_queue_requests
    Call Trace:
     dump_stack_lvl
     __might_resched
     might_alloc
     null_alloc_page drivers/block/null_blk/main.c:878
     null_insert_page drivers/block/null_blk/main.c:1027
     copy_to_nullb drivers/block/null_blk/main.c:1165
     null_handle_memory_backed drivers/block/null_blk/main.c:1388
     null_queue_rq drivers/block/null_blk/main.c:1711
     blk_mq_dispatch_queue_requests block/blk-mq.c:2872

Reject configurations in null_validate_conf() where a blocking or
memory-backed device attempts to share a non-blocking global tag set
(dev->shared_tags && dev->blocking && !g_blocking).

Fixes: 14509b748ff5 ("null_blk: add configfs variable shared_tags")
Reported-by: syzbot+95fdab36405e5ffdb680@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=95fdab36405e5ffdb680
Signed-off-by: Rohinthan P <rokinthanp03@gmail.com>
---
 drivers/block/null_blk/main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 4a9beec..64b8bee 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -1940,6 +1940,11 @@ static int null_validate_conf(struct nullb_device *dev)
 		return -EINVAL;
 	}
 
+	if (dev->shared_tags && dev->blocking && !g_blocking) {
+		pr_err("blocking/memory-backed devices cannot share non-blocking tag set\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.53.0


                 reply	other threads:[~2026-09-23  7:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260923070126.21936-1-rokinthanp03@gmail.com \
    --to=rokinthanp03@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=syzbot+95fdab36405e5ffdb680@syzkaller.appspotmail.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®