Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1304334 > unrolled thread

Re: [PATCH v2 12/13] arm64: add support for relocatable kernel

Started byJames Morse <james.morse@arm.com>
First post2016-01-08 11:20 +0100
Last post2016-01-08 11:30 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: [PATCH v2 12/13] arm64: add support for relocatable kernel James Morse <james.morse@arm.com> - 2016-01-08 11:20 +0100
    Re: [PATCH v2 12/13] arm64: add support for relocatable kernel Ard Biesheuvel <ard.biesheuvel@linaro.org> - 2016-01-08 11:30 +0100

#1304334 — Re: [PATCH v2 12/13] arm64: add support for relocatable kernel

FromJames Morse <james.morse@arm.com>
Date2016-01-08 11:20 +0100
SubjectRe: [PATCH v2 12/13] arm64: add support for relocatable kernel
Message-ID<qOCjh-5hH-23@gated-at.bofh.it>
Hi Ard!

On 30/12/15 15:26, Ard Biesheuvel wrote:
> This adds support for runtime relocation of the kernel Image, by
> building it as a PIE (ET_DYN) executable and applying the dynamic
> relocations in the early boot code.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---

> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
> index 01a33e42ed70..ab582ee58b58 100644
> --- a/arch/arm64/kernel/head.S
> +++ b/arch/arm64/kernel/head.S
> @@ -243,6 +253,16 @@ ENDPROC(stext)
>  preserve_boot_args:
>  	mov	x21, x0				// x21=FDT
>  
> +#ifdef CONFIG_ARM64_RELOCATABLE_KERNEL
> +	/*
> +	 * Mask off the bits of the random value supplied in x1 so it can serve
> +	 * as a KASLR displacement value which will move the kernel image to a
> +	 * random offset in the lower half of the VMALLOC area.
> +	 */
> +	mov	x23, #(1 << (VA_BITS - 2)) - 1
> +	and	x23, x23, x1, lsl #SWAPPER_BLOCK_SHIFT
> +#endif

I've managed to make this fail to boot by providing a seed that caused
the kernel to overlap a 1G boundary on a 4K system.

(It looks like your v3 may have the same issue - but I haven't tested it.)


> +
>  	adr_l	x0, boot_args			// record the contents of
>  	stp	x21, x1, [x0]			// x0 .. x3 at kernel entry
>  	stp	x2, x3, [x0, #16]


Thanks!

James

[toc] | [next] | [standalone]


#1304351

FromArd Biesheuvel <ard.biesheuvel@linaro.org>
Date2016-01-08 11:30 +0100
Message-ID<qOCsX-5li-45@gated-at.bofh.it>
In reply to#1304334
On 8 January 2016 at 11:17, James Morse <james.morse@arm.com> wrote:
> Hi Ard!
>
> On 30/12/15 15:26, Ard Biesheuvel wrote:
>> This adds support for runtime relocation of the kernel Image, by
>> building it as a PIE (ET_DYN) executable and applying the dynamic
>> relocations in the early boot code.
>>
>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>> ---
>
>> diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
>> index 01a33e42ed70..ab582ee58b58 100644
>> --- a/arch/arm64/kernel/head.S
>> +++ b/arch/arm64/kernel/head.S
>> @@ -243,6 +253,16 @@ ENDPROC(stext)
>>  preserve_boot_args:
>>       mov     x21, x0                         // x21=FDT
>>
>> +#ifdef CONFIG_ARM64_RELOCATABLE_KERNEL
>> +     /*
>> +      * Mask off the bits of the random value supplied in x1 so it can serve
>> +      * as a KASLR displacement value which will move the kernel image to a
>> +      * random offset in the lower half of the VMALLOC area.
>> +      */
>> +     mov     x23, #(1 << (VA_BITS - 2)) - 1
>> +     and     x23, x23, x1, lsl #SWAPPER_BLOCK_SHIFT
>> +#endif
>
> I've managed to make this fail to boot by providing a seed that caused
> the kernel to overlap a 1G boundary on a 4K system.
>

Ah, yes. Thanks for spotting that.

> (It looks like your v3 may have the same issue - but I haven't tested it.)
>
>

Yes, it does. It probably makes sense to sacrifice some entropy bits
and simply round up the kaslr offset to a log2 upper bound of the
kernel Image size, rather than hacking up some logic in assembly to
test whether we are crossing a PMD/PUD boundary


>> +
>>       adr_l   x0, boot_args                   // record the contents of
>>       stp     x21, x1, [x0]                   // x0 .. x3 at kernel entry
>>       stp     x2, x3, [x0, #16]
>
>
> Thanks!
>
> James
>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web