linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] statx: reject unknown flags when using NULL path
@ 2017-03-11  6:58 Eric Biggers
  2017-03-20 17:11 ` Eric Biggers
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Biggers @ 2017-03-11  6:58 UTC (permalink / raw)
  To: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA
  Cc: Alexander Viro, David Howells,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, Christoph Hellwig,
	Darrick J . Wong, Linux API, linux-xfs-u79uwXL29TY76Z2rM5mHXA,
	Eric Biggers

From: Eric Biggers <ebiggers-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>

The statx() system call currently accepts unknown flags when called with
a NULL path to operate on a file descriptor.  Left unchanged, this could
make it hard to introduce new query flags in the future, since
applications may not be able to tell whether a given flag is supported.

Fix this by failing the system call with EINVAL if any flags other than
KSTAT_QUERY_FLAGS are specified in combination with a NULL path.

Arguably, we could still permit known lookup-related flags such as
AT_SYMLINK_NOFOLLOW.  However, that would be inconsistent with how
sys_utimensat() behaves when passed a NULL path, which seems to be the
closest precedent.  And given that the NULL path case is (I believe)
mainly intended to be used to implement a wrapper function like fstatx()
that doesn't have a path argument, I think rejecting lookup-related
flags too is probably the best choice.

Signed-off-by: Eric Biggers <ebiggers-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
---
 fs/stat.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/stat.c b/fs/stat.c
index fa0be59340cc..df484a60846d 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -130,9 +130,13 @@ EXPORT_SYMBOL(vfs_getattr);
 int vfs_statx_fd(unsigned int fd, struct kstat *stat,
 		 u32 request_mask, unsigned int query_flags)
 {
-	struct fd f = fdget_raw(fd);
+	struct fd f;
 	int error = -EBADF;
 
+	if (query_flags & ~KSTAT_QUERY_FLAGS)
+		return -EINVAL;
+
+	f = fdget_raw(fd);
 	if (f.file) {
 		error = vfs_getattr(&f.file->f_path, stat,
 				    request_mask, query_flags);
-- 
2.12.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
  2017-03-11  6:58 [PATCH] statx: reject unknown flags when using NULL path Eric Biggers
@ 2017-03-20 17:11 ` Eric Biggers
  2017-03-20 17:44   ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Eric Biggers @ 2017-03-20 17:11 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Alexander Viro, David Howells, mtk.manpages, Christoph Hellwig,
	Darrick J . Wong, Linux API, linux-xfs, Eric Biggers

On Fri, Mar 10, 2017 at 10:58:23PM -0800, Eric Biggers wrote:
> From: Eric Biggers <ebiggers@google.com>
> 
> The statx() system call currently accepts unknown flags when called with
> a NULL path to operate on a file descriptor.  Left unchanged, this could
> make it hard to introduce new query flags in the future, since
> applications may not be able to tell whether a given flag is supported.
> 
> Fix this by failing the system call with EINVAL if any flags other than
> KSTAT_QUERY_FLAGS are specified in combination with a NULL path.
> 

Does anyone have comments on this patch?

I really think we need to get this in before v4.11 is released, since it deals
with the API.

- Eric

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
  2017-03-20 17:11 ` Eric Biggers
@ 2017-03-20 17:44   ` Christoph Hellwig
  2017-03-31 15:39     ` Christoph Hellwig
  0 siblings, 1 reply; 8+ messages in thread
From: Christoph Hellwig @ 2017-03-20 17:44 UTC (permalink / raw)
  To: Eric Biggers
  Cc: linux-fsdevel, Alexander Viro, David Howells, mtk.manpages,
	Christoph Hellwig, Darrick J . Wong, Linux API, linux-xfs,
	Eric Biggers

On Mon, Mar 20, 2017 at 10:11:42AM -0700, Eric Biggers wrote:
> On Fri, Mar 10, 2017 at 10:58:23PM -0800, Eric Biggers wrote:
> > From: Eric Biggers <ebiggers@google.com>
> > 
> > The statx() system call currently accepts unknown flags when called with
> > a NULL path to operate on a file descriptor.  Left unchanged, this could
> > make it hard to introduce new query flags in the future, since
> > applications may not be able to tell whether a given flag is supported.
> > 
> > Fix this by failing the system call with EINVAL if any flags other than
> > KSTAT_QUERY_FLAGS are specified in combination with a NULL path.
> > 
> 
> Does anyone have comments on this patch?

Looks good to me.

> I really think we need to get this in before v4.11 is released, since it deals
> with the API.

Yes.  And we really need test for all of this.  Or just revert the
patches.  Shipping with untested syscalls is just a desaster.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
  2017-03-20 17:44   ` Christoph Hellwig
@ 2017-03-31 15:39     ` Christoph Hellwig
  2017-03-31 15:43       ` Al Viro
       [not found]       ` <20170331154315.GB29622-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Christoph Hellwig @ 2017-03-31 15:39 UTC (permalink / raw)
  To: Eric Biggers
  Cc: linux-fsdevel, Alexander Viro, David Howells, mtk.manpages,
	Christoph Hellwig, Darrick J . Wong, Linux API, linux-xfs,
	Eric Biggers

Al, Linus:

can we get this in please?  It would be sad to grow another syscall
with an unchecked flags argument..

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
  2017-03-31 15:39     ` Christoph Hellwig
@ 2017-03-31 15:43       ` Al Viro
       [not found]       ` <20170331154315.GB29622-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Al Viro @ 2017-03-31 15:43 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Eric Biggers, linux-fsdevel, David Howells, mtk.manpages,
	Darrick J . Wong, Linux API, linux-xfs, Eric Biggers

On Fri, Mar 31, 2017 at 08:39:52AM -0700, Christoph Hellwig wrote:
> Al, Linus:
> 
> can we get this in please?  It would be sad to grow another syscall
> with an unchecked flags argument..

Applied, will be in tonight pull request...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
       [not found]       ` <20170331154315.GB29622-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
@ 2017-03-31 15:51         ` David Howells
       [not found]           ` <21301.1490975484-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
       [not found]           ` <20170331160224.GA27791-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: David Howells @ 2017-03-31 15:51 UTC (permalink / raw)
  To: Al Viro
  Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA, Christoph Hellwig, Eric Biggers,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, Darrick J . Wong, Linux API,
	linux-xfs-u79uwXL29TY76Z2rM5mHXA, Eric Biggers

Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org> wrote:

> > can we get this in please?  It would be sad to grow another syscall
> > with an unchecked flags argument..
> 
> Applied, will be in tonight pull request...

I'm not convinced that this is right.  I'm more inclined to let any flag be
passed that is available to statx() with a filename and just mask off the
bits before handing them on.

David

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
       [not found]           ` <21301.1490975484-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
@ 2017-03-31 16:02             ` Christoph Hellwig
  0 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2017-03-31 16:02 UTC (permalink / raw)
  To: David Howells
  Cc: Al Viro, Christoph Hellwig, Eric Biggers,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, Darrick J . Wong, Linux API,
	linux-xfs-u79uwXL29TY76Z2rM5mHXA, Eric Biggers

On Fri, Mar 31, 2017 at 04:51:24PM +0100, David Howells wrote:
> I'm not convinced that this is right.  I'm more inclined to let any flag be
> passed that is available to statx() with a filename and just mask off the
> bits before handing them on.

And what would these flags actually do?  Currently we verify that
the allowed flags are passed for the case where we have a filename.

We need to do the same for the non-filename case, and we should
also check that we don't pass flags that don't make sense for this case.

Eric's patch is doing exactly that.

The only thing he could do even better is to add a testcase to xfstests
to verify this :)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] statx: reject unknown flags when using NULL path
       [not found]           ` <20170331160224.GA27791-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
@ 2017-03-31 16:58             ` David Howells
  0 siblings, 0 replies; 8+ messages in thread
From: David Howells @ 2017-03-31 16:58 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: dhowells-H+wXaHxf7aLQT0dZR+AlfA, Al Viro, Eric Biggers,
	linux-fsdevel-u79uwXL29TY76Z2rM5mHXA,
	mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w, Darrick J . Wong, Linux API,
	linux-xfs-u79uwXL29TY76Z2rM5mHXA, Eric Biggers

Christoph Hellwig <hch-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org> wrote:

> The only thing he could do even better is to add a testcase to xfstests
> to verify this :)

I will be pushing this sort of thing to LTP.

David

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-03-31 16:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-11  6:58 [PATCH] statx: reject unknown flags when using NULL path Eric Biggers
2017-03-20 17:11 ` Eric Biggers
2017-03-20 17:44   ` Christoph Hellwig
2017-03-31 15:39     ` Christoph Hellwig
2017-03-31 15:43       ` Al Viro
     [not found]       ` <20170331154315.GB29622-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2017-03-31 15:51         ` David Howells
     [not found]           ` <21301.1490975484-S6HVgzuS8uM4Awkfq6JHfwNdhmdF6hFW@public.gmane.org>
2017-03-31 16:02             ` Christoph Hellwig
     [not found]           ` <20170331160224.GA27791-wEGCiKHe2LqWVfeAwA7xHQ@public.gmane.org>
2017-03-31 16:58             ` David Howells

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).