]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r356359-r356360: kern_mmap: add fpcheck invariant for linux_mmap
authorKyle Evans <kevans@FreeBSD.org>
Sat, 11 Jan 2020 15:06:06 +0000 (15:06 +0000)
committerKyle Evans <kevans@FreeBSD.org>
Sat, 11 Jan 2020 15:06:06 +0000 (15:06 +0000)
commit8d0947f245c0de16a21763c1634acbb8c8b10a3e
tree36053ea22449c1dba12ff5359728059489f369fd
parentf238b5be5f315835e6714cb68860f586d5b26b88
MFC r356359-r356360: kern_mmap: add fpcheck invariant for linux_mmap

r356359:
kern_mmap: add a variant that allows caller to inspect fp

Linux mmap rejects mmap() on a write-only file with EACCES.
linux_mmap_common currently does a fun dance to grab the fp associated with
the passed in fd, validates it, then drops the reference and calls into
kern_mmap(). Doing so is perhaps both fragile and premature; there's still
plenty of chance for the request to get rejected with a more appropriate
error, and it's prone to a race where the file we ultimately mmap has
changed after it drops its referenced.

This change alleviates the need to do this by providing a kern_mmap variant
that allows the caller to inspect the fp just before calling into the fileop
layer. The callback takes flags, prot, and maxprot as one could imagine
scenarios where any of these, in conjunction with the file itself, may
influence a caller's decision.

The file type check in the linux compat layer has been removed; EINVAL is
seemingly not an appropriate response to the file not being a vnode or
device. The fileop layer will reject the operation with ENODEV if it's not
supported, which more closely matches the common linux description of
mmap(2) return values.

If we discover that we're allowing an mmap() on a file type that Linux
normally wouldn't, we should restrict those explicitly.

r356360:
kern_mmap: restore character deleted in transit
sys/compat/linux/linux_mmap.c
sys/sys/syscallsubr.h
sys/vm/vm_mmap.c