Page MenuHomeFreeBSD

Check the setsockop value size passed by the user before copying it in.
AbandonedPublic

Authored by brooks on Apr 27 2017, 4:15 AM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 18 2025, 7:26 AM
Unknown Object (File)
Jan 13 2025, 5:22 PM
Unknown Object (File)
Jan 2 2025, 12:40 AM
Unknown Object (File)
Dec 26 2024, 7:01 AM
Unknown Object (File)
Dec 2 2024, 12:55 PM
Unknown Object (File)
Oct 7 2024, 5:41 AM
Unknown Object (File)
Sep 30 2024, 2:04 AM
Unknown Object (File)
Sep 22 2024, 6:08 AM
Subscribers
None

Details

Reviewers
asomers
ngie
Group Reviewers
network
Summary

The current sockoption processing code completely ignores the size of
the passed option when copying it in. This change rejects sizes that
aren't exactly what is expected to prevent bugs like passing size_t
where int is meant.

Test Plan

We should write tests to pass nonsense sizes.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 8929
Build 9319: arc lint + arc unit

Event Timeline

ngie requested changes to this revision.Apr 27 2017, 6:48 AM

net@ should be CCed on this

Should this logic be shoved into sooptcopyin, given that the appropriate lengths are passed in (just to avoid unnecessary duplication)?

sys/kern/uipc_socket.c
2681

Why not remove this, then remove the surrounding braces in the new code?

This revision now requires changes to proceed.Apr 27 2017, 6:48 AM
In D10519#217948, @ngie wrote:

Should this logic be shoved into sooptcopyin, given that the appropriate lengths are passed in (just to avoid unnecessary duplication)?

sooptcopyin has different and incompatible length checking (even if called with the available length it wouldn't return an error when a size_t is passed in place of an int). We should be calling it correctly, but that won't fix this bug.

sys/kern/uipc_socket.c
2681

What do you refer to by "this"?

In D10519#217948, @ngie wrote:

Should this logic be shoved into sooptcopyin, given that the appropriate lengths are passed in (just to avoid unnecessary duplication)?

sooptcopyin has different and incompatible length checking (even if called with the available length it wouldn't return an error when a size_t is passed in place of an int). We should be calling it correctly, but that won't fix this bug.

Upon further reflection, I think we are calling sooptcopyin correctly, it just has a weird interface that isn't what we want here. A sensible approach might be to create an sooptcopyin_exact.

I believe this is the wrong approach, the right approach is likely a sooptcopyin_exact or sooptcopyin_flag. I've submitted https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=218919 to track this issue.