Commit graph

2252 commits

Author SHA1 Message Date
Kelvin Zhang
f48bd84efc Merge "Check for mprotect result" into main am: 0b2996f144 am: fd88338ed7 am: bb9ceed708 am: 4917ef4f28 am: 9bfc89f9c3 am: d527e08d47
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2654229

Change-Id: I3dd97860caad449924adb5f4794de63dc9ea694e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 06:00:56 +00:00
Kelvin Zhang
4917ef4f28 Merge "Check for mprotect result" into main am: 0b2996f144 am: fd88338ed7 am: bb9ceed708
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2654229

Change-Id: Ib82d7a96364fc94e394175785db37ac6132b2ff5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-07-12 03:41:53 +00:00
Kelvin Zhang
fd93b6031e Check for mprotect result
Failure to mark shadow stack page as writable will result in a SEGV
fault later when a function tries to save return addresses to shadow
stack. The engineer looking at the crash report would be very confused
because the program crashes at very beginning of an innocent looking
function. For ease of debugging, check for shadow stack errors early.

Test: th
Bug: 279808236
Bug: 253652966
Change-Id: Id2da68fa984b5dfb1846ed14aa7ededee7f2508f
2023-07-11 15:42:32 -07:00
Steven Moreland
4b3d3fa472 Merge "Revert^2 "fdsan android::Parcel"" 2023-06-30 17:02:54 +00:00
Florian Mayer
28f93db5a7 Merge "[HWASan] add comment to explain why we can use __has_feature" am: 26e0e00279 am: f04c163217 am: 8d60940a21
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2636328

Change-Id: Iaf1938cc09d60b775134d703b7d9324fcd8aa07f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-23 03:50:10 +00:00
Florian Mayer
26e0e00279 Merge "[HWASan] add comment to explain why we can use __has_feature" 2023-06-23 01:16:22 +00:00
Steven Moreland
1d413fce69 Revert^2 "fdsan android::Parcel"
7836677d99

Change-Id: If972bf911fd61286780a7c9800239b83ecddccab
2023-06-22 23:03:57 +00:00
Florian Mayer
02108ce6b1 [HWASan] add comment to explain why we can use __has_feature
Bug: 276930343
Change-Id: I0b3e152269a147f67cae3c534be92ee169fe393b
2023-06-22 14:56:18 -07:00
Priyanka Advani
7836677d99 Revert "fdsan android::Parcel"
Revert submission 23699976-fdsan-parcel

Reason for revert: Possible culprit for b/288448299

Reverted changes: /q/submissionid:23699976-fdsan-parcel

Change-Id: I709d2629755b7d014763a7bbd03a65d9f6e7efa7
2023-06-22 21:22:35 +00:00
Christopher Ferris
0ceeea5a49 Merge "Add new mallopt M_LOG_STATS." am: 90e2827762 am: 29bedad140 am: 1e364e01b8
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2585453

Change-Id: Ia79a45c3a23c008e0c22cfb7e2c5e4ee000aa6f4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-20 22:42:53 +00:00
Christopher Ferris
e9a7b81d4a Add new mallopt M_LOG_STATS.
This new mallopt cause statistics of the allocator to be printed in
the log.

Add a stats print for jemalloc.

This is designed to be used as part of a dumpsys meminfo --XXXX
option so that it's easier to get information about apps that
have an unusual memory footprint.

Test: Unit tests pass.
Test: Ran on a device using jemalloc and verified log data.
Test: Ran on a device using scudo and verified log data.
Change-Id: I6fa44ce619c064b2596fbbb478c231994af94f4c
2023-06-17 00:00:02 +00:00
Elliott Hughes
bc93a2acf2 Merge "Expose tzalloc()/localtime_rz()/mktime_z()/tzfree()." am: f5cd29269f am: 472f1d099e am: ecb17c8cf4
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2626240

Change-Id: I1cebfa0141dc9ed977927f88ba5813f18427deda
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-16 17:40:04 +00:00
Elliott Hughes
f5cd29269f Merge "Expose tzalloc()/localtime_rz()/mktime_z()/tzfree()." 2023-06-16 15:14:24 +00:00
Elliott Hughes
2bd4316bd6 Expose tzalloc()/localtime_rz()/mktime_z()/tzfree().
* Rationale

The question often comes up of how to use multiple time zones in C code.
If you're single-threaded, you can just use setenv() to manipulate $TZ.
toybox does this, for example. But that's not thread-safe in two
distinct ways: firstly, getenv() is not thread-safe with respect to
modifications to the environment (and between the way putenv() is
specified and the existence of environ, it's not obvious how to fully
fix that), and secondly the _caller_ needs to ensure that no other
threads are using tzset() or any function that behaves "as if" tzset()
was called (which is neither easy to determine nor easy to ensure).

This isn't a bigger problem because most of the time the right answer
is to stop pretending that libc is at all suitable for any i18n, and
switch to icu4c instead. (The NDK icu4c headers do not include ucal_*,
so this is not a realistic option for most applications.)

But what if you're somewhere in between? Like the rust chrono library,
for example? What then?

Currently their "least worst" option is to reinvent the entire wheel and
read our tzdata files. Which isn't a great solution for anyone, for
obvious maintainability reasons.

So it's probably time we broke the catch-22 here and joined NetBSD in
offering a less broken API than standard C has for the last 40 years.
Sure, any would-be caller will have to have a separate "is this
Android?" and even "is this API level >= 35?" path, but that will fix
itself sometime in the 2030s when developers can just assume "yes, it
is", whereas if we keep putting off exposing anything, this problem
never gets solved.

(No-one's bothered to try to implement the std::chrono::time_zone
functionality in libc++ yet, but they'll face a similar problem if/when
they do.)

* Implementation

The good news is that tzcode already implements these functions, so
there's relatively little here.

I've chosen not to expose `struct state` because `struct __timezone_t`
makes for clearer error messages, given that compiler diagnostics will
show the underlying type name (`struct __timezone_t*`) rather than the
typedef name (`timezone_t`) that's used in calling code.

I've moved us over to FreeBSD's wcsftime() rather than keep the OpenBSD
one building --- I've long wanted to only have one implementation here,
and FreeBSD is already doing the "convert back and forth, calling the
non-wide function in the middle" dance that I'd hoped to get round to
doing myself someday. This should mean that our strftime() and
wcsftime() behaviors can't easily diverge in future, plus macOS/iOS are
mostly FreeBSD, so any bugs will likely be interoperable with the other
major mobile operating system, so there's something nice for everyone
there!

The FreeBSD wcsftime() implementation includes a wcsftime_l()
implementation, so that's one stub we can remove. The flip side of that
is that it uses mbsrtowcs_l() and wcsrtombs_l() which we didn't
previously have. So expose those as aliases of mbsrtowcs() and
wcsrtombs().

Bug: https://github.com/chronotope/chrono/issues/499
Test: treehugger
Change-Id: Iee1b9d763ead15eef3d2c33666b3403b68940c3c
2023-06-16 08:10:47 -07:00
Dimitry Ivanov
29fd8c0fbc Merge "Use more appropriate param type for __early_abort" am: 81d1e3df44 am: 344ab813b3 am: f11be221ad
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2627970

Change-Id: I35788ec65d04d2a3de62ffb8b2955ce8c571852a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-16 11:59:58 +00:00
dimitry
e07704aa6e Use more appropriate param type for __early_abort
Test: build, start emulator
Change-Id: I5f31ceb9a85ee7750f17edff76782c778a4515d8
2023-06-15 14:40:42 +00:00
Steven Moreland
94e2325940 fdsan android::Parcel
Parcel manages ownership of FDs from the binder kernel
in a complicated way. Since sizeof(Parcel) is frozen
in the ABI right now, and we can't allocate more things
on the heap in Parcel, we need to keep on managing
FD ownership manually there.

Ignore-AOSP-First: this requires some fixes only in
  git_master to avoid crashing

Bug: 287093457
Test: boot
Change-Id: I4976507727899f1bb09de41e97f329bee58a4572
2023-06-14 23:36:24 +00:00
Elliott Hughes
4250ecf354 Merge "Remove PAGE_SIZE call sites." am: 826ea44822 am: 891e3b0aa8 am: efbf89a550
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2083840

Change-Id: If14df13789935e08a8dd8f50fb91bf4699d17cda
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-13 22:41:51 +00:00
Peter Collingbourne
bb11ee6d9c Remove PAGE_SIZE call sites.
To enable experiments with non-4KiB page sizes, introduce
an inline page_size() function that will either return the runtime
page size (if PAGE_SIZE is not 4096) or a constant 4096 (elsewhere).
This should ensure that there are no changes to the generated code on
unaffected platforms.

Test: source build/envsetup.sh
      lunch aosp_cf_arm64_16k_phone-userdebug
      m -j32 installclean
      m -j32
Test: launch_cvd \
  -kernel_path /path/to/out/android14-5.15/dist/Image \
  -initramfs_path /path/to/out/android14-5.15/dist/initramfs.img \
  -userdata_format=ext4
Bug: 277272383
Bug: 230790254
Change-Id: Ic0ed98b67f7c6b845804b90a4e16649f2fc94028
2023-06-12 10:59:39 -07:00
Elliott Hughes
21894a6756 Merge "Remove __RENAME_LDBL." am: 87e170df01 am: e6351fb5f0 am: 8db2935824
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2619230

Change-Id: Id8878f6a19a428de18ab006aa9eda715bc1e2e64
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-06-09 15:53:57 +00:00
Elliott Hughes
ab2d3e1049 Remove __RENAME_LDBL.
Discussion of this during my recent minor cleanup convinced me that we
should just remove __RENAME_LDBL. There's no obvious benefit to being
able to build something for 32-bit if you can't build the same code for
64-bit, given that most new hardware (and entire verticals such as Auto)
are 64-bit-only, and the Play Store requires any app with 32-bit code to
also ship 64-bit code.

Test: treehugger
Change-Id: I1c5503b968ca66925d7bd125bd3630c41ec1bfd0
2023-06-07 17:20:53 +00:00
Florian Mayer
fbc2a7dcd2 Merge "Revert "Add debug logging for memtag level"" am: e20c5fa4ac am: ba681ceaec am: 60388bf04a
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2595472

Change-Id: Id284004406f6ac9c40cbe66a361cd85763e2a71f
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-05-18 04:24:20 +00:00
Florian Mayer
e20c5fa4ac Merge "Revert "Add debug logging for memtag level"" 2023-05-18 01:06:23 +00:00
Florian Mayer
dd44378da7 Revert "Add debug logging for memtag level"
This reverts commit b3f3e86878.

Reason for revert: This created spam in tombstones.

Change-Id: Ia7b8285a6abd6f89d49859a981be1c9cfa104f81
2023-05-17 20:59:14 +00:00
Treehugger Robot
5f421c586b Merge "riscv64: say "x3" rather than "gp" in shadow call stack assembler." am: ad333b6161 am: 7e6e6d64ee am: 54b76d6a2b
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2592806

Change-Id: I8465f12ba1f4d1db23915b9c6ed4c4c6a7591075
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-05-17 19:03:39 +00:00
Elliott Hughes
c35a0dc08e riscv64: say "x3" rather than "gp" in shadow call stack assembler.
Neither is great, but "gp" seems actively misleading (and setjmp.S
says x3 every time, so we should be consistent if nothing else).

Bug: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/379
Test: treehugger
Change-Id: Ibccda74d4794caa770b82e7ba2e31ce7b645b83f
2023-05-16 16:09:30 -07:00
Treehugger Robot
8e3529f757 Merge "Make fork equivalent to vfork when HWASan or MTE stack tagging is enabled." am: 68904aee7b am: 52a892139c am: 8e7d2d4bb0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2507976

Change-Id: If43865e657a8c7862e1ac76a4f071ab28cf8ade9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-05-09 02:59:50 +00:00
Treehugger Robot
68904aee7b Merge "Make fork equivalent to vfork when HWASan or MTE stack tagging is enabled." 2023-05-09 00:53:48 +00:00
Peter Collingbourne
b6a592b25b Make fork equivalent to vfork when HWASan or MTE stack tagging is enabled.
Bug: 274056091
Change-Id: Iac029ca6b0e26f57f20c0a54822b75e3cae67344
2023-05-08 15:26:00 -07:00
Elliott Hughes
640eabdee8 Merge "<time.h>: change the new C23 TIME_ constants." am: e023a02cce am: d0268a32bc am: 145cf9ecc0
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2576754

Change-Id: I0d6b6f0182e0f447f38239799073e89eee7c2ac0
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-05-04 20:00:03 +00:00
Elliott Hughes
e023a02cce Merge "<time.h>: change the new C23 TIME_ constants." 2023-05-04 17:35:17 +00:00
Elliott Hughes
3ee91eaa43 Merge "syslog.h: implement LOG_PERROR." am: 1dff230f75 am: b6ce42afdd am: 0e55347f45
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2465131

Change-Id: I9e248a93bb7c26a13872b4ee645233a516038f16
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-05-04 17:12:19 +00:00
Elliott Hughes
7db0a6cc5f <time.h>: change the new C23 TIME_ constants.
Jens Gustedt suggested a better implementation last year on the musl
mailing list: https://www.openwall.com/lists/musl/2022/11/19/1

It means the constants are sparse, but in return it means we can add
future constants and they'll be backward compatible. (Sadly you'll need
to be on API level 35 before you can use anything but TIME_UTC.)

I doubt this will ever matter, because everyone should just stick to
clock_gettime()/clock_getres() anyway, and anyone who does have a
legitimate use for timespec_get() and timespec_getres() probably needs
to support non-Linux and so can't use any clocks that aren't in ISO C
anyway. But given that we don't _have_ to paint ourselves into a corner
here, we may as well take the opportunity to not do so.

Test: strace
Change-Id: I293d32fcbcf7f6703564dac0978ae2a10192a482
2023-05-03 15:37:46 -07:00
Elliott Hughes
213d943a33 syslog.h: implement LOG_PERROR.
This is the one openlog() flag that toybox uses. We should probably try
to unify toybox's POSIX logger and Android-specific log at some point,
and this will help.

Also fix our behavior with an empty format string, noticed while adding
tests.

Test: treehugger
Test: adb shell logger -s foo
Change-Id: Ic027e78a460be3db83cc4c6f9946c9efa22be6e1
2023-05-03 14:19:40 -07:00
Elliott Hughes
b24caabefc Merge "C23: add timespec_getres() and the new TIME_* constants." am: 0593e7922f am: fede367249 am: af3436f9bd
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2560172

Change-Id: I853f5ce436663f46fa991b86ae14916086350207
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-27 18:02:06 +00:00
Elliott Hughes
52541eea33 C23: add timespec_getres() and the new TIME_* constants.
Nothing to see here --- you'll want to keep using POSIX clock_gettime()
and clock_getres() instead. But portable code might use this eventually,
and it's trivial, so let's add it anyway.

(The whole "zero as an error return" precluding the direct use of
Linux's CLOCK_ constants is what really makes this a terrible API ---
we're going to have to add explicit translation any time they add a
new base.)

Test: treehugger
Change-Id: Iddb6cbe67b67b2b10fdd8b5ee654896d23deee47
2023-04-25 17:29:22 -07:00
Treehugger Robot
0a5eb724b5 Merge "riscv64: fix the name of Zisslpcfi." am: d3733e1edd am: 949a2b0d45 am: 73d0e3b87e
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2552295

Change-Id: Ic1a63dbf74ae3f94c7f815ba478c0b0c412575c6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-22 03:27:37 +00:00
Treehugger Robot
d3733e1edd Merge "riscv64: fix the name of Zisslpcfi." 2023-04-22 01:19:29 +00:00
Elliott Hughes
7663578d73 riscv64: fix the name of Zisslpcfi.
Love these risc-v extension names!

Test: N/A
Change-Id: Ieb13f82a507aa11d79650b2cf627e68f213d6a79
2023-04-21 15:32:46 -07:00
Elliott Hughes
0ea424a7ec Merge "Make tmpfile() respect $TMPDIR." am: 17b2bae190 am: 4260d4d7eb am: 2aefec48a5
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2545855

Change-Id: Ic4ac021444440a0cfc5c029f0d5f4c5d211b748b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-19 22:46:42 +00:00
Elliott Hughes
17b2bae190 Merge "Make tmpfile() respect $TMPDIR." 2023-04-19 20:01:51 +00:00
Elliott Hughes
8b86c0bdeb Make tmpfile() respect $TMPDIR.
Contrary to the old comment, POSIX says nothing about whether or not
tmpfile() respects $TMPDIR, and it's significantly more useful on
Android if it does (because there's no shared /tmp that everyone can
write to).

Bug: https://issuetracker.google.com/36991167
Test: treehugger
Change-Id: I3cc45adff167420f100c8ed1c63cba1ea67e9f70
2023-04-18 17:11:06 -07:00
Florian Mayer
7aa49ba9f7 Merge "Introduce hwasan mode for linker" am: 4967017c86 am: c6c98f0053 am: b541b2ea65
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2526420

Change-Id: I17ed450781febfe7cd4d5a8fd22d4cfda462bd21
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-15 00:42:08 +00:00
Florian Mayer
4967017c86 Merge "Introduce hwasan mode for linker" 2023-04-14 23:27:56 +00:00
Florian Mayer
c10d064b5c Introduce hwasan mode for linker
This mode instructs the linker to search for libraries in hwasan
subdirectories of all library search paths. This is set up to contain a
hwasan-enabled copy of libc, which is needed for HWASan programs to
operate. There are two ways this mode can be enabled:

* for native binaries, by using the linker_hwasan64 symlink as its
  interpreter
* for apps: by setting the LD_HWASAN environment variable in wrap.sh

Bug: 276930343
Change-Id: I0f4117a50091616f26947fbe37a28ee573b97ad0
2023-04-14 01:33:30 -07:00
Elliott Hughes
fc51cac4e3 Merge "riscv64: switch from x18 to gp for shadow call stack." am: 4aa40a5f77 am: 23a6dcc453 am: 38c4e72f19
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2526531

Change-Id: I44a16f02692a2a4fec8ef32674a141ebf4b86a0e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-13 16:10:18 +00:00
Elliott Hughes
7dd3896fe1 riscv64: switch from x18 to gp for shadow call stack.
We want to give back a useful callee-saved general purpose
register (x18) that was only "chosen" because it was what llvm
allowed for historical reasons. gp is a better choice because it's
effectively unused otherwise anyway.

Unfortunately, that means we need extra space in jmp_buf (which I've
reserved in an earlier change, e7b3b8b467),
so let's rearrange the entries in jmp_buf to match their order in the
register file.

Bug: https://github.com/google/android-riscv64/issues/72
Bug: http://b/277909695
Test: treehugger
Change-Id: Ia629409a894c1a83d2052885702bbdd895c758e1
2023-04-12 14:19:38 -07:00
Elliott Hughes
e9b5ab48b3 Merge "<spawn.h>: add posix_spawn_file_actions_addchdir_np()/posix_spawn_file_actions_addfchdir_np()." am: 7b5cc4b251 am: be6c661e18 am: 485af5eed1
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2523159

Change-Id: I8f7622cdebde59e34cb31ff2dd40424019387c91
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-06 19:46:06 +00:00
Elliott Hughes
462ca8b314 <spawn.h>: add posix_spawn_file_actions_addchdir_np()/posix_spawn_file_actions_addfchdir_np().
The recent header nullability additions and the corresponding source
cleanup made me notice that we're missing a couple of actions that most
of the other implementations have. They've also been added to the _next_
revision of POSIX, unchanged except for the removal of the `_np` suffix.

They're trivial to implement, the testing is quite simple too, and
if they're going to be in POSIX soon, having them accessible in older
versions of Android via __RENAME() seems useful. (No-one else has shipped
the POSIX names yet.)

Bug: http://b/152414297
Test: treehugger
Change-Id: I0d2a1e47fbd2e826cff9c45038928aa1b6fcce59
2023-04-04 17:28:39 -07:00
Zijun Zhao
97a35e109d Merge "posix_spawn_file_actions_addopen(): crash early rather than late." am: 6ef483eb87 am: f658816d6b am: d7a95555c9
Original change: https://android-review.googlesource.com/c/platform/bionic/+/2515747

Change-Id: Ia6621ac5aeab2a043973903ddd30f7b5caea73b9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2023-04-01 01:55:42 +00:00