mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Christian Brauner <brauner@kernel.org>
Cc: dhowells@redhat.com, Al Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <christian@brauner.io>,
	Marc Dionne <marc.dionne@auristor.com>,
	Jeffrey Altman <jaltman@auristor.com>,
	Steve French <sfrench@samba.org>,
	linux-afs@lists.infradead.org, openafs-devel@openafs.org,
	linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Etienne Champetier <champetier.etienne@gmail.com>,
	Chet Ramey <chet.ramey@case.edu>,
	Cheyenne Wills <cwills@sinenomine.net>,
	Mimi Zohar <zohar@linux.ibm.com>,
	linux-integrity@vger.kernel.org
Subject: Re: [PATCH 1/2] vfs: Allow filesystems with foreign owner IDs to override UID checks
Date: Tue, 21 Oct 2025 14:20:21 +0100	[thread overview]
Message-ID: <1523597.1761052821@warthog.procyon.org.uk> (raw)
In-Reply-To: <20251021-agieren-spruch-65c107748c09@brauner>

Christian Brauner <brauner@kernel.org> wrote:

> > +	if (unlikely(inode->i_op->have_same_owner)) {
> 
> Same, as above: similar to IOP_FASTPERM this should use a flag to avoid pointer derefs.

Can we do these IOP_* flags better?  Surely we can determine at the point the
inode has its ->i_op assigned that these things are provided?  This optimises
the case where they don't exist at the expense of the case where they do (we
still have to check the pointer every time).

> > +	if (unlikely(inode->i_op->have_same_owner)) {
> 
> Same, as above: similar to IOP_FASTPERM this should use a flag to avoid pointer derefs.
> 
> Really, we should very properly bias this towards the common case where
> the filesystem will not have a custom ownership comparison callback at all.

Hence the unlikely().

> > +		struct dentry *parent;
> > +		struct inode *dir;
> > +		int ret;
> > +
> > +		if (inode != nd->inode) {
> > +			dir = nd->inode;
> > +			ret = inode->i_op->have_same_owner(idmap, inode, dir);
> > +		} else if (nd->flags & LOOKUP_RCU) {
> > +			parent = READ_ONCE(nd->path.dentry);
> > +			dir = READ_ONCE(parent->d_inode);
> > +			if (!dir)
> > +				return -ECHILD;
> > +			ret = inode->i_op->have_same_owner(idmap, inode, dir);
> > +		} else {
> > +			parent = dget_parent(nd->path.dentry);
> > +			dir = parent->d_inode;
> > +			ret = inode->i_op->have_same_owner(idmap, inode, dir);
> > +			dput(parent);
> > +		}
> > +		return ret;
> > +	}
> 
> This about as ugly as it can get and costly...

I can break this out into a helper, but it should make no difference to the
actual code generated.

> > +	ret = vfs_inode_and_dir_have_same_owner(idmap, inode, nd);
> > +	if (ret <= 0)
> > +		return ret;
> 
> Ok, so while that doesn't exactly surface the error it's still weird.
> Please make that consistent. Either have those two new helper functions
> return negative error codes and zero on success or have it be a proper
> boolean instead so there's no possible confusion. This is just begging
> for someone to do if (ret) return ret and bubble up that positive return
> value.

The problem is that you have three available returns: Yes they do, no they
don't and some arbitrary error was encountered.  The first two are not error
cases, and potentially any error you pick to represent, say, "no" could also
be returned by the underlying filesystem.

David


  parent reply	other threads:[~2025-10-21 13:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 13:35 [PATCH 0/2] vfs, afs, bash: Fix miscomparison of foreign user IDs in the VFS David Howells
2025-10-14 13:35 ` [PATCH 1/2] vfs: Allow filesystems with foreign owner IDs to override UID checks David Howells
2025-10-21 12:38   ` Christian Brauner
2025-10-21 13:20   ` David Howells [this message]
2025-10-29 12:39     ` Christian Brauner
2025-10-14 13:35 ` [PATCH 2/2] afs, bash: Fix open(O_CREAT) on an extant AFS file in a sticky dir David Howells
2025-10-14 18:27 ` [PATCH 0/2] vfs, afs, bash: Fix miscomparison of foreign user IDs in the VFS Steve French
  -- strict thread matches above, loose matches on Subject: below --
2025-09-03 12:01 David Howells
2025-09-03 12:01 ` [PATCH 1/2] vfs: Allow filesystems with foreign owner IDs to override UID checks David Howells
2025-07-23 15:26 [PATCH 0/2] vfs, afs, bash: Fix miscomparison of foreign user IDs in the VFS David Howells
2025-07-23 15:26 ` [PATCH 1/2] vfs: Allow filesystems with foreign owner IDs to override UID checks David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1523597.1761052821@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=brauner@kernel.org \
    --cc=champetier.etienne@gmail.com \
    --cc=chet.ramey@case.edu \
    --cc=christian@brauner.io \
    --cc=cwills@sinenomine.net \
    --cc=jaltman@auristor.com \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-integrity@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=openafs-devel@openafs.org \
    --cc=sfrench@samba.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=zohar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®