[profile] In Android, do not mkdir() dirs in GCOV_PREFIX

Summary:
In Android, attempting to mkdir() or even stat() top-level directories
like /data causes noisy selinux denials.  During whole-system coverage
instrumentation, this causes a deluge of noisy messages that drown out
legitimate selinux denials, that should be audited and fixed.

To avoid this, skip creating any directory in GCOV_PREFIX (thereby
assuming that it exists).

- Android platform ensures that the GCOV_PREFIX used in Android is
created and read/writable by all processes.
- This only affects the Android platform (by checking against
__ANDROID_API_FUTURE__) and for apps built with Clang coverage, the
runtime will still create any non-existent parent directories for the
coverage files.

Reviewers: srhines, davidxl

Subscribers: krytarowski, #sanitizers, danalbert, llvm-commits

Tags: #sanitizers, #llvm

Differential Revision: https://reviews.llvm.org/D65245

llvm-svn: 367064
This commit is contained in:
Pirama Arumuga Nainar
2019-07-25 22:10:56 +00:00
parent c07c83b162
commit 6caa8da072

View File

@@ -39,8 +39,25 @@ COMPILER_RT_WEAK unsigned lprofDirMode = 0755;
COMPILER_RT_VISIBILITY
void __llvm_profile_recursive_mkdir(char *path) {
int i;
int start = 1;
for (i = 1; path[i] != '\0'; ++i) {
#if defined(__ANDROID__) && defined(__ANDROID_API__) && \
defined(__ANDROID_API_FUTURE__) && \
__ANDROID_API__ == __ANDROID_API_FUTURE__
// Avoid spammy selinux denial messages in Android by not attempting to
// create directories in GCOV_PREFIX. These denials occur when creating (or
// even attempting to stat()) top-level directories like "/data".
//
// Do so by ignoring ${GCOV_PREFIX} when invoking mkdir().
const char *gcov_prefix = getenv("GCOV_PREFIX");
if (gcov_prefix != NULL) {
const int gcov_prefix_len = strlen(gcov_prefix);
if (strncmp(path, gcov_prefix, gcov_prefix_len) == 0)
start = gcov_prefix_len;
}
#endif
for (i = start; path[i] != '\0'; ++i) {
char save = path[i];
if (!IS_DIR_SEPARATOR(path[i]))
continue;