diff options
author | Peter Collingbourne <pcc@google.com> | 2021-07-08 00:45:56 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-07-08 00:45:56 +0000 |
commit | e33a6fc3e8e823e1ca3d90139a14c94dfa1be4ca (patch) | |
tree | f20b75c58f76c5e1c8a5c56058978e21702004c8 | |
parent | ffed9fed90d3d6c4a54e168ba19224185f95a6f0 (diff) | |
parent | 4683b113906c6b4c252929876b16b5967aa0cbe0 (diff) | |
download | bionic-e33a6fc3e8e823e1ca3d90139a14c94dfa1be4ca.tar.gz |
Merge "Allow the kernel to upgrade ASYNC mode processes to SYNC mode." into sc-dev am: 4683b11390
Original change: https://googleplex-android-review.googlesource.com/c/platform/bionic/+/15223414
Change-Id: Ie00b3bf1f9840963cb1b596a16b53dc4ff4301e9
-rw-r--r-- | libc/bionic/heap_tagging.cpp | 7 | ||||
-rw-r--r-- | libc/bionic/libc_init_static.cpp | 6 |
2 files changed, 11 insertions, 2 deletions
diff --git a/libc/bionic/heap_tagging.cpp b/libc/bionic/heap_tagging.cpp index ffbabb9a0..41aa20507 100644 --- a/libc/bionic/heap_tagging.cpp +++ b/libc/bionic/heap_tagging.cpp @@ -139,7 +139,12 @@ bool SetHeapTaggingLevel(HeapTaggingLevel tag_level) { } if (tag_level == M_HEAP_TAGGING_LEVEL_ASYNC) { - set_tcf_on_all_threads(PR_MTE_TCF_ASYNC); + // When entering ASYNC mode, specify that we want to allow upgrading to SYNC by OR'ing in + // the SYNC flag. But if the kernel doesn't support specifying multiple TCF modes, fall back + // to specifying a single mode. + if (!set_tcf_on_all_threads(PR_MTE_TCF_ASYNC | PR_MTE_TCF_SYNC)) { + set_tcf_on_all_threads(PR_MTE_TCF_ASYNC); + } #if defined(USE_SCUDO) scudo_malloc_set_track_allocation_stacks(0); #endif diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp index 069ebb0ab..3a8513f98 100644 --- a/libc/bionic/libc_init_static.cpp +++ b/libc/bionic/libc_init_static.cpp @@ -311,7 +311,11 @@ __attribute__((no_sanitize("hwaddress", "memtag"))) void __libc_init_mte(const v unsigned long prctl_arg = PR_TAGGED_ADDR_ENABLE | PR_MTE_TAG_SET_NONZERO; prctl_arg |= (level == M_HEAP_TAGGING_LEVEL_SYNC) ? PR_MTE_TCF_SYNC : PR_MTE_TCF_ASYNC; - if (prctl(PR_SET_TAGGED_ADDR_CTRL, prctl_arg, 0, 0, 0) == 0) { + // When entering ASYNC mode, specify that we want to allow upgrading to SYNC by OR'ing in the + // SYNC flag. But if the kernel doesn't support specifying multiple TCF modes, fall back to + // specifying a single mode. + if (prctl(PR_SET_TAGGED_ADDR_CTRL, prctl_arg | PR_MTE_TCF_SYNC, 0, 0, 0) == 0 || + prctl(PR_SET_TAGGED_ADDR_CTRL, prctl_arg, 0, 0, 0) == 0) { __libc_shared_globals()->initial_heap_tagging_level = level; return; } |