Bug 161949 - [kernel] 64-bit structures are used even with 32-bit code
Summary: [kernel] 64-bit structures are used even with 32-bit code
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 8.2-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-24 02:00 UTC by Charles Davis
Modified: 2017-12-31 22:32 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 Charles Davis 2011-10-24 02:00:02 UTC
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).

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.
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.
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2011-10-25 14:22:25 UTC
Responsible Changed
From-To: freebsd-amd64->freebsd-bugs

reclassify this one to see if that gets it a wider audience.
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:00:38 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped