summaryrefslogtreecommitdiff
path: root/security
diff options
context:
space:
mode:
authornixiaoming <nixiaoming@huawei.com>2018-08-05 12:10:36 +0300
committerPaul Moore <paul@paul-moore.com>2018-08-08 00:26:25 +0300
commit7e4237faa7213c1cc1d0aa65a44c67ba4729ce9f (patch)
tree73df8262776cde450d4415380490785eb03e8b0f /security
parent631d2b490569118c5e4d4e35983efe36d9798cb5 (diff)
downloadlinux-7e4237faa7213c1cc1d0aa65a44c67ba4729ce9f.tar.xz
selinux: cleanup dentry and inodes on error in selinuxfs
If the resource requested by d_alloc_name is not added to the linked list through d_add, then dput needs to be called to release the subsequent abnormal branch to avoid resource leakage. Add missing dput to selinuxfs.c Signed-off-by: nixiaoming <nixiaoming@huawei.com> [PM: tweak the subject line] Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'security')
-rw-r--r--security/selinux/selinuxfs.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index eb7f12ab5c33..5cc9101ab79b 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -1377,13 +1377,18 @@ static int sel_make_bools(struct selinux_fs_info *fsi)
ret = -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
- if (!inode)
+ if (!inode) {
+ dput(dentry);
goto out;
+ }
ret = -ENAMETOOLONG;
len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
- if (len >= PAGE_SIZE)
+ if (len >= PAGE_SIZE) {
+ dput(dentry);
+ iput(inode);
goto out;
+ }
isec = (struct inode_security_struct *)inode->i_security;
ret = security_genfs_sid(fsi->state, "selinuxfs", page,
@@ -1598,8 +1603,10 @@ static int sel_make_avc_files(struct dentry *dir)
return -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode);
- if (!inode)
+ if (!inode) {
+ dput(dentry);
return -ENOMEM;
+ }
inode->i_fop = files[i].ops;
inode->i_ino = ++fsi->last_ino;
@@ -1644,8 +1651,10 @@ static int sel_make_initcon_files(struct dentry *dir)
return -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO);
- if (!inode)
+ if (!inode) {
+ dput(dentry);
return -ENOMEM;
+ }
inode->i_fop = &sel_initcon_ops;
inode->i_ino = i|SEL_INITCON_INO_OFFSET;
@@ -1745,8 +1754,10 @@ static int sel_make_perm_files(char *objclass, int classvalue,
rc = -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO);
- if (!inode)
+ if (!inode) {
+ dput(dentry);
goto out;
+ }
inode->i_fop = &sel_perm_ops;
/* i+1 since perm values are 1-indexed */
@@ -1775,8 +1786,10 @@ static int sel_make_class_dir_entries(char *classname, int index,
return -ENOMEM;
inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO);
- if (!inode)
+ if (!inode) {
+ dput(dentry);
return -ENOMEM;
+ }
inode->i_fop = &sel_class_ops;
inode->i_ino = sel_class_to_ino(index);
@@ -1850,8 +1863,10 @@ static int sel_make_policycap(struct selinux_fs_info *fsi)
return -ENOMEM;
inode = sel_make_inode(fsi->sb, S_IFREG | 0444);
- if (inode == NULL)
+ if (inode == NULL) {
+ dput(dentry);
return -ENOMEM;
+ }
inode->i_fop = &sel_policycap_ops;
inode->i_ino = iter | SEL_POLICYCAP_INO_OFFSET;
@@ -1944,8 +1959,10 @@ static int sel_fill_super(struct super_block *sb, void *data, int silent)
ret = -ENOMEM;
inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
- if (!inode)
+ if (!inode) {
+ dput(dentry);
goto err;
+ }
inode->i_ino = ++fsi->last_ino;
isec = (struct inode_security_struct *)inode->i_security;