From mboxrd@z Thu Jan 1 00:00:00 1970 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 2B7A2C00140 for ; Sun, 21 Aug 2022 17:53:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C8FA6B0073; Sun, 21 Aug 2022 13:53:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25DE66B0074; Sun, 21 Aug 2022 13:53:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 118FB8E0001; Sun, 21 Aug 2022 13:53:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0086B6B0073 for ; Sun, 21 Aug 2022 13:53:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9AC88407BD for ; Sun, 21 Aug 2022 17:53:50 +0000 (UTC) X-FDA: 79824347820.16.8529A78 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf04.hostedemail.com (Postfix) with ESMTP id F33AF4010F for ; Sun, 21 Aug 2022 17:52:20 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 49CE5B80B77; Sun, 21 Aug 2022 17:52:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F7EAC433C1; Sun, 21 Aug 2022 17:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661104338; bh=4p7yfjIq1tiv/g9ut0gygVgmob/tNi6cVnkLCUCXz10=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JkdQhCJR/uZHyTuzxZahcWiQtflHyk0dww9r8YWVQFIDxSanYudlw4B/HZQ3qmpf2 bVCsro16+QMYkszaBCg20ENA2E5TlH0d7VIojnosLTR4BjdmpfKu5uB5NXJzHa8NMg 7Vlu5pJGi6c2igKdd/irLW0PBoqvXcDAIbyJuI/D/8Sxxv0NUCkAHemN7LyJWDfn/T CusgC/HcHiSOtboPo/jfwNZKV4drJoDZ2NCFK4g5Q7RyISK9Y/MzdkcF+p2CA9Lr1V lc3Z/KKdjLnB96GwDEpjt5iRjzn+KOcd5JgqI1eIyup7yRTawRbdmv/hV+dujxT+Yq 5H4Meemt8OAUA== From: SeongJae Park To: Greg KH Cc: Andrew Morton , SeongJae Park , badari.pulavarty@intel.com, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] mm/damon/dbgfs: avoid duplicate context directory creation Date: Sun, 21 Aug 2022 17:52:15 +0000 Message-Id: <20220821175215.152419-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661104341; a=rsa-sha256; cv=none; b=Lj24Ag3iIs+H/v41/D8upBz9iO3iuiVUmrWf0Z2C9eXOQvwoXRoHaZdFdQ9gPKr3/ddWOU 7tjUBoLxyjLhWG3cS26RA3/r1X5Zqag7qe7Ao3spCTJ56/77MjpSGA+PAbo1MlglwwOFxC BuPYNc1O9xDlWmvyVVL4BxsgZXfmHRI= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JkdQhCJR; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661104341; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=WQglBhLUcsDtz58iy/7oFZZagr5Tta5yAZtGTSs3/0c=; b=YgvJXZyVW/jxAufgwhWkkbr5n6i44Tlighr6i7AS/0hruCQqQS36LTBxUiupA2QtSZeEw4 eDE/6pQ0cV7kpRjsaxFgwkPPQQLQTuP1gZs7AEAiuNHj/ouQ+aMasQUoTtNicQ8A4t0+7u 2eDXN6VPQx6w3L6Pbx9uAFjkhbZ4vSc= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=JkdQhCJR; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of sj@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspam-User: X-Stat-Signature: miqxbybzfprgg4p7rn8jpbrxs1jwpysk X-Rspamd-Queue-Id: F33AF4010F X-Rspamd-Server: rspam06 X-HE-Tag: 1661104340-630805 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: Hi Greg, On Sat, 20 Aug 2022 19:32:37 +0200 Greg KH wrote: > On Fri, Aug 19, 2022 at 02:08:09PM -0700, Andrew Morton wrote: > > On Fri, 19 Aug 2022 17:19:30 +0000 SeongJae Park wrote: > > > > > From: Badari Pulavarty > > > > > > When user tries to create a DAMON context via the DAMON debugfs > > > interface with a name of an already existing context, the context > > > directory creation silently fails but the context is added in the > > > internal data structure. As a result, memory could leak and DAMON > > > cannot be turned on. An example test case is as below: > > > > > > # cd /sys/kernel/debug/damon/ > > > # echo "off" > monitor_on > > > # echo paddr > target_ids > > > # echo "abc" > mk_context > > > # echo "abc" > mk_context > > > # echo $$ > abc/target_ids > > > # echo "on" > monitor_on <<< fails > > > > > > This commit fixes the issue by checking if the name already exist and > > > immediately returning '-EEXIST' in the case. > > > > > > ... > > > > > > --- a/mm/damon/dbgfs.c > > > +++ b/mm/damon/dbgfs.c > > > @@ -795,7 +795,7 @@ static void dbgfs_destroy_ctx(struct damon_ctx *ctx) > > > */ > > > static int dbgfs_mk_context(char *name) > > > { > > > - struct dentry *root, **new_dirs, *new_dir; > > > + struct dentry *root, **new_dirs, *new_dir, *dir; > > > struct damon_ctx **new_ctxs, *new_ctx; > > > > > > if (damon_nr_running_ctxs()) > > > @@ -817,6 +817,12 @@ static int dbgfs_mk_context(char *name) > > > if (!root) > > > return -ENOENT; > > > > > > + dir = debugfs_lookup(name, root); > > > + if (dir) { > > > + dput(dir); > > > + return -EEXIST; > > > + } > > > + > > > new_dir = debugfs_create_dir(name, root); > > > dbgfs_dirs[dbgfs_nr_ctxs] = new_dir; > > > > It would be simpler (and less racy) to check the debugfs_create_dir() > > return value for IS_ERR()? > > > > Yes, if you _HAVE_ to know if the code works properly (i.e. because your > feature totally depends on debugfs like damon does), or you have a > potential duplicate name like this, then sure, check the return value > and do something based on it. > > It's odd enough that you should put a comment above the check just so I > don't go and send a patch to delete it later on :) Thank you for the kind explanation, Greg. I will revise this patch to simply check the return value with a comment noticing it's really needed due to the potential duplicate names. Thanks, SJ > > thanks, > > greg k-h >