Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp391638pxb; Fri, 3 Sep 2021 04:42:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzONC3HzqB4mLIHCdLJ9F714fKVWs7MQ5iNBMVnY3uUZDROKxriWQBtlH/2aYD9aDDzJDRA X-Received: by 2002:a5e:9249:: with SMTP id z9mr2731885iop.14.1630669352950; Fri, 03 Sep 2021 04:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630669352; cv=none; d=google.com; s=arc-20160816; b=w34vBU8B1vOmh/79f2FC9TvTGz9wSz6s0simuNd4uwnmfdoLA3GkynNe1kY4UijOKL lLOU2SEknZVXkp8yiWfwTFZrfp+vfBAFskVSZFxdbUdRg9Xl5zoNocEBnuQI3YRNBY5e 08mHT4csC0sCxZMXK3p8zwJuejZ03gfOcOgJdBHZZQtMccTLjTXZkTAO4OomwP7I8wKA F+JfWzsEuuzSacfQc2R88ACSQp7J6A/QucpZ3TvyuC7L9EAyHQpLNg0OE34leglNY8EW DRCKxKSF192fEtjwszVtKUHDjUYczDm7HWi0wLk/Q+EbzbhRJDb6+YWOHbNB/9ErfnW3 sI4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=zJQVNDV8yA1O8e86lmRlZ0x2ZEH2pQg3CaSynFUhqoU=; b=CZn5h6rzNC8z+5pusawv6mz2gpjsYnHTJR22c1393d7X4i5pHEi+ygxaAbFZufNh8D 6oRSXC53uDwaE/0+dYS87ys6Kz53ZXLKDq6l9ktmgUsxr5gJf4zsN9UEeg/fJZsK6/H9 UacKCrLKXgC476AC7GlJIW2DoKY5a51Xhj+wTGWlzFwyQw71PAiwxN59cD949J43om7Y vL26O/CatEGJfOwKlEUo4EyVT1kH8EbpGTc//CyEc2OoacHxwusmQnZZTXSWh+a2/4zO HM7IfiucFVMrWCKerssCoskjxtZhc9csKB/4OM+5PBUU9O6SgQuDLoZESY7O85CXhAZS 80jw== 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 q22si4397292jae.93.2021.09.03.04.42.21; Fri, 03 Sep 2021 04:42:32 -0700 (PDT) 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 S1348854AbhICJlX (ORCPT + 99 others); Fri, 3 Sep 2021 05:41:23 -0400 Received: from smtp23.cstnet.cn ([159.226.251.23]:33598 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244602AbhICJlW (ORCPT ); Fri, 3 Sep 2021 05:41:22 -0400 Received: from localhost.localdomain (unknown [124.16.138.128]) by APP-03 (Coremail) with SMTP id rQCowABnbxNk7TFhRzwVAA--.65058S2; Fri, 03 Sep 2021 17:39:48 +0800 (CST) From: Jiang Jiasheng To: pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, joro@8bytes.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jiang Jiasheng Subject: [PATCH 5/5] KVM: SVM: Potentially kvfree the ptr points to error page Date: Fri, 3 Sep 2021 09:39:46 +0000 Message-Id: <1630661986-816436-1-git-send-email-jiasheng@iscas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: rQCowABnbxNk7TFhRzwVAA--.65058S2 X-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Originating-IP: [124.16.138.128] X-CM-SenderInfo: pmld2xxhqjqxpvfd2hldfou0/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Directly use the sev_unpin_memory() may cause kvfree() free the error page, for region->pages may point to the error page. Signed-off-by: Jiang Jiasheng --- arch/x86/kvm/svm/sev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 8d36f0c..ee7d691 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -1664,6 +1664,8 @@ find_enc_region(struct kvm *kvm, struct kvm_enc_region *range) static void __unregister_enc_region_locked(struct kvm *kvm, struct enc_region *region) { + if (IS_ERR(region->pages)) + return; sev_unpin_memory(kvm, region->pages, region->npages); list_del(®ion->list); kfree(region); -- 2.7.4