Skip to content

Commit 0e8eb44

Browse files
[libc] Fix read under msan (#80203)
The read 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 0e0d155 commit 0e8eb44

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

libc/src/unistd/linux/read.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 <sys/syscall.h> // For syscall numbers.
1616

@@ -22,6 +22,9 @@ LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) {
2222
libc_errno = static_cast<int>(-ret);
2323
return -1;
2424
}
25+
// The cast is important since there is a check that dereferences the pointer
26+
// which fails on void*.
27+
MSAN_UNPOISON(reinterpret_cast<char *>(buf), count);
2528
return ret;
2629
}
2730

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,7 @@ libc_function(
25992599
hdrs = ["src/unistd/read.h"],
26002600
deps = [
26012601
":__support_common",
2602+
":__support_macros_sanitizer",
26022603
":__support_osutil_syscall",
26032604
":errno",
26042605
],

0 commit comments

Comments
 (0)