Skip to content

Commit 7e4237f

Browse files
nixiaomingpcmoore
authored andcommitted
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>
1 parent 631d2b4 commit 7e4237f

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

security/selinux/selinuxfs.c

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,13 +1377,18 @@ static int sel_make_bools(struct selinux_fs_info *fsi)
13771377

13781378
ret = -ENOMEM;
13791379
inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
1380-
if (!inode)
1380+
if (!inode) {
1381+
dput(dentry);
13811382
goto out;
1383+
}
13821384

13831385
ret = -ENAMETOOLONG;
13841386
len = snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]);
1385-
if (len >= PAGE_SIZE)
1387+
if (len >= PAGE_SIZE) {
1388+
dput(dentry);
1389+
iput(inode);
13861390
goto out;
1391+
}
13871392

13881393
isec = (struct inode_security_struct *)inode->i_security;
13891394
ret = security_genfs_sid(fsi->state, "selinuxfs", page,
@@ -1598,8 +1603,10 @@ static int sel_make_avc_files(struct dentry *dir)
15981603
return -ENOMEM;
15991604

16001605
inode = sel_make_inode(dir->d_sb, S_IFREG|files[i].mode);
1601-
if (!inode)
1606+
if (!inode) {
1607+
dput(dentry);
16021608
return -ENOMEM;
1609+
}
16031610

16041611
inode->i_fop = files[i].ops;
16051612
inode->i_ino = ++fsi->last_ino;
@@ -1644,8 +1651,10 @@ static int sel_make_initcon_files(struct dentry *dir)
16441651
return -ENOMEM;
16451652

16461653
inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO);
1647-
if (!inode)
1654+
if (!inode) {
1655+
dput(dentry);
16481656
return -ENOMEM;
1657+
}
16491658

16501659
inode->i_fop = &sel_initcon_ops;
16511660
inode->i_ino = i|SEL_INITCON_INO_OFFSET;
@@ -1745,8 +1754,10 @@ static int sel_make_perm_files(char *objclass, int classvalue,
17451754

17461755
rc = -ENOMEM;
17471756
inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO);
1748-
if (!inode)
1757+
if (!inode) {
1758+
dput(dentry);
17491759
goto out;
1760+
}
17501761

17511762
inode->i_fop = &sel_perm_ops;
17521763
/* i+1 since perm values are 1-indexed */
@@ -1775,8 +1786,10 @@ static int sel_make_class_dir_entries(char *classname, int index,
17751786
return -ENOMEM;
17761787

17771788
inode = sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO);
1778-
if (!inode)
1789+
if (!inode) {
1790+
dput(dentry);
17791791
return -ENOMEM;
1792+
}
17801793

17811794
inode->i_fop = &sel_class_ops;
17821795
inode->i_ino = sel_class_to_ino(index);
@@ -1850,8 +1863,10 @@ static int sel_make_policycap(struct selinux_fs_info *fsi)
18501863
return -ENOMEM;
18511864

18521865
inode = sel_make_inode(fsi->sb, S_IFREG | 0444);
1853-
if (inode == NULL)
1866+
if (inode == NULL) {
1867+
dput(dentry);
18541868
return -ENOMEM;
1869+
}
18551870

18561871
inode->i_fop = &sel_policycap_ops;
18571872
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)
19441959

19451960
ret = -ENOMEM;
19461961
inode = sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO);
1947-
if (!inode)
1962+
if (!inode) {
1963+
dput(dentry);
19481964
goto err;
1965+
}
19491966

19501967
inode->i_ino = ++fsi->last_ino;
19511968
isec = (struct inode_security_struct *)inode->i_security;

0 commit comments

Comments
 (0)