Skip to content

Commit 6404674

Browse files
Al Virotorvalds
authored andcommitted
vfs: fix do_last() regression
Brown paperbag time: fetching ->i_uid/->i_mode really should've been done from nd->inode. I even suggested that, but the reason for that has slipped through the cracks and I went for dir->d_inode instead - made for more "obvious" patch. Analysis: - at the entry into do_last() and all the way to step_into(): dir (aka nd->path.dentry) is known not to have been freed; so's nd->inode and it's equal to dir->d_inode unless we are already doomed to -ECHILD. inode of the file to get opened is not known. - after step_into(): inode of the file to get opened is known; dir might be pointing to freed memory/be negative/etc. - at the call of may_create_in_sticky(): guaranteed to be out of RCU mode; inode of the file to get opened is known and pinned; dir might be garbage. The last was the reason for the original patch. Except that at the do_last() entry we can be in RCU mode and it is possible that nd->path.dentry->d_inode has already changed under us. In that case we are going to fail with -ECHILD, but we need to be careful; nd->inode is pointing to valid struct inode and it's the same as nd->path.dentry->d_inode in "won't fail with -ECHILD" case, so we should use that. Reported-by: "Rantala, Tommi T. (Nokia - FI/Espoo)" <[email protected]> Reported-by: [email protected] Wearing-brown-paperbag: Al Viro <[email protected]> Cc: [email protected] Fixes: d0cb501 ("do_last(): fetch directory ->i_mode and ->i_uid before it's too late") Signed-off-by: Al Viro <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 14cd0bd commit 6404674

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/namei.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,8 +3333,8 @@ static int do_last(struct nameidata *nd,
33333333
struct file *file, const struct open_flags *op)
33343334
{
33353335
struct dentry *dir = nd->path.dentry;
3336-
kuid_t dir_uid = dir->d_inode->i_uid;
3337-
umode_t dir_mode = dir->d_inode->i_mode;
3336+
kuid_t dir_uid = nd->inode->i_uid;
3337+
umode_t dir_mode = nd->inode->i_mode;
33383338
int open_flag = op->open_flag;
33393339
bool will_truncate = (open_flag & O_TRUNC) != 0;
33403340
bool got_write = false;

0 commit comments

Comments
 (0)