Skip to content

Commit 95f567f

Browse files
stefanbergerAl Viro
authored andcommitted
fs: Simplify getattr interface function checking AT_GETATTR_NOSEC flag
Commit 8a924db ("fs: Pass AT_GETATTR_NOSEC flag to getattr interface function")' introduced the AT_GETATTR_NOSEC flag to ensure that the call paths only call vfs_getattr_nosec if it is set instead of vfs_getattr. Now, simplify the getattr interface functions of filesystems where the flag AT_GETATTR_NOSEC is checked. There is only a single caller of inode_operations getattr function and it is located in fs/stat.c in vfs_getattr_nosec. The caller there is the only one from which the AT_GETATTR_NOSEC flag is passed from. Two filesystems are checking this flag in .getattr and the flag is always passed to them unconditionally from only vfs_getattr_nosec: - ecryptfs: Simplify by always calling vfs_getattr_nosec in ecryptfs_getattr. From there the flag is passed to no other function and this function is not called otherwise. - overlayfs: Simplify by always calling vfs_getattr_nosec in ovl_getattr. From there the flag is passed to no other function and this function is not called otherwise. The query_flags in vfs_getattr_nosec will mask-out AT_GETATTR_NOSEC from any caller using AT_STATX_SYNC_TYPE as mask so that the flag is not important inside this function. Also, since no filesystem is checking the flag anymore, remove the flag entirely now, including the BUG_ON check that never triggered. The net change of the changes here combined with the original commit is that ecryptfs and overlayfs do not call vfs_getattr but only vfs_getattr_nosec. Fixes: 8a924db ("fs: Pass AT_GETATTR_NOSEC flag to getattr interface function") Reported-by: Al Viro <[email protected]> Closes: https://lore.kernel.org/linux-fsdevel/20241101011724.GN1350452@ZenIV/T/#u Cc: Tyler Hicks <[email protected]> Cc: [email protected] Cc: Miklos Szeredi <[email protected]> Cc: Amir Goldstein <[email protected]> Cc: [email protected] Cc: Christian Brauner <[email protected]> Cc: [email protected] Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Stefan Berger <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 0dd4fb7 commit 95f567f

File tree

5 files changed

+8
-31
lines changed

5 files changed

+8
-31
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/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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ int vfs_getattr_nosec(const struct path *path, struct kstat *stat,
165165
if (inode->i_op->getattr)
166166
return inode->i_op->getattr(idmap, path, stat,
167167
request_mask,
168-
query_flags | AT_GETATTR_NOSEC);
168+
query_flags);
169169

170170
generic_fillattr(idmap, request_mask, inode, stat);
171171
return 0;
@@ -198,9 +198,6 @@ int vfs_getattr(const struct path *path, struct kstat *stat,
198198
{
199199
int retval;
200200

201-
if (WARN_ON_ONCE(query_flags & AT_GETATTR_NOSEC))
202-
return -EPERM;
203-
204201
retval = security_inode_getattr(path);
205202
if (retval)
206203
return retval;

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 */

0 commit comments

Comments
 (0)