Skip to content

Commit 69e9768

Browse files
solbjorntsbogend
authored andcommitted
MIPS: relocatable: fix possible boot hangup with KASLR enabled
LLVM-built Linux triggered a boot hangup with KASLR enabled. arch/mips/kernel/relocate.c:get_random_boot() uses linux_banner, which is a string constant, as a random seed, but accesses it as an array of unsigned long (in rotate_xor()). When the address of linux_banner is not aligned to sizeof(long), such access emits unaligned access exception and hangs the kernel. Use PTR_ALIGN() to align input address to sizeof(long) and also align down the input length to prevent possible access-beyond-end. Fixes: 405bc8f ("MIPS: Kernel: Implement KASLR using CONFIG_RELOCATABLE") Cc: stable@vger.kernel.org # 4.7+ Signed-off-by: Alexander Lobakin <alobakin@pm.me> Tested-by: Nathan Chancellor <natechancellor@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
1 parent 6982224 commit 69e9768

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

arch/mips/kernel/relocate.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,14 @@ static int __init relocate_exception_table(long offset)
187187
static inline __init unsigned long rotate_xor(unsigned long hash,
188188
const void *area, size_t size)
189189
{
190-
size_t i;
191-
unsigned long *ptr = (unsigned long *)area;
190+
const typeof(hash) *ptr = PTR_ALIGN(area, sizeof(hash));
191+
size_t diff, i;
192+
193+
diff = (void *)ptr - area;
194+
if (unlikely(size < diff + sizeof(hash)))
195+
return hash;
196+
197+
size = ALIGN_DOWN(size - diff, sizeof(hash));
192198

193199
for (i = 0; i < size / sizeof(hash); i++) {
194200
/* Rotate by odd number of bits and XOR. */

0 commit comments

Comments
 (0)