[compiler-rt] [sanitizer] Disable writes to log files for binaries in a secure context. (PR #92593)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 17 16:23:49 PDT 2024
https://github.com/bigb4ng updated https://github.com/llvm/llvm-project/pull/92593
>From ca9856c2f6616851bfd0bc6aac351bb6f2742fd8 Mon Sep 17 00:00:00 2001
From: bigb4ng <130478744+bigb4ng at users.noreply.github.com>
Date: Fri, 17 May 2024 07:26:39 +0300
Subject: [PATCH] [sanitizer] Disable using log_path with AT_SECURE.
Fix for https://github.com/google/sanitizers/issues/1130.
An original issue described by Szabolcs Nagy at https://seclists.org/oss-sec/2016/q1/363.
---
.../lib/sanitizer_common/sanitizer_file.cpp | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
index 7ef499ce07b13..3c0e0b8d5cc59 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_file.cpp
@@ -17,8 +17,9 @@
#if !SANITIZER_FUCHSIA
-#include "sanitizer_common.h"
-#include "sanitizer_file.h"
+# include "sanitizer_common.h"
+# include "sanitizer_file.h"
+# include "sanitizer_getauxval.h"
# include "sanitizer_interface_internal.h"
namespace __sanitizer {
@@ -104,6 +105,17 @@ void ReportFile::SetReportPath(const char *path) {
}
}
+ // This is so we can use the weak definition from sanitizer_getauxval.h
+ if (&getauxval && getauxval(/* AT_SECURE */ 23) != 0 && path &&
+ internal_strcmp(path, "stderr") != 0 &&
+ internal_strcmp(path, "stdout") != 0) {
+ Report(
+ "ERROR: log_path must be 'stderr' or 'stdout' for AT_SECURE "
+ "(e.g. setuid binaries), is '%s'\n",
+ path);
+ Die();
+ }
+
SpinMutexLock l(mu);
if (fd != kStdoutFd && fd != kStderrFd && fd != kInvalidFd)
CloseFile(fd);
More information about the llvm-commits
mailing list