Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 04 Jan 2013 14:41:48 -0500
From:      Jung-uk Kim <jkim@FreeBSD.org>
To:        Martin Laabs <info@martinlaabs.de>
Cc:        freebsd-emulation@freebsd.org
Subject:   Re: Bug analyzed - how to fix it?
Message-ID:  <50E7307C.3000205@FreeBSD.org>
In-Reply-To: <50E71402.8010702@martinlaabs.de>
References:  <50E71402.8010702@martinlaabs.de>

next in thread | previous in thread | raw e-mail | index | archive | help
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2013-01-04 12:40:18 -0500, Martin Laabs wrote:
> Hi,
> 
> I'm (hopefully) done with the bug analyses of 
> "http://www.freebsd.org/cgi/query-pr.cgi?pr=174933". The bug in one
> sentences: if_nameindex (resided in the libc) fails if called out
> of a linux binary.
> 
> The cause is that the if_nameindex calls a function named
> __opensock that return a socket. This socket is used to call an
> ioctl(SIOCGIFCONF ...). This ioctl call is actually implemented in
> the linuxulator. Unfortunately the __opensock function tries to
> create the following socket:
> 
> socket(PF_NETLINK, SOCK_RAW, 0) in decimal: socket(16,3,0)

It seems "0" is actually NETLINK_ROUTE:

http://fxr.watson.org/fxr/source/include/uapi/linux/netlink.h?v=linux-2.6#L7

> This type of socket type however is not supported by the
> linuxulator and IMHO in freebsd at all. However - maybe it just has
> another name in FreeBSD.

It is one of those Linux-only things that we cannot be easily add to
Linuxulator, I'm afraid:

http://en.wikipedia.org/wiki/Netlink
http://tools.ietf.org/html/rfc3549

> So - for me there seem to be two solutions:
> 
> 1. Write a dirty patch that returns a PF_INET instead of the
> PF_NETLINK socket if called with the arguments above. This should
> be OK since I assume that SIOCGIFCONF ioctl works also fine with
> PF_INET sockets. (I'll test this to verify whether this is true) 
> This however would be somewhat dirty since PF_NETLINK sockets are
> not really supported and if another application tries to open a
> real PF_NETLINK socket it will get a false positive result.
> 
> 2. Patch the glibc to not create a PF_NETLINK socket in __opensock
> but create a PF_INET socket instead. The problem is that I do not
> know about the side effects since the __opensock function is used
> elsewhere in the libc also. The second drawback is that this would
> lead to a customized libc for the linuxulator. As far as I know the
> current libc(s) are just bare copies out of linux systems. So this
> solution would also increase maintenance effort.
> 
> Do you have an other idea how to fix the problem?

I just glanced at the GNU libc sources.  I found they had backward
shims for pre-netlink kernels.

sysdeps/unix/sysv/linux/kernel-features.h [*]:

/* With kernel 2.4.17 we always have netlink support.  */
#if __LINUX_KERNEL_VERSION >= (132096+17)
# define __ASSUME_NETLINK_SUPPORT      1
#endif

In other words, if the GNU libc was compiled for Linux 2.4.17 and
later, it assumes the netlink is always available and it won't bother
compiling in fallback functions.

Jung-uk Kim

* Note: the fallback methods was completely removed in recent glibc.

http://www.sourceware.org/git/gitweb.cgi?p=glibc.git;a=commit;h=89b4b02f421d2a6d24eb632d9c6977dbe786e6ee
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)

iQEcBAEBAgAGBQJQ5zB8AAoJECXpabHZMqHOsUIIAII/XRA/I1Gppf/aWHpLlyTI
xoS3F8fx3fvrQtKQqPmdrMRScCvAdYyCpsaJP4S2efNV+eYO1scpSMK74TSjUVJu
MwVa4m9eJGqj8WLFpII3qVU0XEHl1hjWKI68B38FoOkdX6MVJq35AoZ4D9MYdN3X
wNYkWoa5q0tjGjWGxlolMKarU9mdabJyNpNMk4XO96khDm5g9JbnLoNVPeRXoeef
VOfw7b05a+otstnPYscldgnuEL1IGphneRr+AVGwUmafzDNk9fY5vVe+3AcOQRvJ
1qwuoQrAAkrk6NxwR95o8UTKZdbin4872kw4iZceRi4wiR3EJ6z0cU9UhaDMR50=
=duLb
-----END PGP SIGNATURE-----



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?50E7307C.3000205>