Commit graph

10 commits

Author SHA1 Message Date
Tamas Petz
bca786d742 [arm64] Build NDK with PAuth and BTI
This change adds a new arch named "armv8-a-branchprot". The new target
is no different from the usual "armv8-a" variant except it has the
compiler flag "-mbranch-protection=standard" set.

With this flag compiler emits Armv8.3-A Pointer Authentication and
Armv8.5-A Branch Target Identification instructions. All of these
instructions are in the hint space; therefore devices which do not
support any of these extensions would execute them as NOPs.

In terms of directory structure there is no change in the output of
build/soong/scripts/build-ndk-prebuilts.sh script.

Test: build NDK prebuilts

Change-Id: Ie52ccba5653fbf567f0b7ca312d8a8e71602ad06
2021-01-26 08:15:07 +01:00
Ivan Lozano
6cd99e6ab4 Add Rust fuzzing support.
Add a rust_fuzz module which builds a libfuzzer binary that enabes
asan+sancov. This relies on the libfuzzer-sys crate.

Bug: 147140513
Test: Local rust_fuzz example builds, fuzzes with asan+sancov.
Change-Id: I57db3b8d25869791824ccfab768d13b0bb9d42fa
2021-01-25 11:11:10 -05:00
Roland Levillain
dba548af83 Merge "Introduce new Arm64 arch variant with dot product features" 2020-09-21 17:54:04 +00:00
Treehugger Robot
5a1a88ee93 Merge "LinuxBionic supports arm64" 2020-09-14 15:59:16 +00:00
Ivan Lozano
6d45a9863a rust: Pass lld flags from cc to rust linker args.
Rust is not passing the sysroot flag to Clang when invoking it as the
linker. This means files from the host may leak in, and host targets
may fail if sysroot files are not available from the host.

This patch prepends the lld flags from cc into rust linkargs. This
pulls in the sysroots flag, and also ensures that we remain in sync
with linkage flags used in cc.

The '-Wl,--no-undefined-version' from cc is overridden to avoid
missing version assignment errors for rust's generated alloc
functions.

Bug: 167690054
Test: cd external/rust; mma
Test: strace -f -e %file <host libstd.dylib.so build command> pulls
      from correct sysroots.
Change-Id: Ic40597f546f3b112012155614056afed487c6ca1
2020-09-09 14:20:00 -04:00
Jiyong Park
4afa2e2682 LinuxBionic supports arm64
LinuxBionic now supports arm64 architecture in addition to the existing
x86_64 arch. This is to make it possible to build host tools like adb,
fastboot, crosvm, etc. for Linux/ARM on regular Linux/x86 machines.

The arm64 target can be selected in various ways in Android.bp files:

   - target.host (because this is still considered as a host target)
   - target.linux (provided that the module is also enabled for host)
   - target.linux_bionic (use the OS name directly)
   - target.linux_bionic_arm64 (OS name + arch combo)
   - target.linux_arm64 (provided that the module is also for host)
   - target.not_windows
   - arch.arm64

The toolchain for the new target is almost the same as the toolchain
config for Android/ARM64. One notable difference is that the clang
triple is aarch64-linux instead of aarch64-linux-android, so that
__ANDROID__ is not defined for the new OS type.

Bug: 134795810
Test: HOST_CROSS_OS=linux_bionic HOST_CROSS_ARCH=arm64 m nothing

Change-Id: If4300583edfb6d75bd4d984b38f73b6a406b4447
2020-09-09 21:57:10 +09:00
Raphael Gault
70b96b0d64 Introduce new Arm64 arch variant with dot product features
In order to rely on `-march`/`-mcpu` compiler flags for feature
detection, we introduce a new arch variant based on armv8.2 with the
addition of dot product features.

Test: test-art-target on Pixel 4.

Change-Id: I4d97db6129e2cd718a2b21008d36ec767739f925
2020-08-26 15:52:22 +00:00
Ivan Lozano
78e5ee0b8d Remove rust execute-only memory linker flag.
With kernel support being removed for execute-only memory layouts,
remove support for XOM until there's kernel support again.

Bug: 153457617
Test: Rust binaries no longer have execute-only text sections.
Change-Id: I19cfb5b347a1f44394a619e17bb0c057c09e76a9
2020-04-09 09:40:50 -04:00
Nick Desaulniers
dcee1e5c54 soong: use -Wl,-z,separate-code w/ -Wl,--execute-only
The clang-r370808 upgrade contains a change to LLD allow PT_LOAD
segments to reside at non-multiples of the page size in the resulting
object file.  https://reviews.llvm.org/rL369344

While this helps reduce the alignment waste and resulting image size, it
has interesting implications for execute only memory (XOM): The runtime
loader will now load code or data from other segments into pages with
different protections than intended.

This would partially defeat execute only (XOM) text sections as the
segment could now overlap with previous and following sections. This
might allow for code or data from the preceding and following sections
(like .eh_frame, and .data.rel.ro) to be executable, and either ends of
.text to be readable.

When the runtime loader (linker[64]) `mmap`s segments from *.so files,
the file offset parameter (see `man 2 mmap`) MUST be a multiple of the
page size.  Since the updated LLD can now pack segments in a file (which
helps minimize resulting object file size) (previously, the segment
offsets were page aligned), this has interesting implications.

To appreciate the current bug, consider the following output from
`readelf` before this patch is applied, but after the toolchain upgrade:

```
$ readelf -lSW $OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so
...
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
...
  [13] .eh_frame         PROGBITS        000000000002e7c0 02e7c0 013374 00   A  0   0  8
  [14] .text             PROGBITS        0000000000042b40 041b40 09ecb4 00  AX  0   0 64
  [15] .plt              PROGBITS        00000000000e1800 0e0800 001f30 00  AX  0   0 16
  [16] .data.rel.ro      PROGBITS        00000000000e4740 0e2740 005208 00  WA  0   0 32
...
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x000230 0x000230 R   0x8
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x041b34 0x041b34 R   0x1000
  LOAD           0x041b40 0x0000000000042b40 0x0000000000042b40 0x0a0bf0 0x0a0bf0   E 0x1000
  LOAD           0x0e2740 0x00000000000e4740 0x00000000000e4740 0x006720 0x006720 RW  0x1000
...
   01     .note.android.ident .note.gnu.build-id .dynsym .gnu.version .gnu.version_d .gnu.version_r .gnu.hash .dynstr .rela.dyn .rela.plt .rodata .eh_frame_hdr .eh_frame
   02     .text .plt
   03     .data.rel.ro .fini_array .init_array .dynamic .got .got.plt
...

The above output tells us:
1. .text will wind up in the third (02) segment.
2. The third segment will be (LOAD)'ed as (E)xecutable.
3. Because the file (Offset) of the first segment (0x41b40) is NOT a
   multiple of the page size, it cannot be passed as the `offset` to
   `mmap`. As such it will be rounded down to the first multiple of the
   page size, 0x41000.
4. The preceding section (.eh_frame) will be loaded in the preceding
   segment (01). It occupies file (Off)set range [(0x2e7c0):0x41b34].
   0x41b34 is not explicit in the output, instead you must use the
   formula:
     Off     + Size    == End
   ie.
     0x2e7c0 + 0x13374 == 0x41b34
   (This happens to match (FileSiz) of the second segment, which makes
   sense as .eh_frame is the final section in the second segment.)
5. mmap'ing file offset 0x41000 when loading the second segment will
   include 0x4c0 bytes (0x42000 - 0x41b40) from .text, now mapped as
   readable (oops). Suddenly code from .text is now readable (and thus
   scannable for gadgets for ROP chains).
6. mmap'ing file offset 0x41000 when loading the third segment will
   include 0xb34 bytes (0x41b34 - 0x41000) from .eh_frame, now mapped as
   executable (oops). Suddenly data from .eh_frame is now executable
   (and thus a potential gadget for ROP chains).
7. mmap'ing file offset 0xe2000 when loading the third segment will
   include 0x8CO bytes (0xe3000 - 0xe2740) from .data.rel.ro, now mapped
   as executable (oops). Suddenly data from .data.rel.ro is now
   executable (and thus a potential gadget for ROP chains).
8. mmap'ing file offset 0xe2000 when loading the fourth segment will
   include 0x730 bytes (0xe0800 + 0x1f30 - 0xe2000) from .plt, now
   mapped as readable (oops). Suddenly data from .plt is now readable
   (and thus scannable for gadgets for ROP chains).

All these oops' could be avoided if the linker placed .text+.plt at page
size aligned file offsets, which is what `-Wl,-z,separate-code` code
does.  After this patch, we have:

```
$ readelf -lSW $OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so
...
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x000230 0x000230 R   0x8
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x041b34 0x041b34 R   0x1000
  LOAD           0x042000 0x0000000000042000 0x0000000000042000 0x0a0be0 0x0a0be0   E 0x1000
  LOAD           0x0e3000 0x00000000000e3000 0x00000000000e3000 0x006720 0x006720 RW  0x1000
```

In the future, we could go back to tightly packing segments in the
binary if the runtime loader was improved to detect the previously
stated problem, and `memset` over the problematic ranges of the freshly
`mmap`ed pages (implying additional startup cost for reduced binary
size). This might save ~6 KB from each native binary, which adds up to
~17 MB for an AOSP image.

Also, prefer
-Wl,--execute-only
rather than
-Wl,-execute-only

Bug: 139945549
Bug: 146144180
Test: readelf -lSW $OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so
Change-Id: I64527e034ca3c71565ea52ed06f81f75d5216627
Reported-by: Ryan Prichard <rprichard@google.com>
Suggested-by: Fangrui Song <maskray@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2019-12-16 09:55:37 -08:00
Ivan Lozano
f1c8433b40 Add AArch64 device Rust toolchain.
Bug: 141207434
Test: build example rust device module.
Change-Id: I0932a614942bf4a4d4b6c153fcc4fc79c7f202bd
2019-09-24 10:35:28 -07:00