From patchwork Mon Sep 25 18:39:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Cabaj X-Patchwork-Id: 1839301 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RvWrS40RXz1yp0 for ; Tue, 26 Sep 2023 04:39:51 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qkqUh-0005aU-11; Mon, 25 Sep 2023 18:39:43 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qkqUR-0005ZN-08 for kernel-team@lists.ubuntu.com; Mon, 25 Sep 2023 18:39:27 +0000 Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id BACF03F314 for ; Mon, 25 Sep 2023 18:39:26 +0000 (UTC) Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-59c09bcf078so129123227b3.1 for ; Mon, 25 Sep 2023 11:39:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695667166; x=1696271966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Q8X3RXai1m+hYcH1QlUqBcsMwAi9nMMteV0irlBB2U=; b=VsHI3ZuiQchq4E5Cy+3bZxPpXvCTDHeD8u0DJPSJCm9tNSRpeY1v8Ip2XMFhwwMZqZ 18Qqz1B+5eqg42QPojCEbGBLE/otCK1uCgFUzxYgA7sOy5dyGS4NAQsGmdXdswN0DdIX clcltwgyz+A0XRFfkIeI26GLNdcprMmu2RLIZhXK4oIsQ9BwD5lb4SJNAZTFBQnTQB+M q0ARAlbwlkQqUINbJZpteV5wC+alEn+qoKYd7nIb+aWlX+sLbIx/yCtdpEh9m5PQcXWy RKH/PyO27UklIVbXet+vFafzr6HG5sKUp7+75D8TNcSVe/R12JFTsXcZO0LuA9e2oroW hYZQ== X-Gm-Message-State: AOJu0YxuVrBt6ZmlBz2kz9XiDdS4raf9fAqM31Jf0YPwh/7xr2bohVFg 61TMXszLY01U9w0v2LBygb2G733XmfrqV4IUBWokTVhusE+3US45oTHYf54td8vHuDpjm1qVSvn cpeKI4/OBD5RP7YU99W1Bs0U1zXWO64Jhcscf9Vk68qg6wLVNGQ== X-Received: by 2002:a0d:e446:0:b0:59a:b70e:5c13 with SMTP id n67-20020a0de446000000b0059ab70e5c13mr7360211ywe.29.1695667165858; Mon, 25 Sep 2023 11:39:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5uyIrWj9xNlK2XfmdxdYTgNXhnsiR0OTGaQioyD64Bpscm3egBwjnvh0BIB77bEwNJXdEsg== X-Received: by 2002:a0d:e446:0:b0:59a:b70e:5c13 with SMTP id n67-20020a0de446000000b0059ab70e5c13mr7360199ywe.29.1695667165521; Mon, 25 Sep 2023 11:39:25 -0700 (PDT) Received: from smtp.gmail.com (h69-130-246-116.mdtnwi.broadband.dynamic.tds.net. [69.130.246.116]) by smtp.gmail.com with ESMTPSA id r74-20020a0de84d000000b0059bc980b1eesm2548135ywe.6.2023.09.25.11.39.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 11:39:25 -0700 (PDT) From: John Cabaj To: kernel-team@lists.ubuntu.com Subject: [SRU][mantic:linux-gcp, lunar:linux-gcp][PATCH 1/2] x86/sev-es: Allow copy_from_kernel_nofault in earlier boot Date: Mon, 25 Sep 2023 13:39:21 -0500 Message-Id: <20230925183922.71728-2-john.cabaj@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230925183922.71728-1-john.cabaj@canonical.com> References: <20230925183922.71728-1-john.cabaj@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Adam Dunlap BugLink: https://bugs.launchpad.net/bugs/2037316 Previously, if copy_from_kernel_nofault was called before boot_cpu_data.x86_virt_bits was set up, then it would trigger undefined behavior due to a shift by 64. This ended up causing boot failures in the latest version of ubuntu2204 in the gcp project when using SEV-SNP. Specifically, this function is called during an early #VC handler which is triggered by a cpuid to check if nx is implemented. Fixes: 1aa9aa8ee517 ("x86/sev-es: Setup GHCB-based boot #VC handler") Suggested-by: Dave Hansen Signed-off-by: Adam Dunlap Link: https://lore.kernel.org/lkml/20230912002703.3924521-2-acdunlap@google.com/ Signed-off-by: John Cabaj --- arch/x86/mm/maccess.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/maccess.c b/arch/x86/mm/maccess.c index 5a53c2cc169c..6993f026adec 100644 --- a/arch/x86/mm/maccess.c +++ b/arch/x86/mm/maccess.c @@ -9,12 +9,21 @@ bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size) unsigned long vaddr = (unsigned long)unsafe_src; /* - * Range covering the highest possible canonical userspace address - * as well as non-canonical address range. For the canonical range - * we also need to include the userspace guard page. + * Do not allow userspace addresses. This disallows + * normal userspace and the userspace guard page: */ - return vaddr >= TASK_SIZE_MAX + PAGE_SIZE && - __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits); + if (vaddr < TASK_SIZE_MAX + PAGE_SIZE) + return false; + + /* + * Allow everything during early boot before 'x86_virt_bits' + * is initialized. Needed for instruction decoding in early + * exception handlers. + */ + if (!boot_cpu_data.x86_virt_bits) + return true; + + return __is_canonical_address(vaddr, boot_cpu_data.x86_virt_bits); } #else bool copy_from_kernel_nofault_allowed(const void *unsafe_src, size_t size)