From patchwork Wed Feb 1 09:06:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Johansen X-Patchwork-Id: 722407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3vCy2G3Xkqz9s1h; Wed, 1 Feb 2017 20:07:34 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1cYqt1-00015W-Dg; Wed, 01 Feb 2017 09:07:31 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1cYqsc-0000fJ-L6 for kernel-team@lists.ubuntu.com; Wed, 01 Feb 2017 09:07:06 +0000 Received: from static-50-53-52-155.bvtn.or.frontiernet.net ([50.53.52.155] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1cYqsc-0003gb-2R for kernel-team@lists.ubuntu.com; Wed, 01 Feb 2017 09:07:06 +0000 From: John Johansen To: kernel-team@lists.ubuntu.com Subject: [PATCH 09/14] UBUNTU: SAUCE: apparmor: fix leak on securityfs pin count Date: Wed, 1 Feb 2017 01:06:01 -0800 Message-Id: <20170201090606.22422-10-john.johansen@canonical.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170201090606.22422-1-john.johansen@canonical.com> References: <20170201090606.22422-1-john.johansen@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com apparmor is leaking pinfs refcoutn when inode setup fails. BugLink: http://bugs.launchpad.net/bugs/1660846 Signed-off-by: John Johansen --- include/linux/security.h | 5 ++++- security/apparmor/apparmorfs.c | 4 +++- security/inode.c | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/linux/security.h b/include/linux/security.h index 32a4043..a31c1db 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -1587,6 +1587,7 @@ static inline void security_audit_rule_free(void *lsmrule) #ifdef CONFIG_SECURITYFS extern int securityfs_pin_fs(void); +extern void securityfs_release_fs(void); extern int __securityfs_setup_d_inode(struct inode *dir, struct dentry *dentry, umode_t mode, void *data, const struct file_operations *fops, @@ -1606,7 +1607,9 @@ static inline int securityfs_pin_fs(void) { return -ENODEV; } - +static inline void securityfs_release_fs(void) +{ +} static inline int __securityfs_setup_d_inode(struct inode *dir, struct dentry *dentry, umode_t mode, void *data, diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 3f1dd67..ee9a780 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -1057,7 +1057,7 @@ static int ns_mkdir_op(struct inode *dir, struct dentry *dentry, umode_t mode) error = __securityfs_setup_d_inode(dir, dentry, mode | S_IFDIR, NULL, NULL, NULL); if (error) - goto out; + goto out_pin; ns = aa_create_ns(parent, ACCESS_ONCE(dentry->d_name.name), dentry); if (IS_ERR(ns)) { @@ -1066,6 +1066,8 @@ static int ns_mkdir_op(struct inode *dir, struct dentry *dentry, umode_t mode) } aa_put_ns(ns); /* list ref remains */ +out_pin: + securityfs_release_fs(); out: aa_put_ns(parent); diff --git a/security/inode.c b/security/inode.c index 692b284..e701820 100644 --- a/security/inode.c +++ b/security/inode.c @@ -51,6 +51,11 @@ int securityfs_pin_fs(void) return simple_pin_fs(&fs_type, &mount, &mount_count); } +void securityfs_release_fs(void) +{ + simple_release_fs(&mount, &mount_count); +} + int __securityfs_setup_d_inode(struct inode *dir, struct dentry *dentry, umode_t mode, void *data, const struct file_operations *fops,