From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.134 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377200; b=jPSgn5UNaVfIqXjXuMZQ2YC711y2F2KEHM8rUyR3W3VrK9GtPhxUjDDvBzTnCbZHCzPS ByXHWPqtPHhktqkhGrsnLVc2itddHTvCgZsl1Fndb3w4i61rXCUK97qRmPpbT4laFKTtS LllzUe0s8mlhmgNN11oHISN1s8A/MwCNxbRUNEioqtTS75Dri+fsZIuHkW4TDs8avkjOD 0mw0EVE3vlp5YZA7Z5Mt/pFBdWOdakHktDgKt8+lvcR6HbTkTO7452l6gkJHfZAoJsZgw 01+qTHrXVULHUS9ken7Vn20ukhZjPQ5nxF5remH8v7i6GmAsf9eUP5uyDTkNl6kDHrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377200; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: 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=0ihzgZbadqPzcQQVlZb+lLM7YUxxQqgvkNfHAspjMDytvbo/kqxk5Qztss8X9D7P2mjF Te6nEvXcitIKfRimjSJoFi5NAmv30skRMcRLHDWzlamAMxR2MK3cBftCrFFlJtr2A9Qu6 5AotnXldemKapk3LPiW5nexXLX33DzwPc9BoQqwbZw4cIRdQW3PoZPYzN1SCcn2AegwFg WS3Q/FaALMql2BJEpf4qUYZDzajoUljvqsEmb3wTkDmT/icK69DngBMn6ujDcRHKQSxVq nwee+DLAzBTtuFLDvvR6YZuXlbm/Yf7OhA8uGQqH0VgbXqWNNGn3XxqMZJxK5umf/mQ== 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.134 Received: from mail-pj2-f6.google.com (mail-pj2-f6.google.com [74.125.227.134]) (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 44FB0606A32C for ; Fri, 4 Dec 2026 09:40:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 44FB0606A32C 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-f6.google.com with SMTP id d9443c01a7336-2f0a42f6d3aso2254245ad.0 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=0sBcDJm7waPauR5+o5GMDYKmXdSZ3IrLADhlt8vJ2WOOvfpkhtWmy73Ov6co/Shke5 9Pn2dMZ3jsMoxOurDPVp7+TAodSK+ME9JrglwTvx7re1BBf7MoqfZq9Re3owMxX+v3Q9 /26uC75gh/mgLxxeCkrpM9rLy0PwC/5C05JzqPD67ZaWzOoFVVKug7Dv/q3a+2xSuMk4 5tGp0XaNFUztPayvpfidd0oksIUVS2Vrg9WBjiM/brFCujx8zcfMpYBJ8+ZPU+uCICiF GueTmDpR7dYShc7Iaw68crHM88aJc+B3oWlgpxbeZfRPpF+4yQTANx47A/UOE1G/uBN3 kY8g== X-Gm-Message-State: APuU4Z/TU6/oP5H2k6DGBLlTBFaP6qa13xA/elvXqMXpARvFglcUEC8H ANF+owY0pyMKFuCKrjnuiGPXxT5tN2wfEfr862n/ZjMxZYiBL9AnqWHt X-Gm-Gg: AZFdTZd1wki9R5xxEt/4R/3SUc7KzX6BnOs+n03megUYOFOV9WEPlS8qfEGY5kGmyqF Qi44A9zvoxzm5DNgv7o9kztM2AskeovpvG19dRIbiHYUoKqdA597D0ne0yWKZ5kkXgGXwqlqE55 M6goFM/9CtB2ZY/ndU/c9dt/D0s6Y3qufwTF8wDek7vjfaP4KNUDKgZ9nsxDlpjZLRoWBffhvoD +AmSWFYjB03DDYQ8aom7SHs0aaCj9hrGylHx9iKjPOqBxXxLnwNSaPWvP7RmMW8dq8L6UOuLu57 Ok5RHz+eEx+8dyejheQs4rEIop1+efg78oZoZUHTxNiZ8vGO6XV7sj+C9Z6SCCnbZoMf0vBREMD GRvlkpwqFON/rtdtCExwdlnu7IDm+WYADqsnRTpEe3wvFqHzy4tp1Padnw8JPcvxmUrqes2602I us/YEAJ8zmf9DnfiCAw4Re9umLMNj2V4UqLrj+oiQdAUvhljTp+RSKBzjtIfmlJhIg8WZT6IjC0 8g/4gGAuYjfUjawL+RM2jsbU3sJyPxp+O3vIqpSDTnss61Gdn7ruihF4kZ/IpVUIEJ7FWOB/yAG 5ZtGytPyqUAq+eQ8o+Ob 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: linux-kernel@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