NetBSD Problem Report #46077
From www@NetBSD.org Thu Feb 23 03:20:46 2012
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
by www.NetBSD.org (Postfix) with ESMTP id 1D78B63BCEF
for <gnats-bugs@gnats.NetBSD.org>; Thu, 23 Feb 2012 03:20:46 +0000 (UTC)
Message-Id: <20120223032016.2A79B63BCEF@www.NetBSD.org>
Date: Thu, 23 Feb 2012 03:20:16 +0000 (UTC)
From: mnunberg@haskalah.org
Reply-To: mnunberg@haskalah.org
To: gnats-bugs@NetBSD.org
Subject: fstat() returns EINVAL on dup'd connected socket
X-Send-Pr-Version: www-1.0
>Number: 46077
>Category: kern
>Synopsis: fstat() returns EINVAL on dup'd connected socket
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 23 03:25:03 +0000 2012
>Closed-Date: Sat Mar 17 08:37:24 +0000 2012
>Last-Modified: Sat Mar 17 19:55:01 +0000 2012
>Originator: M. Nunberg
>Release: NetBSD 5.1.2 NetBSD 5.1.2 (GENERIC)
>Organization:
>Environment:
NetBSD 5.1.2 NetBSD 5.1.2 (GENERIC) #0: Thu Feb 2 17:22:10 UTC 2012 builds@b6.netbsd.org:/home/builds/ab/netbsd-5-1-2-RELEASE/i386/201202021012Z-obj/home/builds/ab/netbsd-5-1-2-RELEASE/src/sys/arch/i386/compile/GENERIC i386
>Description:
fstat will sometimes return EINVAL on a dup'd connected socket when the socket connection is not yet established, e.g. EINPROGRESS
I am running this under KVM in Linux, if this makes a difference.
The machine has been upgraded from an older release using the upgrade from the ISO (upgraded from 5.1.1).
>How-To-Repeat:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
int main(void)
{
struct stat sb;
struct sockaddr_in saddr;
uint32_t ipaddr;
int flags;
int s;
int dupsock;
assert( (s = socket(PF_INET, SOCK_STREAM, 0)) >= 0 );
assert( (flags = fcntl(s, F_GETFL)) != -1 );
assert( fcntl(s, F_SETFL, flags | O_NONBLOCK) != -1 );
memset(&saddr, 0, sizeof(saddr));
assert( inet_pton(AF_INET, "127.0.0.1", &ipaddr) );
saddr.sin_addr.s_addr = ipaddr;
saddr.sin_port = htons(42);
saddr.sin_family = AF_INET;
assert( connect(s, (struct sockaddr*)&saddr, sizeof(saddr)) == -1 &&
errno == EINPROGRESS );
/* Now let's try fstat() */
if (fstat(s, &sb) == -1) {
printf("Error: %s\n", strerror(errno));
abort();
}
exit(0);
}
>Fix:
I do not have a a fix per se, however I think I may have found the line where this error is being set.
http://nxr.netbsd.org/source/xref/src/sys/netinet/tcp_usrreq.c#269
>Release-Note:
>Audit-Trail:
From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/46077 CVS commit: src/tests/lib/libc/sys
Date: Tue, 6 Mar 2012 10:32:15 +0000
Module Name: src
Committed By: jruoho
Date: Tue Mar 6 10:32:15 UTC 2012
Modified Files:
src/tests/lib/libc/sys: t_stat.c
Log Message:
A test case for PR kern/46077: fstat() returns EINVAL on dup'd connected
socket. Expected failure on NetBSD x86, 5.0 - 6.0. Does not fail on Linux.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/lib/libc/sys/t_stat.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/46077 CVS commit: src/sys/netinet
Date: Fri, 16 Mar 2012 22:48:51 -0400
Module Name: src
Committed By: christos
Date: Sat Mar 17 02:48:51 UTC 2012
Modified Files:
src/sys/netinet: tcp_usrreq.c
Log Message:
PR/46077: M. Nunberg: Stat should not fial on connecting socket.
To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.163 src/sys/netinet/tcp_usrreq.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: jruoho@NetBSD.org
State-Changed-When: Sat, 17 Mar 2012 08:37:24 +0000
State-Changed-Why:
Fixed, and fix confirmed by the test runs.
From: "Jukka Ruohonen" <jruoho@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/46077 CVS commit: src/tests/lib/libc/sys
Date: Sat, 17 Mar 2012 08:37:08 +0000
Module Name: src
Committed By: jruoho
Date: Sat Mar 17 08:37:08 UTC 2012
Modified Files:
src/tests/lib/libc/sys: t_stat.c
Log Message:
PR kern/46077 was fixed; remove xfail.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libc/sys/t_stat.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Manuel Bouyer" <bouyer@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/46077 CVS commit: [netbsd-6] src/sys/netinet
Date: Sat, 17 Mar 2012 19:51:46 +0000
Module Name: src
Committed By: bouyer
Date: Sat Mar 17 19:51:46 UTC 2012
Modified Files:
src/sys/netinet [netbsd-6]: tcp_usrreq.c
Log Message:
Pull up following revision(s) (requested by jruoho in ticket #124):
sys/netinet/tcp_usrreq.c: revision 1.163
PR/46077: M. Nunberg: Stat should not fial on connecting socket.
To generate a diff of this commit:
cvs rdiff -u -r1.162 -r1.162.2.1 src/sys/netinet/tcp_usrreq.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.