From: Kees Cook <kees@kernel.org>
To: Balbir Singh <balbirs@nvidia.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
x86@kernel.org, linux-kernel@vger.kernel.org, apopple@nvidia.com,
jgg@nvidia.com, jhubbard@nvidia.com,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] x86/kaslr: Revisit entropy when CONFIG_PCI_P2PDMA is enabled
Date: Thu, 6 Feb 2025 14:51:08 -0800 [thread overview]
Message-ID: <202502061450.0935BB9@keescook> (raw)
In-Reply-To: <08746633-d844-4dc1-90c7-7c3d63b5f4b2@nvidia.com>
On Fri, Feb 07, 2025 at 09:23:50AM +1100, Balbir Singh wrote:
> On 2/7/25 08:46, Kees Cook wrote:
> > On Fri, Feb 07, 2025 at 08:22:23AM +1100, Balbir Singh wrote:
> >> On 2/7/25 06:59, Kees Cook wrote:
> >>> On Thu, Feb 06, 2025 at 09:10:58AM +0100, Peter Zijlstra wrote:
> >>>> On Thu, Feb 06, 2025 at 01:32:01PM +1100, Balbir Singh wrote:
> >>>>> When CONFIG_PCI_P2PDMA is enabled, it maps the PFN's via a
> >>>>> ZONE_DEVICE mapping using devm_memremap_pages(). The mapped
> >>>>> virtual address range corresponds to the pci_resource_start()
> >>>>> of the BAR address and size corresponding to the BAR length.
> >>>>>
> >>>>> When KASLR is enabled, the direct map range of the kernel is
> >>>>> reduced to the size of physical memory plus additional padding.
> >>>>> If the BAR address is beyond this limit, PCI peer to peer DMA
> >>>>> mappings fail.
> >>>>>
> >>>>> Fix this by not shrinking the size of direct map when CONFIG_PCI_P2PDMA
> >>>>> is enabled. This reduces the total available entropy, but it's
> >>>>> better than the current work around of having to disable KASLR
> >>>>> completely.
> >>>
> >>> So, just to restate my understanding: this is about only the direct map
> >>> (i.e. kaslr_region[0]). The notes (which I think should be left in the
> >>> commit log) say that the entropy dropped from 49 TiB (46 bits) to 20 TiB
> >>> (45 bits). If I'm reading right, the offset granularity is in PUD_SIZE
> >>> (30 bits) steps, so the entropy is going from 16 bits to 15 bits. I don't
> >>> see any general problem with that. Especially if the alternative is 0
> >>> bits of entropy. :)
> >>>
> >>
> >> Yes, this is about the direct map (kaslr_region[0]) and the data is from my
> >> system which has 46 bits of physical address. On larger systems with LA57
> >> the drop might be higher. I am happy to repost the patch with my testing notes
> >> in the commit log, if you think it's useful to have in the commit log.
> >
> > Actually, it might be more useful to note it in the CONFIG help
> > text? "This may reduce direct map ASLR entropy by 1 bit with 46 physical
> > bits, X bits with YY physical bits, [etc...]"
> >
>
> I worded it as follows in drivers/pci/Kconfig
>
> Enabling this option will reduce the entropy of x86 KASLR memory
> regions. For example - on a 46 bit system, the entropy goes down
> from 16 bits to 15 bits. The actual reduction in entropy depends
> on the physical address bits, on processor features, kernel config
> (5 level page table) and physical memory present on the system.
>
> Does that seem reasonable?
Yeah, I like it. Thanks!
--
Kees Cook
prev parent reply other threads:[~2025-02-06 22:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 2:32 [PATCH] x86/kaslr: Revisit entropy when CONFIG_PCI_P2PDMA is enabled Balbir Singh
2025-02-06 8:10 ` Peter Zijlstra
2025-02-06 19:59 ` Kees Cook
2025-02-06 21:22 ` Balbir Singh
2025-02-06 21:46 ` Kees Cook
2025-02-06 22:23 ` Balbir Singh
2025-02-06 22:51 ` Kees Cook [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202502061450.0935BB9@keescook \
--to=kees@kernel.org \
--cc=apopple@nvidia.com \
--cc=balbirs@nvidia.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox