Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp1568784rwa; Sun, 21 Aug 2022 11:19:47 -0700 (PDT) X-Google-Smtp-Source: AA6agR4t+X1gHB9wuHGZ7Eshu9hp9IdNveMtQpPC+TStH9pKtEbzErhUWdb9TiC7iqpiz2l2OVZp X-Received: by 2002:a17:903:230e:b0:172:ccb3:f4de with SMTP id d14-20020a170903230e00b00172ccb3f4demr9104485plh.18.1661105987087; Sun, 21 Aug 2022 11:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661105987; cv=none; d=google.com; s=arc-20160816; b=b1cgERK7oFDnNiZiRHai+dw3vP+58o/YaJ2dCsfH/cTX2Hvo5ONMXHo6VLbzmtspq2 E/aJKeE7u6ENVwWdyePy/Qqm2FfCCwunevYHsi2JZS2xAmicYFvKpXxxS9CZvhb8yJEM A/NcXUCnP3S81DZX8I2UH/8SsO9T01Df6GbH5iVqhXXEOT9EmLd16gb/R/YCid0n51lT wRhn3OVmwk4QDebgZOY3k1D2/mkwxdZmJQyTxpkcmQxASF5zmTYmyapaV9jxzIebkMfc ThT4B31moC+F6wJatGH12o1bC4PiI8/0SAgR87wPrhrReRTJY7S0F/p/y1IpRONen4lS B9hQ== 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=WQglBhLUcsDtz58iy/7oFZZagr5Tta5yAZtGTSs3/0c=; b=gT40xW2kE4l7cSALjaYs5UzqlNRtSowJjEQFUOghdMBKLyW7QCcITytBoCSBn8X5zV idxfpar6xH/CWtV52tHyJG43TkwIb/meb+WDuMksTTmOClgmG87XC5vmaaZjSq+qjWfh o+EZ7VRggcjlxxUys6ncA1qLtOXIob8HLd7JJEgc3KB0LguW0X+LsekKkq3GQM5LpGyG NI2o0KX3fktYgLSo0xvjnJdspN0XUvbY3M5XJjMZ1SS7TXeNzhp2zibOSsDMqCVzpI24 8ungFhHSkM2HO1nnP/AY7vWOrXkrgkv4W42YeKA7H4eje7ueX59mAFmGU5lngatDEsQj uz8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JkdQhCJR; 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 s15-20020a17090302cf00b00172cf750179si5892643plk.544.2022.08.21.11.19.36; Sun, 21 Aug 2022 11:19:47 -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=JkdQhCJR; 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 S229505AbiHURwV (ORCPT + 99 others); Sun, 21 Aug 2022 13:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229491AbiHURwU (ORCPT ); Sun, 21 Aug 2022 13:52:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A4C18357; Sun, 21 Aug 2022 10:52:19 -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 B4B6660F31; Sun, 21 Aug 2022 17:52:18 +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 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 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 >