vfs, afs: Pass the file from fstat()/statx() to the fs for auth purposes
Subsystems (7)
David Howells
maintainerRFC PATCH 1/1 vfs, afs: Pass the file from fstat()/statx() to the fs for auth purposes
read(), write() and ftruncate() all have the file available from which they can extract the information needed to perform authenticated operations to a network filesystem server for that filesystem, but fstat() and statx() do not.
This could lead to the situation where a read(), say, on a file descriptor will work, but fstat() will fail because the calling process doesn't intrinsically have the right to do that.
Change this by passing the file, if we have it, in struct kstat from which the filesystem can pick it up and use it, similar to the way ftruncate() passes the information in struct iattr.
Make use of this in the afs filesystem to pass to validation in case we need to refetch the inode attributes from the server.
--- fs/afs/inode.c | 10 ++++++++- fs/exportfs/expfs.c | 2 - fs/stat.c | 56 ++++++++++++++++++++++++++++++++++++++------------- include/linux/fs.h | 3 +- include/linux/stat.h | 1 5 files changed, 55 insertions(+), 17 deletions(-)
fs/afs/inode.c +9 -1
@@ -670,6 +670,9 @@ int afs_validate(struct afs_vnode *vnode, struct key *key) vnode->fid.vid, vnode->fid.vnode, vnode->flags, key_serial(key)); +if (!vnode->volume) + goto valid;/* Dynroot */ +if (unlikely (test_bit (AFS_VNODE_DELETED , &vnode->flags))) {if (vnode->vfs_inode.i_nlink)clear_nlink (&vnode->vfs_inode);
@@ -728,10 +731,15 @@ int afs_getattr(struct user_namespace *mnt_userns, const struct path *path, {struct inode *inode =d_inode (path->dentry);struct afs_vnode *vnode =AFS_FS_I (inode); -int seq =0 ; +struct afs_file *af = stat->file ? stat->file->private_data :NULL ; +int ret, seq =0 ;_enter ("{ ino=%lu v=%u }" , inode->i_ino, inode->i_generation); + ret =afs_validate (vnode, af ? af->key :NULL ); +if (ret <0 ) +return ret; + do { read_seqbegin_or_lock(&vnode->cb_lock, &seq); generic_fillattr(&init_user_ns, inode, stat);
fs/exportfs/expfs.c +1 -1
@@ -303,7 +303,7 @@ static int get_name(const struct path *path, char *name, struct dentry *child)* actually call ->getattr, not just read i_ino: */ error =vfs_getattr_nosec (&child_path, &stat, -STATX_INO ,AT_STATX_SYNC_AS_STAT ); +STATX_INO ,AT_STATX_SYNC_AS_STAT ,NULL );if (error)return error; buffer.ino = stat.ino;
fs/stat.c +42 -14
98 lines not on this page · raw message
include/linux/fs.h +2 -1
@@ -3312,7 +3312,8 @@ extern int page_symlink(struct inode *inode, const char *symname, int len);extern const struct inode_operations page_symlink_inode_operations;extern void kfree_link (void *);void generic_fillattr (struct user_namespace *,struct inode *,struct kstat *); -extern int vfs_getattr_nosec (const struct path *,struct kstat *,u32 ,unsigned int ); +extern int vfs_getattr_nosec (const struct path *,struct kstat *,u32 ,unsigned int , +struct file *);extern int vfs_getattr (const struct path *,struct kstat *,u32 ,unsigned int );void __inode_add_bytes (struct inode *inode,loff_t bytes);void inode_add_bytes (struct inode *inode,loff_t bytes);
include/linux/stat.h +1 -0
@@ -20,6 +20,7 @@#include <linux/uidgid.h> struct kstat { +struct file *file;/* File if called from fstat() equivalent or NULL */ u32 result_mask;/* What fields the user got */ umode_t mode;unsigned int nlink;