Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp926794pxb; Wed, 6 Apr 2022 04:30:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPX2/NiXt7vYldVd1JiusPZ95Fv+Rs/B3bAB3wO9F3yUjrxLaJOSrTq1bDiR8TWLDN/BOh X-Received: by 2002:a17:90a:aa98:b0:1b8:5adb:e35f with SMTP id l24-20020a17090aaa9800b001b85adbe35fmr9436647pjq.192.1649244652065; Wed, 06 Apr 2022 04:30:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649244652; cv=none; d=google.com; s=arc-20160816; b=ZWfEUpiYOBIoEFIyFdUusFIx8lBbEp8ItD4anR/1PC0x7nN1cZWNmwhS+rp7RyOZAi +Negv+yd0gtUGrJ5m9D00kf7pQdQ/sT12wswCb75NuUccYb5T9Ayc2m6/v/yNKp87YoJ 0lE385LvTtr8SKIvERFkq6szUKkRuedG1iPEPJbXJAO1hXMDSKPQVW05YyqWRPU/tVQG SmM7yk2tsCxltzTLE+Co6L4/6FmWp3lMBZE8oYSXZund+5Fr+LsY0VO/CUOFDOCP+ZB/ vPy7fD0J0brXr1XveEN0NJH4/1j4kv8jDGFKMwauOCv9JxhA5npde3hXRiGHP8vQ951K K9RQ== 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=HSmiW4ud7ARFUc8YiqnwL5DE1+pVOSbJF0626/kpnDqd3I78i8iuDtJkkvVg0llWwp iFaIQD49UPagUaK1pcaYeJGj3l8Ppajr16X2idJGikvq9mTG1jlUZqhnrSh39FuBtArO 4K8wPwMFAnBKRLeCyEShuwpD08onZ2BmWEuj6j/l0Bck7973IU+g9OTeaR9uLQTxkNdv EKY3br8FGSiW3k7cuWZZBcf5fSd7gm7mu7oZo5B8BgX0USksI5czQUhtea7lK+CIWvye 5ohiTPusDN9OZ7+t/oNHNw6weWHbW4VYywmre68KFJoh7OYGruujtwrMS08H4svbnpSx 618w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JYKQn4xx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id j20-20020aa78dd4000000b004fa3a8dffe6si14507346pfr.157.2022.04.06.04.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 04:30:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JYKQn4xx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 588C2605B04; Wed, 6 Apr 2022 02:52:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1389823AbiDEWCa (ORCPT + 99 others); Tue, 5 Apr 2022 18:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349411AbiDEJts (ORCPT ); Tue, 5 Apr 2022 05:49:48 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94FB0186D7; Tue, 5 Apr 2022 02:45:01 -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 31D29615E5; Tue, 5 Apr 2022 09:45:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D745C385A1; Tue, 5 Apr 2022 09:45:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151900; bh=lLUB6/PLO7CaoHTOodfcqfI4F641Ksv26ccVQ4WLnvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYKQn4xx321XcxPobA/oYu/gyaM0gzfa9V0RN78QslUcICh7HOTdzVBOZQuDXkXd5 8StZochu6tvWq8IchEXd86cig2+4xhL8zhHp70Ywt/71b3fMxf3VTsSUBTXqpF375k r1lo24NQ6nhnbaA2AM2YIAntuIZo7NXdvBYZhgPI= 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.15 534/913] MIPS: pgalloc: fix memory leak caused by pgd_free() Date: Tue, 5 Apr 2022 09:26:36 +0200 Message-Id: <20220405070355.856117025@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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