Skip to content

Commit db7cfe8

Browse files
committed
ovl: port ovl_lower_positive() to cred guard
Use the scoped ovl cred guard. Link: https://patch.msgid.link/20251117-work-ovl-cred-guard-v4-39-b31603935724@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 6b6ef7d commit db7cfe8

1 file changed

Lines changed: 35 additions & 37 deletions

File tree

fs/overlayfs/namei.c

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,6 @@ bool ovl_lower_positive(struct dentry *dentry)
14181418
{
14191419
struct ovl_entry *poe = OVL_E(dentry->d_parent);
14201420
const struct qstr *name = &dentry->d_name;
1421-
const struct cred *old_cred;
14221421
unsigned int i;
14231422
bool positive = false;
14241423
bool done = false;
@@ -1434,46 +1433,45 @@ bool ovl_lower_positive(struct dentry *dentry)
14341433
if (!ovl_dentry_upper(dentry))
14351434
return true;
14361435

1437-
old_cred = ovl_override_creds(dentry->d_sb);
1438-
/* Positive upper -> have to look up lower to see whether it exists */
1439-
for (i = 0; !done && !positive && i < ovl_numlower(poe); i++) {
1440-
struct dentry *this;
1441-
struct ovl_path *parentpath = &ovl_lowerstack(poe)[i];
1436+
with_ovl_creds(dentry->d_sb) {
1437+
/* Positive upper -> have to look up lower to see whether it exists */
1438+
for (i = 0; !done && !positive && i < ovl_numlower(poe); i++) {
1439+
struct dentry *this;
1440+
struct ovl_path *parentpath = &ovl_lowerstack(poe)[i];
14421441

1443-
/*
1444-
* We need to make a non-const copy of dentry->d_name,
1445-
* because lookup_one_positive_unlocked() will hash name
1446-
* with parentpath base, which is on another (lower fs).
1447-
*/
1448-
this = lookup_one_positive_unlocked(
1449-
mnt_idmap(parentpath->layer->mnt),
1450-
&QSTR_LEN(name->name, name->len),
1451-
parentpath->dentry);
1452-
if (IS_ERR(this)) {
1453-
switch (PTR_ERR(this)) {
1454-
case -ENOENT:
1455-
case -ENAMETOOLONG:
1456-
break;
1457-
1458-
default:
1459-
/*
1460-
* Assume something is there, we just couldn't
1461-
* access it.
1462-
*/
1463-
positive = true;
1464-
break;
1442+
/*
1443+
* We need to make a non-const copy of dentry->d_name,
1444+
* because lookup_one_positive_unlocked() will hash name
1445+
* with parentpath base, which is on another (lower fs).
1446+
*/
1447+
this = lookup_one_positive_unlocked(mnt_idmap(parentpath->layer->mnt),
1448+
&QSTR_LEN(name->name, name->len),
1449+
parentpath->dentry);
1450+
if (IS_ERR(this)) {
1451+
switch (PTR_ERR(this)) {
1452+
case -ENOENT:
1453+
case -ENAMETOOLONG:
1454+
break;
1455+
1456+
default:
1457+
/*
1458+
* Assume something is there, we just couldn't
1459+
* access it.
1460+
*/
1461+
positive = true;
1462+
break;
1463+
}
1464+
} else {
1465+
struct path path = {
1466+
.dentry = this,
1467+
.mnt = parentpath->layer->mnt,
1468+
};
1469+
positive = !ovl_path_is_whiteout(OVL_FS(dentry->d_sb), &path);
1470+
done = true;
1471+
dput(this);
14651472
}
1466-
} else {
1467-
struct path path = {
1468-
.dentry = this,
1469-
.mnt = parentpath->layer->mnt,
1470-
};
1471-
positive = !ovl_path_is_whiteout(OVL_FS(dentry->d_sb), &path);
1472-
done = true;
1473-
dput(this);
14741473
}
14751474
}
1476-
ovl_revert_creds(old_cred);
14771475

14781476
return positive;
14791477
}

0 commit comments

Comments
 (0)