From nobody@FreeBSD.org  Mon Oct 24 00:55:34 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 4E07C106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 24 Oct 2011 00:55:34 +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 3D8B58FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 24 Oct 2011 00:55:34 +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 p9O0tYaE092212
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 24 Oct 2011 00:55:34 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p9O0tXex092211;
	Mon, 24 Oct 2011 00:55:33 GMT
	(envelope-from nobody)
Message-Id: <201110240055.p9O0tXex092211@red.freebsd.org>
Date: Mon, 24 Oct 2011 00:55:33 GMT
From: Charles Davis <cdavis@mymail.mines.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [kern] 64-bit structures are used even with 32-bit code
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161949
>Category:       kern
>Synopsis:       [kernel] 64-bit structures are used even with 32-bit code
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 24 01:00:02 UTC 2011
>Closed-Date:    
>Last-Modified:  Mon Jan 02 05:22:04 UTC 2012
>Originator:     Charles Davis
>Release:        8.2-RELEASE
>Organization:
Colorado School of Mines
>Environment:
FreeBSD <hostname> 8.2-RELEASE-p3 FreeBSD 8.2-RELEASE-p3 #0: Tue Sep 27 18:45:57 UTC 2011    root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC amd64
>Description:
When a process transfers data to or from the kernel, and those data are
organized into structures whose size depends on whether or not the size
of a pointer is 4 or 8 bytes, an LP64 kernel always uses 64-bit structures,
even with 32-bit processes. I know this is true of structures returned from
sysctl(3), but I also think it is true of structures used with ioctl(2)
and fcntl(2). Because 32-bit processes expect 32-bit structures, attempts
to use the 64-bit structures fail at best and cause massive data corruption
at worst.

This is already affecting real-world code. A patch of mine that was
recently committed to Wine (http://www.winehq.org) exposed this issue
with the xtcpcb and xinpcb structs returned by the sysctl(3)s
"net.inet.tcp.pcblist" and "net.inet.udp.pcblist" (cf. Wine bug 28857:
http://bugs.winehq.org/show_bug.cgi?id=28857).

>How-To-Repeat:
Run any 32-bit program under a 64-bit kernel that calls sysctl(3),
ioctl(2), or fcntl(2) and uses a data structure with those calls whose
size depends on the pointer size.
>Fix:
FreeBSD should detect if a process is a 32-bit one, and if so, it should
use 32-bit structures instead of 64-bit ones. I don't know how the former
can be done; a cursory look through the <sys/proc.h> header reveals
nothing. The latter is easy, but tedious: definitions for the 32-bit
structs must be added to the kernel headers.

Another way to solve this problem (at the cost of binary compatibility
for 32-bit programs) is to simply make the 32-bit and 64-bit structures
the same.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-amd64->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Oct 25 13:22:25 UTC 2011 
Responsible-Changed-Why:  
reclassify this one to see if that gets it a wider audience. 

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