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: <Y3VaunS49xJvHflm@redhat.com>
Date:   Wed, 16 Nov 2022 16:48:42 -0500
From:   Mike Snitzer <snitzer@...hat.com>
To:     Yu Kuai <yukuai1@...weicloud.com>
Cc:     hch@....de, axboe@...nel.dk, agk@...hat.com, snitzer@...nel.org,
        dm-devel@...hat.com, linux-block@...r.kernel.org,
        linux-kernel@...r.kernel.org, yukuai3@...wei.com,
        yi.zhang@...wei.com
Subject: Re: [PATCH RFC v3 05/10] dm: make sure create and remove dm device
 won't race with open and close table

On Tue, Nov 15 2022 at  9:10P -0500,
Yu Kuai <yukuai1@...weicloud.com> wrote:

> From: Yu Kuai <yukuai3@...wei.com>
> 
> open_table_device() and close_table_device() is protected by
> table_devices_lock, hence use it to protect add_disk() and
> del_gendisk().
> 
> Prepare to track per-add_disk holder relations in dm.
> 
> Signed-off-by: Yu Kuai <yukuai3@...wei.com>
> ---
>  drivers/md/dm.c | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/drivers/md/dm.c b/drivers/md/dm.c
> index 2917700b1e15..3728b56b364b 100644
> --- a/drivers/md/dm.c
> +++ b/drivers/md/dm.c
> @@ -1952,7 +1952,14 @@ static void cleanup_mapped_device(struct mapped_device *md)
>  		spin_unlock(&_minor_lock);
>  		if (dm_get_md_type(md) != DM_TYPE_NONE) {
>  			dm_sysfs_exit(md);
> +
> +			/*
> +			 * Hold lock to make sure del_gendisk() won't concurrent
> +			 * with open/close_table_device().
> +			 */
> +			mutex_lock(&md->table_devices_lock);
>  			del_gendisk(md->disk);
> +			mutex_unlock(&md->table_devices_lock);
>  		}
>  		dm_queue_destroy_crypto_profile(md->queue);
>  		put_disk(md->disk);
> @@ -2312,15 +2319,24 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
>  	if (r)
>  		return r;
>  
> +	/*
> +	 * Hold lock to make sure add_disk() and del_gendisk() won't concurrent
> +	 * with open_table_device() and close_table_device().
> +	 */
> +	mutex_lock(&md->table_devices_lock);
>  	r = add_disk(md->disk);
> +	mutex_unlock(&md->table_devices_lock);
>  	if (r)
>  		return r;
>  
>  	r = dm_sysfs_init(md);
>  	if (r) {
> +		mutex_lock(&md->table_devices_lock);
>  		del_gendisk(md->disk);
> +		mutex_unlock(&md->table_devices_lock);
>  		return r;
>  	}
> +
>  	md->type = type;
>  	return 0;
>  }
> -- 
> 2.31.1
> 

In the new comments added: s/concurrent/race/ ?

But otherwise:

Reviewed-by: Mike Snitzer <snitzer@...nel.org>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ