Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp701136pxb; Tue, 5 Apr 2022 19:23:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHE8bsNaKJrev8JcANHOVNCr0ZddPzZd6UinPJx54T6f6xDL8Tk++j0phJI4rOJYsJ2mvi X-Received: by 2002:a17:902:e844:b0:156:bf35:643c with SMTP id t4-20020a170902e84400b00156bf35643cmr6235817plg.137.1649211797224; Tue, 05 Apr 2022 19:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649211797; cv=none; d=google.com; s=arc-20160816; b=qm7WTrkQmWBwCLgDsxPgiyasHXB8grznabtn3SRI+wxMybOHxMDuddWtZUv5NgUKWZ fjUelewrawl36B7AQfY+tMzeAcYatVxiHgjKcInxLwLx5A4om4g3fJLe1VERs2Ye4O7J iTdvVhK6HfMLzdRQSCbHx88Ms+/rwNm7jOVR0guTMpny3NSHjw8ye1kWQ8n2jM4c4VK9 48iJbt8IC2/jJuL0kixx4XbETiW66tx80vYJUld3w/gFvdV8chTNKKWWU2Z1HLr24lE4 tWZoT3PEsn2V/xa0TXje0Gufeut+EvVuipwSvWdMpvu5YE8S5uh9sC4fsYbQq0rChYyn wSRQ== 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=RhMDUKYIJCOEqggZ0qBo9JzNkDb6nE+gxk5bWQFg+jg=; b=Cz2qfJe9pTBlKT5mw8WaF1R/uVrpCevKbJ19MVd3ECwuJvK5h5ZI+wOmX6DSfHeCIn EC40fTj4evLp8Px2RssOVaP7Rohsd2UvfbATMxvXw4Ojx7o/N17MY3pA3+mBtXu2N4Xl 8mz2249vxNlHomEta31M7GqThe9/68rm5MjDKS6dD+j1enlSzsG1IYD8aFulZjV8Iy6Y L00YGkCZpc6jL2KbJXJE6fhrpGa1i84xloB13Mc1+RYz56ej6/hUuTxV3ce+pHmlQr3c Qcdvh+ttAj7iTe8xEummJ/veqqqvUqNuNrYeB7oSTu1VdmRktROy8So1Ev/MQWHY0qvD lcxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zlreul0u; 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 z9-20020a634c09000000b003816043f080si15188780pga.629.2022.04.05.19.23.02; Tue, 05 Apr 2022 19:23:17 -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=Zlreul0u; 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 S1378325AbiDEMwn (ORCPT + 99 others); Tue, 5 Apr 2022 08:52:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245225AbiDEJLp (ORCPT ); Tue, 5 Apr 2022 05:11:45 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 034882BB1B; Tue, 5 Apr 2022 02:00:00 -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 F3D9A61562; Tue, 5 Apr 2022 08:59:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 07DBDC385A1; Tue, 5 Apr 2022 08:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149199; bh=lLUB6/PLO7CaoHTOodfcqfI4F641Ksv26ccVQ4WLnvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zlreul0uvMew0Yh2wCdvc8h0teaP2tRm8ReW77bxrbTiefPjMGjoYqSVXRQNsPjLj b1S8SvpChZWut/NzgTLx45xKVs4AzBBdrYMFFoJh1rK6Mc0e6EfTEKkbsztSCWRKnd ipIeFDcU86s2RWXlfcy4kBD/2pJwUtK6KLSiwJ+A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yaliang Wang , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 5.16 0593/1017] MIPS: pgalloc: fix memory leak caused by pgd_free() Date: Tue, 5 Apr 2022 09:25:06 +0200 Message-Id: <20220405070411.880591899@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 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: Yaliang Wang [ Upstream commit 2bc5bab9a763d520937e4f3fe8df51c6a1eceb97 ] pgd page is freed by generic implementation pgd_free() since commit f9cb654cb550 ("asm-generic: pgalloc: provide generic pgd_free()"), however, there are scenarios that the system uses more than one page as the pgd table, in such cases the generic implementation pgd_free() won't be applicable anymore. For example, when PAGE_SIZE_4KB is enabled and MIPS_VA_BITS_48 is not enabled in a 64bit system, the macro "PGD_ORDER" will be set as "1", which will cause allocating two pages as the pgd table. Well, at the same time, the generic implementation pgd_free() just free one pgd page, which will result in the memory leak. The memory leak can be easily detected by executing shell command: "while true; do ls > /dev/null; grep MemFree /proc/meminfo; done" Fixes: f9cb654cb550 ("asm-generic: pgalloc: provide generic pgd_free()") Signed-off-by: Yaliang Wang Signed-off-by: Thomas Bogendoerfer Signed-off-by: Sasha Levin --- arch/mips/include/asm/pgalloc.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h index c7925d0e9874..867e9c3db76e 100644 --- a/arch/mips/include/asm/pgalloc.h +++ b/arch/mips/include/asm/pgalloc.h @@ -15,6 +15,7 @@ #define __HAVE_ARCH_PMD_ALLOC_ONE #define __HAVE_ARCH_PUD_ALLOC_ONE +#define __HAVE_ARCH_PGD_FREE #include static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd, @@ -48,6 +49,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd) extern void pgd_init(unsigned long page); extern pgd_t *pgd_alloc(struct mm_struct *mm); +static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd) +{ + free_pages((unsigned long)pgd, PGD_ORDER); +} + #define __pte_free_tlb(tlb,pte,address) \ do { \ pgtable_pte_page_dtor(pte); \ -- 2.34.1