freebsd-skq/sys/fs/tmpfs
Konstantin Belousov 64c250439f Refcount tmpfs nodes and mount structures.
On dotdot lookup and fhtovp operations, it is possible for the file
represented by tmpfs node to be removed after the thread calculated
the pointer.  In this case, tmpfs_alloc_vp() accesses freed memory.

Introduce the reference count on the nodes.  The allnodes list from
tmpfs mount owns 1 reference, and threads performing unlocked
operations on the node, add one transient reference.  Similarly, since
struct tmpfs_mount maintains the list where nodes are enlisted,
refcount it by one reference from struct mount and one reference from
each node on the list.  Both nodes and tmpfs_mounts are removed when
refcount goes to zero.

Note that this means that nodes and tmpfs_mounts might survive some
time after the node is deleted or tmpfs_unmount() finished.  The
tmpfs_alloc_vp() in these cases returns error either due to node
removal (tn_nlinks == 0) or because of insmntque1(9) error.

Tested by:	pho (as part of larger patch)
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2017-01-19 19:15:21 +00:00
..
tmpfs_fifoops.c Lock tmpfs node tn_status updates done under the shared vnode lock. 2017-01-06 17:43:36 +00:00
tmpfs_fifoops.h Remove code separator lines which do not conform to style(9). 2014-07-14 08:17:11 +00:00
tmpfs_subr.c Refcount tmpfs nodes and mount structures. 2017-01-19 19:15:21 +00:00
tmpfs_vfsops.c Refcount tmpfs nodes and mount structures. 2017-01-19 19:15:21 +00:00
tmpfs_vnops.c Refcount tmpfs nodes and mount structures. 2017-01-19 19:15:21 +00:00
tmpfs_vnops.h Remove code separator lines which do not conform to style(9). 2014-07-14 08:17:11 +00:00
tmpfs.h Refcount tmpfs nodes and mount structures. 2017-01-19 19:15:21 +00:00