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=-3.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, USER_AGENT_NEOMUTT 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 661D9C61CE4 for ; Sat, 19 Jan 2019 15:10:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 254CC2084C for ; Sat, 19 Jan 2019 15:10:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=brauner.io header.i=@brauner.io header.b="Tjnl4cE/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728221AbfASPK3 (ORCPT ); Sat, 19 Jan 2019 10:10:29 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46276 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728161AbfASPK2 (ORCPT ); Sat, 19 Jan 2019 10:10:28 -0500 Received: by mail-wr1-f65.google.com with SMTP id l9so18375868wrt.13 for ; Sat, 19 Jan 2019 07:10:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brauner.io; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ZEpfP/m37y5en84UyKAm22UGDoEqS9AFGWAMmB/iaxo=; b=Tjnl4cE/+3uSfoxsHJewyMtusYwhwmbzR/gG34p+mr194a+YoW1dwfEzfNBM5YdSmr 8exxjpB1uI9qvm7sZv60f0OX4aN859GPx161tjU71LGvrmR+EnDj2AkZudKKkK5WI/fA J+aEgdgom00xkCXZdjW+p457q0W/v22R/u3ZoSa6NLQwx6kbsY5Vpkbg2ilbRPd4Tvf3 8xcpnFKe0wnuT2kBgArf37pqxLX0nYVg9hAQ9k7k3Iq4Cu3l/PT+JQGW3ld3RBlZtdY8 WE4udVK821Bqm4ZVE6hNh+0RnyJKiJrzzYMbR2XXbkR0J8/tr2SAAxF9p1FmCR42oxYa V4oA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ZEpfP/m37y5en84UyKAm22UGDoEqS9AFGWAMmB/iaxo=; b=AnneY8J5Ij/eXReb0AZEkOighODZXb6E/oec84IDZBu030vCzS6jDzcXRVYzcNlZWH hHAx+qqPqIwF10VuWlCDi+CKOMLhkivB2Y2ozVEjnhtZ37Lav3xEKT1qLzRuUQqS1QQY WXIamIR0GmUDq19rJGx+KmtLqBuzUJPG/zSbGH9Cw4qR+uoE/o1JB8VQhooVfRY2RTcj YC4iRjqKhoNX6qNrD/hGI2xJ95Bjkv3gPsWWafdoV2wrVFVW5gLSrPLevOo0P49b8Ka+ L5vUI2KRdZxWGRshtmMfsdchOOQGaM0p6qeDKHU673I6h6B/w9q2S5JPCeO+1MK6mKI6 hhoQ== X-Gm-Message-State: AJcUukcnYAB5KlMl44wW3AHRu6hlxruhVetSf+CXvwftmj7OJWPHrqJV 1Nq0nA7Cl2mLp9fOcKnuknnqvmbFhKinag== X-Google-Smtp-Source: ALg8bN59TNW0uT4SeX1mxJU77+DrFTfOEpohJ+Iv1QkI5Tqx+J3ljy3qqBFMiEsxv3MpP9LiVpPxOg== X-Received: by 2002:adf:8544:: with SMTP id 62mr21758984wrh.1.1547910627141; Sat, 19 Jan 2019 07:10:27 -0800 (PST) Received: from brauner.io ([196.167.47.106]) by smtp.gmail.com with ESMTPSA id u10sm71183590wrr.33.2019.01.19.07.10.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 19 Jan 2019 07:10:26 -0800 (PST) Date: Sat, 19 Jan 2019 16:10:22 +0100 From: Christian Brauner To: Al Viro 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: <20190119151020.w5tukab57sk4vxss@brauner.io> References: <20190118145344.11532-1-christian@brauner.io> <20190118145344.11532-3-christian@brauner.io> <20190118225552.GZ2217@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190118225552.GZ2217@ZenIV.linux.org.uk> User-Agent: NeoMutt/20180716 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 10:55:52PM +0000, Al Viro wrote: > 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? BINDERFS_I() is called in is_binderfs_device() which is called in binder.c: static int binder_open(struct inode *nodp, struct file *filp) { /* binderfs stashes devices in i_private */ if (is_binderfs_device(nodp)) binder_dev = nodp->i_private; else binder_dev = container_of(filp->private_data, struct binder_device, miscdev); and it was just easier to have it take an inode as arg since that's what binder_open() makes easily available. Just kept it this way for is_binderfs_control_device() too but will switch the latter over now. > > 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... Hm yes, I think I'll just do: static inline bool is_binderfs_control_device(const struct dentry *dentry) { struct binderfs_info *info = dentry->d_sb->s_fs_info; return info->control_dentry == dentry; } and pick up what you scratched below. > > 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...