Page MenuHomeFreeBSD

netinet6: ip6_setpktopt() requires NET_EPOCH
ClosedPublic

Authored by kp on Dec 15 2021, 1:56 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mar 4 2024, 8:09 AM
Unknown Object (File)
Feb 14 2024, 1:42 PM
Unknown Object (File)
Dec 23 2023, 3:04 AM
Unknown Object (File)
Dec 14 2023, 10:34 AM
Unknown Object (File)
Dec 12 2023, 3:25 AM
Unknown Object (File)
Nov 23 2023, 11:10 AM
Unknown Object (File)
Nov 13 2023, 10:51 PM
Unknown Object (File)
Nov 11 2023, 9:22 PM

Details

Summary

ip6_setpktopt() can call ifnet_byindex() which requires epoch. Mark the
function as requiring NET_EPOCH, and ensure we enter it priot to calling
it.

Reported-by: syzbot+92526116441688fea8a3@syzkaller.appspotmail.com
Sponsored by: Rubicon Communications, LLC ("Netgate")

Diff Detail

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

Event Timeline

kp requested review of this revision.Dec 15 2021, 1:56 PM

I'm not IPv6 expert, so may suggest a stupid thing. There multiple places where we do ifnet_byindex() and then supply the result to in6_setscope(). Note that in6_setscope() enters the epoch recursively. Is it worth to create KPI that would setscope by index?

I'm not IPv6 expert, so may suggest a stupid thing. There multiple places where we do ifnet_byindex() and then supply the result to in6_setscope(). Note that in6_setscope() enters the epoch recursively. Is it worth to create KPI that would setscope by index?

Maybe. While I was looking at this I wondered if it'd be worth expanding the NET_EPOCH coverage a bit more so that basically the entire setsockopt/ioctl/... code path is covered. We've got a struct ifnet pointer if nothing else, and we shouldn't expect that to remain while we're outside of NET_EPOCH. That's a much bigger change though, and I was only looking to fix a low-hanging bug found by syzcaller.

In D33462#757218, @kp wrote:

Maybe. While I was looking at this I wondered if it'd be worth expanding the NET_EPOCH coverage a bit more so that basically the entire setsockopt/ioctl/... code path is covered. We've got a struct ifnet pointer if nothing else, and we shouldn't expect that to remain while we're outside of NET_EPOCH. That's a much bigger change though, and I was only looking to fix a low-hanging bug found by syzcaller.

But that would require to have memory preallocated, as many setsockopts allocate. The setsockopt path is probably the most difficult with the epoch protected network stack.

In D33462#757218, @kp wrote:

Maybe. While I was looking at this I wondered if it'd be worth expanding the NET_EPOCH coverage a bit more so that basically the entire setsockopt/ioctl/... code path is covered. We've got a struct ifnet pointer if nothing else, and we shouldn't expect that to remain while we're outside of NET_EPOCH. That's a much bigger change though, and I was only looking to fix a low-hanging bug found by syzcaller.

But that would require to have memory preallocated, as many setsockopts allocate. The setsockopt path is probably the most difficult with the epoch protected network stack.

Yeah, that's a concern.

I've had a quick look around w.r.t. your original suggestion, and as far as I can see there's not really a pattern of ifnet_byindex() / in6_setscope() in the tree, so introducing a separate function for this seems like it would accomplish little.

There might be room for a variant of in6_setscope() which assumes it's already in NET_EPOCH. There are certainly a few paths where that's the case and we could save ourselves the work of entering NET_EPOCH recursively. That's a bigger change (and with a bit more risk) than I'm looking to make here though.

In D33462#757723, @kp wrote:

I've had a quick look around w.r.t. your original suggestion, and as far as I can see there's not really a pattern of ifnet_byindex() / in6_setscope() in the tree, so introducing a separate function for this seems like it would accomplish little.
There might be room for a variant of in6_setscope() which assumes it's already in NET_EPOCH. There are certainly a few paths where that's the case and we could save ourselves the work of entering NET_EPOCH recursively. That's a bigger change (and with a bit more risk) than I'm looking to make here though.

Sorry for stupid suggestion then! The current patch looks good to me. A more thorough redesign can be left for later.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 17 2021, 5:00 PM
This revision was automatically updated to reflect the committed changes.