@@ -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.
269265static 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}
0 commit comments