Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp149668imu; Wed, 2 Jan 2019 16:22:57 -0800 (PST) X-Google-Smtp-Source: ALg8bN5q/D3Rxff5VQ5qENaQCT3P23+PnbrM2krk6nLIcYG6EmQYvfOFZvI9d1Lj6nnHHcw7fa7i X-Received: by 2002:a63:5907:: with SMTP id n7mr15126202pgb.435.1546474977863; Wed, 02 Jan 2019 16:22:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546474977; cv=none; d=google.com; s=arc-20160816; b=aGfzahyn0Xn3xJ610xeYpr0dgFI1uUKbVtjLsCQxZ0+WtM4wyKb1UK9poIICEJ14z0 wURcefuOos8Jo5xzEP/EUYvV2B9kb8JkeOuneu3L9BAzOnkcBF8Joo9roLv689o6qcWj CRRSt72ooi8sJiR/IPOU5e1PqWwSOSoyIZ7N4+3LzT44VB65ausSAHUw9NCqQU/T8y7Y XhuT7Tw+fzsnK7efbNFk8wjxuTYmFpI0i1zwsU0fMRh6b5W6SjKDW/4reUotCr11ah13 dwntygAvpQSbvkW2UZtIu7nzCKJIJuwRJhKZIC0oEgKVbki8hrQz/o5dRj6G7TfY9MKc 1Q7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature; bh=K/hOWKtqQZ9Y+0xuXr52DlLfCsfN6a83f790ZTqPZLU=; b=jZ7bSacz0KbbE0KuQi6eZuRN3spUN9BlCuFIGGAjeBqDPqOXkoDReMBAzhwO3oPs// wxDvF+TjmYCQW8N22Ov0y8rrxu9gQ/cxGn2vZTih/SQenUV7aNWLa1WFusDTjrx9+EKA VBt39cqhygStkJR5AjaA1D9fMTDBqxekHxFRToNS1QkmRRfHU7vGu7uo+xxiaY1ti+d2 oy7SyZw+xCDqOwUPI2ZPQTV6UoewU8BEm3OuF+CCgfBV+7OuxiwOGA/ChWb/Ylq37TRO 16cAmq65wwBCjk/CAUzfmxl63rV4/t3SuCBlBAhY00Sz50UFeueFBVhJsYlXOnMj2erl +jgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=vBJxKYyh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si10114312pld.282.2019.01.02.16.22.16; Wed, 02 Jan 2019 16:22:57 -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=@google.com header.s=20161025 header.b=vBJxKYyh; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728170AbfABU4g (ORCPT + 99 others); Wed, 2 Jan 2019 15:56:36 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38364 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727888AbfABU4f (ORCPT ); Wed, 2 Jan 2019 15:56:35 -0500 Received: by mail-pf1-f194.google.com with SMTP id q1so15672574pfi.5 for ; Wed, 02 Jan 2019 12:56:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=K/hOWKtqQZ9Y+0xuXr52DlLfCsfN6a83f790ZTqPZLU=; b=vBJxKYyhWDF2HOaEqX8OEeNQ/KJe9qsGHVs/Ru7Iq9BIxFnX49zD1OmGeqOlLTAZ1S zEuFfCAZfwOfdl7MWYmSpRwjPjkt7RYajusfwAcZJfHNNP1wB/iwxI9XLis9b2FNCaHy SjWBI5y04QpBSbqNHRQ8vQCb6OSXsxXi6SJ5UC/3nDR8qhXlUHSdWd5MtvsxfNy+7eej tOGMdR3TWnUnwAsquLR0l286kuMF9LH82xUy14GJl3K1ncYhBcUk7ICmZFs3g3E8Tjnt 2ykKvVkbt19tBXdi39JPikNUWv/RKV3EEVn/5BoXwUfGVPrvlMWQf0sVrXeJlW0xqZcy kR/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=K/hOWKtqQZ9Y+0xuXr52DlLfCsfN6a83f790ZTqPZLU=; b=cTQW/Rj1b7x0btsqULLKJ+Vr4jzfYmx6jk7ywWV2RL7jVhAKg7Z8YO8XfhrH+q8+rR SOTPgTqkd2kuPZ3eRogn6tV1tPhSZ6nu/0uLqfxT3JO5MFHzNUVJ8DXktgs8spSNWWtn b/4qb+ZAQrZQCii0qcw0s8tRwxmYxXXw89/ugbj8Segdrewa/FMge95PHX9U5g4mHgJO XlPwl3lrtgmHGUCvVMMth9DgxTwzq8KITqF4o+NBzr6P3sIQJlR84RWVCRigVl8qoOM9 h9BDxRYT76ucWF4UEa18H/R/kprlKNMRv/uwqAzvFLH6486KVvdPP1zgHXwvvbf5IB+5 FkzQ== X-Gm-Message-State: AJcUukffs3WqaX1fYDonRwecukeV1te9XAesfjM2fSgcGP1vDLGjeZ0Z wP/vkJfMSi91tbG+md8+h4CZJA== X-Received: by 2002:a63:4d0e:: with SMTP id a14mr14859234pgb.408.1546462595051; Wed, 02 Jan 2019 12:56:35 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id q75sm78264856pfa.38.2019.01.02.12.56.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 02 Jan 2019 12:56:34 -0800 (PST) Date: Wed, 2 Jan 2019 12:56:33 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Brijesh Singh , Joerg Roedel , Paolo Bonzini , =?UTF-8?Q?Radim_Kr=C4=8Dm=C3=A1=C5=99?= cc: Thomas Lendacky , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [patch] kvm: sev: Fail KVM_SEV_INIT if already initialized Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -6278,6 +6278,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;