Page MenuHomeFreeBSD

sendfile: Ensure that sfio->npages is initialized
ClosedPublic

Authored by markj on Dec 22 2020, 5:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Feb 22, 2:36 PM
Unknown Object (File)
Fri, Feb 14, 2:39 PM
Unknown Object (File)
Fri, Feb 7, 12:47 AM
Unknown Object (File)
Jan 30 2025, 1:17 PM
Unknown Object (File)
Jan 18 2025, 5:55 PM
Unknown Object (File)
Dec 20 2024, 10:34 AM
Unknown Object (File)
Nov 23 2024, 3:05 PM
Unknown Object (File)
Nov 23 2024, 12:05 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
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable