Page MenuHomeFreeBSD

posixshm: Fix range locking in shm_write()
ClosedPublic

Authored by markj on Apr 5 2025, 4:38 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Nov 28, 9:31 PM
Unknown Object (File)
Thu, Nov 27, 11:53 AM
Unknown Object (File)
Fri, Nov 21, 1:59 PM
Unknown Object (File)
Wed, Nov 19, 1:32 PM
Unknown Object (File)
Tue, Nov 4, 6:42 AM
Unknown Object (File)
Mon, Nov 3, 7:36 PM
Unknown Object (File)
Mon, Nov 3, 7:35 PM
Unknown Object (File)
Mon, Nov 3, 7:35 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.Apr 5 2025, 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.Apr 5 2025, 9:27 PM
This revision was automatically updated to reflect the committed changes.