From e4fbec3d4151c109ad968a76eabe98c3dbe2eeab Mon Sep 17 00:00:00 2001 From: Dave Anderson Date: Fri, 17 Feb 2017 15:01:06 -0500 Subject: [PATCH] Allow the "--kaslr=" and/or "--kaslr=auto" command line options to be used with the 32-bit X86 architecture. (anderson@redhat.com) --- help.c | 4 ++-- main.c | 2 +- symbols.c | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/help.c b/help.c index 42aa4dc..b43ef50 100644 --- a/help.c +++ b/help.c @@ -331,8 +331,8 @@ char *program_usage_info[] = { " and verification. The default count is 32768.", "", " --kaslr offset | auto", - " If an x86_64 kernel was configured with CONFIG_RANDOMIZE_BASE, the", - " offset value is equal to the difference between the symbol values ", + " If an x86 or x86_64 kernel was configured with CONFIG_RANDOMIZE_BASE,", + " the offset value is equal to the difference between the symbol values ", " compiled into the vmlinux file and their relocated KASLR value. If", " set to auto, the KASLR offset value will be automatically calculated.", "", diff --git a/main.c b/main.c index 6fee13e..2b5b06b 100644 --- a/main.c +++ b/main.c @@ -228,7 +228,7 @@ main(int argc, char **argv) } } else if (STREQ(long_options[option_index].name, "kaslr")) { if (!machine_type("X86_64") && - !machine_type("ARM64")) + !machine_type("ARM64") && !machine_type("X86")) error(INFO, "--kaslr not valid " "with this machine type.\n"); else if (STREQ(optarg, "auto")) diff --git a/symbols.c b/symbols.c index 989e047..0c4ed66 100644 --- a/symbols.c +++ b/symbols.c @@ -594,7 +594,7 @@ kaslr_init(void) { char *string; - if ((!machine_type("X86_64") && !machine_type("ARM64")) || + if ((!machine_type("X86_64") && !machine_type("ARM64") && !machine_type("X86")) || (kt->flags & RELOC_SET)) return; @@ -712,7 +712,11 @@ store_symbols(bfd *abfd, int dynamic, void *minisyms, long symcount, fromend = from + symcount * size; if (machine_type("X86")) { - if (!(kt->flags & RELOC_SET)) + if (kt->flags2 & KASLR) { + if ((kt->flags2 & RELOC_AUTO) && !(kt->flags & RELOC_SET)) + derive_kaslr_offset(abfd, dynamic, from, + fromend, size, store); + } else if (!(kt->flags & RELOC_SET)) kt->flags |= RELOC_FORCE; } else if (machine_type("X86_64") || machine_type("ARM64")) { if ((kt->flags2 & RELOC_AUTO) && !(kt->flags & RELOC_SET))