FreeBSD/src de4e1ae (r351195)sys/fs/tmpfs tmpfs_vfsops.c, sys/kern vfs_default.c

Fix an issue with executing tmpfs binary.

Suppose that a binary was executed from tmpfs mount, and the text
vnode was reclaimed while the binary was still running.  It is
possible during even the normal operations since tmpfs vnode'
vm_object has swap type, and no references on the vnode is held.  Also
assume that the text vnode was revived for some reason.  Then, on the
process exit or exec, unmapping of the text mapping tries to remove
the text reference from the vnode, but since it went from
recycle/instantiation cycle, there is no reference kept, and assertion
in VOP_UNSET_TEXT_CHECKED() triggers.

Fix this by keeping a use reference on the tmpfs vnode for each exec
reference.  This prevents the vnode reclamation while executable map
entry is active.

Do it by adding per-mount flag MNTK_TEXT_REFS that directs
vop_stdset_text() to add use ref on first vnode text use, and
per-vnode VI_TEXT_REF flag, to record the need on unref in
vop_stdunset_text() on last vnode text use going away.  Set
MNTK_TEXT_REFS for tmpfs mounts.

Reported by:    bdrewery
Tested by:      sbruno, pho (previous version)
Sponsored by:   The FreeBSD Foundation
MFC after:      1 week
DeltaFile
+21-0sys/kern/vfs_default.c
+2-1sys/fs/tmpfs/tmpfs_vfsops.c
+1-0sys/sys/mount.h
+1-0sys/sys/vnode.h
+25-14 files

UnifiedSplitRaw