ovl: narrow locking in ovl_whiteout()
authorNeilBrown <neil@brown.name>
Wed, 16 Jul 2025 00:44:29 +0000 (10:44 +1000)
committerChristian Brauner <brauner@kernel.org>
Fri, 18 Jul 2025 09:10:42 +0000 (11:10 +0200)
commit8afa0a736713898f04d52abad69c07caa2c2f227
tree68ed8d2a478e5ce3428d8aeb4f94b9ce28321f82
parent2fa14cf2dca1913054e0225377d0a9999483d34d
ovl: narrow locking in ovl_whiteout()

ovl_whiteout() relies on the workdir i_rwsem to provide exclusive access
to ofs->whiteout which it manipulates.  Rather than depending on this,
add a new mutex, "whiteout_lock" to explicitly provide the required
locking.  Use guard(mutex) for this so that we can return without
needing to explicitly unlock.

Then take the lock on workdir only when needed - to lookup the temp name
and to do the whiteout or link.

Signed-off-by: NeilBrown <neil@brown.name>
Link: https://lore.kernel.org/20250716004725.1206467-19-neil@brown.name
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/overlayfs/dir.c
fs/overlayfs/ovl_entry.h
fs/overlayfs/params.c