Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: e566bff96322 ("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>

authored by

Christian Brauner and committed by
Linus Torvalds
87c9e88a 4b9d25b4

+12 -8
+12 -8
fs/overlayfs/dir.c
··· 581 581 goto out_dput; 582 582 } 583 583 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) 585 586 { 586 587 int err; 587 588 ··· 597 596 override_cred->fsgid = inode->i_gid; 598 597 599 598 err = security_dentry_create_files_as(dentry, mode, &dentry->d_name, 600 - current->cred, override_cred); 599 + original_creds, override_cred); 601 600 if (err) 602 601 return ERR_PTR(err); 603 602 ··· 615 614 DEFINE_CLASS(ovl_override_creator_creds, 616 615 const struct cred *, 617 616 if (!IS_ERR_OR_NULL(_T)) ovl_revert_creator_creds(_T), 618 - ovl_override_creator_creds(dentry, inode, mode), 619 - struct dentry *dentry, struct inode *inode, umode_t mode) 617 + ovl_override_creator_creds(original_creds, dentry, inode, mode), 618 + const struct cred *original_creds, 619 + struct dentry *dentry, 620 + struct inode *inode, 621 + umode_t mode) 620 622 621 623 static int ovl_create_handle_whiteouts(struct dentry *dentry, 622 624 struct inode *inode, ··· 637 633 int err; 638 634 struct dentry *parent = dentry->d_parent; 639 635 640 - with_ovl_creds(dentry->d_sb) { 636 + scoped_class(override_creds_ovl, original_creds, dentry->d_sb) { 641 637 /* 642 638 * When linking a file with copy up origin into a new parent, mark the 643 639 * new parent dir "impure". ··· 665 661 if (attr->hardlink) 666 662 return ovl_create_handle_whiteouts(dentry, inode, attr); 667 663 668 - scoped_class(ovl_override_creator_creds, cred, dentry, inode, attr->mode) { 664 + scoped_class(ovl_override_creator_creds, cred, original_creds, dentry, inode, attr->mode) { 669 665 if (IS_ERR(cred)) 670 666 return PTR_ERR(cred); 671 667 return ovl_create_handle_whiteouts(dentry, inode, attr); ··· 1368 1364 int flags = file->f_flags | OVL_OPEN_FLAGS; 1369 1365 int err; 1370 1366 1371 - with_ovl_creds(dentry->d_sb) { 1372 - scoped_class(ovl_override_creator_creds, cred, dentry, inode, mode) { 1367 + scoped_class(override_creds_ovl, original_creds, dentry->d_sb) { 1368 + scoped_class(ovl_override_creator_creds, cred, original_creds, dentry, inode, mode) { 1373 1369 if (IS_ERR(cred)) 1374 1370 return PTR_ERR(cred); 1375 1371