]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
unionfs_rename: fix numerous locking issues
authorJason A. Harmening <jah@FreeBSD.org>
Sun, 18 Feb 2024 00:20:51 +0000 (18:20 -0600)
committerJason A. Harmening <jah@FreeBSD.org>
Mon, 29 Apr 2024 01:19:48 +0000 (20:19 -0500)
commit05e8ab627bc6fc6e607aea94b60fd264b8a6c736
tree5d463740b324ddf888debd43761cb9182c679e76
parent993d1fad5bd805dbd1820975e58839ff4276e7b0
unionfs_rename: fix numerous locking issues

There are a few places in which unionfs_rename() accesses fvp's private
data without holding the necessary lock/interlock.  Moreover, the
implementation completely fails to handle the case in which fdvp is not
the same as tdvp; in this case it simply fails to lock fdvp at all.
Finally, it locks fvp while potentially already holding tvp's lock, but
makes no attempt to deal with possible LOR there.

Fix this by optimistically using the vnode interlock to protect
the short accesses to fdvp and fvp private data, sequentially.
If a file copy or shadow directory creation is required to prepare
the upper FS for the rename operation, the interlock must be dropped
and fdvp/fvp locked as necessary.

Additionally, use ERELOOKUP (as suggested by kib@) to simplify the
locking logic and eliminate unionfs_relookup() calls for file-copy/
shadow-directory cases that require tdvp's lock to be dropped.

Reviewed by: kib (earlier version), olce
Tested by: pho
Differential Revision: https://reviews.freebsd.org/D44788
sys/fs/unionfs/union_vnops.c