Skip to content

Commit c6691f6

Browse files
[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.
1 parent 5f87957 commit c6691f6

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

libc/src/unistd/linux/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ add_entrypoint_object(
283283
libc.include.unistd
284284
libc.include.sys_syscall
285285
libc.src.__support.OSUtil.osutil
286+
libc.src.__support.macros.sanitizer
286287
libc.src.errno.errno
287288
)
288289

@@ -309,6 +310,7 @@ add_entrypoint_object(
309310
libc.include.unistd
310311
libc.include.sys_syscall
311312
libc.src.__support.OSUtil.osutil
313+
libc.src.__support.macros.sanitizer
312314
libc.src.errno.errno
313315
)
314316

libc/src/unistd/linux/pread.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "src/__support/OSUtil/syscall.h" // For internal syscall function.
1212
#include "src/__support/common.h"
13-
13+
#include "src/__support/macros/sanitizer.h" // for MSAN_UNPOISON
1414
#include "src/errno/libc_errno.h"
1515
#include <stdint.h> // For uint64_t.
1616
#include <sys/syscall.h> // For syscall numbers.
@@ -28,6 +28,9 @@ LLVM_LIBC_FUNCTION(ssize_t, pread,
2828
ssize_t ret = LIBC_NAMESPACE::syscall_impl<ssize_t>(SYS_pread64, fd, buf,
2929
count, offset);
3030
#endif
31+
// The cast is important since there is a check that dereferences the pointer
32+
// which fails on void*.
33+
MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
3134
if (ret < 0) {
3235
libc_errno = static_cast<int>(-ret);
3336
return -1;

0 commit comments

Comments
 (0)