Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130401165311.GM20323@brightrain.aerifal.cx>
Date: Mon, 1 Apr 2013 12:53:11 -0400
From: Rich Felker <dalias@...ifal.cx>
To: simon@...kelleys.org.uk
Cc: musl@...ts.openwall.com
Subject: Breakeage on Linux due to SO_REUSEPORT

Hi,

Back in November, we had a bug report against musl libc due to dnsmasq
failing because we had defined SO_REUSEPORT in the headers, but Linux
did not support it. At the time I just removed the definition, but
we're adding it back now, as Linux has just recently added
SO_REUSEPORT support, and thus the same issue will arise with glibc
(which is just including asm/socket.h and thus getting the kernel's
definition of it) too. I've attached the original bug report thread.

The fundamental problem is that it's not valid to assume SO_REUSEPORT
is supported/working just because it's defined. Instead, the usage
pattern should probably be something like

#ifdef SO_REUSEPORT
	if (setsockopt(s, SO_REUSEPORT, ...)<0 && errno==ENOPROTOOPT)
#endif
	setsockopt(s, SO_REUSEADDR, ...);


Rich

Received: from mother.openwall.net ([195.42.179.200])
	by brightrain.aerifal.cx
Received: (qmail 23717 invoked by uid 550); 16 Nov 2012 01:29:12 -0000
Mailing-List: contact musl-help@...ts.openwall.com; run by ezmlm
Precedence: bulk
List-Post: <mailto:musl@...ts.openwall.com>
List-Help: <mailto:musl-help@...ts.openwall.com>
List-Unsubscribe: <mailto:musl-unsubscribe@...ts.openwall.com>
List-Subscribe: <mailto:musl-subscribe@...ts.openwall.com>
Reply-To: musl@...ts.openwall.com
Delivered-To: mailing list musl@...ts.openwall.com
Received: (qmail 23702 invoked from network); 16 Nov 2012 01:29:11 -0000
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:in-reply-to:references:date:message-id:subject:from:to
         :content-type;
        bh=tPCeuAavYzpVzX6kd3ANHYQuwBrnjmQh0/7OEvyKmkg=;
        b=qx1dJ4tW7VXjI4eThI/SCTHFlNHFEKTElpOv8UqDUhaDOggzJ767ICCluOHf2aBKTn
         TCvzRywiuDgoE/EJOAQqnBEWWxcT+aMRsTyXEf+cyJ8oG92mivp0TR4rpvThGqcRzrqh
         E3/ol1yS70RAkDjUANphRa3hGwhDCKc5SapbF39ALTFwG3EG3h7+8fo5R9WfQt4h8J+i
         U4lwiOmAZiZbirWOYqtUlayrHo21Fez1tSBs0ERqlDr3439Y0UqvDc7KZ1QL75tcgpT4
         XiveCKDQyXIh7x7foIo3beklCQwZMDsQ6j8VRfay1SscZZjobcorWE1ikRuwl/2VpRLF
         lTbA==
MIME-Version: 1.0
In-Reply-To: <20121116001831.GM20323@...ghtrain.aerifal.cx>
References: <CAKHv7phcN_sPbdOummz7SEikUFmG0mZBEvhoOAidKLLW072e0g@...l.gmail.com>
	<20121115233725.GK20323@...ghtrain.aerifal.cx>
	<20121116001110.GL20323@...ghtrain.aerifal.cx>
	<20121116001831.GM20323@...ghtrain.aerifal.cx>
Date: Fri, 16 Nov 2012 03:28:59 +0200
Message-ID: <CAKHv7pgwi-C7=Y+GcieMON2ryRsfXryhjmbFqa147f6jZfTHfw@...l.gmail.com>
From: Paul Schutte <sjpschutte@...il.com>
To: musl@...ts.openwall.com
Content-Type: multipart/alternative; boundary=e89a8f503bf627905804ce92b187
Subject: Re: [musl] A few issues on MIPS and now on ARMEL

--e89a8f503bf627905804ce92b187
Content-Type: text/plain; charset=ISO-8859-1

Thanks Rich !

It is working.

You guys are the best !

Don't know if anyone is interested, but this is the memory usage of the
glibc binary (dynamically linked, distro supplied) :
root      9931  0.4  0.4   4232  1020 pts/2    S+   03:23   0:00 /dnsmasq

Musl binary, statically linked:
root      9927  0.0  0.1    328   244 pts/2    S    03:20   0:00 ./dnsmasq

RSS size down from 1020 to 244, thus 25% of original consumption.

Regards
Paul

On Fri, Nov 16, 2012 at 2:18 AM, Rich Felker <dalias@...ifal.cx> wrote:

> On Thu, Nov 15, 2012 at 07:11:10PM -0500, Rich Felker wrote:
> > On Thu, Nov 15, 2012 at 06:37:25PM -0500, Rich Felker wrote:
> > > On Fri, Nov 16, 2012 at 12:21:11AM +0200, Paul Schutte wrote:
> > > > Hi guys,
> > > >
> > > > I am now hitting a similar problem on armel.
> > > >
> > > > I am cross-compiling "dnsmasq"
> > > >
> > > > Glibc strace:
> > > >
> > > > ---snip---
> > > > socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 5
> > > > fcntl64(5, F_GETFL)                     = 0x2 (flags O_RDWR)
> > > > fcntl64(5, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
> > > > setsockopt(5, SOL_IP, IP_MTU_DISCOVER, [0], 4) = 0
> > > > setsockopt(5, SOL_IP, IP_PKTINFO, [1], 4) = 0
> > > > setsockopt(5, SOL_SOCKET, SO_BROADCAST, [1], 4) = 0
> > > > setsockopt(5, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
> > > >
> > > >
> > > > Musl strace:
> > > >
> > > > socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 5
> > > > fcntl64(5, F_GETFL)                     = 0x2 (flags O_RDWR)
> > > > fcntl64(5, F_SETFL, O_RDWR|O_NONBLOCK|O_LARGEFILE) = 0
> > > > setsockopt(5, SOL_IP, IP_MTU_DISCOVER, [0], 4) = 0
> > > > setsockopt(5, SOL_IP, IP_PKTINFO, [1], 4) = 0
> > > > setsockopt(5, SOL_SOCKET, SO_BROADCAST, [1], 4) = 0
> > > > setsockopt(5, SOL_SOCKET, *0xf /* SO_??? */*, [1], 4) = -1
> ENOPROTOOPT
> > > > (Protocol not available)
> > >
> > > Thanks for the report. I'll check and see if ARM has unusual
> > > definitions we're missing.
> >
> > This doesn't seem to be ARM-specific. Linux has reserved a number for
> > SO_REUSEPORT, but it's not implemented in the kernel it seems, and
> > musl is providing the value, presumably causing the app to use it and
> > think it works. I'm guessing I should just remove it, but it might be
> > possible/preferable to make setsockopt and getsockopt remap it to
> > SO_REUSEADDR internally. Ideas anyone?
>
> For now I've disabled it, matching what other libcs do on Linux.
> Changes are in current git.
>
> Rich
>

--e89a8f503bf627905804ce92b187
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Thanks Rich !<br><br>It is working.<br><br>You guys are the best !<br><br>D=
on&#39;t know if anyone is interested, but this is the memory usage of the =
glibc binary (dynamically linked, distro supplied) :<br>root=A0=A0=A0=A0=A0=
 9931=A0 0.4=A0 0.4=A0=A0 4232=A0 1020 pts/2=A0=A0=A0 S+=A0=A0 03:23=A0=A0 =
0:00 /dnsmasq<br>
<br>Musl binary, statically linked: <br>root=A0=A0=A0=A0=A0 9927=A0 0.0=A0 =
0.1=A0=A0=A0 328=A0=A0 244 pts/2=A0=A0=A0 S=A0=A0=A0 03:20=A0=A0 0:00 ./dns=
masq<br><br>RSS size down from 1020 to 244, thus 25% of original consumptio=
n.<br><br>Regards<br>Paul<br><br><div class=3D"gmail_quote">
On Fri, Nov 16, 2012 at 2:18 AM, Rich Felker <span dir=3D"ltr">&lt;<a href=
=3D"mailto:dalias@...ifal.cx" target=3D"_blank">dalias@...ifal.cx</a>&gt;</=
span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8e=
x;border-left:1px #ccc solid;padding-left:1ex">
On Thu, Nov 15, 2012 at 07:11:10PM -0500, Rich Felker wrote:<br>
&gt; On Thu, Nov 15, 2012 at 06:37:25PM -0500, Rich Felker wrote:<br>
&gt; &gt; On Fri, Nov 16, 2012 at 12:21:11AM +0200, Paul Schutte wrote:<br>
&gt; &gt; &gt; Hi guys,<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I am now hitting a similar problem on armel.<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; I am cross-compiling &quot;dnsmasq&quot;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Glibc strace:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; ---snip---<br>
&gt; &gt; &gt; socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) =3D 5<br>
&gt; &gt; &gt; fcntl64(5, F_GETFL) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=3D 0x2 (flags O_RDWR)<br>
&gt; &gt; &gt; fcntl64(5, F_SETFL, O_RDWR|O_NONBLOCK) =A0=3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_IP, IP_MTU_DISCOVER, [0], 4) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_IP, IP_PKTINFO, [1], 4) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_SOCKET, SO_BROADCAST, [1], 4) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_SOCKET, SO_REUSEADDR, [1], 4) =3D 0<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; Musl strace:<br>
&gt; &gt; &gt;<br>
&gt; &gt; &gt; socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) =3D 5<br>
&gt; &gt; &gt; fcntl64(5, F_GETFL) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
=3D 0x2 (flags O_RDWR)<br>
&gt; &gt; &gt; fcntl64(5, F_SETFL, O_RDWR|O_NONBLOCK|O_LARGEFILE) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_IP, IP_MTU_DISCOVER, [0], 4) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_IP, IP_PKTINFO, [1], 4) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_SOCKET, SO_BROADCAST, [1], 4) =3D 0<br>
&gt; &gt; &gt; setsockopt(5, SOL_SOCKET, *0xf /* SO_??? */*, [1], 4) =3D -1=
 ENOPROTOOPT<br>
&gt; &gt; &gt; (Protocol not available)<br>
&gt; &gt;<br>
&gt; &gt; Thanks for the report. I&#39;ll check and see if ARM has unusual<=
br>
&gt; &gt; definitions we&#39;re missing.<br>
&gt;<br>
&gt; This doesn&#39;t seem to be ARM-specific. Linux has reserved a number =
for<br>
&gt; SO_REUSEPORT, but it&#39;s not implemented in the kernel it seems, and=
<br>
&gt; musl is providing the value, presumably causing the app to use it and<=
br>
&gt; think it works. I&#39;m guessing I should just remove it, but it might=
 be<br>
&gt; possible/preferable to make setsockopt and getsockopt remap it to<br>
&gt; SO_REUSEADDR internally. Ideas anyone?<br>
<br>
For now I&#39;ve disabled it, matching what other libcs do on Linux.<br>
Changes are in current git.<br>
<span class=3D"HOEnZb"><font color=3D"#888888"><br>
Rich<br>
</font></span></blockquote></div><br>

--e89a8f503bf627905804ce92b187--

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.