Skip to content

Commit c6d6447

Browse files
committed
Merge tag 'pull-statx' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull statx updates from Al Viro: "Sanitize struct filename and lookup flags handling in statx and friends" * tag 'pull-statx' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: libfs: kill empty_dir_getattr() fs: Simplify getattr interface function checking AT_GETATTR_NOSEC flag fs/stat.c: switch to CLASS(fd_raw) kill getname_statx_lookup_flags() io_statx_prep(): use getname_uflags()
2 parents 9fb2cfa + 6c056ae commit c6d6447

File tree

8 files changed

+15
-58
lines changed

8 files changed

+15
-58
lines changed

fs/ecryptfs/inode.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,14 +1008,6 @@ static int ecryptfs_getattr_link(struct mnt_idmap *idmap,
10081008
return rc;
10091009
}
10101010

1011-
static int ecryptfs_do_getattr(const struct path *path, struct kstat *stat,
1012-
u32 request_mask, unsigned int flags)
1013-
{
1014-
if (flags & AT_GETATTR_NOSEC)
1015-
return vfs_getattr_nosec(path, stat, request_mask, flags);
1016-
return vfs_getattr(path, stat, request_mask, flags);
1017-
}
1018-
10191011
static int ecryptfs_getattr(struct mnt_idmap *idmap,
10201012
const struct path *path, struct kstat *stat,
10211013
u32 request_mask, unsigned int flags)
@@ -1024,8 +1016,8 @@ static int ecryptfs_getattr(struct mnt_idmap *idmap,
10241016
struct kstat lower_stat;
10251017
int rc;
10261018

1027-
rc = ecryptfs_do_getattr(ecryptfs_dentry_to_lower_path(dentry),
1028-
&lower_stat, request_mask, flags);
1019+
rc = vfs_getattr_nosec(ecryptfs_dentry_to_lower_path(dentry),
1020+
&lower_stat, request_mask, flags);
10291021
if (!rc) {
10301022
fsstack_copy_attr_all(d_inode(dentry),
10311023
ecryptfs_inode_to_lower(d_inode(dentry)));

fs/internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ int open_namespace(struct ns_common *ns);
246246
* fs/stat.c:
247247
*/
248248

249-
int getname_statx_lookup_flags(int flags);
250249
int do_statx(int dfd, struct filename *filename, unsigned int flags,
251250
unsigned int mask, struct statx __user *buffer);
252251
int do_statx_fd(int fd, unsigned int flags, unsigned int mask,

fs/libfs.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,15 +1715,6 @@ static struct dentry *empty_dir_lookup(struct inode *dir, struct dentry *dentry,
17151715
return ERR_PTR(-ENOENT);
17161716
}
17171717

1718-
static int empty_dir_getattr(struct mnt_idmap *idmap,
1719-
const struct path *path, struct kstat *stat,
1720-
u32 request_mask, unsigned int query_flags)
1721-
{
1722-
struct inode *inode = d_inode(path->dentry);
1723-
generic_fillattr(&nop_mnt_idmap, request_mask, inode, stat);
1724-
return 0;
1725-
}
1726-
17271718
static int empty_dir_setattr(struct mnt_idmap *idmap,
17281719
struct dentry *dentry, struct iattr *attr)
17291720
{
@@ -1737,9 +1728,7 @@ static ssize_t empty_dir_listxattr(struct dentry *dentry, char *list, size_t siz
17371728

17381729
static const struct inode_operations empty_dir_inode_operations = {
17391730
.lookup = empty_dir_lookup,
1740-
.permission = generic_permission,
17411731
.setattr = empty_dir_setattr,
1742-
.getattr = empty_dir_getattr,
17431732
.listxattr = empty_dir_listxattr,
17441733
};
17451734

fs/overlayfs/inode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
170170

171171
type = ovl_path_real(dentry, &realpath);
172172
old_cred = ovl_override_creds(dentry->d_sb);
173-
err = ovl_do_getattr(&realpath, stat, request_mask, flags);
173+
err = vfs_getattr_nosec(&realpath, stat, request_mask, flags);
174174
if (err)
175175
goto out;
176176

@@ -195,8 +195,8 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
195195
(!is_dir ? STATX_NLINK : 0);
196196

197197
ovl_path_lower(dentry, &realpath);
198-
err = ovl_do_getattr(&realpath, &lowerstat, lowermask,
199-
flags);
198+
err = vfs_getattr_nosec(&realpath, &lowerstat, lowermask,
199+
flags);
200200
if (err)
201201
goto out;
202202

@@ -248,8 +248,8 @@ int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
248248

249249
ovl_path_lowerdata(dentry, &realpath);
250250
if (realpath.dentry) {
251-
err = ovl_do_getattr(&realpath, &lowerdatastat,
252-
lowermask, flags);
251+
err = vfs_getattr_nosec(&realpath, &lowerdatastat,
252+
lowermask, flags);
253253
if (err)
254254
goto out;
255255
} else {

fs/overlayfs/overlayfs.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,6 @@ static inline bool ovl_open_flags_need_copy_up(int flags)
412412
return ((OPEN_FMODE(flags) & FMODE_WRITE) || (flags & O_TRUNC));
413413
}
414414

415-
static inline int ovl_do_getattr(const struct path *path, struct kstat *stat,
416-
u32 request_mask, unsigned int flags)
417-
{
418-
if (flags & AT_GETATTR_NOSEC)
419-
return vfs_getattr_nosec(path, stat, request_mask, flags);
420-
return vfs_getattr(path, stat, request_mask, flags);
421-
}
422-
423415
/* util.c */
424416
int ovl_get_write_access(struct dentry *dentry);
425417
void ovl_put_write_access(struct dentry *dentry);

fs/stat.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
207207
if (inode->i_op->getattr)
208208
return inode->i_op->getattr(idmap, path, stat,
209209
request_mask,
210-
query_flags | AT_GETATTR_NOSEC);
210+
query_flags);
211211

212212
generic_fillattr(idmap, request_mask, inode, stat);
213213
return 0;
@@ -240,9 +240,6 @@ int vfs_getattr(const struct path *path, struct kstat *stat,
240240
{
241241
int retval;
242242

243-
if (WARN_ON_ONCE(query_flags & AT_GETATTR_NOSEC))
244-
return -EPERM;
245-
246243
retval = security_inode_getattr(path);
247244
if (retval)
248245
return retval;
@@ -262,27 +259,20 @@ EXPORT_SYMBOL(vfs_getattr);
262259
*/
263260
int vfs_fstat(int fd, struct kstat *stat)
264261
{
265-
struct fd f;
266-
int error;
267-
268-
f = fdget_raw(fd);
269-
if (!fd_file(f))
262+
CLASS(fd_raw, f)(fd);
263+
if (fd_empty(f))
270264
return -EBADF;
271-
error = vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0);
272-
fdput(f);
273-
return error;
265+
return vfs_getattr(&fd_file(f)->f_path, stat, STATX_BASIC_STATS, 0);
274266
}
275267

276-
int getname_statx_lookup_flags(int flags)
268+
static int statx_lookup_flags(int flags)
277269
{
278270
int lookup_flags = 0;
279271

280272
if (!(flags & AT_SYMLINK_NOFOLLOW))
281273
lookup_flags |= LOOKUP_FOLLOW;
282274
if (!(flags & AT_NO_AUTOMOUNT))
283275
lookup_flags |= LOOKUP_AUTOMOUNT;
284-
if (flags & AT_EMPTY_PATH)
285-
lookup_flags |= LOOKUP_EMPTY;
286276

287277
return lookup_flags;
288278
}
@@ -319,7 +309,7 @@ static int vfs_statx_fd(int fd, int flags, struct kstat *stat,
319309
u32 request_mask)
320310
{
321311
CLASS(fd_raw, f)(fd);
322-
if (!fd_file(f))
312+
if (fd_empty(f))
323313
return -EBADF;
324314
return vfs_statx_path(&fd_file(f)->f_path, flags, stat, request_mask);
325315
}
@@ -343,7 +333,7 @@ static int vfs_statx(int dfd, struct filename *filename, int flags,
343333
struct kstat *stat, u32 request_mask)
344334
{
345335
struct path path;
346-
unsigned int lookup_flags = getname_statx_lookup_flags(flags);
336+
unsigned int lookup_flags = statx_lookup_flags(flags);
347337
int error;
348338

349339
if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_EMPTY_PATH |

include/uapi/linux/fcntl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,4 @@
154154
usable with open_by_handle_at(2). */
155155
#define AT_HANDLE_MNT_ID_UNIQUE 0x001 /* Return the u64 unique mount ID. */
156156

157-
#if defined(__KERNEL__)
158-
#define AT_GETATTR_NOSEC 0x80000000
159-
#endif
160-
161157
#endif /* _UAPI_LINUX_FCNTL_H */

io_uring/statx.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
3636
sx->buffer = u64_to_user_ptr(READ_ONCE(sqe->addr2));
3737
sx->flags = READ_ONCE(sqe->statx_flags);
3838

39-
sx->filename = getname_flags(path,
40-
getname_statx_lookup_flags(sx->flags));
39+
sx->filename = getname_uflags(path, sx->flags);
4140

4241
if (IS_ERR(sx->filename)) {
4342
int ret = PTR_ERR(sx->filename);

0 commit comments

Comments
 (0)