Skip to content

Commit

Permalink
statx: Kill fd-with-NULL-path support in favour of AT_EMPTY_PATH
Browse files Browse the repository at this point in the history
With the new statx() syscall, the following both allow the attributes of
the file attached to a file descriptor to be retrieved:

	statx(dfd, NULL, 0, ...);

and:

	statx(dfd, "", AT_EMPTY_PATH, ...);

Change the code to reject the first option, though this means copying
the path and engaging pathwalk for the fstat() equivalent.  dfd can be a
non-directory provided path is "".

[ The timing of this isn't wonderful, but applying this now before we
  have statx() in any released kernel, before anybody starts using the
  NULL special case.    - Linus ]

Fixes: a528d35 ("statx: Add a system call to make enhanced file info available")
Reported-by: Michael Kerrisk <[email protected]>
Signed-off-by: David Howells <[email protected]>
cc: Eric Sandeen <[email protected]>
cc: [email protected]
cc: [email protected]
cc: [email protected]
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
dhowells authored and torvalds committed Apr 26, 2017
1 parent fc08b19 commit 1e2f82d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions fs/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,13 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
/**
* sys_statx - System call to get enhanced stats
* @dfd: Base directory to pathwalk from *or* fd to stat.
* @filename: File to stat *or* NULL.
* @filename: File to stat or "" with AT_EMPTY_PATH
* @flags: AT_* flags to control pathwalk.
* @mask: Parts of statx struct actually required.
* @buffer: Result buffer.
*
* Note that if filename is NULL, then it does the equivalent of fstat() using
* dfd to indicate the file of interest.
* Note that fstat() can be emulated by setting dfd to the fd of interest,
* supplying "" as the filename and setting AT_EMPTY_PATH in the flags.
*/
SYSCALL_DEFINE5(statx,
int, dfd, const char __user *, filename, unsigned, flags,
Expand All @@ -567,11 +567,10 @@ SYSCALL_DEFINE5(statx,
return -EINVAL;
if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
return -EINVAL;
if (!filename)
return -EINVAL;

if (filename)
error = vfs_statx(dfd, filename, flags, &stat, mask);
else
error = vfs_statx_fd(dfd, &stat, mask, flags);
error = vfs_statx(dfd, filename, flags, &stat, mask);
if (error)
return error;

Expand Down

0 comments on commit 1e2f82d

Please sign in to comment.