Page MenuHomeFreeBSD

posixshm: Fix range locking in shm_write()
ClosedPublic

Authored by markj on Sat, Apr 5, 4:38 PM.
Tags
None
Referenced Files
F114085293: D49673.diff
Mon, Apr 7, 7:21 PM
F114082019: D49673.id.diff
Mon, Apr 7, 6:32 PM
F114077355: D49673.id153177.diff
Mon, Apr 7, 5:09 PM
F114062760: D49673.diff
Mon, Apr 7, 12:25 PM
Subscribers

Details

Summary

There is a somewhat strange case where when writing to a POSIX shm
object, the object is not allowed to grow, and the I/O offset+length
overflows. In that case we simply truncate the I/O to the object size.
Later we write-lock the range [offset, objsize). However, we were not
checking whether offset > objsize, in which case we're writing zero
bytes but locking an invalid range.

Modify the range locking in shm_write() to take this possibility into
account. While here, rename a variable to make its purpose a bit more
clear, and add an assertion against negative offsets (which is supposed
to be enforced by the caller of fo_write for I/O to files that aren't
character devices).

Reported by: syzkaller

Diff Detail

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

Event Timeline

markj requested review of this revision.Sat, Apr 5, 4:38 PM

Reported by: syzkaller

In particular, this tripped an assertion I added locally to kern_rangelock.c which checks that the range passed in has start <= end.

This revision is now accepted and ready to land.Sat, Apr 5, 9:27 PM
This revision was automatically updated to reflect the committed changes.