linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/damon/sysfs: Fix an array out-of-bounds read error due
@ 2022-03-02 18:02 Colin Ian King
  2022-03-02 20:53 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Colin Ian King @ 2022-03-02 18:02 UTC (permalink / raw)
  To: SeongJae Park, Andrew Morton, Stephen Rothwell, linux-mm
  Cc: kernel-janitors, linux-kernel

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")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 mm/damon/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
index 32a9d21c0db5..fda2506c676f 100644
--- a/mm/damon/sysfs.c
+++ b/mm/damon/sysfs.c
@@ -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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] mm/damon/sysfs: Fix an array out-of-bounds read error due
  2022-03-02 18:02 [PATCH] mm/damon/sysfs: Fix an array out-of-bounds read error due Colin Ian King
@ 2022-03-02 20:53 ` Andrew Morton
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2022-03-02 20:53 UTC (permalink / raw)
  To: Colin Ian King
  Cc: SeongJae Park, Stephen Rothwell, linux-mm, kernel-janitors, linux-kernel

On Wed,  2 Mar 2022 18:02:52 +0000 Colin Ian King <colin.i.king@gmail.com> wrote:

> 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/20220301185619.2904-1-sj@kernel.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-02 20:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02 18:02 [PATCH] mm/damon/sysfs: Fix an array out-of-bounds read error due Colin Ian King
2022-03-02 20:53 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).