From owner-svn-src-all@FreeBSD.ORG Thu Jul 4 19:03:52 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 6EE59889; Thu, 4 Jul 2013 19:03:52 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-bk0-x232.google.com (mail-bk0-x232.google.com [IPv6:2a00:1450:4008:c01::232]) by mx1.freebsd.org (Postfix) with ESMTP id A19361957; Thu, 4 Jul 2013 19:03:51 +0000 (UTC) Received: by mail-bk0-f50.google.com with SMTP id ik8so779421bkc.9 for ; Thu, 04 Jul 2013 12:03:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=Icyepyaol2tEDS15AwkpWqYRKjewm5+r6vPzhpOYKEI=; b=UxI96+PE8NCOufurqLOMuaSP6ewV8LlrrW6QrkeBfMc75owUBrlPqpiyIz5qwrNiXh aCGfiK+c5ufYYi355VpIVXNGpO+C4Ug/R4l1t9A5WBQFZ5OPjHdD052QvHKC0X+v77Me 93dnJvrvIZAcEAC890OQsZTpnK0MvGAq/eDzVAEDX1DEDDbmAB58tekqNTsDbP3jg5Hv 5B0inFkjk1d0/0lM4K356qGze8CCrrcJyJKK52t4qJ2gF77nvG+SSUi1kmHyGzH80jjw o+5tw+E/V+YB/jXt2S4CSAkQk7vC7dvipZXk8kxNMvL8Tq+Xr5ExpxsTYzYrsv97Jj2V Zovw== X-Received: by 10.205.32.198 with SMTP id sl6mr1299914bkb.20.1372964630543; Thu, 04 Jul 2013 12:03:50 -0700 (PDT) Received: from localhost ([178.150.115.244]) by mx.google.com with ESMTPSA id rj6sm1342315bkb.12.2013.07.04.12.03.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 04 Jul 2013 12:03:49 -0700 (PDT) Sender: Mikolaj Golub Date: Thu, 4 Jul 2013 22:03:47 +0300 From: Mikolaj Golub To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r252710 - in head/sys: netinet netinet6 Message-ID: <20130704190345.GA12450@gmail.com> References: <201307041838.r64Ic1Ld099772@svn.freebsd.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" Content-Disposition: inline In-Reply-To: <201307041838.r64Ic1Ld099772@svn.freebsd.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Jul 2013 19:03:52 -0000 --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jul 04, 2013 at 06:38:01PM +0000, Mikolaj Golub wrote: > Author: trociny > Date: Thu Jul 4 18:38:00 2013 > New Revision: 252710 > URL: http://svnweb.freebsd.org/changeset/base/252710 > > Log: > In r227207, to fix the issue with possible NULL inp_socket pointer > dereferencing, when checking for SO_REUSEPORT option (and SO_REUSEADDR > for multicast), INP_REUSEPORT flag was introduced to cache the socket > option. It was decided then that one flag would be enough to cache > both SO_REUSEPORT and SO_REUSEADDR: when processing SO_REUSEADDR > setsockopt(2), it was checked if it was called for a multicast address > and INP_REUSEPORT was set accordingly. > > Unfortunately that approach does not work when setsockopt(2) is called > before binding to a multicast address: the multicast check fails and > INP_REUSEPORT is not set. > > Fix this by adding INP_REUSEADDR flag to unconditionally cache > SO_REUSEADDR. > > PR: 179901 > Submitted by: Michael Gmelin freebsd grem.de (initial version) > Reviewed by: rwatson > MFC after: 1 week Also, in this PR another issue is reported by Michael: if SO_REUSEADDR is set for the first multicast bound socket and one tries to bind a socket to the same address:port with SO_REUSEPORT, it fails, although for multicast there should not be difference between SO_REUSEPORT and SO_REUSEADDR. This is an old issue (observed on FreeBSD7 too), but I would like to fix it. Below is a patch I am going to commit to HEAD. Though I am not going to MFC it before 9.2 unless I have strong support from people. -- Mikolaj Golub --9jxsPFA5p3P2qPhR Content-Type: text/x-diff; charset=us-ascii Content-Disposition: inline; filename="pr179901.2.1.patch" commit 7cf3a6a95d74ae91c80350fc1ae8e96fe59c3c65 Author: Mikolaj Golub Date: Sun Jun 30 00:09:20 2013 +0300 A complete duplication of binding should be allowed if on both new and duplicated sockets a multicast address is bound and either SO_REUSEPORT or SO_REUSEADDR is set. But actually it works for the following combinations: * SO_REUSEPORT is set for the fist socket and SO_REUSEPORT for the new; * SO_REUSEADDR is set for the fist socket and SO_REUSEADDR for the new; * SO_REUSEPORT is set for the fist socket and SO_REUSEADDR for the new; and fails for this: * SO_REUSEADDR is set for the fist socket and SO_REUSEPORT for the new. Fix the last case. PR: 179901 diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 3506b74..eb15a38 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -554,7 +554,7 @@ in_pcbbind_setup(struct inpcb *inp, struct sockaddr *nam, in_addr_t *laddrp, * and a multicast address is bound on both * new and duplicated sockets. */ - if (so->so_options & SO_REUSEADDR) + if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) != 0) reuseport = SO_REUSEADDR|SO_REUSEPORT; } else if (sin->sin_addr.s_addr != INADDR_ANY) { sin->sin_port = 0; /* yech... */ diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index a0a6874..fb84279 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -156,7 +156,7 @@ in6_pcbbind(register struct inpcb *inp, struct sockaddr *nam, * and a multicast address is bound on both * new and duplicated sockets. */ - if (so->so_options & SO_REUSEADDR) + if ((so->so_options & (SO_REUSEADDR|SO_REUSEPORT)) != 0) reuseport = SO_REUSEADDR|SO_REUSEPORT; } else if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { struct ifaddr *ifa; --9jxsPFA5p3P2qPhR--