Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68F8D379982; Sat, 12 Sep 2026 11:09:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789211351; cv=none; b=X8/GDQTXqdpZESVF3xLGPTqZwzde09nDJ+bnEMkA1NF7gudmvbnMLfo4FTBZc5kO66xAL7spSWp2kqgNiOe5sGYEynK+y80dqVJ/3cvh/aSjR8EauUSRuJz0UUxdfDuJ91ZqqZ/cCl0Vuc6yerUIAwSHgdI8iKiNYXOiRnV6Kj4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789211351; c=relaxed/simple; bh=y6m/KotnYnkIu+eG8B1eB8rPFcxzUnodRoEyB5p13Hc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WLq+HC+9RqVeL3MtfC7WPC7D0lHlkJLxRuXUAh3Lxy6jbrnnZi18zCJTIX1YjSXR4x0fnYaAgCUf+NDVPyNj4FHKtztIbgsoTAI41yHG6bouvpJ+BjnVOnABjK5/+8kY9N1cSWpUjMtDliYozco2ucG+s3TIgTZc/xSLsBAEqsc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Nwg+XxSE; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Nwg+XxSE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F9E81F000FF; Sat, 12 Sep 2026 11:09:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789211350; bh=9FfhTnVJS4UYudjcJ5E285m7/TY5ofNNra1jNcNTLvU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Nwg+XxSE6ZGeTLsrzoHiiI8awOQ4+lOOlPJpSx8b0x1VjK74kuOYPK3bd7ws1PuwY WKZatxlkihf/9hiJMvQFBWH+V6W2b3AKDMlcj9CKmcisl/QAbpvPv9lnLk9Zc5VnGb +mlN8VUi14YwJac1kphXmtUWmI6q4t5Zp9UZ7dhI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Bart Van Assche , Zizhi Wo , Damien Le Moal , Nilay Shroff , Jens Axboe , Sasha Levin Subject: [PATCH 6.18 1213/1518] null_blk: use DEFINE_MUTEX for the file-scope mutex Date: Sat, 12 Sep 2026 08:56:22 +0200 Message-ID: <20260912065650.928809767@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065623.398859879@linuxfoundation.org> References: <20260912065623.398859879@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zizhi Wo [ Upstream commit 017dac7670909eaea3eb36e6b3b5a8be9ce0a14d ] In null_init(), mutex_init(&lock) currently happens after configfs_register_subsystem(), which exposes the nullb subsystem to userspace. A racing mkdir() into /sys/kernel/config/nullb/ can reach null_find_dev_by_name() -> mutex_lock(&lock) before the mutex is initialized, trigger warning: [ 123.137788] DEBUG_LOCKS_WARN_ON(lock->magic != lock) [ 123.137796] WARNING: kernel/locking/mutex.c:159 at mutex_lock+0x171/0x1c0, CPU#13: mkdir/1301 [ 123.140090] Modules linked in: null_blk(+) nft_fib_inet nft_fib_ipv4 ...... [ 123.154926] Call Trace: [ 123.155172] [ 123.155419] ? __pfx_mutex_lock+0x10/0x10 [ 123.156181] ? __pfx__raw_spin_lock+0x10/0x10 [ 123.156571] nullb_group_make_group+0x20/0x100 [null_blk] [ 123.157011] configfs_mkdir+0x47b/0xc70 [ 123.157337] ? __pfx_configfs_mkdir+0x10/0x10 [ 123.157719] ? may_create_dentry+0x242/0x2e0 [ 123.158061] vfs_mkdir+0x2a9/0x6c0 [ 123.158352] filename_mkdirat+0x3dc/0x500 [ 123.158710] ? __pfx_filename_mkdirat+0x10/0x10 [ 123.159070] ? strncpy_from_user+0x3a/0x1d0 [ 123.159413] __x64_sys_mkdir+0x6b/0x90 [ 123.159760] do_syscall_64+0xea/0x600 Replace the runtime mutex_init(&lock) with a static DEFINE_MUTEX(lock) declaration to fix this issue. Fixes: 49c3b9266a71 ("block: null_blk: Improve device creation with configfs") Suggested-by: Bart Van Assche Signed-off-by: Zizhi Wo Reviewed-by: Bart Van Assche Reviewed-by: Damien Le Moal Reviewed-by: Nilay Shroff Link: https://patch.msgid.link/20260725022509.714271-2-wozizhi@huaweicloud.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/null_blk/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 50938881219bc..8f0cdeafe9c90 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -66,7 +66,7 @@ struct nullb_page { #define NULLB_PAGE_FREE (MAP_SZ - 2) static LIST_HEAD(nullb_list); -static struct mutex lock; +static DEFINE_MUTEX(lock); static int null_major; static DEFINE_IDA(nullb_indexes); static struct blk_mq_tag_set tag_set; @@ -2167,8 +2167,6 @@ static int __init null_init(void) if (ret) return ret; - mutex_init(&lock); - null_major = register_blkdev(0, "nullb"); if (null_major < 0) { ret = null_major; -- 2.53.0