Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp739345imm; Thu, 13 Sep 2018 07:04:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZnlOnG8vYpClUGJoSYYliZ81tZkuCBUjJn5dpNYdTpCNhYTis8/ah5mkrA2nUuD5U0hkFr X-Received: by 2002:a63:2b4d:: with SMTP id r74-v6mr7399903pgr.406.1536847490908; Thu, 13 Sep 2018 07:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847490; cv=none; d=google.com; s=arc-20160816; b=agi9bYA1JML5/2hxxJ8LI/eIETR7ng9EaQt6CEXNe14xxv+EiEHZymhBqOkKRnJOoj 7vx5xD2l/6nJ7y7qaZPXy1djC8tIfo0JMCHD0bskZN8YqJdkN6wK4ZNFS6L0c+Ujdln/ JUwjCnS7iXx1koyv9f40dY0HhR0OKVcDx46bW5bXBI5sHTCSBzJkGYlOoN7s9dNg9w6B 2MDNiz/u8fn27NNNzvyZbnWV0UGxCDMIPgEvvvE6BCGtcphzcx00gQ90ksGQ2UPJ5SVh PgdkCFzrs/nm7pnJhRsgXu6A8UwRzB/sx+TIDfF+xZAzQ6egSn8uTN2hOgBlatQ398+e Rlpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=B7T2CkDlJShss1oa0vYA7aSnxIokyC20VFQ4t3DxgyI=; b=PtxXp5Sd65Mb+HHj4CNzpoWAq85baCirXYVhDk04efdLOKLezlrridxfxFLu99y2H7 w7zddOJMl9fNCSgNI0ctzcWMpQajES0oJyP+/T3hCV3QtB972+V4kUmgzCaw5JpVhtl6 ymdCIllKiFnZbzMB8FyAqPbD3HwhLwh96rRXGFl/ak5MdR/YAJeO2T9hTP0TUDHrciMj IgJEuGLT3MaGo51HdoE/gOZcEX7nTQnA5ePBURGlZzy98LLt4xWJy91T8kGxF7oj1/YF aLmzWM1GbXmZ6y1gQ3VymbADllBAF6abTbkMnPDtGNdJ/vNB4wOjhWpab9jJNqGk4kuh ITFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10-v6si4358451pgg.315.2018.09.13.07.04.31; Thu, 13 Sep 2018 07:04:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731954AbeIMTMC (ORCPT + 99 others); Thu, 13 Sep 2018 15:12:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35212 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731249AbeIMTMB (ORCPT ); Thu, 13 Sep 2018 15:12:01 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 34CC1D20; Thu, 13 Sep 2018 14:02:22 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, nixiaoming , Paul Moore , Sasha Levin Subject: [PATCH 4.18 117/197] selinux: cleanup dentry and inodes on error in selinuxfs Date: Thu, 13 Sep 2018 15:31:06 +0200 Message-Id: <20180913131846.229231657@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- security/selinux/selinuxfs.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) --- a/security/selinux/selinuxfs.c +++ b/security/selinux/selinuxfs.c @@ -1365,13 +1365,18 @@ static int sel_make_bools(struct selinux 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, @@ -1586,8 +1591,10 @@ static int sel_make_avc_files(struct den 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; @@ -1632,8 +1639,10 @@ static int sel_make_initcon_files(struct 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; @@ -1733,8 +1742,10 @@ static int sel_make_perm_files(char *obj 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 */ @@ -1763,8 +1774,10 @@ static int sel_make_class_dir_entries(ch 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); @@ -1838,8 +1851,10 @@ static int sel_make_policycap(struct sel 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; @@ -1932,8 +1947,10 @@ static int sel_fill_super(struct super_b 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;