Skip to content

Commit c00d9c0

Browse files
author
Android Build Coastguard Worker
committed
Snap for 10201233 from da292f0 to u-keystone-qcom-release
Change-Id: I7981d01a8668b8ed11eb6c84ace0926a79d83c6f
2 parents fb2fa73 + da292f0 commit c00d9c0

File tree

4 files changed

+19
-37
lines changed

4 files changed

+19
-37
lines changed

libc/bionic/gwp_asan_wrappers.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,8 @@ bool GetGwpAsanOptionImpl(char* value_out,
307307
sysprop_names[3] = persist_default_sysprop;
308308
}
309309

310-
// TODO(mitchp): Log overrides using this.
311-
const char* source;
312310
return get_config_from_env_or_sysprops(env_var, sysprop_names, arraysize(sysprop_names),
313-
value_out, PROP_VALUE_MAX, &source);
311+
value_out, PROP_VALUE_MAX);
314312
}
315313

316314
bool GetGwpAsanIntegerOption(unsigned long long* result,

libc/bionic/libc_init_static.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,16 @@ static unsigned __get_memtag_note(const ElfW(Phdr)* phdr_start, size_t phdr_ct,
217217
// Returns true if there's an environment setting (either sysprop or env var)
218218
// that should overwrite the ELF note, and places the equivalent heap tagging
219219
// level into *level.
220-
static bool get_environment_memtag_setting(const char* basename, HeapTaggingLevel* level) {
220+
static bool get_environment_memtag_setting(HeapTaggingLevel* level) {
221221
static const char kMemtagPrognameSyspropPrefix[] = "arm64.memtag.process.";
222222
static const char kMemtagGlobalSysprop[] = "persist.arm64.memtag.default";
223223
static const char kMemtagOverrideSyspropPrefix[] =
224224
"persist.device_config.memory_safety_native.mode_override.process.";
225225

226-
if (basename == nullptr) return false;
226+
const char* progname = __libc_shared_globals()->init_progname;
227+
if (progname == nullptr) return false;
228+
229+
const char* basename = __gnu_basename(progname);
227230

228231
char options_str[PROP_VALUE_MAX];
229232
char sysprop_name[512];
@@ -234,9 +237,8 @@ static bool get_environment_memtag_setting(const char* basename, HeapTaggingLeve
234237
kMemtagOverrideSyspropPrefix, basename);
235238
const char* sys_prop_names[] = {sysprop_name, remote_sysprop_name, kMemtagGlobalSysprop};
236239

237-
const char* source = nullptr;
238240
if (!get_config_from_env_or_sysprops("MEMTAG_OPTIONS", sys_prop_names, arraysize(sys_prop_names),
239-
options_str, sizeof(options_str), &source)) {
241+
options_str, sizeof(options_str))) {
240242
return false;
241243
}
242244

@@ -247,35 +249,27 @@ static bool get_environment_memtag_setting(const char* basename, HeapTaggingLeve
247249
} else if (strcmp("off", options_str) == 0) {
248250
*level = M_HEAP_TAGGING_LEVEL_TBI;
249251
} else {
250-
async_safe_format_log(ANDROID_LOG_ERROR, "libc",
251-
"%s: unrecognized memtag level in %s: \"%s\" (options are \"sync\", "
252-
"\"async\", or \"off\").",
253-
basename, source, options_str);
252+
async_safe_format_log(
253+
ANDROID_LOG_ERROR, "libc",
254+
"unrecognized memtag level: \"%s\" (options are \"sync\", \"async\", or \"off\").",
255+
options_str);
254256
return false;
255257
}
256-
async_safe_format_log(ANDROID_LOG_DEBUG, "libc", "%s: chose memtag level \"%s\" from %s.",
257-
basename, options_str, source);
258-
return true;
259-
}
260258

261-
static void log_elf_memtag_level(const char* basename, const char* level) {
262-
async_safe_format_log(ANDROID_LOG_DEBUG, "libc", "%s: chose memtag level \"%s\" from ELF note",
263-
basename ?: "<unknown>", level);
259+
return true;
264260
}
265261

266262
// Returns the initial heap tagging level. Note: This function will never return
267263
// M_HEAP_TAGGING_LEVEL_NONE, if MTE isn't enabled for this process we enable
268264
// M_HEAP_TAGGING_LEVEL_TBI.
269265
static HeapTaggingLevel __get_heap_tagging_level(const void* phdr_start, size_t phdr_ct,
270266
uintptr_t load_bias, bool* stack) {
271-
const char* progname = __libc_shared_globals()->init_progname;
272-
const char* basename = progname ? __gnu_basename(progname) : nullptr;
273267
unsigned note_val =
274268
__get_memtag_note(reinterpret_cast<const ElfW(Phdr)*>(phdr_start), phdr_ct, load_bias);
275269
*stack = note_val & NT_MEMTAG_STACK;
276270

277271
HeapTaggingLevel level;
278-
if (get_environment_memtag_setting(basename, &level)) return level;
272+
if (get_environment_memtag_setting(&level)) return level;
279273

280274
// Note, previously (in Android 12), any value outside of bits [0..3] resulted
281275
// in a check-fail. In order to be permissive of further extensions, we
@@ -290,17 +284,14 @@ static HeapTaggingLevel __get_heap_tagging_level(const void* phdr_start, size_t
290284
// by anyone, but we note it (heh) here for posterity, in case the zero
291285
// level becomes meaningful, and binaries with this note can be executed
292286
// on Android 12 devices.
293-
log_elf_memtag_level(basename, "off");
294287
return M_HEAP_TAGGING_LEVEL_TBI;
295288
case NT_MEMTAG_LEVEL_ASYNC:
296-
log_elf_memtag_level(basename, "async");
297289
return M_HEAP_TAGGING_LEVEL_ASYNC;
298290
case NT_MEMTAG_LEVEL_SYNC:
299291
default:
300292
// We allow future extensions to specify mode 3 (currently unused), with
301293
// the idea that it might be used for ASYMM mode or something else. On
302294
// this version of Android, it falls back to SYNC mode.
303-
log_elf_memtag_level(basename, "sync");
304295
return M_HEAP_TAGGING_LEVEL_SYNC;
305296
}
306297
}

libc/bionic/sysprop_helpers.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,18 @@ static bool get_property_value(const char* property_name, char* dest, size_t des
5757
}
5858

5959
bool get_config_from_env_or_sysprops(const char* env_var_name, const char* const* sys_prop_names,
60-
size_t sys_prop_names_size, char* options, size_t options_size,
61-
const char** chosen_source) {
60+
size_t sys_prop_names_size, char* options,
61+
size_t options_size) {
6262
const char* env = getenv(env_var_name);
6363
if (env && *env != '\0') {
6464
strncpy(options, env, options_size);
6565
options[options_size - 1] = '\0'; // Ensure null-termination.
66-
*chosen_source = env_var_name;
6766
return true;
6867
}
6968

7069
for (size_t i = 0; i < sys_prop_names_size; ++i) {
7170
if (sys_prop_names[i] == nullptr) continue;
72-
if (get_property_value(sys_prop_names[i], options, options_size)) {
73-
*chosen_source = sys_prop_names[i];
74-
return true;
75-
}
71+
if (get_property_value(sys_prop_names[i], options, options_size)) return true;
7672
}
7773
return false;
7874
}

libc/bionic/sysprop_helpers.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,10 @@
3636
// 2. System properties, in the order they're specified in sys_prop_names.
3737
// If neither of these options are specified (or they're both an empty string),
3838
// this function returns false. Otherwise, it returns true, and the presiding
39-
// options string is written to the `options` buffer of size `size`. It will
40-
// store a pointer to either env_var_name, or into the relevant entry of
41-
// sys_prop_names into choicen_source, indiciating which value was used. If
42-
// this function returns true, `options` is guaranteed to be null-terminated.
39+
// options string is written to the `options` buffer of size `size`. If this
40+
// function returns true, `options` is guaranteed to be null-terminated.
4341
// `options_size` should be at least PROP_VALUE_MAX.
4442
__LIBC_HIDDEN__ bool get_config_from_env_or_sysprops(const char* env_var_name,
4543
const char* const* sys_prop_names,
4644
size_t sys_prop_names_size, char* options,
47-
size_t options_size,
48-
const char** chosen_source);
45+
size_t options_size);

0 commit comments

Comments
 (0)