Skip to contentSkip to conversation

mm/damon/sysfs: Fix an array out-of-bounds read error due

PATCH In review Colin Ian King 2 participants 2 messages Mar 2, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/damon/sysfs: Fix an array out-of-bounds read error due

There is an off-by-one error in the upper limit to a for-loop that causes an out-of-bounds read error on the array damon_sysfs_wmark_metric_strs. Fix the comparison by replacing the <= operator with <.

Fixes 8f614da9d987 ("mm/damon/sysfs: support DAMOS watermarks")
---
 mm/damon/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/sysfs.c +1 -1
index 32a9d21c0db5..fda2506c676f 100644
@@ -266,7 +266,7 @@ static ssize_t metric_store(struct kobject *kobj, struct kobj_attribute *attr,
 			struct damon_sysfs_watermarks, kobj);
 	enum damos_wmark_metric metric;
 
-	for (metric = 0; metric <= NR_DAMOS_WMARK_METRICS; metric++) {
+	for (metric = 0; metric < NR_DAMOS_WMARK_METRICS; metric++) {
 		if (sysfs_streq(buf, damon_sysfs_wmark_metric_strs[metric])) {
 			watermarks->metric = metric;
 			return count;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 5 lines · On Wed, 2 Mar 2022 18:02:52 +0000 Colin Ian King <[email protected]>…

There is an off-by-one error in the upper limit to a for-loop that causes an out-of-bounds read error on the array damon_sysfs_wmark_metric_strs. Fix the comparison by replacing the <= operator with <.

Thanks, we already have
https://lkml.kernel.org/r/[email protected]