Sure,
The bytes of `msghdr` need to be cleared because the `msghdr` struct layout specified in QEMU appears to generalize between the definitions of `msghdr` across different libc's and kernels. To appropriately generalize `msghdr` across libc's and kernels would either:
1. require specializing code in do_sendrecvmsg_locked() for each individual libc and kernel version, or
2. zeroing out all bytes of `msghdr`, b/c certain libc or kernel versions may misinterpret the undefined padding bytes that come from misalignment in the struct as actual syscall params.
The patch I provided would be going for route #2, given that it's a simpler fix for the underlying problem for the short term.
What I believe is the background behind why the struct layout has been a problem is because, since the beginning, the Linux kernel has always specified the layout of `msghdr` differently from POSIX. Given that this implies incompatibility between kernels on how `msghdr` is specified, different libc projects such as musl and glibc provide different workarounds by laying out `msghdr` differently amongst one another.
A few projects running tests/applications through QEMU have been bitten by this, and a solution that one of the projects discovered was that patching QEMU to zero-initialize the bytes msghdr the same way my patch does allow for compatibility between different `msghdr` layouts across glibc, musl, and the Linux kernel:
https://github.com/void-linux/void-packages/issues/23557#issuecomment-718392360
As for my rationale for sending in this patch, it is because I'm currently implementing cross-platform networking in the standard library for the Zig programming language, and have run into this exact same problem with EMSGSIZE being returned by sendmsg() when tests are run through QEMU on x86_64-linux-musl.
Hope this gives enough context about the problem and patch, but please do let me know if there is any more information that I could provide which would help.
Best regards,
Kenta Iwasaki