]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commitdiff
selinux: cleanup dentry and inodes on error in selinuxfs
authornixiaoming <nixiaoming@huawei.com>
Sun, 5 Aug 2018 09:10:36 +0000 (17:10 +0800)
committerJuerg Haefliger <juergh@canonical.com>
Wed, 24 Jul 2019 01:47:08 +0000 (19:47 -0600)
BugLink: https://bugs.launchpad.net/bugs/1835972
[ Upstream commit 7e4237faa7213c1cc1d0aa65a44c67ba4729ce9f ]

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>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
security/selinux/selinuxfs.c

index 1b4bed79101e6e15e62cb0a29babe00f6698771c..9c0f185c3a4f54fc5b859891ae0d77ec83f3b406 100644 (file)
@@ -1292,13 +1292,18 @@ static int sel_make_bools(void)
 
                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 *)selinux_inode(inode);
                ret = security_genfs_sid("selinuxfs", page, SECCLASS_FILE, &sid);
@@ -1506,8 +1511,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 = ++sel_last_ino;
@@ -1551,8 +1558,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;
@@ -1650,8 +1659,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 */
@@ -1678,8 +1689,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);
@@ -1752,8 +1765,10 @@ static int sel_make_policycap(void)
                        return -ENOMEM;
 
                inode = sel_make_inode(policycap_dir->d_sb, S_IFREG | S_IRUGO);
-               if (inode == NULL)
+               if (inode == NULL) {
+                       dput(dentry);
                        return -ENOMEM;
+               }
 
                inode->i_fop = &sel_policycap_ops;
                inode->i_ino = iter | SEL_POLICYCAP_INO_OFFSET;
@@ -1837,8 +1852,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 = ++sel_last_ino;
        isec = (struct inode_security_struct *)selinux_inode(inode);