From patchwork Thu Sep 28 21:11:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 146312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3609692vqu; Thu, 28 Sep 2023 14:28:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBzXJJ3ajDDAE9kz5d8ecrnOUkrcwKTuOsaX33Oo6YCuGhFLjtJPSavu/drC7msd0wYdhw X-Received: by 2002:a05:6a20:f384:b0:14c:e089:94a8 with SMTP id qr4-20020a056a20f38400b0014ce08994a8mr1970700pzb.27.1695936482623; Thu, 28 Sep 2023 14:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695936482; cv=none; d=google.com; s=arc-20160816; b=0eXXdioc4IKNf7cFRH4idn65r/wWmi9PG/6laaNJ6WGVFw+geoum2OCiY55FCJTpzQ x0VsKN+oKugdgpZWtb3fIHlg06Lth3SkKZawPmIecyN7XpgVo0puXKsGdgrzuRD7DLSy luzf+bpXysFrLhPjuhL2ovWbs6yhUtjFAhsahZ0btedDTjg/vq7oKGe1qRTcjZeMiRVN NbCKIO7A/l4SevUTUh9RTgCD5l4bE6839sgAo4xqXoUNaY81gvdekwGlR7AKAjNvlgnM 8cFxLTfnHFWxldealZdbKke9cTa0nFGZbUmugJcW53QAu6J//0gwndCqo3raaBPiu185 eGJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=p7sigFB184YC/SX6XMhV2FIvnc162HpcpbCQDua+9fg=; fh=4/HIj9uqkicdLkhhbH2C5qbrTV6yX9z4Wmd8of2aPNc=; b=hC8+jBNqP2U86CkYSHixS9OjJy5YUMVxKnbVSFck7NhBmankkyPC3Ag3m4wc2zenEH 0EVLZIf+2rEnTAhITliZColFyAKydR1CBQyOR7IihpWbsMiBmcJvfkS+x0RX/ztXFtOk tZMQDg36ZVUBOoTEZWrUwV+THQnQjDDxBvFTrSo/QqGCdD2oxGYA9JLJmG6SvvoK6Mic DzVAIDCO2fKLu5xF/nH6UEbpwOJX57dST+SEdgeo7u+ucVj4VdtxqAk8Tj4gVBtU0x1E +ns/s4HxhQQrOS1Hyl6DH7iRRBzjZwlww3xlKJQbnplhmhHgemPndl0vqDwsHt/NYwUh CF4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WMQg8b6c; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id kk18-20020a17090b4a1200b002748c1bbd79si44836pjb.6.2023.09.28.14.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 14:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=WMQg8b6c; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D6A1280C2E87; Thu, 28 Sep 2023 14:12:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232246AbjI1VLx (ORCPT + 22 others); Thu, 28 Sep 2023 17:11:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232476AbjI1VLr (ORCPT ); Thu, 28 Sep 2023 17:11:47 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 847051A4; Thu, 28 Sep 2023 14:11:45 -0700 (PDT) Date: Thu, 28 Sep 2023 21:11:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695935504; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p7sigFB184YC/SX6XMhV2FIvnc162HpcpbCQDua+9fg=; b=WMQg8b6c5ytFhetly6y2zJQaK8TbQgHm8Z3IpIJ0kjaTwNdYBoYHOAqgVA9X5VZXcXkrY/ RpIGvPGTpFwdCwGfJs4grr1O8qXZRMbmcv7bzHkMCZqBzVBN6NLXf7zHcrhRMmlY1d5Hf3 dpzyt+ypyJnu4MBqupDCbYCpdYYz33X39UoJfRADOVso7fibsrYg3/ch3Cob7hS8OvHjHT 9PmlbvDUwdgPyvEm1X8aieiCoqYoY1v9PIQpC/OMkQXwYcxFCBxNjc0N18Wt4QlkfjbN7o 8N4W6G/lcXcIdRaooeQNf04m45WCCXxthPetqagr3ova+53DDoM1qJsx7QJ52g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695935504; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p7sigFB184YC/SX6XMhV2FIvnc162HpcpbCQDua+9fg=; b=TQ4WV/LfFYDQk+s7osTutVt3WhmoBZ587ugS5qniCb7jFYp2vgc86wKaY0yUyq8yMDvMiD ZkZrp7D9h9bM5/Dg== From: "tip-bot2 for Adam Dunlap" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/sev-es: Allow copy_from_kernel_nofault() in earlier boot Cc: Dave Hansen , Adam Dunlap , Ingo Molnar , Jacob Xu , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230912002703.3924521-2-acdunlap@google.com> References: <20230912002703.3924521-2-acdunlap@google.com> MIME-Version: 1.0 Message-ID: <169593550362.27769.15603585869717433478.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 14:12:11 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778318293103276957 X-GMAIL-MSGID: 1778318293103276957 The following commit has been merged into the x86/mm branch of tip: Commit-ID: f79936545fb122856bd78b189d3c7ee59928c751 Gitweb: https://git.kernel.org/tip/f79936545fb122856bd78b189d3c7ee59928c751 Author: Adam Dunlap AuthorDate: Mon, 11 Sep 2023 17:27:02 -07:00 Committer: Ingo Molnar CommitterDate: Thu, 28 Sep 2023 22:49:35 +02:00 x86/sev-es: Allow copy_from_kernel_nofault() in earlier boot 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 Signed-off-by: Ingo Molnar Tested-by: Jacob Xu Link: https://lore.kernel.org/r/20230912002703.3924521-2-acdunlap@google.com --- 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 5a53c2c..6993f02 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)