Bug 99068 - [linux] [patch] Linux emulator crashed by java, when calling ioctl(fd,SIOCGIFINDEX,...)
Summary: [linux] [patch] Linux emulator crashed by java, when calling ioctl(fd,SIOCGIF...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-emulation (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-06-17 02:20 UTC by Federico Ignacio
Modified: 2011-01-30 08:10 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Federico Ignacio 2006-06-17 02:20:21 UTC
While trying to install Oracle 10g under Linux compatibility, the installer
freezes.
Really the problem seems to reside in the Java VM, or the linux emulation.
In the system console and /var/log/messages I get:
Jun 16 21:33:53 freebsd kernel: linux: pid 79295 (java): ioctl fd=21, cmd=0x8933 ('�',51) is not implemented
I was surfing internet, and seems there are more java applications with
the same problem.

Fix: 

For what I can see, it seems that it fails calling:
    ioctl(fd,SIOCGIFINDEX,&if). 

I mean, 0x8933 is SIOCGIFINDEX in Linux (that's something i found -not
100% sure-), but get's incorrectly mapped in FreeBSD.

SIOCGIFINDEX definition (after tracing trough .h files) is an OR from
different things, including the size of a "struct ifreq" I guess this
strcut size is different in Linux and BSD.

***
from sys/sockio.h
    #define SIOCGIFINDEX    _IOWR('i', 32, struct ifreq)    /* get IF index */
from sys/ioccom.h
    #define _IOC(inout,group,num,len) \
        ((unsigned long)(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num)))

    #define IOC_INOUT       (IOC_IN|IOC_OUT)
    #define _IOWR(g,n,t)    _IOC(IOC_INOUT, (g), (n), sizeof(t))
***

The solution may be implement a workaround in the /usr/src/sys/net/if.c ?
although it would be really dirty. Or maybe making "ifreq" the same size
that in Linux. There must be a better way...
How-To-Repeat: Install plain FreeBSD 6.1 with additional packages: unzip, linux_base
and linux_devel. Of course set linux compatibility on.
Install XFree86-libs-4.3.0-35.EL from "RedHat Enterprise Linux 3" (this
is needed to get /usr/X11R6/lib/LibXp.so.6 initially missing)
Download oracle 10g for Linux 32bit.
Unpack with unzip, and run from user "oracle" "runInstaller" just pres
"next" couple of times, and the screen freezes.
Comment 1 Marcin Cieslak 2006-09-10 21:18:13 UTC
A quick patch for this as below (linux.h needs to patched
for all architectures).

--- linux.h	Sun Sep 10 22:03:28 2006
+++ linux.h_new	Sun Sep 10 22:02:53 2006
@@ -657,6 +657,7 @@
  		struct l_sockaddr	ifru_hwaddr;
  		l_short		ifru_flags[1];
  		l_int		ifru_metric;
+		l_int		ifru_ivalue;
  		l_int		ifru_mtu;
  		struct l_ifmap	ifru_map;
  		char		ifru_slave[LINUX_IFNAMSIZ];
@@ -666,6 +667,7 @@

  #define	ifr_name	ifr_ifrn.ifrn_name	/* interface name */
  #define	ifr_hwaddr	ifr_ifru.ifru_hwaddr	/* MAC address */
+#define	ifr_ifindex	ifr_ifru.ifru_ivalue	/* Interface index */

  /*
   * poll()
--- linux_ioctl.h	Sun Sep 10 22:05:48 2006
+++ linux_ioctl.h_new	Sun Sep 10 22:05:32 2006
@@ -196,9 +196,10 @@
  #define	LINUX_SIOCGIFHWADDR	0x8927
  #define	LINUX_SIOCADDMULTI	0x8931
  #define	LINUX_SIOCDELMULTI	0x8932
+#define	LINUX_SIOCGIFINDEX	0x8933

  #define	LINUX_IOCTL_SOCKET_MIN	LINUX_FIOSETOWN
-#define	LINUX_IOCTL_SOCKET_MAX	LINUX_SIOCDELMULTI
+#define	LINUX_IOCTL_SOCKET_MAX	LINUX_SIOCGIFINDEX

  /*
   * Device private ioctl calls
--- linux_ioctl.c	Sun Sep 10 22:05:48 2006
+++ linux_ioctl.c_new	Sun Sep 10 22:08:24 2006
@@ -2239,6 +2239,17 @@
  	return (copyout(&flags, &ifr->ifr_flags, sizeof(flags)));
  }

+static int
+linux_ifindex(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr)
+{
+#if DEBUG
+	printf("Interface index: %d\n", ifp->if_index);
+#endif
+	l_int index;
+	index = ifp->if_index;
+	return (copyout(&index, &ifr->ifr_ifindex, sizeof(index)));
+}
+
  #define ARPHRD_ETHER	1
  #define ARPHRD_LOOPBACK	772

@@ -2325,6 +2336,7 @@
  	case LINUX_SIOCSIFADDR:
  	case LINUX_SIOCGIFDSTADDR:
  	case LINUX_SIOCGIFBRDADDR:
+	case LINUX_SIOCGIFINDEX:
  	case LINUX_SIOCGIFNETMASK:
  	case LINUX_SIOCSIFNETMASK:
  	case LINUX_SIOCGIFMTU:
@@ -2421,6 +2433,11 @@
  	case LINUX_SIOCGIFBRDADDR:
  		args->cmd = OSIOCGIFBRDADDR;
  		error = ioctl(td, (struct ioctl_args *)args);
+		break;
+
+	case LINUX_SIOCGIFINDEX:
+		args->cmd = SIOCGIFINDEX;
+		error = linux_ifindex(td, ifp, (struct l_ifreq *)args->arg);
  		break;

  	case LINUX_SIOCGIFNETMASK:

-- 
               << Marcin Cieslak // saper@system.pl >>
Comment 2 Alexander Leidinger 2006-09-11 08:29:16 UTC
Quoting Marcin Cieslak <saper@SYSTEM.PL> (from Sun, 10 Sep 2006  
22:18:13 +0200):

> --- linux_ioctl.c	Sun Sep 10 22:05:48 2006
> +++ linux_ioctl.c_new	Sun Sep 10 22:08:24 2006
> @@ -2239,6 +2239,17 @@
>  	return (copyout(&flags, &ifr->ifr_flags, sizeof(flags)));
>  }
>
> +static int
> +linux_ifindex(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr)
> +{
> +#if DEBUG
> +	printf("Interface index: %d\n", ifp->if_index);

Minor issues: we have a linux-debug-printf-something for such  
purposes. Please have a look at other places in the linux emulation  
code where DEBUG is used. And it would be nice if it also tells where  
this message comes from (function name).

Bye,
Alexander.

-- 
	Max told his friend that he'd just as soon not go hiking in the hills.
Said he, "I'm an anti-climb Max."

http://www.Leidinger.net    Alexander @ Leidinger.net: PGP ID = B0063FE7
http://www.FreeBSD.org       netchild @ FreeBSD.org  : PGP ID = 72077137
Comment 3 Marcin Cieslak 2008-07-11 22:40:44 UTC
I think this is fixed by revision 1.139 of linux_ioctl.c.

-- 
               << Marcin Cieslak // saper@system.pl >>
Comment 4 Mark Linimon freebsd_committer freebsd_triage 2008-07-12 07:46:30 UTC
State Changed
From-To: open->feedback

Note that submitter has been asked for feedback.
Comment 5 Alexander Best freebsd_committer freebsd_triage 2010-08-17 20:57:01 UTC
Responsible Changed
From-To: freebsd-bugs->freebsd-emulation

Over to maintainer(s).
Comment 6 Alexander Best freebsd_committer freebsd_triage 2011-01-30 08:07:54 UTC
State Changed
From-To: feedback->closed

1) Feedback timeout. 
2) Fixed in HEAD (r180768). 
3) MFC'ed to stable/7 in r173628.