Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2554315rwb; Mon, 3 Oct 2022 02:28:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM69BAvfoPJev+KzefHyy2w1ArA3S85HF4DTnCCVvbJ+LtlQRI4cflUJLYv4XiUt+Nr1HsOn X-Received: by 2002:aa7:de10:0:b0:458:e101:fe54 with SMTP id h16-20020aa7de10000000b00458e101fe54mr5265727edv.80.1664789288284; Mon, 03 Oct 2022 02:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664789288; cv=none; d=google.com; s=arc-20160816; b=gtdkdQDrR3GaW6s4YMR74tOKxd5QV3PocdiI0dXlbge1suOR5m75Cc4Q5mXrlwUdPe yKz5ghTuy73cbehYbiNWZ3YB8ie+B+zPNPteyAXBeHkc1WKLMQAOCGmby/fC1FGXiUEy 5uV4RiZnW9yj/CRsEfLMu0zYdOWuICsMBKRjjtSpqXHareGaGtR007zdNusbp7YKYYRW 4xuN+mSU8n3bC2twc++4bw9zixGp/HM6X9IDmMyPNSGr1cFIzXhfFImx4m12N5QjOHRK ggY8oxiUxPw2dvbETayD0X/YxdUkGHC2y8mRYZJzxyytwuBs7SKc+4GszGL9/As+HDp0 pTtA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fkEktzsIFZo47QlWj/NKPQzZXbdctsSr5vOwkotnxQk=; b=y0nHXxPE7M8kbiJzXsZPC9vp4zJ0hhNRSZSLEqsbFNlCMIUWHF14RsdWJihw3zHVkT a3RQYqaEHfUKKvObUYKDdiPx6IWAD+SuqaNw1Vnc/InpkGajClR0pjA5b2yc6+jlrH4K 3VxXfLdrNSqigQf9+wf4PjSd9cCd7tQHZ6uOaozELqoewxUDXlpCd9paRag1sJVOCbdx YI3tiVLJQh5UZBuZfKmyCQhatzBGDmV23DWhg0N+jkCBW7fC/AYdUaHG/jfN/a9U9prE WNUaGOe9hU3SpkpSxEsZ/NM0xNy0uRJky/ImszgaVHjc71QB8VqUyeROY7yAvonNtTZu ezXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=HOvIIDpx; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g25-20020a50d0d9000000b00457463dfc74si7729228edf.83.2022.10.03.02.27.41; Mon, 03 Oct 2022 02:28:08 -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=@linuxfoundation.org header.s=korg header.b=HOvIIDpx; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbiJCIlP (ORCPT + 99 others); Mon, 3 Oct 2022 04:41:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230195AbiJCIk4 (ORCPT ); Mon, 3 Oct 2022 04:40:56 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B91521EC60; Mon, 3 Oct 2022 01:15:14 -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 sin.source.kernel.org (Postfix) with ESMTPS id C895ECE0B1B; Mon, 3 Oct 2022 07:17:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5891EC433B5; Mon, 3 Oct 2022 07:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781434; bh=OMhC/0OyVug3ZfZTIbErceYWR0Edznp98eG1Zj1b+TU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HOvIIDpxR5mcsNIVA0OaulbAq+nDU4DDpsrA/IHq4Bog2uOzaGDtfPO0VyzbPVu6a nHq6CRSHHpwyxJNAjVGXWWHNWiXv/Ydeh3uent2eknUfHLznCHe3XhSS6Leh5A0jG1 9nlKvKZLvrpNt9iDqOlrPGObDowsVKmRct8J193Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, SeongJae Park , Andrew Morton Subject: [PATCH 5.15 19/83] mm/damon/dbgfs: fix memory leak when using debugfs_lookup() Date: Mon, 3 Oct 2022 09:10:44 +0200 Message-Id: <20221003070722.466233554@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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 From: Greg Kroah-Hartman commit 1552fd3ef7dbe07208b8ae84a0a6566adf7dfc9d upstream. When calling debugfs_lookup() the result must have dput() called on it, otherwise the memory will leak over time. Fix this up by properly calling dput(). Link: https://lkml.kernel.org/r/20220902191149.112434-1-sj@kernel.org Fixes: 75c1c2b53c78b ("mm/damon/dbgfs: support multiple contexts") Signed-off-by: Greg Kroah-Hartman Signed-off-by: SeongJae Park Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- mm/damon/dbgfs.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -443,6 +443,7 @@ static int dbgfs_rm_context(char *name) struct dentry *root, *dir, **new_dirs; struct damon_ctx **new_ctxs; int i, j; + int ret = 0; if (damon_nr_running_ctxs()) return -EBUSY; @@ -457,14 +458,16 @@ static int dbgfs_rm_context(char *name) new_dirs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs), GFP_KERNEL); - if (!new_dirs) - return -ENOMEM; + if (!new_dirs) { + ret = -ENOMEM; + goto out_dput; + } new_ctxs = kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs), GFP_KERNEL); if (!new_ctxs) { - kfree(new_dirs); - return -ENOMEM; + ret = -ENOMEM; + goto out_new_dirs; } for (i = 0, j = 0; i < dbgfs_nr_ctxs; i++) { @@ -484,7 +487,13 @@ static int dbgfs_rm_context(char *name) dbgfs_ctxs = new_ctxs; dbgfs_nr_ctxs--; - return 0; + goto out_dput; + +out_new_dirs: + kfree(new_dirs); +out_dput: + dput(dir); + return ret; } static ssize_t dbgfs_rm_context_write(struct file *file,