Skip to content

Commit

Permalink
[libc] unpoison memory returned by pipe syscall (llvm#88942)
Browse files Browse the repository at this point in the history
The memory sanitizer doesn't recognize the results of the pipe syscall
as being initialized. This patch manually unpoisons that memory.
  • Loading branch information
michaelrj-google authored Apr 18, 2024
1 parent b8adf16 commit b8de7cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libc/src/unistd/linux/pipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ libc_support_library(
deps = [
":__support_common",
":__support_cpp_bit",
":__support_macros_sanitizer",
],
)

Expand Down Expand Up @@ -2998,6 +2999,7 @@ libc_function(
hdrs = ["src/unistd/pipe.h"],
deps = [
":__support_common",
":__support_macros_sanitizer",
":__support_osutil_syscall",
":errno",
],
Expand Down Expand Up @@ -3025,6 +3027,7 @@ libc_function(
}),
deps = [
":__support_common",
":__support_macros_sanitizer",
":__support_osutil_syscall",
":errno",
],
Expand Down

0 comments on commit b8de7cf

Please sign in to comment.