HomeFreeBSD

The sendfile(2) allows to send extra data from userspace before the file

Description

The sendfile(2) allows to send extra data from userspace before the file
data (headers). Historically the size of the headers was not checked
against the socket buffer space. Application could easily overcommit the
socket buffer space.

With the new sendfile (r293439) the problem remained, but a KASSERT was
inserted that checked that amount of data written to the socket matches
its space. In case when size of headers is bigger that socket space,
KASSERT fires. Without INVARIANTS the new sendfile won't panic, but
would report incorrect amount of bytes sent.

o With this change, the headers copyin is moved down into the cycle, after

the sbspace() check.  The uio size is trimmed by socket space there,
which fixes the overcommit problem and its consequences.

o The compatibility handling for FreeBSD 4 sendfile headers API is pushed

up the stack to syscall wrappers.  This required a copy and paste of the
code, but in turn this allowed to remove extra stack carried parameter
from fo_sendfile_t, and embrace entire compat code into #ifdef.  If in
future we got more fo_sendfile_t function, the copy and paste level would
even reduce.

Reviewed by: emax, gallatin, Maxim Dounin <mdounin mdounin.ru>
Tested by: Vitalij Satanivskij <satan ukr.net>
Sponsored by: Netflix

Details

Provenance
glebiusAuthored on
Reviewer
emax
Parents
rS297399: Type of the interrupt handlers on x86 cannot be expressed in C.
Branches
Unknown
Tags
Unknown