diff mbox series

[3/3] MIPS: KASLR: Make relocation_address can be configured

Message ID 1605752954-10368-3-git-send-email-hejinyang@loongson.cn (mailing list archive)
State Superseded
Headers show
Series [1/3] MIPS: KASLR: Correcte valid bits in apply_r_mips_26_rel | expand

Commit Message

Jinyang He Nov. 19, 2020, 2:29 a.m. UTC
When CONFIG_RANDOMIZE_BASE is not set, determine_relocation_address()
always returns a constant. It is not friendly to users if the address
cannot be used. Make it can be configured at Kconfig.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/Kconfig           | 5 +++++
 arch/mips/kernel/relocate.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

Comments

Sergey Shtylyov Nov. 19, 2020, 8:06 a.m. UTC | #1
Hello!

On 19.11.2020 5:29, Jinyang He wrote:

> When CONFIG_RANDOMIZE_BASE is not set, determine_relocation_address()
> always returns a constant. It is not friendly to users if the address
> cannot be used. Make it can be configured at Kconfig.

    Make it configurable?

> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
[...]

MBR, Sergei
Jinyang He Nov. 19, 2020, 9:31 a.m. UTC | #2
Hi,

On 11/19/2020 04:06 PM, Sergei Shtylyov wrote:
> Hello!
>
> On 19.11.2020 5:29, Jinyang He wrote:
>
>> When CONFIG_RANDOMIZE_BASE is not set, determine_relocation_address()
>> always returns a constant. It is not friendly to users if the address
>> cannot be used. Make it can be configured at Kconfig.
>
>    Make it configurable?
Oh, yes. Sorry for the expression.
0xffffffff81000000 cannot be used on Loongson64 if CONFIG_RANDOMIZE_BASE 
is disabled.
It's lower than address of _end. It makes relocation_addr_valid() return 
0 always.

Thanks!
Jinyang

>> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
> [...]
>
> MBR, Sergei
Thomas Bogendoerfer Nov. 19, 2020, 12:45 p.m. UTC | #3
On Thu, Nov 19, 2020 at 10:29:14AM +0800, Jinyang He wrote:
> When CONFIG_RANDOMIZE_BASE is not set, determine_relocation_address()
> always returns a constant. It is not friendly to users if the address
> cannot be used. Make it can be configured at Kconfig.

and how do I get the information which address I need to enter ?
This looks more like platforms need to supply a working address and
not the user configuring the kernel...

Thomas.
Jinyang He Nov. 20, 2020, 2:43 a.m. UTC | #4
Hi,

On 11/19/2020 08:45 PM, Thomas Bogendoerfer wrote:
> On Thu, Nov 19, 2020 at 10:29:14AM +0800, Jinyang He wrote:
>> When CONFIG_RANDOMIZE_BASE is not set, determine_relocation_address()
>> always returns a constant. It is not friendly to users if the address
>> cannot be used. Make it can be configured at Kconfig.
> and how do I get the information which address I need to enter ?
> This looks more like platforms need to supply a working address and
> not the user configuring the kernel...
You are right.

We only have two address to enter if CONFIG_RANDOMIZE_BASE disabled. One
is 0xffffffff81000000 in the current if succeed, the other is the orignal
address if failed. From relocation_addr_valid() we see that the avaliable
address need to higher than &_end to avoid overlaps original kernel.
E.g. 0xffffffff83000000 and 0xffffffff84000000 both is avaliable on
Loongson64 platform when &_end ==  0xffffffff82213f80. But
0xffffffff82000000 is not available in that case.

In reality test, I compiled kernel first and got &_end. And then modified
the relocate_address to avaliable and compiled kernel once more. It is
a bad idea.

Is it different from modifying CONFIG_PHYSICAL_START when just relocate
one address? Does it make sense if only one address to relocate?

Morever, RANDOMIZE_BASE is normally avaliable. Can we add a kernel
parameter like "relocation=0xffffffff81000000" to direct address?
At least, other architecture disabling RANDOMIZE_BASE looks like "nokaslr".
Thus, can we delete these code which RANDOMIZE_BASE disabled?

Thanks! :-)
Jinyang

> Thomas.
>
diff mbox series

Patch

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 1508829..1c95478 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -2803,6 +2803,11 @@  config RELOCATION_TABLE_SIZE
 
 	  If unsure, leave at the default value.
 
+config RELOCATE_DESTINATION
+	hex "Relocate address when RANDOMIZE_BASE is not set"
+	depends on RELOCATABLE && !RANDOMIZE_BASE
+	default "0xffffffff81000000"
+
 config RANDOMIZE_BASE
 	bool "Randomize the address of the kernel image"
 	depends on RELOCATABLE
diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c
index 709cfa0..b7ea6ff 100644
--- a/arch/mips/kernel/relocate.c
+++ b/arch/mips/kernel/relocate.c
@@ -276,7 +276,7 @@  static inline void __init *determine_relocation_address(void)
 	 * Choose a new address for the kernel
 	 * For now we'll hard code the destination
 	 */
-	return (void *)0xffffffff81000000;
+	return (void *)CONFIG_RELOCATE_DESTINATION;
 }
 
 #endif