diff options
author | michaelrj-google <71531609+michaelrj-google@users.noreply.github.com> | 2024-01-31 16:14:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 16:14:49 -0800 |
commit | 0e8eb445db0cc2552d9d077b527a43c779785cb9 (patch) | |
tree | 327fb7bb93f3ce4205748df5d460218eccf2d4c0 | |
parent | 0e0d155f87b199c137fe7bd506fb443c242f785e (diff) |
[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.
-rw-r--r-- | libc/src/unistd/linux/read.cpp | 5 | ||||
-rw-r--r-- | utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 1 |
2 files changed, 5 insertions, 1 deletions
diff --git a/libc/src/unistd/linux/read.cpp b/libc/src/unistd/linux/read.cpp index 691a236982e3..41be1eb10c0d 100644 --- a/libc/src/unistd/linux/read.cpp +++ b/libc/src/unistd/linux/read.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 <sys/syscall.h> // For syscall numbers. @@ -22,6 +22,9 @@ LLVM_LIBC_FUNCTION(ssize_t, read, (int fd, void *buf, size_t count)) { libc_errno = static_cast<int>(-ret); return -1; } + // The cast is important since there is a check that dereferences the pointer + // which fails on void*. + MSAN_UNPOISON(reinterpret_cast<char *>(buf), count); return ret; } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 3b8ce044b7fc..3d8c5eb178ec 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -2599,6 +2599,7 @@ libc_function( hdrs = ["src/unistd/read.h"], deps = [ ":__support_common", + ":__support_macros_sanitizer", ":__support_osutil_syscall", ":errno", ], |