Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp326700pxu; Tue, 1 Dec 2020 12:13:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJz6TY3EeYOLsdjl5EM0e7twGJvv8LMb/5461zCO59/D1Dy/9zaMIzFmP17epQSDI1Idwafm X-Received: by 2002:a05:6402:c1c:: with SMTP id co28mr4783810edb.287.1606853634594; Tue, 01 Dec 2020 12:13:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606853634; cv=none; d=google.com; s=arc-20160816; b=VJ9M0cd13XoKkm+qLWsVWToKWFUQIiqdLFI0UtDh8RlMbYYxRfIBPr0ZV4H/dwBRdf n3AnDKiY+kLV2Jl0RHkHcdqXgnFwsAxd8guHD1MX1/qxsdM4kJTxW5Ch2fxjXSjahcuH H8+YoZAaWwszu1R//TUGKLjHNjkwVOx3EJ5/iCkib1XEKz5y8sTzz/jQKRYyYvqv/tEq 6WacSs4IrxqtD8/iHoFNoQWVgB2Qq3By/yCktHhO6itnG8R+rHCE5ScHJtuEW7Z7nvaK fi1w//exuWNiE2Osxg/zkG3Z4dc/Hxo0jurJH8QTQnmmOFGFBn3kipHjAEeTpD1C1aol BLww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=g4E1yEJwWdW/1daBdU0AvfQE/Mt8pGGdoQfvkY9adhg=; b=m/eXIpO2NuqFXkc74hg4eHiS35/k9qYELu/zrAzad9nXr3HHzv47tSARTLQreU7mtq 9ICMvDrJicrj0UZqU79NZhttovFQRFZd45vMY7UhpKVt2CFRA6v1JWuEIemWsnSlVViL gyRicpfO5HmxcFizZSirGwXj8j0PggGHySG6IY/Pf/h0mau8y4nGKDVd4BwL0IXtYLlD zWeor0UD5uLaG+etMRpgIUNmx5nrBDvxIRV3HMNPbjlhD1YplyXnF+Vu8Bws+Ap1FqwM 3BcLa1j0C0R1+KYQHEEUg0KGHCn0cf1YxUdttrLQ510S4lFNyBmBCar4LF0t06Frg/XN kk1g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si565666edy.403.2020.12.01.12.13.31; Tue, 01 Dec 2020 12:13:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392392AbgLAULd (ORCPT + 99 others); Tue, 1 Dec 2020 15:11:33 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9085 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727450AbgLAULb (ORCPT ); Tue, 1 Dec 2020 15:11:31 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CltWC4w76zLxvM; Wed, 2 Dec 2020 04:10:15 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.186.123) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Wed, 2 Dec 2020 04:10:38 +0800 From: Yanan Wang To: , , Marc Zyngier , Catalin Marinas , Will Deacon , James Morse , "Julien Thierry" , Suzuki K Poulose , Gavin Shan , Quentin Perret CC: , , , , , , , Yanan Wang Subject: [PATCH v2 1/3] KVM: arm64: Fix possible memory leak in kvm stage2 Date: Wed, 2 Dec 2020 04:10:32 +0800 Message-ID: <20201201201034.116760-2-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20201201201034.116760-1-wangyanan55@huawei.com> References: <20201201201034.116760-1-wangyanan55@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.186.123] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When installing a new leaf pte onto an invalid ptep, we need to get_page(ptep). When just updating a valid leaf ptep, we shouldn't get_page(ptep). Incorrect page_count of translation tables might lead to memory leak, when unmapping a stage 2 memory range. Signed-off-by: Yanan Wang --- arch/arm64/kvm/hyp/pgtable.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 0271b4a3b9fe..b232bdd142a6 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -470,6 +470,9 @@ static bool stage2_map_walker_try_leaf(u64 addr, u64 end, u32 level, if (!kvm_block_mapping_supported(addr, end, phys, level)) return false; + if (kvm_pte_valid(*ptep)) + put_page(virt_to_page(ptep)); + if (kvm_set_valid_leaf_pte(ptep, phys, data->attr, level)) goto out; -- 2.19.1