Skip to content

Commit b8de7cf

Browse files
[libc] unpoison memory returned by pipe syscall (#88942)
The memory sanitizer doesn't recognize the results of the pipe syscall as being initialized. This patch manually unpoisons that memory.
1 parent b8adf16 commit b8de7cf

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

libc/src/unistd/linux/pipe.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
13+
#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON
1314
#include "src/errno/libc_errno.h"
1415
#include <sys/syscall.h> // For syscall numbers.
1516

@@ -23,6 +24,7 @@ LLVM_LIBC_FUNCTION(int, pipe, (int pipefd[2])) {
2324
int ret = LIBC_NAMESPACE::syscall_impl<int>(
2425
SYS_pipe2, reinterpret_cast<long>(pipefd), 0);
2526
#endif
27+
MSAN_UNPOISON(pipefd, sizeof(int) * 2);
2628
if (ret < 0) {
2729
libc_errno = -ret;
2830
return -1;

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,7 @@ libc_support_library(
10411041
deps = [
10421042
":__support_common",
10431043
":__support_cpp_bit",
1044+
":__support_macros_sanitizer",
10441045
],
10451046
)
10461047

@@ -2998,6 +2999,7 @@ libc_function(
29982999
hdrs = ["src/unistd/pipe.h"],
29993000
deps = [
30003001
":__support_common",
3002+
":__support_macros_sanitizer",
30013003
":__support_osutil_syscall",
30023004
":errno",
30033005
],
@@ -3025,6 +3027,7 @@ libc_function(
30253027
}),
30263028
deps = [
30273029
":__support_common",
3030+
":__support_macros_sanitizer",
30283031
":__support_osutil_syscall",
30293032
":errno",
30303033
],

0 commit comments

Comments
 (0)