From patchwork Fri Jan 18 14:53:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10770545 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 A2D7D91E for ; Fri, 18 Jan 2019 14:54:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 925BF2A035 for ; Fri, 18 Jan 2019 14:54:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 866D02A185; Fri, 18 Jan 2019 14:54:10 +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 0A2992A111 for ; Fri, 18 Jan 2019 14:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727631AbfAROyJ (ORCPT ); Fri, 18 Jan 2019 09:54:09 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:38866 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbfAROyI (ORCPT ); Fri, 18 Jan 2019 09:54:08 -0500 Received: by mail-wr1-f66.google.com with SMTP id v13so15419580wrw.5 for ; Fri, 18 Jan 2019 06:54:07 -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=JIu0gxheHpfHMGtY6RG0wmqCifwZppPWn7yXlpfF3JQ=; b=EmbAHrWDz3SMekBTo9S3HTxYzUPPtivAaQU0CMYuSJ6rdRaXF/naDeuRowQrEUrKIL aNePWVrTUuihoQmd8ER8zjt73DFDeqKJd7sX+e0ecfABh2jbcT68UYE08o6mmcxidYJ1 3SCpI6zn35EHvWApEJrUDXyYzRw3im1omsnJLYIVsKtJ5WQaAwt2TwiodOZaZ1z5UaRf Ev+qIOxKKbnsssNRmzrRmbJJe+lsmrp9pqE4iUg9kB/dylOBOeEYMUv1aLQwAKXq9duR KFqS71g8aREGwpyBuDs+O1y4iQ22qv7OldR9YRTlpsML6W3vkPpfzK1dgbE7LeMPRwIx 5KXA== 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=JIu0gxheHpfHMGtY6RG0wmqCifwZppPWn7yXlpfF3JQ=; b=Y1NAXcS1v0JQCWXrHDjvVGv1u8eOTttoDKDvAu7C78MhCl080sFi0ec2mpY9wMQe4N /z9xx2586UL61HMZxqU60rGjKynUaKqSkJ+jB0laTODCTcuhiOHktAvHgU/WXtN5KB67 2lRaYg1t4+TD/RfnNatomcidM4DvxKMxjqYhXgJAjBqdsejOK0vf0Izaq72pd4d5TXyo S9gUJOXin2gGoksUvyBIKno9Mly6Afjo4Sevh0O/QA37d76ye6kpFwAm2zHk7mjSjEEE Cvb/N1vLIUFqHuYcdmgHNoW4MmTtMYnOEMMjAJBOQ7XzdRdLRnRJV704YccZZ5O5vOsC ndfg== X-Gm-Message-State: AJcUukfOdkpwEqwxJ9JrGQv1yKRLG/cvytjpYiWqCcNEkohLmirsGxEg HBxX9VCUsZCEOcGcTRntd4PBJg== X-Google-Smtp-Source: ALg8bN5pUicTApvOFwjDNAxheQ1709rqBXxkvaKf3uiacUebglLzHo5Kn4YBzhsuY9s9/0T3xma4fg== X-Received: by 2002:a5d:6450:: with SMTP id d16mr16858877wrw.64.1547823247151; Fri, 18 Jan 2019 06:54:07 -0800 (PST) Received: from localhost.localdomain ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id l15sm67655466wrw.4.2019.01.18.06.54.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 06:54:06 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: tkjos@google.com, Christian Brauner Subject: [PATCH 1/5] binderfs: remove outdated comment Date: Fri, 18 Jan 2019 15:53:40 +0100 Message-Id: <20190118145344.11532-2-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118145344.11532-1-christian@brauner.io> References: <20190118145344.11532-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 The comment stems from an early version of that patchset and is just confusing now. Cc: Al Viro Signed-off-by: Christian Brauner --- drivers/android/binderfs.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index e4ff4c3fa371..898d847f8505 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -373,10 +373,6 @@ static int binderfs_rename(struct inode *old_dir, struct dentry *old_dentry, static int binderfs_unlink(struct inode *dir, struct dentry *dentry) { - /* - * The control dentry is only ever touched during mount so checking it - * here should not require us to take lock. - */ if (BINDERFS_I(dir)->control_dentry == dentry) return -EPERM; From patchwork Fri Jan 18 14:53:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10770547 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 3559991E for ; Fri, 18 Jan 2019 14:54:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24C972A2BC for ; Fri, 18 Jan 2019 14:54:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 199272BBE3; Fri, 18 Jan 2019 14:54:13 +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 AC6842A2BC for ; Fri, 18 Jan 2019 14:54:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727726AbfAROyM (ORCPT ); Fri, 18 Jan 2019 09:54:12 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37183 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727357AbfAROyL (ORCPT ); Fri, 18 Jan 2019 09:54:11 -0500 Received: by mail-wm1-f65.google.com with SMTP id g67so4758853wmd.2 for ; Fri, 18 Jan 2019 06:54:10 -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=VfFQnPccwF2QQE62JILvf3t1S1SYAKZFu0evYmCdlcc=; b=H6m3zfl6jAHedfrCvZnFAutIfg5fyX5S426InAEaZ350stIgGKuCeBIvGdjc1epEBh +jNgolATu7Ho+b/dzOvfoqR1ITNEsJaVsfrlmVTKBD2O+73KK/tB9Y3noysGHWytEBEM a7RhzoaLv2EKOltC4VnyPXirmYKIodVlFTCu3Y9LO+MJ/Qk//VCkrYRTqhomROcjHyyZ QeVqi3dKpsPwa8H8HLpCxzJcMmiZvxtMokbDjHXMT4pSpn/YI54vNiEP3c6kCfsnQsHX E9r0xZIZwbtxiIX3xu3iBuGYcptnVb5IcGQSoO3+jkLNJyV1D/g/ifEHnLbcz4OBCJec 28Bw== 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=VfFQnPccwF2QQE62JILvf3t1S1SYAKZFu0evYmCdlcc=; b=HDWdg+e0OexPTo6U2GhZTAst84nUF/+++x3WAdRXHHjQQJcN5qLthtRQvyWQoFZp1Y T4a6LAK6kuj7RsJEWOKKxLK7ZmQIQ6e8r41c9hUNfZR2BwmZ7/ZU8iEwMBV0KVXKZXgV wCooEZXGJRdS75rz0uIr3DOk6bnIodTbMFOti5+KoovBvWQMBknBXg90NfP/tQ9JWvAu 0Pe2WjUgCzssR+l9jMQT0tcUXa4jyIo+29bYRaMcs5ea1pkdT1TEQQvACqViJpc+P9gT RYBXYb+uej3vu+Pf2EjDpf8UDZos1gIMn7WK7Qd9Rgvhfjl3DrQ/SSmuHHsnRSkoCSy5 8D6Q== X-Gm-Message-State: AJcUukfOx6eCi2NJLzTJVlF5661sDx3MOwu+Umzxc7bTsXEGL8qSnn46 h7/2x6YXLVn27q5Lm5RYib+qAQ== X-Google-Smtp-Source: ALg8bN5MnbbXn7wyphp0+gmQM2GPg7pzeD7ySD9VrWuK03UOX9dXU4iakeWiAp38q/YuPuFlZSFPlg== X-Received: by 2002:a1c:8b09:: with SMTP id n9mr15934429wmd.38.1547823250261; Fri, 18 Jan 2019 06:54:10 -0800 (PST) Received: from localhost.localdomain ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id l15sm67655466wrw.4.2019.01.18.06.54.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 06:54:09 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: tkjos@google.com, Christian Brauner Subject: [PATCH 2/5] binderfs: prevent renaming the control dentry Date: Fri, 18 Jan 2019 15:53:41 +0100 Message-Id: <20190118145344.11532-3-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118145344.11532-1-christian@brauner.io> References: <20190118145344.11532-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 We don't allow to unlink it since it is crucial for binderfs to be useable but if we allow to rename it we make the unlink trivial to bypass. So prevent renaming too and simply treat the control dentry as immutable. Take the opportunity and turn the check for the control dentry into a separate helper is_binderfs_control_device() since it's now used in two places. Additionally, replace the custom rename dance we did with call to simple_rename(). Suggested-by: Al Viro Signed-off-by: Christian Brauner --- drivers/android/binderfs.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 898d847f8505..02c96b5edfa9 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -346,34 +346,33 @@ static const struct super_operations binderfs_super_ops = { .statfs = simple_statfs, }; +static inline bool is_binderfs_control_device(const struct inode *inode, + const struct dentry *dentry) +{ + return BINDERFS_I(inode)->control_dentry == dentry; +} + static int binderfs_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry, unsigned int flags) { - struct inode *inode = d_inode(old_dentry); - - /* binderfs doesn't support directories. */ - if (d_is_dir(old_dentry)) - return -EPERM; + const struct inode *inode = d_inode(old_dentry); - if (flags & ~RENAME_NOREPLACE) - return -EINVAL; - - if (!simple_empty(new_dentry)) - return -ENOTEMPTY; - - if (d_really_is_positive(new_dentry)) - simple_unlink(new_dir, new_dentry); + if (is_binderfs_device(d_inode(old_dentry))) + inode = d_inode(old_dentry); + else + inode = d_inode(new_dentry); - old_dir->i_ctime = old_dir->i_mtime = new_dir->i_ctime = - new_dir->i_mtime = inode->i_ctime = current_time(old_dir); + if (is_binderfs_control_device(inode, old_dentry) || + is_binderfs_control_device(inode, new_dentry)) + return -EPERM; - return 0; + return simple_rename(old_dir, old_dentry, new_dir, new_dentry, flags); } static int binderfs_unlink(struct inode *dir, struct dentry *dentry) { - if (BINDERFS_I(dir)->control_dentry == dentry) + if (is_binderfs_control_device(dir, dentry)) return -EPERM; return simple_unlink(dir, dentry); From patchwork Fri Jan 18 14:53:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10770549 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 E29DE91E for ; Fri, 18 Jan 2019 14:54:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D03D22A185 for ; Fri, 18 Jan 2019 14:54:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C46802A4BF; Fri, 18 Jan 2019 14:54:16 +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 5EA532A29C for ; Fri, 18 Jan 2019 14:54:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727817AbfAROyP (ORCPT ); Fri, 18 Jan 2019 09:54:15 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36192 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727357AbfAROyP (ORCPT ); Fri, 18 Jan 2019 09:54:15 -0500 Received: by mail-wr1-f67.google.com with SMTP id u4so15411164wrp.3 for ; Fri, 18 Jan 2019 06:54:14 -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=GGQFPlFyeUjc3cJT0M/L8VvY3A/TbWxGEsnlidESWwA=; b=AEfEvgKH/Ft6vQji3JnAEFQZ0ehy5hIK6HKQvco/l/VwxOgsQfEXJG7y7pWGWM7ybz OA7EDsqWssYslAEBE2M1smB0WTpNEQ/9fEU3a50DF0wTNC7vJK5lK2l3ya9dBzc6R0R8 fLlqelFj7MMydJSXNO+J1mNTJoMGZ7y85zGPqttVZanbMXWA8fbhW2wOuQqiJA0cxBGx H5pb3/aC8tQN979ZSgGVu3Z6G7ntM+XrkaWdr7X1K4Y6B6k7fe6Xp1EHh44SaNKYAbGK zRJZgrTs5HyI8fAl4G0GCPkfKxeFwuJs+eR1DN2qY5l6ZJZ9ibzphWAGsw9aNVg1C3WT Y83g== 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=GGQFPlFyeUjc3cJT0M/L8VvY3A/TbWxGEsnlidESWwA=; b=n7U3J318cYPcfunVjybZY0/UQN2yzUHIt8gC3Uyij+WHLHb7tOVne4vzZgoXYyOuqP 1jiF/WGc3b/xCGD3Up/ggUTCJ7rPrm2EjUD14aEFHGZx9Ro+Xjf2zrLigoWGKu7kjFny 5ejIF5OgEQ67TUuDEKLEdSzuQUA/54AqzlLewMsN7ghoXkamagU7/QNvsx/b63hK6VH6 FKLAHK22JiuggxzeBstMI+5naC3oN9aq/whVPp1ZireW1izdRCkgSMlTrOhoTVZXq7sa 6b44Dt8d6lTsETGTujFYqEW0VVz3gyoJbEQMpmVMcxvAOTeWre+T9xA0GaAdlvzTLj6F ILKQ== X-Gm-Message-State: AJcUukdFAQ3wTCU0KNFXUQhsTwaouWBfd++G0qMkOzl3BK7TTf75fO9W vEaK66aJepIwYWcr7xhYoUvdRg== X-Google-Smtp-Source: ALg8bN4vSFL2RSn8EEF7EMnr1q6WDzVy8m9F2ZBSiFKZ9JPdqhobHOgMYJtYaYve1Z4ARWQP9xSyWA== X-Received: by 2002:adf:f984:: with SMTP id f4mr17049884wrr.234.1547823253424; Fri, 18 Jan 2019 06:54:13 -0800 (PST) Received: from localhost.localdomain ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id l15sm67655466wrw.4.2019.01.18.06.54.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 06:54:12 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: tkjos@google.com, Christian Brauner Subject: [PATCH 3/5] binderfs: rework binderfs_fill_super() Date: Fri, 18 Jan 2019 15:53:42 +0100 Message-Id: <20190118145344.11532-4-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118145344.11532-1-christian@brauner.io> References: <20190118145344.11532-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 --- drivers/android/binderfs.c | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index 02c96b5edfa9..c0fa495ee994 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -468,8 +468,8 @@ 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; @@ -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; 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); @@ -511,12 +512,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; @@ -527,24 +525,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, From patchwork Fri Jan 18 14:53:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10770551 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 B69A791E for ; Fri, 18 Jan 2019 14:54:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A47B72A035 for ; Fri, 18 Jan 2019 14:54:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 984762CE0B; Fri, 18 Jan 2019 14:54:19 +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 3D72D29C57 for ; Fri, 18 Jan 2019 14:54:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727867AbfAROyS (ORCPT ); Fri, 18 Jan 2019 09:54:18 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36198 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727357AbfAROyS (ORCPT ); Fri, 18 Jan 2019 09:54:18 -0500 Received: by mail-wr1-f68.google.com with SMTP id u4so15411386wrp.3 for ; Fri, 18 Jan 2019 06:54:17 -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=BhbduQ2Vvh13G2CslRl+yOnFdTHcgNgzc7gl8o3eUtg=; b=fCCHNrpAhrFSfHefTHPBs3F9muT9CHB3mRILBtXnhAKP3WA15pd3YzAZ047NHqfDEM TwVWllF3M7XaU2YGMDKkvYfN97/IDdoy6egmmfhfHEvS2ya2tMnFbgvDEJY4iGPd2TWj ATkMaGaU7fbfWtIKaihlxGEa0b++ZdtKGdtcxcUKZQK/6nKL2NGYQDc3j+AiA6Iy4WHv N0YsgKsTWUEs4nFLGbgiyJ05xsqMxn+UpmwgUci9I/AjNFWKqcXSsTPSqVg7bZm4kFrz f/iaHyiuaW8kPAnWEkduJ/bqya013t+8SPqkVYypFgMINhOFEZiMdnP7+L/XSWbHAkhC aIpg== 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=BhbduQ2Vvh13G2CslRl+yOnFdTHcgNgzc7gl8o3eUtg=; b=NopMy9VgEf72JmktbnbxozDY0rIAYDCP5TUOi+YxF80SBNZaGiQpCpVN3dtfARQYsi mmIpE2xsM5hGuF3RjMkbuBixPfrdvL0Qek+De8KNM8OIJ/m58DlBF3lw/6S3aZxIDEg2 UKV4PaDqwv3d2lNpEyRqkaw1/KU3xHPKSE1r5yLZDLfTfnZY0FamTTvpvTu/Avrx3TQi ebwyp9aF2olzoDqezVEX+oZENoOh0rtPjjZhkfJugLE1ld62VT89vzXgULQudK0ZYp75 ErzI7/O0x4WevBurTppAABhdm2aKQA4LFl52ImS6jHg1uZWPEoUIzNxXXRSCin2MThau lAfg== X-Gm-Message-State: AJcUukccEkqJ8wzUltjRBiYhFmUe0P73Q3UlNu5EWZi6/c/tKYPziPF3 SU8OzR2Xlk4Q0ZE7VcFwHxRhfA== X-Google-Smtp-Source: ALg8bN4VvC7ejT340cNmhcpT+y0VL6tJSAMBaQ7cfWDRN1G2wVe/zTLBqhhA9/I0wLc3LZVKwU0EPA== X-Received: by 2002:a5d:5649:: with SMTP id j9mr16681310wrw.256.1547823256743; Fri, 18 Jan 2019 06:54:16 -0800 (PST) Received: from localhost.localdomain ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id l15sm67655466wrw.4.2019.01.18.06.54.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 06:54:16 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: tkjos@google.com, Christian Brauner Subject: [PATCH 4/5] binderfs: kill_litter_super() before cleanup Date: Fri, 18 Jan 2019 15:53:43 +0100 Message-Id: <20190118145344.11532-5-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118145344.11532-1-christian@brauner.io> References: <20190118145344.11532-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 first calling kill_litter_super() before cleaning up info is more correct since destroying info doesn't depend on the state of the dentries and inodes. That the opposite remains true is not guaranteed. Suggested-by: Al Viro Signed-off-by: Christian Brauner --- drivers/android/binderfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index c0fa495ee994..c5feb9ffce0f 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -541,11 +541,12 @@ static void binderfs_kill_super(struct super_block *sb) { struct binderfs_info *info = sb->s_fs_info; + kill_litter_super(sb); + if (info && info->ipc_ns) put_ipc_ns(info->ipc_ns); kfree(info); - kill_litter_super(sb); } static struct file_system_type binder_fs_type = { From patchwork Fri Jan 18 14:53:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 10770553 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 4906713B5 for ; Fri, 18 Jan 2019 14:54:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 380C82CE0B for ; Fri, 18 Jan 2019 14:54:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B0792E96A; Fri, 18 Jan 2019 14:54:24 +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 C9F532A223 for ; Fri, 18 Jan 2019 14:54:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727868AbfAROyX (ORCPT ); Fri, 18 Jan 2019 09:54:23 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52931 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727850AbfAROyX (ORCPT ); Fri, 18 Jan 2019 09:54:23 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so4760074wml.2 for ; Fri, 18 Jan 2019 06:54:21 -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=slfN4Y3NkY47GNxa0b/tkITJyzV38IgAX7v0CyEHCUQ=; b=X/XbyhoEGaNjz6Ss6ph3NBoD2VNaS6kHnfRWZguSi/aX+4DkfvXu+JvKY254L1TaYf tB6TKsr3PESqr+Auxh1uK949a0V7A6KGWGJtTkvIOeXqHcKeGmcl7ptwGh2of6K/v0Vd nkX5ipuyBHzgOteGfttQyeZt+opvWA8wSEdqGGAMYranEOCflR+krqKCxbP9Fg8NolIm Am8xIsKeSNDY39kMGi9oIUtBYy9VeOqP7JSQXG1qAHhj/xcfso/pkZTBK3tRItk1kUr8 4UbovstdLH0+SY1sJVxvj20TgkZqewdkrNgDCeJ7j8i5MW8uE8SaScW8fQjtSMBlQyDJ lAHw== 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=slfN4Y3NkY47GNxa0b/tkITJyzV38IgAX7v0CyEHCUQ=; b=aASc33LOM7YNqaj+GDOuM0djuFpQ0rreOeeZr/+dLmw7yjPuef3em2D/Sx2CBRQNNs z1hMffibtNqt025m59zIHc+lAkkgTAI7AaKf6vv5TigjZSvjZ0ctThti1Dq7+iLnqt2E k96HcHe9Jw6thRi2rKmfZAKA5FuJTpGimKfjFxBGhrDHzndoyZUb+SWK3/q8EdLu4hqV Lmamgq8lJlAm211GXvqB8hT20JAb5NNhxWdkAew6+y0lBaEZldtTwUJsHTqu87curtRx GXU7X1BFdP/llSSg7aWWKNQWgEj7zTWaRKOPWu4w3FQEXy6+w9qdYhZ5I7dar5LKwB92 NJZg== X-Gm-Message-State: AJcUukfEjgo9QwcDj3qXWPD3yaPh4rn/kU1eUzQRK+8MDKsRQASQecF+ GS1sI0yCVJuQPVwKJ1Z2ipK5fgiNxe6MEg== X-Google-Smtp-Source: ALg8bN7/vC52Wk6t3CUWeBKN41sRN+Z2RSoNZRjc4wgDMlGwC2wyFOX0MSHgnHhUG2bhxdui6yUOcQ== X-Received: by 2002:a1c:4681:: with SMTP id t123mr15802725wma.24.1547823260306; Fri, 18 Jan 2019 06:54:20 -0800 (PST) Received: from localhost.localdomain ([154.119.55.246]) by smtp.gmail.com with ESMTPSA id l15sm67655466wrw.4.2019.01.18.06.54.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Jan 2019 06:54:19 -0800 (PST) From: Christian Brauner To: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, linux-fsdevel@vger.kernel.org, viro@zeniv.linux.org.uk Cc: tkjos@google.com, Christian Brauner Subject: [PATCH 5/5] binderfs: drop lock in binderfs_binder_ctl_create Date: Fri, 18 Jan 2019 15:53:44 +0100 Message-Id: <20190118145344.11532-6-christian@brauner.io> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190118145344.11532-1-christian@brauner.io> References: <20190118145344.11532-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 The binderfs_binder_ctl_create() call is a no-op on subsequent calls and the first call is done before we unlock the suberblock. Hence, there is no need to take inode_lock() in there. Let's remove it. Suggested-by: Al Viro Signed-off-by: Christian Brauner --- Note, that fs/devptfs/inode.c:mknod_ptmx() is currently holding inode_lock() too under the exact same circumstances. Seems that we can drop it from there too. --- drivers/android/binderfs.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/android/binderfs.c b/drivers/android/binderfs.c index c5feb9ffce0f..db09274a1b75 100644 --- a/drivers/android/binderfs.c +++ b/drivers/android/binderfs.c @@ -408,8 +408,6 @@ static int binderfs_binder_ctl_create(struct super_block *sb) if (!device) return -ENOMEM; - inode_lock(d_inode(root)); - /* If we have already created a binder-control node, return. */ if (info->control_dentry) { ret = 0; @@ -448,12 +446,10 @@ static int binderfs_binder_ctl_create(struct super_block *sb) inode->i_private = device; info->control_dentry = dentry; d_add(dentry, inode); - inode_unlock(d_inode(root)); return 0; out: - inode_unlock(d_inode(root)); kfree(device); iput(inode);