Skip to content

Commit 89567a4

Browse files
author
CKI KWF Bot
committed
Merge: KASLR: proactive backports to v6.16
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1462 JIRA: https://issues.redhat.com/browse/RHEL-110657 Backport of selected KASLR-related fixes, cleanups, and enhancements targeting upstream v6.16. Signed-off-by: Ricardo Robaina <rrobaina@redhat.com> Approved-by: John W. Linville <linville@redhat.com> Approved-by: Audra Mitchell <aubaker@redhat.com> Approved-by: Prarit Bhargava <prarit@redhat.com> Approved-by: Rafael Aquini <raquini@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents 1902a85 + fe9855f commit 89567a4

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

arch/x86/boot/compressed/kaslr.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
#include "efi.h"
2626

2727
#include <generated/compile.h>
28-
#include <linux/module.h>
29-
#include <linux/uts.h>
30-
#include <linux/utsname.h>
31-
#include <linux/ctype.h>
3228
#include <generated/utsversion.h>
3329
#include <generated/utsrelease.h>
3430

arch/x86/mm/init_64.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -967,9 +967,18 @@ int add_pages(int nid, unsigned long start_pfn, unsigned long nr_pages,
967967
ret = __add_pages(nid, start_pfn, nr_pages, params);
968968
WARN_ON_ONCE(ret);
969969

970-
/* update max_pfn, max_low_pfn and high_memory */
971-
update_end_of_memory_vars(start_pfn << PAGE_SHIFT,
972-
nr_pages << PAGE_SHIFT);
970+
/*
971+
* Special case: add_pages() is called by memremap_pages() for adding device
972+
* private pages. Do not bump up max_pfn in the device private path,
973+
* because max_pfn changes affect dma_addressing_limited().
974+
*
975+
* dma_addressing_limited() returning true when max_pfn is the device's
976+
* addressable memory can force device drivers to use bounce buffers
977+
* and impact their performance negatively:
978+
*/
979+
if (!params->pgmap)
980+
/* update max_pfn, max_low_pfn and high_memory */
981+
update_end_of_memory_vars(start_pfn << PAGE_SHIFT, nr_pages << PAGE_SHIFT);
973982

974983
return ret;
975984
}

arch/x86/mm/kaslr.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@ void __init kernel_randomize_memory(void)
113113
memory_tb = DIV_ROUND_UP(max_pfn << PAGE_SHIFT, 1UL << TB_SHIFT) +
114114
CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING;
115115

116-
/* Adapt physical memory region size based on available memory */
117-
if (memory_tb < kaslr_regions[0].size_tb)
116+
/*
117+
* Adapt physical memory region size based on available memory,
118+
* except when CONFIG_PCI_P2PDMA is enabled. P2PDMA exposes the
119+
* device BAR space assuming the direct map space is large enough
120+
* for creating a ZONE_DEVICE mapping in the direct map corresponding
121+
* to the physical BAR address.
122+
*/
123+
if (!IS_ENABLED(CONFIG_PCI_P2PDMA) && (memory_tb < kaslr_regions[0].size_tb))
118124
kaslr_regions[0].size_tb = memory_tb;
119125

120126
/*

drivers/pci/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ config PCI_P2PDMA
207207
P2P DMA transactions must be between devices behind the same root
208208
port.
209209

210+
Enabling this option will reduce the entropy of x86 KASLR memory
211+
regions. For example - on a 46 bit system, the entropy goes down
212+
from 16 bits to 15 bits. The actual reduction in entropy depends
213+
on the physical address bits, on processor features, kernel config
214+
(5 level page table) and physical memory present on the system.
215+
210216
If unsure, say N.
211217

212218
config PCI_LABEL

0 commit comments

Comments
 (0)