Skip to content

Commit 87c9e88

Browse files
braunertorvalds
authored andcommitted
ovl: pass original credentials, not mounter credentials during create
When creating new files the security layer expects the original credentials to be passed. When cleaning up the code this was accidently changed to pass the mounter's credentials by relying on current->cred which is already overriden at this point. Pass the original credentials directly. Reported-by: Ondrej Mosnacek <omosnace@redhat.com> Reported-by: Paul Moore <paul@paul-moore.com> Fixes: e566bff ("ovl: port ovl_create_or_link() to new ovl_override_creator_creds") Link: https://lore.kernel.org/CAFqZXNvL1ciLXMhHrnoyBmQu1PAApH41LkSWEhrcvzAAbFij8Q@mail.gmail.com Signed-off-by: Christian Brauner <brauner@kernel.org> Tested-by: Ondrej Mosnacek <omosnace@redhat.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 4b9d25b commit 87c9e88

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

fs/overlayfs/dir.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
581581
goto out_dput;
582582
}
583583

584-
static const struct cred *ovl_override_creator_creds(struct dentry *dentry, struct inode *inode, umode_t mode)
584+
static const struct cred *ovl_override_creator_creds(const struct cred *original_creds,
585+
struct dentry *dentry, struct inode *inode, umode_t mode)
585586
{
586587
int err;
587588

@@ -596,7 +597,7 @@ static const struct cred *ovl_override_creator_creds(struct dentry *dentry, stru
596597
override_cred->fsgid = inode->i_gid;
597598

598599
err = security_dentry_create_files_as(dentry, mode, &dentry->d_name,
599-
current->cred, override_cred);
600+
original_creds, override_cred);
600601
if (err)
601602
return ERR_PTR(err);
602603

@@ -614,8 +615,11 @@ static void ovl_revert_creator_creds(const struct cred *old_cred)
614615
DEFINE_CLASS(ovl_override_creator_creds,
615616
const struct cred *,
616617
if (!IS_ERR_OR_NULL(_T)) ovl_revert_creator_creds(_T),
617-
ovl_override_creator_creds(dentry, inode, mode),
618-
struct dentry *dentry, struct inode *inode, umode_t mode)
618+
ovl_override_creator_creds(original_creds, dentry, inode, mode),
619+
const struct cred *original_creds,
620+
struct dentry *dentry,
621+
struct inode *inode,
622+
umode_t mode)
619623

620624
static int ovl_create_handle_whiteouts(struct dentry *dentry,
621625
struct inode *inode,
@@ -633,7 +637,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
633637
int err;
634638
struct dentry *parent = dentry->d_parent;
635639

636-
with_ovl_creds(dentry->d_sb) {
640+
scoped_class(override_creds_ovl, original_creds, dentry->d_sb) {
637641
/*
638642
* When linking a file with copy up origin into a new parent, mark the
639643
* new parent dir "impure".
@@ -661,7 +665,7 @@ static int ovl_create_or_link(struct dentry *dentry, struct inode *inode,
661665
if (attr->hardlink)
662666
return ovl_create_handle_whiteouts(dentry, inode, attr);
663667

664-
scoped_class(ovl_override_creator_creds, cred, dentry, inode, attr->mode) {
668+
scoped_class(ovl_override_creator_creds, cred, original_creds, dentry, inode, attr->mode) {
665669
if (IS_ERR(cred))
666670
return PTR_ERR(cred);
667671
return ovl_create_handle_whiteouts(dentry, inode, attr);
@@ -1364,8 +1368,8 @@ static int ovl_create_tmpfile(struct file *file, struct dentry *dentry,
13641368
int flags = file->f_flags | OVL_OPEN_FLAGS;
13651369
int err;
13661370

1367-
with_ovl_creds(dentry->d_sb) {
1368-
scoped_class(ovl_override_creator_creds, cred, dentry, inode, mode) {
1371+
scoped_class(override_creds_ovl, original_creds, dentry->d_sb) {
1372+
scoped_class(ovl_override_creator_creds, cred, original_creds, dentry, inode, mode) {
13691373
if (IS_ERR(cred))
13701374
return PTR_ERR(cred);
13711375

0 commit comments

Comments
 (0)