From 565528e8c7f3f895e29544f581a858689ff82e5b Mon Sep 17 00:00:00 2001 From: Paul Lawrence Date: Wed, 3 Feb 2021 10:33:05 -0800 Subject: [PATCH] ANDROID: Incremental fs: Set credentials before reading/writing Use same selinux scheme as incfs v2 Fix memory leak Bug: 174692664 Test: incfs_test passes Change-Id: I9a07c02a6f2caf93f88efaa3ce14fff34929804b Signed-off-by: Paul Lawrence Mot-CRs-fixed: (CR) Reviewed-on: https://gerrit.mot.com/1975978 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: gaoyx9 Submit-Approved: gaoyx9 Tested-by: gaoyx9 Reviewed-by: Huosheng Liao --- fs/incfs/data_mgmt.c | 1 + fs/incfs/vfs.c | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/incfs/data_mgmt.c b/fs/incfs/data_mgmt.c index db0b18dcec1b..e0705be44fb2 100644 --- a/fs/incfs/data_mgmt.c +++ b/fs/incfs/data_mgmt.c @@ -199,6 +199,7 @@ void incfs_free_data_file(struct data_file *df) for (i = 0; i < ARRAY_SIZE(df->df_segments); i++) data_file_segment_destroy(&df->df_segments[i]); incfs_free_bfc(df->df_backing_file_context); + kfree(df->df_signature); kfree(df); } diff --git a/fs/incfs/vfs.c b/fs/incfs/vfs.c index ad25bd5ca115..721fab54126d 100644 --- a/fs/incfs/vfs.c +++ b/fs/incfs/vfs.c @@ -903,7 +903,7 @@ static int init_new_file(struct mount_info *mi, struct dentry *dentry, .dentry = dentry }; new_file = dentry_open(&path, O_RDWR | O_NOATIME | O_LARGEFILE, - mi->mi_owner); + current_cred()); if (IS_ERR(new_file)) { error = PTR_ERR(new_file); @@ -1031,7 +1031,7 @@ static int dir_relative_path_resolve( if (dir_fd < 0) return dir_fd; - dir_f = dentry_open(base_path, O_RDONLY | O_NOATIME, mi->mi_owner); + dir_f = dentry_open(base_path, O_RDONLY | O_NOATIME, current_cred()); if (IS_ERR(dir_f)) { error = PTR_ERR(dir_f); @@ -1909,10 +1909,13 @@ static int file_open(struct inode *inode, struct file *file) struct file *backing_file = NULL; struct path backing_path = {}; int err = 0; + const struct cred *old_cred; get_incfs_backing_path(file->f_path.dentry, &backing_path); - backing_file = dentry_open( - &backing_path, O_RDWR | O_NOATIME | O_LARGEFILE, mi->mi_owner); + old_cred = override_creds(mi->mi_owner); + backing_file = dentry_open(&backing_path, + O_RDWR | O_NOATIME | O_LARGEFILE, current_cred()); + revert_creds(old_cred); path_put(&backing_path); if (IS_ERR(backing_file)) {