[PATCH v2] staging: pi433: fix race condition in pi433_ioctl

Dan Carpenter dan.carpenter at oracle.com
Wed Jun 13 05:16:49 EDT 2018


On Tue, Jun 12, 2018 at 09:47:41PM -0400, Hugo Lefeuvre wrote:
>  drivers/staging/pi433/pi433_if.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/staging/pi433/pi433_if.c b/drivers/staging/pi433/pi433_if.c
> index b061f77dda41..3ec1ed01d04b 100644
> --- a/drivers/staging/pi433/pi433_if.c
> +++ b/drivers/staging/pi433/pi433_if.c
> @@ -880,6 +880,7 @@ pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  	int			retval = 0;
>  	struct pi433_instance	*instance;
>  	struct pi433_device	*device;
> +	struct pi433_tx_cfg	tx_cfg_buffer;
>  	void __user *argp = (void __user *)arg;
>  
>  	/* Check type and command number */
> @@ -902,9 +903,15 @@ pi433_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
>  			return -EFAULT;
>  		break;
>  	case PI433_IOC_WR_TX_CFG:
> -		if (copy_from_user(&instance->tx_cfg, argp,
> -				   sizeof(struct pi433_tx_cfg)))
> +		/* do not modify tx config while it is being copied to fifo */

There is no need for this comment, since it's obvious.  Also if you use
simpler names then the copy fits on one line:

		if (copy_from_user(&tx_cfg, argp, sizeof(tx_cfg)) {


> +		mutex_lock(&device->tx_fifo_lock);
> +		if (copy_from_user(&tx_cfg_buffer, argp,
> +				   sizeof(struct pi433_tx_cfg))) {

Sorry for the duplicate review, but it got sent to both my inboxes... :P

regards,
dan carpenter




More information about the Kernelnewbies mailing list