Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp973932imm; Wed, 8 Aug 2018 08:41:45 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxoPSQAB8mTc3hgb7HtDMirjGi+ZEOZCKHOVBFQPiC6TjLcPBupQEh0yoK0JSHD/NihYTw/ X-Received: by 2002:a62:f0d:: with SMTP id x13-v6mr3456881pfi.123.1533742905652; Wed, 08 Aug 2018 08:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533742905; cv=none; d=google.com; s=arc-20160816; b=NzTWuxzYbIMbSaZvjkUGNg0Dv133NKrrHvUzhvKHmMsnMR7oey4rgmxzKPaZWDjbqU XoRk7Iild/o1jpVZmtuE2DQMG1n6lB/HIbA2lzh3z0vbiHpmTV31DZr6Oew0uNWCVdR1 hY/0Kgrg7g1Z1XJ7T69wGvXouLk2zRvyARViPRbScdXyigpnDJLzHa59ORJ04SBDC/ZA 3eDnUacioWlrcqBEbt8gSXPv/1Iqy6M6lrWNTd4NUj0iCXBwPwA8mrUezIf8jM4Ityia +rEmTq8IXZ0dlZtgHaD/IzOe1VG9XVw7nWbYB1P6ly2sDRIztpJMXdZfLzFUvmCAumS7 G8HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=+4hhiODN7cTyFLH5gTWk+jd1FEZsBWmZzCgpV/3+Ag8=; b=Drm4BOCXWm88i3zre1V0/1ySl+Wc0VBg0pm5nukBu+CwkBT4/jEatJa4Lb3GBCKRpo c7myKVDcWNmcsJ9TcrvjpAN+rZXUMPny7KjhXyeVcaeMdW68aDbxF77eCSlDHPb9rAhf 9T9yTuDr+5kVhlWAIn5zkjZJc8cg/VijekT8g1CwrNs06UJ5pIdodWzAk5yfcrw+upOk 8XqizYnCpzW+ACnCWW1RgvlnD1nkvrgBB+0848injGqIhButuiVksXQDwV/vaEZu7xA5 PgKSGRRLsgIXi1Ps+uIGMecr23RsHhMQbPbak8L+85jzLImmuJDPolR9edgXqekQGWV0 zBYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b="EyzOds8/"; 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 c6-v6si4029621pgn.143.2018.08.08.08.41.30; Wed, 08 Aug 2018 08:41:45 -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; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b="EyzOds8/"; 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 S1727539AbeHHSAR (ORCPT + 99 others); Wed, 8 Aug 2018 14:00:17 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:46054 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726954AbeHHSAR (ORCPT ); Wed, 8 Aug 2018 14:00:17 -0400 Received: by mail-lj1-f196.google.com with SMTP id w16-v6so2055475ljh.12 for ; Wed, 08 Aug 2018 08:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+4hhiODN7cTyFLH5gTWk+jd1FEZsBWmZzCgpV/3+Ag8=; b=EyzOds8/AF9WChl5eQ4sEZJ90utn7x60C/4bhvAzVv5cI5PgaqfLZyDfIkd+6KGKDQ 39w8idSZbSRj3p50b46NklZ9aalV8qgYpTT97kelcT66zK2cojEANbqPECbAq1KP/WHe /nVsYvVLSsEK8L8MJvXGvdxJODBHByJ9v/cOWL/LtMOEFB/L3GmjxAN1+bS9IHsO8dsu TYTIARNj0TEVSWUPVc3f0uG1eENLn4EgazrbLSTpbvYWIl/DgnhQh9f3RL/QI0m2EUlE kFGl/UGFngwJ4cPl+06p3rYi5M83vUYqOBv6qU2bl2PyPuRswvaUb8tdwJszfkg+1tAw RP7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+4hhiODN7cTyFLH5gTWk+jd1FEZsBWmZzCgpV/3+Ag8=; b=Vds6Zi/Z2+TqZYw2t23ujy4N0zlLh3tCvcLJTevyevBBwOALWGq/zv6pRXEFUmZbzm BWzx74zWET2HBIgXumMercdco6GVs08VJEG7h+iHUle1JVSbmJdXqdtAdfwVeFz69R2J xwUr1elfhhLI+rObrF+xRPz+9NlJqzFJlMML+waPwN0UW8w017Uw+EZmh3hmt283oHQr h9fGGDXyXD5JxdLHIQt3T9p5w4IlbSYm1MhKqxk7TiaRkSa4/hbWt4B9EC/RRIM6pWdY FY48fRNRl7BkbDhHTli7lN2/b0igHe9F/7xBXhgwx8re4YkUt3ysw2K1q+t3dfdLRR76 ELYg== X-Gm-Message-State: AOUpUlGO+5RZS0G3FBfBLXt/Zr7N47BIXDIN57hdr1yhM9CMojq2hxZ6 qMOPV0csGFDcGEc+mFI2Sno5SdorLbL6nHc363BB X-Received: by 2002:a2e:8743:: with SMTP id q3-v6mr2385773ljj.139.1533742801874; Wed, 08 Aug 2018 08:40:01 -0700 (PDT) MIME-Version: 1.0 References: <20180805091036.30035-1-nixiaoming@huawei.com> In-Reply-To: From: Paul Moore Date: Wed, 8 Aug 2018 11:39:50 -0400 Message-ID: Subject: Re: [PATCH] selinuxfs: Fix the resource leak in the failed branch of sel_make_inode To: nixiaoming@huawei.com Cc: Stephen Smalley , Eric Paris , James Morris , serge@hallyn.com, selinux@tycho.nsa.gov, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 7, 2018 at 5:35 PM Paul Moore wrote: > > On Sun, Aug 5, 2018 at 5:48 AM nixiaoming wrote: > > 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 > > --- > > security/selinux/selinuxfs.c | 33 +++++++++++++++++++++++++-------- > > 1 file changed, 25 insertions(+), 8 deletions(-) > > Thanks for the quick follow-up on this patch. It looks okay to me, > assuming my test kernel works correctly (it's building now) I'll merge > this into selinux/next. Merged into selinux/next, thanks! > > diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c > > index 79d3709..0b66d728 100644 > > --- a/security/selinux/selinuxfs.c > > +++ b/security/selinux/selinuxfs.c > > @@ -1365,13 +1365,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, > > @@ -1586,8 +1591,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; > > @@ -1632,8 +1639,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; > > @@ -1733,8 +1742,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 */ > > @@ -1763,8 +1774,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); > > @@ -1838,8 +1851,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; > > @@ -1932,8 +1947,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; > > -- > > 2.10.1 > > > > -- > > To unsubscribe from this list: send the line "unsubscribe linux-security-module" in > > the body of a message to majordomo@vger.kernel.org > > More majordomo info at http://vger.kernel.org/majordomo-info.html > > > > -- > paul moore > www.paul-moore.com -- paul moore www.paul-moore.com