From owner-freebsd-bugs@FreeBSD.ORG Wed Mar 30 17:20:07 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CB0A616A4EF for ; Wed, 30 Mar 2005 17:20:07 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4020643D54 for ; Wed, 30 Mar 2005 17:20:07 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j2UHK7AC097914 for ; Wed, 30 Mar 2005 17:20:07 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j2UHK7wW097913; Wed, 30 Mar 2005 17:20:07 GMT (envelope-from gnats) Date: Wed, 30 Mar 2005 17:20:07 GMT Message-Id: <200503301720.j2UHK7wW097913@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Maxim Konovalov Subject: Re: kern/79342: When looking for an unused port number for bind or connect, if low & high port range are equal, kernel can trap in divide by zero error X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Maxim Konovalov List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2005 17:20:07 -0000 The following reply was made to PR kern/79342; it has been noted by GNATS. From: Maxim Konovalov To: Anjali Kulkarni Cc: silby@freebsd.org, bug-followup@freebsd.org Subject: Re: kern/79342: When looking for an unused port number for bind or connect, if low & high port range are equal, kernel can trap in divide by zero error Date: Wed, 30 Mar 2005 21:18:27 +0400 (MSD) > Just a note the bug is appeared with > net.inet.ip.portrange.randomized=1 only. > > I think we need to stop doing random port allocation if last - first > delta is ridiculous small. Here is my version of the patch: Index: in_pcb.c =================================================================== RCS file: /home/ncvs/src/sys/netinet/in_pcb.c,v retrieving revision 1.161 diff -u -p -r1.161 in_pcb.c --- in_pcb.c 23 Mar 2005 09:26:38 -0000 1.161 +++ in_pcb.c 30 Mar 2005 16:36:58 -0000 @@ -411,13 +411,19 @@ in_pcbbind_setup(inp, nam, laddrp, lport * For UDP, use random port allocation as long as the user * allows it. For TCP (and as of yet unknown) connections, * use random port allocation only if the user allows it AND - * ipport_tick allows it. + * ipport_tick() allows it. */ if (ipport_randomized && (!ipport_stoprandom || pcbinfo == &udbinfo)) dorandom = 1; else dorandom = 0; + /* + * It makes no sense to do random port allocation if + * we have the only port available. + */ + if (first == last) + dorandom = 0; /* Make sure to not include UDP packets in the count. */ if (pcbinfo != &udbinfo) ipport_tcpallocs++; %%% It's not perfect because it should turn random port allocation off if the diapason of ports is small but I am not sure yet we need an additional sysctl for that. Mike, what is your opinion? As a side note for the original PR: random port allocation was broken in RELENG_4, that is why we turned it off by default in RELENG_4 some time after 4.10-REL and turned it on back right before 4.11-REL when Mike implemented a new algorithm. If you are going to use 4.10-REL you need to turn the port randomization off or import Mike's code. -- Maxim Konovalov