HomeFreeBSD

Fix handling of errors from pru_send(PRUS_NOTREADY)

Description

Fix handling of errors from pru_send(PRUS_NOTREADY)

PRUS_NOTREADY indicates that the caller has not yet populated the chain
with data, and so it is not ready for transmission. This is used by
sendfile (for async I/O) and KTLS (for encryption). In particular, if
pru_send returns an error, the caller is responsible for freeing the
chain since other implicit references to the data buffers exist.

For async sendfile, it happens that an error will only be returned if
the connection was dropped, in which case tcp_usr_ready() will handle
freeing the chain. But since KTLS can be used in conjunction with the
regular socket I/O system calls, many more error cases - which do not
result in the connection being dropped - are reachable. In these cases,
KTLS was effectively assuming success.

So:

  • Change sosend_generic() to free the mbuf chain if pru_send(PRUS_NOTREADY) fails. Nothing else owns a reference to the chain at that point.
  • Similarly, in vn_sendfile() change the !async I/O && KTLS case to free the chain.
  • If async I/O is still outstanding when pru_send fails in vn_sendfile(), set an error in the sfio structure so that the connection is aborted and the mbuf chain is freed.

Reviewed by: gallatin, tuexen
Discussed with: jhb
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 916c61a5ed37da8ecdedd3c5512813d8dcec9a24)

Details

Provenance
markjAuthored on May 21 2021, 9:44 PM
Parents
rG0f05c6f3a527: tcp: Make error handling in tcp_usr_send() more consistent
Branches
Unknown
Tags
Unknown