-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc] unpoison memory returned by pipe syscall #88942
Conversation
The memory sanitizer doesn't recognize the results of the pipe syscall as being initialized. This patch manually unpoisons that memory.
@llvm/pr-subscribers-libc Author: Michael Jones (michaelrj-google) ChangesThe memory sanitizer doesn't recognize the results of the pipe syscall Full diff: https://github.com/llvm/llvm-project/pull/88942.diff 2 Files Affected:
diff --git a/libc/src/unistd/linux/pipe.cpp b/libc/src/unistd/linux/pipe.cpp
index b4e8b9b7d9c85e..8cfb8d1d5c2c13 100644
--- a/libc/src/unistd/linux/pipe.cpp
+++ b/libc/src/unistd/linux/pipe.cpp
@@ -10,6 +10,7 @@
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
#include "src/__support/common.h"
+#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON
#include "src/errno/libc_errno.h"
#include <sys/syscall.h> // For syscall numbers.
@@ -23,6 +24,7 @@ LLVM_LIBC_FUNCTION(int, pipe, (int pipefd[2])) {
int ret = LIBC_NAMESPACE::syscall_impl<int>(
SYS_pipe2, reinterpret_cast<long>(pipefd), 0);
#endif
+ MSAN_UNPOISON(pipefd, sizeof(int) * 2);
if (ret < 0) {
libc_errno = -ret;
return -1;
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index fb37f113b310a7..8caf8acdb7da08 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -786,7 +786,7 @@ libc_support_library(
":errno",
":hdr_fenv_macros",
":hdr_math_macros",
- ":types_fenv_t"
+ ":types_fenv_t",
],
)
@@ -1041,6 +1041,7 @@ libc_support_library(
deps = [
":__support_common",
":__support_cpp_bit",
+ ":__support_macros_sanitizer",
],
)
@@ -1262,7 +1263,7 @@ libc_function(
deps = [
":__support_common",
":__support_fputil_fenv_impl",
- ":types_fexcept_t"
+ ":types_fexcept_t",
],
)
@@ -1273,7 +1274,7 @@ libc_function(
deps = [
":__support_common",
":__support_fputil_fenv_impl",
- ":types_fexcept_t",
+ ":types_fexcept_t",
],
)
@@ -2987,6 +2988,7 @@ libc_function(
hdrs = ["src/unistd/pipe.h"],
deps = [
":__support_common",
+ ":__support_macros_sanitizer",
":__support_osutil_syscall",
":errno",
],
@@ -3014,6 +3016,7 @@ libc_function(
}),
deps = [
":__support_common",
+ ":__support_macros_sanitizer",
":__support_osutil_syscall",
":errno",
],
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+2 but cc @ramosian-glider since these changes are annoying to keep having to make. Are we "holding it wrong?" For instance, our syscall wrapper here treats all arguments as inputs.
But I suspect if we said the pipefd
param was an ouput with =D
(rather than an input with D
), perhaps msan would know that the kernel is expected to overwrite the output and DTRT?
Landing for now to unblock downstream. We can update this with a cleaner design later. |
The memory sanitizer doesn't recognize the results of the pipe syscall
as being initialized. This patch manually unpoisons that memory.