Skip to content

Commit c5b28fc

Browse files
vcgomesamir73il
authored andcommitted
ovl: Optimize override/revert creds
Use override_creds_light() in ovl_override_creds() and revert_creds_light() in ovl_revert_creds(). The _light() functions do not change the 'usage' of the credentials in question, as they refer to the credentials associated with the mounter, which have a longer lifetime. In ovl_setup_cred_for_create(), do not need to modify the mounter credentials (returned by override_creds_light()) 'usage' counter. Add a warning to verify that we are indeed working with the mounter credentials (stored in the superblock). Failure in this assumption means that creds may leak. Suggested-by: Christian Brauner <[email protected]> Signed-off-by: Vinicius Costa Gomes <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent 711747e commit c5b28fc

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

fs/overlayfs/dir.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,15 @@ static const struct cred *ovl_setup_cred_for_create(struct dentry *dentry,
573573
put_cred(override_cred);
574574
return ERR_PTR(err);
575575
}
576-
put_cred(override_creds(override_cred));
576+
577+
/*
578+
* Caller is going to match this with revert_creds_light() and drop
579+
* referenec on the returned creds.
580+
* We must be called with creator creds already, otherwise we risk
581+
* leaking creds.
582+
*/
583+
old_cred = override_creds_light(override_cred);
584+
WARN_ON_ONCE(old_cred != ovl_creds(dentry->d_sb));
577585

578586
return override_cred;
579587
}

fs/overlayfs/util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ const struct cred *ovl_override_creds(struct super_block *sb)
6565
{
6666
struct ovl_fs *ofs = OVL_FS(sb);
6767

68-
return override_creds(ofs->creator_cred);
68+
return override_creds_light(ofs->creator_cred);
6969
}
7070

7171
void ovl_revert_creds(const struct cred *old_cred)
7272
{
73-
revert_creds(old_cred);
73+
revert_creds_light(old_cred);
7474
}
7575

7676
/*

0 commit comments

Comments
 (0)