cpufreq: add NULL check to the store method of cpufreq
PATCH 1/1 cpufreq: add NULL check to the store method of cpufreq
From: shenkai <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
This bug was found on linux 4.19
--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/cpufreq/cpufreq.c +3 -0
@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return ret; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().
Signature · 1 line
2.6.4.windows.1
Rafael J. Wysocki
maintainerQuoted 2 lines · Shen Kai
From: shenkai <[email protected]>
Can you please use the proper spelling of your name here?
Quoted 5 lines
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
Quoted 8 lines
The following operations can lead to a kernel crash.
chmod +w
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqecho 1 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqThis bug was found on linux 4.19
Signed-off-by shenkai <[email protected]>
And here?
Quoted 2 lines
Reported-by linfeilong <[email protected]>Reviewed-by linfeilong <[email protected]>
And the proper spelling of the reporter/reviewer name here too?
Quoted 23 lines
Acked-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cpufreq/cpufreq.c +3
-1@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return ret; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver(). -- 2.6.4.windows.1
PATCH 1/1 cpufreq: add NULL check to the store method of cpufreq
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
This bug was found on linux 4.19
--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/cpufreq/cpufreq.c +3 -0
@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return ret; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().
Signature · 1 line
2.6.4.windows.1
Viresh Kumar
maintainerQuoted 26 lines · Shen Kai
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqecho 1 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqThis bug was found on linux 4.19
Signed-off-by Kai Shen <[email protected]>Reported-by Feilong Lin <[email protected]>Reviewed-by Feilong Lin <[email protected]>Acked-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cpufreq/cpufreq.c +0
-0
drivers/cpufreq/cpufreq.c static ssize_t store(struct kobject *kobj, struct attribute *attr, · line 951
Quoted 5 lines
drivers/cpufreq/cpufreq.c +2
-0@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return ret;
The return error shouldn't be -EINVAL here, maybe ENOPERM or ENOENT ?
Quoted 7 lines
drivers/cpufreq/cpufreq.c +1
-0+/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver(). Signature · 1 line
2.6.4.windows.1
Signature · 1 line
viresh
Viresh Kumar
maintainerQuoted 30 lines · Viresh Kumar
Quoted 29 lines · Shen Kai
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqecho 1 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqThis bug was found on linux 4.19
Signed-off-by Kai Shen <[email protected]>Reported-by Feilong Lin <[email protected]>Reviewed-by Feilong Lin <[email protected]>Acked-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cpufreq/cpufreq.c +0
-0@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ;
Quoted 4 lines
drivers/cpufreq/cpufreq.c static ssize_t store(struct kobject *kobj, struct attribute *attr, · line 951
Quoted 2 lines
drivers/cpufreq/cpufreq.c +2
-0+if (!fattr->store) +return ret;The return error shouldn't be
-EINVALhere, maybe ENOPERM or ENOENT ?
s/ENOPERM/EPERM/
Signature · 1 line
viresh
PATCH 1/1 cpufreq: add NULL check to the store method of cpufreq
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
This bug was found on linux 4.19
--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/cpufreq/cpufreq.c +3 -0
@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return -EPERM ; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().
Signature · 1 line
2.6.4.windows.1
Viresh Kumar
maintainerQuoted 26 lines · Shen Kai
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqecho 1 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqThis bug was found on linux 4.19
Signed-off-by Kai Shen <[email protected]>Reported-by Feilong Lin <[email protected]>Reviewed-by Feilong Lin <[email protected]>Acked-by Viresh Kumar <[email protected]>--- drivers/cpufreq/cpufreq.c | 3 +++ 1 file changed, 3 insertions(+)drivers/cpufreq/cpufreq.c +0
-0
drivers/cpufreq/cpufreq.c static ssize_t store(struct kobject *kobj, struct attribute *attr, · line 952
Quoted 6 lines
drivers/cpufreq/cpufreq.c +3
-0@@ -947,6 +947,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return -EPERM ; +
And this should be -EIO, I found that after looking at all the instances of struct kobj_type in the kernel :(
Also there is another change you need to make.
drivers/cpufreq/cpufreq.c +3 -0
@@ -933,6 +933,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)struct freq_attr *fattr =to_attr (attr);ssize_t ret; +if (!fattr->show) +return -EIO ; +down_read (&policy->rwsem); ret = fattr->show (policy, buf);up_read (&policy->rwsem);
as there is a write-only attribute (reset) in cpufreq stats.
Signature · 1 line
viresh
PATCH v3 1/1 cpufreq: add NULL check to the store method of cpufreq
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq echo 1 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
This bug was found on linux 4.19
---V2->V3
- use return value -EIO instead.
- do NULL check in show method too.
drivers/cpufreq/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/cpufreq/cpufreq.c +6 -0
@@ -933,6 +933,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)struct freq_attr *fattr =to_attr (attr);ssize_t ret; +if (!fattr->show) +return -EIO ; +down_read (&policy->rwsem); ret = fattr->show (policy, buf);up_read (&policy->rwsem);
@@ -947,6 +950,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return -EIO ; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().
Signature · 1 line
2.6.4.windows.1
Quoted 40 lines · Shen Kai
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqecho 1 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqThis bug was found on linux 4.19
Signed-off-by Kai Shen <[email protected]>Reported-by Feilong Lin <[email protected]>Reviewed-by Feilong Lin <[email protected]>Acked-by Viresh Kumar <[email protected]>---
V2->V3
- use return value-EIOinstead.
- do NULL check in show method too.drivers/cpufreq/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/cpufreq/cpufreq.c +3
-0@@ -933,6 +933,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)struct freq_attr *fattr =to_attr (attr);ssize_t ret; +if (!fattr->show) +return -EIO ; +down_read (&policy->rwsem); ret = fattr->show (policy, buf);up_read (&policy->rwsem);
drivers/cpufreq/cpufreq.c static ssize_t store(struct kobject *kobj, struct attribute *attr, · line 958
Quoted 9 lines
drivers/cpufreq/cpufreq.c +3
-0@@ -947,6 +950,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return -EIO ; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().
Signature · 1 line
viresh
Quoted 41 lines · CET Shen Kai
From: Kai Shen <[email protected]>
Add NULL check in the store function here to avoid NULL callback invoking. Though some interfaces of cpufreq are set as read-only, user can still get write permission using chmod which can lead to a kernel crash.
The following operations can lead to a kernel crash.
chmod +w
/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqecho 1 >/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freqThis bug was found on linux 4.19
Signed-off-by Kai Shen <[email protected]>Reported-by Feilong Lin <[email protected]>Reviewed-by Feilong Lin <[email protected]>Acked-by Viresh Kumar <[email protected]>---
V2->V3
- use return value-EIOinstead.
- do NULL check in show method too.drivers/cpufreq/cpufreq.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/cpufreq/cpufreq.c +3
-0@@ -933,6 +933,9 @@ static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)struct freq_attr *fattr =to_attr (attr);ssize_t ret; +if (!fattr->show) +return -EIO ; +down_read (&policy->rwsem); ret = fattr->show (policy, buf);up_read (&policy->rwsem);
drivers/cpufreq/cpufreq.c static ssize_t store(struct kobject *kobj, struct attribute *attr, · line 958
Quoted 9 lines
drivers/cpufreq/cpufreq.c +3
-0@@ -947,6 +950,9 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,struct freq_attr *fattr =to_attr (attr);ssize_t ret = -EINVAL ; +if (!fattr->store) +return -EIO ; +/* * cpus_read_trylock() is used here to work around a circular lock * dependency problem with respect to the cpufreq_register_driver().
Applying as 5.5 material with updated subject and changelog (the original ones did not mention the show() function).
Thanks!