From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384112; b=Dayzxcqtpvl7iQeH57tKkEjM3aGmakoLkdSwZdy3NXtuYbTzfVB8WQRbdPsDHd8Zp1n3 VhsgZ46aYHgoWpzjOkTQWRMUphxo6JaVjIojE+gqV9KezwAhm31E1d4HcgzrRyE/UmNLR ebsj1E/NLA7Qfb6x9t9F+WumH5IT74a32paxJpe0oVWdkEwMTgJ/wuZaWQHO0W/ydkS4y VMUMeVLA7R4f0SIi07yy7rm62SmPwswvRXSysBw7vCL0UMDilliNP3lgtKkPNJLBv3y3/ 1Uty3jy0wJS6CiRBlQRe81X/xIv3I2xng2CCyaYBezyiMsdgzIMeGhvXJSxySYAO+QQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384112; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Axn4WiWdpJXlReLVfgZO+Ek4h1Yk9eKQzzDjmNTHWWU=; b=wJT3wCzETXkkxQh+LqTksL3PgMHp91VFsDjO+o0+U4ijdo6e4FknSHcYOTHgp0SmzTHc DxHjNlAfH767F+LoUjm+vdlFhPK+PFcpFhIYG6+TD6YIwLU2BFJZ06mjNcyw5zvKcNsBZ ZVjG48jbPdMfF0qWhuJXlrut3jC69GNqoc4W97pPmhaXi/5tQIQKvYB3x0lRF4fRjWP2+ eY4EiR1X0t0XF0adcrd5h4eaGlOFzit25GRiGWcAG8HNwxtZmTUvgzTxWjW6qjPGAANwk Ax9xWcQ5KneFA0t+AsolfTqZf5kdY6cUDs+8L7RUAkuPl7TM6sEVfGe+Y4lfckxzB2Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="Eif0jse/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C18C1606A330 for ; Fri, 4 Dec 2026 11:35:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Eif0jse/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9C5AC1F000C2; Fri, 4 Dec 2026 11:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796384112; bh=Axn4WiWdpJXlReLVfgZO+Ek4h1Yk9eKQzzDjmNTHWWU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Eif0jse/+2vXT577b57xLp4DY6voVB6op9LNhf570lbXDMsH/MkAJVWqihA+swgNM gF0soni07MkjRyd7MmizT2VQNgvlzBPTX4spfwUWCsahfbIiHDrtjbWFXkoDlx0XCv JCJHFfUyb5HaTs9H3t3688D48Nqu6EaLrzi+uMGELc04SedlGAWxkyuY4BGHSY2eO4 a09GFOiSOs9WvovMAW8A7xfYdmpQ+RlkesWnBEBzuy32OmaEFgukTL+NQ4YAiboMen anvQ/AG1deYBD7w3cYJ1iPJEzbJ6hjWa1fMTfKH4ofw01UMaZb28Qm3/cDmpClJ2LF cSr2ZauzwGqTA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] x86/unaccepted_memory: Do not accept ranges that are no longer E820 RAM Reply-To: sashiko-reviews@lists.linux.dev To: "Pankaj Gupta" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , x86@kernel.org, "Jonathan Corbet" , "Shuah Khan" , rdunlap@infradead.org Cc: "Arnd Bergmann" , "Dapeng Mi" , "Marco Elver" , "H . Peter Anvin" , "Tom Lendacky" , "Ard Biesheuvel" , "Kiryl Shutsemau" , "Ilias Apalodimas" , "Mike Rapoport" , linux-mm@kvack.org, linux-efi@vger.kernel.org, Pankaj.gupta.linux@gmail.com, "Ethan Nelson-Moore" , "Karl Mehltretter" In-Reply-To: <20261203113224.250498-1-pankaj.gupta@amd.com> References: <20261203113224.250498-1-pankaj.gupta@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:35:11 +0000 X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] x86/unaccepted_memory: arch_clear_accepted() clears partial units in bitmap - [High] x86/unaccepted_memory: e820_table UAF race with free_initmem() - [Medium] efi/unaccepted: set hole bits break range_contains_unaccepted_memory() - [Medium] x86/unaccepted_memory: arch_accept_memory() skips hot-added non-E820-RAM - [Medium] x86/unaccepted_memory: 64-bit PAGE_ALIGN() wraparound in e820_ram_pages() - [Medium] efi: unaddressed maintainer objection to E820 filtering in accept_memory() -- commit 9fd60bf8e1c09dbddfc18def62b612b4e1e680e2 Author: Pankaj Gupta x86/unaccepted_memory: Do not accept ranges that are no longer E820 RAM This commit filters x86 memory acceptance in arch_accept_memory() to whole pages covered by E820_TYPE_RAM entries and adds arch_clear_accepted() so accept_memory() only clears bitmap bits for those E820 RAM subranges. > diff --git a/arch/x86/include/asm/unaccepted_memory.h b/arch/x86/include/= asm/unaccepted_memory.h > index f5937e9866ac1..9e27a9953dd83 100644 > --- a/arch/x86/include/asm/unaccepted_memory.h > +++ b/arch/x86/include/asm/unaccepted_memory.h [ ... ] > @@ -18,6 +19,47 @@ static inline void arch_accept_memory(phys_addr_t star= t, phys_addr_t end) > } > } > =20 > +static inline bool e820_ram_pages(struct e820_entry *entry, phys_addr_t = start, > + phys_addr_t end, phys_addr_t *s, phys_addr_t *e) > +{ > + if (entry->type !=3D E820_TYPE_RAM) > + return false; > + > + *s =3D PAGE_ALIGN(max_t(phys_addr_t, start, entry->addr)); > + *e =3D PAGE_ALIGN_DOWN(min_t(phys_addr_t, end, entry->addr + entry->siz= e)); > + return *s < *e; > +} [Severity: Medium] Can PAGE_ALIGN() wrap *s to zero for a non-overlapping E820_TYPE_RAM entry near U64_MAX? An entry such as memmap=3D0x7ff@0xfffffffffffff800 passes e820__update_tabl= e() because addr + size does not overflow. Calling PAGE_ALIGN() before checking overlap wraps *s to 0 while *e equals end, so *s < *e returns true. arch_accept_memory() then passes [0, end) to __arch_accept_memory(), panick= ing on TDX or faulting on SEV-SNP, and arch_clear_accepted() underflows (s - ba= se) and (last - first) when base is non-zero, writing out of bounds in bitmap_clear(). Checking overlap before calling PAGE_ALIGN() avoids this. > + > +static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) > +{ > + phys_addr_t s, e; > + u32 i; > + > + for (i =3D 0; i < e820_table->nr_entries; i++) { > + if (e820_ram_pages(&e820_table->entries[i], start, end, &s, &e)) > + __arch_accept_memory(s, e); > + } > +} [Severity: High] Can arch_accept_memory() and arch_clear_accepted() race with free_initmem() freeing e820_table_init? During SMP boot, lazy memory acceptance can run accept_memory() on one CPU while kernel_init() runs free_initmem() on another: CPU0 CPU1 kernel_init() accept_memory() free_initmem() arch_accept_memory() /* reads e820_table_init */ __arch_accept_memory(...) e820__reallocate_tables() e820_table =3D kmemdup(...) free_kernel_image_pages(...) /* poisons/unmaps initmem */ e820_table_init->nr_entries <-- use-after-free e820__reallocate_tables() swaps e820_table with a plain store and no grace period before free_kernel_image_pages() poisons or unmaps e820_table_init. On AMD systems with X86_FEATURE_INVLPGB, flush_tlb_all() broadcasts hardware invalidations rather than IPIs, so it does not wait for remote IRQ-disabled CPUs executing arch_accept_memory(). A concurrent reader can then observe POISON_FREE_INITMEM (0xcccccccc) as nr_entries or fault on an unmapped init page with interrupts disabled. [Severity: Medium] Does filtering on e820_table cause arch_accept_memory() to silently skip hot-added memory? e820_table is a static boot-time snapshot that arch_add_memory() never updates. If an EFI_UNACCEPTED_MEMORY range is reclassified to E820_TYPE_SOFT_RESERVED via memmap=3D and later hot-added by dax/kmem (dax_kmem_do_hotplug() -> arch_add_memory() -> online_pages() -> __free_pages_core() -> accept_memory()), e820_ram_pages() rejects it. __free_pages_core() and __accept_page() then expose the unaccepted pages to the buddy allocator via __free_pages_ok(), causing an unrecoverable EPT violation on TDX or RMP fault on SEV-SNP on first access. Checking direct-= map coverage (such as pfn_mapped[] / pfn_range_is_mapped()) instead of boot-time e820_table would cover hot-added memory while still avoiding unmapped holes. > + > +static inline void arch_clear_accepted(unsigned long *bitmap, phys_addr_= t base, > + unsigned long unit_size, > + phys_addr_t start, phys_addr_t end) > +{ > + phys_addr_t s, e; > + u32 i; > + > + for (i =3D 0; i < e820_table->nr_entries; i++) { > + unsigned long first, last; > + > + if (!e820_ram_pages(&e820_table->entries[i], start, end, &s, &e)) > + continue; > + > + first =3D (s - base) / unit_size; > + last =3D DIV_ROUND_UP(e - base, unit_size); > + bitmap_clear(bitmap, first, last - first); > + } > +} [Severity: High] Does rounding first down and last up corrupt the persistent unaccepted bitm= ap when a hole is smaller than or unaligned to unit_size (2 MiB)? Each bitmap bit tracks a full 2 MiB unit in EFI_ACPI_RECLAIM_MEMORY, which persists across kexec. With a sub-unit hole such as memmap=3D1M$0x1ffe0000= 0, accepting any E820_TYPE_RAM page in that 2 MiB unit clears the whole unit's bit even though the hole pages remain unaccepted in hardware. Because e820_table_kexec is snapshotted before parse_early_param() applies memmap=3D, a kexec'd kernel receives the hole as E820_TYPE_RAM with its bit= map bit already cleared and crashes when accessing it. Additionally, sanity_check_segment_list() in kernel/kexec_core.c calls accept_memory() on kexec segments chosen from e820_table_kexec, which arch_accept_memory() now silently skips if they lie in a memmap=3D-excluded range. [Severity: Medium] What happens in range_contains_unaccepted_memory() when a full unit_size ho= le leaves its bitmap bit permanently set? For a 2 MiB-aligned hole such as memmap=3D2M$0x1ffe00000, arch_clear_accept= ed() never clears the hole unit's bit. However, range_contains_unaccepted_memor= y() still extends any unit_size-aligned end by + unit_size for the load_unaligned_zeropad() guard page without consulting e820_table. As a result, pfn_is_unaccepted_memory() always returns true for the last 4 = KiB page of live, accepted RAM immediately preceding the hole, causing unaccepted_memory_vmcore_pfn_is_ram() to omit that page from /proc/vmcore a= nd /proc/kcore to zero it out. [ ... ] > diff --git a/drivers/firmware/efi/unaccepted_memory.c b/drivers/firmware/= efi/unaccepted_memory.c > index 4a8ec8d6a571e..b8a0c0d1d2891 100644 > --- a/drivers/firmware/efi/unaccepted_memory.c > +++ b/drivers/firmware/efi/unaccepted_memory.c [ ... ] > @@ -150,7 +149,8 @@ void accept_memory(phys_addr_t start, unsigned long s= ize) > arch_accept_memory(phys_start, phys_end); > =20 > spin_lock(&unaccepted_memory_lock); > - bitmap_clear(unaccepted->bitmap, range_start, len); > + arch_clear_accepted(unaccepted->bitmap, unaccepted->phys_base, > + unit_size, phys_start, phys_end); > } [Severity: Medium] As reported by Ard Biesheuvel on v1 [1], should memmap=3D instead be disall= owed in confidential VMs so the firmware and OS views of memory remain in sync? Rather than addressing that objection, this version extends the E820-filter= ing workaround into generic EFI code via arch_clear_accepted(), exposing the mismatch between page-granular memmap=3D holes and the 2 MiB unit_size EFI bitmap. [1] https://lore.kernel.org/r/bd56cfa0-6fdc-4e83-b571-f2abf647afa2@app.fast= mail.com --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203113224.2504= 98-1-pankaj.gupta@amd.com?part=3D1