Page MenuHomeFreeBSD

properly align etext and rodata to prevent overlappings in PTI case
Needs ReviewPublic

Authored by op on Feb 25 2018, 10:23 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 13, 11:09 PM
Unknown Object (File)
Mar 8 2024, 1:24 PM
Unknown Object (File)
Dec 20 2023, 3:29 AM
Unknown Object (File)
Sep 15 2023, 11:24 AM
Unknown Object (File)
Jul 27 2023, 2:20 AM
Unknown Object (File)
Jun 22 2023, 6:32 PM
Unknown Object (File)
Jun 22 2023, 1:51 AM
Unknown Object (File)
May 3 2023, 6:24 PM
Subscribers

Details

Reviewers
kib
emaste
alc
jhb
Group Reviewers
secteam
Summary

The pmap_pti_add_kva_locked function truncates the starting address and
rounds up to PAGE_SIZE the end address, thus passing etext is bogous,
since it overlaps with the start of rodata, see the example bellow.

objdump -d kernel before this patch:

...
 ffffffff808fff54:       41 5f                   pop    %r15
 ffffffff808fff56:       5d                      pop    %rbp
 ffffffff808fff57:       c3                      retq           <- etext
 Disassembly of section .rodata:

 ffffffff808fff60 <cam_status_table-0x570>:                     <-  rodata
 ffffffff808fff60:       43                      rex.XB
 ffffffff808fff61:       43                      rex.XB
...

and after:

...
 ffffffff808fff54:       41 5f                   pop    %r15
 ffffffff808fff56:       5d                      pop    %rbp
 ffffffff808fff57:       c3                      retq           <- etext
 Disassembly of section .rodata:

 ffffffff80900000 <cam_status_table-0x570>:                     <- rodata
 ffffffff80900000:       43                      rex.XB
 ffffffff80900001:       43                      rex.XB
...

Obtained from: opBSD

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 15264

Event Timeline

What is the desire here specifically with respect to PTI?

I think we do want a change along these lines; we should be able to map .rodata as NX. But the change would be a bit larger than this.

You can see the problem here: https://github.com/freebsd/freebsd/blob/master/sys/amd64/amd64/pmap.c#L7921

static void
pmap_pti_add_kva_locked(vm_offset_t sva, vm_offset_t eva, bool exec)
     ...
     sva = trunc_page(sva);
     MPASS(sva > VM_MAXUSER_ADDRESS);
     eva = round_page(eva);
     MPASS(sva < eva);
     ...

The end address is rounded up to page size, and in this case the round_page(etext) overlaps with the rodata.

Probably the same problem occurs with all of the other places, where the pmap_pti_add_kva_locked used.

Probably it would be nice to rethink the linker file layout for amd64, since there are lot of parts merged into text, what is not NX naturally.