From nobody@FreeBSD.org  Tue Jun 28 03:20:27 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 431E5106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 28 Jun 2011 03:20:27 +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 1B5D58FC21
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 28 Jun 2011 03:20:27 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p5S3KQHC069147
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 28 Jun 2011 03:20:26 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p5S3KQqu069145;
	Tue, 28 Jun 2011 03:20:26 GMT
	(envelope-from nobody)
Message-Id: <201106280320.p5S3KQqu069145@red.freebsd.org>
Date: Tue, 28 Jun 2011 03:20:26 GMT
From: Paul Procacci <pprocacci@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ioctl SIOCGIFCONF in chroot bug?
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         158369
>Category:       kern
>Synopsis:       ioctl SIOCGIFCONF in chroot(2) bug?
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    pluknet
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 28 03:30:16 UTC 2011
>Closed-Date:    Tue Jul 05 10:03:51 UTC 2011
>Last-Modified:  Tue Jul  5 10:10:08 UTC 2011
>Originator:     Paul Procacci
>Release:        8.2-STABLE
>Organization:
>Environment:
FreeBSD work_machine.myhome 8.2-STABLE FreeBSD 8.2-STABLE #1: Mon Jun 27 18:51:19 CDT 2011     root@work_machine.myhome:/usr/obj/usr/src/sys/WORK_MACHINE  amd64
>Description:
chroot'd applications within a i386 environment (amd64 host) that utilize:

################################
ioctl(fd, SIOCGIFCONF, ifc); 
################################

...aren't working properly.  It's seems the ifc_len member of the ifconf
structure never gets updated.

Utilizing fresh installs of both amd64 and i386 everything seems to work
fine.  However when running this with a chroot'd i386 install on a amd64
host, it fails miserably.

This came up with trying to get wine working with a game.  Here is a
reference to the related wine bug that I filed:

http://bugs.winehq.org/show_bug.cgi?id=27614

Thoughts?
>How-To-Repeat:
1) Install FreeBSD (I choose to install 8.2-STABLE)

2) Install an i386 chroot:
cd /usr/src && make buildworld installworld distribution TARGET=i386 DESTDIR=/compat/i386

3) Compile the following program once in the 64bit env, and again in the chroot'd 32bit env.

################################
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>

int main(void)
{
    struct ifconf *ifc;
    struct ifconf difc;
    int lastlen, cnt = 0;
    int ioctlRet = 0;
    int guessedNumAddresses = 0, numAddresses = 0;

  int fd;
  fd = socket(PF_INET, SOCK_DGRAM, 0);

    ifc=&difc;

    ifc->ifc_len = 0;
    ifc->ifc_buf = NULL;
    if (fd != -1)
    {
        do {
          ifc->ifc_buf = NULL;
          printf("%i ::",cnt);
          cnt++;
          lastlen = ifc->ifc_len;
          if (guessedNumAddresses == 0)
            guessedNumAddresses = 4;
          else
            guessedNumAddresses *= 2;
          ifc->ifc_len = sizeof(struct ifreq) * guessedNumAddresses;
          ifc->ifc_buf = malloc(ifc->ifc_len);
          ioctlRet = ioctl(fd, SIOCGIFCONF, ifc);
          printf("  %i %i %i %s\n",ioctlRet,ifc->ifc_len,lastlen,ifc->ifc_buf);
        } while ((ioctlRet == 0) && (ifc->ifc_len != lastlen));
    }
}
################################
>Fix:
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-amd64->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Jun 28 04:13:50 UTC 2011 
Responsible-Changed-Why:  
reclassify. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=158369 
Responsible-Changed-From-To: freebsd-bugs->pluknet 
Responsible-Changed-By: pluknet 
Responsible-Changed-When: Tue Jun 28 07:33:16 UTC 2011 
Responsible-Changed-Why:  
Take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=158369 
State-Changed-From-To: open->patched 
State-Changed-By: pluknet 
State-Changed-When: Tue Jun 28 08:42:00 UTC 2011 
State-Changed-Why:  
Fixed in head with MFC in 1 week. Thanks for reporting! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=158369 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/158369: commit references a PR
Date: Tue, 28 Jun 2011 08:41:54 +0000 (UTC)

 Author: pluknet
 Date: Tue Jun 28 08:41:44 2011
 New Revision: 223625
 URL: http://svn.freebsd.org/changeset/base/223625
 
 Log:
   Update ifc_len field of struct ifconf passed for the ioctl SIOCGIFCONF32
   (i.e. under COMPAT_FREEBSD32) in case ifconf() returned success to match
   the native SIOCGIFCONF behavior.
   
   PR:		kern/158369
   Reported by:	Paul Procacci <pprocacci att gmail com>
   MFC after:	1 week
 
 Modified:
   head/sys/net/if.c
 
 Modified: head/sys/net/if.c
 ==============================================================================
 --- head/sys/net/if.c	Tue Jun 28 08:36:48 2011	(r223624)
 +++ head/sys/net/if.c	Tue Jun 28 08:41:44 2011	(r223625)
 @@ -2467,6 +2467,8 @@ ifioctl(struct socket *so, u_long cmd, c
  
  			error = ifconf(SIOCGIFCONF, (void *)&ifc);
  			CURVNET_RESTORE();
 +			if (error == 0)
 +				ifc32->ifc_len = ifc.ifc_len;
  			return (error);
  		}
  #endif
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: pluknet 
State-Changed-When: Tue Jul 5 10:03:28 UTC 2011 
State-Changed-Why:  
Merged to stable/8 in r223782. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=158369 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/158369: commit references a PR
Date: Tue,  5 Jul 2011 10:03:31 +0000 (UTC)

 Author: pluknet
 Date: Tue Jul  5 10:03:21 2011
 New Revision: 223782
 URL: http://svn.freebsd.org/changeset/base/223782
 
 Log:
   MFC r223625:
   
    Update ifc_len field of struct ifconf passed for the ioctl SIOCGIFCONF32.
   
   PR:		kern/158369
 
 Modified:
   stable/8/sys/net/if.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
 
 Modified: stable/8/sys/net/if.c
 ==============================================================================
 --- stable/8/sys/net/if.c	Tue Jul  5 07:05:18 2011	(r223781)
 +++ stable/8/sys/net/if.c	Tue Jul  5 10:03:21 2011	(r223782)
 @@ -2527,6 +2527,8 @@ ifioctl(struct socket *so, u_long cmd, c
  
  			error = ifconf(SIOCGIFCONF, (void *)&ifc);
  			CURVNET_RESTORE();
 +			if (error == 0)
 +				ifc32->ifc_len = ifc.ifc_len;
  			return (error);
  		}
  #endif
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
