diff mbox

PM / sysfs: return -EINVAL for bogus strings

Message ID 20170710072140.chms22ep35myvvbd@mwanda (mailing list archive)
State Mainlined
Delegated to: Rafael Wysocki
Headers show

Commit Message

Dan Carpenter July 10, 2017, 7:21 a.m. UTC
In the current code, if the user accidentally writes a bogus command to
this sysfs file, then we set the latency tolerance to an uninitialized
variable.

Fixes: 2d984ad132a8 ("PM / QoS: Introcuce latency tolerance device PM QoS type")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

Pavel Machek July 10, 2017, 7:29 a.m. UTC | #1
On Mon 2017-07-10 10:21:40, Dan Carpenter wrote:
> In the current code, if the user accidentally writes a bogus command to
> this sysfs file, then we set the latency tolerance to an uninitialized
> variable.
> 
> Fixes: 2d984ad132a8 ("PM / QoS: Introcuce latency tolerance device PM QoS type")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Acked-by: Pavel Machek <pavel@ucw.cz>

I'd suggest this is a stable candidate. It only leaks 32 bits to
userspace, but still...

> @@ -272,6 +272,8 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
>  			value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
>  		else if (!strcmp(buf, "any") || !strcmp(buf, "any\n"))
>  			value = PM_QOS_LATENCY_ANY;
> +		else
> +			return -EINVAL;
>  	}
>  	ret = dev_pm_qos_update_user_latency_tolerance(dev, value);
>  	return ret < 0 ? ret : n;
Rafael J. Wysocki July 12, 2017, 9:35 p.m. UTC | #2
On Monday, July 10, 2017 09:29:35 AM Pavel Machek wrote:
> On Mon 2017-07-10 10:21:40, Dan Carpenter wrote:
> > In the current code, if the user accidentally writes a bogus command to
> > this sysfs file, then we set the latency tolerance to an uninitialized
> > variable.
> > 
> > Fixes: 2d984ad132a8 ("PM / QoS: Introcuce latency tolerance device PM QoS type")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Acked-by: Pavel Machek <pavel@ucw.cz>
> 
> I'd suggest this is a stable candidate. It only leaks 32 bits to
> userspace, but still...
> 
> > @@ -272,6 +272,8 @@ static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
> >  			value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
> >  		else if (!strcmp(buf, "any") || !strcmp(buf, "any\n"))
> >  			value = PM_QOS_LATENCY_ANY;
> > +		else
> > +			return -EINVAL;
> >  	}
> >  	ret = dev_pm_qos_update_user_latency_tolerance(dev, value);
> >  	return ret < 0 ? ret : n;
> 
> 

Applied, thanks!
diff mbox

Patch

diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 185a52581cfa..156ab57bca77 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -272,6 +272,8 @@  static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
 			value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
 		else if (!strcmp(buf, "any") || !strcmp(buf, "any\n"))
 			value = PM_QOS_LATENCY_ANY;
+		else
+			return -EINVAL;
 	}
 	ret = dev_pm_qos_update_user_latency_tolerance(dev, value);
 	return ret < 0 ? ret : n;