fs: Fix directory corruption when moving directories
Status from this message: Applied to the vfs.rename.locking branch of the vfs/vfs.git tree.
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest6 patches 12 repliesApplied 4/6
- v16 patches 7 repliesSuperseded
Changes in v2 from the cover letter
* Made sure lock_two_inodes() uses subclass1 for the obtained lock in case there is only one inode locked
* Fixes unlocked_two_nondirectories() to properly unlock inodes even if directories are accidentally passed in.
Patches in v2 Applied · 4/6
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/6 | ext4: Remove ext4 locking of moved directoryfs/ | +2 | 3 replies | Applied |
| 2/6 | Revert "udf: Protect rename against modification of moved directory"fs/ | +2 | 0 replies | Applied |
| 3/6 | Revert "f2fs: fix potential corruption when moving a directory"fs/ | +1 | 0 replies | Applied |
| 4/6 | fs: Establish locking order for unrelated directoriesfs/ fs/ fs/ | +46 | 8 replies | |
| 5/6 | fs: Lock moved directoriesDocumentation/ fs/ | +28 | 0 replies | Applied |
| 6/6 | fs: Restrict lock_two_nondirectories() to non-directory inodesfs/ | +8 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.
Cover letter [PATCH v2 0/6] fs: Fix directory corruption when moving directories
Hello,
this patch set fixes a problem with cross directory renames originally reported in [1]. To quickly sum it up some filesystems (so far we know at least about ext4, udf, f2fs, ocfs2, likely also reiserfs, gfs2 and others) need to lock the directory when it is being renamed into another directory. This is because we need to update the parent pointer in the directory in that case and if that races with other operation on the directory (in particular a conversion from one directory format into another), bad things can happen.
So far we've done the locking in the filesystem code but recently Darrick pointed out [2] that we've missed the RENAME_EXCHANGE case in our ext4 fix. That one is particularly nasty because RENAME_EXCHANGE can arbitrarily mix regular files and directories and proper lock ordering is not achievable in the filesystems alone.
This patch set adds locking into vfs_rename() so that not only parent directories but also moved inodes (regardless whether they are directories or not) are locked when calling into the filesystem.
Changes since v1:
* Made sure lock_two_inodes() uses subclass1 for the obtained lock in case there is only one inode locked
* Fixes unlocked_two_nondirectories() to properly unlock inodes even if directories are accidentally passed in.
Honza
[1] https://lore.kernel.org/all/20230117123735.un7wbamlbdihninm@quack3
[2] https://lore.kernel.org/all/20230517045836.GA11594@frogsfrogsfrogs
Previous versions: