stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH for-5.15.x 0/2] DAMON fixes
@ 2021-11-21 11:02 SeongJae Park
  2021-11-21 11:02 ` [PATCH for-5.15.x 1/2] mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation SeongJae Park
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SeongJae Park @ 2021-11-21 11:02 UTC (permalink / raw)
  To: stable, gregkh; +Cc: akpm, linux-mm, linux-kernel, SeongJae Park

This patchset is a backport of DAMON fixes that merged in the mainline,
for v5.15.x stable series.

SeongJae Park (2):
  mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer
    allocation
  mm/damon/dbgfs: fix missed use of damon_dbgfs_lock

 mm/damon/dbgfs.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

-- 
2.17.1


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

* [PATCH for-5.15.x 1/2] mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation
  2021-11-21 11:02 [PATCH for-5.15.x 0/2] DAMON fixes SeongJae Park
@ 2021-11-21 11:02 ` SeongJae Park
  2021-11-21 11:02 ` [PATCH for-5.15.x 2/2] mm/damon/dbgfs: fix missed use of damon_dbgfs_lock SeongJae Park
  2021-11-22 12:28 ` [PATCH for-5.15.x 0/2] DAMON fixes Greg KH
  2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2021-11-21 11:02 UTC (permalink / raw)
  To: stable, gregkh
  Cc: akpm, linux-mm, linux-kernel, SeongJae Park, Linus Torvalds

commit db7a347b26fe05d2e8c115bb24dfd908d0252bc3 upstream.

Patch series "DAMON fixes".

This patch (of 2):

DAMON users can trigger below warning in '__alloc_pages()' by invoking
write() to some DAMON debugfs files with arbitrarily high count
argument, because DAMON debugfs interface allocates some buffers based
on the user-specified 'count'.

        if (unlikely(order >= MAX_ORDER)) {
                WARN_ON_ONCE(!(gfp & __GFP_NOWARN));
                return NULL;
        }

Because the DAMON debugfs interface code checks failure of the
'kmalloc()', this commit simply suppresses the warnings by adding
'__GFP_NOWARN' flag.

Link: https://lkml.kernel.org/r/20211110145758.16558-1-sj@kernel.org
Link: https://lkml.kernel.org/r/20211110145758.16558-2-sj@kernel.org
Fixes: 4bc05954d007 ("mm/damon: implement a debugfs-based user space interface")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 mm/damon/dbgfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
index faee070977d8..2741ff79e8e8 100644
--- a/mm/damon/dbgfs.c
+++ b/mm/damon/dbgfs.c
@@ -32,7 +32,7 @@ static char *user_input_str(const char __user *buf, size_t count, loff_t *ppos)
 	if (*ppos)
 		return ERR_PTR(-EINVAL);
 
-	kbuf = kmalloc(count + 1, GFP_KERNEL);
+	kbuf = kmalloc(count + 1, GFP_KERNEL | __GFP_NOWARN);
 	if (!kbuf)
 		return ERR_PTR(-ENOMEM);
 
@@ -247,7 +247,7 @@ static ssize_t dbgfs_kdamond_pid_read(struct file *file,
 	char *kbuf;
 	ssize_t len;
 
-	kbuf = kmalloc(count, GFP_KERNEL);
+	kbuf = kmalloc(count, GFP_KERNEL | __GFP_NOWARN);
 	if (!kbuf)
 		return -ENOMEM;
 
-- 
2.17.1


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

* [PATCH for-5.15.x 2/2] mm/damon/dbgfs: fix missed use of damon_dbgfs_lock
  2021-11-21 11:02 [PATCH for-5.15.x 0/2] DAMON fixes SeongJae Park
  2021-11-21 11:02 ` [PATCH for-5.15.x 1/2] mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation SeongJae Park
@ 2021-11-21 11:02 ` SeongJae Park
  2021-11-22 12:28 ` [PATCH for-5.15.x 0/2] DAMON fixes Greg KH
  2 siblings, 0 replies; 4+ messages in thread
From: SeongJae Park @ 2021-11-21 11:02 UTC (permalink / raw)
  To: stable, gregkh
  Cc: akpm, linux-mm, linux-kernel, SeongJae Park, Linus Torvalds

commit d78f3853f831eee46c6dbe726debf3be9e9c0d05 upstream.

DAMON debugfs is supposed to protect dbgfs_ctxs, dbgfs_nr_ctxs, and
dbgfs_dirs using damon_dbgfs_lock.  However, some of the code is
accessing the variables without the protection.  This fixes it by
protecting all such accesses.

Link: https://lkml.kernel.org/r/20211110145758.16558-3-sj@kernel.org
Fixes: 75c1c2b53c78 ("mm/damon/dbgfs: support multiple contexts")
Signed-off-by: SeongJae Park <sj@kernel.org>
Cc: <stable@vger.kernel.org> # 5.15.x
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 mm/damon/dbgfs.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c
index 2741ff79e8e8..f94d19a690df 100644
--- a/mm/damon/dbgfs.c
+++ b/mm/damon/dbgfs.c
@@ -538,12 +538,14 @@ static ssize_t dbgfs_monitor_on_write(struct file *file,
 		return -EINVAL;
 	}
 
+	mutex_lock(&damon_dbgfs_lock);
 	if (!strncmp(kbuf, "on", count))
 		err = damon_start(dbgfs_ctxs, dbgfs_nr_ctxs);
 	else if (!strncmp(kbuf, "off", count))
 		err = damon_stop(dbgfs_ctxs, dbgfs_nr_ctxs);
 	else
 		err = -EINVAL;
+	mutex_unlock(&damon_dbgfs_lock);
 
 	if (err)
 		ret = err;
@@ -596,15 +598,16 @@ static int __init __damon_dbgfs_init(void)
 
 static int __init damon_dbgfs_init(void)
 {
-	int rc;
+	int rc = -ENOMEM;
 
+	mutex_lock(&damon_dbgfs_lock);
 	dbgfs_ctxs = kmalloc(sizeof(*dbgfs_ctxs), GFP_KERNEL);
 	if (!dbgfs_ctxs)
-		return -ENOMEM;
+		goto out;
 	dbgfs_ctxs[0] = dbgfs_new_ctx();
 	if (!dbgfs_ctxs[0]) {
 		kfree(dbgfs_ctxs);
-		return -ENOMEM;
+		goto out;
 	}
 	dbgfs_nr_ctxs = 1;
 
@@ -615,6 +618,8 @@ static int __init damon_dbgfs_init(void)
 		pr_err("%s: dbgfs init failed\n", __func__);
 	}
 
+out:
+	mutex_unlock(&damon_dbgfs_lock);
 	return rc;
 }
 
-- 
2.17.1


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

* Re: [PATCH for-5.15.x 0/2] DAMON fixes
  2021-11-21 11:02 [PATCH for-5.15.x 0/2] DAMON fixes SeongJae Park
  2021-11-21 11:02 ` [PATCH for-5.15.x 1/2] mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation SeongJae Park
  2021-11-21 11:02 ` [PATCH for-5.15.x 2/2] mm/damon/dbgfs: fix missed use of damon_dbgfs_lock SeongJae Park
@ 2021-11-22 12:28 ` Greg KH
  2 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2021-11-22 12:28 UTC (permalink / raw)
  To: SeongJae Park; +Cc: stable, akpm, linux-mm, linux-kernel

On Sun, Nov 21, 2021 at 11:02:09AM +0000, SeongJae Park wrote:
> This patchset is a backport of DAMON fixes that merged in the mainline,
> for v5.15.x stable series.
> 
> SeongJae Park (2):
>   mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer
>     allocation
>   mm/damon/dbgfs: fix missed use of damon_dbgfs_lock
> 
>  mm/damon/dbgfs.c | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> -- 
> 2.17.1
> 

Now queued up, thanks for the backports.

greg k-h

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

end of thread, other threads:[~2021-11-22 12:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-21 11:02 [PATCH for-5.15.x 0/2] DAMON fixes SeongJae Park
2021-11-21 11:02 ` [PATCH for-5.15.x 1/2] mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation SeongJae Park
2021-11-21 11:02 ` [PATCH for-5.15.x 2/2] mm/damon/dbgfs: fix missed use of damon_dbgfs_lock SeongJae Park
2021-11-22 12:28 ` [PATCH for-5.15.x 0/2] DAMON fixes Greg KH

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).