Page MenuHomeFreeBSD

vop_stdadvise(): restore correct handling of length == 0
ClosedPublic

Authored by kib on Tue, Sep 3, 4:27 AM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Sep 13, 11:39 AM
Unknown Object (File)
Thu, Sep 12, 8:12 PM
Unknown Object (File)
Thu, Sep 12, 2:30 AM
Unknown Object (File)
Wed, Sep 11, 11:16 PM
Unknown Object (File)
Wed, Sep 11, 3:53 AM
Unknown Object (File)
Mon, Sep 9, 7:31 PM
Unknown Object (File)
Sat, Sep 7, 4:06 PM
Unknown Object (File)
Wed, Sep 4, 5:34 AM
Subscribers

Details

Summary
Switch to unsigned arithmetic to handle overflow not relying on -fwrap,
and specially treat the case of length == 0 from posix_fadvise() which
passes OFF_MAX as the end to VOP.  There, roundup() overflows and -fwrap
causes bend and endn become negative.  Clamp them at OFF_MAX/bsize
instead.

Also remove locals with single use, and move calculations from under bo
lock.

Reported by:    tmunro

Diff Detail

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

Event Timeline

kib requested review of this revision.Tue, Sep 3, 4:27 AM
markj added inline comments.
sys/kern/vfs_default.c
1122
This revision is now accepted and ready to land.Tue, Sep 3, 12:53 PM
kib marked an inline comment as done.Tue, Sep 3, 9:34 PM
sys/kern/vfs_default.c
1119

I don't think we need this "Restore length" hunk. The round_page() call always just adds one to OFF_MAX (0x7fffffffffffffff -> 0x8000000000000000), so the change to uintmax_t is enough to make the existing endn = bend / bsize produce a correct positive answer.

kib marked an inline comment as done.

clamp is not needed

This revision now requires review to proceed.Wed, Sep 4, 7:35 AM
This revision is now accepted and ready to land.Wed, Sep 4, 11:00 PM