Skip to content

Conversation

@deaklajos
Copy link
Contributor

Backports: 3fc723e (#136195)

Ran into the issue on Alpine when building with TSAN that __sanitizer_msghdr and the msghdr provided by musl did not match. This caused lots of tsan reports and an eventual termination of the application by the oom during a sendmsg.

@llvmbot
Copy link
Member

llvmbot commented Sep 18, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Deák Lajos (deaklajos)

Changes

Backports: 3fc723e (#136195)

Ran into the issue on Alpine when building with TSAN that __sanitizer_msghdr and the msghdr provided by musl did not match. This caused lots of tsan reports and an eventual termination of the application by the oom during a sendmsg.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h (+24)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index f118d53f0df80..24966523f3a02 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -478,6 +478,30 @@ struct __sanitizer_cmsghdr {
   int cmsg_level;
   int cmsg_type;
 };
+#  elif SANITIZER_MUSL
+struct __sanitizer_msghdr {
+  void *msg_name;
+  unsigned msg_namelen;
+  struct __sanitizer_iovec *msg_iov;
+  int msg_iovlen;
+#    if SANITIZER_WORDSIZE == 64
+  int __pad1;
+#    endif
+  void *msg_control;
+  unsigned msg_controllen;
+#    if SANITIZER_WORDSIZE == 64
+  int __pad2;
+#    endif
+  int msg_flags;
+};
+struct __sanitizer_cmsghdr {
+  unsigned cmsg_len;
+#    if SANITIZER_WORDSIZE == 64
+  int __pad1;
+#    endif
+  int cmsg_level;
+  int cmsg_type;
+};
 #  else
 // In POSIX, int msg_iovlen; socklen_t msg_controllen; socklen_t cmsg_len; but
 // many implementations don't conform to the standard.

@github-actions
Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Developer Policy and LLVM Discourse for more information.

@deaklajos
Copy link
Contributor Author

@vitalybuka

@nikic nikic added this to the LLVM 21.x Release milestone Sep 25, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Sep 25, 2025
@nikic nikic moved this from Needs Triage to Needs Review in LLVM Release Status Sep 25, 2025
@github-project-automation github-project-automation bot moved this from Needs Review to Needs Merge in LLVM Release Status Sep 30, 2025
@dyung dyung force-pushed the compiler-rt/backport-musl-msghdr branch from 859ebb3 to 7da3233 Compare October 1, 2025 15:08
Ran into the issue on Alpine when building with TSAN that
`__sanitizer_msghdr` and the `msghdr` provided by musl did not match.
This caused lots of tsan reports and an eventual termination of the
application by the oom during a `sendmsg`.
@dyung dyung force-pushed the compiler-rt/backport-musl-msghdr branch from 7da3233 to 2cb08db Compare October 6, 2025 06:41
@dyung dyung merged commit 2cb08db into llvm:release/21.x Oct 6, 2025
2 of 3 checks passed
@github-project-automation github-project-automation bot moved this from Needs Merge to Done in LLVM Release Status Oct 6, 2025
@github-actions
Copy link

github-actions bot commented Oct 6, 2025

@deaklajos (or anyone else). If you would like to add a note about this fix in the release notes (completely optional). Please reply to this comment with a one or two sentence description of the fix. When you are done, please add the release:note label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

5 participants