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
F174488138: D55845.diff
Sat, Oct 3, 3:40 PM
F174484022: D55845.id.diff
Sat, Oct 3, 2:44 PM
Unknown Object (File)
Sun, Sep 27, 6:52 PM
Unknown Object (File)
Sun, Sep 27, 1:55 PM
Unknown Object (File)
Sat, Sep 26, 5:16 AM
Unknown Object (File)
Thu, Sep 24, 12:12 PM
Unknown Object (File)
Wed, Sep 16, 4:28 AM
Unknown Object (File)
Wed, Sep 16, 4:23 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.