From nobody@FreeBSD.org  Thu Jan  3 10:53:49 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	by hub.freebsd.org (Postfix) with ESMTP id 0A68E62A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  3 Jan 2013 10:53:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id D96ADF07
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  3 Jan 2013 10:53:48 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id r03ArlAi024689
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 3 Jan 2013 10:53:47 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id r03Arlbd024688;
	Thu, 3 Jan 2013 10:53:47 GMT
	(envelope-from nobody)
Message-Id: <201301031053.r03Arlbd024688@red.freebsd.org>
Date: Thu, 3 Jan 2013 10:53:47 GMT
From: Martin Laabs <info@martinlaabs.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: if_nameindex fail in linuxulator enviroment
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         174933
>Category:       kern
>Synopsis:       [linux] if_nameindex fail in linuxulator enviroment
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-emulation
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 03 11:00:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Sun Jan 20 01:55:28 UTC 2013
>Originator:     Martin Laabs
>Release:        9.0-RELEASE-p3
>Organization:
>Environment:
reeBSD pc.martinlaabs.de 9.0-RELEASE-p3 FreeBSD 9.0-RELEASE-p3 #0: Tue Jun 12 02:52:29 UTC 2012     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
The function call if_nameindex out of the libc failes (return NULL) if it is called out of a linux application.
The cause of the failure is an inappropriate call of socket likely called in the __opensock function in the libc. This can be seen out of a ktrace dump:

[...]
3319 a.out    CALL  linux_socketcall(0x1,0xffffc6d4)
3319 a.out    RET   linux_socketcall -1 errno 97 Address family not supported by protocol family
[...]

The cause of the wrong arguments for this socket call is not known to me up to now.

For all the test I use the f10 linux environment. Tests with different linux-base versions are pending. Maybe someone who installed them can do it. On request I can send the linux binary compiled on debian with a 2.6.18 kernel and libc-2.3.6.
>How-To-Repeat:
Compile the following program on FreeBSD and Linux:
Check the return code - maybe the program will segfault if run as linux binary.

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
     struct if_nameindex *ifn;
  
  /*Can be omitted - just to test if this makes a difference since
  the __opensock function remember the last socket options*/
  socket(AF_INET, SOCK_DGRAM, 0);

  ifn=if_nameindex();
  if(ifn==0) 
     err("if_nameindex failed\n"); 

 return 0;
}

>Fix:


>Release-Note:
>Audit-Trail:

From: Eitan Adler <lists@eitanadler.com>
To: bug-followup <bug-followup@freebsd.org>
Cc:  
Subject: Re: kern/174933
Date: Fri, 4 Jan 2013 13:04:31 -0500

 ---------- Forwarded message ----------
 From: Martin Laabs <info@martinlaabs.de>
 Date: 4 January 2013 12:40
 Subject: Bug analyzed - how to fix it?
 To: freebsd-emulation@freebsd.org
 
 
 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)
 
 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.
 
 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?
 
 Thank you,
  Martin
 
 _______________________________________________
 freebsd-emulation@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/freebsd-emulation
 To unsubscribe, send any mail to "freebsd-emulation-unsubscribe@freebsd.org"
 
 
 -- 
 Eitan Adler
Responsible-Changed-From-To: freebsd-bugs->freebsd-emulation 
Responsible-Changed-By: dchagin 
Responsible-Changed-When: Tue Jan 8 13:09:13 UTC 2013 
Responsible-Changed-Why:  
Over to maintainers. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=174933 
>Unformatted:
