From: Matt Redfearn <matt.redfearn@imgtec.com> To: <linux-mips@linux-mips.org> Cc: Matt Redfearn <matt.redfearn@imgtec.com> Subject: [PATCH 0/9] MIPS Relocatable kernel & KASLR Date: Thu, 3 Dec 2015 10:08:08 +0000 [thread overview] Message-ID: <1449137297-30464-1-git-send-email-matt.redfearn@imgtec.com> (raw) This series adds the ability for the MIPS kernel to relocate itself at runtime, optionally to an address determined at random each boot. This series is based on v4.3 and has been tested on the Malta platform. Here is a description of how relocation is achieved: * Kernel is compiled & statically linked as normal (no position independent code). * The linker flag --emit-relocs is added to the linker command line, causing ld to include relocation sections in the output elf * A tool derived from the x86 relocs tool is used to parse the relocation sections and create a binary table of relocations. Each entry in the table is 32bits, comprised of a 24bit offset (in words) from _text and an 8bit relocation type. * The table is inserted into the vmlinux elf, into some space reserved for it in the linker script. Inserting the table into vmlinux means all boot targets will automatically include the relocation code and information. * At boot, the kernel memcpy()s itself elsewhere in memory, then goes through the table performing each relocation on the new image. * If all goes well, control is passed to the entry point of the new kernel. Restrictions: * The new kernel is not allowed to overlap the old kernel, such that the original kernel can still be booted if relocation fails. * Relocation is supported only by multiples of 64k bytes. This eliminates the need to handle R_MIPS_LO16 relocations as the bottom 16bits will remain the same at the relocated address. * In 64 bit kernels, relocation is supported only within the same 4Gb memory segment as the kernel link address (CONFIG_PHYSICAL_START). This eliminates the need to handle R_MIPS_HIGHEST and R_MIPS_HIGHER relocations as the top 32bits will remain the same at the relocated address. * Relocation is currently supported on R2 of the MIPS architecture, 32bit and 64bit. Matt Redfearn (9): MIPS: tools: Add relocs tool MIPS: tools: Build relocs tool MIPS: Reserve space for relocation table MIPS: Generate relocation table when CONFIG_RELOCATABLE MIPS: Kernel: Add relocate.c MIPS: Call relocate_kernel if CONFIG_RELOCATABLE=y MIPS: bootmem: When relocatable, free memory below kernel MIPS: Add CONFIG_RELOCATABLE Kconfig option MIPS: Kernel: Implement kASLR using CONFIG_RELOCATABLE arch/mips/Kconfig | 53 +++ arch/mips/Makefile | 19 ++ arch/mips/boot/tools/Makefile | 8 + arch/mips/boot/tools/relocs.c | 675 +++++++++++++++++++++++++++++++++++++ arch/mips/boot/tools/relocs.h | 34 ++ arch/mips/boot/tools/relocs_32.c | 17 + arch/mips/boot/tools/relocs_64.c | 27 ++ arch/mips/boot/tools/relocs_main.c | 84 +++++ arch/mips/kernel/Makefile | 2 + arch/mips/kernel/head.S | 20 ++ arch/mips/kernel/relocate.c | 296 ++++++++++++++++ arch/mips/kernel/setup.c | 13 + arch/mips/kernel/vmlinux.lds.S | 20 ++ 13 files changed, 1268 insertions(+) create mode 100644 arch/mips/boot/tools/Makefile create mode 100644 arch/mips/boot/tools/relocs.c create mode 100644 arch/mips/boot/tools/relocs.h create mode 100644 arch/mips/boot/tools/relocs_32.c create mode 100644 arch/mips/boot/tools/relocs_64.c create mode 100644 arch/mips/boot/tools/relocs_main.c create mode 100644 arch/mips/kernel/relocate.c -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: Matt Redfearn <matt.redfearn@imgtec.com> To: linux-mips@linux-mips.org Cc: Matt Redfearn <matt.redfearn@imgtec.com> Subject: [PATCH 0/9] MIPS Relocatable kernel & KASLR Date: Thu, 3 Dec 2015 10:08:08 +0000 [thread overview] Message-ID: <1449137297-30464-1-git-send-email-matt.redfearn@imgtec.com> (raw) Message-ID: <20151203100808.ze34UY6FyEF5hb4JRSMMG6OQuk5Jnj-7njJQGkxDGAI@z> (raw) This series adds the ability for the MIPS kernel to relocate itself at runtime, optionally to an address determined at random each boot. This series is based on v4.3 and has been tested on the Malta platform. Here is a description of how relocation is achieved: * Kernel is compiled & statically linked as normal (no position independent code). * The linker flag --emit-relocs is added to the linker command line, causing ld to include relocation sections in the output elf * A tool derived from the x86 relocs tool is used to parse the relocation sections and create a binary table of relocations. Each entry in the table is 32bits, comprised of a 24bit offset (in words) from _text and an 8bit relocation type. * The table is inserted into the vmlinux elf, into some space reserved for it in the linker script. Inserting the table into vmlinux means all boot targets will automatically include the relocation code and information. * At boot, the kernel memcpy()s itself elsewhere in memory, then goes through the table performing each relocation on the new image. * If all goes well, control is passed to the entry point of the new kernel. Restrictions: * The new kernel is not allowed to overlap the old kernel, such that the original kernel can still be booted if relocation fails. * Relocation is supported only by multiples of 64k bytes. This eliminates the need to handle R_MIPS_LO16 relocations as the bottom 16bits will remain the same at the relocated address. * In 64 bit kernels, relocation is supported only within the same 4Gb memory segment as the kernel link address (CONFIG_PHYSICAL_START). This eliminates the need to handle R_MIPS_HIGHEST and R_MIPS_HIGHER relocations as the top 32bits will remain the same at the relocated address. * Relocation is currently supported on R2 of the MIPS architecture, 32bit and 64bit. Matt Redfearn (9): MIPS: tools: Add relocs tool MIPS: tools: Build relocs tool MIPS: Reserve space for relocation table MIPS: Generate relocation table when CONFIG_RELOCATABLE MIPS: Kernel: Add relocate.c MIPS: Call relocate_kernel if CONFIG_RELOCATABLE=y MIPS: bootmem: When relocatable, free memory below kernel MIPS: Add CONFIG_RELOCATABLE Kconfig option MIPS: Kernel: Implement kASLR using CONFIG_RELOCATABLE arch/mips/Kconfig | 53 +++ arch/mips/Makefile | 19 ++ arch/mips/boot/tools/Makefile | 8 + arch/mips/boot/tools/relocs.c | 675 +++++++++++++++++++++++++++++++++++++ arch/mips/boot/tools/relocs.h | 34 ++ arch/mips/boot/tools/relocs_32.c | 17 + arch/mips/boot/tools/relocs_64.c | 27 ++ arch/mips/boot/tools/relocs_main.c | 84 +++++ arch/mips/kernel/Makefile | 2 + arch/mips/kernel/head.S | 20 ++ arch/mips/kernel/relocate.c | 296 ++++++++++++++++ arch/mips/kernel/setup.c | 13 + arch/mips/kernel/vmlinux.lds.S | 20 ++ 13 files changed, 1268 insertions(+) create mode 100644 arch/mips/boot/tools/Makefile create mode 100644 arch/mips/boot/tools/relocs.c create mode 100644 arch/mips/boot/tools/relocs.h create mode 100644 arch/mips/boot/tools/relocs_32.c create mode 100644 arch/mips/boot/tools/relocs_64.c create mode 100644 arch/mips/boot/tools/relocs_main.c create mode 100644 arch/mips/kernel/relocate.c -- 2.1.4
next reply other threads:[~2015-12-03 10:08 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-12-03 10:08 Matt Redfearn [this message] 2015-12-03 10:08 ` [PATCH 0/9] MIPS Relocatable kernel & KASLR Matt Redfearn 2015-12-03 10:08 ` [PATCH 1/9] MIPS: tools: Add relocs tool Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 2/9] MIPS: tools: Build " Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 3/9] MIPS: Reserve space for relocation table Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 4/9] MIPS: Generate relocation table when CONFIG_RELOCATABLE Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 5/9] MIPS: Kernel: Add relocate.c Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 6/9] MIPS: Call relocate_kernel if CONFIG_RELOCATABLE=y Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 14:24 ` Sergei Shtylyov 2015-12-03 14:53 ` Matt Redfearn 2015-12-03 14:53 ` Matt Redfearn 2015-12-03 17:46 ` Sergei Shtylyov 2015-12-03 18:54 ` James Hogan 2015-12-04 8:20 ` Matt Redfearn 2015-12-04 8:20 ` Matt Redfearn 2015-12-04 15:37 ` Ralf Baechle 2015-12-04 15:45 ` Matt Redfearn 2015-12-04 15:45 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 7/9] MIPS: bootmem: When relocatable, free memory below kernel Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 8/9] MIPS: Add CONFIG_RELOCATABLE Kconfig option Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 10:08 ` [PATCH 9/9] MIPS: Kernel: Implement kASLR using CONFIG_RELOCATABLE Matt Redfearn 2015-12-03 10:08 ` Matt Redfearn 2015-12-03 22:23 ` [PATCH 0/9] MIPS Relocatable kernel & KASLR Joshua Kinard 2015-12-04 8:14 ` Matt Redfearn 2015-12-04 8:14 ` Matt Redfearn 2015-12-04 13:14 ` Joshua Kinard
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1449137297-30464-1-git-send-email-matt.redfearn@imgtec.com \ --to=matt.redfearn@imgtec.com \ --cc=linux-mips@linux-mips.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.