Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2064633rwb; Fri, 19 Aug 2022 14:40:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR5szpzkZMbbmTONhcxsY+8ci/B6q4JCcob2wt+uGJi6UdR8M7leXRJHTNVvR6ETmBeuZvQc X-Received: by 2002:a63:e342:0:b0:42a:411:fa34 with SMTP id o2-20020a63e342000000b0042a0411fa34mr7104732pgj.89.1660945222751; Fri, 19 Aug 2022 14:40:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660945222; cv=none; d=google.com; s=arc-20160816; b=JFhf/Z2oDjKghm5G+2vxNUx5m7Zzt7lZfk0jNILVBtvCJ7qCAwe6J3ci/aOivtL2yf SsY3lQ/OTOhXG8Uz+j3rHxAZ1mSKg0S5QJIOu194unaMeBR6A5/AJVAGD50gs2ipb4tQ FtvYHPx64k4jRUCyK3bbjYikLFoBulxzuFuJYeWZ/jsF6FUSIWR3Wd6GNEnKwqUD0lKU hcaLj4E8JEYC7VLxjxYAdmFYHdY9nRyrAUDyJeyt9NxGF4pK7qMPk1TzfnEeL8y171Fv 5sBGkLa5Ogsf69WBivw7bWA8z4fy9vITAoSTmv6fABzaRRAKEnsKHjgDwgai9t91fYua KH4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XNRyJKw6pVcefHs8RgmXzxv6AiCGEbt2gjrU0xvplPI=; b=KrSNZ3S/5T4rY4nGNIR8LuJPRxTtwK4XuHljwJuwO85JChBoT7djL3uJqZ2KagN4vq GYEgOvbZgsJEZtmMkxFp4lobILmMpI9ImUv7WF3I2DaLdYYo9C42wVZQSAou6PQwaLX7 RQTuXh5c+pTF3cNvl7nPkHiYkv4tSSgygYkV8ONmA+BvikmrIrsHqqSjyzpEzpbjEkM4 xAeXoxHx/8ED2/NT/316dJhcxNgKJthSieND8tF9H1wKyI4LjiFjr0WxEQXQSwrpt0o3 Khu1lknsx+QYlsQsvvue700MHLGNhXAyuCdeQ0SCQ8Pr20ZlrVUI0WmBkTMnbJCGoyhu M1Fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y550pgYD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c4-20020a170903234400b0016360b6cec1si5204928plh.230.2022.08.19.14.40.11; Fri, 19 Aug 2022 14:40:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Y550pgYD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352373AbiHSVQh (ORCPT + 99 others); Fri, 19 Aug 2022 17:16:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59748 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352273AbiHSVQf (ORCPT ); Fri, 19 Aug 2022 17:16:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7DDDE7265; Fri, 19 Aug 2022 14:16:34 -0700 (PDT) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 3C6BD616E4; Fri, 19 Aug 2022 21:16:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05B56C433D6; Fri, 19 Aug 2022 21:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660943793; bh=GOhiVfsBqX2y7z90q7076zjMmF36TVkpwUIPXpa8SDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y550pgYDKfKcM94iqZr/Kgq976SROYgaTEdPCdGJTjVuM9A8E9QcWgimbBLXTrhgC wFFQeAuB8KcNOT+QpevCOXkINubcBNAPa1d24Q0EBAxU5908J5ExF6xMOcwgxZDNUN OfF9Ohl6YRulDg4I8E9E1kcGPHJ2yCG7Qwf0n7NalTbH08DnVK91ipOBZrpsgsIIaI 5h7yZxM71gpMmuIQjUh353asy0fDMY8F/VJCNC9aoB/cAswa6sDF6nVNMniOi8WrcH eJm1uH+UyCmoqEMAiM9/PlgF9nleEDZlPAKon/5iBGyNTQ/7zdDIQWWp2cub8TYMt9 JYqLUlDZr7G+w== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , gregkh@linuxfoundation.org, 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: Fri, 19 Aug 2022 21:16:31 +0000 Message-Id: <20220819211631.16658-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220819140809.1e3929fd8f50bfc32cae31d3@linux-foundation.org> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 19 Aug 2022 14:08:09 -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()? I was merely following Greg's previous advice for ignoring the return value[1] of the function, but I might misunderstanding his intention, so CC-ing Greg. Greg, may I ask your opinion? [1] https://lore.kernel.org/linux-mm/YB1kZaD%2F7omxXztF@kroah.com/ Thanks, SJ