NetBSD Problem Report #21713
Received: (qmail 12673 invoked by uid 605); 29 May 2003 16:34:16 -0000
Message-Id: <200305291633.h4TGXqk02037@netbsd.int.duh.org>
Date: Thu, 29 May 2003 12:33:52 -0400 (EDT)
From: tv@pobox.com
Sender: gnats-bugs-owner@netbsd.org
Reply-To: tv@pobox.com
To: gnats-bugs@gnats.netbsd.org
Subject: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
X-Send-Pr-Version: 3.95
>Number: 21713
>Category: kern
>Synopsis: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu May 29 16:35:00 +0000 2003
>Closed-Date: Sat Jul 12 16:43:57 +0000 2003
>Last-Modified: Sat Jul 12 16:43:57 +0000 2003
>Originator: Todd Vierling
>Release: NetBSD 1.6.1
>Organization:
DUH.ORG: Pointing out the obvious since 1994.
>Environment:
System: NetBSD netbsd.int.duh.org 1.6.1 NetBSD 1.6.1 (GENERIC) #0: Tue Apr 8 12:05:52 UTC 2003 autobuild@tgm.daemon.org:/autobuild/netbsd-1-6/i386/OBJ/autobuild/netbsd-1-6/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
If sysctl "net.inet6.ip6.v6only" is set to 0, in6addr_any listening
sockets accept IPv4 connections just fine.
However, if this sysctl is 1 (the default), accepting IPv4 connections
requires setting option INET6_IPV6ONLY before bind(2). This doesn't work.
IPv6 connections are still accepted fine, but IPv4 connections cause
accept() to return -1 with errno ECONNABORTED.
(Context: This causes KDE3 apps which open listen sockets, such as krfbd,
to fail after applying a patch discussed in KDE bug 59100 to implement use
of INET6_IPV6ONLY.)
>How-To-Repeat:
Run the following, then try connecting with telnet or similar to both ::1
port 5901, and 127.0.0.1 port 5901. The accept() should always work
regardless of the sysctl setting above, but fails when
net.inet6.ip6.v6only=1 and connecting via IPv4 (127.0.0.1).
===== BEGIN =====
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <err.h>
#include <unistd.h>
int main(void) {
int sock = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
int opt = 0;
int optlen = sizeof(opt);
struct sockaddr_in6 sa = {0};
if (sock < 0)
err(1, "socket");
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&opt, optlen))
err(1, "setsockopt(v6only)");
opt = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, optlen))
err(1, "setsockopt(reuseaddr)");
sa.sin6_family = AF_INET6;
sa.sin6_addr = in6addr_any;
sa.sin6_port = htons(5901);
if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)))
err(1, "bind");
if (listen(sock, 3))
err(1, "listen");
if (accept(sock, NULL, NULL) < 0)
err(1, "accept");
}
===== END =====
>Fix:
Unknown. This is probably a very roundabout issue deep in the netinet6
stack, and I can't find it (a netinet6 guru needs to look at this).
in6_pcballoc() appears to set the flag IN6P_IPV6_V6ONLY if the sysctl is
on; this is the same flag changed by the setsockopt call. Something must
not be properly handling the socket-internal data when this is not set at
pcballoc time and is set by setsockopt later.
>Release-Note:
>Audit-Trail:
From: Todd Vierling <tv@pobox.com>
To: gnats-bugs@gnats.netbsd.org
Cc:
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to
ECONNABORTED
Date: Thu, 29 May 2003 15:34:41 -0400 (EDT)
On Thu, 29 May 2003 tv@pobox.com wrote:
: in6_pcballoc() appears to set the flag IN6P_IPV6_V6ONLY if the sysctl is
: on; this is the same flag changed by the setsockopt call. Something must
: not be properly handling the socket-internal data when this is not set at
: pcballoc time and is set by setsockopt later.
Obvious correction:
"Something must not be properly handling the socket-internal data when this
is set at pcballoc time and cleared by setsockopt later." (i.e. sysctl
turns the pcb flag on; setsockopt turns it off.)
--
-- Todd Vierling <tv@pobox.com>
From: itojun@iijlab.net
To: tv@pobox.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Fri, 30 May 2003 08:47:54 +0900
>>Synopsis: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
this is the intended behavior.
itojun
State-Changed-From-To: open->closed
State-Changed-By: itojun
State-Changed-When: Thu May 29 23:48:40 UTC 2003
State-Changed-Why:
this is the intended behavior.
State-Changed-From-To: closed->open
State-Changed-By: itojun
State-Changed-When: Thu May 29 23:53:04 UTC 2003
State-Changed-Why:
sorry, i did not read it carefully
From: itojun@iijlab.net
To: tv@pobox.com
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Fri, 30 May 2003 08:56:54 +0900
> sa.sin6_family = AF_INET6;
> sa.sin6_addr = in6addr_any;
> sa.sin6_port = htons(5901);
you forgot memset(&sa, 0, sizeof(sa)); before this.
itojun
From: itojun@iijlab.net
To: tv@pobox.com, gnats-bugs@gnats.netbsd.org
Cc:
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Fri, 30 May 2003 09:08:57 +0900
>> sa.sin6_family = AF_INET6;
>> sa.sin6_addr = in6addr_any;
>> sa.sin6_port = htons(5901);
> you forgot memset(&sa, 0, sizeof(sa)); before this.
and "sa.sin6_len = sizeof(struct sockaddr_in6);"
itojun
From: Todd Vierling <tv@pobox.com>
To: itojun@netbsd.org
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to
ECONNABORTED
Date: Thu, 29 May 2003 20:37:21 -0400 (EDT)
On Fri, 30 May 2003 itojun@iijlab.net wrote:
: > sa.sin6_family = AF_INET6;
: > sa.sin6_addr = in6addr_any;
: > sa.sin6_port = htons(5901);
:
: you forgot memset(&sa, 0, sizeof(sa)); before this.
No I didn't. I used:
struct sockaddr_in6 sa = {0};
This is functionally equivalent according to ANSI. However, to satisfy your
request, the modified testcase below uses memset(3) instead.
: and "sa.sin6_len = sizeof(struct sockaddr_in6);"
Note that when net.inet6.ip6.v6only=0, everything works, which indicates
that missing sa_len is not a runtime error -- even if it is a programmer
mistake. :)
I've fixed this in the example case below, and it does not fix the problem.
I still get ECONNABORTED when connecting to 127.0.0.1. Please actually try
running the code under net.inet6.ip6.v6only=1 and connecting to both ::1 and
127.0.0.1 to see the difference.
===== BEGIN =====
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <err.h>
#include <unistd.h>
int main(void) {
int sock = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP);
int opt = 0;
int optlen = sizeof(opt);
struct sockaddr_in6 sa;
if (sock < 0)
err(1, "socket");
if (setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&opt, optlen))
err(1, "setsockopt(v6only)");
opt = 1;
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, optlen))
err(1, "setsockopt(reuseaddr)");
memset(&sa, 0, sizeof(sa));
sa.sin6_len = sizeof(sa);
sa.sin6_family = AF_INET6;
sa.sin6_addr = in6addr_any;
sa.sin6_port = htons(5902);
if (bind(sock, (struct sockaddr *)&sa, sizeof(sa)))
err(1, "bind");
if (listen(sock, 3))
err(1, "listen");
if (accept(sock, NULL, NULL) < 0)
err(1, "accept");
}
===== END =====
--
-- Todd Vierling <tv@pobox.com>
From: itojun@iijlab.net
To: Todd Vierling <tv@pobox.com>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Fri, 30 May 2003 10:04:23 +0900
>: and "sa.sin6_len = sizeof(struct sockaddr_in6);"
>
>Note that when net.inet6.ip6.v6only=0, everything works, which indicates
>that missing sa_len is not a runtime error -- even if it is a programmer
>mistake. :)
>
>I've fixed this in the example case below, and it does not fix the problem.
>I still get ECONNABORTED when connecting to 127.0.0.1. Please actually try
>running the code under net.inet6.ip6.v6only=1 and connecting to both ::1 and
>127.0.0.1 to see the difference.
i've tracked down the problem, fix is coming soon.
on PRU_ACCEPT, we need to copy some of in6p->in6p_flags bits from
the listening socket to the accepted socket. we don't have that
statement right now.
itojun
From: Jun-ichiro itojun Hagino <itojun@netbsd.org>
To: gnats-bugs@gnats.netbsd.org
Cc:
Subject: pr/21713 CVS commit: src/sys/netinet
Date: Fri, 30 May 2003 01:15:06 +0000 (UTC)
Module Name: src
Committed By: itojun
Date: Fri May 30 01:15:06 UTC 2003
Modified Files:
src/sys/netinet: tcp_input.c
Log Message:
inherit IPV6_V6ONLY from listening socket. PR 21713
To generate a diff of this commit:
cvs rdiff -r1.167 -r1.168 src/sys/netinet/tcp_input.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: itojun@iijlab.net
To: Todd Vierling <tv@pobox.com>, gnats-bugs@gnats.netbsd.org
Cc:
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Fri, 30 May 2003 10:16:11 +0900
> i've tracked down the problem, fix is coming soon.
>
> on PRU_ACCEPT, we need to copy some of in6p->in6p_flags bits from
> the listening socket to the accepted socket. we don't have that
> statement right now.
pls try tcp_input.c 1.168
itojun
From: Todd Vierling <tv@pobox.com>
To: itojun@iijlab.net
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to
ECONNABORTED
Date: Fri, 30 May 2003 14:48:41 -0400 (EDT)
On Fri, 30 May 2003 itojun@iijlab.net wrote:
: > i've tracked down the problem, fix is coming soon.
: >
: > on PRU_ACCEPT, we need to copy some of in6p->in6p_flags bits from
: > the listening socket to the accepted socket. we don't have that
: > statement right now.
:
: pls try tcp_input.c 1.168
Fix verified. Please make sure this is pulled up to netbsd-1-6, as it does
break parts of KDE3.
--
-- Todd Vierling <tv@pobox.com>
From: itojun@iijlab.net
To: Todd Vierling <tv@pobox.com>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Sat, 31 May 2003 18:14:06 +0900
>Fix verified. Please make sure this is pulled up to netbsd-1-6, as it does
>break parts of KDE3.
is IPV6_V6ONLY used in original KDE3, or you are patching it in pkgsrc
patches/patch-xx?
if the latter, please avoid the use of IPV6_V6ONLY and make KDE3
listen to multiple sockets (AF_INET and AF_INET6). setting IPV6_V6ONLY
to 0 on server side has serious security drawbacks.
itojun
From: Todd Vierling <tv@pobox.com>
To: itojun@iijlab.net
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to
ECONNABORTED
Date: Sat, 31 May 2003 07:12:17 -0400 (EDT)
On Sat, 31 May 2003 itojun@iijlab.net wrote:
: >Fix verified. Please make sure this is pulled up to netbsd-1-6, as it does
: >break parts of KDE3.
:
: is IPV6_V6ONLY used in original KDE3, or you are patching it in pkgsrc
: patches/patch-xx?
KDE 3.1.3 will contain it, yes.
: if the latter, please avoid the use of IPV6_V6ONLY and make KDE3
: listen to multiple sockets (AF_INET and AF_INET6). setting IPV6_V6ONLY
: to 0 on server side has serious security drawbacks.
I'm aware of the security concerns (mainly involving sysadmin error, not
kernel error), but this is KDE's design choice. They want apps to have both
IPv6 and IPv4 by default when both are available. Since the app-side code
rarely cares what the sockaddr is, setting V6ONLY to 0 is no worse on
security than listening on two sockets simultaneously.
KDE3 shipped using IPv6 sockets accepting IPv4 connections by default. KDE
3.1.2 assumed that V6ONLY was set to 0 by default, which is true on FreeBSD
but not NetBSD/OpenBSD. The easy fix is to set V6ONLY=0 explicitly on a
per-socket basis so that the default is the same on all OS's for KDE.
Getting the KDE folks to listen separately on two sockets will be much
harder. 8-) However, they did provide method calls to set the V6ONLY
behavior per socket, allowing more advanced apps to turn it on or off
explicitly (regardless of host OS).
--
-- Todd Vierling <tv@pobox.com>
From: itojun@iijlab.net
To: Todd Vierling <tv@pobox.com>
Cc: gnats-bugs@gnats.netbsd.org
Subject: Re: kern/21713: INET6_IPV6ONLY causes inbound IPv4 connections to ECONNABORTED
Date: Mon, 02 Jun 2003 11:09:23 +0900
>KDE3 shipped using IPv6 sockets accepting IPv4 connections by default. KDE
>3.1.2 assumed that V6ONLY was set to 0 by default, which is true on FreeBSD
>but not NetBSD/OpenBSD. The easy fix is to set V6ONLY=0 explicitly on a
>per-socket basis so that the default is the same on all OS's for KDE.
with FreeBSD 5.0 and beyond the default value for V6ONLY is 1.
itojun
From: SAITOH Masanobu <msaitoh@netbsd.org>
To: gnats-bugs@gnats.netbsd.org
Cc:
Subject: pr/21713 CVS commit: [netbsd-1-6] src/sys/netinet
Date: Tue, 17 Jun 2003 09:48:27 +0000 (UTC)
Module Name: src
Committed By: msaitoh
Date: Tue Jun 17 09:48:26 UTC 2003
Modified Files:
src/sys/netinet [netbsd-1-6]: tcp_input.c
Log Message:
Pull up revisions 1.168 (requested by itojun in ticket #1304):
inherit IPV6_V6ONLY from listening socket. Fixes PR#21713.
To generate a diff of this commit:
cvs rdiff -r1.141.4.5 -r1.141.4.6 src/sys/netinet/tcp_input.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: itojun
State-Changed-When: Sat Jul 12 16:43:45 UTC 2003
State-Changed-Why:
fixed
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.