From patchwork Thu Jul 14 17:04:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 12918286 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 8BE2FC433EF for ; Thu, 14 Jul 2022 17:05:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E1B89401B2; Thu, 14 Jul 2022 13:05:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 092E69401A5; Thu, 14 Jul 2022 13:05:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC3EC9401B2; Thu, 14 Jul 2022 13:05:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DE4069401A5 for ; Thu, 14 Jul 2022 13:05:09 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AF2C534BE9 for ; Thu, 14 Jul 2022 17:05:09 +0000 (UTC) X-FDA: 79686330738.06.3A5333E Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf29.hostedemail.com (Postfix) with ESMTP id 1ABD612008A for ; Thu, 14 Jul 2022 17:05:08 +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 dfw.source.kernel.org (Postfix) with ESMTPS id 0546F61E4F; Thu, 14 Jul 2022 17:05:08 +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 ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="PUls/OjF"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 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=1657818309; 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:references:dkim-signature; bh=opbyVZRHixyIq2FqQgugLDc4qvcV2UJiUjucmzPNTxQ=; b=K9OQpHaANgFnTOxF36uFBEACZc4ukPqkd2Auwyq1yODFXiUvISXiHm+x4uWqoyBeMMAgi/ pbGtuA0IttJHebvX9xfceG1ioFMwrS318N28VT2l/OKbify6q02gMOTre1Nk3ypaDWFm42 XKmEa6OKKoSKggIH56Rv/MJIEY3Zxhg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657818309; a=rsa-sha256; cv=none; b=paMZJqYeVF8Pcjl337BMFz2IelBr1PCRoGcqRGumE1wCxcRmYtxDXQf1DDjZSSAa6mYevu OIdaPu2OFkAxh0P5bt+OUWvPwHpsA9yIZ/36BdsSgFfT/e1cdJmM2fDGYZCRQsIwtURtDS 3W54aszu60U/ylCZLNM6wp0Fkb2lXF0= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="PUls/OjF"; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf29.hostedemail.com: domain of sj@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=sj@kernel.org X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1ABD612008A X-Rspam-User: X-Stat-Signature: 43w45dyimz1fmabb8oh991qx93t76xrp X-HE-Tag: 1657818308-646408 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: '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;