Skip to contentSkip to conversation

namei: free new_dentry late

PATCH Superseded Pan Bian 2 participants 3 messages Nov 24, 2018 – Nov 25, 2018 VFS

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Pan Bian

author
#0 lore raw

PATCH 1/1 namei: free new_dentry late

After calling dput(new_dentry), new_dentry is passed to fsnotify_move. This may result in a use-after-free bug. This patch moves the put operation late.

Fixes 49d31c2f389a("dentry name snapshots")
---
 fs/namei.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namei.c +1 -1
index 0cab649..8b104d9 100644
@@ -4498,7 +4498,6 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 		unlock_two_nondirectories(source, target);
 	else if (target)
 		inode_unlock(target);
-	dput(new_dentry);
 	if (!error) {
 		fsnotify_move(old_dir, new_dir, old_name.name, is_dir,
 			      !(flags & RENAME_EXCHANGE) ? target : NULL, old_dentry);
@@ -4507,6 +4506,7 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 				      new_is_dir, NULL, new_dentry);
 		}
 	}
+	dput(new_dentry);
 	release_dentry_name_snapshot(&old_name);
 
 	return error;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 5 lines · Pan Bian

After calling dput(new_dentry), new_dentry is passed to fsnotify_move. This may result in a use-after-free bug. This patch moves the put operation late.

Fixes 49d31c2f389a("dentry name snapshots")

What does that commit have to do with anything? The broken part is

                        fsnotify_move(new_dir, old_dir, old_dentry->d_name.name,
                                      new_is_dir, NULL, new_dentry);

and it predates that commit by 3 years - it came from da1ce0670c14 ("vfs: add cross-rename")...

author
#2 lore raw
Quoted 5 lines · Al Viro
Quoted 4 lines · Pan Bian

After calling dput(new_dentry), new_dentry is passed to fsnotify_move. This may result in a use-after-free bug. This patch moves the put operation late.

Quoted 7 lines
Quoted 1 line
Fixes 49d31c2f389a("dentry name snapshots")

What does that commit have to do with anything? The broken part is

                        fsnotify_move(new_dir, old_dir, old_dentry->d_name.name,
                                      new_is_dir, NULL, new_dentry);

and it predates that commit by 3 years - it came from da1ce0670c14 ("vfs: add cross-rename")...

Thank you for pointing out my mistake! I will correct it and resubmit the patch!

Best regards,
Pan