Page MenuHomeFreeBSD

LinuxKPI: Better handling of zero-size and off-the-end reads
ClosedPublic

Authored by jhb on Mar 13 2026, 1:44 PM.
Tags
None
Referenced Files
F156008368: D55845.diff
Sun, May 10, 5:30 AM
F156006856: D55845.diff
Sun, May 10, 5:22 AM
Unknown Object (File)
Sat, May 9, 5:15 PM
Unknown Object (File)
Sat, May 9, 5:10 PM
Unknown Object (File)
Wed, May 6, 8:17 PM
Unknown Object (File)
Wed, Apr 29, 4:50 PM
Unknown Object (File)
Sun, Apr 26, 3:18 AM
Unknown Object (File)
Sat, Apr 25, 2:39 AM
Subscribers

Details

Summary

I noticed that the buf_size < 0 check can never be true (it's a
size_t) and decided to check for this condition by an alternate
expression, and I also noticed that a read_size of 0 would incorrectly
return -EFAULT. Instead, return success for both of these cases as
reading beyond the EOF of a normal file also returns EOF, not EINVAL.

Sponsored by: AFRL, DARPA

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Mar 13 2026, 1:44 PM
This revision is now accepted and ready to land.Mar 13 2026, 2:11 PM

I probably could rearrange this to merge it before the change to switch to user pointers.

Though the EFAULT error is only after reverting the memcpy back to copy_from_user.