Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp751955imw; Thu, 14 Jul 2022 10:07:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u0bhzmR6fYvxdrPZjId2ir4Pp+90EEpIjDz/WdmFlu6HYbzVOS27ihjwQltIZYgh0iBVwz X-Received: by 2002:a17:906:98c9:b0:72b:40de:9afe with SMTP id zd9-20020a17090698c900b0072b40de9afemr9941116ejb.620.1657818438920; Thu, 14 Jul 2022 10:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657818438; cv=none; d=google.com; s=arc-20160816; b=RYZx1Ulp3JmvcLVzzaiQODW5gsD7wJ4WAplIwZuz01ZMvKdfQf1We17NdS/aC221jM pCqkqJq8VN7pvM++iSpW/R9QeeBk/ak0vuuTQndeb1kd/w7MSS0LVaAw4wfw/rdSxPJN w9X6bgeeY6OfJRyN+DuwdH3g7UA9p356bX1+tvhPyB56JzwZVySORwLXUoKlFQkkddlF XSS2i/fXg9PdGuRPyfpC1eyus84yRAc4oJq9IIOcjC6l00jcLF5IoFOrw2tiLvP0T6FR BA6+JVXizWRIgmyIFXD5+49Wm6ZrdpoN14dMTCjF/vpzcBeUydY8F4wAXhXZZmSSMpg6 DeVw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=opbyVZRHixyIq2FqQgugLDc4qvcV2UJiUjucmzPNTxQ=; b=wNW9M5wuBLrr0f6JNILV/J/I8LQ+huekk9YK3EU5UFUJVy4O3n3NF6at9ddYVjhN1B BEXci56uin4QLkF62+/4oN83JspHPmyzZ8G8/J30BoMqwNvc4GGE7CMZACQNiNu4aqus A8vBQO1zz5knFtlyxs6VFHP84ZCtcO9rv7axEREpWhr+0bCpMWUYtGxX1fUV95L6goGF MyC2w+0npC11lxMmQeu+F45HJXDR7ZStgO6K05q8WfuTQ+8zRumL8kKbfBOSRYktwjvK R1c2yvVm9XYSalSTl+h6H0NxsfrGd6BW77LOi6w0nDn7lHut9JOgJdT4gccuUS/uqKPl ehdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="PUls/OjF"; 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 jz19-20020a170906bb1300b00722f52f1dd4si691714ejb.809.2022.07.14.10.06.54; Thu, 14 Jul 2022 10:07:18 -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="PUls/OjF"; 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 S240112AbiGNRFU (ORCPT + 99 others); Thu, 14 Jul 2022 13:05:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232398AbiGNRFL (ORCPT ); Thu, 14 Jul 2022 13:05:11 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2C028711 for ; Thu, 14 Jul 2022 10:05:10 -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 64734CE2978 for ; Thu, 14 Jul 2022 17:05:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDBF4C34114; Thu, 14 Jul 2022 17:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657818307; bh=WadMQH2Ma9dG1nxvj1p2IIitBxICYq77zOLfBOTGYgg=; h=From:To:Cc:Subject:Date:From; b=PUls/OjFdJhBE9Z5qItunWM8OW6ncv/3+aGrs4HWLkdPET+VLoDMqrN3Sum6FT/+5 MspF7aN9T1FuLVK6eRspz8G7Bgh8JkXhjKFmWrQK59zNI5eZMfzwcQFKXInGMZ71w8 2W0xlW6yJCK/7yBRVHQ87I+RSJZoq8D1K+7jYP03IpHi5TBz3mTZWzh7b7cHcJxZHi tkQWPniVzUu0aEkTeeA6hnidQJ+bnBgJost+W+eOJWKPHTXow6bXEQmr+sPas60/YS oH6tHa32H7doMnvtlZ53DZPjwmLbzY7AlzviaMeWgvMsfIT903nhKesEKZwQeQHBA6 3FCocgCOX3/5A== From: SeongJae Park To: akpm@linux-foundation.org Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH for mm-stable] mm/damon/lru_sort: fix potential memory leak in damon_lru_sort_init() Date: Thu, 14 Jul 2022 17:04:58 +0000 Message-Id: <20220714170458.49727-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 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 'damon_lru_sort_init()' returns an error when 'damon_select_ops()' fails without freeing 'ctx' which allocated before. This commit fixes the potential memory leak by freeing 'ctx' under the situation. Commit 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting"), which caused the problem is not in the mainline but mm-stable. Please meld this into the commit. Fixes: 40e983cca927 ("mm/damon: introduce DAMON-based LRU-lists Sorting") Signed-off-by: SeongJae Park --- mm/damon/lru_sort.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/lru_sort.c b/mm/damon/lru_sort.c index c276736a071c..9de6f00a71c5 100644 --- a/mm/damon/lru_sort.c +++ b/mm/damon/lru_sort.c @@ -524,8 +524,10 @@ static int __init damon_lru_sort_init(void) if (!ctx) return -ENOMEM; - if (damon_select_ops(ctx, DAMON_OPS_PADDR)) + if (damon_select_ops(ctx, DAMON_OPS_PADDR)) { + damon_destroy_ctx(ctx); return -EINVAL; + } ctx->callback.after_wmarks_check = damon_lru_sort_after_wmarks_check; ctx->callback.after_aggregation = damon_lru_sort_after_aggregation; -- 2.25.1