From patchwork Mon Jan 21 10:48:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10773571 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2F4D9139A for ; Mon, 21 Jan 2019 10:49:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E8A3298EA for ; Mon, 21 Jan 2019 10:49:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 130F129901; Mon, 21 Jan 2019 10:49:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2628298EA for ; Mon, 21 Jan 2019 10:49:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbfAUKtz (ORCPT ); Mon, 21 Jan 2019 05:49:55 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:38385 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727525AbfAUKtz (ORCPT ); Mon, 21 Jan 2019 05:49:55 -0500 Received: by mail-ed1-f66.google.com with SMTP id h50so16202750ede.5 for ; Mon, 21 Jan 2019 02:49:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=W043WQStXK5KbWXSBBamW/URLr8YdnqlQMRR5drKHIg=; b=NvYLqOsTBIwOdusKLPmEK8FU08Q/Vjn36u0u0ooAxZmgtKf4O58OvJeii03hTHQiyF 9OfFsdYtVaO5z4LsE5gk9wPUfuAlf29ccu6HHUoNV6RlSK8CAtPOUpn95AEkpY+sMo7w g2XsqTEVA6fFpW7A7LAOJAslO2fXTc6K5B5g9EKyLh2zo6RgxdKkxGafbtTa/pVWtYDZ sxT7H4D653UWub6CxPVHLWlRicRMkk822QiL6iqoDSpV0jBMXRbUh4I0B1W0Q2eJz7aj 7CW8yrXYIrB7yuqTnmXy71zLbCARMyL+qeAkLrZfI64s6TdsClgWyAi6UZlud2/iSGCZ X0Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=W043WQStXK5KbWXSBBamW/URLr8YdnqlQMRR5drKHIg=; b=Tsiq0j4AIZOK1ksLNZ5LU0OGu/E8C+agHayYXvWOb/PbxvUaDHEXrVBp8O4rc2pNNY v1DzQur0W+cT/fCPAVoIV9cb+8ATXjTfPS26GpZppTszQlSih4tQBavMIlzrYPowqMfe kA8nzi/lK1kXCAavNgT8wkVz2aIFbJx/f6o5g/WaeaKFPFze0bu0Vb5ag8O3NP242SsT fAlNIztolw6kzFVf+Sl1CRWVYw4XO3KzzRBP1dnsQ5UvHpXnTqXtiM5pU4T8h/n4VvB+ X6qZucHbCayAKGwF/HBZg1RIyijDkygI97UIBhDgic9wkg5kPHbJSD945f6bqsxfiSko bmHA== X-Gm-Message-State: AJcUukf4IDu+fC0J5n02XxUS0Xq5y9wf+67m7WTRFH5xkJyncBfi05R2 9iKzksyIlygVvaLq9C3Ri6bBkA== X-Google-Smtp-Source: ALg8bN67ro5xkxxwSpCmCuwbZZMGrAYvS3v5WauNJRIVsk+/m7NCiwfucAq5ANRE0rEzm212PScfuA== X-Received: by 2002:aa7:dace:: with SMTP id x14mr27379892eds.13.1548067793619; Mon, 21 Jan 2019 02:49:53 -0800 (PST) Received: from localhost.localdomain ([2a02:8109:b6bf:f9e4:9473:6b39:afaf:14d4]) by smtp.gmail.com with ESMTPSA id e35sm9006196eda.13.2019.01.21.02.49.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Jan 2019 02:49:53 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk, dhowells@redhat.com Cc: tkjos@google.com, Christian Brauner Subject: [PATCH v1 3/7] binderfs: rework binderfs_fill_super() Date: Mon, 21 Jan 2019 11:48:04 +0100 Message-Id: <20190121104808.24108-4-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190121104808.24108-1-christian@brauner.io> References: <20190121104808.24108-1-christian@brauner.io> MIME-Version: 1.0 X-Patchwork-Bot: notify Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Al pointed out that on binderfs_fill_super() error deactivate_locked_super() will call binderfs_kill_super() so all of the freeing and putting we currently do in binderfs_fill_super() is unnecessary and buggy. Let's simply return errors and let binderfs_fill_super() take care of cleaning up on error. Suggested-by: Al Viro Signed-off-by: Christian Brauner --- /* Changelog */ v1: - correctly grab and stash a reference to task's ipc_ns to prevent leaks - replace d_alloc_name() + d_lookup() combination with lookup_one_len() - replace kmalloc() + strscpy() with kmemdup() --- drivers/android/binderfs.c | 41 ++++++++++---------------------------- 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index e73f9dbee099..89a2ee1a02f6 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -461,12 +461,9 @@ static const struct inode_operations binderfs_dir_inode_operations = { 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; - - get_ipc_ns(ipc_ns); sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; @@ -488,15 +485,17 @@ 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; + + info->ipc_ns = get_ipc_ns(current->nsproxy->ipc_ns); ret = binderfs_parse_mount_opts(data, &info->mount_opts); if (ret) - goto err_without_dentry; + return ret; - info->ipc_ns = ipc_ns; info->root_gid = make_kgid(sb->s_user_ns, 0); if (!gid_valid(info->root_gid)) info->root_gid = GLOBAL_ROOT_GID; @@ -504,12 +503,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent) if (!uid_valid(info->root_uid)) info->root_uid = GLOBAL_ROOT_UID; - sb->s_fs_info = info; - - ret = -ENOMEM; inode = new_inode(sb); if (!inode) - goto err_without_dentry; + return -ENOMEM; inode->i_ino = FIRST_INODE; inode->i_fop = &simple_dir_operations; @@ -520,24 +516,9 @@ static int binderfs_fill_super(struct super_block *sb, void *data, int silent) sb->s_root = d_make_root(inode); if (!sb->s_root) - goto err_without_dentry; - - ret = binderfs_binder_ctl_create(sb); - if (ret) - goto err_with_dentry; - - return 0; - -err_with_dentry: - dput(sb->s_root); - sb->s_root = NULL; - -err_without_dentry: - put_ipc_ns(ipc_ns); - iput(inode); - kfree(info); + return -ENOMEM; - return ret; + return binderfs_binder_ctl_create(sb); } static struct dentry *binderfs_mount(struct file_system_type *fs_type,