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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 18 Jul 2023 09:21:26 +0800
From:   Yu Kuai <yukuai1@...weicloud.com>
To:     Sergei Shtepa <sergei.shtepa@...am.com>,
        Yu Kuai <yukuai1@...weicloud.com>, axboe@...nel.dk,
        hch@...radead.org, corbet@....net, snitzer@...nel.org
Cc:     viro@...iv.linux.org.uk, brauner@...nel.org, dchinner@...hat.com,
        willy@...radead.org, dlemoal@...nel.org, linux@...ssschuh.net,
        jack@...e.cz, ming.lei@...hat.com, linux-block@...r.kernel.org,
        linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-fsdevel@...r.kernel.org,
        Donald Buczek <buczek@...gen.mpg.de>,
        "yukuai (C)" <yukuai3@...wei.com>
Subject: Re: [PATCH v5 02/11] block: Block Device Filtering Mechanism

Hi,

在 2023/07/18 1:39, Sergei Shtepa 写道:
> Hi.
> 
> On 7/12/23 14:34, Yu Kuai wrote:
>> Subject:
>> Re: [PATCH v5 02/11] block: Block Device Filtering Mechanism
>> From:
>> Yu Kuai <yukuai1@...weicloud.com>
>> Date:
>> 7/12/23, 14:34
>>
>> To:
>> Yu Kuai <yukuai1@...weicloud.com>, Sergei Shtepa <sergei.shtepa@...am.com>, axboe@...nel.dk, hch@...radead.org, corbet@....net, snitzer@...nel.org
>> CC:
>> viro@...iv.linux.org.uk, brauner@...nel.org, dchinner@...hat.com, willy@...radead.org, dlemoal@...nel.org, linux@...ssschuh.net, jack@...e.cz, ming.lei@...hat.com, linux-block@...r.kernel.org, linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org, Donald Buczek <buczek@...gen.mpg.de>, "yukuai (C)" <yukuai3@...wei.com>
>>
>>
>> Hi,
>>
>> 在 2023/07/12 18:04, Yu Kuai 写道:
>>> Hi,
>>>
>>> 在 2023/07/11 10:02, Yu Kuai 写道:
>>>
>>>>> +static bool submit_bio_filter(struct bio *bio)
>>>>> +{
>>>>> +    if (bio_flagged(bio, BIO_FILTERED))
>>>>> +        return false;
>>>>> +
>>>>> +    bio_set_flag(bio, BIO_FILTERED);
>>>>> +    return bio->bi_bdev->bd_filter->ops->submit_bio(bio);
>>>>> +}
>>>>> +
>>>>>    static void __submit_bio(struct bio *bio)
>>>>>    {
>>>>> +    /*
>>>>> +     * If there is a filter driver attached, check if the BIO needs to go to
>>>>> +     * the filter driver first, which can then pass on the bio or consume it.
>>>>> +     */
>>>>> +    if (bio->bi_bdev->bd_filter && submit_bio_filter(bio))
>>>>> +        return;
>>>>> +
>>>>>        if (unlikely(!blk_crypto_bio_prep(&bio)))
>>>>>            return;
>>>
>>> ...
>>>
>>>>> +static void __blkfilter_detach(struct block_device *bdev)
>>>>> +{
>>>>> +    struct blkfilter *flt = bdev->bd_filter;
>>>>> +    const struct blkfilter_operations *ops = flt->ops;
>>>>> +
>>>>> +    bdev->bd_filter = NULL;
>>>>> +    ops->detach(flt);
>>>>> +    module_put(ops->owner);
>>>>> +}
>>>>> +
>>>>> +void blkfilter_detach(struct block_device *bdev)
>>>>> +{
>>>>> +    if (bdev->bd_filter) {
>>>>> +        blk_mq_freeze_queue(bdev->bd_queue);
>>>
>>> And this is not sate as well, for bio-based device, q_usage_counter is
>>> not grabbed while submit_bio_filter() is called, hence there is a risk
>>> of uaf from submit_bio_filter().
>>
>> And there is another question, can blkfilter_detach() from
>> del_gendisk/delete_partiton and ioctl concurrent? I think it's a
>> problem.
>>
> 
> Yes, it looks like if two threads execute the blkfilter_detach() function,
> then a problem is possible. The blk_mq_freeze_queue() function does not
> block threads.
> But for this, it is necessary that the IOCTL for the block device and
> its removal are performed simultaneously. Is this possible?

I think it's possible, ioctl only requires to open the disk/partition,
and it won't block disk removal:

t1:			t2:

open dev
ioctl
			remove dev
			 del_gendisk
  blkfilter_detach	  blkfilter_detach

> 
> I suppose that using mutex bdev->bd_disk->open_mutex in
> blkfilter_ioctl_attach(), blkfilter_ioctl_detach() and
> blkfilter_ioctl_ctl() can fix the problem. What do you think?

I think it's ok, and blkfilter ioctl must check disk_live() while
holding the lock.

Thanks,
Kuai

> 
> 
>> Thanks,
>> Kuai
>>>
>>> Thanks,
>>> Kuai
>>>
>>> .
>>>
>>
> .
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ