NetBSD Problem Report #13279
Received: (qmail 2569 invoked from network); 21 Jun 2001 23:22:23 -0000
Message-Id: <20010621232441.31BD37C5@starfruit.itojun.org>
Date: Fri, 22 Jun 2001 08:24:41 +0900 (JST)
From: itojun@itojun.org
Reply-To: itojun@itojun.org
To: gnats-bugs@gnats.netbsd.org
Cc: Cedric Berger <cedric@wireless-networks.com>
Subject: sys/compat/linux should rewrite sa_family in sockaddr
X-Send-Pr-Version: 3.95
>Number: 13279
>Category: kern
>Synopsis: sys/compat/linux should rewrite sa_family in sockaddr
>Confidential: no
>Severity: serious
>Priority: low
>Responsible: jdolecek
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Jun 21 23:23:01 +0000 2001
>Closed-Date: Wed Jul 04 10:06:54 +0000 2001
>Last-Modified: Wed Jul 04 10:06:54 +0000 2001
>Originator: Jun-ichiro itojun Hagino
>Release: all releases and current
>Organization:
itojun.org
>Environment:
System: NetBSD starfruit.itojun.org 1.5W NetBSD 1.5W (STARFRUIT) #506: Mon Jun 18 12:19:27 JST 2001 itojun@starfruit.itojun.org:/usr/home/itojun/NetBSD/src/sys/arch/i386/compile/STARFRUIT i386
Architecture: i386
Machine: i386
>Description:
sys/compat/linux/linux_socket.c does not try to rewrite sa_family
in sockaddr args to various syscalls that take sockaddr
(connect, bind, sendto...). therefore, when LINUX_AF_xx differs
from AF_xx, linux emulation won't work. {LINUX_,}AF_INET6 is
an example.
http://www.sigmasoft.com/~openbsd/archive/openbsd-tech/200106/msg00266.html
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: kern-bug-people->jdolecek
Responsible-Changed-By: jdolecek
Responsible-Changed-When: Fri Jun 22 09:14:28 PDT 2001
Responsible-Changed-Why:
I'll take care of this.
From: Jaromír Dolecek <jdolecek@NetBSD.org>
To: itojun@itojun.org
Cc: gnats-bugs@gnats.netbsd.org, Cedric Berger <cedric@wireless-networks.com>
Subject: Re: kern/13279: sys/compat/linux should rewrite sa_family in sockaddr
Date: Tue, 26 Jun 2001 20:30:32 +0200 (CEST)
Hi Itojun,
I have an IPv6 (or maybe ratger "getaddrinfo") question for you.
I've made necessary changes for Linux emulation to modify the family
accordingly. It seems to work OK for IPv4, and even for IPv6 with
a small hack.
Now the description of why I need a hack. If I ignore initial
sockaddr family/sa_len stuff, NetBSD getaddrinfo(3) returns
address "0:16:0...0:1:0:0". If I compile the binary as Linux binary
and run it on same system, Linux getaddrinfo(3) returns same address,
but without the four trailing zero bytes. If I make the program use
the address with trailing zeros (i.e. the address returned by NetBSD
getaddrinfo(2)), it works either when compiled
on NetBSD or Linux. If I use the getaddrinfo() result, the Linux
binary gets EINVAL from the connect(2).
I can send you the test program if you want to, but it's quite
streightforwardly written by the example in getaddrinfo() manpage.
The only difference is I hint getaddrinfo to get IPv6 address, and
use port 'ssh':
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_INET6;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
error = getaddrinfo("::1", "ssh", &hints, &res);
The question is: do you have any idea what may be the problem here?
Jaromir
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
NetBSD - just plain best OS! -=*=- Got spare MCA cards or docs? Hand me them!
From: Cedric Berger <cedric@wireless-networks.com>
To: =?iso-8859-1?Q?Jarom=EDr?= Dolecek <jdolecek@NetBSD.org>
Cc: itojun@itojun.org, gnats-bugs@gnats.netbsd.org
Subject: Re: kern/13279: sys/compat/linux should rewrite sa_family in sockaddr
Date: Tue, 26 Jun 2001 11:43:54 -0700
Hi Jaromír,
"Jaromír Dolecek" wrote:
> Hi Itojun,
>
> I have an IPv6 (or maybe ratger "getaddrinfo") question for you.
>
> I've made necessary changes for Linux emulation to modify the family
> accordingly. It seems to work OK for IPv4, and even for IPv6 with
> a small hack.
Do you have the code? I was planning to implement that *this afternoon*
on OpenBSD, but I don't feel like doing duplicate work. I you've the
patches, I gladly review them and test them on OpenBSD, as I said.
I believe OpenBSD and NetBSD have very simmilar code here.
Cedric
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
To: jdolecek@NetBSD.org
Cc: gnats-bugs@gnats.netbsd.org,
Cedric Berger <cedric@wireless-networks.com>
Subject: Re: kern/13279: sys/compat/linux should rewrite sa_family in sockaddr
Date: Wed, 27 Jun 2001 03:51:32 +0900
>Hi Itojun,
>
>I have an IPv6 (or maybe ratger "getaddrinfo") question for you.
>
>I've made necessary changes for Linux emulation to modify the family
>accordingly. It seems to work OK for IPv4, and even for IPv6 with
>a small hack.
>
>Now the description of why I need a hack. If I ignore initial
>sockaddr family/sa_len stuff, NetBSD getaddrinfo(3) returns
>address "0:16:0...0:1:0:0". If I compile the binary as Linux binary
>and run it on same system, Linux getaddrinfo(3) returns same address,
>but without the four trailing zero bytes. If I make the program use
>the address with trailing zeros (i.e. the address returned by NetBSD
>getaddrinfo(2)), it works either when compiled
>on NetBSD or Linux. If I use the getaddrinfo() result, the Linux
>binary gets EINVAL from the connect(2).
I guess you are using older Linux IPv6 code/library.
the definition of sockaddr_in6 was changed between RFC2133 and 2553.
RFC2133 is totally obsolete (Linux uses this).
most of the currently-exisitng systems (including NetBSD) implement
RFC2553.
here are options we can take:
- require Linux binaries to use RFC2553 API (newer libc headers
use RFC2553, so require it)
- modify sizes as necessary in emulation layer. very bad idea
(linux API can see two distinct address as being the same)
i vote for the first one.
itojun
RFC2133:
truct sockaddr_in6 {
u_int16m_t sin6_family; /* AF_INET6 */
u_int16m_t sin6_port; /* transport layer port # */
u_int32m_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
};
RFC2533:
struct sockaddr_in6 {
sa_family_t sin6_family; /* AF_INET6 */
in_port_t sin6_port; /* transport layer port # */
uint32_t sin6_flowinfo; /* IPv6 traffic class & flow info */
struct in6_addr sin6_addr; /* IPv6 address */
uint32_t sin6_scope_id; /* set of interfaces for a scope */
};
>
>I can send you the test program if you want to, but it's quite
>streightforwardly written by the example in getaddrinfo() manpage.
>The only difference is I hint getaddrinfo to get IPv6 address, and
>use port 'ssh':
>
> memset(&hints, 0, sizeof(hints));
> hints.ai_family = PF_INET6;
> hints.ai_socktype = SOCK_STREAM;
> hints.ai_protocol = 0;
> error = getaddrinfo("::1", "ssh", &hints, &res);
>
>The question is: do you have any idea what may be the problem here?
>
>Jaromir
>--
>Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
>NetBSD - just plain best OS! -=*=- Got spare MCA cards or docs? Hand me them!
>
From: Jaromír Dolecek <jdolecek@NetBSD.org>
To: Jun-ichiro itojun Hagino <itojun@iijlab.net>
Cc: gnats-bugs@gnats.netbsd.org, Cedric Berger <cedric@wireless-networks.com>
Subject: Re: kern/13279: sys/compat/linux should rewrite sa_family in sockaddr
Date: Tue, 26 Jun 2001 21:27:35 +0200 (CEST)
Jun-ichiro itojun Hagino wrote:
> I guess you are using older Linux IPv6 code/library.
That's right. The definition lacks the scope_id in Linux header I have.
Thanks!
> here are options we can take:
> - require Linux binaries to use RFC2553 API (newer libc headers
> use RFC2553, so require it)
> - modify sizes as necessary in emulation layer. very bad idea
> (linux API can see two distinct address as being the same)
> i vote for the first one.
I'd vote too, however SuSE as recent as 6.3 used the obsolete form :(
At least, I've got the headers via suse_devel-6.3 package.
How often does the scope id actually differ in practice? I'd probably
make the code fake scopeid 0 for Linux if it's using the old struct,
and log message about that at LOG_DEBUG (or LOG_INFO) level.
Jaromir
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
NetBSD - just plain best OS! -=*=- Got spare MCA cards or docs? Hand me them!
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
To: jdolecek@NetBSD.org
Cc: gnats-bugs@gnats.netbsd.org,
Cedric Berger <cedric@wireless-networks.com>
Subject: Re: kern/13279: sys/compat/linux should rewrite sa_family in sockaddr
Date: Wed, 27 Jun 2001 04:33:29 +0900
>> here are options we can take:
>> - require Linux binaries to use RFC2553 API (newer libc headers
>> use RFC2553, so require it)
>> - modify sizes as necessary in emulation layer. very bad idea
>> (linux API can see two distinct address as being the same)
>> i vote for the first one.
>
>I'd vote too, however SuSE as recent as 6.3 used the obsolete form :(
>At least, I've got the headers via suse_devel-6.3 package.
>
>How often does the scope id actually differ in practice? I'd probably
all linklocal address and site-local addresses.
it is not the issue with "how often". you can't just put dummy
value, when the value identifies communiating peer.
by putting dummy value you will open up security hole (bad guy
can pretend to be A while he actually is B, and such).
i really vote strongly to the former.
>make the code fake scopeid 0 for Linux if it's using the old struct,
>and log message about that at LOG_DEBUG (or LOG_INFO) level.
please don't fill it with 0. reject shorter sockaddr_in6.
itojun
From: Jaromír Dolecek <jdolecek@NetBSD.org>
To: Jun-ichiro itojun Hagino <itojun@iijlab.net>
Cc: gnats-bugs@gnats.netbsd.org, Cedric Berger <cedric@wireless-networks.com>
Subject: Re: kern/13279: sys/compat/linux should rewrite sa_family in sockaddr
Date: Tue, 26 Jun 2001 21:59:16 +0200 (CEST)
Jun-ichiro itojun Hagino wrote:
> please don't fill it with 0. reject shorter sockaddr_in6.
OK, I'll make it so.
Jaromir
--
Jaromir Dolecek <jdolecek@NetBSD.org> http://www.ics.muni.cz/~dolecek/
NetBSD - just plain best OS! -=*=- Got spare MCA cards or docs? Hand me them!
State-Changed-From-To: open->analyzed
State-Changed-By: jdolecek
State-Changed-When: Fri Jun 29 02:52:50 PDT 2001
State-Changed-Why:
I have patch to this. Tested it with simple IPv6 program, should
probably undergo more testing before commit. I've asked for testers
on current-users@, currently waiting for reply.
State-Changed-From-To: analyzed->closed
State-Changed-By: jdolecek
State-Changed-When: Wed Jul 4 03:06:38 PDT 2001
State-Changed-Why:
Fixed, thanks for report.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.49 2026/05/14 01:52:41 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.