ovl: fix UAF in ovl_do_mkdir() debug print
Subsystems (2)
Amir Goldstein
maintainerPATCH 1/1 ovl: fix UAF in ovl_do_mkdir() debug print
ovl_do_mkdir() prints the input dentry with %pd after vfs_mkdir(). Since commit fe497f0759e0 ("VFS: change vfs_mkdir() to unlock on failure."), vfs_mkdir() calls end_creating() on the input dentry on failure and may replace it on success, so the post-call %pd can use-after-free the dentry when CONFIG_OVERLAY_FS_DEBUG is enabled.
Print the dentry before the call and only the result afterward.
---
Christian,
One more fallout from directory locking prep series reported by syzbot. I have asked LLM to audit the kernel for other similar uses of %pd post end_creating() and it did not find any.
Could you take this via vfs.fixes?
Thanks,
Amir.
fs/overlayfs/overlayfs.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/overlayfs/overlayfs.h +3 -1
@@ -254,8 +254,10 @@ static inline struct dentry *ovl_do_mkdir(struct ovl_fs *ofs, {struct dentry *ret; +/* vfs_mkdir() drops @dentry on failure and may replace it on success */ +pr_debug ("mkdir(%pd2, 0%o)\n" , dentry, mode); ret =vfs_mkdir (ovl_upper_mnt_idmap (ofs), dir, dentry, mode,NULL ); -pr_debug ("mkdir(%pd2, 0%o) = %i\n" , dentry, mode,PTR_ERR_OR_ZERO (ret)); +pr_debug ("...mkdir = %i\n" ,PTR_ERR_OR_ZERO (ret));return ret; }
Signature · 1 line
2.55.0
Quoted 9 lines · Amir Goldstein
ovl_do_mkdir()prints the input dentry with %pd aftervfs_mkdir(). Since commitfe497f0759e0("VFS: changevfs_mkdir()to unlock on failure."),vfs_mkdir()callsend_creating()on the input dentry on failure and may replace it on success, so the post-call %pd can use-after-free the dentry whenCONFIG_OVERLAY_FS_DEBUGis enabled.Print the dentry before the call and only the result afterward.
[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] ovl: fix UAF in ovl_do_mkdir() debug print
https://git.kernel.org/vfs/vfs/c/ae146bc1abde