[Xcb] [PATCH libxcb] Fix alignment issues in FD passing code
Uli Schlachter
psychon at znc.in
Wed Nov 13 13:47:54 PST 2013
On 11.11.2013 23:11, Mark Kettenis wrote:
> From: Mark Kettenis <kettenis at openbsd.org>
>
> A char array on the stack is not guaranteed to have more than byte alignment.
> This means that casting it to a 'struct cmsghdr' and accessing its members
> may result in unaligned access. This will generate SIGBUS on struct
> alignment architectures like OpenBSD/sparc64. The canonical solution is to
> use a union to force proper alignment.
Since this mail had a response on xorg-devel which didn't go to the xcb list:
On 12.11.2013 01:52, Mouse wrote:
>> A char array on the stack is not guaranteed to have more than byte
>> alignment. This means that casting it to a 'struct cmsghdr' and
>> accessing its members may result in unaligned access. This will
>> generate SIGBUS on struct alignment architectures like
>> OpenBSD/sparc64. The canonical solution is to use a union to force
>> proper alignment.
>
> This is good enough for access to the struct cmsghdr. It is, however,
> not good enough to use CMSG_DATA (nor, I think, CMSG_NXTHDR) on the
> resulting cmsghdr; as far as I can tell there is no way to align the
> buffer correctly for that. If you're willing to make the assumption
> (which I find no grounds for in 3542) that it's the alignment of some
> object type, you can malloc the buffer, but in at least some
> implementations, the alignment required is chosen by the kernel and can
> potentially vary, either between runs (eg, across a
> mostly-binary-compatible OS version change) or even at run time. In
> any case, I see no grounds, except for an unwarranted familiarity with
> certain common implementations, for assuming that the alignment of
> struct cmsghdr is sufficient.
>
> This is one of the reasons I consider the CMSG_* interface
> fundamentally broken.
>
> /~\ The ASCII Mouse
> \ / Ribbon Campaign
> X Against HTML mouse at rodents-montreal.org
> / \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
(Just writing this to make sure it gets seen and whoever wants to handle this
patch knows this)
Uli
--
If you have to type the letters "A-E-S" into your source code, you're doing it
wrong.
More information about the Xcb
mailing list