Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3087668rwb; Mon, 15 Aug 2022 17:49:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR6BbG4HhVF8p4P7ekqR1WSHxETYXBy3VQgIp688AFXRCqTRzTQHIxTPhu8vRMIuoiTuUN/X X-Received: by 2002:a05:6402:184:b0:442:fd54:2a21 with SMTP id r4-20020a056402018400b00442fd542a21mr16313946edv.129.1660610982517; Mon, 15 Aug 2022 17:49:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610982; cv=none; d=google.com; s=arc-20160816; b=RWZPGFjvkLa+hl62FhpEJHLX+XP/Z/EPiFD+MWLMaesJCVMFZHedlVj8ftwE8QcWXl wh04Rmd7LzdMfhddtPUA6+H7oi32+6rYiwzT3ePp4E+OyQ+Ncu/43pjQWnpZ3CaKZXVO V1RMIsOxAMqEZ9j8+xoltLjBaoiYpwlzTc7H/OaCVlPavyISUJXGb5kitCXrFM36I3jJ Fhe0KfzQS4MELoGfMzPngWwLxfsI+3kbZ0uUqN8H138Pn59e6vyk3duQGjHPpL10JCaZ d5MOh3DanH0NDPaixvmzlVTjNTaxW5bub8KvXrbBHWJNaiLInwsisKMRQeAjZrpE4Tz0 bqKQ== 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=58CquPRxlSk4I3GR8w9GFn+onZu6imR3IL294otLT0Y=; b=ITTAOFdGWPr9irjNK7eMeqGx5FT8fO46dI6MgAdez9pO1T0kcTrLDAybfpkSWCoA00 sByvgnGaCWyUAvv0p/GpHfJkyTrdy6IE6TTfwx+0L3004+TIZoTbOyIhZhpnlNzHBQln R8xj4qhKIn1VFRQaYfTErKO4QmVogw9SaLh3e4xKKpIARpQC1i6DMG8hu+WL872+73oA esmc8L2l9ydCCnN2er21VPDlTI1dT8o4jBQBQODJOfPl7UNzJdO6zhm0yFysjcZBzr1o w5XNX23tAzmWdCnlLwFnNGrY/5qrym9wOIFF4Kn7M7tr/7jeErYA0DnytnburR9btPcA gJYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EJj2YeTi; 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 e20-20020a50d4d4000000b0044052e86694si9046022edj.377.2022.08.15.17.49.17; Mon, 15 Aug 2022 17:49:42 -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=EJj2YeTi; 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 S230273AbiHOXd7 (ORCPT + 99 others); Mon, 15 Aug 2022 19:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346406AbiHOX1S (ORCPT ); Mon, 15 Aug 2022 19:27:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF843BA17C; Mon, 15 Aug 2022 13:07:08 -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 EAED16068D; Mon, 15 Aug 2022 20:07:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3D33C433C1; Mon, 15 Aug 2022 20:07:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594027; bh=RDj5KPfi2DGB835dglTgPaPt8BgMLgpCXvMGM1nKy5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EJj2YeTiohuzD8LhKevfl7RSSX63LGzqIW0kX/CuUxJJP6CkY/1f/Q4pauFl9/0qz INYouWvdPhKkB7rM0f5DKBFT3h84IvvGgWPIN9PjIegrApHGTSEZz3wcv0ExG1UiUN o8yDVNYWV+NZEAikYNVKigPNpIn1nafocKdr0gTw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianglei Nie , SeongJae Park , Andrew Morton , Sasha Levin Subject: [PATCH 5.18 1044/1095] mm/damon/reclaim: fix potential memory leak in damon_reclaim_init() Date: Mon, 15 Aug 2022 20:07:23 +0200 Message-Id: <20220815180512.274821489@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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,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 From: Jianglei Nie [ Upstream commit 188043c7f4f2bd662f2a55957d684fffa543e600 ] damon_reclaim_init() allocates a memory chunk for ctx with damon_new_ctx(). When damon_select_ops() fails, ctx is not released, which will lead to a memory leak. We should release the ctx with damon_destroy_ctx() when damon_select_ops() fails to fix the memory leak. Link: https://lkml.kernel.org/r/20220714063746.2343549-1-niejianglei2021@163.com Fixes: 4d69c3457821 ("mm/damon/reclaim: use damon_select_ops() instead of damon_{v,p}a_set_operations()") Signed-off-by: Jianglei Nie Reviewed-by: SeongJae Park Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/damon/reclaim.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index e34c4d0c4d93..11982685508e 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -384,8 +384,10 @@ static int __init damon_reclaim_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_aggregation = damon_reclaim_after_aggregation; -- 2.35.1