Page MenuHomeFreeBSD

freebsd32: Make sendmsg match native ABI for unpadded final control message
ClosedPublic

Authored by jrtc27 on Sep 13 2022, 11:19 PM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 23 2023, 1:38 AM
Unknown Object (File)
Dec 12 2023, 8:33 AM
Unknown Object (File)
Oct 6 2023, 3:46 PM
Unknown Object (File)
Aug 15 2023, 6:51 PM
Unknown Object (File)
Aug 14 2023, 3:43 PM
Unknown Object (File)
Aug 14 2023, 2:48 AM
Unknown Object (File)
Aug 5 2023, 12:36 AM
Unknown Object (File)
Aug 5 2023, 12:33 AM
Subscribers

Details

Summary

The API says that CMSG_SPACE should be used for msg_controllen, but in
practice the native ABI allows you to only use CMSG_LEN for the final
(typically only) control message, and real-world software does this,
including Wayland. For freebsd32, this is in practice mostly harmless,
since control messages are generally used to carry file descriptors,
which are already 4 bytes in size and thus no padding is needed, but
they can carry other quantities that may not result in an aligned
length. This was discovered after CheriBSD's freebsd64 equivalent was
updated to match the freebsd32 implementation, as that uses 8 byte
alignment which does break the file descriptor use case, and thus
Wayland.

This used to be addressed by aligning buflen before the first iteration,
but that allowed unwanted invalid inputs and was lost in 1b1428dcc82b,
with no safer equivalent put in its place.

Obtained from: CheriBSD
Fixes: 1b1428dcc82b ("Fix a TOCTOU vulnerability in freebsd32_copyin_control().")
MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Sep 14 2022, 7:21 AM

The API says that CMSG_SPACE should be used for msg_controllen

The example in CMSG_DATA.3 uses CMSG_LEN(). :(

The API says that CMSG_SPACE should be used for msg_controllen

The example in CMSG_DATA.3 uses CMSG_LEN(). :(

For cmsg_len, which is correct. For msg_controllen it uses sizeof(cmsgbuf.buf), which is CMSG_SPACE(sizeof(int)).