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]
Message-ID: <14b09a61-8e8f-166d-45b9-7dd07922286e@oracle.com>
Date:   Mon, 29 Aug 2016 23:33:41 +0200
From:   Vegard Nossum <vegard.nossum@...cle.com>
To:     Tejun Heo <tj@...nel.org>
Cc:     Rabin Vincent <rabin@....in>, Jens Axboe <axboe@...com>,
        Jan Kara <jack@...e.cz>, Al Viro <viro@...iv.linux.org.uk>,
        linux-block@...r.kernel.org, linux-kernel@...r.kernel.org,
        stable@...r.kernel.org
Subject: Re: [PATCH] bdev: fix NULL pointer dereference in sync()/close() race

On 08/29/2016 09:55 PM, Tejun Heo wrote:
> On Sat, Aug 27, 2016 at 11:30:22AM +0200, Vegard Nossum wrote:
>> If people who are more savvy in block/fs code could ack the locking bits
>> I think we should apply the patch ASAP because it's an easy local DOS if
>> you have (open/read) access to any block device.
>
> I think the right thing to do there is doing blkdev_get() /
> blkdev_put() around func() invocation in iterate_bdevs() rather than
> holding bd_mutex across the callback.  Can you please verify whether
> that works?

Didn't work for me, I kept getting use-after-free in __blkdev_get() on
bdev->bd_invalidated after it calls bdev->bd_disk->fops->open(). I tried
a few related things without much luck.

The only thing that worked for me without holding the mutex across the
call was this:

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 08ae993..586d745 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -1885,6 +1885,7 @@ void iterate_bdevs(void (*func)(struct 
block_device *, void *), void *arg)
  	spin_lock(&blockdev_superblock->s_inode_list_lock);
  	list_for_each_entry(inode, &blockdev_superblock->s_inodes, i_sb_list) {
  		struct address_space *mapping = inode->i_mapping;
+		struct block_device *bdev;

  		spin_lock(&inode->i_lock);
  		if (inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW) ||
@@ -1906,7 +1907,19 @@ void iterate_bdevs(void (*func)(struct 
block_device *, void *), void *arg)
  		iput(old_inode);
  		old_inode = inode;

-		func(I_BDEV(inode), arg);
+		bdev = I_BDEV(inode);
+
+		mutex_lock(&bdev->bd_mutex);
+		bdev->bd_openers++;
+		bdev->bd_holders++;
+		mutex_unlock(&bdev->bd_mutex);
+
+		func(bdev, arg);
+
+		mutex_lock(&bdev->bd_mutex);
+		bdev->bd_openers--;
+		bdev->bd_holders--;
+		mutex_unlock(&bdev->bd_mutex);

  		spin_lock(&blockdev_superblock->s_inode_list_lock);
  	}

I'm guessing that's too simple to work in general (especially when you
bring in partitions and stuff; I'm just opening /dev/sr0 in my reproducer).

It's been a long day, I'll have a look tomorrow and see if I didn't just
do something stupid.


Vegard

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ