Page MenuHomeFreeBSD

tests/unix_passfd: test that control mixed with data creates records
ClosedPublic

Authored by glebius on Feb 3 2024, 9:13 PM.
Tags
None
Referenced Files
F108454676: D43724.diff
Fri, Jan 24, 11:35 PM
Unknown Object (File)
Dec 16 2024, 6:13 PM
Unknown Object (File)
Dec 13 2024, 7:25 AM
Unknown Object (File)
Dec 5 2024, 12:15 PM
Unknown Object (File)
Nov 28 2024, 9:59 AM
Unknown Object (File)
Nov 26 2024, 8:40 PM
Unknown Object (File)
Nov 24 2024, 9:59 PM
Unknown Object (File)
Nov 2 2024, 2:09 AM
Subscribers

Details

Summary

If socket has data interleaved with control it would never allow to read
two pieces of data, neither two pieces of control with one recvmsg(2). In
other words, presence of control makes a SOCK_STREAM socket behave like
SOCK_SEQPACKET, where control marks the records. This is not a documented
or specified behavior, but this is how it worked always for BSD sockets.
If you look closer at it, this actually makes a lot of sense, as if it
were the opposite both the kernel code and an application code would
become way more complex.

The change made recvfd_payload() to return received length and requires
caller to do ATF_REQUIRE() itself. This required a small change to
existing test rights_creds_payload. It also refactors a bit f28532a0f363,
pushing two identical calls out of TEST_PROTO ifdef.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 55789
Build 52678: arc lint + arc unit

Event Timeline

tests/sys/kern/unix_passfd_test.c
207

Since this function does not return negative values (it asserts that recvmsg() does not fail), it can return a size_t, so callers don't need to cast.

968

This line does nothing, the loop will iterate once.

971

Same here.

oops, should be <=. I've been testing it wrong all the time.

Fix cycles to actually do the test!

tests/sys/kern/unix_passfd_test.c
207

I'd prefer not to. Now there is one caller that casts and one that doesn't cast, as it compares to another ssize_t. Potentially in the future internal assertion can be removed if yet another test would want to check that recvfd_payload() actually failed. Like we already have for sendfd_payload().

tests/sys/kern/unix_passfd_test.c
952
970

IMO it is worth asserting that close() returns 0. It can help catch test bugs at least.

Assert close(2) was successful.

markj added inline comments.
tests/sys/kern/unix_passfd_test.c
970

Missed this naked close() call. Yes it is probably excessive, but it doesn't hurt.

This revision is now accepted and ready to land.Feb 6 2024, 4:11 PM