linux-next: manual merge of the random tree with Linus' tree
Hi all, [I think I have reported this before ...] Today's linux-next merge of the random tree got a conflict in: include/linux/random.h between commit: 022c204040f3 ("random,stackprotect: introduce get_random_canary function") from Linus' tree and commit: da9ba564bd68 ("random: add get_random_{bytes,u32,u64,int,long,once}_wait family") from the random tree. I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell diff --cc include/linux/random.h index 1fa0dc880bd7,4aecc339558d.. --- a/include/linux/random.h +++ b/include/linux/random.h @@@ -57,27 -58,31 +58,52 @@@ static inline unsigned long get_random_ #endif } +/* + * On 64-bit architectures, protect against non-terminated C string overflows + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. + */ +#ifdef CONFIG_64BIT +# ifdef __LITTLE_ENDIAN +# define CANARY_MASK 0xff00UL +# else /* big endian, 64 bits: */ +# define CANARY_MASK 0x00ffUL +# endif +#else /* 32 bits: */ +# define CANARY_MASK 0xUL +#endif + +static inline unsigned long get_random_canary(void) +{ + unsigned long val = get_random_long(); + + return val & CANARY_MASK; +} + + /* Calls wait_for_random_bytes() and then calls get_random_bytes(buf, nbytes). + * Returns the result of the call to wait_for_random_bytes. */ + static inline int get_random_bytes_wait(void *buf, int nbytes) + { + int ret = wait_for_random_bytes(); + if (unlikely(ret)) + return ret; + get_random_bytes(buf, nbytes); + return 0; + } + + #define declare_get_random_var_wait(var) \ + static inline int get_random_ ## var ## _wait(var *out) { \ + int ret = wait_for_random_bytes(); \ + if (unlikely(ret)) \ + return ret; \ + *out = get_random_ ## var(); \ + return 0; \ + } + declare_get_random_var_wait(u32) + declare_get_random_var_wait(u64) + declare_get_random_var_wait(int) + declare_get_random_var_wait(long) + #undef declare_get_random_var + unsigned long randomize_page(unsigned long start, unsigned long range); u32 prandom_u32(void);
linux-next: manual merge of the random tree with Linus' tree
Hi all, [I think I have reported this before ...] Today's linux-next merge of the random tree got a conflict in: include/linux/random.h between commit: 022c204040f3 ("random,stackprotect: introduce get_random_canary function") from Linus' tree and commit: da9ba564bd68 ("random: add get_random_{bytes,u32,u64,int,long,once}_wait family") from the random tree. I fixed it up (see below) and can carry the fix as necessary. This is now fixed as far as linux-next is concerned, but any non trivial conflicts should be mentioned to your upstream maintainer when your tree is submitted for merging. You may also want to consider cooperating with the maintainer of the conflicting tree to minimise any particularly complex conflicts. -- Cheers, Stephen Rothwell diff --cc include/linux/random.h index 1fa0dc880bd7,4aecc339558d.. --- a/include/linux/random.h +++ b/include/linux/random.h @@@ -57,27 -58,31 +58,52 @@@ static inline unsigned long get_random_ #endif } +/* + * On 64-bit architectures, protect against non-terminated C string overflows + * by zeroing out the first byte of the canary; this leaves 56 bits of entropy. + */ +#ifdef CONFIG_64BIT +# ifdef __LITTLE_ENDIAN +# define CANARY_MASK 0xff00UL +# else /* big endian, 64 bits: */ +# define CANARY_MASK 0x00ffUL +# endif +#else /* 32 bits: */ +# define CANARY_MASK 0xUL +#endif + +static inline unsigned long get_random_canary(void) +{ + unsigned long val = get_random_long(); + + return val & CANARY_MASK; +} + + /* Calls wait_for_random_bytes() and then calls get_random_bytes(buf, nbytes). + * Returns the result of the call to wait_for_random_bytes. */ + static inline int get_random_bytes_wait(void *buf, int nbytes) + { + int ret = wait_for_random_bytes(); + if (unlikely(ret)) + return ret; + get_random_bytes(buf, nbytes); + return 0; + } + + #define declare_get_random_var_wait(var) \ + static inline int get_random_ ## var ## _wait(var *out) { \ + int ret = wait_for_random_bytes(); \ + if (unlikely(ret)) \ + return ret; \ + *out = get_random_ ## var(); \ + return 0; \ + } + declare_get_random_var_wait(u32) + declare_get_random_var_wait(u64) + declare_get_random_var_wait(int) + declare_get_random_var_wait(long) + #undef declare_get_random_var + unsigned long randomize_page(unsigned long start, unsigned long range); u32 prandom_u32(void);
linux-next: manual merge of the random tree with Linus' tree
Hi Theodore, Today's linux-next merge of the random tree got a conflict in arch/x86/include/asm/archrandom.h between commit 5bfce5ef55cb ("x86, kaslr: Provide randomness functions") from Linus' tree and commits e3be36e60bdc ("x86, random: Enable the RDSEED instruction") and 91a60dc7aa88 ("random: Add arch_has_random[_seed]()") from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). -- Cheers, Stephen Rothwells...@canb.auug.org.au diff --cc arch/x86/include/asm/archrandom.h index e6a92455740e,c7ed4a61e928.. --- a/arch/x86/include/asm/archrandom.h +++ b/arch/x86/include/asm/archrandom.h @@@ -39,20 -42,16 +42,30 @@@ #ifdef CONFIG_ARCH_RANDOM +/* Instead of arch_get_random_long() when alternatives haven't run. */ +static inline int rdrand_long(unsigned long *v) +{ + int ok; + asm volatile("1: " RDRAND_LONG "\n\t" + "jc 2f\n\t" + "decl %0\n\t" + "jnz 1b\n\t" + "2:" + : "=r" (ok), "=a" (*v) + : "0" (RDRAND_RETRY_LOOPS)); + return ok; +} + + /* A single attempt at RDSEED */ + static inline bool rdseed_long(unsigned long *v) + { + unsigned char ok; + asm volatile(RDSEED_LONG "\n\t" +"setc %0" +: "=qm" (ok), "=a" (*v)); + return ok; + } + #define GET_RANDOM(name, type, rdrand, nop) \ static inline int name(type *v) \ { \ @@@ -80,15 -95,14 +109,21 @@@ GET_SEED(arch_get_random_seed_int, unsi GET_RANDOM(arch_get_random_long, unsigned long, RDRAND_LONG, ASM_NOP3); GET_RANDOM(arch_get_random_int, unsigned int, RDRAND_INT, ASM_NOP3); + GET_SEED(arch_get_random_seed_long, unsigned long, RDSEED_LONG, ASM_NOP4); + GET_SEED(arch_get_random_seed_int, unsigned int, RDSEED_INT, ASM_NOP4); + #endif /* CONFIG_X86_64 */ + #define arch_has_random() static_cpu_has(X86_FEATURE_RDRAND) + #define arch_has_random_seed()static_cpu_has(X86_FEATURE_RDSEED) + +#else + +static inline int rdrand_long(unsigned long *v) +{ + return 0; +} + #endif /* CONFIG_ARCH_RANDOM */ extern void x86_init_rdrand(struct cpuinfo_x86 *c); pgpucwbxrLs8X.pgp Description: PGP signature
linux-next: manual merge of the random tree with Linus' tree
Hi Theodore, Today's linux-next merge of the random tree got a conflict in arch/x86/include/asm/archrandom.h between commit 5bfce5ef55cb (x86, kaslr: Provide randomness functions) from Linus' tree and commits e3be36e60bdc (x86, random: Enable the RDSEED instruction) and 91a60dc7aa88 (random: Add arch_has_random[_seed]()) from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). -- Cheers, Stephen Rothwells...@canb.auug.org.au diff --cc arch/x86/include/asm/archrandom.h index e6a92455740e,c7ed4a61e928.. --- a/arch/x86/include/asm/archrandom.h +++ b/arch/x86/include/asm/archrandom.h @@@ -39,20 -42,16 +42,30 @@@ #ifdef CONFIG_ARCH_RANDOM +/* Instead of arch_get_random_long() when alternatives haven't run. */ +static inline int rdrand_long(unsigned long *v) +{ + int ok; + asm volatile(1: RDRAND_LONG \n\t + jc 2f\n\t + decl %0\n\t + jnz 1b\n\t + 2: + : =r (ok), =a (*v) + : 0 (RDRAND_RETRY_LOOPS)); + return ok; +} + + /* A single attempt at RDSEED */ + static inline bool rdseed_long(unsigned long *v) + { + unsigned char ok; + asm volatile(RDSEED_LONG \n\t +setc %0 +: =qm (ok), =a (*v)); + return ok; + } + #define GET_RANDOM(name, type, rdrand, nop) \ static inline int name(type *v) \ { \ @@@ -80,15 -95,14 +109,21 @@@ GET_SEED(arch_get_random_seed_int, unsi GET_RANDOM(arch_get_random_long, unsigned long, RDRAND_LONG, ASM_NOP3); GET_RANDOM(arch_get_random_int, unsigned int, RDRAND_INT, ASM_NOP3); + GET_SEED(arch_get_random_seed_long, unsigned long, RDSEED_LONG, ASM_NOP4); + GET_SEED(arch_get_random_seed_int, unsigned int, RDSEED_INT, ASM_NOP4); + #endif /* CONFIG_X86_64 */ + #define arch_has_random() static_cpu_has(X86_FEATURE_RDRAND) + #define arch_has_random_seed()static_cpu_has(X86_FEATURE_RDSEED) + +#else + +static inline int rdrand_long(unsigned long *v) +{ + return 0; +} + #endif /* CONFIG_ARCH_RANDOM */ extern void x86_init_rdrand(struct cpuinfo_x86 *c); pgpucwbxrLs8X.pgp Description: PGP signature
Re: linux-next: manual merge of the random tree with Linus' tree
On Mon, Nov 04, 2013 at 05:04:11PM +1100, Stephen Rothwell wrote: > Hi Ted, > > Today's linux-next merge of the random tree got a conflict in > drivers/base/core.c between commit 63967685605b ("driver core: add > #include to core files") from Linus' tree and commit > f0ed2b943a53 ("random: use device attach events for entropy") from the > random tree. > > I fixed it up (see below) and can carry the fix as necessary (no action > is required). I think Ted is going to drop this patch from his tree as it didn't work properly, right Ted? thanks, greg k-h -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: linux-next: manual merge of the random tree with Linus' tree
On Mon, Nov 04, 2013 at 05:04:11PM +1100, Stephen Rothwell wrote: Hi Ted, Today's linux-next merge of the random tree got a conflict in drivers/base/core.c between commit 63967685605b (driver core: add #include linux/sysfs.h to core files) from Linus' tree and commit f0ed2b943a53 (random: use device attach events for entropy) from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). I think Ted is going to drop this patch from his tree as it didn't work properly, right Ted? thanks, greg k-h -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
linux-next: manual merge of the random tree with Linus' tree
Hi Ted, Today's linux-next merge of the random tree got a conflict in drivers/base/core.c between commit 63967685605b ("driver core: add #include to core files") from Linus' tree and commit f0ed2b943a53 ("random: use device attach events for entropy") from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). -- Cheers, Stephen Rothwells...@canb.auug.org.au diff --cc drivers/base/core.c index 67b180d855b2,5e98fc379d0f.. --- a/drivers/base/core.c +++ b/drivers/base/core.c @@@ -26,7 -26,7 +26,8 @@@ #include #include #include +#include + #include #include "base.h" #include "power/power.h" pgpa9L46hh42V.pgp Description: PGP signature
linux-next: manual merge of the random tree with Linus' tree
Hi Ted, Today's linux-next merge of the random tree got a conflict in drivers/base/core.c between commit 63967685605b (driver core: add #include linux/sysfs.h to core files) from Linus' tree and commit f0ed2b943a53 (random: use device attach events for entropy) from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). -- Cheers, Stephen Rothwells...@canb.auug.org.au diff --cc drivers/base/core.c index 67b180d855b2,5e98fc379d0f.. --- a/drivers/base/core.c +++ b/drivers/base/core.c @@@ -26,7 -26,7 +26,8 @@@ #include linux/async.h #include linux/pm_runtime.h #include linux/netdevice.h +#include linux/sysfs.h + #include linux/random.h #include base.h #include power/power.h pgpa9L46hh42V.pgp Description: PGP signature
linux-next: manual merge of the random tree with Linus' tree
Hi Theodore, Today's linux-next merge of the random tree got a conflict in init/main.c between commit 65f382fd0c8f ("context_tracking: Ground setup for static key use") from Linus' tree and commit 382521d2478b ("random: run random_int_secret_init() run after all late_initcalls") from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). -- Cheers, Stephen Rothwells...@canb.auug.org.au diff --cc init/main.c index af310af,586cd33..000 --- a/init/main.c +++ b/init/main.c @@@ -75,7 -75,7 +75,8 @@@ #include #include #include +#include + #include #include #include pgp3zMtK09bE7.pgp Description: PGP signature
linux-next: manual merge of the random tree with Linus' tree
Hi Theodore, Today's linux-next merge of the random tree got a conflict in init/main.c between commit 65f382fd0c8f (context_tracking: Ground setup for static key use) from Linus' tree and commit 382521d2478b (random: run random_int_secret_init() run after all late_initcalls) from the random tree. I fixed it up (see below) and can carry the fix as necessary (no action is required). -- Cheers, Stephen Rothwells...@canb.auug.org.au diff --cc init/main.c index af310af,586cd33..000 --- a/init/main.c +++ b/init/main.c @@@ -75,7 -75,7 +75,8 @@@ #include linux/blkdev.h #include linux/elevator.h #include linux/sched_clock.h +#include linux/context_tracking.h + #include linux/random.h #include asm/io.h #include asm/bugs.h pgp3zMtK09bE7.pgp Description: PGP signature