Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Oct 2011 00:55:33 GMT
From:      Charles Davis <cdavis@mymail.mines.edu>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   amd64/161949: [kern] 64-bit structures are used even with 32-bit code
Message-ID:  <201110240055.p9O0tXex092211@red.freebsd.org>
Resent-Message-ID: <201110240100.p9O102cE072182@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         161949
>Category:       amd64
>Synopsis:       [kern] 64-bit structures are used even with 32-bit code
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-amd64
>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:
>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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201110240055.p9O0tXex092211>