Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp924957imj; Sat, 9 Feb 2019 10:56:14 -0800 (PST) X-Google-Smtp-Source: AHgI3IYu9kSRAaNeDRW6udwCgjuKWXLJID05HHKxzXb/tOjSVUc7SMRCgVEbPyHxWYgH8miJtmS4 X-Received: by 2002:a63:1204:: with SMTP id h4mr26539141pgl.51.1549738574749; Sat, 09 Feb 2019 10:56:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549738574; cv=none; d=google.com; s=arc-20160816; b=dBkSElOTzXbE/IATWR0DA/wv+19nITsQEryYFjN7WFZJQqN+A3lcplr1vfaKB6axkL 6zLK3B/k2E6sN6lkerCafzO1bMDhaBZHll+v5D5UF/DdhuqhYhm6D1PxQwzSqLeHm1wF c8Bt6eg7robfkGbT9i83lF8Y/7gdi4kr014Kh8LGRic3cAeWvepoLfWQg1M0YzsBi2f5 pRd/4INwWImtGmuGbaywdsUTD5X5UsA7IhAbVgoYzWjXvHW0iJmpmh4OjtcN0audCAYJ X0nM09uJ+9+iWR8twVZH8cl/DLUSdMopSn48VhAi6Df4KWBcZfe4DEGHwX540ictBDZI 8afg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1EfSKT/H20hujFP0BDAlTMHo0a/xjiapND5YnMz5Ijg=; b=yf1v0UOIhSTp6E8VT2K0aanwoXxFhlltZMTVqLQQL1OwkSHf2/Pc6MVobUa2PyXGYi q0YivMxE76+xpdqmCzppPtHmr3Dj1c43icQ8zUkVYmSeJEUuQBVsD0tCDOd2VWHa8kV8 IR92mmxSFnd/vnRDeKu8HvKgsbII3UxfJKjrp5FEw6s1ZWAOJvPdXmSmHR8jcCJs6S5A 8rI41mppffeT4DABzR7j4c0Sft6QG3n72F+P2glMKM19FlZ0aU6ty5XaNGB6W8rz2dVr bgCGz6LuY7q9y8p6lAsrl8KfVDcrC9VCr3hYaitDcZF5QZrG729Q7UnFB7VMRpGDb26z iTKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xEGfRNkE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ce14si6208661plb.423.2019.02.09.10.55.59; Sat, 09 Feb 2019 10:56:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xEGfRNkE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727842AbfBISsq (ORCPT + 99 others); Sat, 9 Feb 2019 13:48:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:33554 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727762AbfBISsg (ORCPT ); Sat, 9 Feb 2019 13:48:36 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2450320821; Sat, 9 Feb 2019 18:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549738115; bh=7dNY/jnpiJaLzuRHr89GzTmL+sHB9nQOHbeN85JT2n4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xEGfRNkEg/7+sKhXeHPzm32F1S9e3A6txSqF9l4W03KC0HgLOj8D/zg3B4QiLq/cS 6mjl3rFtX5VqooongLmGXNUWK/INHMeoByLqdvfnj5Lwe195xAi1LVO9fey9Ff0ZZS S84oT8Cd0cfYxaLjv1gB0RyGAEob2uA/UjJRmil8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Rientjes , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Sasha Levin , kvm@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 42/42] kvm: sev: Fail KVM_SEV_INIT if already initialized Date: Sat, 9 Feb 2019 13:47:34 -0500 Message-Id: <20190209184734.125935-42-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190209184734.125935-1-sashal@kernel.org> References: <20190209184734.125935-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Rientjes [ Upstream commit 3f14a89d1132dcae3c8ce6721c6ef51f6e6d9b5f ] By code inspection, it was found that multiple calls to KVM_SEV_INIT could deplete asid bits and overwrite kvm_sev_info's regions_list. Multiple calls to KVM_SVM_INIT is not likely to occur with QEMU, but this should likely be fixed anyway. This code is serialized by kvm->lock. Fixes: 1654efcbc431 ("KVM: SVM: Add KVM_SEV_INIT command") Reported-by: Cfir Cohen Signed-off-by: David Rientjes Signed-off-by: Radim Krčmář Signed-off-by: Sasha Levin --- arch/x86/kvm/svm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 101f53ccf571..3db60e0a59fd 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6248,6 +6248,9 @@ static int sev_guest_init(struct kvm *kvm, struct kvm_sev_cmd *argp) int asid, ret; ret = -EBUSY; + if (unlikely(sev->active)) + return ret; + asid = sev_asid_new(); if (asid < 0) return ret; -- 2.19.1