Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
ef01f00
UBUNTU: [Packaging] initialize linux-hwe-6.2
May 10, 2023
5e5f1a2
UBUNTU: [Packaging] update variants
May 10, 2023
bb29668
UBUNTU: [Packaging] update update.conf
May 10, 2023
703e9d0
UBUNTU: [Packaging] import and update copy-files and local-mangle
May 10, 2023
8d747cf
UBUNTU: [Config] import annotations from master
May 10, 2023
30ffa6b
UBUNTU: Start new release
May 10, 2023
52d1453
UBUNTU: link-to-tracker: update tracking bug
May 10, 2023
e4e1488
UBUNTU: Ubuntu-hwe-6.2-6.2.0-21.21~22.04.2
May 10, 2023
f6044e2
UBUNTU: [Packaging] update variants
May 11, 2023
500fb75
UBUNTU: [Packaging] update Ubuntu.md
May 11, 2023
ce32322
Revert "UBUNTU: SAUCE: modpost: support arbitrary symbol length in mo…
May 24, 2023
342ebdb
UBUNTU: Start new release
May 30, 2023
1d01846
UBUNTU: link-to-tracker: update tracking bug
May 30, 2023
f3059ec
UBUNTU: Ubuntu-hwe-6.2-6.2.0-23.23~22.04.1
May 30, 2023
781a6f2
UBUNTU: [Packaging] Update local-mangle to override gcc version
LukeNow Jun 27, 2023
4a45d64
UBUNTU: [Packaging] update local-mangle to not include rust
LukeNow Jun 27, 2023
32494ea
UBUNTU: [Config] Update annotations after change to gcc-11
LukeNow Jun 27, 2023
940fba2
UBUNTU: Start new release
LukeNow Jun 27, 2023
e09287d
UBUNTU: [Packaging] Replace miscellaneous changelog entries
LukeNow Jun 27, 2023
68fb228
UBUNTU: link-to-tracker: update tracking bug
LukeNow Jun 27, 2023
8c3d2ac
UBUNTU: Ubuntu-hwe-6.2-6.2.0-25.25~22.04.1
LukeNow Jun 27, 2023
b28c8a8
UBUNTU: [Config] Do not override RUST_IS_AVAILABLE
smb49 Jun 28, 2023
d7ecd44
UBUNTU: Ubuntu-hwe-6.2-6.2.0-25.25~22.04.2
smb49 Jun 28, 2023
5e6f3e4
UBUNTU: [Packaging] Convert getabis to hwe-6.2
smb49 Jul 13, 2023
3b68586
UBUNTU: Start new release
smb49 Jul 13, 2023
a1374ac
UBUNTU: link-to-tracker: update tracking bug
smb49 Jul 13, 2023
b2ec4e1
UBUNTU: Ubuntu-hwe-6.2-6.2.0-26.26~22.04.1
smb49 Jul 13, 2023
c7f6de0
UBUNTU: [Packaging] update variants
smb49 Aug 16, 2023
f5ba85e
UBUNTU: [Config] Keep Rust disabled
smb49 Aug 16, 2023
7e7d062
UBUNTU: [Config] Drop CONFIG_PAHOLE_HAS_LANG_EXCLUDE deviation
smb49 Aug 16, 2023
ea8ccfa
UBUNTU: Start new release
smb49 Aug 16, 2023
4b75d1c
UBUNTU: link-to-tracker: update tracking bug
smb49 Aug 16, 2023
ee98e4c
UBUNTU: Ubuntu-hwe-6.2-6.2.0-31.31~22.04.1
smb49 Aug 16, 2023
eda7d66
UBUNTU: Start new release
smb49 Aug 18, 2023
8865e98
UBUNTU: link-to-tracker: update tracking bug
smb49 Aug 18, 2023
e049366
UBUNTU: Ubuntu-hwe-6.2-6.2.0-32.32~22.04.1
smb49 Aug 18, 2023
d6212db
UBUNTU: [Packaging] Initialize linux-nvidia-6.2
ianmay81 Apr 6, 2023
6dcb8da
UBUNTU: [Packaging] update variants
ianmay81 May 3, 2023
1a79990
UBUNTU: [Packaging] update Ubuntu.md
ianmay81 May 3, 2023
66556d6
UBUNTU: [Packaging] update update.conf
ianmay81 May 3, 2023
b50abfe
UBUNTU: Start new release
ianmay81 May 3, 2023
9970197
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1002.2~22.04.1
ianmay81 May 3, 2023
08039fc
UBUNTU: [Packaging] fix Vcs-Git url
ianmay81 May 4, 2023
b6a61ad
UBUNTU: [Packaging] update helper script
ianmay81 May 31, 2023
6a4c9f4
UBUNTU: Start new release
ianmay81 May 31, 2023
4a3928a
UBUNTU: link-to-tracker: update tracking bug
ianmay81 May 31, 2023
07968e0
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1003.3~22.04.1
ianmay81 May 31, 2023
ad56b58
spi: Add TPM HW flow flag
kkyarlagadda Apr 21, 2023
2036083
spi: tegra210-quad: Enable TPM wait polling
kkyarlagadda Apr 21, 2023
23269e4
spi: tegra210-quad: set half duplex flag
kkyarlagadda Feb 23, 2023
c368c92
genirq: Use hlist for managing resend handlers
shankerd04 May 19, 2023
0bc4a97
genirq: Encapsulate sparse bitmap handling
shankerd04 May 19, 2023
e72e3c5
genirq: Use a maple tree for interrupt descriptor management
shankerd04 May 19, 2023
00c7f2a
tpm_tis-spi: Add hardware wait polling
kkyarlagadda Apr 21, 2023
6bc3939
arm64: kaslr: don't pretend KASLR is enabled if offset < MIN_KIMG_ALIGN
ardbiesheuvel Feb 23, 2023
0e22c25
arm64: module: remove old !KASAN_VMALLOC logic
mrutland-arm May 30, 2023
6297a81
arm64: kasan: remove !KASAN_VMALLOC remnants
mrutland-arm May 30, 2023
dbce7de
arm64: kaslr: split kaslr/module initialization
mrutland-arm May 30, 2023
3a5ef4a
arm64: module: move module randomization to module.c
mrutland-arm May 30, 2023
162d77b
arm64: module: mandate MODULE_PLTS
mrutland-arm May 30, 2023
0c4f6cc
arm64: module: rework module VA range selection
mrutland-arm May 30, 2023
9b39c5e
UBUNTU: [Packaging] resync getabis
nvidia-bfigg Jun 28, 2023
9d14746
UBUNTU: [Packaging] update helper scripts
nvidia-bfigg Jun 28, 2023
ff4c11c
UBUNTU: [Packaging] resync getabis
nvidia-bfigg Jun 29, 2023
38925a1
UBUNTU: [Packaging] update helper scripts
nvidia-bfigg Jun 29, 2023
c7b326c
UBUNTU: Start new release
nvidia-bfigg Jun 29, 2023
3d90f3e
UBUNTU: link-to-tracker: update tracking bug
nvidia-bfigg Jun 29, 2023
9cc70a8
UBUNTU: CONFIG: CONFIG_ARM64_MODULE_PLTS added, CC VERSION changed
nvidia-bfigg Jun 30, 2023
9fa57a4
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1004.4~22.04.1
nvidia-bfigg Jun 30, 2023
ba9576c
mm, slab/slub: Ensure kmem_cache_alloc_bulk() is available early
KAGA-KOKO Feb 7, 2023
3d8886b
UBUNTU: [Packaging] nvidia-6.2: remove tools-common package
ianmay81 Jul 26, 2023
946056c
UBUNTU: [Packaging] update variants
ianmay81 Jul 26, 2023
57bd515
UBUNTU: Start new release
ianmay81 Jul 26, 2023
2c2f61a
UBUNTU: link-to-tracker: update tracking bug
ianmay81 Jul 26, 2023
7c472bf
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1006.6~22.04.2
ianmay81 Jul 26, 2023
e2e5c0e
NVIDIA: SAUCE: Add NVMe Patches to enable GDS
sourabgupta3 Jul 27, 2023
4ff7f9c
UBUNTU: [Packaging] update variants
ianmay81 Aug 5, 2023
769da36
UBUNTU: [Packaging] update update.conf
ianmay81 Aug 5, 2023
fba8345
UBUNTU: Start new release
ianmay81 Aug 5, 2023
64aacfa
UBUNTU: [Config] nvidia-6.2: update annotations
ianmay81 Aug 5, 2023
aecef76
NVIDIA: [Config] Overriding CONFIG_PREEMPT_NONE, CONFIG_CPU_FREQ_DEFA…
ianmay81 Aug 5, 2023
66cd912
NVIDIA: SAUCE: NFS: Patch NFS driver to support GDS with 6.2 Kernel
sourabgupta3 Jul 19, 2023
50ae4be
UBUNTU: link-to-tracker: update tracking bug
ianmay81 Aug 5, 2023
585bfd3
UBUNTU: debian/dkms-versions -- update from kernel-versions (main/d20…
ianmay81 Aug 5, 2023
c34627a
UBUNTU: debian/dkms-versions -- add nvidia-fs and mstflint
ianmay81 Aug 5, 2023
2b7ce9a
UBUNTU: [Packaging] add nvidia build depends for nvidia-fs-dkms
ianmay81 Aug 5, 2023
f713997
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1007.7
ianmay81 Aug 6, 2023
ef3b9ac
UBUNTU: Start new release
ianmay81 Aug 7, 2023
7b4e201
UBUNTU: [Packaging] nvidia-6.2: remove nvidia-fs module
ianmay81 Aug 7, 2023
491289e
UBUNTU: link-to-tracker: update tracking bug
ianmay81 Aug 7, 2023
be1ba0f
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1008.8
ianmay81 Aug 7, 2023
bfa15a4
Revert "NVIDIA: SAUCE: Add NVMe Patches to enable GDS"
nvidia-bfigg Aug 10, 2023
220de10
NVMe/MVMEeOF: Patch NVMe/NVMeOF driver to support GDS on Linux 6.2 Ke…
sourabgupta3 Jul 19, 2023
d8b5aa5
NVIDIA: SAUCE: iommu/arm-smmu-v3: Allow default substream bypass with…
nicolinc Jun 22, 2023
9b73aa8
UBUNTU: Start new release
ianmay81 Aug 14, 2023
f7fb848
UBUNTU: link-to-tracker: update tracking bug
ianmay81 Aug 14, 2023
c98db24
NVIDIA: [Config] CONFIG_NR_CPUS=512 for Grace
nvidia-bfigg Aug 9, 2023
c42de76
NVIDIA: [Config] CONFIG_MTD_SPI_NOR=y for Grace
nvidia-bfigg Aug 9, 2023
03f8509
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1009.9
ianmay81 Aug 14, 2023
2769adf
NVMeoF driver patch: Minor fix to free up sg table on error path
sourabgupta3 Aug 16, 2023
3b5c8c0
UBUNTU: [Packaging] resync update-dkms-versions helper
nvidia-bfigg Aug 25, 2023
0d95014
UBUNTU: [Packaging] resync getabis
nvidia-bfigg Aug 25, 2023
1a8e868
NVIDIA: [dkms] updating mstflint to the 4.25 version
nvidia-bfigg Aug 25, 2023
7029ccd
UBUNTU: Start new release
nvidia-bfigg Aug 25, 2023
3e8df80
UBUNTU: link-to-tracker: update tracking bug
nvidia-bfigg Aug 28, 2023
f961570
UBUNTU: Ubuntu-nvidia-6.2-6.2.0-1010.10
nvidia-bfigg Aug 28, 2023
bdb416d
NVIDIA: [Config]: Ensure the TPM is available before IMA initializes
jamieNguyenNVIDIA Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Documentation/arm64/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ AArch64 Linux memory layout with 4KB pages + 4 levels (48-bit)::
0000000000000000 0000ffffffffffff 256TB user
ffff000000000000 ffff7fffffffffff 128TB kernel logical memory map
[ffff600000000000 ffff7fffffffffff] 32TB [kasan shadow region]
ffff800000000000 ffff800007ffffff 128MB modules
ffff800008000000 fffffbffefffffff 124TB vmalloc
ffff800000000000 ffff80007fffffff 2GB modules
ffff800080000000 fffffbffefffffff 124TB vmalloc
fffffbfff0000000 fffffbfffdffffff 224MB fixed mappings (top down)
fffffbfffe000000 fffffbfffe7fffff 8MB [guard region]
fffffbfffe800000 fffffbffff7fffff 16MB PCI I/O space
Expand All @@ -50,8 +50,8 @@ AArch64 Linux memory layout with 64KB pages + 3 levels (52-bit with HW support):
0000000000000000 000fffffffffffff 4PB user
fff0000000000000 ffff7fffffffffff ~4PB kernel logical memory map
[fffd800000000000 ffff7fffffffffff] 512TB [kasan shadow region]
ffff800000000000 ffff800007ffffff 128MB modules
ffff800008000000 fffffbffefffffff 124TB vmalloc
ffff800000000000 ffff80007fffffff 2GB modules
ffff800080000000 fffffbffefffffff 124TB vmalloc
fffffbfff0000000 fffffbfffdffffff 224MB fixed mappings (top down)
fffffbfffe000000 fffffbfffe7fffff 8MB [guard region]
fffffbfffe800000 fffffbffff7fffff 16MB PCI I/O space
Expand Down
10 changes: 5 additions & 5 deletions Ubuntu.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Name: linux
Version: 6.1.0
Series: 23.04 (lunar)
Name: linux-nvidia-6.2
Version: 6.2.0
Series: 22.04 (jammy)
Description:
This is the source code for the Ubuntu linux kernel for the 23.04 series. This
source tree is used to produce the flavours: generic, generic-64k, generic-lpae.
This is the source code for the Ubuntu linux kernel for the 22.04 series. This
source tree is used to produce the flavours: nvidia, nvidia-64k.
This kernel is configured to support the widest range of desktop, laptop and
server configurations.
28 changes: 3 additions & 25 deletions arch/arm64/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ config ARM64
select HAVE_IOREMAP_PROT
select HAVE_IRQ_TIME_ACCOUNTING
select HAVE_KVM
select HAVE_MOD_ARCH_SPECIFIC
select HAVE_NMI
select HAVE_PERF_EVENTS
select HAVE_PERF_REGS
Expand Down Expand Up @@ -553,7 +554,6 @@ config ARM64_ERRATUM_845719
config ARM64_ERRATUM_843419
bool "Cortex-A53: 843419: A load or store might access an incorrect address"
default y
select ARM64_MODULE_PLTS if MODULES
help
This option links the kernel with '--fix-cortex-a53-843419' and
enables PLT support to replace certain ADRP instructions, which can
Expand Down Expand Up @@ -2066,26 +2066,6 @@ config ARM64_SME
register state capable of holding two dimensional matrix tiles to
enable various matrix operations.

config ARM64_MODULE_PLTS
bool "Use PLTs to allow module memory to spill over into vmalloc area"
depends on MODULES
select HAVE_MOD_ARCH_SPECIFIC
help
Allocate PLTs when loading modules so that jumps and calls whose
targets are too far away for their relative offsets to be encoded
in the instructions themselves can be bounced via veneers in the
module's PLT. This allows modules to be allocated in the generic
vmalloc area after the dedicated module memory area has been
exhausted.

When running with address space randomization (KASLR), the module
region itself may be too far away for ordinary relative jumps and
calls, and so in that case, module PLTs are required and cannot be
disabled.

Specific errata workaround(s) might also force module PLTs to be
enabled (ARM64_ERRATUM_843419).

config ARM64_PSEUDO_NMI
bool "Support for NMI-like interrupts"
select ARM_GIC_V3
Expand Down Expand Up @@ -2126,7 +2106,6 @@ config RELOCATABLE

config RANDOMIZE_BASE
bool "Randomize the address of the kernel image"
select ARM64_MODULE_PLTS if MODULES
select RELOCATABLE
help
Randomizes the virtual address at which the kernel image is
Expand Down Expand Up @@ -2157,9 +2136,8 @@ config RANDOMIZE_MODULE_REGION_FULL
When this option is not set, the module region will be randomized over
a limited range that contains the [_stext, _etext] interval of the
core kernel, so branch relocations are almost always in range unless
ARM64_MODULE_PLTS is enabled and the region is exhausted. In this
particular case of region exhaustion, modules might be able to fall
back to a larger 2GB area.
the region is exhausted. In this particular case of region
exhaustion, modules might be able to fall back to a larger 2GB area.

config CC_HAVE_STACKPROTECTOR_SYSREG
def_bool $(cc-option,-mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=0)
Expand Down
15 changes: 14 additions & 1 deletion arch/arm64/include/asm/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#define KIMAGE_VADDR (MODULES_END)
#define MODULES_END (MODULES_VADDR + MODULES_VSIZE)
#define MODULES_VADDR (_PAGE_END(VA_BITS_MIN))
#define MODULES_VSIZE (SZ_128M)
#define MODULES_VSIZE (SZ_2G)
#define VMEMMAP_START (-(UL(1) << (VA_BITS - VMEMMAP_SHIFT)))
#define VMEMMAP_END (VMEMMAP_START + VMEMMAP_SIZE)
#define PCI_IO_END (VMEMMAP_START - SZ_8M)
Expand Down Expand Up @@ -180,6 +180,7 @@
#include <linux/compiler.h>
#include <linux/mmdebug.h>
#include <linux/types.h>
#include <asm/boot.h>
#include <asm/bug.h>

#if VA_BITS > 48
Expand All @@ -203,6 +204,18 @@ static inline unsigned long kaslr_offset(void)
return kimage_vaddr - KIMAGE_VADDR;
}

#ifdef CONFIG_RANDOMIZE_BASE
void kaslr_init(void);
static inline bool kaslr_enabled(void)
{
extern bool __kaslr_is_enabled;
return __kaslr_is_enabled;
}
#else
static inline void kaslr_init(void) { }
static inline bool kaslr_enabled(void) { return false; }
#endif

/*
* Allow all memory at the discovery stage. We will clip it later.
*/
Expand Down
8 changes: 0 additions & 8 deletions arch/arm64/include/asm/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <asm-generic/module.h>

#ifdef CONFIG_ARM64_MODULE_PLTS
struct mod_plt_sec {
int plt_shndx;
int plt_num_entries;
Expand All @@ -21,7 +20,6 @@ struct mod_arch_specific {
/* for CONFIG_DYNAMIC_FTRACE */
struct plt_entry *ftrace_trampolines;
};
#endif

u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
void *loc, const Elf64_Rela *rela,
Expand All @@ -30,12 +28,6 @@ u64 module_emit_plt_entry(struct module *mod, Elf64_Shdr *sechdrs,
u64 module_emit_veneer_for_adrp(struct module *mod, Elf64_Shdr *sechdrs,
void *loc, u64 val);

#ifdef CONFIG_RANDOMIZE_BASE
extern u64 module_alloc_base;
#else
#define module_alloc_base ((u64)_etext - MODULES_VSIZE)
#endif

struct plt_entry {
/*
* A program that conforms to the AArch64 Procedure Call Standard
Expand Down
2 changes: 0 additions & 2 deletions arch/arm64/include/asm/module.lds.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
SECTIONS {
#ifdef CONFIG_ARM64_MODULE_PLTS
.plt 0 : { BYTE(0) }
.init.plt 0 : { BYTE(0) }
.text.ftrace_trampoline 0 : { BYTE(0) }
#endif

#ifdef CONFIG_KASAN_SW_TAGS
/*
Expand Down
3 changes: 1 addition & 2 deletions arch/arm64/kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ obj-$(CONFIG_COMPAT) += sigreturn32.o
obj-$(CONFIG_COMPAT_ALIGNMENT_FIXUPS) += compat_alignment.o
obj-$(CONFIG_KUSER_HELPERS) += kuser32.o
obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o entry-ftrace.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_ARM64_MODULE_PLTS) += module-plts.o
obj-$(CONFIG_MODULES) += module.o module-plts.o
obj-$(CONFIG_PERF_EVENTS) += perf_regs.o perf_callchain.o
obj-$(CONFIG_HW_PERF_EVENTS) += perf_event.o
obj-$(CONFIG_HAVE_HW_BREAKPOINT) += hw_breakpoint.o
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/kernel/cpufeature.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,7 @@ bool kaslr_requires_kpti(void)
return false;
}

return kaslr_offset() > 0;
return kaslr_enabled();
}

static bool __meltdown_safe = true;
Expand Down
8 changes: 3 additions & 5 deletions arch/arm64/kernel/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)

static struct plt_entry *get_ftrace_plt(struct module *mod, unsigned long addr)
{
#ifdef CONFIG_ARM64_MODULE_PLTS
#ifdef CONFIG_MODULES
struct plt_entry *plt = mod->arch.ftrace_trampolines;

if (addr == FTRACE_ADDR)
Expand Down Expand Up @@ -145,7 +145,7 @@ static bool ftrace_find_callable_addr(struct dyn_ftrace *rec,
* must use a PLT to reach it. We can only place PLTs for modules, and
* only when module PLT support is built-in.
*/
if (!IS_ENABLED(CONFIG_ARM64_MODULE_PLTS))
if (!IS_ENABLED(CONFIG_MODULES))
return false;

/*
Expand Down Expand Up @@ -249,10 +249,8 @@ int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec,
*
* Note: 'mod' is only set at module load time.
*/
if (!IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) &&
IS_ENABLED(CONFIG_ARM64_MODULE_PLTS) && mod) {
if (!IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_ARGS) && mod)
return aarch64_insn_patch_text_nosync((void *)pc, new);
}

if (!ftrace_find_callable_addr(rec, mod, &addr))
return -EINVAL;
Expand Down
83 changes: 14 additions & 69 deletions arch/arm64/kernel/kaslr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,90 +4,35 @@
*/

#include <linux/cache.h>
#include <linux/crc32.h>
#include <linux/init.h>
#include <linux/libfdt.h>
#include <linux/mm_types.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/pgtable.h>
#include <linux/random.h>
#include <linux/printk.h>

#include <asm/fixmap.h>
#include <asm/kernel-pgtable.h>
#include <asm/cpufeature.h>
#include <asm/memory.h>
#include <asm/mmu.h>
#include <asm/sections.h>
#include <asm/setup.h>

u64 __ro_after_init module_alloc_base;
u16 __initdata memstart_offset_seed;

struct arm64_ftr_override kaslr_feature_override __initdata;

static int __init kaslr_init(void)
{
u64 module_range;
u32 seed;

/*
* Set a reasonable default for module_alloc_base in case
* we end up running with module randomization disabled.
*/
module_alloc_base = (u64)_etext - MODULES_VSIZE;
bool __ro_after_init __kaslr_is_enabled = false;

void __init kaslr_init(void)
{
if (kaslr_feature_override.val & kaslr_feature_override.mask & 0xf) {
pr_info("KASLR disabled on command line\n");
return 0;
}

if (!kaslr_offset()) {
pr_warn("KASLR disabled due to lack of seed\n");
return 0;
return;
}

pr_info("KASLR enabled\n");

/*
* KASAN without KASAN_VMALLOC does not expect the module region to
* intersect the vmalloc region, since shadow memory is allocated for
* each module at load time, whereas the vmalloc region will already be
* shadowed by KASAN zero pages.
* The KASLR offset modulo MIN_KIMG_ALIGN is taken from the physical
* placement of the image rather than from the seed, so a displacement
* of less than MIN_KIMG_ALIGN means that no seed was provided.
*/
BUILD_BUG_ON((IS_ENABLED(CONFIG_KASAN_GENERIC) ||
IS_ENABLED(CONFIG_KASAN_SW_TAGS)) &&
!IS_ENABLED(CONFIG_KASAN_VMALLOC));

seed = get_random_u32();

if (IS_ENABLED(CONFIG_RANDOMIZE_MODULE_REGION_FULL)) {
/*
* Randomize the module region over a 2 GB window covering the
* kernel. This reduces the risk of modules leaking information
* about the address of the kernel itself, but results in
* branches between modules and the core kernel that are
* resolved via PLTs. (Branches between modules will be
* resolved normally.)
*/
module_range = SZ_2G - (u64)(_end - _stext);
module_alloc_base = max((u64)_end - SZ_2G, (u64)MODULES_VADDR);
} else {
/*
* Randomize the module region by setting module_alloc_base to
* a PAGE_SIZE multiple in the range [_etext - MODULES_VSIZE,
* _stext) . This guarantees that the resulting region still
* covers [_stext, _etext], and that all relative branches can
* be resolved without veneers unless this region is exhausted
* and we fall back to a larger 2GB window in module_alloc()
* when ARM64_MODULE_PLTS is enabled.
*/
module_range = MODULES_VSIZE - (u64)(_etext - _stext);
if (kaslr_offset() < MIN_KIMG_ALIGN) {
pr_warn("KASLR disabled due to lack of seed\n");
return;
}

/* use the lower 21 bits to randomize the base of the module region */
module_alloc_base += (module_range * (seed & ((1 << 21) - 1))) >> 21;
module_alloc_base &= PAGE_MASK;

return 0;
pr_info("KASLR enabled\n");
__kaslr_is_enabled = true;
}
subsys_initcall(kaslr_init)
Loading