Page MenuHomeFreeBSD

unix/stream: do not put empty mbufs on the socket
ClosedPublic

Authored by glebius on Feb 4 2024, 4:37 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Jan 27, 6:58 AM
Unknown Object (File)
Dec 18 2024, 1:29 PM
Unknown Object (File)
Dec 8 2024, 7:24 PM
Unknown Object (File)
Nov 30 2024, 12:01 PM
Unknown Object (File)
Nov 2 2024, 2:41 AM
Unknown Object (File)
Oct 27 2024, 6:23 AM
Unknown Object (File)
Oct 26 2024, 10:03 AM
Unknown Object (File)
Sep 28 2024, 10:03 AM
Subscribers

Details

Summary

It is a legitimate case to use sendmsg(2) to send control only, with zero
bytes of data and then recvmsg(2) them with zero length iov, receiving
control only. This sendmsg(2)+recmsg(2) would leave a zero length mbuf on
the top of the socket buffer. If you now try to repeat this combo again,
your recvmsg(2) would not return control data, because it sits behind an
MT_DATA mbuf and you have provided zero length uio_resid. IMHO, best
strategy to deal with zero length buffers in a chain is to not put them
there in the first place. Thus, solve this right in uipc_send() instead
of touching soreceive_generic().

Diff Detail

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

Event Timeline

sys/kern/uipc_usrreq.c
1005

Presumably you plan to remove the print before committing.

1013

So the right behaviour for SEQPACKET sockets is still to receive the 0-length message?

glebius added inline comments.
sys/kern/uipc_usrreq.c
1005

Oops, thanks :)

1013

At this point I don't care about them. This file marks them as PR_ATOMIC, which makes soreceive_generic() threat them like datagram sockets, which is against the specification. They are also marked as PR_ADDR, but they don't return sockaddr. This &sun_noname is a crutch to create a boundary record, the address is not returned in recv(2). There is XXXRW comment down there, but I'm not sure PR_ADDR and the crutch are required really, PR_ATOMIC should be enough.

Anyway, in my new uipc_soreceive_stream_or_seqpacket() they will be treated according to specification. Some tests might need an adjustments and new tests need to be written. Right now I'm getting close to all SOCK_STREAM test passed and then will work on SEQPACKET.

glebius marked an inline comment as done.

Remove debug printfs.

markj added inline comments.
sys/kern/uipc_usrreq.c
1003
This revision is now accepted and ready to land.Feb 6 2024, 4:08 PM