diff mbox series

[8/7] block: don't claim devices that are not live in bd_link_disk_holder

Message ID 20221102064854.GA8950@lst.de (mailing list archive)
State New, archived
Headers show
Series None | expand

Commit Message

Christoph Hellwig Nov. 2, 2022, 6:48 a.m. UTC
For gendisk that are not live or their partitions, the bd_holder_dir
pointer is not valid and the kobject might not have been allocated
yet or freed already.  Check that the disk is live before creating the
linkage and error out otherwise.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/holder.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Yu Kuai Nov. 2, 2022, 12:17 p.m. UTC | #1
Hi,

在 2022/11/02 14:48, Christoph Hellwig 写道:
> For gendisk that are not live or their partitions, the bd_holder_dir
> pointer is not valid and the kobject might not have been allocated
> yet or freed already.  Check that the disk is live before creating the
> linkage and error out otherwise.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>   block/holder.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/block/holder.c b/block/holder.c
> index a8c355b9d0806..a8806bbed2112 100644
> --- a/block/holder.c
> +++ b/block/holder.c
> @@ -66,6 +66,11 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
>   		return -EINVAL;
>   
>   	mutex_lock(&disk->open_mutex);
> +	/* bd_holder_dir is only valid for live disks */
> +	if (!disk_live(bdev->bd_disk)) {
> +		ret = -EINVAL;
> +		goto out_unlock;
> +	}

I think this is still not safe 
Yu Kuai Nov. 2, 2022, 12:22 p.m. UTC | #2
在 2022/11/02 20:17, Yu Kuai 写道:
> Hi,
> 
> 在 2022/11/02 14:48, Christoph Hellwig 写道:
>> For gendisk that are not live or their partitions, the bd_holder_dir
>> pointer is not valid and the kobject might not have been allocated
>> yet or freed already.  Check that the disk is live before creating the
>> linkage and error out otherwise.
>>
>> Signed-off-by: Christoph Hellwig <hch@lst.de>
>> ---
>>   block/holder.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/block/holder.c b/block/holder.c
>> index a8c355b9d0806..a8806bbed2112 100644
>> --- a/block/holder.c
>> +++ b/block/holder.c
>> @@ -66,6 +66,11 @@ int bd_link_disk_holder(struct block_device *bdev, 
>> struct gendisk *disk)
>>           return -EINVAL;
>>       mutex_lock(&disk->open_mutex);
>> +    /* bd_holder_dir is only valid for live disks */
>> +    if (!disk_live(bdev->bd_disk)) {
>> +        ret = -EINVAL;
>> +        goto out_unlock;
>> +    }
> 
> I think this is still not safe 
Christoph Hellwig Nov. 2, 2022, 2:17 p.m. UTC | #3
On Wed, Nov 02, 2022 at 08:17:37PM +0800, Yu Kuai wrote:
> I think this is still not safe 
Yu Kuai Nov. 3, 2022, 1:03 a.m. UTC | #4
Hi,

在 2022/11/02 22:17, Christoph Hellwig 写道:
> On Wed, Nov 02, 2022 at 08:17:37PM +0800, Yu Kuai wrote:
>> I think this is still not safe 
diff mbox series

Patch

diff --git a/block/holder.c b/block/holder.c
index a8c355b9d0806..a8806bbed2112 100644
--- a/block/holder.c
+++ b/block/holder.c
@@ -66,6 +66,11 @@  int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
 		return -EINVAL;
 
 	mutex_lock(&disk->open_mutex);
+	/* bd_holder_dir is only valid for live disks */
+	if (!disk_live(bdev->bd_disk)) {
+		ret = -EINVAL;
+		goto out_unlock;
+	}
 
 	WARN_ON_ONCE(!bdev->bd_holder);