From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-co1nam03on0118.outbound.protection.outlook.com ([104.47.40.118]:50016 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727762AbeH3WLS (ORCPT ); Thu, 30 Aug 2018 18:11:18 -0400 From: Sasha Levin To: "stable@vger.kernel.org" CC: nixiaoming , Paul Moore , Sasha Levin Subject: [PATCH AUTOSEL 4.18 088/113] selinux: cleanup dentry and inodes on error in selinuxfs Date: Thu, 30 Aug 2018 18:07:54 +0000 Message-ID: <20180830180714.36167-22-alexander.levin@microsoft.com> References: <20180830180714.36167-1-alexander.levin@microsoft.com> In-Reply-To: <20180830180714.36167-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: nixiaoming [ 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 [PM: tweak the subject line] Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/selinuxfs.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c index 79d3709b0671..0b66d7283b00 100644 --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1365,13 +1365,18 @@ static int sel_make_bools(struct selinux_fs_info *f= si) =20 ret =3D -ENOMEM; inode =3D sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR); - if (!inode) + if (!inode) { + dput(dentry); goto out; + } =20 ret =3D -ENAMETOOLONG; len =3D snprintf(page, PAGE_SIZE, "/%s/%s", BOOL_DIR_NAME, names[i]); - if (len >=3D PAGE_SIZE) + if (len >=3D PAGE_SIZE) { + dput(dentry); + iput(inode); goto out; + } =20 isec =3D (struct inode_security_struct *)inode->i_security; ret =3D security_genfs_sid(fsi->state, "selinuxfs", page, @@ -1586,8 +1591,10 @@ static int sel_make_avc_files(struct dentry *dir) return -ENOMEM; =20 inode =3D sel_make_inode(dir->d_sb, S_IFREG|files[i].mode); - if (!inode) + if (!inode) { + dput(dentry); return -ENOMEM; + } =20 inode->i_fop =3D files[i].ops; inode->i_ino =3D ++fsi->last_ino; @@ -1632,8 +1639,10 @@ static int sel_make_initcon_files(struct dentry *dir= ) return -ENOMEM; =20 inode =3D sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO); - if (!inode) + if (!inode) { + dput(dentry); return -ENOMEM; + } =20 inode->i_fop =3D &sel_initcon_ops; inode->i_ino =3D i|SEL_INITCON_INO_OFFSET; @@ -1733,8 +1742,10 @@ static int sel_make_perm_files(char *objclass, int c= lassvalue, =20 rc =3D -ENOMEM; inode =3D sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO); - if (!inode) + if (!inode) { + dput(dentry); goto out; + } =20 inode->i_fop =3D &sel_perm_ops; /* i+1 since perm values are 1-indexed */ @@ -1763,8 +1774,10 @@ static int sel_make_class_dir_entries(char *classnam= e, int index, return -ENOMEM; =20 inode =3D sel_make_inode(dir->d_sb, S_IFREG|S_IRUGO); - if (!inode) + if (!inode) { + dput(dentry); return -ENOMEM; + } =20 inode->i_fop =3D &sel_class_ops; inode->i_ino =3D sel_class_to_ino(index); @@ -1838,8 +1851,10 @@ static int sel_make_policycap(struct selinux_fs_info= *fsi) return -ENOMEM; =20 inode =3D sel_make_inode(fsi->sb, S_IFREG | 0444); - if (inode =3D=3D NULL) + if (inode =3D=3D NULL) { + dput(dentry); return -ENOMEM; + } =20 inode->i_fop =3D &sel_policycap_ops; inode->i_ino =3D iter | SEL_POLICYCAP_INO_OFFSET; @@ -1932,8 +1947,10 @@ static int sel_fill_super(struct super_block *sb, vo= id *data, int silent) =20 ret =3D -ENOMEM; inode =3D sel_make_inode(sb, S_IFCHR | S_IRUGO | S_IWUGO); - if (!inode) + if (!inode) { + dput(dentry); goto err; + } =20 inode->i_ino =3D ++fsi->last_ino; isec =3D (struct inode_security_struct *)inode->i_security; --=20 2.17.1