Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1614191

[PATCH 2/8] statx: reject unknown flags when using NULL path

From David Howells <dhowells@redhat.com>
Newsgroups linux.kernel
Subject [PATCH 2/8] statx: reject unknown flags when using NULL path
Date 2017-03-31 19:40 +0200
Message-ID <tr8GK-7Fk-21@gated-at.bofh.it> (permalink)
References <tr8GJ-7Fk-3@gated-at.bofh.it>
Organization Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903

Show all headers | View raw


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.

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@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
---

 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);

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/8] Documentation/filesystems: fix documentation for  ->getattr() David Howells <dhowells@redhat.com> - 2017-03-31 19:40 +0200
  [PATCH 8/8] statx: Include a mask for stx_attributes in struct statx David Howells <dhowells@redhat.com> - 2017-03-31 19:40 +0200
    Re: [PATCH 8/8] statx: Include a mask for stx_attributes in struct  statx "Darrick J. Wong" <darrick.wong@oracle.com> - 2017-03-31 19:50 +0200
    Re: [PATCH 8/8] statx: Include a mask for stx_attributes in struct  statx Christoph Hellwig <hch@infradead.org> - 2017-04-04 09:20 +0200
  [PATCH 7/8] statx: Reserve the top bit of the mask for future  struct expansion David Howells <dhowells@redhat.com> - 2017-03-31 19:40 +0200
  [PATCH 5/8] ext4: Add statx support David Howells <dhowells@redhat.com> - 2017-03-31 19:40 +0200
  [PATCH 2/8] statx: reject unknown flags when using NULL path David Howells <dhowells@redhat.com> - 2017-03-31 19:40 +0200
  [PATCH 4/8] statx: optimize copy of struct statx to userspace David Howells <dhowells@redhat.com> - 2017-03-31 19:40 +0200

csiph-web