From owner-freebsd-bugs@FreeBSD.ORG Thu May 23 20:00:00 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.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 BE18B13C for ; Thu, 23 May 2013 20:00:00 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id A4FDCDDC for ; Thu, 23 May 2013 20:00:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id r4NK00UV010516 for ; Thu, 23 May 2013 20:00:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id r4NK00if010515; Thu, 23 May 2013 20:00:00 GMT (envelope-from gnats) Resent-Date: Thu, 23 May 2013 20:00:00 GMT Resent-Message-Id: <201305232000.r4NK00if010515@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Steve Zweep Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 90B7F12B for ; Thu, 23 May 2013 19:59:03 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from oldred.FreeBSD.org (oldred.freebsd.org [8.8.178.121]) by mx1.freebsd.org (Postfix) with ESMTP id 693F6DD2 for ; Thu, 23 May 2013 19:59:03 +0000 (UTC) Received: from oldred.FreeBSD.org ([127.0.1.6]) by oldred.FreeBSD.org (8.14.5/8.14.5) with ESMTP id r4NJx2k7090785 for ; Thu, 23 May 2013 19:59:02 GMT (envelope-from nobody@oldred.FreeBSD.org) Received: (from nobody@localhost) by oldred.FreeBSD.org (8.14.5/8.14.5/Submit) id r4NJx2wD090784; Thu, 23 May 2013 19:59:02 GMT (envelope-from nobody) Message-Id: <201305231959.r4NJx2wD090784@oldred.FreeBSD.org> Date: Thu, 23 May 2013 19:59:02 GMT From: Steve Zweep To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: kern/178881: [patch] getifaddrs(3) does not report IPv6 addresses properly in 32-bit compatibility mode X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 May 2013 20:00:00 -0000 >Number: 178881 >Category: kern >Synopsis: [patch] getifaddrs(3) does not report IPv6 addresses properly in 32-bit compatibility mode >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu May 23 20:00:00 UTC 2013 >Closed-Date: >Last-Modified: >Originator: Steve Zweep >Release: 9.1-RELEASE (amd64) >Organization: WatchGuard Technologies >Environment: FreeBSD outland2.borderware.com 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243825: Tue Dec 4 09:23:10 UTC 2012 root@farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC amd64 >Description: This was uncovered trying to run 32-bit Postfix on a 64-bit kernel, and subsequently verified with a simple utility which just iterates and prints the IP addresses returned from getifaddrs(). In 32-bit compatibility mode IPv4 addresses are reported correctly, but IPv6 addresses are not. The address family is reported as '0' instead of the expected 28 for AF_INET6. The same test utility works as expected when compiled as a 64-bit executable. >How-To-Repeat: - configure a network interface with an IPv6 address - compile a 32-bit program which calls getifaddrs() to iterate through interface addresses - examine the output >Fix: The problem appears to be in the 32-bit compatibility code in sys/net/rtsock.c which handles the NET_RT_IFLIST sysctl used by getifaddrs(). The calculated size of the sockaddr structure does not match that which the client code in getifaddrs is expecting. I'm no expert here, but the following patch worked for me: --- rtsock.c.orig 2013-04-15 17:01:25.000000000 -0400 +++ rtsock.c 2013-04-19 11:53:09.000000000 -0400 @@ -1157,6 +1157,13 @@ default: len = sizeof(struct rt_msghdr); } + +#ifdef COMPAT_FREEBSD32 +#define SA_SIZE32(sa) ( (!(sa) || ((struct sockaddr *)(sa))->sa_len == 0) ? \ + sizeof(uint32_t) : \ + 1 + ( (((struct sockaddr *)(sa))->sa_len - 1) | (sizeof(uint32_t) - 1) ) ) +#endif + cp0 = cp; if (cp0) cp += len; @@ -1166,7 +1173,12 @@ if ((sa = rtinfo->rti_info[i]) == NULL) continue; rtinfo->rti_addrs |= (1 << i); - dlen = SA_SIZE(sa); +#ifdef COMPAT_FREEBSD32 + if (w != NULL && w->w_req->flags & SCTL_MASK32) + dlen = SA_SIZE32(sa); + else +#endif + dlen = SA_SIZE(sa); if (cp) { bcopy((caddr_t)sa, cp, (unsigned)dlen); cp += dlen; >Release-Note: >Audit-Trail: >Unformatted: