From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9937 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: recvmsg/sendmsg broken on mips64 Date: Thu, 21 Apr 2016 13:16:08 -0400 Message-ID: <20160421171608.GZ21636@brightrain.aerifal.cx> References: <20160407184643.GI9862@port70.net> <2656e404-f225-cd95-3989-a48df486d914@dd-wrt.com> <20160410221812.GP21636@brightrain.aerifal.cx> <20160410222947.GQ21636@brightrain.aerifal.cx> <20160411023522.GR21636@brightrain.aerifal.cx> <20160421013715.GX21636@brightrain.aerifal.cx> <57187FA8.8010806@dd-wrt.com> <20160421153637.GY21636@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1461259072 30003 80.91.229.3 (21 Apr 2016 17:17:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 21 Apr 2016 17:17:52 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-9950-gllmg-musl=m.gmane.org@lists.openwall.com Thu Apr 21 19:17:46 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1atIDH-0006ox-0c for gllmg-musl@m.gmane.org; Thu, 21 Apr 2016 19:16:23 +0200 Original-Received: (qmail 7518 invoked by uid 550); 21 Apr 2016 17:16:21 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 7496 invoked from network); 21 Apr 2016 17:16:20 -0000 Content-Disposition: inline In-Reply-To: <20160421153637.GY21636@brightrain.aerifal.cx> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:9937 Archived-At: 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