freebsd-dev/sys
Rick Macklem 2be417843a PR#259071 provides a test program that fails for the NFS client.
Testing with it, there appears to be a race between Lookup
and VOPs like Setattr-of-size, where Lookup ends up loading
stale attributes (including what might be the wrong file size)
into the NFS vnode's attribute cache.

The race occurs when the modifying VOP (which holds a lock
on the vnode), blocks the acquisition of the vnode in Lookup,
after the RPC (with now potentially stale attributes).

Here's what seems to happen:
Child                                Parent

does stat(), which does
VOP_LOOKUP(), doing the Lookup
RPC with the directory vnode
locked, acquiring file attributes
valid at this point in time

blocks waiting for locked file       does ftruncate(), which
vnode                                does VOP_SETATTR() of Size,
                                     changing the file's size
                                     while holding an exclusive
                                     lock on the file's vnode
                                     releases the vnode lock
acquires file vnode and fills in
now stale attributes including
the old wrong Size
                                     does a read() which returns
                                     wrong data size

This patch fixes the problem by saving a timestamp in the NFS vnode
in the VOPs that modify the file (Setattr-of-size, Allocate).
Then lookup/readdirplus compares that timestamp with the time just
before starting the RPC after it has acquired the file's vnode.
If the modifying RPC occurred during the Lookup, the attributes
in the RPC reply are discarded, since they might be stale.

With this patch the test program works as expected.

Note that the test program does not fail on a July stable/12,
although this race is in the NFS client code.  I suspect a
fairly recent change to the name caching code exposed this
bug.

PR:	259071
Reviewed by:	asomers
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D32635
2021-10-30 16:35:02 -07:00
..
amd64 linux: make PTRACE_SETREGS use a correct struct 2021-10-30 10:13:37 +01:00
arm arm: Remove obsolete comments 2021-10-27 09:44:58 -06:00
arm64 NXP: Add ls1028a SPI clock driver 2021-10-29 09:52:20 +02:00
bsm Add fspacectl(2), vn_deallocate(9) and VOP_DEALLOCATE(9). 2021-08-05 23:20:42 +08:00
cam ada: Fix intra-object buffer overread of identify strings 2021-10-27 18:38:37 +01:00
cddl Allow ddb and dtrace use the DMAP region on arm64 2021-10-01 11:27:33 +01:00
compat linux: Also translate the signal if the code is CLD_KILLED 2021-10-29 15:28:00 +01:00
conf Remove enetc_mdio driver 2021-10-29 10:08:26 +02:00
contrib Merge commit 'ce929fe84f9c453263af379f3b255ff8eca01d48' 2021-10-29 19:18:03 +02:00
crypto crypto: Support Chacha20-Poly1305 with a nonce size of 8 bytes. 2021-10-06 14:08:49 -07:00
ddb Create sys/reg.h for the common code previously in machine/reg.h 2021-08-30 12:50:53 +01:00
dev Revert "qoriq_gpio: Implement interrupt controller functionality" 2021-10-29 12:05:55 +02:00
dts ipq4018: add a device tree file for the ASUS rt-ac58u router 2021-10-18 19:18:46 +00:00
fs PR#259071 provides a test program that fails for the NFS client. 2021-10-30 16:35:02 -07:00
gdb
geom Fix off-by-one error in msdosfs FAT32 volume label copying 2021-10-28 01:01:00 +01:00
gnu
i386 Retire synchronous PPP kernel driver sppp(4). 2021-10-22 11:41:36 -07:00
isa
kern linux: Add additional ptracestop only if the debugger is Linux 2021-10-30 09:54:17 +01:00
kgssapi
libkern libkern: remove bcopy 2021-08-24 11:24:07 +00:00
mips Convert vm_page_alloc() callers to use vm_page_alloc_noobj(). 2021-10-19 21:22:56 -04:00
modules Remove enetc_mdio driver 2021-10-29 10:08:26 +02:00
net if_epair: delete mbuf tags 2021-10-28 10:41:16 +02:00
net80211 net80211: correct input_sta length checks and control frame handling 2021-10-22 10:42:06 +00:00
netgraph Retire synchronous PPP kernel driver sppp(4). 2021-10-22 11:41:36 -07:00
netinet tcp: Rack might retransmit forever. 2021-10-29 17:37:49 -04:00
netinet6 net: Allow binding of unspecified address without address existance 2021-10-20 19:25:51 -04:00
netipsec ipsec: fix typo part2 2021-09-27 07:46:56 +02:00
netpfil pf: fix dummynet + NAT 2021-10-28 10:41:17 +02:00
netsmb
nfs
nfsclient
nfsserver
nlm
ofed socket: De-duplicate SBLOCKWAIT() definitions 2021-09-14 09:01:32 -04:00
opencrypto ktls: Fix assertion for TLS 1.0 CBC when using non-zero starting seqno. 2021-10-27 16:35:56 -07:00
powerpc Use the vm_radix_init() helper when initializing pmaps 2021-10-19 21:22:56 -04:00
riscv Convert consumers to vm_page_alloc_noobj_contig() 2021-10-19 21:22:56 -04:00
rpc rpc: Convert an SOLISTENING check to an assertion 2021-09-17 14:19:05 -04:00
security Add fspacectl(2), vn_deallocate(9) and VOP_DEALLOCATE(9). 2021-08-05 23:20:42 +08:00
sys Unmap shared page manually before doing vm_map_remove() on exit or exec 2021-10-28 22:01:59 +03:00
teken
tests routing: add IPv6 fib validation procedure. 2021-08-16 23:04:01 +00:00
tools ipq4018: add TCSR definitions from Linux. 2021-10-18 19:18:01 +00:00
ufs ufs: remove write-only variables 2021-10-21 21:40:46 +03:00
vm sysctl vm.objects: yield if hog 2021-10-25 20:34:02 +03:00
x86 dmar: Disable protected memory regions after initialization 2021-10-29 10:08:25 +02:00
xdr
xen
Makefile