[libc-commits] [libc] [libc] Fix pread under msan (PR #80893)
via libc-commits
libc-commits at lists.llvm.org
Tue Feb 6 10:38:16 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: None (michaelrj-google)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/80893.diff
2 Files Affected:
- (modified) libc/src/unistd/linux/CMakeLists.txt (+2)
- (modified) libc/src/unistd/linux/pread.cpp (+4-1)
``````````diff
diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt
index 42190079141b0..df85d44e9e9ed 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 614de9732c627..11cefc5c2f3a8 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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/80893
More information about the libc-commits
mailing list