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
Unknown Object (File)
Sun, Aug 23, 6:27 PM
Unknown Object (File)
Sat, Aug 22, 12:36 AM
Unknown Object (File)
Fri, Aug 21, 3:42 PM
Unknown Object (File)
Thu, Aug 20, 1:41 PM
Unknown Object (File)
Thu, Aug 20, 8:57 AM
Unknown Object (File)
Thu, Aug 20, 7:39 AM
Unknown Object (File)
Wed, Aug 19, 10:25 PM
Unknown Object (File)
Wed, Aug 19, 5:12 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.