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-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed,  8 Apr 2015 02:23:45 -0400
From:	Jarod Wilson <jarod@...hat.com>
To:	linux-kernel@...r.kernel.org
Cc:	Ming Lei <ming.lei@...onical.com>,
	Christoph Hellwig <hch@...radead.org>,
	Jens Axboe <axboe@...nel.dk>, Tejun Heo <tj@...nel.org>,
	Alexander Viro <viro@...iv.linux.org.uk>,
	Markus Pargmann <mpa@...gutronix.de>,
	Stefan Weinhuber <wein@...ibm.com>,
	Stefan Haberland <stefan.haberland@...ibm.com>,
	Sebastian Ott <sebott@...ux.vnet.ibm.com>,
	Fabian Frederick <fabf@...net.be>,
	David Herrmann <dh.herrmann@...il.com>,
	Mike Galbraith <bitbucket@...ine.de>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Peter Zijlstra <peterz@...radead.org>,
	nbd-general@...ts.sourceforge.net, linux-s390@...r.kernel.org,
	Jarod Wilson <jarod@...hat.com>
Subject: [PATCH 6/7] block: replace trylock with mutex_lock in blkdev_reread_part()

From: Ming Lei <ming.lei@...onical.com>

The only possible problem of using mutex_lock() instead of trylock
is about deadlock.

If there aren't any locks held before calling blkdev_reread_part(lock),
deadlock can't be caused by this conversion.

If there are locks held before calling blkdev_reread_part(lock),
and if these locks arn't required in open, close handler and I/O
path, deadlock shouldn't be caused too.

Both user space's ioctl(BLKRRPART) and md_setup_drive() from
init/do_mounts_md.c belongs to the 1st case, so the conversion is safe
for the two cases.

For loop, the previous patches in this pathset has fixed the ABBA lock
dependency, so the conversion is OK.

For nbd, tx_lock is held when calling the function:

        - both open and release won't hold the lock
        - when blkdev_reread_part() is run, I/O thread has been stopped
        already, so tx_lock won't be acquired in I/O path at that time.
        - so the conversion won't cause deadlock for nbd

For dasd, both dasd_open(), dasd_release() and request function don't
acquire any mutex/semphone, so the conversion should be safe.

[jarod: update for modifications earlier in series.]

CC: Christoph Hellwig <hch@...radead.org>
CC: Jens Axboe <axboe@...nel.dk>
CC: Tejun Heo <tj@...nel.org>
CC: Alexander Viro <viro@...iv.linux.org.uk>
CC: Markus Pargmann <mpa@...gutronix.de>
CC: Stefan Weinhuber <wein@...ibm.com>
CC: Stefan Haberland <stefan.haberland@...ibm.com>
CC: Sebastian Ott <sebott@...ux.vnet.ibm.com>
CC: Fabian Frederick <fabf@...net.be>
CC: Ming Lei <ming.lei@...onical.com>
CC: David Herrmann <dh.herrmann@...il.com>
CC: Mike Galbraith <bitbucket@...ine.de>
CC: Andrew Morton <akpm@...ux-foundation.org>
CC: Peter Zijlstra <peterz@...radead.org>
CC: nbd-general@...ts.sourceforge.net
CC: linux-s390@...r.kernel.org
Signed-off-by: Ming Lei <ming.lei@...onical.com>
Signed-off-by: Jarod Wilson <jarod@...hat.com>
---
 block/ioctl.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/ioctl.c b/block/ioctl.c
index 64a4fcb..47c8e6d 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -170,15 +170,19 @@ EXPORT_SYMBOL(__blkdev_reread_part);
 
 /*
  * This is an exported API for the block driver, and will
- * acquire bd_mutex. Make sure you aren't calling it with
- * bd_mutex already held, or we'll return -EBUSY.
+ * acquire bd_mutex.
+ *
+ * Make sure held locks aren't required in open()/close()
+ * handlers and I/O paths to avoid an ABBA deadlock:
+ * - bd_mutex is held before calling a block driver's open/close
+ *   handler
+ * - reading a partition table may submit I/O to the block device
  */
 int blkdev_reread_part(struct block_device *bdev)
 {
 	int res;
 
-	if (!mutex_trylock(&bdev->bd_mutex))
-		return -EBUSY;
+	mutex_lock(&bdev->bd_mutex);
 	res = __blkdev_reread_part(bdev);
 	mutex_unlock(&bdev->bd_mutex);
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ