[libc-commits] [libc] c6691f6 - [libc] Fix pread under msan (#80893)

via libc-commits libc-commits at lists.llvm.org
Tue Feb 6 11:17:03 PST 2024


Author: michaelrj-google
Date: 2024-02-06T11:16:59-08:00
New Revision: c6691f689e9aa787b809fd3493bae8a5ca845cea

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

LOG: [libc] Fix pread under msan (#80893)

The pread function wasn't properly unpoisoning its result under msan,
causing test failures downstream when I tried to roll it out. This patch
adds the msan unpoison call that fixes the issue.

Added: 
    

Modified: 
    libc/src/unistd/linux/CMakeLists.txt
    libc/src/unistd/linux/pread.cpp

Removed: 
    


################################################################################
diff  --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 42190079141b06..df85d44e9e9edc 100644
--- a/libc/src/unistd/linux/CMakeLists.txt
+++ b/libc/src/unistd/linux/CMakeLists.txt
@@ -283,6 +283,7 @@ add_entrypoint_object(
     libc.include.unistd
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
+    libc.src.__support.macros.sanitizer
     libc.src.errno.errno
 )
 
@@ -309,6 +310,7 @@ add_entrypoint_object(
     libc.include.unistd
     libc.include.sys_syscall
     libc.src.__support.OSUtil.osutil
+    libc.src.__support.macros.sanitizer
     libc.src.errno.errno
 )
 

diff  --git a/libc/src/unistd/linux/pread.cpp b/libc/src/unistd/linux/pread.cpp
index 614de9732c6271..11cefc5c2f3a89 100644
--- a/libc/src/unistd/linux/pread.cpp
+++ b/libc/src/unistd/linux/pread.cpp
@@ -10,7 +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 <stdint.h>      // For uint64_t.
 #include <sys/syscall.h> // For syscall numbers.
@@ -28,6 +28,9 @@ LLVM_LIBC_FUNCTION(ssize_t, pread,
   ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_pread64, fd, buf,
                                                       count, offset);
 #endif
+  // The cast is important since there is a check that dereferences the pointer
+  // which fails on void*.
+  MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
   if (ret < 0) {
     libc_errno = static_cast<int>(-ret);
     return -1;


        


More information about the libc-commits mailing list