diff --git a/correct-spectre-flag-behavior.patch b/kernel-patches/correct-spectre-flag-behavior.patch similarity index 100% rename from correct-spectre-flag-behavior.patch rename to kernel-patches/correct-spectre-flag-behavior.patch diff --git a/kernel-patches/openpax.patch b/kernel-patches/openpax.patch new file mode 100644 index 0000000..a0732e1 --- /dev/null +++ b/kernel-patches/openpax.patch @@ -0,0 +1,1103 @@ +SPDX-FileCopyrightText: (c) 2024 Ariadne Conill +SPDX-FileCopyrightText: (c) 2024 Daniel Micay + +SPDX-License-Identifier: GPL-2.0-only + +From 1da3bb862286af0d83d8546a917618259276d465 Mon Sep 17 00:00:00 2001 +From: Ariadne Conill +Date: Sun, 7 Jul 2024 14:22:33 -0700 +Subject: [PATCH] security: Add openpax configuration menus + +Signed-off-by: Ariadne Conill + +xattr: add support for retrieving PaX flags stored in xattrs + +Signed-off-by: Ariadne Conill + +mm: add openpax flags, settable via atomics + +Signed-off-by: Ariadne Conill + +mman: enforce MPROTECT when enabled for a task + +Signed-off-by: Ariadne Conill + +elf: wire up setup for PaX flags + +Signed-off-by: Ariadne Conill + +security: openpax: add OPENPAX_SOFTMODE configuration knob + +This configuration knob enables OpenPaX soft mode, wherein OpenPaX features will +be disabled by default, with OpenPaX features only enforcing on binaries where +OpenPaX has been explicitly configured. + +Signed-off-by: Ariadne Conill + +documentation: add pax_softmode= to kernel parameters doc + +Signed-off-by: Ariadne Conill + +init: add pax_softmode= kernel command-line option + +Signed-off-by: Ariadne Conill + +sysctl: wire up PaX softmode setting + +Signed-off-by: Ariadne Conill + +elf: only enable PaX features by default if softmode is disabled + +Signed-off-by: Ariadne Conill + +elf: enable PAXF_RANDMMAP if randomize_va_space > 0 + +Signed-off-by: Ariadne Conill + +elf: use PAXF_RANDMMAP to control whether ASLR is enabled on a process + +Signed-off-by: Ariadne Conill + +elf: allow executable stacks if PAXF_EMUTRAMP is enabled + +Signed-off-by: Ariadne Conill + +proc: display PaX status in procfs status entries + +Signed-off-by: Ariadne Conill + +elf: only test for PAXF_RANDMMAP if OPENPAX is enabled + +Signed-off-by: Ariadne Conill + +security: add openpax EMUTRAMP config option + +Signed-off-by: Ariadne Conill + +elf: simplify executable stack logic + +Signed-off-by: Ariadne Conill + +x86: fault: add openpax_fault_is_trampoline to detect if a page-fault might be a trampoline + +Signed-off-by: Ariadne Conill + +x86: fault: add stack trampoline emulator + +Stack trampoline definitions were derived from the original PaX. + +Signed-off-by: Ariadne Conill + +x86: fault: hook up stack trampoline emulator + +Signed-off-by: Ariadne Conill + +security: openpax: add OPENPAX_EMUTRAMP_DEFAULT config option + +Signed-off-by: Ariadne Conill + +elf: enable EMUTRAMP by default if CONFIG_OPENPAX_EMUTRAMP_DEFAULT is enabled + +Signed-off-by: Ariadne Conill + +arm64: determine stack entropy based on mmap entropy + +Stack mapping entropy is currently hard-wired to 11 bits of entropy on +32-bit and 18 bits of entropy on 64-bit. The stack itself gains an extra +8 bits of entropy from lower bit randomization within 16 byte alignment +constraints. The argument block could have all lower bits randomized but +it currently only gets the mapping randomization. + +Rather than hard-wiring values this switches to using the mmap entropy +configuration like the mmap base and executable base, resulting in a +range of 8 to 16 bits on 32-bit and 18 to 24 bits on 64-bit (with 4k +pages and 3 level page tables) depending on kernel configuration and +overridable via the sysctl entries. + +It's worth noting that since these kernel configuration options default +to the minimum supported entropy value, the entropy on 32-bit will drop +from 11 to 8 bits for builds using the defaults. However, following the +configuration seems like the right thing to do regardless. At the very +least, changing the defaults for COMPAT (32-bit processes on 64-bit) +should be considered due to the larger address space compared to real +32-bit. + +Signed-off-by: Daniel Micay +Signed-off-by: Ariadne Conill + +x86: determine stack entropy based on mmap entropy + +Stack mapping entropy is currently hard-wired to 11 bits of entropy on +32-bit and 22 bits of entropy on 64-bit. The stack itself gains an extra +8 bits of entropy from lower bit randomization within 16 byte alignment +constraints. The argument block could have all lower bits randomized but +it currently only gets the mapping randomization. + +Rather than hard-wiring values this switches to using the mmap entropy +configuration like the mmap base and executable base, resulting in a +range of 8 to 16 bits on 32-bit and 28 to 32 bits on 64-bit depending on +kernel configuration and overridable via the sysctl entries. + +It's worth noting that since these kernel configuration options default +to the minimum supported entropy value, the entropy on 32-bit will drop +from 11 to 8 bits for builds using the defaults. However, following the +configuration seems like the right thing to do regardless. At the very +least, changing the defaults for COMPAT (32-bit processes on 64-bit) +should be considered due to the larger address space compared to real +32-bit. + +Signed-off-by: Daniel Micay +Signed-off-by: Ariadne Conill + +mmap: further improve randomization of brk(2) addresses + +This code mostly inspired by linux-hardened patch set. + +Signed-off-by: Ariadne Conill + +exec: randomize argument block location + +Signed-off-by: Ariadne Conill + +use maximum supported mmap rnd entropy by default + +Signed-off-by: Daniel Micay +Signed-off-by: Ariadne Conill + +elf: avoid double read of randomize_va_space in OpenPaX flag setup + +Previously we would read randomize_va_space in openpax_setup_flags, +and then again later after calling openpax_setup_flags. + +As randomize_va_space is a sysctl, its value can change at any time. +Accordingly, snapshot randomize_va_space before calling +openpax_set_flags and pass the snapshot value to openpax_set_flags. + +This resolves a minor race condition where one may be able to slightly +weaken process ASLR by turning ASLR on or off during an exec call. + +Signed-off-by: Ariadne Conill + +init: provide pax_softmode symbol unconditionally + +Otherwise we have to add a bunch of #ifdefs when we otherwise +would not need to. + +Fixes: a78588f6fc2f2 ("init: add pax_softmode= kernel command-line option") +Fixes: https://github.com/edera-dev/linux-openpax/issues/1 +Signed-off-by: Ariadne Conill +--- + .../admin-guide/kernel-parameters.txt | 3 + + arch/Kconfig | 4 +- + arch/arm64/include/asm/elf.h | 6 +- + arch/x86/include/asm/elf.h | 12 +- + arch/x86/kernel/process.c | 4 +- + arch/x86/mm/fault.c | 218 ++++++++++++++++++ + fs/binfmt_elf.c | 88 ++++++- + fs/proc/array.c | 15 ++ + fs/xattr.c | 16 ++ + include/linux/init.h | 1 + + include/linux/mm_types.h | 11 + + include/linux/xattr.h | 4 + + include/uapi/linux/xattr.h | 5 + + init/main.c | 11 + + kernel/sysctl.c | 15 ++ + mm/mmap.c | 7 + + mm/util.c | 4 +- + mm/vma.h | 11 +- + mm/vma_exec.c | 4 + + mm/vma_internal.h | 1 + + security/Kconfig | 1 + + security/Kconfig.openpax | 89 +++++++ + tools/testing/vma/include/dup.h | 3 + + tools/testing/vma/include/stubs.h | 5 + + tools/testing/vma/main.c | 1 + + 25 files changed, 523 insertions(+), 16 deletions(-) + create mode 100644 security/Kconfig.openpax + +diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt +index 33cd30996..0cf1f7afe 100644 +--- a/Documentation/admin-guide/kernel-parameters.txt ++++ b/Documentation/admin-guide/kernel-parameters.txt +@@ -5034,6 +5034,9 @@ Kernel parameters + the specified number of seconds. This is to be used if + your oopses keep scrolling off the screen. + ++ pax_softmode= ++ Enables OpenPaX soft mode if set to a non-zero value. ++ + pci=option[,option...] [PCI,EARLY] various PCI subsystem options. + + Some options herein operate on a specific device +diff --git a/arch/Kconfig b/arch/Kconfig +index 45c657772..4ea9fa84b 100644 +--- a/arch/Kconfig ++++ b/arch/Kconfig +@@ -1245,7 +1245,7 @@ config ARCH_MMAP_RND_BITS + int "Number of bits to use for ASLR of mmap base address" if EXPERT + range ARCH_MMAP_RND_BITS_MIN ARCH_MMAP_RND_BITS_MAX + default ARCH_MMAP_RND_BITS_DEFAULT if ARCH_MMAP_RND_BITS_DEFAULT +- default ARCH_MMAP_RND_BITS_MIN ++ default ARCH_MMAP_RND_BITS_MAX + depends on HAVE_ARCH_MMAP_RND_BITS + help + This value can be used to select the number of bits to use to +@@ -1279,7 +1279,7 @@ config ARCH_MMAP_RND_COMPAT_BITS + int "Number of bits to use for ASLR of mmap base address for compatible applications" if EXPERT + range ARCH_MMAP_RND_COMPAT_BITS_MIN ARCH_MMAP_RND_COMPAT_BITS_MAX + default ARCH_MMAP_RND_COMPAT_BITS_DEFAULT if ARCH_MMAP_RND_COMPAT_BITS_DEFAULT +- default ARCH_MMAP_RND_COMPAT_BITS_MIN ++ default ARCH_MMAP_RND_COMPAT_BITS_MAX + depends on HAVE_ARCH_MMAP_RND_COMPAT_BITS + help + This value can be used to select the number of bits to use to +diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h +index d2779d604..1265a425f 100644 +--- a/arch/arm64/include/asm/elf.h ++++ b/arch/arm64/include/asm/elf.h +@@ -189,10 +189,10 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, + /* 1GB of VA */ + #ifdef CONFIG_COMPAT + #define STACK_RND_MASK (test_thread_flag(TIF_32BIT) ? \ +- 0x7ff >> (PAGE_SHIFT - 12) : \ +- 0x3ffff >> (PAGE_SHIFT - 12)) ++ ((1UL << mmap_rnd_compat_bits) - 1) >> (PAGE_SHIFT - 12) : \ ++ ((1UL << mmap_rnd_bits) - 1) >> (PAGE_SHIFT - 12)) + #else +-#define STACK_RND_MASK (0x3ffff >> (PAGE_SHIFT - 12)) ++#define STACK_RND_MASK (((1UL << mmap_rnd_bits) - 1) >> (PAGE_SHIFT - 12)) + #endif + + #ifdef __AARCH64EB__ +diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h +index 4133c790e..e23e07853 100644 +--- a/arch/x86/include/asm/elf.h ++++ b/arch/x86/include/asm/elf.h +@@ -313,8 +313,8 @@ extern unsigned long get_sigframe_size(void); + + #ifdef CONFIG_X86_32 + +-#define __STACK_RND_MASK(is32bit) (0x7ff) +-#define STACK_RND_MASK (0x7ff) ++#define __STACK_RND_MASK(is32bit) ((1UL << mmap_rnd_bits) - 1) ++#define STACK_RND_MASK ((1UL << mmap_rnd_bits) - 1) + + #define ARCH_DLINFO ARCH_DLINFO_IA32 + +@@ -322,8 +322,12 @@ extern unsigned long get_sigframe_size(void); + + #else /* CONFIG_X86_32 */ + +-/* 16GB for 64bit, 8MB for 32bit */ +-#define __STACK_RND_MASK(is32bit) ((is32bit) ? 0x7ff : 0x3fffff) ++/* 1GB for 64bit, 8MB for 32bit */ ++#ifdef CONFIG_COMPAT ++#define __STACK_RND_MASK(is32bit) ((is32bit) ? (1UL << mmap_rnd_compat_bits) - 1 : (1UL << mmap_rnd_bits) - 1) ++#else ++#define __STACK_RND_MASK(is32bit) ((1UL << mmap_rnd_bits) - 1) ++#endif + #define STACK_RND_MASK __STACK_RND_MASK(mmap_is_ia32()) + + #define ARCH_DLINFO \ +diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c +index 346c438ac..26f884f70 100644 +--- a/arch/x86/kernel/process.c ++++ b/arch/x86/kernel/process.c +@@ -1027,9 +1027,9 @@ unsigned long arch_align_stack(unsigned long sp) + unsigned long arch_randomize_brk(struct mm_struct *mm) + { + if (mmap_is_ia32()) +- return randomize_page(mm->brk, SZ_32M); ++ return mm->brk + get_random_long() % SZ_32M + PAGE_SIZE; + +- return randomize_page(mm->brk, SZ_1G); ++ return mm->brk + get_random_long() % SZ_1G + PAGE_SIZE; + } + + /* +diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c +index aa88370ce..7ac4eaae0 100644 +--- a/arch/x86/mm/fault.c ++++ b/arch/x86/mm/fault.c +@@ -1204,6 +1204,217 @@ do_kern_addr_fault(struct pt_regs *regs, unsigned long hw_error_code, + } + NOKPROBE_SYMBOL(do_kern_addr_fault); + ++#ifdef CONFIG_OPENPAX_EMUTRAMP ++/* ++ * Determine if a fault is possibly caused by an emulatable stack or ++ * heap trampoline. We return false if trampoline emulation is not ++ * enabled. ++ */ ++static inline ++bool openpax_fault_is_trampoline(unsigned long error_code, ++ struct pt_regs *regs, ++ unsigned long address) ++{ ++ struct mm_struct *mm = current->mm; ++ unsigned long ip = regs->ip; ++ ++ if (!test_bit(PAXF_EMUTRAMP, &mm->pax_flags)) ++ return false; ++ ++ if (v8086_mode(regs)) ++ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff); ++ ++ if (test_bit(PAXF_PAGEEXEC, &mm->pax_flags)) { ++ if ((__supported_pte_mask & _PAGE_NX) && (error_code & X86_PF_INSTR)) ++ return true; ++ if (!(error_code & (X86_PF_PROT | X86_PF_WRITE)) && ip == address) ++ return true; ++ return false; ++ } ++ ++ return false; ++} ++NOKPROBE_SYMBOL(openpax_fault_is_trampoline); ++ ++static inline ++bool openpax_emulate_trampoline_32(struct pt_regs *regs) ++{ ++ int err; ++ ++ /* libffi trampoline type 1, gcc trampoline type 2 */ ++ do { ++ unsigned char mov, jmp; ++ unsigned int addr1, addr2; ++ ++#ifdef CONFIG_X86_64 ++ if ((regs->ip + 9) >> 32) ++ break; ++#endif ++ ++ err = get_user(mov, (unsigned char __user *) regs->ip); ++ err |= get_user(addr1, (unsigned int __user *) (regs->ip + 1)); ++ err |= get_user(jmp, (unsigned char __user *) (regs->ip + 5)); ++ err |= get_user(addr2, (unsigned int __user *) (regs->ip + 6)); ++ ++ if (err) ++ break; ++ ++ if ((mov == 0xB8 || mov == 0xB9) && jmp == 0xE9) { ++ if (mov == 0xB8) ++ regs->ax = addr1; ++ else ++ regs->cx = addr1; ++ ++ regs->ip = (unsigned int)(regs->ip + addr2 + 10); ++ return true; ++ } ++ } while (0); ++ ++ /* older gcc trampoline type... */ ++ do { ++ unsigned char mov1, mov2; ++ unsigned short jmp; ++ unsigned int addr1, addr2; ++ ++#ifdef CONFIG_X86_64 ++ if ((regs->ip + 11) >> 32) ++ break; ++#endif ++ ++ err = get_user(mov1, (unsigned char __user *) regs->ip); ++ err |= get_user(addr1, (unsigned int __user *) (regs->ip + 1)); ++ err |= get_user(mov2, (unsigned char __user *) (regs->ip + 5)); ++ err |= get_user(addr2, (unsigned int __user *) (regs->ip + 6)); ++ err |= get_user(jmp, (unsigned short __user *) (regs->ip + 10)); ++ ++ if (err) ++ break; ++ ++ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) { ++ regs->cx = addr1; ++ regs->ax = addr2; ++ regs->ip = addr2; ++ return true; ++ } ++ } while (0); ++ ++ return false; ++} ++NOKPROBE_SYMBOL(openpax_emulate_trampoline_32); ++ ++#ifdef CONFIG_X86_64 ++static inline ++bool openpax_emulate_trampoline_64(struct pt_regs *regs) ++{ ++ int err; ++ ++ /* libffi trampoline type 1 */ ++ do { ++ unsigned short mov1, mov2, jmp1; ++ unsigned char stcclc, jmp2; ++ unsigned long addr1, addr2; ++ ++ err = get_user(mov1, (unsigned short __user *) regs->ip); ++ err |= get_user(addr1, (unsigned long __user *) (regs->ip + 2)); ++ err |= get_user(mov2, (unsigned short __user *) (regs->ip + 10)); ++ err |= get_user(addr2, (unsigned long __user *) (regs->ip + 12)); ++ err |= get_user(stcclc, (unsigned char __user *) (regs->ip + 20)); ++ err |= get_user(jmp1, (unsigned short __user *) (regs->ip + 21)); ++ err |= get_user(jmp2, (unsigned char __user *) (regs->ip + 23)); ++ ++ if (err) ++ break; ++ ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) { ++ regs->r11 = addr1; ++ regs->r10 = addr2; ++ ++ if (stcclc == 0xF8) ++ regs->flags &= ~X86_EFLAGS_CF; ++ else ++ regs->flags |= X86_EFLAGS_CF; ++ ++ regs->ip = addr1; ++ return true; ++ } ++ } while (0); ++ ++ /* gcc trampoline type 1 */ ++ do { ++ unsigned short mov1, mov2, jmp1; ++ unsigned char jmp2; ++ unsigned int addr1; ++ unsigned long addr2; ++ ++ err = get_user(mov1, (unsigned short __user *) regs->ip); ++ err |= get_user(addr1, (unsigned int __user *) (regs->ip + 2)); ++ err |= get_user(mov2, (unsigned short __user *) (regs->ip + 6)); ++ err |= get_user(addr2, (unsigned long __user *) (regs->ip + 8)); ++ err |= get_user(jmp1, (unsigned short __user *) (regs->ip + 16)); ++ err |= get_user(jmp2, (unsigned char __user *) (regs->ip + 18)); ++ ++ if (err) ++ break; ++ ++ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) { ++ regs->r11 = addr1; ++ regs->r10 = addr2; ++ regs->ip = addr1; ++ return true; ++ } ++ } while (0); ++ ++ /* gcc trampoline type 2 */ ++ do { ++ unsigned short mov1, mov2, jmp1; ++ unsigned char jmp2; ++ unsigned long addr1, addr2; ++ ++ err = get_user(mov1, (unsigned short __user *) regs->ip); ++ err |= get_user(addr1, (unsigned long __user *) (regs->ip + 2)); ++ err |= get_user(mov2, (unsigned short __user *) (regs->ip + 10)); ++ err |= get_user(addr2, (unsigned long __user *) (regs->ip + 12)); ++ err |= get_user(jmp1, (unsigned short __user *) (regs->ip + 20)); ++ err |= get_user(jmp2, (unsigned char __user *) (regs->ip + 22)); ++ ++ if (err) ++ break; ++ ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) { ++ regs->r11 = addr1; ++ regs->r10 = addr2; ++ regs->ip = addr1; ++ return true; ++ } ++ } while (0); ++ ++ return false; ++} ++NOKPROBE_SYMBOL(openpax_emulate_trampoline_64); ++#endif ++ ++/* ++ * Emulate a trampoline. Returns false if emulation failed, meaning ++ * that the task should be killed. ++ */ ++static inline ++bool openpax_emulate_trampoline(struct pt_regs *regs) ++{ ++ if (v8086_mode(regs)) ++ return false; ++ ++ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) ++ return openpax_emulate_trampoline_32(regs); ++#ifdef CONFIG_X86_64 ++ else ++ return openpax_emulate_trampoline_64(regs); ++#endif ++ ++ return false; ++} ++NOKPROBE_SYMBOL(openpax_emulate_trampoline); ++#endif ++ + /* + * Handle faults in the user portion of the address space. Nothing in here + * should check X86_PF_USER without a specific justification: for almost +@@ -1328,6 +1539,13 @@ void do_user_addr_fault(struct pt_regs *regs, + } + #endif + ++#ifdef CONFIG_OPENPAX_EMUTRAMP ++ if (openpax_fault_is_trampoline(error_code, regs, address)) { ++ if (openpax_emulate_trampoline(regs)) ++ return; ++ } ++#endif ++ + if (!(flags & FAULT_FLAG_USER)) + goto lock_mmap; + +diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c +index 06d0df105..84d7a2ecb 100644 +--- a/fs/binfmt_elf.c ++++ b/fs/binfmt_elf.c +@@ -48,6 +48,7 @@ + #include + #include + #include ++#include + #include + #include + +@@ -826,6 +827,72 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr, + return ret == -ENOENT ? 0 : ret; + } + ++#ifdef CONFIG_OPENPAX ++#ifdef CONFIG_OPENPAX_XATTR_PAX_FLAGS ++static int openpax_parse_xattr_flags(struct file * const file) ++{ ++ ssize_t xattr_size, i; ++ unsigned char xattr_value[sizeof("pemrs") - 1]; ++ ++ xattr_size = pax_getxattr(file, xattr_value, sizeof xattr_value); ++ if (xattr_size < 0 || xattr_size > sizeof xattr_value) ++ return -ENOENT; ++ ++ for (i = 0; i < xattr_size; i++) ++ switch (xattr_value[i]) { ++ default: ++ return -EINVAL; ++ ++#define parse_flag(option_disable, option_enable, flag) \ ++ case option_disable: \ ++ clear_bit(flag, ¤t->mm->pax_flags); \ ++ break; \ ++ case option_enable: \ ++ set_bit(flag, ¤t->mm->pax_flags); \ ++ break; ++ ++ parse_flag('p', 'P', PAXF_PAGEEXEC); ++ parse_flag('e', 'E', PAXF_EMUTRAMP); ++ parse_flag('m', 'M', PAXF_MPROTECT); ++ parse_flag('r', 'R', PAXF_RANDMMAP); ++ parse_flag('s', 'S', PAXF_SEGMEXEC); ++#undef parse_flag ++ } ++ ++ return 0; ++} ++#endif ++ ++static int openpax_set_flags(struct file * const file, const int snapshot_randomize_va_space) ++{ ++#ifdef CONFIG_OPENPAX_XATTR_PAX_FLAGS ++ int error; ++#endif ++ current->mm->pax_flags = 0; ++ ++ if (snapshot_randomize_va_space) { ++ set_bit(PAXF_RANDMMAP, ¤t->mm->pax_flags); ++ } ++ ++ if (!pax_softmode) { ++ set_bit(PAXF_PAGEEXEC, ¤t->mm->pax_flags); ++ set_bit(PAXF_MPROTECT, ¤t->mm->pax_flags); ++ } ++ ++#ifdef CONFIG_OPENPAX_EMUTRAMP_DEFAULT ++ set_bit(PAXF_EMUTRAMP, ¤t->mm->pax_flags); ++#endif ++ ++#ifdef CONFIG_OPENPAX_XATTR_PAX_FLAGS ++ error = openpax_parse_xattr_flags(file); ++ if (error != -ENOENT) ++ return error; ++#endif ++ ++ return 0; ++} ++#endif ++ + static int load_elf_binary(struct linux_binprm *bprm) + { + struct file *interpreter = NULL; /* to shut gcc up */ +@@ -1014,11 +1081,28 @@ static int load_elf_binary(struct linux_binprm *bprm) + /* Do this immediately, since STACK_TOP as used in setup_arg_pages + may depend on the personality. */ + SET_PERSONALITY2(*elf_ex, &arch_state); ++ ++ const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space); ++ ++#ifdef CONFIG_OPENPAX ++ retval = openpax_set_flags(bprm->file, snapshot_randomize_va_space); ++ if (retval) ++ goto out_free_dentry; ++ ++ if (test_bit(PAXF_PAGEEXEC, ¤t->mm->pax_flags) || test_bit(PAXF_SEGMEXEC, ¤t->mm->pax_flags)) { ++ executable_stack = EXSTACK_DISABLE_X; ++ current->personality &= ~READ_IMPLIES_EXEC; ++ } else ++#endif ++ + if (elf_read_implies_exec(*elf_ex, executable_stack)) + current->personality |= READ_IMPLIES_EXEC; + +- const int snapshot_randomize_va_space = READ_ONCE(randomize_va_space); +- if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space) ++ if (!(current->personality & ADDR_NO_RANDOMIZE) && snapshot_randomize_va_space ++#ifdef CONFIG_OPENPAX ++ && test_bit(PAXF_RANDMMAP, ¤t->mm->pax_flags) ++#endif ++ ) + current->flags |= PF_RANDOMIZE; + + setup_new_exec(bprm); +diff --git a/fs/proc/array.c b/fs/proc/array.c +index f6f75d206..4643cc1b2 100644 +--- a/fs/proc/array.c ++++ b/fs/proc/array.c +@@ -435,6 +435,18 @@ __weak void arch_proc_pid_thread_features(struct seq_file *m, + { + } + ++#ifdef CONFIG_OPENPAX ++static inline void task_pax(struct seq_file *m, struct mm_struct *mm) ++{ ++ seq_printf(m, "PaX:\t%c%c%c%c%c\n", ++ test_bit(PAXF_PAGEEXEC, &mm->pax_flags) ? 'P' : 'p', ++ test_bit(PAXF_EMUTRAMP, &mm->pax_flags) ? 'E' : 'e', ++ test_bit(PAXF_MPROTECT, &mm->pax_flags) ? 'M' : 'm', ++ test_bit(PAXF_RANDMMAP, &mm->pax_flags) ? 'R' : 'r', ++ test_bit(PAXF_SEGMEXEC, &mm->pax_flags) ? 'S' : 's'); ++} ++#endif ++ + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, + struct pid *pid, struct task_struct *task) + { +@@ -451,6 +463,9 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, + task_core_dumping(m, task); + task_thp_status(m, mm); + task_untag_mask(m, mm); ++#ifdef CONFIG_OPENPAX ++ task_pax(m, mm); ++#endif + mmput(mm); + } + task_sig(m, task); +diff --git a/fs/xattr.c b/fs/xattr.c +index d58979115..74ed47182 100644 +--- a/fs/xattr.c ++++ b/fs/xattr.c +@@ -447,6 +447,22 @@ __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name, + } + EXPORT_SYMBOL(__vfs_getxattr); + ++#ifdef CONFIG_OPENPAX_XATTR_PAX_FLAGS ++ssize_t ++pax_getxattr(struct file *file, void *value, size_t size) ++{ ++ struct inode *inode = file->f_path.dentry->d_inode; ++ ssize_t error; ++ ++ error = inode_permission(file_mnt_idmap(file), inode, MAY_EXEC); ++ if (error) ++ return error; ++ ++ return __vfs_getxattr(file->f_path.dentry, inode, XATTR_NAME_USER_PAX_FLAGS, value, size); ++} ++EXPORT_SYMBOL(pax_getxattr); ++#endif ++ + ssize_t + vfs_getxattr(struct mnt_idmap *idmap, struct dentry *dentry, + const char *name, void *value, size_t size) +diff --git a/include/linux/init.h b/include/linux/init.h +index 6326c61e2..89999a156 100644 +--- a/include/linux/init.h ++++ b/include/linux/init.h +@@ -138,6 +138,7 @@ extern char __initdata boot_command_line[]; + extern char *saved_command_line; + extern unsigned int saved_command_line_len; + extern unsigned int reset_devices; ++extern int pax_softmode; + + /* used by init/main.c */ + void setup_arch(char **); +diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h +index 6d815f644..159659519 100644 +--- a/include/linux/mm_types.h ++++ b/include/linux/mm_types.h +@@ -1320,6 +1320,9 @@ struct mm_struct { + mm_context_t context; + + mm_flags_t flags; /* Must use mm_flags_* hlpers to access */ ++#ifdef CONFIG_OPENPAX ++ unsigned long pax_flags; ++#endif + + #ifdef CONFIG_AIO + spinlock_t ioctx_lock; +@@ -2016,4 +2019,12 @@ static inline unsigned long mmf_init_legacy_flags(unsigned long flags) + return flags & MMF_INIT_LEGACY_MASK; + } + ++#ifdef CONFIG_OPENPAX ++#define PAXF_PAGEEXEC 1 ++#define PAXF_EMUTRAMP 2 ++#define PAXF_MPROTECT 3 ++#define PAXF_RANDMMAP 4 ++#define PAXF_SEGMEXEC 5 ++#endif ++ + #endif /* _LINUX_MM_TYPES_H */ +diff --git a/include/linux/xattr.h b/include/linux/xattr.h +index 54ac3cbc1..add6707db 100644 +--- a/include/linux/xattr.h ++++ b/include/linux/xattr.h +@@ -26,6 +26,7 @@ + + struct inode; + struct dentry; ++struct file; + + static inline bool is_posix_acl_xattr(const char *name) + { +@@ -76,6 +77,9 @@ struct xattr { + size_t value_len; + }; + ++#ifdef CONFIG_OPENPAX_XATTR_PAX_FLAGS ++ssize_t pax_getxattr(struct file *, void *, size_t); ++#endif + ssize_t __vfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t); + ssize_t vfs_getxattr(struct mnt_idmap *, struct dentry *, const char *, + void *, size_t); +diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h +index 2e5aef48f..8832f1d9d 100644 +--- a/include/uapi/linux/xattr.h ++++ b/include/uapi/linux/xattr.h +@@ -92,5 +92,10 @@ struct xattr_args { + #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default" + #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT + ++/* User namespace */ ++#define XATTR_PAX_PREFIX "pax." ++#define XATTR_PAX_FLAGS_SUFFIX "flags" ++#define XATTR_NAME_USER_PAX_FLAGS XATTR_USER_PREFIX XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX ++#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX + + #endif /* _UAPI_LINUX_XATTR_H */ +diff --git a/init/main.c b/init/main.c +index 31f2bf549..80e9a015c 100644 +--- a/init/main.c ++++ b/init/main.c +@@ -195,6 +195,17 @@ static int __init set_reset_devices(char *str) + + __setup("reset_devices", set_reset_devices); + ++int pax_softmode; ++ ++#ifdef CONFIG_OPENPAX_SOFTMODE ++static int __init setup_pax_softmode(char *str) ++{ ++ get_option(&str, &pax_softmode); ++ return 1; ++} ++__setup("pax_softmode=", setup_pax_softmode); ++#endif ++ + static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, }; + const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, }; + static const char *panic_later, *panic_param; +diff --git a/kernel/sysctl.c b/kernel/sysctl.c +index f7b75985d..f5c9b9cd0 100644 +--- a/kernel/sysctl.c ++++ b/kernel/sysctl.c +@@ -1397,6 +1397,18 @@ int proc_do_static_key(const struct ctl_table *table, int dir, + return ret; + } + ++#ifdef CONFIG_OPENPAX_SOFTMODE ++static const struct ctl_table pax_table[] = { ++ { ++ .procname = "softmode", ++ .data = &pax_softmode, ++ .maxlen = sizeof(int), ++ .mode = 0600, ++ .proc_handler = proc_dointvec, ++ }, ++}; ++#endif ++ + static const struct ctl_table sysctl_subsys_table[] = { + #ifdef CONFIG_SYSCTL + { +@@ -1446,6 +1458,9 @@ static const struct ctl_table sysctl_subsys_table[] = { + int __init sysctl_init_bases(void) + { + register_sysctl_init("kernel", sysctl_subsys_table); ++#ifdef CONFIG_OPENPAX_SOFTMODE ++ register_sysctl_init("kernel/pax", pax_table); ++#endif + + return 0; + } +diff --git a/mm/mmap.c b/mm/mmap.c +index 4bf26b0f1..9caa66ca7 100644 +--- a/mm/mmap.c ++++ b/mm/mmap.c +@@ -154,6 +154,13 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) + + newbrk = PAGE_ALIGN(brk); + oldbrk = PAGE_ALIGN(mm->brk); ++ /* properly handle unaligned min_brk as an empty heap */ ++ if (min_brk & ~PAGE_MASK) { ++ if (brk == min_brk) ++ newbrk -= PAGE_SIZE; ++ if (mm->brk == min_brk) ++ oldbrk -= PAGE_SIZE; ++ } + if (oldbrk == newbrk) { + mm->brk = brk; + goto success; +diff --git a/mm/util.c b/mm/util.c +index bf0513d1d..c9d134c18 100644 +--- a/mm/util.c ++++ b/mm/util.c +@@ -391,9 +391,9 @@ unsigned long __weak arch_randomize_brk(struct mm_struct *mm) + { + /* Is the current task 32bit ? */ + if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task()) +- return randomize_page(mm->brk, SZ_32M); ++ return mm->brk + get_random_long() % SZ_32M + PAGE_SIZE; + +- return randomize_page(mm->brk, SZ_1G); ++ return mm->brk + get_random_long() % SZ_1G + PAGE_SIZE; + } + + unsigned long arch_mmap_rnd(void) +diff --git a/mm/vma.h b/mm/vma.h +index 024fabe63..cfff3a195 100644 +--- a/mm/vma.h ++++ b/mm/vma.h +@@ -817,13 +817,22 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift); + * we propose to set. + * + * Return: false if proposed change is OK, true if not ok and should be denied. ++ * ++ * Note: If OpenPaX is enabled, it will be assumed that we want to deny ++ * PROT_WRITE | PROT_EXEC by default, unless the MPROTECT feature bit is ++ * disabled on a binary. + */ + static inline bool map_deny_write_exec(const vma_flags_t *old, + const vma_flags_t *new) + { + /* If MDWE is disabled, we have nothing to deny. */ +- if (!mm_flags_test(MMF_HAS_MDWE, current->mm)) ++ if ( ++#ifdef CONFIG_OPENPAX_MPROTECT ++ !test_bit(PAXF_MPROTECT, ¤t->mm->pax_flags) && ++#endif ++ !mm_flags_test(MMF_HAS_MDWE, current->mm)) { + return false; ++ } + + /* If the new VMA is not executable, we have nothing to deny. */ + if (!vma_flags_test(new, VMA_EXEC_BIT)) +diff --git a/mm/vma_exec.c b/mm/vma_exec.c +index 586c52155..4fd518010 100644 +--- a/mm/vma_exec.c ++++ b/mm/vma_exec.c +@@ -160,6 +160,10 @@ int create_init_stack_vma(struct mm_struct *mm, struct vm_area_struct **vmap, + mmap_write_unlock(mm); + *vmap = vma; + *top_mem_p = vma->vm_end - sizeof(void *); ++ ++ if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) ++ *top_mem_p ^= get_random_u32() & ~PAGE_MASK; ++ + return 0; + + err: +diff --git a/mm/vma_internal.h b/mm/vma_internal.h +index 4d300e7bb..816e120cf 100644 +--- a/mm/vma_internal.h ++++ b/mm/vma_internal.h +@@ -37,6 +37,7 @@ + #include + #include + #include ++#include + #include + #include + #include +diff --git a/security/Kconfig b/security/Kconfig +index f7bf6cdc6..4714274a5 100644 +--- a/security/Kconfig ++++ b/security/Kconfig +@@ -300,6 +300,7 @@ config SECURITY_COMMONCAP_KUNIT_TEST + If unsure, say N. + + source "security/Kconfig.hardening" ++source "security/Kconfig.openpax" + + endmenu + +diff --git a/security/Kconfig.openpax b/security/Kconfig.openpax +new file mode 100644 +index 000000000..76ee14509 +--- /dev/null ++++ b/security/Kconfig.openpax +@@ -0,0 +1,89 @@ ++# ++# OpenPaX configuration ++# ++ ++menu "OpenPaX options" ++ ++config OPENPAX ++ bool "Enable OpenPaX features" ++ default y ++ help ++ This configuration setting enables OpenPaX features. ++ OpenPaX adds memory safety-related defenses to the kernel which ++ reduce the risks posed by exploitable memory safety bugs. ++ ++config OPENPAX_SOFTMODE ++ bool "Support PaX soft mode" ++ default y ++ help ++ Enabling this option will allow you to configure OpenPaX ++ features to run in soft mode. In this mode, OpenPaX features ++ will be disabled by default, only running on applications ++ which explicitly enable them. ++ ++ Soft mode can be enabled via the kernel.pax.softmode sysctl, ++ or the pax_softmode=1 kernel command-line option. ++ ++config OPENPAX_XATTR_PAX_FLAGS ++ bool "Use filesystem extended attributes to modify OpenPaX features" ++ depends on OPENPAX ++ default y ++ help ++ Enabling this option will allow you to control whether ++ OpenPaX features are enabled on a per-executable basis via ++ xattr attributes. ++ ++ For compatibility with the original PaX patch, the feature ++ flags are read from the user.pax.flags extended attribute. ++ ++ If you disable this feature, then all applications will run ++ with OpenPaX enabled by default. ++ ++config OPENPAX_MPROTECT ++ bool "Enforce W^X for memory mappings" ++ depends on OPENPAX ++ default y ++ help ++ Enabling this option prevents programs from making pages ++ executable when they are also writable. In addition, it ++ also denies transition of writable mappings to executable ++ mappings. ++ ++ This feature is known to break programs which depend on ++ just-in-time (JIT) compilation. It is advisable to enable ++ this feature system-wide, but mark programs which have ++ JIT compilation appropriately so the W^X enforcement is ++ disabled for them. ++ ++config OPENPAX_EMUTRAMP ++ bool "Emulate stack and heap trampolines" ++ depends on OPENPAX ++ default y ++ help ++ Enabling this option allows programs to depend on common ++ types of stack and heap trampolines (such as the ones ++ generated by GCC and libffi) to continue working despite ++ the stack and heap being non-executable memory. ++ ++ This option works by intercepting the page faults caused ++ by executing code in non-executable memory and emulating ++ the side effects that would have happened from executing ++ the trampoline. ++ ++ Most likely, you should say 'y' here. ++ ++config OPENPAX_EMUTRAMP_DEFAULT ++ bool "Enable trampoline emulation by default" ++ depends on OPENPAX_EMUTRAMP ++ default y ++ help ++ Enabling this option allows programs which require ++ trampolines to be emulated to continue working by default. ++ ++ Otherwise, the emulation flag must be enabled in a binary's ++ PaX marking, e.g. with paxmark -E . ++ ++ If you do not say 'y' here, you will have to manually mark ++ all programs which require trampoline emulation. ++ ++endmenu +diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h +index 4c58487b7..f89d5d4c0 100644 +--- a/tools/testing/vma/include/dup.h ++++ b/tools/testing/vma/include/dup.h +@@ -418,8 +418,11 @@ enum { + */ + enum { + READ_IMPLIES_EXEC = 0x0400000, ++ ADDR_NO_RANDOMIZE = 0x0040000, + }; + ++extern int randomize_va_space; ++ + struct vma_iterator { + struct ma_state mas; + }; +diff --git a/tools/testing/vma/include/stubs.h b/tools/testing/vma/include/stubs.h +index d6136e19a..2ca910a7c 100644 +--- a/tools/testing/vma/include/stubs.h ++++ b/tools/testing/vma/include/stubs.h +@@ -27,6 +27,11 @@ struct unmap_desc; + + #define vma_policy(vma) NULL + ++static inline u32 get_random_u32(void) ++{ ++ return 0; ++} ++ + #define down_write_nest_lock(sem, nest_lock) + + #define data_race(expr) expr +diff --git a/tools/testing/vma/main.c b/tools/testing/vma/main.c +index 18338f5d2..381b9fb97 100644 +--- a/tools/testing/vma/main.c ++++ b/tools/testing/vma/main.c +@@ -15,6 +15,7 @@ + #include "tests/vma.c" + + int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT; ++int randomize_va_space = 2; + + /* Helper functions which utilise static kernel functions. */ + +-- +2.56.1 + diff --git a/patches/add-spectre-patch.patch b/spec-patches/add-secureblue-patches.patch similarity index 54% rename from patches/add-spectre-patch.patch rename to spec-patches/add-secureblue-patches.patch index 4d59d7b..6f783a1 100644 --- a/patches/add-spectre-patch.patch +++ b/spec-patches/add-secureblue-patches.patch @@ -2,23 +2,28 @@ # # SPDX-License-Identifier: MIT +diff --git a/kernel.spec b/kernel.spec +index 9c0ef4637..8fbcc4d74 100644 --- a/kernel.spec +++ b/kernel.spec -@@ -1216,6 +1216,8 @@ +@@ -1180,6 +1180,9 @@ Source4002: gating.yaml Patch1: patch-%{patchversion}-redhat.patch %endif - -+Patch999998: correct-spectre-flag-behavior.patch + ++Patch80001: secureblue-openpax.patch ++Patch999998: secureblue-correct-spectre-flag-behavior.patch + # empty final patch to facilitate testing of kernel patches Patch999999: linux-kernel-test.patch - -@@ -2192,6 +2194,8 @@ + +@@ -2106,6 +2109,10 @@ cp -a %{SOURCE1} . ApplyOptionalPatch patch-%{patchversion}-redhat.patch %endif - -+ApplyPatch correct-spectre-flag-behavior.patch + ++for patch_file in "${RPM_SOURCE_DIR}"/secureblue-*.patch; do ++ ApplyPatch "${patch_file##*/}" ++done + ApplyOptionalPatch linux-kernel-test.patch - + %{log_msg "End of patch applications"} diff --git a/patches/trusted-keys.patch b/spec-patches/trusted-keys.patch similarity index 79% rename from patches/trusted-keys.patch rename to spec-patches/trusted-keys.patch index 1ea8551..92c0d55 100644 --- a/patches/trusted-keys.patch +++ b/spec-patches/trusted-keys.patch @@ -3,10 +3,10 @@ # SPDX-License-Identifier: MIT diff --git a/kernel.spec b/kernel.spec -index 2e03403..59594fe 100644 +index 9c0ef4637..f91089430 100644 --- a/kernel.spec +++ b/kernel.spec -@@ -1214,6 +1214,7 @@ Source3002: Patchlist.changelog +@@ -1172,6 +1172,7 @@ Source3002: Patchlist.changelog Source4000: README.rst Source4001: rpminspect.yaml Source4002: gating.yaml @@ -14,7 +14,7 @@ index 2e03403..59594fe 100644 ## Patches needed for building this package -@@ -2313,6 +2314,7 @@ cat secureboot.pem >> ../certs/rhel.pem +@@ -2236,6 +2237,7 @@ cat secureboot.pem >> ../certs/rhel.pem openssl x509 -inform der -in %{ima_ca_cert} -out imaca.pem cat imaca.pem >> ../certs/rhel.pem diff --git a/srpm_script.sh b/srpm_script.sh index eac4151..b747281 100644 --- a/srpm_script.sh +++ b/srpm_script.sh @@ -54,6 +54,14 @@ configs_to_enable=( # Sanity checks on notifier call chains, slight perf hit # in exchange for reduced kernel panics/oopses and dangling pointers CONFIG_DEBUG_NOTIFIERS + + # Enable OpenPaX features. For details, see patches/openpax. + CONFIG_OPENPAX + CONFIG_OPENPAX_SOFTMODE + CONFIG_OPENPAX_XATTR_PAX_FLAGS + CONFIG_OPENPAX_MPROTECT + CONFIG_OPENPAX_EMUTRAMP + CONFIG_OPENPAX_EMUTRAMP_DEFAULT ) configs_to_disable=( @@ -122,7 +130,6 @@ configs_to_disable=( # Don't autoload line disciplines, already set by our sysctl CONFIG_LDISC_AUTOLOAD - ############################################################ ####### Features for mobile carriers / datacenters ######### ############################################################ @@ -140,8 +147,8 @@ configs_to_disable=( # https://cateee.net/lkddb/web-lkddb/AF_KCM.html # Kernel Connection Multiplexor - # Has been the source of CVEs, appears to have little to no use outside of - # datacenter applications. + # Has been the source of CVEs, appears to have little to no use outside of + # datacenter applications. CONFIG_AF_KCM # https://www.kernelconfig.io/CONFIG_BAREUDP @@ -332,7 +339,6 @@ configs_to_disable=( # Enables Firewire debugging over remote DMA CONFIG_PROVIDE_OHCI1394_DMA_INIT - ############################################################ ################# Unused ports and devices ################# ############################################################ @@ -421,7 +427,6 @@ configs_to_disable=( # Enable support for GPIB cards and dongles. CONFIG_GPIB - ############################################################ ################# Attack surface reduction ################# ############################################################ @@ -430,7 +435,7 @@ configs_to_disable=( CONFIG_DEVPORT # https://cateee.net/lkddb/web-lkddb/LIVEPATCH.html - # Attack surface, not useful with bootc + # Attack surface, not useful with bootc CONFIG_LIVEPATCH # https://cateee.net/lkddb/web-lkddb/X86_IOPL_IOPERM.html @@ -449,7 +454,7 @@ configs_to_disable=( # https://www.kernelconfig.io/CONFIG_DEVMEM # Provides support for the /dev/mem device, which can RW directly to memory CONFIG_DEVMEM - + # https://cateee.net/lkddb/web-lkddb/STRICT_DEVMEM.html # https://cateee.net/lkddb/web-lkddb/IO_STRICT_DEVMEM.html # Fedora enables these but they depends on devmem, which we disable, so we must disable them too @@ -538,7 +543,7 @@ configs_to_disable=( CONFIG_PARPORT # Legacy game port support - # And all joystick modules aside from xpad + # And all joystick modules aside from xpad # https://cateee.net/lkddb/web-lkddb/GAMEPORT.html # Already blocked at runtime: https://github.com/secureblue/secureblue/blob/live/files/system/usr/lib/modprobe.d/secureblue.conf#L195 CONFIG_GAMEPORT @@ -580,11 +585,11 @@ configs_to_disable=( ) for config_to_disable in "${configs_to_disable[@]}"; do - echo "# ${config_to_disable} is not set" >> kernel-local + echo "# ${config_to_disable} is not set" >>kernel-local done for config_to_enable in "${configs_to_enable[@]}"; do - echo "${config_to_enable}=y" >> kernel-local + echo "${config_to_enable}=y" >>kernel-local done sed --sandbox -i \ @@ -594,10 +599,12 @@ sed --sandbox -i \ # Merge trusted-keys/* into secureblue-certs.pem. This gets appended to # certs/rhel.pem alongside Fedora's keys (see trusted-keys.patch), so they # all end up in CONFIG_SYSTEM_TRUSTED_KEYS and thus .builtin_trusted_keys. -cat "${script_dir}"/trusted-keys/*.pem > secureblue-certs.pem +cat "${script_dir}"/trusted-keys/*.pem >secureblue-certs.pem -cp "${script_dir}/correct-spectre-flag-behavior.patch" . +git apply "${script_dir}"/spec-patches/*.patch -git apply "${script_dir}"/patches/*.patch +for patch_file in "${script_dir}"/kernel-patches/*.patch; do + cp "${patch_file}" "./secureblue-${patch_file##*/}" +done mv ./* "${build_dir}"