lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251211073426.123026-1-jaeyuel.im@lge.com>
Date: Thu, 11 Dec 2025 07:34:26 +0000
From: jaeyuel.im@....com
To: Alasdair Kergon <agk@...hat.com>,
	Mike Snitzer <snitzer@...nel.org>,
	Mikulas Patocka <mpatocka@...hat.com>
Cc: dm-devel@...ts.linux.dev,
	linux-kernel@...r.kernel.org,
	"jaeyuel.im" <jaeyuel.im@....com>
Subject: [PATCH] dm init: ensure block device is ready before creating mapped device

From: "jaeyuel.im" <jaeyuel.im@....com>

The current implementation of dm_init_init() uses early_lookup_bdev() to
wait for the device node to appear. However, early_lookup_bdev() only
verifies that the device node exists and returns the dev_t. It does not
guarantee that the underlying block device structure is fully initialized
and ready for I/O operations or to be opened.

On certain platforms (e.g., embedded systems with specific storage
drivers), this can lead to a race condition where dm_early_create()
attempts to open the device immediately after early_lookup_bdev() returns,
but fails because the device is not yet fully ready. This results in boot
failures as the mapped device cannot be created.

This patch adds an additional check using blkdev_get_no_open() after
early_lookup_bdev() returns. This ensures that the struct block_device is
actually available and the device is ready to be opened, effectively
preventing the race condition.

Signed-off-by: jaeyuel.im <jaeyuel.im@....com>
---
 drivers/md/dm-init.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/md/dm-init.c b/drivers/md/dm-init.c
index ff9420f06483..76b84ca39906 100644
--- a/drivers/md/dm-init.c
+++ b/drivers/md/dm-init.c
@@ -299,10 +299,24 @@ static int __init dm_init_init(void)
 	for (i = 0; i < ARRAY_SIZE(waitfor); i++) {
 		if (waitfor[i]) {
 			dev_t dev;
+			struct block_device *bdev;
 
 			DMINFO("waiting for device %s ...", waitfor[i]);
 			while (early_lookup_bdev(waitfor[i], &dev))
 				fsleep(5000);
+
+			/*
+			 * early_lookup_bdev() only checks if the device node exists and
+			 * returns the dev_t. It does not guarantee that the underlying
+			 * block device is fully initialized and ready to be opened. On
+			 * some platforms, this can lead to a race condition where
+			 * dm_early_create() fails because the device is not yet ready.
+			 * Ensure the block device is truly available by attempting to
+			 * get it.
+			 */
+			while (!(bdev = blkdev_get_no_open(dev)))
+				fsleep(5000);
+			blkdev_put_no_open(bdev);
 		}
 	}
 
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ