From patchwork Fri Feb 17 17:24:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 9580429 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 621F76042F for ; Fri, 17 Feb 2017 17:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5276728763 for ; Fri, 17 Feb 2017 17:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4579E2876B; Fri, 17 Feb 2017 17:25:02 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 ADE6A28773 for ; Fri, 17 Feb 2017 17:25:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934574AbdBQRY7 (ORCPT ); Fri, 17 Feb 2017 12:24:59 -0500 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:44736 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934203AbdBQRY6 (ORCPT ); Fri, 17 Feb 2017 12:24:58 -0500 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 5B3FB8EE34B; Fri, 17 Feb 2017 09:24:52 -0800 (PST) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id asHthhAGeJHx; Fri, 17 Feb 2017 09:24:47 -0800 (PST) Received: from [153.66.254.194] (50-47-107-254.evrt.wa.frontiernet.net [50.47.107.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id D54B58EE191; Fri, 17 Feb 2017 09:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=hansenpartnership.com; s=20151216; t=1487352286; bh=tj257q9EofDrlE/GX+Bh61b0sh1LVjTUMRlZY+LQtfg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=T22fSpnXIR6vYk2CLdCkvAlt75wzgHi8AP4kFZi6E3ufpnKTlk3sd1k/R4zk4FlnH a8HdkmqNN3XNbb76YtB3J5LmtIU/yrswhlbr34cYAryBw6pewQRARHK+eQE1oA0TU1 V1dYZM3A5Sl7EF7QHhUdK26lhLvQsgfS8uWfH3Kk= Message-ID: <1487352280.4351.19.camel@HansenPartnership.com> Subject: Re: [RFC 1/1] shiftfs: uid/gid shifting bind mount From: James Bottomley To: Al Viro Cc: Djalal Harouni , Chris Mason , Theodore Tso , Josh Triplett , "Eric W. Biederman" , Andy Lutomirski , Seth Forshee , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, Dongsu Park , David Herrmann , Miklos Szeredi , Alban Crequy , "Serge E. Hallyn" , Phil Estes Date: Fri, 17 Feb 2017 09:24:40 -0800 In-Reply-To: <20170217022918.GC29622@ZenIV.linux.org.uk> References: <1486235880.2484.17.camel@HansenPartnership.com> <1486235972.2484.19.camel@HansenPartnership.com> <20170217022918.GC29622@ZenIV.linux.org.uk> X-Mailer: Evolution 3.16.5 Mime-Version: 1.0 Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP On Fri, 2017-02-17 at 02:29 +0000, Al Viro wrote: > On Sat, Feb 04, 2017 at 11:19:32AM -0800, James Bottomley wrote: > > > +static const struct dentry_operations shiftfs_dentry_ops = { > > + .d_release = shiftfs_d_release, > > + .d_real = shiftfs_d_real, > > +}; > > In other words, those dentries are *never* revalidated. Nevermind > that underlying fs might be mounted elsewhere and be actively > modified under you. > > > +static struct dentry *shiftfs_lookup(struct inode *dir, struct > > dentry *dentry, > > + unsigned int flags) > > +{ > > + struct dentry *real = dir->i_private, *new; > > + struct inode *reali = real->d_inode, *newi; > > + const struct cred *oldcred, *newcred; > > + > > + inode_lock(reali); > > + oldcred = shiftfs_new_creds(&newcred, dentry->d_sb); > > + new = lookup_one_len(dentry->d_name.name, real, dentry > > ->d_name.len); > > + shiftfs_old_creds(oldcred, &newcred); > > + inode_unlock(reali); > > + > > + if (IS_ERR(new)) > > + return new; > > + > > + dentry->d_fsdata = new; > > + > > + if (!new->d_inode) > > + return NULL; > > What happens when somebody comes along and creates the damn thing on > the underlying fs? _Not_ via your code, that is - using the > underlying fs mounted elsewhere. Point taken. This, I think fixes the dcache revalidation issue. James --- -- To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/shiftfs.c b/fs/shiftfs.c index a4a1f98..1e71efe 100644 --- a/fs/shiftfs.c +++ b/fs/shiftfs.c @@ -118,9 +118,43 @@ static struct dentry *shiftfs_d_real(struct dentry *dentry, return real; } +static int shiftfs_d_weak_revalidate(struct dentry *dentry, unsigned int flags) +{ + struct dentry *real = dentry->d_fsdata; + + if (d_unhashed(real)) + return 0; + + if (!(real->d_flags & DCACHE_OP_WEAK_REVALIDATE)) + return 1; + + return real->d_op->d_weak_revalidate(real, flags); +} + +static int shiftfs_d_revalidate(struct dentry *dentry, unsigned int flags) +{ + struct dentry *real = dentry->d_fsdata; + int ret; + + if (d_unhashed(real)) + return 0; + + if (!(real->d_flags & DCACHE_OP_REVALIDATE)) + return 1; + + ret = real->d_op->d_revalidate(real, flags); + + if (ret == 0 && !(flags & LOOKUP_RCU)) + d_invalidate(real); + + return ret; +} + static const struct dentry_operations shiftfs_dentry_ops = { .d_release = shiftfs_d_release, .d_real = shiftfs_d_real, + .d_revalidate = shiftfs_d_revalidate, + .d_weak_revalidate = shiftfs_d_weak_revalidate, }; static int shiftfs_readlink(struct dentry *dentry, char __user *data, @@ -431,9 +465,7 @@ static struct dentry *shiftfs_lookup(struct inode *dir, struct dentry *dentry, return ERR_PTR(-ENOMEM); } - d_splice_alias(newi, dentry); - - return NULL; + return d_splice_alias(newi, dentry); } static int shiftfs_permission(struct inode *inode, int mask)