From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.139 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377201; b=b1G08Gcd3Zctn0Stjl405pF+VRwBz2GDZxWjQ6i06KXT40nttp1EIKU08xgeoqSnwPi1 fSn/TQbFQ4qM7ebuo+TtXxFZHrlb8youSdk4GmCUutOW64cYfgbfcrsftlpUxjHvI0PM5 WwhSuCYOKP3ez4y3B8A43MZ6QsokLJwlZUzlZo5QgtarWXU7sLSel6vZQYYn93g61Lg3h hTqsQ2gqwHzZOX0QPpcFmr1LyL5xo7/jzvIrpZZTRqaQD6LFDVecdYJCpsKsjCb2hD3Cc 35AWsqY2ytoDtrEANhdV+8hBzp5t0Iyk+a2fyagv8Lc9Ykj9sEZGJL8flfnmCQ4HaIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377201; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:X-Mailer; bh=3u0NyIO+zpo7v+Y/xW8uawqguJzPvVD70CM1ILIG3K4=; b=SZnNmoJxmtzuA/2IoXxV64DmL79Nv9+7SrAoTmDRTCMcP1BLfoy7YbEqvI7HkAMp0F+U uRnWPsrasylxrYMCdNEpKOMKX+lyBib50aK3DsIx3V5WDQlDWPNLqbALFhmsSlpH9gO0r Xyor9CPpr5OxB3om2wfX3KArkpob/elrI7obcl215GNBmJb2zC7hNr84j3J7br0rzWEyP HjLH/AwXkf6hq4HCWBfPMUaelJRyNH4D3JiQChtlcaAU2OWaURxKG8USd88ivA5M1W+mK xQ6jwLpdhtuxcuS3LS1fVbgKm6ddCNB1LZpCWTVDEw40Q/h0GV6EYA9uTCZlmwWFALg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=iBeFq7MZ; arc=none smtp.remote-ip=74.125.227.139 Received: from mail-pj2-f11.google.com (mail-pj2-f11.google.com [74.125.227.139]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3ECA6606A322 for ; Fri, 4 Dec 2026 09:40:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3ECA6606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=iBeFq7MZ Received: by mail-pj2-f11.google.com with SMTP id d9443c01a7336-2f138cc0a18so2450525ad.1 for ; Fri, 04 Dec 2026 01:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796377200; x=1796982000; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3u0NyIO+zpo7v+Y/xW8uawqguJzPvVD70CM1ILIG3K4=; b=iBeFq7MZqkrYVDaRPQQAL7InBFnhARrmaQPFoPaKgelOlhk+4XAxU1qV1Mu4JYIl4u /OL26v6MzT95Z3MSo9QtMeSe/p/5aN2FonAage/H4wbSi8B2waiVRECiMVfvfHHUKfeQ l3eqryvLr4rmt4xFJmPBL9VR8mETYdoAI0z1QhzawKbj+LfVhSXmuIkWSbRSGpJF0hh5 oiXokR0z92iQB5GAe1cVnMP1igZpMNhNo3Np5rPBLm34sxSgeoVz/ropmQI03Y80nLpe wPMKzBjNpTgsYisS09Y+BGIe7iEFF/xceztXkow8p14MjdyHJgBKOK0S6CxYYZBpWEMT ZsJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796377200; x=1796982000; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3u0NyIO+zpo7v+Y/xW8uawqguJzPvVD70CM1ILIG3K4=; b=xTXrg9SoeGDlNYKzExOZkNvaJ61IzAKcy+gjfkLVktkz2OQj+oyIa2i8UgrfRiXuyi vMnrcW7Nid0CUwGFKQG6LgvOdEGCb42I9PEpDOkfVkUEnsf0qAcHlfpAGLlAB1bL6+si M+AHhsMyY6YGTSeej2rUUix+ye/Svg8ZDJV+9Zx+3z+hsuscM0TngUmYTR/0Qp6o7V3Q OkC0THoi0peJ2ECYqqg1d5j9n2hJlGrr7wMALJaxq2JXRIBCs3GZ2ZUghvEENaHouCXW vhEKIGr/1mnOlzQOGLPE4frecd+QxPANOKyQS69GZCUSR405dzXoOLfA63ZukLQPrAB5 20dQ== X-Forwarded-Encrypted: i=1; AL+hErH9A3+Sw+fO5UBbuJ+ZZ6n+sD2e+4iq4dHhcBNh/yXM4eI7TtQLTaWp5l3Ufy6FNlGens2ldXQ=@vger.kernel.org X-Gm-Message-State: APuU4Z9X6mIYZixlrN8deAvCvVjowyNDp69vJmLg5sTBC970dqQRSHzr hMa3oKfKF6ZEzta0HejQ0Rivw43U8wfY6WCe7ti7OFuiJwbdic83zNOY X-Gm-Gg: AZFdTZeBLiOx6YyNja/Qp0GeMznoIS355ALFN02PbOcfYb+hqjlaFiyWdSVDiG4IDVY AiUXtQm9f9Lj/GYTdv/csR52soqILXbr2evpxGG1wHXuJY7sEosUEonzDsKKFjlAdd05PKSZNw6 WuHtZ1wYaq96r7RKWIyfjfAb8YhEuEdwKv4xABtRI+TMj96ERf54Te1ZTNGa28xcTYmCLInCHz7 o1zcCU0FV83KRBHjIGWCgUMiRxlCySE4uzIcnfIYYNbJ/IfGkYpqoNquV0pGHM0KnhJXrDN/M2v b5iTGemj0ZQhoRJFUXWGReQO8SAC0DBLCDqw3qI3E/Ov3CNq7yEJTewtMygw+pEfvOvEVTrYvK0 1T3dX5i8i2eLbq8sTgCfxj7WaGSbSo911hl7jiZ1wX6GjhibEva4LNO/5Ng5JBTunFeBvSMVUHB y+Y/ppI85vh2/u0c0ASmfkFmKnwWNpSyzrHI4YSNQ8ovMumWlHE5QXqH3kJEGrMeD6UWjFn02uI bjM0vY6KHJ//9IcIhl8sgx9W7d0Hbp+dM6r2qXujszp423fKOTqK3Mg1mkSjaTKLvT0QJ6LlS3A rs8UDGYeOHu4x2NdrP6y X-Received: by 2002:a17:902:da82:b0:2ed:3eeb:b0db with SMTP id d9443c01a7336-2f1ba12d1e3mr14777535ad.17.1796377199435; Fri, 04 Dec 2026 01:39:59 -0800 (PST) Received: from hhost ([2409:8a55:3162:1f0:711d:d4c6:bc15:a5a4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b798ec40sm8615475ad.72.2026.12.04.01.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 01:39:58 -0800 (PST) Date: Fri, 4 Dec 2026 17:39:21 +0800 From: Xingyuan Mo To: Borislav Petkov , Thomas Gleixner , Ingo Molnar , Dave Hansen , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , "H. Peter Anvin" Cc: "open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Xingyuan Mo , stable@vger.kernel.org Subject: [PATCH] x86/microcode/AMD: Validate the equivalence table size on Zen and newer Message-ID: <20261204093907.2319771-1-hdthky0@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email 2.43.0 Commit 94838d230a6c ("x86/microcode/AMD: Use the family,model,stepping encoded in the patch ID") made verify_equivalence_table() return early for Zen and newer CPUs because their containers no longer need the equivalence table. The early return happens before the table length in hdr[2] is checked against the container size, but the callers still use hdr[2] as a byte offset: parse_container() advances buf and shrinks size by hdr[2] + CONTAINER_HDR_SZ, and the late loader does the same with the offset returned by install_equiv_cpu_table(). A container whose hdr[2] is larger than the file therefore underflows the size_t and makes the loader parse memory past the end of the buffer. On a Zen system a crafted kernel/x86/microcode/AuthenticAMD.bin in the initrd panics the kernel in save_microcode_in_initrd() before init runs: Oops: BUG: unable to handle page fault for address: ffffed101fffbf8f #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 7ff03067 P4D 7ff03067 PUD 7ff02067 PMD 0 Oops: Oops: 0000 [#1] SMP KASAN NOPTI CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.4.0-rc4-00571-g9437ee8b6cf6 #1 PREEMPT(lazy) Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:__asan_load4+0x50/0xa0 Code: 00 00 00 00 80 ff ff 48 39 c7 72 43 48 8d 47 03 48 89 c2 83 e2 07 48 83 fa 02 76 1c 48 b9 00 00 00 00 00 fc ff df 48 c1 e8 03 <0f> b6 04 08 84 c0 75 3e 5d e9 62 7b b3 01 48 b9 00 00 00 00 00 fc RSP: 0018:ffff8880080dfb48 EFLAGS: 00000203 RAX: 1ffff1101fffbf8f RBX: ffff8880fffdfc7c RCX: dffffc0000000000 RDX: 0000000000000007 RSI: ffffffff80000034 RDI: ffff8880fffdfc7c RBP: ffff8880080dfb48 R08: ffffffff8129f15f R09: ffffed100101bf9d R10: ffff8880080dfcef R11: 0000000000000001 R12: ffffffff80000034 R13: ffff8880080dfbe0 R14: 0000000000000017 R15: ffff8880080dfbe0 FS: 0000000000000000(0000) GS:ffff8880e7930000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffed101fffbf8f CR3: 000000000448e000 CR4: 00000000000006f0 Call Trace: verify_patch+0x3f/0x1e0 parse_container+0x237/0x2f0 ? __pfx_parse_container+0x10/0x10 ? microcode_loader_disabled+0x77/0xe0 save_microcode_in_initrd+0x19d/0x2e0 ? __pfx_save_microcode_in_initrd+0x10/0x10 ? trace_irq_enable+0xe8/0x110 ? _raw_spin_unlock_irqrestore+0x35/0x60 ? rcu_read_lock_any_held+0x80/0xb0 ? __cpuhp_setup_state+0x167/0x1f0 ? __pfx_cache_ap_register+0x10/0x10 ? __pfx_save_microcode_in_initrd+0x10/0x10 do_one_initcall+0xca/0x420 ? __pfx_do_one_initcall+0x10/0x10 ? paint_ptr+0x3d/0x70 ? kmemleak_not_leak+0x2e/0x40 ? __register_sysctl_init+0x36/0x60 ? rcu_is_watching+0x25/0x60 kernel_init_freeable+0x1d8/0x420 ? __pfx_kernel_init+0x10/0x10 kernel_init+0x29/0x1f0 ret_from_fork+0x3ec/0x550 ? __pfx_ret_from_fork+0x10/0x10 ? __asan_storeN+0x16/0x20 ? __switch_to+0x2e4/0x6d0 ? __pfx_kernel_init+0x10/0x10 ret_from_fork_asm+0x1a/0x30 Modules linked in: CR2: ffffed101fffbf8f ---[ end trace 0000000000000000 ]--- RIP: 0010:__asan_load4+0x50/0xa0 Code: 00 00 00 00 80 ff ff 48 39 c7 72 43 48 8d 47 03 48 89 c2 83 e2 07 48 83 fa 02 76 1c 48 b9 00 00 00 00 00 fc ff df 48 c1 e8 03 <0f> b6 04 08 84 c0 75 3e 5d e9 62 7b b3 01 48 b9 00 00 00 00 00 fc RSP: 0018:ffff8880080dfb48 EFLAGS: 00000203 RAX: 1ffff1101fffbf8f RBX: ffff8880fffdfc7c RCX: dffffc0000000000 RDX: 0000000000000007 RSI: ffffffff80000034 RDI: ffff8880fffdfc7c RBP: ffff8880080dfb48 R08: ffffffff8129f15f R09: ffffed100101bf9d R10: ffff8880080dfcef R11: 0000000000000001 R12: ffffffff80000034 R13: ffff8880080dfbe0 R14: 0000000000000017 R15: ffff8880080dfbe0 FS: 0000000000000000(0000) GS:ffff8880e7930000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffffed101fffbf8f CR3: 000000000448e000 CR4: 00000000000006f0 note: swapper/0[1] exited with irqs disabled Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009 ---[ end Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000009 ]--- Move the size check in front of the family test so that the table length is validated for every family. The type field and the minimum table size remain pre-Zen checks only. Fixes: 94838d230a6c ("x86/microcode/AMD: Use the family,model,stepping encoded in the patch ID") Cc: stable@vger.kernel.org Signed-off-by: Xingyuan Mo --- arch/x86/kernel/cpu/microcode/amd.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index 6cdc410e75471..7b627848959dc 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -398,6 +398,14 @@ static bool verify_equivalence_table(const u8 *buf, size_t buf_size) if (!verify_container(buf, buf_size)) return false; + buf_size -= CONTAINER_HDR_SZ; + + equiv_tbl_len = hdr[2]; + if (buf_size < equiv_tbl_len) { + ucode_dbg("Truncated equivalence table.\n"); + return false; + } + /* Zen and newer do not need an equivalence table. */ if (x86_family(bsp_cpuid_1_eax) >= 0x17) return true; @@ -409,11 +417,7 @@ static bool verify_equivalence_table(const u8 *buf, size_t buf_size) return false; } - buf_size -= CONTAINER_HDR_SZ; - - equiv_tbl_len = hdr[2]; - if (equiv_tbl_len < sizeof(struct equiv_cpu_entry) || - buf_size < equiv_tbl_len) { + if (equiv_tbl_len < sizeof(struct equiv_cpu_entry)) { ucode_dbg("Truncated equivalence table.\n"); return false; } -- 2.43.0