Skip to content

Commit eab2a11

Browse files
author
Al Viro
committed
gfs2_drevalidate(): use stable parent inode and name passed by caller
No need to mess with dget_parent() for the former; for the latter we really should not rely upon ->d_name.name remaining stable. Theoretically a UAF, but it's hard to exfiltrate the information... Reviewed-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 19e1dbd commit eab2a11

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

fs/gfs2/dentry.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,48 +35,40 @@
3535
static int gfs2_drevalidate(struct inode *dir, const struct qstr *name,
3636
struct dentry *dentry, unsigned int flags)
3737
{
38-
struct dentry *parent;
39-
struct gfs2_sbd *sdp;
40-
struct gfs2_inode *dip;
38+
struct gfs2_sbd *sdp = GFS2_SB(dir);
39+
struct gfs2_inode *dip = GFS2_I(dir);
4140
struct inode *inode;
4241
struct gfs2_holder d_gh;
4342
struct gfs2_inode *ip = NULL;
44-
int error, valid = 0;
43+
int error, valid;
4544
int had_lock = 0;
4645

4746
if (flags & LOOKUP_RCU)
4847
return -ECHILD;
4948

50-
parent = dget_parent(dentry);
51-
sdp = GFS2_SB(d_inode(parent));
52-
dip = GFS2_I(d_inode(parent));
5349
inode = d_inode(dentry);
5450

5551
if (inode) {
5652
if (is_bad_inode(inode))
57-
goto out;
53+
return 0;
5854
ip = GFS2_I(inode);
5955
}
6056

61-
if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) {
62-
valid = 1;
63-
goto out;
64-
}
57+
if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
58+
return 1;
6559

6660
had_lock = (gfs2_glock_is_locked_by_me(dip->i_gl) != NULL);
6761
if (!had_lock) {
6862
error = gfs2_glock_nq_init(dip->i_gl, LM_ST_SHARED, 0, &d_gh);
6963
if (error)
70-
goto out;
64+
return 0;
7165
}
7266

73-
error = gfs2_dir_check(d_inode(parent), &dentry->d_name, ip);
67+
error = gfs2_dir_check(dir, name, ip);
7468
valid = inode ? !error : (error == -ENOENT);
7569

7670
if (!had_lock)
7771
gfs2_glock_dq_uninit(&d_gh);
78-
out:
79-
dput(parent);
8072
return valid;
8173
}
8274

0 commit comments

Comments
 (0)