Page MenuHomeFreeBSD

MAC: improve handling of listening sockets
ClosedPublic

Authored by tuexen on Sep 22 2024, 8:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Jan 26, 6:09 PM
Unknown Object (File)
Sat, Jan 25, 5:05 PM
Unknown Object (File)
Fri, Jan 24, 9:17 AM
Unknown Object (File)
Thu, Jan 23, 4:19 AM
Unknown Object (File)
Jan 17 2025, 10:06 PM
Unknown Object (File)
Jan 12 2025, 3:15 PM
Unknown Object (File)
Jan 12 2025, 11:26 AM
Unknown Object (File)
Nov 24 2024, 10:37 AM
Subscribers

Details

Summary

so_peerlabel can only be used when the socket is not listening.

Test Plan
kldload mac_test
nc -l 1234

and then terminate nc using CTRL-C.

Diff Detail

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

Event Timeline

Hum, this bug is quite old. :(

sys/kern/uipc_socket.c
4178

The right place to check this is in mac_getsockopt_peerlabel(). Without the socket lock (which is acquired in that function), it is possible for listen() and getsockopt(SO_PEERLABEL) to race with each other.

tuexen added inline comments.
sys/kern/uipc_socket.c
4178

I totally agree. Fixed. But doesn't this comment apply also to the others usages of SOLISTENING() in sogetopt()?

sys/kern/uipc_socket.c
4178

Most likely, yes. There are many SOLISTENING races, unfortunately. Some of the ones below are mostly harmless in that they'll just return a garbage value if the race is lost.

sys/security/mac/mac_socket.c
584

Shouldn't this be in mac_getsockopt_peerlabel()?

Fix mac_getsockopt_label(), not mac_setsockopt_label() as pointed out by Mark.

tuexen added inline comments.
sys/kern/uipc_socket.c
4178

OK, I'll fix them. I decided to not call SOCK_LOCK(), because it wan't called in that places...

sys/security/mac/mac_socket.c
584

Yes, of course. Thanks for catching that.

markj added a subscriber: olivier.

I think this is ok. The bug suggests that we should optionally run the regression test suite with mac_test loaded. I tried it locally and easily reproduced the original panic. Perhaps @olivier would want to try this in his test environment?

This revision is now accepted and ready to land.Sep 24 2024, 8:47 AM
This revision was automatically updated to reflect the committed changes.
tuexen marked 2 inline comments as done.