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: <f0849d52-55b8-5771-d99a-341f6af74024@huaweicloud.com>
Date:   Thu, 28 Sep 2023 14:05:46 +0800
From:   Yu Kuai <yukuai1@...weicloud.com>
To:     Zhong Jinghua <zhongjinghua@...weicloud.com>, josef@...icpanda.com,
        axboe@...nel.dk
Cc:     linux-block@...r.kernel.org, nbd@...er.debian.org,
        linux-kernel@...r.kernel.org, yi.zhang@...wei.com,
        "yukuai (C)" <yukuai3@...wei.com>
Subject: Re: [PATCH -next 2/3] nbd: factor out a helper to get nbd_config
 without holding 'config_lock'

在 2023/07/07 11:15, Zhong Jinghua 写道:
> From: Zhong Jinghua <zhongjinghua@...wei.com>
> 
> There are no functional changes, just to make code cleaner and prepare
> to fix null-ptr-dereference while accessing 'nbd->config'.
> 
LGTM

Reviewed-by: Yu Kuai <yukuai3@...wei.com>

> Signed-off-by: Zhong Jinghua <zhongjinghua@...wei.com>
> ---
>   drivers/block/nbd.c | 27 +++++++++++++++++++--------
>   1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index cd6d78914954..7186a9a49445 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -393,6 +393,14 @@ static u32 req_to_nbd_cmd_type(struct request *req)
>   	}
>   }
>   
> +static struct nbd_config *nbd_get_config_unlocked(struct nbd_device *nbd)
> +{
> +	if (refcount_inc_not_zero(&nbd->config_refs))
> +		return nbd->config;
> +
> +	return NULL;
> +}
> +
>   static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req)
>   {
>   	struct nbd_cmd *cmd = blk_mq_rq_to_pdu(req);
> @@ -407,13 +415,13 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req)
>   		return BLK_EH_DONE;
>   	}
>   
> -	if (!refcount_inc_not_zero(&nbd->config_refs)) {
> +	config = nbd_get_config_unlocked(nbd);
> +	if (!config) {
>   		cmd->status = BLK_STS_TIMEOUT;
>   		__clear_bit(NBD_CMD_INFLIGHT, &cmd->flags);
>   		mutex_unlock(&cmd->lock);
>   		goto done;
>   	}
> -	config = nbd->config;
>   
>   	if (config->num_connections > 1 ||
>   	    (config->num_connections == 1 && nbd->tag_set.timeout)) {
> @@ -975,12 +983,12 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
>   	struct nbd_sock *nsock;
>   	int ret;
>   
> -	if (!refcount_inc_not_zero(&nbd->config_refs)) {
> +	config = nbd_get_config_unlocked(nbd);
> +	if (!config) {
>   		dev_err_ratelimited(disk_to_dev(nbd->disk),
>   				    "Socks array is empty\n");
>   		return -EINVAL;
>   	}
> -	config = nbd->config;
>   
>   	if (index >= config->num_connections) {
>   		dev_err_ratelimited(disk_to_dev(nbd->disk),
> @@ -1556,6 +1564,7 @@ static int nbd_alloc_and_init_config(struct nbd_device *nbd)
>   static int nbd_open(struct block_device *bdev, fmode_t mode)
>   {
>   	struct nbd_device *nbd;
> +	struct nbd_config *config;
>   	int ret = 0;
>   
>   	mutex_lock(&nbd_index_mutex);
> @@ -1568,7 +1577,9 @@ static int nbd_open(struct block_device *bdev, fmode_t mode)
>   		ret = -ENXIO;
>   		goto out;
>   	}
> -	if (!refcount_inc_not_zero(&nbd->config_refs)) {
> +
> +	config = nbd_get_config_unlocked(nbd);
> +	if (!config) {
>   		mutex_lock(&nbd->config_lock);
>   		if (refcount_inc_not_zero(&nbd->config_refs)) {
>   			mutex_unlock(&nbd->config_lock);
> @@ -1584,7 +1595,7 @@ static int nbd_open(struct block_device *bdev, fmode_t mode)
>   		mutex_unlock(&nbd->config_lock);
>   		if (max_part)
>   			set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
> -	} else if (nbd_disconnected(nbd->config)) {
> +	} else if (nbd_disconnected(config)) {
>   		if (max_part)
>   			set_bit(GD_NEED_PART_SCAN, &bdev->bd_disk->state);
>   	}
> @@ -2194,7 +2205,8 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
>   	}
>   	mutex_unlock(&nbd_index_mutex);
>   
> -	if (!refcount_inc_not_zero(&nbd->config_refs)) {
> +	config = nbd_get_config_unlocked(nbd);
> +	if (!config) {
>   		dev_err(nbd_to_dev(nbd),
>   			"not configured, cannot reconfigure\n");
>   		nbd_put(nbd);
> @@ -2202,7 +2214,6 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
>   	}
>   
>   	mutex_lock(&nbd->config_lock);
> -	config = nbd->config;
>   	if (!test_bit(NBD_RT_BOUND, &config->runtime_flags) ||
>   	    !nbd->pid) {
>   		dev_err(nbd_to_dev(nbd),
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ