freebsd-dev/sys
Konstantin Belousov 8a1509e442 Handle LoR in flush_pagedep_deps().
When operating in SU or SU+J mode, ffs_syncvnode() might need to
instantiate other vnode by inode number while owning syncing vnode
lock.  Typically this other vnode is the parent of our vnode, but due
to renames occuring right before fsync (or during fsync when we drop
the syncing vnode lock, see below) it might be no longer parent.

More, the called function flush_pagedep_deps() needs to lock other
vnode while owning the lock for vnode which owns the buffer, for which
the dependencies are flushed.  This creates another instance of the
same LoR as was fixed in softdep_sync().

Put the generic code for safe relocking into new SU helper
get_parent_vp() and use it in flush_pagedep_deps().  The case for safe
relocking of two vnodes with undefined lock order was extracted into
vn helper vn_lock_pair().

Due to call sequence
     ffs_syncvnode()->softdep_sync_buf()->flush_pagedep_deps(),
ffs_syncvnode() indicates with ERELOOKUP that passed vnode was
unlocked in process, and can return ENOENT if the passed vnode
reclaimed.  All callers of the function were inspected.

Because UFS namei lookups store auxiliary information about directory
entry in in-memory directory inode, and this information is then used
by UFS code that creates/removed directory entry in the actual
mutating VOPs, it is critical that directory vnode lock is not dropped
between lookup and VOP.  For softdep_prelink(), which ensures that
later link/unlink operation can proceed without overflowing the
journal, calls were moved to the place where it is safe to drop
processing VOP because mutations are not yet applied.  Then, ERELOOKUP
causes restart of the whole VFS operation (typically VFS syscall) at
top level, including the re-lookup of the involved pathes.  [Note that
we already do the same restart for failing calls to vn_start_write(),
so formally this patch does not introduce new behavior.]

Similarly, unsafe calls to fsync in snapshot creation code were
plugged.  A possible view on these failures is that it does not make
sense to continue creating snapshot if the snapshot vnode was
reclaimed due to forced unmount.

It is possible that relock/ERELOOKUP situation occurs in
ffs_truncate() called from ufs_inactive().  In this case, dropping the
vnode lock is not safe.  Detect the situation with VI_DOINGINACT and
reschedule inactivation by setting VI_OWEINACT.  ufs_inactive()
rechecks VI_OWEINACT and avoids reclaiming vnode is truncation failed
this way.

In ffs_truncate(), allocation of the EOF block for partial truncation
is re-done after vnode is synced, since we cannot leave the buffer
locked through ffs_syncvnode().

In collaboration with:	pho
Reviewed by:	mckusick (previous version), markj
Tested by:	markj (syzkaller), pho
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D26136
2020-11-14 05:30:10 +00:00
..
amd64 vmm: Make pmap_invalidate_ept() wait synchronously for guest exits 2020-11-11 15:01:17 +00:00
arm Remove the 'nap' field from ARM's 'struct syscall_args', to bring it 2020-11-05 18:10:03 +00:00
arm64 arm64: bs_sr_<N> take II 2020-11-09 23:34:32 +00:00
bsm
cam Make CTL nicer to increased MAXPHYS. 2020-11-11 21:59:39 +00:00
cddl malloc: move malloc_type_internal into malloc_type 2020-11-06 21:33:59 +00:00
compat LinuxKPI: Implement ACPI bits required by drm-kmod in base system 2020-11-09 13:20:14 +00:00
conf Disable kernel INIT_ALL_ZERO on amd64 2020-11-13 18:34:13 +00:00
contrib MFV: r367652 2020-11-13 22:45:26 +00:00
crypto Check cipher key lengths during probesession. 2020-11-05 23:31:58 +00:00
ddb db_search_symbol: prevent pollution from bogus symbols 2020-10-26 16:42:53 +00:00
dev Add PMRCAP printing and fix earlier CAP_HI. 2020-11-14 01:45:34 +00:00
dts Brand our DTS with the Linux version it was imported from 2020-10-10 07:18:51 +00:00
fs Make it possible to mount a fuse filesystem, such as squashfuse, 2020-11-09 08:53:15 +00:00
gdb gdb(4): Don't escape GDB special characters at application layer 2020-09-30 14:55:54 +00:00
geom gbde: replace malloc_last_fail with a kludge 2020-11-12 20:20:57 +00:00
gnu Brand our DTS with the Linux version it was imported from 2020-10-10 07:18:51 +00:00
i386 linux(4): Deduplicate unimpl/dummy syscall handlers 2020-11-05 19:30:31 +00:00
isa
kern malloc: retire MALLOC_PROFILE 2020-11-13 19:22:53 +00:00
kgssapi State kgssapi dependency on xdr. 2020-09-17 22:29:38 +00:00
libkern arc4random(9): Integrate with RANDOM_FENESTRASX push-reseed 2020-10-10 21:48:06 +00:00
mips Remove 'struct trapframe' pointer from mips64's 'struct syscall_args'. 2020-11-06 19:19:51 +00:00
modules LinuxKPI: Implement ACPI bits required by drm-kmod in base system 2020-11-09 13:20:14 +00:00
net iflib: Free full mbuf chains when draining transmit queues 2020-11-11 18:00:06 +00:00
net80211 net80211: fix a typo 2020-11-04 12:07:33 +00:00
netgraph ng_nat: unbreak ABI 2020-11-10 02:26:44 +00:00
netinet ip_fastfwd: style(9) tidy for r367628 2020-11-13 18:25:07 +00:00
netinet6 Fix use-after-free in icmp6_notify_error(). 2020-10-28 20:22:20 +00:00
netipsec Trigger soft lifetime expiration on sequence number 2020-10-16 11:27:01 +00:00
netpfil Add dtrace SDT probe ipfw:::rule-matched. 2020-10-21 15:01:33 +00:00
netsmb net: clean up empty lines in .c and .h files 2020-09-01 21:19:14 +00:00
nfs nfs: clean up empty lines in .c and .h files 2020-09-01 21:25:39 +00:00
nfsclient nfs: clean up empty lines in .c and .h files 2020-09-01 21:25:39 +00:00
nfsserver nfs: clean up empty lines in .c and .h files 2020-09-01 21:25:39 +00:00
nlm nlm: clean up empty lines in .c and .h files 2020-09-01 22:14:52 +00:00
ofed Fix for referencing file via its vnode in ibore. 2020-11-02 10:44:29 +00:00
opencrypto Use void * in place of caddr_t. 2020-11-06 18:09:52 +00:00
powerpc [PowerPC64LE] Radix MMU fixes for LE. 2020-11-13 16:56:03 +00:00
riscv riscv: set kernel_pmap hart mask more precisely 2020-11-05 00:52:52 +00:00
rpc Fix a potential memory leak in the NFS over TLS handling code. 2020-09-05 00:50:52 +00:00
security mac_framework.h: fix build with DEBUG_VFS_LOCKS and !MAC 2020-09-03 20:30:52 +00:00
sys Implement vn_lock_pair(). 2020-11-13 09:31:57 +00:00
teken Do a sweep and remove most WARNS=6 settings 2020-10-01 01:10:51 +00:00
tests Add small tool to invoke kernel test framework tests. 2020-09-02 09:20:40 +00:00
tools Brand our DTS with the Linux version it was imported from 2020-10-10 07:18:51 +00:00
ufs Handle LoR in flush_pagedep_deps(). 2020-11-14 05:30:10 +00:00
vm vm_map: Handle kernel map entry allocator recursion 2020-11-11 17:16:39 +00:00
x86 linux(4): Deduplicate unimpl/dummy syscall handlers 2020-11-05 19:30:31 +00:00
xdr xdr: clean up empty lines in .c and .h files 2020-09-01 22:13:28 +00:00
xen xen: clean up empty lines in .c and .h files 2020-09-01 21:21:55 +00:00
Makefile