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 8D221C5AE5E for ; Fri, 18 Jan 2019 22:55:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6283420823 for ; Fri, 18 Jan 2019 22:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729798AbfARWz5 (ORCPT ); Fri, 18 Jan 2019 17:55:57 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:57772 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729709AbfARWz5 (ORCPT ); Fri, 18 Jan 2019 17:55:57 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.91 #2 (Red Hat Linux)) id 1gkd3I-0002Vc-Bv; Fri, 18 Jan 2019 22:55:52 +0000 Date: Fri, 18 Jan 2019 22:55:52 +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 2/5] binderfs: prevent renaming the control dentry Message-ID: <20190118225552.GZ2217@ZenIV.linux.org.uk> References: <20190118145344.11532-1-christian@brauner.io> <20190118145344.11532-3-christian@brauner.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190118145344.11532-3-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:41PM +0100, Christian Brauner wrote: > 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(). Umm... > +static inline bool is_binderfs_control_device(const struct inode *inode, > + const struct dentry *dentry) > +{ > + return BINDERFS_I(inode)->control_dentry == dentry; > +} What do you need an inode for? static inline struct binderfs_info *BINDERFS_I(const struct inode *inode) { return inode->i_sb->s_fs_info; } so it looks like all you care about is the superblock. Which can be had simply as dentry->d_sb... Besides, what's the point of calling is_binderfs_device() in ->rename()? If your directory methods are given dentries from another filesystem, the kernel is already FUBAR. So your rename should simply do if (is_binderfs_control_device(old_dentry) || is_binderfs_control_device(new_dentry)) return -EPERM; return simple_rename(......); and that's it...