Page MenuHomeFreeBSD

linux: Fix sockopt copyout
ClosedPublic

Authored by chuck on Mar 16 2026, 6:34 PM.
Tags
None
Referenced Files
F160525983: D55881.id.diff
Thu, Jun 25, 8:53 AM
Unknown Object (File)
Wed, Jun 24, 12:13 PM
Unknown Object (File)
Wed, Jun 24, 5:09 AM
Unknown Object (File)
Wed, Jun 24, 3:36 AM
Unknown Object (File)
Tue, Jun 23, 6:44 AM
Unknown Object (File)
Sun, Jun 21, 3:00 AM
Unknown Object (File)
Sun, Jun 21, 3:00 AM
Unknown Object (File)
Sat, Jun 20, 6:21 PM
Subscribers

Details

Summary

The Linux getsockopt did not check the size of the provided buffer when
copying out the value, leading to buffer overflows (e.g., for TCP_INFO).

Fix is to use the smaller of the option value size and the provided
buffer.

Diff Detail

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

Event Timeline

chuck requested review of this revision.Mar 16 2026, 6:34 PM
sys/compat/linux/linux_socket.c
2319

Is it right to use FreeBSD-native type for socklen? Do we need e.g. linux_socklen_t, if we do not have it already?

sys/compat/linux/linux_socket.c
2319

There is a l_socklen_t in sys/amd64/linux/linux.h, but it is defined as an l_ulong. Since linux_getsockopt_args defines optlen as l_uintptr_t, perhaps this should be l_uint?

sys/compat/linux/linux_socket.c
2319

But why l_uint? It should be l_socklen_t, no?

sys/compat/linux/linux_socket.c
2319

In the Linux sources the type is int *. I don't know why our emulator uses l_uintptr_t, it looks incorrect. Probably that should be fixed.

Update change from review feedback

This revision is now accepted and ready to land.Sat, Jun 6, 3:37 AM
sys/compat/linux/linux_socket.c
2321–2322

Now I don't understand what this change is fixing. Is it the loptlen < 0 check that's required?

sys/compat/linux/linux_socket.c
2321–2322

The fix is the copyin() of optlen to reconcile how much data to copyout() (smaller of length passed to the function and the Linux buffer length).

The "less than zero" check is to account for the sign difference when converting Linux's integer optlen to (an unsigned) socklen_t in order to compare the buffer sizes.

This revision now requires review to proceed.Mon, Jun 8, 6:11 PM
This revision is now accepted and ready to land.Mon, Jun 8, 6:23 PM
This revision was automatically updated to reflect the committed changes.