Skip to content

Commit 069fd76

Browse files
mpredfearnralfbaechle
authored andcommitted
MIPS: Reserve space for relocation table
When CONFIG_RELOCATABLE is enabled, add a new section in the memory map to be filled with relocation data. CONFIG_RELOCATION_TABLE_SIZE allows the amount of space reserved to be adjusted if necessary. The relocs tool will populate this reserved space with relocation information. The space is reserved within the elf by filling it with 0's, and an invalid entry is left at the start of the space such that kernel relocation will be aborted if the table is empty. Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com> Cc: Aaro Koskinen <aaro.koskinen@nokia.com> Cc: David Daney <ddaney@caviumnetworks.com> Cc: Jonas Gorski <jogo@openwrt.org> Cc: linux-mips@linux-mips.org Cc: kernel-hardening@lists.openwall.com Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/12982/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent aadeec4 commit 069fd76

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

arch/mips/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,22 @@ config NUMA
24732473
config SYS_SUPPORTS_NUMA
24742474
bool
24752475

2476+
config RELOCATION_TABLE_SIZE
2477+
hex "Relocation table size"
2478+
depends on RELOCATABLE
2479+
range 0x0 0x01000000
2480+
default "0x00100000"
2481+
---help---
2482+
A table of relocation data will be appended to the kernel binary
2483+
and parsed at boot to fix up the relocated kernel.
2484+
2485+
This option allows the amount of space reserved for the table to be
2486+
adjusted, although the default of 1Mb should be ok in most cases.
2487+
2488+
The build will fail and a valid size suggested if this is too small.
2489+
2490+
If unsure, leave at the default value.
2491+
24762492
config NODES_SHIFT
24772493
int
24782494
default "6"

arch/mips/kernel/vmlinux.lds.S

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ SECTIONS
136136
#ifdef CONFIG_SMP
137137
PERCPU_SECTION(1 << CONFIG_MIPS_L1_CACHE_SHIFT)
138138
#endif
139+
140+
#ifdef CONFIG_RELOCATABLE
141+
. = ALIGN(4);
142+
143+
.data.reloc : {
144+
_relocation_start = .;
145+
/*
146+
* Space for relocation table
147+
* This needs to be filled so that the
148+
* relocs tool can overwrite the content.
149+
* An invalid value is left at the start of the
150+
* section to abort relocation if the table
151+
* has not been filled in.
152+
*/
153+
LONG(0xFFFFFFFF);
154+
FILL(0);
155+
. += CONFIG_RELOCATION_TABLE_SIZE - 4;
156+
_relocation_end = .;
157+
}
158+
#endif
159+
139160
#ifdef CONFIG_MIPS_RAW_APPENDED_DTB
140161
__appended_dtb = .;
141162
/* leave space for appended DTB */

0 commit comments

Comments
 (0)