Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp670204pxb; Tue, 5 Apr 2022 18:06:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx3RhjXaE3Ok6s+7GrBfQevdbQf4fY6eQawgdSTzSnJT/Fm97Se2hU93DbadOgX4uoLJBcW X-Received: by 2002:a17:907:7ea6:b0:6db:ca53:9b0a with SMTP id qb38-20020a1709077ea600b006dbca539b0amr5938574ejc.763.1649207175934; Tue, 05 Apr 2022 18:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649207175; cv=none; d=google.com; s=arc-20160816; b=Lh/kKQaDqbmeIzTwHUbChmqwgTHicsKGp52qiUZGCgX7jGn74tbF5bEt1mdKZWfE2m E8UbLTLNinIpVpONzqpX7RSf7JglJu+cWWDWhj7HtRFUdjzfhQhsGTnBqfL4x/uL+RaA f4xVc1JZq12NvyDfkfTXra7U8Z6HV9QtfWLi5pdyXMRhuusTXulKc36InF5lDisjux41 D/mQFgyrk5okcNpTglxA0tX1c0INtNnQbkumjgpzLNJ8niYWZi2KjbYoOOAjrafuP2P8 mwBWKvptiYalqwHxPMgCOCM4ri5Q1wjDBE+qzzn7/+VgwTN3NoPb70uAWaw/anRs/5GX jjoA== 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=Cqzi/zTV82l9u8eCI9FIertKmtzipcnnbhNq12FU9xSiw6yQ+Aj3YIBv/I+2NGcSas xyLQFh0CcQNVLvkHKioWBEZmB6zuHMyQQhbD1F/PyJj54Vp4DnDmMK9YpQX3sdsdTRKS 4s8rQdl8cETSscx3fIWKGbQNa6F/vuTHVkzaMnJTxEazYtksayLNQGLVnET7bnyxWTCr xs1ZDucXP7mQi5ciAm0PXqTgGZe2qBhEYoMssdAZ/YamV9swls3HugNPYhpXfMd6VAfK QZwjyHHxlglpj9GVQG6cZNX7Er3f0sfZZPwh0i7L3NV8MlcMRsiYDspGCYaQF4k9fzFF CWiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=NCbEYHEV; 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 f10-20020a0564021e8a00b004192be40d9dsi11031781edf.63.2022.04.05.18.05.50; Tue, 05 Apr 2022 18:06:15 -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=NCbEYHEV; 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 S240396AbiDEJGG (ORCPT + 99 others); Tue, 5 Apr 2022 05:06:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238435AbiDEITG (ORCPT ); Tue, 5 Apr 2022 04:19:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 230B4B84F; Tue, 5 Apr 2022 01:08:53 -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 A0522608C0; Tue, 5 Apr 2022 08:08:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0AF5C385A0; Tue, 5 Apr 2022 08:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146132; bh=lLUB6/PLO7CaoHTOodfcqfI4F641Ksv26ccVQ4WLnvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NCbEYHEVd7RYLFpnJc9KyEBJC2VMl+DchmjYl+4aR3SPLMPf4hK8wqkUcoSTFudit z48TIa1wzl+07nHbFZOXMmXrxbThgV7MgVqI1Lzn6My98PjVlPtxwi5da7iHzC3RlG /mKXiGH9DJjeiuHyVbCIhLaUNvL0MdXcCCmO3gD4= 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.17 0654/1126] MIPS: pgalloc: fix memory leak caused by pgd_free() Date: Tue, 5 Apr 2022 09:23:21 +0200 Message-Id: <20220405070426.826625832@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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