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)
Mon, Sep 15, 2:24 PM
Unknown Object (File)
Sun, Sep 14, 7:09 PM
Unknown Object (File)
Aug 16 2025, 5:27 PM
Unknown Object (File)
Aug 13 2025, 1:08 AM
Unknown Object (File)
Aug 12 2025, 5:40 PM
Unknown Object (File)
Aug 3 2025, 9:58 AM
Unknown Object (File)
Jul 15 2025, 6:56 PM
Unknown Object (File)
Jul 10 2025, 3:12 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.