[libc-commits] [libc] b8de7cf - [libc] unpoison memory returned by pipe syscall (#88942)

via libc-commits libc-commits at lists.llvm.org
Thu Apr 18 13:36:22 PDT 2024


Author: Michael Jones
Date: 2024-04-18T13:36:18-07:00
New Revision: b8de7cf6588ebc95e33a0e4a5b4254a94df60e4e

URL: https://github.com/llvm/llvm-project/commit/b8de7cf6588ebc95e33a0e4a5b4254a94df60e4e
DIFF: https://github.com/llvm/llvm-project/commit/b8de7cf6588ebc95e33a0e4a5b4254a94df60e4e.diff

LOG: [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.

Added: 
    

Modified: 
    libc/src/unistd/linux/pipe.cpp
    utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Removed: 
    


################################################################################
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 be02c227043218..3df8341712aa93 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -1041,6 +1041,7 @@ libc_support_library(
     deps = [
         ":__support_common",
         ":__support_cpp_bit",
+        ":__support_macros_sanitizer",
     ],
 )
 
@@ -2998,6 +2999,7 @@ libc_function(
     hdrs = ["src/unistd/pipe.h"],
     deps = [
         ":__support_common",
+        ":__support_macros_sanitizer",
         ":__support_osutil_syscall",
         ":errno",
     ],
@@ -3025,6 +3027,7 @@ libc_function(
     }),
     deps = [
         ":__support_common",
+        ":__support_macros_sanitizer",
         ":__support_osutil_syscall",
         ":errno",
     ],


        


More information about the libc-commits mailing list