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: <2023082223-cautious-confined-5e05@gregkh>
Date:   Tue, 22 Aug 2023 16:06:40 +0200
From:   Greg KH <gregkh@...uxfoundation.org>
To:     Abhijit Gangurde <abhijit.gangurde@....com>
Cc:     masahiroy@...nel.org, linux-kernel@...r.kernel.org,
        Nipun.Gupta@....com, nikhil.agarwal@....com, puneet.gupta@....com,
        git@....com, michal.simek@....com
Subject: Re: [PATCH v3 2/5] cdx: Introduce lock to protect controller ops

On Mon, Aug 14, 2023 at 03:52:20PM +0530, Abhijit Gangurde wrote:
> Add a mutex lock to prevent race between controller ops initiated by
> the bus subsystem and the controller registration/unregistration.
> 
> Signed-off-by: Abhijit Gangurde <abhijit.gangurde@....com>
> ---
>  drivers/cdx/cdx.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
> index 1c0f76cf4f15..50df061f4537 100644
> --- a/drivers/cdx/cdx.c
> +++ b/drivers/cdx/cdx.c
> @@ -72,6 +72,8 @@
>  
>  /* IDA for CDX controllers registered with the CDX bus */
>  DEFINE_IDA(cdx_controller_ida);
> +/* Lock to protect controller ops */
> +static DEFINE_MUTEX(cdx_controller_lock);
>  
>  static char *compat_node_name = "xlnx,versal-net-cdx";
>  
> @@ -396,6 +398,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
>  	if (!val)
>  		return -EINVAL;
>  
> +	mutex_lock(&cdx_controller_lock);
> +
>  	/* Unregister all the devices on the bus */
>  	cdx_unregister_devices(&cdx_bus_type);
>  
> @@ -415,6 +419,8 @@ static ssize_t rescan_store(const struct bus_type *bus,
>  		put_device(&pd->dev);
>  	}
>  
> +	mutex_unlock(&cdx_controller_lock);
> +
>  	return count;
>  }
>  static BUS_ATTR_WO(rescan);
> @@ -538,11 +544,13 @@ int cdx_register_controller(struct cdx_controller *cdx)
>  		return ret;
>  	}
>  
> +	mutex_lock(&cdx_controller_lock);
>  	cdx->id = ret;
>  
>  	/* Scan all the devices */
>  	cdx->ops->scan(cdx);
>  	cdx->controller_registered = true;
> +	mutex_unlock(&cdx_controller_lock);
>  
>  	return 0;
>  }
> @@ -553,9 +561,13 @@ void cdx_unregister_controller(struct cdx_controller *cdx)
>  	if (cdx->id >= MAX_CDX_CONTROLLERS)
>  		return;
>  
> +	mutex_lock(&cdx_controller_lock);
> +
>  	cdx->controller_registered = false;
>  	device_for_each_child(cdx->dev, NULL, cdx_unregister_device);
>  	ida_free(&cdx_controller_ida, cdx->id);
> +
> +	mutex_unlock(&cdx_controller_lock);
>  }
>  EXPORT_SYMBOL_GPL(cdx_unregister_controller);
>  
> -- 
> 2.25.1
> 

Ah, now you lock things, that answers the question in patch 1...

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ