Skip to content

Commit 1e2f82d

Browse files
dhowellstorvalds
authored andcommitted
statx: Kill fd-with-NULL-path support in favour of AT_EMPTY_PATH
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]>
1 parent fc08b19 commit 1e2f82d

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

fs/stat.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -547,13 +547,13 @@ cp_statx(const struct kstat *stat, struct statx __user *buffer)
547547
/**
548548
* sys_statx - System call to get enhanced stats
549549
* @dfd: Base directory to pathwalk from *or* fd to stat.
550-
* @filename: File to stat *or* NULL.
550+
* @filename: File to stat or "" with AT_EMPTY_PATH
551551
* @flags: AT_* flags to control pathwalk.
552552
* @mask: Parts of statx struct actually required.
553553
* @buffer: Result buffer.
554554
*
555-
* Note that if filename is NULL, then it does the equivalent of fstat() using
556-
* dfd to indicate the file of interest.
555+
* Note that fstat() can be emulated by setting dfd to the fd of interest,
556+
* supplying "" as the filename and setting AT_EMPTY_PATH in the flags.
557557
*/
558558
SYSCALL_DEFINE5(statx,
559559
int, dfd, const char __user *, filename, unsigned, flags,
@@ -567,11 +567,10 @@ SYSCALL_DEFINE5(statx,
567567
return -EINVAL;
568568
if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
569569
return -EINVAL;
570+
if (!filename)
571+
return -EINVAL;
570572

571-
if (filename)
572-
error = vfs_statx(dfd, filename, flags, &stat, mask);
573-
else
574-
error = vfs_statx_fd(dfd, &stat, mask, flags);
573+
error = vfs_statx(dfd, filename, flags, &stat, mask);
575574
if (error)
576575
return error;
577576

0 commit comments

Comments
 (0)