[libc-commits] [libc] [libc] More unpoison for recvmsg (PR #117347)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Fri Nov 22 11:11:34 PST 2024


https://github.com/michaelrj-google updated https://github.com/llvm/llvm-project/pull/117347

>From 135e6393715de545cd54be2d9a987fea721864d5 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Fri, 22 Nov 2024 08:48:45 -0800
Subject: [PATCH 1/2] [libc] More unpoison for recvmsg

The msghdr struct is very nested which makes it a pain to unpoison. I'm
pretty sure I've got all of it now. I also added a test which should
hopefully exercise the iovec part under sanitizers since I suspect
that's what's been causing issues.
---
 libc/src/sys/socket/linux/recvmsg.cpp                   | 1 +
 libc/test/src/sys/socket/linux/sendmsg_recvmsg_test.cpp | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/libc/src/sys/socket/linux/recvmsg.cpp b/libc/src/sys/socket/linux/recvmsg.cpp
index e42b6346f330a0..647beeede07f57 100644
--- a/libc/src/sys/socket/linux/recvmsg.cpp
+++ b/libc/src/sys/socket/linux/recvmsg.cpp
@@ -41,6 +41,7 @@ LLVM_LIBC_FUNCTION(ssize_t, recvmsg, (int sockfd, msghdr *msg, int flags)) {
   // Unpoison the msghdr, as well as all its components.
   MSAN_UNPOISON(msg, sizeof(msghdr));
   MSAN_UNPOISON(msg->msg_name, msg->msg_namelen);
+  MSAN_UNPOISON(msg->msg_iov, msg->msg_iovlen * sizeof(struct iovec));
 
   for (size_t i = 0; i < msg->msg_iovlen; ++i) {
     MSAN_UNPOISON(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
diff --git a/libc/test/src/sys/socket/linux/sendmsg_recvmsg_test.cpp b/libc/test/src/sys/socket/linux/sendmsg_recvmsg_test.cpp
index abcb0a3e6e5062..4d3bae1bfe142a 100644
--- a/libc/test/src/sys/socket/linux/sendmsg_recvmsg_test.cpp
+++ b/libc/test/src/sys/socket/linux/sendmsg_recvmsg_test.cpp
@@ -64,6 +64,8 @@ TEST(LlvmLibcSendMsgRecvMsgTest, SucceedsWithSocketPair) {
   ASSERT_EQ(recv_result, static_cast<ssize_t>(MESSAGE_LEN));
   ASSERT_ERRNO_SUCCESS();
 
+  ASSERT_EQ(recv_message.msg_iov->iov_base, reinterpret_cast<void *>(buffer));
+
   ASSERT_STREQ(buffer, TEST_MESSAGE);
 
   // close both ends of the socket

>From 9a1828828668cdabc92c1690b9e450c15ef3b05e Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Fri, 22 Nov 2024 11:11:15 -0800
Subject: [PATCH 2/2] remove struct

---
 libc/src/sys/socket/linux/recvmsg.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/src/sys/socket/linux/recvmsg.cpp b/libc/src/sys/socket/linux/recvmsg.cpp
index 647beeede07f57..b81f844a23a65f 100644
--- a/libc/src/sys/socket/linux/recvmsg.cpp
+++ b/libc/src/sys/socket/linux/recvmsg.cpp
@@ -41,7 +41,7 @@ LLVM_LIBC_FUNCTION(ssize_t, recvmsg, (int sockfd, msghdr *msg, int flags)) {
   // Unpoison the msghdr, as well as all its components.
   MSAN_UNPOISON(msg, sizeof(msghdr));
   MSAN_UNPOISON(msg->msg_name, msg->msg_namelen);
-  MSAN_UNPOISON(msg->msg_iov, msg->msg_iovlen * sizeof(struct iovec));
+  MSAN_UNPOISON(msg->msg_iov, msg->msg_iovlen * sizeof(iovec));
 
   for (size_t i = 0; i < msg->msg_iovlen; ++i) {
     MSAN_UNPOISON(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);



More information about the libc-commits mailing list