From patchwork Sun Nov 21 11:02:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12630733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AF1DC433EF for ; Sun, 21 Nov 2021 11:03:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12ED76B0072; Sun, 21 Nov 2021 06:02:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0DF4F6B0073; Sun, 21 Nov 2021 06:02:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F0F986B0074; Sun, 21 Nov 2021 06:02:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id E37586B0072 for ; Sun, 21 Nov 2021 06:02:37 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AAEB48CA5C for ; Sun, 21 Nov 2021 11:02:27 +0000 (UTC) X-FDA: 78832648734.29.F2EBA10 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf16.hostedemail.com (Postfix) with ESMTP id 50A83F00009F for ; Sun, 21 Nov 2021 11:02:24 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id A60C660E75; Sun, 21 Nov 2021 11:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637492546; bh=3WQ4Hy7C4N5e4Mvc456YSywZpMU1nWyWDKWdhSHcNnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qnFzF2aA3uKsbVnIMdsR+RLFjNe1tXP0MbB5i1nVyhrrqjApWcsueb/B8SOzynnwY OEFmo/XVkpyCvv0aR8wZ4hzphjiT+uWsWQ8EsluTRaUuKaiOJBOomPN/3F1K74sjzx ymwiXeksCEmPM7dlaglJ9g4oai2za8L3UXKMGzqW01epFW/F3LFuJWpAOHdNASxI0l KmV1TpNCQY6tbn/QVYu4Cbfz27WIAlDPCHc2UW161w3w23MznuhnfKd6ADgVQiU17z SUZvMFRBD8WolDjiSSAjypWIJefIYIvDSaNXiGYvGEdwH/vbYrltN50AhVyPYqV4nC PflKb1MCumrmw== From: SeongJae Park To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park , Linus Torvalds Subject: [PATCH for-5.15.x 1/2] mm/damon/dbgfs: use '__GFP_NOWARN' for user-specified size buffer allocation Date: Sun, 21 Nov 2021 11:02:10 +0000 Message-Id: <20211121110211.17032-2-sj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211121110211.17032-1-sj@kernel.org> References: <20211121110211.17032-1-sj@kernel.org> X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 50A83F00009F X-Stat-Signature: t3cnytrbgqek3cgb7e3j1sy8kttrqijh Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=qnFzF2aA; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of sj@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1637492544-577997 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Cc: # 5.15.x Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- 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; From patchwork Sun Nov 21 11:02:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12630743 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EB7BC433F5 for ; Sun, 21 Nov 2021 11:03:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CB8F6B0073; Sun, 21 Nov 2021 06:02:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 17D266B0074; Sun, 21 Nov 2021 06:02:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 043746B0075; Sun, 21 Nov 2021 06:02:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id EAB5B6B0073 for ; Sun, 21 Nov 2021 06:02:40 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id B28CA82E23ED for ; Sun, 21 Nov 2021 11:02:30 +0000 (UTC) X-FDA: 78832648860.16.9C2AF84 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf15.hostedemail.com (Postfix) with ESMTP id 3D256D0000AD for ; Sun, 21 Nov 2021 11:02:27 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id B67AD608FB; Sun, 21 Nov 2021 11:02:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637492549; bh=Ufdx8ARO4THgjUCgnF+gxz8aDr/YgOiNmfXPT9ZpqNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZBF83KaobljbaaJHUuggWujZFm3neyoLpPN16qo3IUNGlLYGLYtmBB/l6Mko3JQEY qfRHQbd0pnJpTKrTHsaEWFxkFnCeGL3disH4QTConTzOfDroNBhIbV5868l6TOYEux tdzZRbAk/PPtkBv7RFRY5kK+UgLKT24sRlUSSqkBCueWwn4IFl2oq7/3yEgQwkU69O g5blPr7aZhJ088ee+TAVwMjQzzaQNpzPPeHTpC4iYV0m+FbCGdMfKvV9kpcHJoQibq mll/nT7nliW+YpMVBsdbzEbRXV/p/p+wsPpXNjGo9XgQvMWno2lR1piAPa8HTcde2Z frViPCtFB7Ygw== From: SeongJae Park To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park , Linus Torvalds Subject: [PATCH for-5.15.x 2/2] mm/damon/dbgfs: fix missed use of damon_dbgfs_lock Date: Sun, 21 Nov 2021 11:02:11 +0000 Message-Id: <20211121110211.17032-3-sj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211121110211.17032-1-sj@kernel.org> References: <20211121110211.17032-1-sj@kernel.org> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 3D256D0000AD X-Stat-Signature: 3aof6mwrohpsiotnepatwmt39j6e9obn Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZBF83Kao; spf=pass (imf15.hostedemail.com: domain of sj@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sj@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-HE-Tag: 1637492547-768072 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 Cc: # 5.15.x Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- 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; }