kern/114325: SIOCGIFADDR ioctl behaves incorrectly inside jail
Floris Bos
info at je-eigen-domein.nl
Thu Jul 5 08:20:04 UTC 2007
>Number: 114325
>Category: kern
>Synopsis: SIOCGIFADDR ioctl behaves incorrectly inside jail
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Thu Jul 05 08:20:03 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator: Floris Bos
>Release: FreeBSD 6.2-STABLE-200702
>Organization:
>Environment:
FreeBSD cheetah.to-the-max.net 6.2-STABLE-200702 FreeBSD 6.2-STABLE-200702 #0: Sat Mar 10 01:09:58 CET 2007 max at cheetah.to-the-max.net:/usr/obj/usr/src/sys/MAX amd64
>Description:
Inside a jail: When using the SIOCGIFADDR ioctl to retrieve the IP-address of a network device it returns the main IP-address of the parent host instead of the jail's IP-address.
Inside a jail with IP-address 83.149.75.179:
# ifconfig
nve0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 83.149.75.179 netmask 0xffffffff broadcast 83.149.75.179
ether 00:e0:81:5f:b5:ad
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
bge0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
options=1b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING>
ether 00:e0:81:5f:b5:ac
media: Ethernet autoselect (none)
status: no carrier
plip0: flags=108810<POINTOPOINT,SIMPLEX,MULTICAST,NEEDSGIANT> mtu 1500
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
# ./ipaddr
According to SIOCGIFADDR Device nve0 has IP-address: 83.149.75.182
>How-To-Repeat:
- Use a server with multiple IP-addresses.
- Create a jail using one of the IP-addresses other than the main address.
- Compile and execute the following program inside the jail (change the ETHERNET_DEVICE to the name of the network device):
ipaddr.c:
==
#include <string.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
// The ethernet device to retrieve the IP of
#define ETHERNET_DEVICE "nve0"
int main(int argc, char **argv)
{
int sock;
struct ifreq ifr;
struct sockaddr_in *ifaddr;
sock = socket(AF_INET, SOCK_DGRAM, 0);
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, ETHERNET_DEVICE, IF_NAMESIZE);
if (ioctl(sock, SIOCGIFADDR, &ifr) == -1)
{
perror("Error retrieving IP address");
}
else
{
ifaddr = (struct sockaddr_in *)&ifr.ifr_addr;
printf("According to SIOCGIFADDR Device %s has IP-address: %s\n", ETHERNET_DEVICE, inet_ntoa(ifaddr->sin_addr));
}
return 0;
}
==
Expected behavior: it should return the IP-address of the jail.
Actual behavior: it returns the main IP-address of the parent environment.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list