Page MenuHomeFreeBSD

sendfile: Ensure that sfio->npages is initialized
ClosedPublic

Authored by markj on Dec 22 2020, 5:31 PM.
Tags
None
Referenced Files
F150597456: D27726.id81063.diff
Thu, Apr 2, 4:52 PM
F150535525: D27726.diff
Thu, Apr 2, 3:35 AM
Unknown Object (File)
Sun, Mar 29, 1:43 PM
Unknown Object (File)
Mon, Mar 23, 4:18 PM
Unknown Object (File)
Wed, Mar 11, 5:54 AM
Unknown Object (File)
Mon, Mar 9, 5:42 PM
Unknown Object (File)
Mon, Mar 9, 2:58 AM
Unknown Object (File)
Dec 31 2025, 11:59 PM
Subscribers

Details

Summary

We initialize sfio->npages only when some I/O is required to satisfy the
request. However, sendfile_iodone() contains an INVARIANTS-only check
that references sfio->npages, and this check is executed even if no I/O
is performed, so the check may use an uninitialized value.

Fix the problem by initializing sfio->npages earlier. Note that
sendfile_swapin() always initializes the page array. In some rare cases
we need to trim the page array so ensure that sfio->npages gets updated
accordingly.

Test Plan

syzkaller triggered the bug and KASAN detected it because the uninitialized
value caused the loop in sendfile_iodone() to run past the end of the buffer.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 35622
Build 32518: arc lint + arc unit