diff options
author | Alan Modra <amodra@gmail.com> | 2022-02-03 08:57:47 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-02-13 14:00:56 +1030 |
commit | 31b4d3a16f200bf04db8439a63b72bba7af4e1be (patch) | |
tree | a422261355b8221ded5777ec889cc7054c99203f | |
parent | 9833b7757d246f22db4eb24b8e5db7eb5e05b6d9 (diff) | |
download | gdb-31b4d3a16f200bf04db8439a63b72bba7af4e1be.zip gdb-31b4d3a16f200bf04db8439a63b72bba7af4e1be.tar.gz gdb-31b4d3a16f200bf04db8439a63b72bba7af4e1be.tar.bz2 |
PR28824, relro security issues, x86 keep COMMONPAGESIZE relro
x86 treats MAXPAGESIZE as a memory optimisation parameter, actual
hardware paging is always COMMPAGESIZE of 4k. Use COMMONPAGESIZE for
the end of the relro segment alignment.
The previous patch regresses pr18176, increasing the testcase file
size from 322208 to 2099872 bytes. Fixing this on x86 will require
introducing a gap after the end of the relro segment (of up to
relropagesize-1 bytes).
PR 28824
PR 18176
* ld.h (ld_config_type): Add relro_use_commonpagesize field.
* ldexp.c (fold_segment_align): Set relropagesize depending on
relro_use_commonpagesize.
* emultempl/elf-x86.em (elf_x86_create_output_section_statements):
Set relro_use_commonpagesize.
* testsuite/ld-x86-64/pr18176.d: xfail.
-rw-r--r-- | ld/emultempl/elf-x86.em | 1 | ||||
-rw-r--r-- | ld/ld.h | 4 | ||||
-rw-r--r-- | ld/ldexp.c | 5 | ||||
-rw-r--r-- | ld/testsuite/ld-x86-64/pr18176.d | 1 |
4 files changed, 10 insertions, 1 deletions
diff --git a/ld/emultempl/elf-x86.em b/ld/emultempl/elf-x86.em index f75521c..134e4e1 100644 --- a/ld/emultempl/elf-x86.em +++ b/ld/emultempl/elf-x86.em @@ -33,6 +33,7 @@ static struct elf_linker_x86_params params; static void elf_x86_create_output_section_statements (void) { + config.relro_use_commonpagesize = true; _bfd_elf_linker_x86_set_options (&link_info, ¶ms); } @@ -276,6 +276,10 @@ typedef struct /* If set, code and non-code sections should never be in one segment. */ bool separate_code; + /* TRUE if the end of the relro segment should be aligned to + COMMONPAGESIZE rather than MAXPAGESIZE. */ + bool relro_use_commonpagesize; + /* The rpath separation character. Usually ':'. */ char rpath_separator; @@ -481,7 +481,10 @@ fold_segment_align (seg_align_type *seg, etree_value_type *lhs) seg->base = expld.result.value; seg->commonpagesize = commonpage; seg->maxpagesize = maxpage; - seg->relropagesize = maxpage; + if (config.relro_use_commonpagesize) + seg->relropagesize = commonpage; + else + seg->relropagesize = maxpage; seg->relro_end = 0; } else diff --git a/ld/testsuite/ld-x86-64/pr18176.d b/ld/testsuite/ld-x86-64/pr18176.d index a99ff15..728c15a 100644 --- a/ld/testsuite/ld-x86-64/pr18176.d +++ b/ld/testsuite/ld-x86-64/pr18176.d @@ -3,6 +3,7 @@ #ld: -melf_x86_64 -shared -z relro -T pr18176.t -z max-page-size=0x200000 -z common-page-size=0x1000 $NO_DT_RELR_LDFLAGS #readelf: -l --wide #target: x86_64-*-linux* +#xfail: *-*-* #... GNU_RELRO 0x04bd17 0x000000000024bd17 0x000000000024bd17 0x0022e9 0x0022e9 R 0x1 |