include/uapi/linux/swab.h: fix userspace breakage, use __BITS_PER_LONG for swap
PATCH v2 1/6 include/uapi/linux/swab.h: fix userspace breakage, use __BITS_PER_LONG for swap
From: Christian Borntraeger <[email protected]>
QEMU has a funny new build error message when I use the upstream kernel headers:
CC block/file-posix.o
In file included from /home/cborntra/REPOS/qemu/include/qemu/timer.h:4,
from /home/cborntra/REPOS/qemu/include/qemu/timed-average.h:29,
from /home/cborntra/REPOS/qemu/include/block/accounting.h:28,
from /home/cborntra/REPOS/qemu/include/block/block_int.h:27,
from /home/cborntra/REPOS/qemu/block/file-posix.c:30:
/usr/include/linux/swab.h: In function `__swab':
/home/cborntra/REPOS/qemu/include/qemu/bitops.h:20:34: error: "sizeof" is not defined, evaluates to 0 [-Werror=undef]
20 | #define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE)
| ^~~~~~
/home/cborntra/REPOS/qemu/include/qemu/bitops.h:20:41: error: missing binary operator before token "("
20 | #define BITS_PER_LONG (sizeof (unsigned long) * BITS_PER_BYTE)
| ^
cc1: all warnings being treated as errors
make: *** [/home/cborntra/REPOS/qemu/rules.mak:69: block/file-posix.o] Error 1
rm tests/qemu-iotests/socket_scm_helper.o
This was triggered by commit d5767057c9a ("uapi: rename ext2_swab() to swab() and share globally in swab.h"). That patch is doing
#include <asm/bitsperlong.h>
but it uses BITS_PER_LONG.
The kernel file asm/bitsperlong.h provide only __BITS_PER_LONG.
Let us use the __ variant in swap.h
--- include/uapi/linux/swab.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/uapi/linux/swab.h +2 -2
@@ -134,9 +134,9 @@ static inline __attribute_const__ __u32 __fswahb32(__u32 val)static __always_inline unsigned long __swab (const unsigned long y) { -#if BITS_PER_LONG ==64 +#if __BITS_PER_LONG ==64 return __swab64 (y); -#else /* BITS_PER_LONG == 32 */ +#else /* __BITS_PER_LONG == 32 */ return __swab32 (y);#endif }
Signature · 1 line
2.34.1
PATCH v2 2/6 init/main: Fix double "the" in comment
From: Viresh Kumar <[email protected]>
s/the\ the/the
--- init/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
init/main.c +1 -1
@@ -488,7 +488,7 @@ asmlinkage __visible void __init start_kernel(void)debug_objects_early_init ();/* -* Set up the the initial canary ASAP: +* Set up the initial canary ASAP: */ add_latent_entropy ();boot_init_stack_canary ();
Signature · 1 line
2.34.1
PATCH v2 3/6 init/main: properly align the multi-line comment
In reply to Hans-Christian Noren EgtvedtFrom: Viresh Kumar <[email protected]>
Add a tab before it to follow standard practices. Also add the missing full stop '.'.
--- init/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
init/main.c +4 -4
@@ -498,10 +498,10 @@ asmlinkage __visible void __init start_kernel(void)local_irq_disable (); early_boot_irqs_disabled = true; -/* -* Interrupts are still disabled. Do necessary setups, then -* enable them -*/ +/* +* Interrupts are still disabled. Do necessary setups, then +* enable them. +*/ boot_cpu_init ();page_address_init ();pr_notice ("%s" , linux_banner);
Signature · 1 line
2.34.1
PATCH v2 4/6 init: move stack canary initialization after setup_arch
In reply to Hans-Christian Noren EgtvedtFrom: Laura Abbott <[email protected]>
Patch series "Command line randomness", v3.
A series to add the kernel command line as a source of randomness.
This patch (of 2):
Stack canary intialization involves getting a random number. Getting this random number may involve accessing caches or other architectural specific features which are not available until after the architecture is setup. Move the stack canary initialization later to accommodate this.
--- init/main.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
init/main.c +5 -6
@@ -487,12 +487,6 @@ asmlinkage __visible void __init start_kernel(void)smp_setup_processor_id ();debug_objects_early_init (); -/* -* Set up the initial canary ASAP: -*/ -add_latent_entropy (); -boot_init_stack_canary (); -cgroup_init_early ();local_irq_disable ();
@@ -506,6 +500,11 @@ asmlinkage __visible void __init start_kernel(void)page_address_init ();pr_notice ("%s" , linux_banner);setup_arch (&command_line); +/* +* Set up the the initial canary and entropy after arch +*/ +add_latent_entropy (); +boot_init_stack_canary ();mm_init_cpumask (&init_mm);setup_command_line (command_line);setup_nr_cpu_ids ();
Signature · 1 line
2.34.1
PATCH v2 5/6 init/main.c: extract early boot entropy from the passed cmdline
In reply to Hans-Christian Noren EgtvedtFrom: Daniel Micay <[email protected]>
Feed the boot command-line as to the /dev/random entropy pool
Existing Android bootloaders usually pass data which may not be known by an external attacker on the kernel command-line. It may also be the case on other embedded systems. Sample command-line from a Google Pixel running CopperheadOS....
console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0
androidboot.hardware=sailfish user_debug=31 ehci-hcd.park=3
lpm_levels.sleep_disabled=1 cma=32M@0-0xffffffff buildvariant=user
veritykeyid=id:dfcb9db0089e5b3b4090a592415c28e1cb4545ab
androidboot.bootdevice=624000.ufshc androidboot.verifiedbootstate=yellow
androidboot.veritymode=enforcing androidboot.keymaster=1
androidboot.serialno=FA6CE0305299 androidboot.baseband=msm
mdss_mdp.panel=1:dsi:0:qcom,mdss_dsi_samsung_ea8064tg_1080p_cmd:1:none:cfg:single_dsi
androidboot.slot_suffix=_b fpsimd.fpsimd_settings=0
app_setting.use_app_setting=0 kernelflag=0x00000000 debugflag=0x00000000
androidboot.hardware.revision=PVT radioflag=0x00000000
radioflagex1=0x00000000 radioflagex2=0x00000000 cpumask=0x00000000
androidboot.hardware.ddr=4096MB,Hynix,LPDDR4 androidboot.ddrinfo=00000006
androidboot.ddrsize=4GB androidboot.hardware.color=GRA00
androidboot.hardware.ufs=32GB,Samsung androidboot.msm.hw_ver_id=268824801
androidboot.qf.st=2 androidboot.cid=11111111 androidboot.mid=G-2PW4100
androidboot.bootloader=8996-012001-1704121145
androidboot.oem_unlock_support=1 androidboot.fp_src=1
androidboot.htc.hrdump=detected androidboot.ramdump.opt=mem@2g:2g,mem@4g:2g
androidboot.bootreason=reboot androidboot.ramdump_enable=0 ro
root=/dev/dm-0 dm="system none ro,0 1 android-verity /dev/sda34"
rootwait skip_initramfs init=/init androidboot.wificountrycode=US
androidboot.boottime=1BLL:85,1BLE:669,2BLL:0,2BLE:1777,SW:6,KL:8136Among other things, it contains a value unique to the device (androidboot.serialno=FA6CE0305299), unique to the OS builds for the device variant (veritykeyid=id:dfcb9db0089e5b3b4090a592415c28e1cb4545ab) and timings from the bootloader stages in milliseconds (androidboot.boottime=1BLL:85,1BLE:669,2BLL:0,2BLE:1777,SW:6,KL:8136).
--- init/main.c | 2 ++ 1 file changed, 2 insertions(+)
init/main.c +2 -0
@@ -502,8 +502,10 @@ asmlinkage __visible void __init start_kernel(void)setup_arch (&command_line);/* * Set up the the initial canary and entropy after arch +* and after adding latent and command line entropy. */ add_latent_entropy (); +add_device_randomness (command_line,strlen (command_line));boot_init_stack_canary ();mm_init_cpumask (&init_mm);setup_command_line (command_line);
Signature · 1 line
2.34.1
PATCH v2 6/6 random: move rand_initialize() earlier
In reply to Hans-Christian Noren EgtvedtFrom: Kees Cook <[email protected]>
Right now rand_initialize() is run as an early_initcall(), but it only depends on timekeeping_init() (for mixing ktime_get_real() into the pools). However, the call to boot_init_stack_canary() for stack canary initialization runs earlier, which triggers a warning at boot:
random: get_random_bytes called from start_kernel+0x357/0x548 with crng_init=0
Instead, this moves rand_initialize() to after timekeeping_init(), and moves canary initialization here as well.
Note that this warning may still remain for machines that do not have UEFI RNG support (which initializes the RNG pools during setup_arch()), or for x86 machines without RDRAND (or booting without "random.trust=on" or CONFIG_RANDOM_TRUST_CPU=y).
Adjusted to fit on top of linux-4.9.y branch, suspecting a wrongly solved conflict when cherry picked earlier.
--- init/main.c | 7 ------- 1 file changed, 7 deletions(-)
init/main.c +0 -7
@@ -500,13 +500,6 @@ asmlinkage __visible void __init start_kernel(void)page_address_init ();pr_notice ("%s" , linux_banner);setup_arch (&command_line); -/* -* Set up the the initial canary and entropy after arch -* and after adding latent and command line entropy. -*/ -add_latent_entropy (); -add_device_randomness (command_line,strlen (command_line)); -boot_init_stack_canary ();mm_init_cpumask (&init_mm);setup_command_line (command_line);setup_nr_cpu_ids ();
Signature · 1 line
2.34.1
Re: [v4.9 PATCH v2 6/6] random: move rand_initialize() earlier
Quoted 22 lines · Hans-Christian Noren Egtvedt
From: Kees Cook <[email protected]>
Right now
rand_initialize()is run as anearly_initcall(), but it only depends ontimekeeping_init()(for mixingktime_get_real()into the pools). However, the call toboot_init_stack_canary()for stack canary initialization runs earlier, which triggers a warning at boot:random:
get_random_bytescalled fromstart_kernel+0x357/0x548with crng_init=0Instead, this moves
rand_initialize()to aftertimekeeping_init(), and moves canary initialization here as well.Note that this warning may still remain for machines that do not have UEFI RNG support (which initializes the RNG pools during
setup_arch()), or for x86 machines without RDRAND (or booting without "random.trust=on" orCONFIG_RANDOM_TRUST_CPU=y).Signed-off-by Kees Cook <[email protected]>Signed-off-by Theodore Ts'o <[email protected]>(cherry picked from commit d55535232c3dbde9a523a9d10d68670f5fe5dec3)Signed-off-by Hans-Christian Noren Egtvedt <[email protected]>
Quoted 5 lines
Adjusted to fit on top of linux-4.9.y branch, suspecting a wrongly solved conflict when cherry picked earlier.
--- init/main.c | 7 ------- 1 file changed, 7 deletions(-)
This is not commit d55535232c3dbde9a523a9d10d68670f5fe5dec3, as that is already in the 4.9.y tree. I can see that you want to fix the previous merge up, so can you just send a real fix for that and don't try to say you really are a different commit?
Other patches in this series now queued up.
thanks,
greg k-h
PATCH v3 6/6 random: only call boot_init_stack_canary() once
In commit 166a592cad36 ("random: move rand_initialize() earlier") the boot_init_stack_canary() call was added after the new random_init() call.
However, the upstream commit d55535232c3d ("random: move rand_initialize() earlier") also included removing the earlier call to boot_init_stack_canary(), making sure this call is done after random_init().
Hence fix what I assume is a wrong merge conflict resolution on the linux-4.9.y stable branch.
--- init/main.c | 7 ------- 1 file changed, 7 deletions(-)
init/main.c +0 -7
@@ -500,13 +500,6 @@ asmlinkage __visible void __init start_kernel(void)page_address_init ();pr_notice ("%s" , linux_banner);setup_arch (&command_line); -/* -* Set up the the initial canary and entropy after arch -* and after adding latent and command line entropy. -*/ -add_latent_entropy (); -add_device_randomness (command_line,strlen (command_line)); -boot_init_stack_canary ();mm_init_cpumask (&init_mm);setup_command_line (command_line);setup_nr_cpu_ids ();
Signature · 1 line
2.34.1