Re: [PATCH mips-fixes] MIPS: relocatable: fix possible boot hangup with KASLR enabled

Nathan Chancellor
2021-01-11T05:22:46Z

Apologies for not being familiar enough with the issue to give a review
but I did reproduce the hang that the commit mentions with
malta_kvm_guest_defconfig + CONFIG_RELOCATABLE=y +
CONFIG_RANDOMIZE_BASE=y and this patch does resolve it so:

Tested-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
> arch/mips/kernel/relocate.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c
> index 47aeb3350a76..0e365b7c742d 100644
> --- a/arch/mips/kernel/relocate.c
> +++ b/arch/mips/kernel/relocate.c
> @@ -187,8 +187,14 @@ static int __init relocate_exception_table(long offset)
> static inline __init unsigned long rotate_xor(unsigned long hash,
> const void *area, size_t size)
> {
> - size_t i;
> - unsigned long *ptr = (unsigned long *)area;
> + const typeof(hash) *ptr = PTR_ALIGN(area, sizeof(hash));
> + size_t diff, i;
> +
> + diff = (void *)ptr - area;
> + if (unlikely(size < diff + sizeof(hash)))
> + return hash;
> +
> + size = ALIGN_DOWN(size - diff, sizeof(hash));
>
> for (i = 0; i < size / sizeof(hash); i++) {
> /* Rotate by odd number of bits and XOR. */
> --
> 2.30.0
>
>