Skip to content

Commit 81b77b5

Browse files
committed
ovl: add copy up credential guard
Add a credential guard for copy up. This will allows us to waste struct struct ovl_cu_creds and simplify the code. Link: https://patch.msgid.link/20251114-work-ovl-cred-guard-copyup-v1-1-ea3fb15cf427@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent c0fb968 commit 81b77b5

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

fs/overlayfs/copy_up.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,33 @@ static void ovl_revert_cu_creds(struct ovl_cu_creds *cc)
752752
}
753753
}
754754

755+
static const struct cred *ovl_prepare_copy_up_creds(struct dentry *dentry)
756+
{
757+
struct cred *copy_up_cred = NULL;
758+
int err;
759+
760+
err = security_inode_copy_up(dentry, &copy_up_cred);
761+
if (err < 0)
762+
return ERR_PTR(err);
763+
764+
if (!copy_up_cred)
765+
return NULL;
766+
767+
return override_creds(copy_up_cred);
768+
}
769+
770+
static void ovl_revert_copy_up_creds(const struct cred *orig_cred)
771+
{
772+
const struct cred *copy_up_cred;
773+
774+
copy_up_cred = revert_creds(orig_cred);
775+
put_cred(copy_up_cred);
776+
}
777+
778+
DEFINE_CLASS(copy_up_creds, const struct cred *,
779+
if (!IS_ERR_OR_NULL(_T)) ovl_revert_copy_up_creds(_T),
780+
ovl_prepare_copy_up_creds(dentry), struct dentry *dentry)
781+
755782
/*
756783
* Copyup using workdir to prepare temp file. Used when copying up directories,
757784
* special files or when upper fs doesn't support O_TMPFILE.

0 commit comments

Comments
 (0)