Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4245418pxj; Wed, 12 May 2021 00:57:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMgKRIxZLsnF1aa7wZPGN152yR76lMh2z3sPAvUH7tKFSjQUsDvyN2r36adsIu8+HKVUJn X-Received: by 2002:a6b:f10a:: with SMTP id e10mr25693713iog.188.1620806262839; Wed, 12 May 2021 00:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620806262; cv=none; d=google.com; s=arc-20160816; b=iJDfQVxe9dmQk0HshvTdzHmjw2ZschhL5jglUZJKHWER6wy0VpAt1rOxm7lhMhG4hn 55DGsa8F+IaxLAZlO0Ly+UiBQt6+stY/elMEEAkSRcjwzauvfrYBo8B1LiaMCOha7yJp 5/cAlHgb07D5s9ifPnwKJbEPUAJu4KkBn1yZNVFyl4YkYlSg2hzYvj6cErz0X0u7VHsI imHFsQfBof5/noAsHHmFPJbSxz4su/+SKM8I4eNnFOgTY9JvUA49/OCiLXUeyi3SCk16 tf+uq0ceCd2ZKLE387KAlYFOifT8Jecowk06e6QKFIOVCzJ5l1AEsE6ed1FiIcIRj+ml 9v2A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7zSfkepFBRp4VAYU45NXlAj6sAnHkc/MIivPKDk4y/w=; b=Oui+jE0rqryVQ5mdpfz1hY2oTdFN0XUHX1pH9mAaZj29swhdCEEqXKN4/DzPrWlK5g jA7ALewA0+nRxxcDH9OtvAPXRzdl0CFXWBQsBzJcZZHSnLDFkIi+dgUG5l1A7Z5i0dh9 X0rirAoSotlC11TrMd267F1OYbMGG/8hbVACbrb+Y7o9HI7AumOBMTEChKcL6EBIBcOM wNsZ65gHCiouVAO+URyCqiEnpm54bF1WDBCW+fCpofrW6mhGacQXbLtJVXSSx1ZUuCEO bFlxTkhOtCTDp3tstDVVB3cC2fiCrSHr63JJJsBHGjSi2NdR5+GZTWh7DWyMsW8Hxooh Zcow== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si22944659ilm.87.2021.05.12.00.57.30; Wed, 12 May 2021 00:57:42 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230411AbhELH4a (ORCPT + 99 others); Wed, 12 May 2021 03:56:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230272AbhELH4U (ORCPT ); Wed, 12 May 2021 03:56:20 -0400 Received: from theia.8bytes.org (8bytes.org [IPv6:2a01:238:4383:600:38bc:a715:4b6d:a889]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3EDC06175F; Wed, 12 May 2021 00:55:12 -0700 (PDT) Received: from cap.home.8bytes.org (p549ad305.dip0.t-ipconnect.de [84.154.211.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by theia.8bytes.org (Postfix) with ESMTPSA id 14ABF3E6; Wed, 12 May 2021 09:55:09 +0200 (CEST) From: Joerg Roedel To: x86@kernel.org, Hyunwook Baek Cc: Joerg Roedel , Joerg Roedel , stable@vger.kernel.org, hpa@zytor.com, Andy Lutomirski , Dave Hansen , Peter Zijlstra , Jiri Slaby , Dan Williams , Tom Lendacky , Juergen Gross , Kees Cook , David Rientjes , Cfir Cohen , Erdem Aktas , Masami Hiramatsu , Mike Stunes , Sean Christopherson , Martin Radev , Arvind Sankar , linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH 3/6] x86/sev-es: Use __put_user()/__get_user Date: Wed, 12 May 2021 09:54:42 +0200 Message-Id: <20210512075445.18935-4-joro@8bytes.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512075445.18935-1-joro@8bytes.org> References: <20210512075445.18935-1-joro@8bytes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel The put_user() and get_user() functions do checks on the address which is passed to them. They check whether the address is actually a user-space address and whether its fine to access it. They also call might_fault() to indicate that they could fault and possibly sleep. All of these checks are neither wanted nor required in the #VC exception handler, which can be invoked from almost any context and also for MMIO instructions from kernel space on kernel memory. All the #VC handler wants to know is whether a fault happened when the access was tried. This is provided by __put_user()/__get_user(), which just do the access no matter what. Fixes: f980f9c31a92 ("x86/sev-es: Compile early handler code into kernel image") Cc: stable@vger.kernel.org # v5.10+ Signed-off-by: Joerg Roedel --- arch/x86/kernel/sev.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c index 6530a844eb61..110b39345b40 100644 --- a/arch/x86/kernel/sev.c +++ b/arch/x86/kernel/sev.c @@ -342,22 +342,22 @@ static enum es_result vc_write_mem(struct es_em_ctxt *ctxt, switch (size) { case 1: memcpy(&d1, buf, 1); - if (put_user(d1, target)) + if (__put_user(d1, target)) goto fault; break; case 2: memcpy(&d2, buf, 2); - if (put_user(d2, target)) + if (__put_user(d2, target)) goto fault; break; case 4: memcpy(&d4, buf, 4); - if (put_user(d4, target)) + if (__put_user(d4, target)) goto fault; break; case 8: memcpy(&d8, buf, 8); - if (put_user(d8, target)) + if (__put_user(d8, target)) goto fault; break; default: @@ -396,22 +396,22 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt, switch (size) { case 1: - if (get_user(d1, s)) + if (__get_user(d1, s)) goto fault; memcpy(buf, &d1, 1); break; case 2: - if (get_user(d2, s)) + if (__get_user(d2, s)) goto fault; memcpy(buf, &d2, 2); break; case 4: - if (get_user(d4, s)) + if (__get_user(d4, s)) goto fault; memcpy(buf, &d4, 4); break; case 8: - if (get_user(d8, s)) + if (__get_user(d8, s)) goto fault; memcpy(buf, &d8, 8); break; -- 2.31.1