diff mbox

scsi: sd: add check for changing allow_restart

Message ID 20170927165313.GA36250@localhost.didichuxing.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

weiping zhang Sept. 27, 2017, 4:53 p.m. UTC
/sys/class/scsi_disk/0:2:0:0/allow_restart can be changed to 0 unexpectly by
writing invalid string, like following:

echo asdf > /sys/class/scsi_disk/0:2:0:0/allow_restart

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 drivers/scsi/sd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

weiping zhang Oct. 7, 2017, 8:47 a.m. UTC | #1
On Thu, Sep 28, 2017 at 12:53:18AM +0800, weiping zhang wrote:
> /sys/class/scsi_disk/0:2:0:0/allow_restart can be changed to 0 unexpectly by
> writing invalid string, like following:
> 
> echo asdf > /sys/class/scsi_disk/0:2:0:0/allow_restart
> 
> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> ---
>  drivers/scsi/sd.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 3ef2214..d18639f 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -253,6 +253,7 @@ static ssize_t
>  allow_restart_store(struct device *dev, struct device_attribute *attr,
>  		    const char *buf, size_t count)
>  {
> +	int err, v;
>  	struct scsi_disk *sdkp = to_scsi_disk(dev);
>  	struct scsi_device *sdp = sdkp->device;
>  
> @@ -262,7 +263,11 @@ allow_restart_store(struct device *dev, struct device_attribute *attr,
>  	if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC)
>  		return -EINVAL;
>  
> -	sdp->allow_restart = simple_strtoul(buf, NULL, 10);
> +	err = kstrtoint(buf, 10, &v);
> +	if (err || (v != 0 && v != 1))
> +		return -EINVAL;
> +
> +	sdp->allow_restart = v;
>  
>  	return count;
>  }
> -- 
> 2.9.4
> 
Hello Martin,

Ping
Martin K. Petersen Oct. 11, 2017, 5:22 p.m. UTC | #2
weiping,

> /sys/class/scsi_disk/0:2:0:0/allow_restart can be changed to 0 unexpectly by
> writing invalid string, like following:
>
> echo asdf > /sys/class/scsi_disk/0:2:0:0/allow_restart

Please switch to kstrtobool() and fix up manage_start_stop as well.

Thanks!
weiping zhang Oct. 12, 2017, 6:22 a.m. UTC | #3
On Wed, Oct 11, 2017 at 01:22:18PM -0400, Martin K. Petersen wrote:
> 
> weiping,
> 
> > /sys/class/scsi_disk/0:2:0:0/allow_restart can be changed to 0 unexpectly by
> > writing invalid string, like following:
> >
> > echo asdf > /sys/class/scsi_disk/0:2:0:0/allow_restart
> 
> Please switch to kstrtobool() and fix up manage_start_stop as well.
> 
> Thanks!
> 
Thanks, I'll send v2 later.
diff mbox

Patch

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 3ef2214..d18639f 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -253,6 +253,7 @@  static ssize_t
 allow_restart_store(struct device *dev, struct device_attribute *attr,
 		    const char *buf, size_t count)
 {
+	int err, v;
 	struct scsi_disk *sdkp = to_scsi_disk(dev);
 	struct scsi_device *sdp = sdkp->device;
 
@@ -262,7 +263,11 @@  allow_restart_store(struct device *dev, struct device_attribute *attr,
 	if (sdp->type != TYPE_DISK && sdp->type != TYPE_ZBC)
 		return -EINVAL;
 
-	sdp->allow_restart = simple_strtoul(buf, NULL, 10);
+	err = kstrtoint(buf, 10, &v);
+	if (err || (v != 0 && v != 1))
+		return -EINVAL;
+
+	sdp->allow_restart = v;
 
 	return count;
 }