From patchwork Fri May 17 07:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuxuan Luo X-Patchwork-Id: 1936295 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 4VgfTl0BZhz1ydW for ; Fri, 17 May 2024 17:58:18 +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 1s7sTh-0005TW-Fa; Fri, 17 May 2024 07:58:09 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1s7sTd-0005SR-2l for kernel-team@lists.ubuntu.com; Fri, 17 May 2024 07:58:05 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (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-1.canonical.com (Postfix) with ESMTPS id CD6893F363 for ; Fri, 17 May 2024 07:58:03 +0000 (UTC) Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-a59eea00cafso577026866b.1 for ; Fri, 17 May 2024 00:58:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715932683; x=1716537483; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WJ33IyI1UoK9jqdPfng8Dr07tqIwKMMOuYIs3hbiq6c=; b=IUongPw/ScmCqGAgIRXKCeKeTDco5zi48szqtfgQYwn7R2aAyMtnDwvqV/HstaqIHc M51m3AUbRDkK5bGYwhODybjvBAx6bmNL8TxkllECglWz4VsB4fCGi29zCLXp46Jp4QCW 7d+c2f3wAjHyU9QQP0WUOpviqAZPLeS0xJ2TOv2wP0ffJbhPvAkXxltQQj/Pid1HdoRG 4h9uaQUs+y8+Jz2oAzO/iGCAGJW3uCrVKqsboDRMqLsy1Lot5/MHg6sZh9AvcdcRx0EP UQto+aWp4cnR0L1/JvB5J2rFXYe/wuk+W1gnAvkfOSqJvBJLaO8mQP0jpqA8ff7dENht 2vZg== X-Gm-Message-State: AOJu0YxPcj7V9grRjYV1rHJJDMkX5gJpXWh0V2oG4yce7w4e8mnL1H86 ZlaNjKycZx0FBfaf2BB1XNxWkrQG2KHsUW0jZ8emKZcF8T4MM9G5P7SGkiX6L0G4BCWE6/onIx2 /FctHxUbZosAiRtcRjjDJ0ZdL82e+MW5QKYEJkLpVamK5bH07mGgOa9I7xzn6wLaRPZZ2KSpaa6 0k8a2FD0qWoAhD X-Received: by 2002:a17:907:12cb:b0:a5a:893a:a73a with SMTP id a640c23a62f3a-a5a893aa833mr906870666b.10.1715932683088; Fri, 17 May 2024 00:58:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvMvOy7DnTqjh6NzFMZQYMT9WLi/ogj3xW7qV8b1Zbp7cHKRPT1nUOP/121X+3YI4qLlKXRA== X-Received: by 2002:a17:907:12cb:b0:a5a:893a:a73a with SMTP id a640c23a62f3a-a5a893aa833mr906868966b.10.1715932682688; Fri, 17 May 2024 00:58:02 -0700 (PDT) Received: from localhost.localdomain ([2001:67c:1562:8007::aac:4795]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a17b179f1sm1080016966b.212.2024.05.17.00.58.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 00:58:02 -0700 (PDT) From: Yuxuan Luo To: kernel-team@lists.ubuntu.com Subject: [PATCH 02/15] x86/cpufeatures: Add CPUID_LNX_5 to track recently added Linux-defined word Date: Fri, 17 May 2024 03:57:15 -0400 Message-Id: <20240517075728.9722-3-yuxuan.luo@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240517075728.9722-1-yuxuan.luo@canonical.com> References: <20240517075728.9722-1-yuxuan.luo@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: Sean Christopherson Add CPUID_LNX_5 to track cpufeatures' word 21, and add the appropriate compile-time assert in KVM to prevent direct lookups on the features in CPUID_LNX_5. KVM uses X86_FEATURE_* flags to manage guest CPUID, and so must translate features that are scattered by Linux from the Linux-defined bit to the hardware-defined bit, i.e. should never try to directly access scattered features in guest CPUID. Opportunistically add NR_CPUID_WORDS to enum cpuid_leafs, along with a compile-time assert in KVM's CPUID infrastructure to ensure that future additions update cpuid_leafs along with NCAPINTS. No functional change intended. Fixes: 7f274e609f3d ("x86/cpufeatures: Add new word for scattered features") Cc: Sandipan Das Signed-off-by: Sean Christopherson Acked-by: Dave Hansen Signed-off-by: Linus Torvalds (backported from commit 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc) [yuxuan.luo: crops the build checks from reverse_cpuid.h to cpuid.h since reverse_cpuid is yet to be introduced. ] CVE-2024-2201 Signed-off-by: Yuxuan Luo --- arch/x86/include/asm/cpufeature.h | 2 ++ arch/x86/kvm/cpuid.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index 41cb0cbbfdebf..6611478530810 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -32,6 +32,8 @@ enum cpuid_leafs CPUID_7_EDX, CPUID_8000_001F_EAX, CPUID_8000_0021_EAX, + CPUID_LNX_5, + NR_CPUID_WORDS, }; #ifdef CONFIG_X86_FEATURE_NAMES diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index defae8082789f..50d426d3af08f 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -60,6 +60,8 @@ static __always_inline struct cpuid_reg x86_feature_cpuid(unsigned x86_feature) { unsigned x86_leaf = x86_feature / 32; + BUILD_BUG_ON(NR_CPUID_WORDS != NCAPINTS); + BUILD_BUG_ON(x86_leaf == CPUID_LNX_5); BUILD_BUG_ON(x86_leaf >= ARRAY_SIZE(reverse_cpuid)); BUILD_BUG_ON(reverse_cpuid[x86_leaf].function == 0);