From patchwork Wed Nov 10 14:57:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12612325 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8773C433EF for ; Wed, 10 Nov 2021 14:58:28 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 687D961205 for ; Wed, 10 Nov 2021 14:58:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 687D961205 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 072C06B0071; Wed, 10 Nov 2021 09:58:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 022236B0072; Wed, 10 Nov 2021 09:58:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E53F56B0073; Wed, 10 Nov 2021 09:58:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0177.hostedemail.com [216.40.44.177]) by kanga.kvack.org (Postfix) with ESMTP id D6B546B0071 for ; Wed, 10 Nov 2021 09:58:27 -0500 (EST) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 98DF482265 for ; Wed, 10 Nov 2021 14:58:27 +0000 (UTC) X-FDA: 78793326654.14.959DE68 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf20.hostedemail.com (Postfix) with ESMTP id 7CA02D000657 for ; Wed, 10 Nov 2021 14:58:10 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 50CB761205; Wed, 10 Nov 2021 14:58:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636556300; bh=wVl1UaUEL3yKERyB5XOdBAhxETQh6Uu2L+EMIBFpdJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UdJH0Kkp3Hv2JMeVRT8GM3ZpEkDybXPwgajDyAEGPu2FCYpuExvUJj3JAw89DBk0+ rT5BhZ1jC+H1ZzRxNaZdRby06mQ8dUzlwNvz6GIgzVUQsHGIM8TdtcVEdfh/XXik7f v8Yn9TzaaR3oB9CQiSuN2EFuWkb+57chN3lR89DObknWbgBKTmzIZPXhTOY8194nwi xsHkGxg/R2UM6sYe/aB44xf3JKa7POtZpQ+tsZ+juYGzCQg4YJVzkRNLMayummZAj0 GTD1c8NEIIHRPWYxTHe2vBONKg/eL0ADR3La9+5NfkBu3rvAIA1P9v4hfDyMqpjPiO Ffff0YYsNjpiw== From: SeongJae Park To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 1/2] mm/damon/dbgfs: Use '__GFP_NOWARN' for user-specified size buffer allocation Date: Wed, 10 Nov 2021 14:57:57 +0000 Message-Id: <20211110145758.16558-2-sj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211110145758.16558-1-sj@kernel.org> References: <20211110145758.16558-1-sj@kernel.org> X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 7CA02D000657 X-Stat-Signature: r5k3kd1e8zn9knujnuopwdsd8zrequxq Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=UdJH0Kkp; spf=pass (imf20.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: 1636556290-713133 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: 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. Fixes: 4bc05954d007 ("mm/damon: implement a debugfs-based user space interface") Signed-off-by: SeongJae Park --- mm/damon/dbgfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index eccc14b34901..8ce1311ac533 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); @@ -133,7 +133,7 @@ static ssize_t dbgfs_schemes_read(struct file *file, char __user *buf, char *kbuf; ssize_t len; - kbuf = kmalloc(count, GFP_KERNEL); + kbuf = kmalloc(count, GFP_KERNEL | __GFP_NOWARN); if (!kbuf) return -ENOMEM; @@ -452,7 +452,7 @@ static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf, char *kbuf; ssize_t len; - kbuf = kmalloc(count, GFP_KERNEL); + kbuf = kmalloc(count, GFP_KERNEL | __GFP_NOWARN); if (!kbuf) return -ENOMEM; @@ -578,7 +578,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 Wed Nov 10 14:57:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12612327 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1255C433F5 for ; Wed, 10 Nov 2021 14:58:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6053A61205 for ; Wed, 10 Nov 2021 14:58:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6053A61205 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id F1BA56B0072; Wed, 10 Nov 2021 09:58:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2BB26B0073; Wed, 10 Nov 2021 09:58:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF39B6B0074; Wed, 10 Nov 2021 09:58:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0217.hostedemail.com [216.40.44.217]) by kanga.kvack.org (Postfix) with ESMTP id C18876B0072 for ; Wed, 10 Nov 2021 09:58:29 -0500 (EST) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 51C878224F for ; Wed, 10 Nov 2021 14:58:29 +0000 (UTC) X-FDA: 78793326738.31.6628C7B Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf26.hostedemail.com (Postfix) with ESMTP id 18EE12001713 for ; Wed, 10 Nov 2021 14:58:25 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 271E56121F; Wed, 10 Nov 2021 14:58:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636556304; bh=bEYLEpQQ/QKPQQ1OXoATAhxucj4jMroHnPUyPDZXhY4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f1jSpjjjVxqXU2XTM9p8NxigTx/aKWoco2eyDBvti78m/lv/NvYKT5qm2sOVmhkr0 x4K3tfxY7zTXaiItbmovJmSqr8VRgXzCV2fdq3IZVFfLA/pyBTl+GUSQBw1E6OeTko f8AFQVYDFuHBIanKTMKsSEGhcg6cCwf/IOX/OXkMwwqglHOOQ9V+KN6OcgWOz/9g/z +Y72/tlDfLwsz0ABVaHzLnbBARcqjqxmB2vx9SzsrpkVQNDlUcfHqF6+Oy6Z2jG8no PmNudwvFiZHJkbVg6/nlUIX2/urAg8quvydxZgyJ6ngnn9u6uzXmgfi/hSqdumq/RP z9jlYip3Yadbg== From: SeongJae Park To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 2/2] mm/damon/dbgfs: Fix missed use of damon_dbgfs_lock Date: Wed, 10 Nov 2021 14:57:58 +0000 Message-Id: <20211110145758.16558-3-sj@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211110145758.16558-1-sj@kernel.org> References: <20211110145758.16558-1-sj@kernel.org> X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 18EE12001713 X-Stat-Signature: zhqbosrre1765nd7epe6z16sqqfxpi5a Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=f1jSpjjj; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf26.hostedemail.com: domain of sj@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=sj@kernel.org X-HE-Tag: 1636556305-146644 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: 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 commit fixes it by protecting all such accesses. Fixes: 75c1c2b53c78 ("mm/damon/dbgfs: support multiple contexts") Signed-off-by: SeongJae Park --- mm/damon/dbgfs.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index 8ce1311ac533..9b520bb4a3e7 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -877,12 +877,14 @@ static ssize_t dbgfs_monitor_on_write(struct file *file, return -EINVAL; } + mutex_lock(&damon_dbgfs_lock); if (!strncmp(kbuf, "on", count)) { int i; for (i = 0; i < dbgfs_nr_ctxs; i++) { if (damon_targets_empty(dbgfs_ctxs[i])) { kfree(kbuf); + mutex_unlock(&damon_dbgfs_lock); return -EINVAL; } } @@ -892,6 +894,7 @@ static ssize_t dbgfs_monitor_on_write(struct file *file, } else { ret = -EINVAL; } + mutex_unlock(&damon_dbgfs_lock); if (!ret) ret = count; @@ -944,15 +947,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; @@ -963,6 +967,8 @@ static int __init damon_dbgfs_init(void) pr_err("%s: dbgfs init failed\n", __func__); } +out: + mutex_unlock(&damon_dbgfs_lock); return rc; }