Skip to content

[libc] Fix sendmsg iovec unpoisoning #115057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

michaelrj-google
Copy link
Contributor

The unpoisoning for sendmsg had a typo where it would not unpoison all
of the elements in the iovec, causing msan errors. This patch fixes
that.

The unpoisoning for sendmsg had a typo where it would not unpoison all
of the elements in the iovec, causing msan errors. This patch fixes
that.
@llvmbot
Copy link
Member

llvmbot commented Nov 5, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

The unpoisoning for sendmsg had a typo where it would not unpoison all
of the elements in the iovec, causing msan errors. This patch fixes
that.


Full diff: https://github.com/llvm/llvm-project/pull/115057.diff

1 Files Affected:

  • (modified) libc/src/sys/socket/linux/recvmsg.cpp (+3-1)
diff --git a/libc/src/sys/socket/linux/recvmsg.cpp b/libc/src/sys/socket/linux/recvmsg.cpp
index 60bbc84877b850..43929da87e16d2 100644
--- a/libc/src/sys/socket/linux/recvmsg.cpp
+++ b/libc/src/sys/socket/linux/recvmsg.cpp
@@ -40,9 +40,11 @@ LLVM_LIBC_FUNCTION(ssize_t, recvmsg,
   }
 
   // Unpoison the msghdr, as well as all its components.
+  MSAN_UNPOISON(msg, sizeof(struct msghdr));
   MSAN_UNPOISON(msg->msg_name, msg->msg_namelen);
+
   for (size_t i = 0; i < msg->msg_iovlen; ++i) {
-    MSAN_UNPOISON(msg->msg_iov->iov_base, msg->msg_iov->iov_len);
+    MSAN_UNPOISON(msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len);
   }
   MSAN_UNPOISON(msg->msg_control, msg->msg_controllen);
 

@michaelrj-google michaelrj-google merged commit fedb9fd into llvm:main Nov 5, 2024
4 of 5 checks passed
@michaelrj-google michaelrj-google deleted the libcRecvMsgFixUnpoisonLoop branch November 5, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants