From owner-freebsd-bugs@FreeBSD.ORG Thu Mar 13 16:50:01 2008 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ABE82106566B for ; Thu, 13 Mar 2008 16:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 83C5B8FC22 for ; Thu, 13 Mar 2008 16:50:01 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.2/8.14.2) with ESMTP id m2DGo14n092435 for ; Thu, 13 Mar 2008 16:50:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.2/8.14.1/Submit) id m2DGo1XG092434; Thu, 13 Mar 2008 16:50:01 GMT (envelope-from gnats) Resent-Date: Thu, 13 Mar 2008 16:50:01 GMT Resent-Message-Id: <200803131650.m2DGo1XG092434@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Laurent Frigault Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ADD5D1065671 for ; Thu, 13 Mar 2008 16:44:46 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id 976B58FC1D for ; Thu, 13 Mar 2008 16:44:46 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m2DGfRFo027337 for ; Thu, 13 Mar 2008 16:41:27 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.2/8.14.1/Submit) id m2DGfRqr027336; Thu, 13 Mar 2008 16:41:27 GMT (envelope-from nobody) Message-Id: <200803131641.m2DGfRqr027336@www.freebsd.org> Date: Thu, 13 Mar 2008 16:41:27 GMT From: Laurent Frigault To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: kern/121668: connect randomly fails with EPERM with some pf rules X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Mar 2008 16:50:01 -0000 >Number: 121668 >Category: kern >Synopsis: connect randomly fails with EPERM with some pf rules >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Mar 13 16:50:01 UTC 2008 >Closed-Date: >Last-Modified: >Originator: Laurent Frigault >Release: 6.2-RELEASE-p10 , 7.0-RELEASE >Organization: >Environment: FreeBSD troll.free.org 6.2-RELEASE-p10 FreeBSD 6.2-RELEASE-p10 #0: Wed Jan 16 14:22:17 CET 2008 lolo@troll.free.org:/usr/src/sys/i386/compile/SMP i386 FreeBSD surt.free.org 7.0-RELEASE FreeBSD 7.0-RELEASE #1: Wed Feb 27 18:29:25 CET 2008 root@surt.free.org:/usr/src/sys/amd64/compile/GENERIC amd64 >Description: >From times to times, connect fails with EPERM when using pf statefully. I discover this problem when investigating the cause of unexpected mysql connection failure between a web php script and and mysql server running on an other server. This leads me to a connect(2) problem failing without reason with EPERM (there is no EPERM failure cause in connect manual) . ruleset1 (no state was the default before 7.0): ============================================== scrub in all fragment reassemble pass out quick on lo0 all no state pass in quick on lo0 all no state .. ============================================== ruleset 2 ============================================== scrub in all fragment reassemble pass out quick on lo0 proto tcp from any to any port 9 flags S/SA keep state pass out quick on lo0 all no state pass in quick on lo0 all no state ============================================== With ruleset 1 => no problem With ruleset 2 => connect fails sometimes with EPERM There is no reject information in pf logs which is logical because pf rules authorize those connections >How-To-Repeat: sysctl net.inet.tcp.nolocaltimewait=1 not needed, but helps to reproduce the problem with client and server on the same computer. start inetd with discard/tcp service enabled : inetd_enable="YES" inetd_flags="-wl -R 0" % grep ^discard /etc/inetd.conf discard stream tcp nowait root internal pf rules: scrub in all fragment reassemble pass out quick on lo0 proto tcp from any to any port 9 flags S/SA keep state pass out quick on lo0 all no state pass in quick on lo0 all no state Lauch the following perl script. Sometimes, connect will wrongly fail with EPERM ============================================================== #!/usr/bin/perl -w use strict; use Socket; use Errno; $|=1; sub con($$$) { my ($sin,$port,$proto) = @_; socket(Socket_Handle, PF_INET, SOCK_STREAM, $proto); if(connect(Socket_Handle,$sin)) { print "ok\t"; print Socket_Handle "hello\n"; close (Socket_Handle); } else { print "$!\n"; }; } my $proto = getprotobyname('tcp'); my $port = getservbyname('discard', 'tcp'); my $sin = sockaddr_in($port,inet_aton("127.1")); for (my $cpt=0;$cpt<=2000;++$cpt) { print "$cpt\t"; con($sin,$port,$proto); }; ============================================================== >Fix: >Release-Note: >Audit-Trail: >Unformatted: