From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69840C5AE5E for ; Fri, 18 Jan 2019 23:03:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3A6D320652 for ; Fri, 18 Jan 2019 23:03:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729898AbfARXD6 (ORCPT ); Fri, 18 Jan 2019 18:03:58 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:57870 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729780AbfARXD5 (ORCPT ); Fri, 18 Jan 2019 18:03:57 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gkdB4-0002y8-Oh; Fri, 18 Jan 2019 23:03:54 +0000 Date: Fri, 18 Jan 2019 23:03:54 +0000 From: Al Viro To: Christian Brauner Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, tkjos@google.com Subject: Re: [PATCH 3/5] binderfs: rework binderfs_fill_super() Message-ID: <20190118230354.GA2217@ZenIV.linux.org.uk> References: <20190118145344.11532-1-christian@brauner.io> <20190118145344.11532-4-christian@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190118145344.11532-4-christian@brauner.io> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Fri, Jan 18, 2019 at 03:53:42PM +0100, Christian Brauner wrote: > static int binderfs_fill_super(struct super_block *sb, void *data, int silent) > { > + int ret; > struct binderfs_info *info; > - int ret = -ENOMEM; > struct inode *inode = NULL; > struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns; > > @@ -495,13 +495,14 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent) > sb->s_op = &binderfs_super_ops; > sb->s_time_gran = 1; > > - info = kzalloc(sizeof(struct binderfs_info), GFP_KERNEL); > - if (!info) > - goto err_without_dentry; > + sb->s_fs_info = kzalloc(sizeof(struct binderfs_info), GFP_KERNEL); > + if (!sb->s_fs_info) > + return -ENOMEM; > + info = sb->s_fs_info; ... and that's when you should grab ipcns reference and stick it into info->ipc_ns, to match the logics in binderfs_kill_super(). Otherwise the failure above > ret = binderfs_parse_mount_opts(data, &info->mount_opts); > if (ret) > - goto err_without_dentry; > + return ret; ... or here leaves you with an ipcns leak. Destructor does if ->s_fs_info is non-NULL release ->s_fs_info->ipc_ns free ->s_fs_info so constructor should not leave object in a state when ipcns is already grabbed, but not stored in ->s_fs_info->ipc_ns (including the case of allocation failure leaving it with NULL ->s_fs_info).