This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC PATCH] Little hardening DSOs/executables against exploits (take 2)


On Thu, Jan 15, 2004 at 11:07:53PM +1030, Alan Modra wrote:
> On Wed, Jan 14, 2004 at 09:09:00AM +0100, Jakub Jelinek wrote:
> > The logic could be written as (on ppc32 example (BTW, shouldn't elf32ppc.sh
> > define COMMONPAGESIZE=0x1000 ?)).
> 
> Yes.  Done.

Thanks.

> >   .jcr            : { KEEP (*(.jcr)) }
> >   .data.rel.ro : { *(.data.rel.ro.local) *(.data.rel.ro*) }
> >   .dynamic        : { *(.dynamic) }
> >   .fixup          : ONLY_IF (SIZE (.sbss) < 1024 || THIS_SEGMENT_SIZE <= 32768) { *(.fixup) }
> >   .got1           : ONLY_IF (SIZE (.sbss) < 1024 || THIS_SEGMENT_SIZE <= 32768) { *(.got1) }
> >   .got2           : ONLY_IF (SIZE (.sbss) < 1024 || THIS_SEGMENT_SIZE <= 32768) { *(.got2) }
> 
> The above three sections can always go here.  No need for anything fancy
> as they're not accessed via r13.

Ok, this could be handled by introducing OTHER_RELRO_SECTIONS variable
and change it in elf32ppc.sh.  Will do that.

> .sdata2 and .sbss2 are EABI only, and in the non-shared lib case are
> accessed via r2.  In that case, you shouldn't include them in any
> calculations involving the size of data accessed via r13.  When building
> shared libs they _are_ accessed via r13, the same as .got, .sdata and
> .sbss.  Another weird thing about .sdata2 is that the EABI says
>   "The special section .sdata2 is intended to hold initialized read-only
>   small data that contribute to the program memory image.  The section
>   can, however, be used to hold writable data."
> It seems to me that the current linker script puts them in the wrong
> place..
> 
> Incidentally, instead of inventing new "ONLY_IF" and "THIS_SEGMENT_SIZE"
> magic, can't you just use
> 
> . = some_condition_on_section_sizes ? . : DATA_SEGMENT_RELRO_END (.);
> .got { ... };
> . = some_condition_on_section_sizes ? DATA_SEGMENT_RELRO_END (.) : .;

I don't think it is possible this way.  It could be perhaps:

IF (some_condition) {
  output_section_stmt;
  ...
} else {
  different_output_sec_stmt;
  ...
}

That's because the order of .got/.sbss/.data/.sdata/.bss should be following:

RW segment small:
----------+
.got      |
RELRO_END |
.data     |- reachable by pic reg
.sdata    |
.sbss-----+
.bss

SBSS small:
.got------+
RELRO_END |
.sdata    |- reachable by pic reg
.sbss-----+
.data
.bss

otherwise:
RELRO_END
.data
.got------+
.sdata    |- reachable by pic reg
.sbss-----+

so it is not just about where RELRO_END is, but the sections need to be in
different orders.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]