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; }