|
Message-ID: <20160421171608.GZ21636@brightrain.aerifal.cx> Date: Thu, 21 Apr 2016 13:16:08 -0400 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Subject: Re: recvmsg/sendmsg broken on mips64 On Thu, Apr 21, 2016 at 11:36:37AM -0400, Rich Felker wrote: > > >I've managed to track down the cause of the breakage. Somehow your > > >iproute2 has been miscompiled. What I did was add debug logic to > > >libc.so to print the contents of the msghdr struct passed in before > > >fixups, after fixups, and after the syscall. The output I got was: > > > > > >msghdr: 0xffffd58e08 12 0xffffd58df8 1 0 0 0 0 0 > > >msghdr: 0xffffd58e08 12 0xffffd58df8 0 0 0 0 0 0 > > >msghdr: 0xffffd58e08 12 0xffffd58df8 0 0 0 0 0 32 > > > > > >The fields (including __pad1 and __pad2) are printed in order. So as > > >you can see, ip passed in a structure with a 1 in __pad1 and a 0 in > > >msg_iovlen. The source (libnetlink.c) stores 1 to msg_iovlen, so my > > >guess is that somehow it ended up getting the wrong-endian version of > > >the structure definition. You could confirm this by adding #error to > > >the little-endian case in arch/mips64/bits/socket.h and recompiling. I > > >suspect it's going to take some additional work to track down the > > >cause, which is likely specific to something in your toolchain (it > > >didn't happen for me when I built my own iproute2). > > i tried that already before i contacted you. the #error case never > > raises within the little endian case > > Was that when compiling musl or iproute2? The problem is in how > iproute2 was built; your libc.so seems fine. > > > so your guess doesnt match reality. (i even tried it again right > > now. all is fine. it only uses the big endian case) > > If it's not the endian tests, I don't know what else would have caused > this. I'll get a disassembly dump of the function to show you. Is > there any way I can reproduce your exact toolchain to see if I can get > the same miscompilation to happen? OK, I finally found the source you're building from and tracked down the problem, which is simply that you have a buggy, 10-year-outdated version of iproute2's libnetlink.c. The relevant code is here: https://github.com/mirror/dd-wrt/blob/25e48ec1931daf4ef98a91ada9623638d128f34d/src/router/iproute2/lib/libnetlink.c#L156 Rather than using designated initializers as the current code does: http://git.kernel.org/cgit/linux/kernel/git/shemminger/iproute2.git/tree/lib/libnetlink.c?id=4bf138d6d2747b198fc0a78f5fe4e1c9287e9e90#n220 it's simply assuming an order for the members of struct msghdr. There are several ways you could fix this: 1. Update to a modern version of iproute2. This would probably fix a lot of other bugs too. 2. Copy the designated-initializers approach from the modern code into your version. 3. Just use a zero-initializer for the structure and then assign values to individual members by name with ordinary assignments. Let me know if you need any more info. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.