tmpfs: simplify constructing "security.foo" xattr names
Subsystems (8)
PATCH 1/3 tmpfs: simplify constructing "security.foo" xattr names
Use kasprintf() instead of doing it with kmalloc() + 2 x memcpy().
--- mm/shmem.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
mm/shmem.c +2 -9
@@ -4232,7 +4232,6 @@ static int shmem_initxattrs(struct inode *inode,struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb);const struct xattr *xattr;size_t ispace =0 ; -size_t len;CLASS (simple_xattrs, xattrs)();if (IS_ERR (xattrs))
@@ -4260,17 +4259,11 @@ static int shmem_initxattrs(struct inode *inode,if (IS_ERR (new_xattr))break ; - len =strlen (xattr->name) +1 ; - new_xattr->name =kmalloc (XATTR_SECURITY_PREFIX_LEN + len, -GFP_KERNEL_ACCOUNT ); + new_xattr->name =kasprintf (GFP_KERNEL_ACCOUNT , +XATTR_SECURITY_PREFIX "%s" , xattr->name);if (!new_xattr->name)break ; -memcpy (new_xattr->name,XATTR_SECURITY_PREFIX , -XATTR_SECURITY_PREFIX_LEN ); -memcpy (new_xattr->name +XATTR_SECURITY_PREFIX_LEN , - xattr->name, len); -if (simple_xattr_add (xattrs, new_xattr))break ;retain_and_null_ptr (new_xattr);
Signature · 1 line
2.54.0
PATCH 2/3 simple_xattr: change interface to pass struct simple_xattrs **
Change the simple_xattr API to accept pointer-to-pointer (struct simple_xattrs **) instead of pointer. This allows the functions to handle lazy allocation internally without requiring callers to use simple_xattrs_lazy_alloc().
The simple_xattr_set(), simple_xattr_set_limited() and simple_xattr_add() functions now handle allocation when xattrs is NULL. simple_xattrs_free() now also frees the xattrs structure itself and sets the pointer to NULL.
This simplifies callers and removes the need for most callers to explicitly manage xattrs allocation and lifetime.
--- fs/kernfs/dir.c | 12 +++-------- fs/kernfs/inode.c | 24 ++++------------------ fs/pidfs.c | 37 ++++++---------------------------- fs/xattr.c | 46 ++++++++++++++++++++++++++++++++++--------- include/linux/xattr.h | 21 ++++++-------------- mm/shmem.c | 30 ++++++---------------------- net/socket.c | 24 +++++----------------- 7 files changed, 67 insertions(+), 127 deletions(-)
fs/kernfs/dir.c +3 -9
@@ -605,11 +605,8 @@ void kernfs_put(struct kernfs_node *kn)if (kernfs_type (kn) ==KERNFS_LINK )kernfs_put (kn->symlink.target_kn); -if (kn->iattr && kn->iattr->xattrs) { -simple_xattrs_free (kn->iattr->xattrs,NULL ); -kfree (kn->iattr->xattrs); - kn->iattr->xattrs =NULL ; - } +if (kn->iattr) +simple_xattrs_free (&kn->iattr->xattrs,NULL );spin_lock (&root->kernfs_idr_lock);idr_remove (&root->ino_idr, (u32 )kernfs_ino (kn));
@@ -709,10 +706,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, err_out4:if (kn->iattr) { -if (kn->iattr->xattrs) { -simple_xattrs_free (kn->iattr->xattrs,NULL ); -kfree (kn->iattr->xattrs); - } +simple_xattrs_free (&kn->iattr->xattrs,NULL );kmem_cache_free (kernfs_iattrs_cache, kn->iattr); } err_out3:
fs/kernfs/inode.c +4 -20
@@ -144,8 +144,7 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)if (!attrs)return -ENOMEM ; -return simple_xattr_list (d_inode (dentry),READ_ONCE (attrs->xattrs), - buf, size); +return simple_xattr_list (d_inode (dentry), &attrs->xattrs, buf, size); }static inline void set_default_inode_attr (struct inode *inode,umode_t mode)
@@ -297,34 +296,24 @@ int kernfs_xattr_get(struct kernfs_node *kn, const char *name, void *value, size_t size) {struct kernfs_iattrs *attrs =kernfs_iattrs_noalloc (kn); -struct simple_xattrs *xattrs;if (!attrs)return -ENODATA ; - xattrs =READ_ONCE (attrs->xattrs); -if (!xattrs) -return -ENODATA ; - -return simple_xattr_get (xattrs, name, value, size); +return simple_xattr_get (&attrs->xattrs, name, value, size); }int kernfs_xattr_set (struct kernfs_node *kn,const char *name,const void *value,size_t size,int flags) {struct simple_xattr *old_xattr; -struct simple_xattrs *xattrs;struct kernfs_iattrs *attrs; attrs =kernfs_iattrs (kn);if (!attrs)return -ENOMEM ; - xattrs =simple_xattrs_lazy_alloc (&attrs->xattrs, value, flags); -if (IS_ERR_OR_NULL (xattrs)) -return PTR_ERR (xattrs); - - old_xattr =simple_xattr_set (xattrs, name, value, size, flags); + old_xattr =simple_xattr_set (&attrs->xattrs, name, value, size, flags);if (IS_ERR (old_xattr))return PTR_ERR (old_xattr);
@@ -362,7 +351,6 @@ static int kernfs_vfs_user_xattr_set(const struct xattr_handler *handler, {const char *full_name =xattr_full_name (handler, suffix);struct kernfs_node *kn = inode->i_private; -struct simple_xattrs *xattrs;struct kernfs_iattrs *attrs;if (!(kernfs_root (kn)->flags &KERNFS_ROOT_SUPPORT_USER_XATTR ))
@@ -372,11 +360,7 @@ static int kernfs_vfs_user_xattr_set(const struct xattr_handler *handler,if (!attrs)return -ENOMEM ; - xattrs =simple_xattrs_lazy_alloc (&attrs->xattrs, value, flags); -if (IS_ERR_OR_NULL (xattrs)) -return PTR_ERR (xattrs); - -return simple_xattr_set_limited (xattrs, &attrs->xattr_limits, +return simple_xattr_set_limited (&attrs->xattrs, &attrs->xattr_limits, full_name, value, size, flags); }
fs/pidfs.c +6 -31
@@ -196,12 +196,7 @@ static void pidfs_free_attr_work(struct work_struct *work) head =llist_del_all (&pidfs_free_list);llist_for_each_entry_safe (attr, next, head, pidfs_llist) { -struct simple_xattrs *xattrs = attr->xattrs; - -if (xattrs) { -simple_xattrs_free (xattrs,NULL ); -kfree (xattrs); - } +simple_xattrs_free (&attr->xattrs,NULL );kfree (attr); } }
@@ -815,14 +810,8 @@ static ssize_t pidfs_listxattr(struct dentry *dentry, char *buf, size_t size) {struct inode *inode =d_inode (dentry);struct pid *pid = inode->i_private; -struct pidfs_attr *attr = pid->attr; -struct simple_xattrs *xattrs; - - xattrs =READ_ONCE (attr->xattrs); -if (!xattrs) -return 0 ; -return simple_xattr_list (inode, xattrs, buf, size); +return simple_xattr_list (inode, &pid->attr->xattrs, buf, size); }static const struct inode_operations pidfs_inode_operations = {
@@ -1057,16 +1046,9 @@ static int pidfs_xattr_get(const struct xattr_handler *handler, const char *suffix, void *value, size_t size) { struct pid *pid = inode->i_private; -struct pidfs_attr *attr = pid->attr; -const char *name; -struct simple_xattrs *xattrs; - - xattrs =READ_ONCE (attr->xattrs); -if (!xattrs) -return -ENODATA ; +const char *name =xattr_full_name (handler, suffix); - name =xattr_full_name (handler, suffix); -return simple_xattr_get (xattrs, name, value, size); +return simple_xattr_get (&pid->attr->xattrs, name, value, size); } static int pidfs_xattr_set(const struct xattr_handler *handler,
@@ -1075,20 +1057,13 @@ static int pidfs_xattr_set(const struct xattr_handler *handler, const void *value, size_t size, int flags) { struct pid *pid = inode->i_private; -struct pidfs_attr *attr = pid->attr; -const char *name; -struct simple_xattrs *xattrs; +const char *name =xattr_full_name (handler, suffix);struct simple_xattr *old_xattr;/* Ensure we're the only one to set @attr->xattrs. */ WARN_ON_ONCE (!inode_is_locked (inode)); - xattrs =simple_xattrs_lazy_alloc (&attr->xattrs, value, flags); -if (IS_ERR_OR_NULL (xattrs)) -return PTR_ERR (xattrs); - - name =xattr_full_name (handler, suffix); - old_xattr =simple_xattr_set (xattrs, name, value, size, flags); + old_xattr =simple_xattr_set (&pid->attr->xattrs, name, value, size, flags);if (IS_ERR (old_xattr))return PTR_ERR (old_xattr);
fs/xattr.c +37 -9
127 lines not on this page · raw message
include/linux/xattr.h +6 -15
@@ -133,26 +133,23 @@ static inline void simple_xattr_limits_init(struct simple_xattr_limits *limits) }int simple_xattrs_init (struct simple_xattrs *xattrs); -struct simple_xattrs *simple_xattrs_alloc (void ); -struct simple_xattrs *simple_xattrs_lazy_alloc (struct simple_xattrs **xattrsp, -const void *value,int flags); -void simple_xattrs_free (struct simple_xattrs *xattrs,size_t *freed_space); +void simple_xattrs_free (struct simple_xattrs **xattrs,size_t *freed_space);size_t simple_xattr_space (const char *name,size_t size);struct simple_xattr *simple_xattr_alloc (const void *value,size_t size);void simple_xattr_free (struct simple_xattr *xattr);void simple_xattr_free_rcu (struct simple_xattr *xattr); -int simple_xattr_get (struct simple_xattrs *xattrs,const char *name, +int simple_xattr_get (struct simple_xattrs **xattrs,const char *name,void *buffer,size_t size); -struct simple_xattr *simple_xattr_set (struct simple_xattrs *xattrs, +struct simple_xattr *simple_xattr_set (struct simple_xattrs **xattrs,const char *name,const void *value,size_t size,int flags); -int simple_xattr_set_limited (struct simple_xattrs *xattrs, +int simple_xattr_set_limited (struct simple_xattrs **xattrs,struct simple_xattr_limits *limits,const char *name,const void *value,size_t size,int flags); -ssize_t simple_xattr_list (struct inode *inode,struct simple_xattrs *xattrs, +ssize_t simple_xattr_list (struct inode *inode,struct simple_xattrs **xattrs,char *buffer,size_t size); -int simple_xattr_add (struct simple_xattrs *xattrs, +int simple_xattr_add (struct simple_xattrs **xattrs,struct simple_xattr *new_xattr);int xattr_list_one (char **buffer,ssize_t *remaining_size,const char *name);
@@ -162,10 +159,4 @@ DEFINE_CLASS(simple_xattr, simple_xattr_alloc(value, size), const void *value, size_t size) -DEFINE_CLASS (simple_xattrs, - struct simple_xattrs *, - if (!IS_ERR_OR_NULL(_T)) { simple_xattrs_free(_T, NULL); kfree(_T); }, -simple_xattrs_alloc (), - void) -#endif /* _LINUX_XATTR_H */
mm/shmem.c +6 -24
@@ -1425,10 +1425,8 @@ static void shmem_evict_inode(struct inode *inode) } } -if (info->xattrs) { -simple_xattrs_free (info->xattrs, sbinfo->max_inodes ? &freed :NULL ); -kfree (info->xattrs); - } +simple_xattrs_free (&info->xattrs, sbinfo->max_inodes ? &freed :NULL ); +shmem_free_inode (inode->i_sb, freed);WARN_ON (inode->i_blocks);clear_inode (inode);
@@ -4233,10 +4231,6 @@ static int shmem_initxattrs(struct inode *inode,const struct xattr *xattr;size_t ispace =0 ; -CLASS (simple_xattrs, xattrs)(); -if (IS_ERR (xattrs)) -return PTR_ERR (xattrs); -if (sbinfo->max_inodes) {for (xattr = xattr_array; xattr->name !=NULL ; xattr++) { ispace += simple_xattr_space(xattr->name,
@@ -4264,7 +4258,7 @@ static int shmem_initxattrs(struct inode *inode,if (!new_xattr->name)break ; -if (simple_xattr_add (xattrs, new_xattr)) +if (simple_xattr_add (&info->xattrs, new_xattr))break ;retain_and_null_ptr (new_xattr); }
@@ -4278,7 +4272,6 @@ static int shmem_initxattrs(struct inode *inode,return -ENOMEM ; } -smp_store_release (&info->xattrs,no_free_ptr (xattrs));return 0 ; }
@@ -4287,14 +4280,9 @@ static int shmem_xattr_handler_get(const struct xattr_handler *handler, const char *name, void *buffer, size_t size) { struct shmem_inode_info *info = SHMEM_I(inode); -struct simple_xattrs *xattrs; - - xattrs =READ_ONCE (info->xattrs); -if (!xattrs) -return -ENODATA ; name =xattr_full_name (handler, name); -return simple_xattr_get (xattrs, name, buffer, size); +return simple_xattr_get (&info->xattrs, name, buffer, size); } static int shmem_xattr_handler_set(const struct xattr_handler *handler,
@@ -4305,16 +4293,11 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler, {struct shmem_inode_info *info =SHMEM_I (inode);struct shmem_sb_info *sbinfo =SHMEM_SB (inode->i_sb); -struct simple_xattrs *xattrs;struct simple_xattr *old_xattr;size_t ispace =0 ; name =xattr_full_name (handler, name); - xattrs =simple_xattrs_lazy_alloc (&info->xattrs, value, flags); -if (IS_ERR_OR_NULL (xattrs)) -return PTR_ERR (xattrs); -if (value && sbinfo->max_inodes) { ispace =simple_xattr_space (name, size);raw_spin_lock (&sbinfo->stat_lock);
@@ -4327,7 +4310,7 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler,return -ENOSPC ; } - old_xattr =simple_xattr_set (xattrs, name, value, size, flags); + old_xattr =simple_xattr_set (&info->xattrs, name, value, size, flags);if (!IS_ERR (old_xattr)) { ispace =0 ;if (old_xattr && sbinfo->max_inodes)
@@ -4375,8 +4358,7 @@ static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size) {struct shmem_inode_info *info =SHMEM_I (d_inode (dentry)); -return simple_xattr_list (d_inode (dentry),READ_ONCE (info->xattrs), - buffer, size); +return simple_xattr_list (d_inode (dentry), &info->xattrs, buffer, size); }#endif /* CONFIG_TMPFS_XATTR */
net/socket.c +5 -19
@@ -347,12 +347,8 @@ static struct inode *sock_alloc_inode(struct super_block *sb)static void sock_evict_inode (struct inode *inode) {struct sockfs_inode *si =SOCKFS_I (inode); -struct simple_xattrs *xattrs = si->xattrs; -if (xattrs) { -simple_xattrs_free (xattrs,NULL ); -kfree (xattrs); - } +simple_xattrs_free (&si->xattrs,NULL );clear_inode (inode); }
@@ -443,13 +439,9 @@ static int sockfs_user_xattr_get(const struct xattr_handler *handler, const char *suffix, void *value, size_t size) { const char *name = xattr_full_name(handler, suffix); -struct simple_xattrs *xattrs; - - xattrs =READ_ONCE (SOCKFS_I (inode)->xattrs); -if (!xattrs) -return -ENODATA ; +struct sockfs_inode *si =SOCKFS_I (inode); -return simple_xattr_get (xattrs, name, value, size); +return simple_xattr_get (&si->xattrs, name, value, size); } static int sockfs_user_xattr_set(const struct xattr_handler *handler,
@@ -460,13 +452,8 @@ static int sockfs_user_xattr_set(const struct xattr_handler *handler, {const char *name =xattr_full_name (handler, suffix);struct sockfs_inode *si =SOCKFS_I (inode); -struct simple_xattrs *xattrs; - - xattrs =simple_xattrs_lazy_alloc (&si->xattrs, value, flags); -if (IS_ERR_OR_NULL (xattrs)) -return PTR_ERR (xattrs); -return simple_xattr_set_limited (xattrs, &si->xattr_limits, +return simple_xattr_set_limited (&si->xattrs, &si->xattr_limits, name, value, size, flags); }
@@ -635,8 +622,7 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,struct sockfs_inode *si =SOCKFS_I (d_inode (dentry));ssize_t len, used; - len =simple_xattr_list (d_inode (dentry),READ_ONCE (si->xattrs), - buffer, size); + len =simple_xattr_list (d_inode (dentry), &si->xattrs, buffer, size);if (len <0 )return len;
Signature · 1 line
2.54.0
PATCH 3/3 simpe_xattr: use per-sb cache
In reply to Miklos SzerediMove the hash table to the super block to remove excessive overhead in case of small number of xattrs per inode.
Add linked list to the inode, used for listxattr and eviction. Listxattr uses rcu protection to iterate the list of xattrs.
Following stats are based on slabinfo diff, after creating 100k empty files, then adding a "user.test=foo" xattr to each:
v7.0 (no rhashtable):
File creation: 993.40 bytes/file
Xattr addition: 79.99 bytes/file
v7.1-rc2 (per-inode rhashtable):
File creation: 939.73 bytes/file
Xattr addition: 1296.08 bytes/file
v7.1-rc2 + this patch (per-sb rhashtable)
File creation: 947.08 bytes/file
Xattr addition: 79.95 bytes/file
This patch reverts the xattr overhead to the v7.0 level.
--- fs/kernfs/dir.c | 5 +- fs/kernfs/inode.c | 10 +- fs/kernfs/kernfs-internal.h | 4 +- fs/pidfs.c | 14 +- fs/xattr.c | 265 ++++++++++++++++-------------------- include/linux/shmem_fs.h | 3 +- include/linux/xattr.h | 30 ++-- mm/shmem.c | 13 +- net/socket.c | 12 +- 9 files changed, 178 insertions(+), 178 deletions(-)
fs/kernfs/dir.c +3 -2
@@ -606,7 +606,7 @@ void kernfs_put(struct kernfs_node *kn)kernfs_put (kn->symlink.target_kn);if (kn->iattr) -simple_xattrs_free (&kn->iattr->xattrs,NULL ); +simple_xattrs_free (&root->xa_cache, &kn->iattr->xattrs,NULL );spin_lock (&root->kernfs_idr_lock);idr_remove (&root->ino_idr, (u32 )kernfs_ino (kn));
@@ -621,6 +621,7 @@ void kernfs_put(struct kernfs_node *kn) }else {/* just released the root kn, free @root too */ idr_destroy (&root->ino_idr); +simple_xattr_cache_cleanup (&root->xa_cache);kfree_rcu (root, rcu); } }
@@ -706,7 +707,7 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, err_out4:if (kn->iattr) { -simple_xattrs_free (&kn->iattr->xattrs,NULL ); +simple_xattrs_free (&root->xa_cache, &kn->iattr->xattrs,NULL );kmem_cache_free (kernfs_iattrs_cache, kn->iattr); } err_out3:
fs/kernfs/inode.c +7 -3
@@ -37,6 +37,7 @@ static struct kernfs_iattrs *__kernfs_iattrs(struct kernfs_node *kn, bool alloc)if (!ret)return NULL ; +INIT_LIST_HEAD_RCU (&ret->xattrs);/* assign default attributes */ ret->ia_uid =GLOBAL_ROOT_UID ; ret->ia_gid =GLOBAL_ROOT_GID ;
@@ -296,11 +297,12 @@ int kernfs_xattr_get(struct kernfs_node *kn, const char *name, void *value, size_t size) {struct kernfs_iattrs *attrs =kernfs_iattrs_noalloc (kn); +struct simple_xattr_cache *cache = &kernfs_root (kn)->xa_cache;if (!attrs)return -ENODATA ; -return simple_xattr_get (&attrs->xattrs, name, value, size); +return simple_xattr_get (cache, &attrs->xattrs, name, value, size); } int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
@@ -308,12 +310,13 @@ int kernfs_xattr_set(struct kernfs_node *kn, const char *name, {struct simple_xattr *old_xattr;struct kernfs_iattrs *attrs; +struct simple_xattr_cache *cache = &kernfs_root (kn)->xa_cache; attrs =kernfs_iattrs (kn);if (!attrs)return -ENOMEM ; - old_xattr =simple_xattr_set (&attrs->xattrs, name, value, size, flags); + old_xattr =simple_xattr_set (cache, &attrs->xattrs, name, value, size, flags);if (IS_ERR (old_xattr))return PTR_ERR (old_xattr);
@@ -360,7 +363,8 @@ static int kernfs_vfs_user_xattr_set(const struct xattr_handler *handler,if (!attrs)return -ENOMEM ; -return simple_xattr_set_limited (&attrs->xattrs, &attrs->xattr_limits, +return simple_xattr_set_limited (&kernfs_root (kn)->xa_cache, + &attrs->xattrs, &attrs->xattr_limits, full_name, value, size, flags); }
fs/kernfs/kernfs-internal.h +3 -1
@@ -26,7 +26,7 @@ struct kernfs_iattrs {struct timespec64 ia_mtime;struct timespec64 ia_ctime; -struct simple_xattrs *xattrs; +struct list_head xattrs;struct simple_xattr_limits xattr_limits; };
@@ -54,6 +54,8 @@ struct kernfs_root {rwlock_t kernfs_rename_lock;struct rcu_head rcu; + +struct simple_xattr_cache xa_cache; };/* +1 to avoid triggering overflow warning when negating it */
fs/pidfs.c +9 -5
@@ -37,6 +37,8 @@ static struct kmem_cache *pidfs_attr_cachep __ro_after_init;static struct path pidfs_root_path = {}; +static struct simple_xattr_cache pidfs_xa_cache; +void pidfs_get_root (struct path *path) { *path = pidfs_root_path;
@@ -96,7 +98,7 @@ static const struct rhashtable_params pidfs_ino_ht_params = {* use file handles. */ struct pidfs_attr { -struct simple_xattrs *xattrs; +struct list_head xattrs;union {struct pidfs_anon_attr ;struct llist_node pidfs_llist;
@@ -196,7 +198,7 @@ static void pidfs_free_attr_work(struct work_struct *work) head =llist_del_all (&pidfs_free_list);llist_for_each_entry_safe (attr, next, head, pidfs_llist) { -simple_xattrs_free (&attr->xattrs,NULL ); +simple_xattrs_free (&pidfs_xa_cache, &attr->xattrs,NULL );kfree (attr); } }
@@ -224,7 +226,7 @@ void pidfs_free_pid(struct pid *pid)if (IS_ERR (attr))return ; -if (likely (!attr->xattrs)) +if (likely (list_empty (&attr->xattrs)))kfree (attr);else if (llist_add (&attr->pidfs_llist, &pidfs_free_list))schedule_work (&pidfs_free_work);
@@ -1007,6 +1009,8 @@ int pidfs_register_pid(struct pid *pid)if (!new_attr)return -ENOMEM ; +INIT_LIST_HEAD_RCU (&new_attr->xattrs); +/* Synchronize with pidfs_exit(). */ guard (spinlock_irq)(&pid->wait_pidfd.lock);
@@ -1048,7 +1052,7 @@ static int pidfs_xattr_get(const struct xattr_handler *handler,struct pid *pid = inode->i_private;const char *name =xattr_full_name (handler, suffix); -return simple_xattr_get (&pid->attr->xattrs, name, value, size); +return simple_xattr_get (&pidfs_xa_cache, &pid->attr->xattrs, name, value, size); } static int pidfs_xattr_set(const struct xattr_handler *handler,
@@ -1063,7 +1067,7 @@ static int pidfs_xattr_set(const struct xattr_handler *handler,/* Ensure we're the only one to set @attr->xattrs. */ WARN_ON_ONCE (!inode_is_locked (inode)); - old_xattr =simple_xattr_set (&pid->attr->xattrs, name, value, size, flags); + old_xattr =simple_xattr_set (&pidfs_xa_cache, &pid->attr->xattrs, name, value, size, flags);if (IS_ERR (old_xattr))return PTR_ERR (old_xattr);
fs/xattr.c +119 -146
443 lines not on this page · raw message
include/linux/shmem_fs.h +2 -1
@@ -48,7 +48,7 @@ struct shmem_inode_info { };struct timespec64 i_crtime;/* file creation time */ struct shared_policy policy;/* NUMA memory alloc policy */ -struct simple_xattrs *xattrs;/* list of xattrs */ +struct list_head xattrs;/* list of xattrs */ pgoff_t fallocend;/* highest fallocate endindex */ unsigned int fsflags;/* for FS_IOC_[SG]ETFLAGS */ atomic_t stop_eviction;/* hold when working on inode */
@@ -89,6 +89,7 @@ struct shmem_sb_info {struct list_head shrinklist;/* List of shinkable inodes */ unsigned long shrinklist_len;/* Length of shrinklist */ struct shmem_quota_limits qlimits;/* Default quota limits */ +struct simple_xattr_cache xa_cache; };static inline struct shmem_inode_info *SHMEM_I (struct inode *inode)
include/linux/xattr.h +19 -11
@@ -106,13 +106,17 @@ static inline const char *xattr_prefix(const struct xattr_handler *handler)return handler->prefix ?: handler->name; } -struct simple_xattrs { -struct rhashtable ht; +struct simple_xattr_cache { +struct rhashtable *ht; };struct simple_xattr {struct rhash_head hash_node; -struct rcu_head rcu; +union { +struct list_head node; +struct rcu_head rcu; + }; +struct list_head *parent;char *name;size_t size; char value[] __counted_by(size);
@@ -132,27 +136,31 @@ static inline void simple_xattr_limits_init(struct simple_xattr_limits *limits)atomic_set (&limits->xattr_size,0 ); } -int simple_xattrs_init (struct simple_xattrs *xattrs); -void simple_xattrs_free (struct simple_xattrs **xattrs,size_t *freed_space); +void simple_xattrs_free (struct simple_xattr_cache *cache,struct list_head *xattrs, +size_t *freed_space);size_t simple_xattr_space (const char *name,size_t size);struct simple_xattr *simple_xattr_alloc (const void *value,size_t size);void simple_xattr_free (struct simple_xattr *xattr);void simple_xattr_free_rcu (struct simple_xattr *xattr); -int simple_xattr_get (struct simple_xattrs **xattrs,const char *name, -void *buffer,size_t size); -struct simple_xattr *simple_xattr_set (struct simple_xattrs **xattrs, +int simple_xattr_get (struct simple_xattr_cache *cache,struct list_head *xattrs, +const char *name,void *buffer,size_t size); +struct simple_xattr *simple_xattr_set (struct simple_xattr_cache *cache, +struct list_head *xattrs,const char *name,const void *value,size_t size,int flags); -int simple_xattr_set_limited (struct simple_xattrs **xattrs, +int simple_xattr_set_limited (struct simple_xattr_cache *cache, +struct list_head *xattrs,struct simple_xattr_limits *limits,const char *name,const void *value,size_t size,int flags); -ssize_t simple_xattr_list (struct inode *inode,struct simple_xattrs **xattrs, +ssize_t simple_xattr_list (struct inode *inode,struct list_head *xattrs,char *buffer,size_t size); -int simple_xattr_add (struct simple_xattrs **xattrs, +int simple_xattr_add (struct simple_xattr_cache *cache,struct list_head *xattrs,struct simple_xattr *new_xattr);int xattr_list_one (char **buffer,ssize_t *remaining_size,const char *name); +void simple_xattr_cache_cleanup (struct simple_xattr_cache *cache); + DEFINE_CLASS(simple_xattr, struct simple_xattr *, if (!IS_ERR_OR_NULL(_T)) simple_xattr_free(_T),
mm/shmem.c +9 -4
@@ -1425,7 +1425,7 @@ static void shmem_evict_inode(struct inode *inode) } } -simple_xattrs_free (&info->xattrs, sbinfo->max_inodes ? &freed :NULL ); +simple_xattrs_free (&sbinfo->xa_cache, &info->xattrs, sbinfo->max_inodes ? &freed :NULL );shmem_free_inode (inode->i_sb, freed);WARN_ON (inode->i_blocks);
@@ -3084,6 +3084,7 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, inode->i_generation =get_random_u32 (); info =SHMEM_I (inode);memset (info,0 , (char *)inode - (char *)info); +INIT_LIST_HEAD_RCU (&info->xattrs);spin_lock_init (&info->lock);atomic_set (&info->stop_eviction,0 ); info->seals =F_SEAL_SEAL ;
@@ -4258,7 +4259,7 @@ static int shmem_initxattrs(struct inode *inode,if (!new_xattr->name)break ; -if (simple_xattr_add (&info->xattrs, new_xattr)) +if (simple_xattr_add (&sbinfo->xa_cache, &info->xattrs, new_xattr))break ;retain_and_null_ptr (new_xattr); }
@@ -4279,10 +4280,11 @@ static int shmem_xattr_handler_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *buffer, size_t size) { + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);struct shmem_inode_info *info =SHMEM_I (inode); name =xattr_full_name (handler, name); -return simple_xattr_get (&info->xattrs, name, buffer, size); +return simple_xattr_get (&sbinfo->xa_cache, &info->xattrs, name, buffer, size); } static int shmem_xattr_handler_set(const struct xattr_handler *handler,
@@ -4310,7 +4312,7 @@ static int shmem_xattr_handler_set(const struct xattr_handler *handler,return -ENOSPC ; } - old_xattr =simple_xattr_set (&info->xattrs, name, value, size, flags); + old_xattr =simple_xattr_set (&sbinfo->xa_cache, &info->xattrs, name, value, size, flags);if (!IS_ERR (old_xattr)) { ispace =0 ;if (old_xattr && sbinfo->max_inodes)
@@ -4959,6 +4961,9 @@ static void shmem_put_super(struct super_block *sb)free_percpu (sbinfo->ino_batch);percpu_counter_destroy (&sbinfo->used_blocks);mpol_put (sbinfo->mpol); +#ifdef CONFIG_TMPFS_XATTR +simple_xattr_cache_cleanup (&sbinfo->xa_cache); +#endif kfree (sbinfo); sb->s_fs_info =NULL ; }
net/socket.c +7 -5
@@ -310,8 +310,10 @@ static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,static struct kmem_cache *sock_inode_cachep__ro_after_init ; +static struct simple_xattr_cache sockfs_xa_cache; +struct sockfs_inode { -struct simple_xattrs *xattrs; +struct list_head xattrs;struct simple_xattr_limits xattr_limits;struct socket_alloc ; };
@@ -328,7 +330,7 @@ static struct inode *sock_alloc_inode(struct super_block *sb) si =alloc_inode_sb (sb, sock_inode_cachep,GFP_KERNEL );if (!si)return NULL ; - si->xattrs =NULL ; +INIT_LIST_HEAD_RCU (&si->xattrs);simple_xattr_limits_init (&si->xattr_limits);init_waitqueue_head (&si->socket.wq.wait);
@@ -348,7 +350,7 @@ static void sock_evict_inode(struct inode *inode) {struct sockfs_inode *si =SOCKFS_I (inode); -simple_xattrs_free (&si->xattrs,NULL ); +simple_xattrs_free (&sockfs_xa_cache, &si->xattrs,NULL );clear_inode (inode); }
@@ -441,7 +443,7 @@ static int sockfs_user_xattr_get(const struct xattr_handler *handler,const char *name =xattr_full_name (handler, suffix);struct sockfs_inode *si =SOCKFS_I (inode); -return simple_xattr_get (&si->xattrs, name, value, size); +return simple_xattr_get (&sockfs_xa_cache, &si->xattrs, name, value, size); } static int sockfs_user_xattr_set(const struct xattr_handler *handler,
@@ -453,7 +455,7 @@ static int sockfs_user_xattr_set(const struct xattr_handler *handler,const char *name =xattr_full_name (handler, suffix);struct sockfs_inode *si =SOCKFS_I (inode); -return simple_xattr_set_limited (&si->xattrs, &si->xattr_limits, +return simple_xattr_set_limited (&sockfs_xa_cache, &si->xattrs, &si->xattr_limits, name, value, size, flags); }
Signature · 1 line
2.54.0
Quoted 1 line · Miklos Szeredi
tmpfs: simplify constructing "security.foo" xattr names
Thanks, this looks great!
---
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.misc
[1/3] tmpfs: simplify constructing "security.foo" xattr names
https://git.kernel.org/vfs/vfs/c/aba5853b137b [2/3] simple_xattr: change interface to pass struct simple_xattrs ** https://git.kernel.org/vfs/vfs/c/1cd9d2387c05 [3/3] simpe_xattr: use per-sb cache https://git.kernel.org/vfs/vfs/c/12e9e3cd03b5
hi Christian, Miklos,
https://lore.kernel.org/all/177945382308.2991556.1256192774754909984.b4-ty@b4/
Quoted 22 lines
Quoted 1 line · Miklos Szeredi
tmpfs: simplify constructing "security.foo" xattr names
Thanks, this looks great!
---
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.misc
Quoted 6 lines
[1/3] tmpfs: simplify constructing "security.foo" xattr names
https://git.kernel.org/vfs/vfs/c/aba5853b137b [2/3] simple_xattr: change interface to pass struct simple_xattrs ** https://git.kernel.org/vfs/vfs/c/1cd9d2387c05 [3/3] simpe_xattr: use per-sb cache https://git.kernel.org/vfs/vfs/c/12e9e3cd03b5
I have been doing some testing of Chuck's nfsd-testing tree, which includes some vfs changes.
The test systems are reliably crashing, in what looks like it might possibly be something related to these three patches.
I reverted the three patches, and the crashes stopped.
best wishes,
calum.
[ 9.215122] BUG: kernel NULL pointer dereference, address: 00000000000000e0 [ 9.218829] #PF: supervisor read access in kernel mode [ 9.221484] #PF: error_code(0x0000) - not-present page [ 9.224201] PGD 0 P4D 0 [ 9.225557] Oops: Oops: 0000 [#1] SMP NOPTI [ 9.227773] CPU: 0 UID: 0 PID: 1 Comm: systemd Not tainted 7.1.0-rc4.master.20260524.el10.rc1.x86_64 #1 PREEMPT(lazy) [ 9.233281] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.6.4 02/27/2023 [ 9.237483] RIP: 0010:simple_xattr_set+0x27/0x8b0 [ 9.239951] Code: 90 90 90 0f 1f 40 d6 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 d6 41 55 49 89 f5 4c 89 c6 41 54 53 48 83 e4 f0 48 83 ec 40 <4c> 8b 27 44 89 4c 24 3c 4c 89 6c 24 20 48 89 54 24 28 4d 85 e4 0f [ 9.249572] RSP: 0018:ffffd1334001fa20 EFLAGS: 00010282 [ 9.252362] RAX: ffff89974107e460 RBX: ffffffff856b2f80 RCX: ffff899758b0ef60 [ 9.256059] RDX: ffffffff856b2f80 RSI: 000000000000001e RDI: 00000000000000e0 [ 9.259712] RBP: ffffd1334001fa90 R08: 000000000000001e R09: 0000000000000001 [ 9.263416] R10: ffff89974107e460 R11: 0030733a745f7075 R12: 000000000000001e [ 9.267138] R13: ffff89974107e498 R14: ffffffff856b2f80 R15: ffff8997443c5440 [ 9.270772] FS: 00007fc098c74500(0000) GS:ffff899ae8a58000(0000) knlGS:0000000000000000 [ 9.274906] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 9.277976] CR2: 00000000000000e0 CR3: 00000001013d1000 CR4: 00000000003506f0 [ 9.281668] Call Trace: [ 9.282985] <TASK> [ 9.284145] ? srso_return_thunk+0x5/0x5f [ 9.286188] ? srso_return_thunk+0x5/0x5f [ 9.288277] ? ktime_get_real_ts64+0xce/0x140 [ 9.290614] ? srso_return_thunk+0x5/0x5f [ 9.292776] kernfs_xattr_set+0x63/0xb0 [ 9.294829] selinux_kernfs_init_security+0x13b/0x270 [ 9.297496] security_kernfs_init_security+0x36/0xc0 [ 9.300105] __kernfs_new_node+0x182/0x290 [ 9.302421] ? srso_return_thunk+0x5/0x5f [ 9.304597] ? srso_return_thunk+0x5/0x5f [ 9.306645] ? pcpu_alloc_noprof+0x481/0x990 [ 9.308854] kernfs_new_node+0x80/0xc0 [ 9.310876] kernfs_create_dir_ns+0x2b/0xa0 [ 9.313103] cgroup_create+0x116/0x380 [ 9.315123] cgroup_mkdir+0x7c/0x1a0 [ 9.317051] kernfs_iop_mkdir+0x75/0xf0 [ 9.319014] vfs_mkdir+0xc2/0x240 [ 9.320809] filename_mkdirat+0x1cc/0x220 [ 9.322932] __x64_sys_mkdir+0x2f/0x50 [ 9.324938] do_syscall_64+0xe8/0x5e0 [ 9.326895] ? srso_return_thunk+0x5/0x5f [ 9.329104] ? count_memcg_events+0xdf/0x190 [ 9.331392] ? srso_return_thunk+0x5/0x5f [ 9.333556] ? handle_mm_fault+0x24a/0x350 [ 9.335741] ? srso_return_thunk+0x5/0x5f [ 9.337894] ? do_user_addr_fault+0x221/0x680 [ 9.340194] ? srso_return_thunk+0x5/0x5f [ 9.342653] ? arch_exit_to_user_mode_prepare.isra.0+0x9/0xe0 [ 9.345955] ? srso_return_thunk+0x5/0x5f [ 9.348377] ? srso_return_thunk+0x5/0x5f [ 9.350793] ? do_syscall_64+0x9d/0x5e0 [ 9.353123] ? srso_return_thunk+0x5/0x5f [ 9.355707] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 9.358689] RIP: 0033:0x7fc09832076b [ 9.360891] Code: 0f 1e fa 48 89 f2 b9 00 01 00 00 48 89 fe bf 9c ff ff ff e9 a7 ca ff ff 0f 1f 80 00 00 00 00 f3 0f 1e fa b8 53 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 05 c3 0f 1f 40 00 48 8b 15 71 56 0d 00 f7 d8 [ 9.371018] RSP: 002b:00007ffd34f0af28 EFLAGS: 00000246 ORIG_RAX: 0000000000000053 [ 9.375220] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fc09832076b [ 9.379178] RDX: 0000000000000000 RSI: 00000000000001ed RDI: 00005609edb55790 [ 9.383159] RBP: 00007ffd34f0af60 R08: 0000000000000000 R09: 0000000000000000 [ 9.387102] R10: 0000000000000000 R11: 0000000000000246 R12: 00005609edaeea70 [ 9.391136] R13: 0000000000001fad R14: 00007fc098754472 R15: 00005609edb481d0 [ 9.395140] </TASK> [ 9.396605] Modules linked in: vsock_loopback vmw_vsock_virtio_transport_common vmw_vsock_vmci_transport vsock vmw_vmci xfs nvme_tcp nvme_fabrics nvme_core nvme_keyring nvme_auth sd_mod ata_generic pata_acpi ata_piix virtio_net net_failover failover libata virtio_scsi serio_raw btrfs libblake2b zstd_compress raid6_pq xor sunrpc dm_mirror dm_region_hash dm_log be2iscsi bnx2i cnic uio cxgb4i cxgb4 tls cxgb3i cxgb3 mdio libcxgbi libcxgb qla4xxx iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi iscsi_ibft iscsi_boot_sysfs dm_multipath dm_mod qemu_fw_cfg virtio_pci virtio_pci_legacy_dev virtio_pci_modern_dev [ 9.424581] CR2: 00000000000000e0 [ 9.426635] ---[ end trace 0000000000000000 ]--- [ 9.429400] RIP: 0010:simple_xattr_set+0x27/0x8b0 [ 9.432229] Code: 90 90 90 0f 1f 40 d6 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 d6 41 55 49 89 f5 4c 89 c6 41 54 53 48 83 e4 f0 48 83 ec 40 <4c> 8b 27 44 89 4c 24 3c 4c 89 6c 24 20 48 89 54 24 28 4d 85 e4 0f [ 9.442394] RSP: 0018:ffffd1334001fa20 EFLAGS: 00010282 [ 9.445458] RAX: ffff89974107e460 RBX: ffffffff856b2f80 RCX: ffff899758b0ef60 [ 9.449465] RDX: ffffffff856b2f80 RSI: 000000000000001e RDI: 00000000000000e0 [ 9.453436] RBP: ffffd1334001fa90 R08: 000000000000001e R09: 0000000000000001 [ 9.457506] R10: ffff89974107e460 R11: 0030733a745f7075 R12: 000000000000001e [ 9.461589] R13: ffff89974107e498 R14: ffffffff856b2f80 R15: ffff8997443c5440 [ 9.465681] FS: 00007fc098c74500(0000) GS:ffff899ae8a58000(0000) knlGS:0000000000000000 [ 9.470290] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 9.473702] CR2: 00000000000000e0 CR3: 00000001013d1000 CR4: 00000000003506f0 [ 9.477743] Kernel panic - not syncing: Fatal exception [ 9.481889] Kernel Offset: 0x2a00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) [ 9.487771] ---[ end Kernel panic - not syncing: Fatal exception ]---
[Cc: Greg KH]
Quoted 35 lines · Calum Mackay
hi Christian, Miklos,
https://lore.kernel.org/all/177945382308.2991556.1256192774754909984.b4-ty@b4/
Quoted 22 lines
Quoted 1 line · Miklos Szeredi
tmpfs: simplify constructing "security.foo" xattr names
Thanks, this looks great!
---
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.miscQuoted 6 lines
[1/3] tmpfs: simplify constructing "security.foo" xattr names
https://git.kernel.org/vfs/vfs/c/aba5853b137b [2/3] simple_xattr: change interface to pass struct simple_xattrs ** https://git.kernel.org/vfs/vfs/c/1cd9d2387c05 [3/3] simpe_xattr: use per-sb cache https://git.kernel.org/vfs/vfs/c/12e9e3cd03b5
Quoted 5 lines
I have been doing some testing of Chuck's nfsd-testing tree, which includes some vfs changes.
The test systems are reliably crashing, in what looks like it might possibly be something related to these three patches.
Calum, thanks for the report.
Relevant part of call trace is:
kernfs_new_node
__kernfs_new_node
security_kernfs_init_security
selinux_kernfs_init_security
kernfs_xattr_set
kernfs_root
Since __parent is assigned after security_kernfs_init_security() gets called, kernfs_root() will return NULL.
Greg, any idea about dealing with this?
Thanks,
Miklos
Quoted 128 lines
I reverted the three patches, and the crashes stopped.
best wishes,
calum.[ 9.215122] BUG: kernel NULL pointer dereference, address: 00000000000000e0 [ 9.218829] #PF: supervisor read access in kernel mode [ 9.221484] #PF: error_code(0x0000) - not-present page [ 9.224201] PGD 0 P4D 0 [ 9.225557] Oops: Oops: 0000 [#1] SMP NOPTI [ 9.227773] CPU: 0 UID: 0 PID: 1 Comm: systemd Not tainted 7.1.0-rc4.master.20260524.el10.rc1.x86_64 #1 PREEMPT(lazy) [ 9.233281] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.6.4 02/27/2023 [ 9.237483] RIP: 0010:simple_xattr_set+0x27/0x8b0 [ 9.239951] Code: 90 90 90 0f 1f 40 d6 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 d6 41 55 49 89 f5 4c 89 c6 41 54 53 48 83 e4 f0 48 83 ec 40 <4c> 8b 27 44 89 4c 24 3c 4c 89 6c 24 20 48 89 54 24 28 4d 85 e4 0f [ 9.249572] RSP: 0018:ffffd1334001fa20 EFLAGS: 00010282 [ 9.252362] RAX: ffff89974107e460 RBX: ffffffff856b2f80 RCX: ffff899758b0ef60 [ 9.256059] RDX: ffffffff856b2f80 RSI: 000000000000001e RDI: 00000000000000e0 [ 9.259712] RBP: ffffd1334001fa90 R08: 000000000000001e R09: 0000000000000001 [ 9.263416] R10: ffff89974107e460 R11: 0030733a745f7075 R12: 000000000000001e [ 9.267138] R13: ffff89974107e498 R14: ffffffff856b2f80 R15: ffff8997443c5440 [ 9.270772] FS: 00007fc098c74500(0000) GS:ffff899ae8a58000(0000) knlGS:0000000000000000 [ 9.274906] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 9.277976] CR2: 00000000000000e0 CR3: 00000001013d1000 CR4: 00000000003506f0 [ 9.281668] Call Trace: [ 9.282985] <TASK> [ 9.284145] ? srso_return_thunk+0x5/0x5f [ 9.286188] ? srso_return_thunk+0x5/0x5f [ 9.288277] ? ktime_get_real_ts64+0xce/0x140 [ 9.290614] ? srso_return_thunk+0x5/0x5f [ 9.292776] kernfs_xattr_set+0x63/0xb0 [ 9.294829] selinux_kernfs_init_security+0x13b/0x270 [ 9.297496] security_kernfs_init_security+0x36/0xc0 [ 9.300105] __kernfs_new_node+0x182/0x290 [ 9.302421] ? srso_return_thunk+0x5/0x5f [ 9.304597] ? srso_return_thunk+0x5/0x5f [ 9.306645] ? pcpu_alloc_noprof+0x481/0x990 [ 9.308854] kernfs_new_node+0x80/0xc0 [ 9.310876] kernfs_create_dir_ns+0x2b/0xa0 [ 9.313103] cgroup_create+0x116/0x380 [ 9.315123] cgroup_mkdir+0x7c/0x1a0 [ 9.317051] kernfs_iop_mkdir+0x75/0xf0 [ 9.319014] vfs_mkdir+0xc2/0x240 [ 9.320809] filename_mkdirat+0x1cc/0x220 [ 9.322932] __x64_sys_mkdir+0x2f/0x50 [ 9.324938] do_syscall_64+0xe8/0x5e0 [ 9.326895] ? srso_return_thunk+0x5/0x5f [ 9.329104] ? count_memcg_events+0xdf/0x190 [ 9.331392] ? srso_return_thunk+0x5/0x5f [ 9.333556] ? handle_mm_fault+0x24a/0x350 [ 9.335741] ? srso_return_thunk+0x5/0x5f [ 9.337894] ? do_user_addr_fault+0x221/0x680 [ 9.340194] ? srso_return_thunk+0x5/0x5f [ 9.342653] ? arch_exit_to_user_mode_prepare.isra.0+0x9/0xe0 [ 9.345955] ? srso_return_thunk+0x5/0x5f [ 9.348377] ? srso_return_thunk+0x5/0x5f [ 9.350793] ? do_syscall_64+0x9d/0x5e0 [ 9.353123] ? srso_return_thunk+0x5/0x5f [ 9.355707] entry_SYSCALL_64_after_hwframe+0x76/0x7e [ 9.358689] RIP: 0033:0x7fc09832076b [ 9.360891] Code: 0f 1e fa 48 89 f2 b9 00 01 00 00 48 89 fe bf 9c ff ff ff e9 a7 ca ff ff 0f 1f 80 00 00 00 00 f3 0f 1e fa b8 53 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 05 c3 0f 1f 40 00 48 8b 15 71 56 0d 00 f7 d8 [ 9.371018] RSP: 002b:00007ffd34f0af28 EFLAGS: 00000246 ORIG_RAX: 0000000000000053 [ 9.375220] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fc09832076b [ 9.379178] RDX: 0000000000000000 RSI: 00000000000001ed RDI: 00005609edb55790 [ 9.383159] RBP: 00007ffd34f0af60 R08: 0000000000000000 R09: 0000000000000000 [ 9.387102] R10: 0000000000000000 R11: 0000000000000246 R12: 00005609edaeea70 [ 9.391136] R13: 0000000000001fad R14: 00007fc098754472 R15: 00005609edb481d0 [ 9.395140] </TASK> [ 9.396605] Modules linked in: vsock_loopback
vmw_vsock_virtio_transport_commonvmw_vsock_vmci_transportvsockvmw_vmcixfsnvme_tcpnvme_fabricsnvme_corenvme_keyringnvme_authsd_modata_genericpata_acpiata_piixvirtio_netnet_failoverfailover libatavirtio_scsiserio_rawbtrfs libblake2bzstd_compressraid6_pqxor sunrpcdm_mirrordm_region_hashdm_logbe2iscsi bnx2i cnic uio cxgb4i cxgb4 tls cxgb3i cxgb3 mdio libcxgbi libcxgb qla4xxxiscsi_tcplibiscsi_tcplibiscsiscsi_transport_iscsiiscsi_ibftiscsi_boot_sysfsdm_multipathdm_modqemu_fw_cfgvirtio_pcivirtio_pci_legacy_devvirtio_pci_modern_dev[ 9.424581] CR2: 00000000000000e0 [ 9.426635] ---[ end trace 0000000000000000 ]--- [ 9.429400] RIP: 0010:simple_xattr_set+0x27/0x8b0 [ 9.432229] Code: 90 90 90 0f 1f 40 d6 0f 1f 44 00 00 55 48 89 e5 41 57 41 56 49 89 d6 41 55 49 89 f5 4c 89 c6 41 54 53 48 83 e4 f0 48 83 ec 40 <4c> 8b 27 44 89 4c 24 3c 4c 89 6c 24 20 48 89 54 24 28 4d 85 e4 0f [ 9.442394] RSP: 0018:ffffd1334001fa20 EFLAGS: 00010282 [ 9.445458] RAX: ffff89974107e460 RBX: ffffffff856b2f80 RCX: ffff899758b0ef60 [ 9.449465] RDX: ffffffff856b2f80 RSI: 000000000000001e RDI: 00000000000000e0 [ 9.453436] RBP: ffffd1334001fa90 R08: 000000000000001e R09: 0000000000000001 [ 9.457506] R10: ffff89974107e460 R11: 0030733a745f7075 R12: 000000000000001e [ 9.461589] R13: ffff89974107e498 R14: ffffffff856b2f80 R15: ffff8997443c5440 [ 9.465681] FS: 00007fc098c74500(0000) GS:ffff899ae8a58000(0000) knlGS:0000000000000000 [ 9.470290] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 9.473702] CR2: 00000000000000e0 CR3: 00000001013d1000 CR4: 00000000003506f0 [ 9.477743] Kernel panic - not syncing: Fatal exception [ 9.481889] Kernel Offset: 0x2a00000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) [ 9.487771] ---[ end Kernel panic - not syncing: Fatal exception ]---
Greg Kroah-Hartman
maintainerQuoted 55 lines · Miklos Szeredi
[Cc: Greg KH]
Quoted 35 lines · Calum Mackay
hi Christian, Miklos,
https://lore.kernel.org/all/177945382308.2991556.1256192774754909984.b4-ty@b4/
Quoted 22 lines
Quoted 1 line · Miklos Szeredi
tmpfs: simplify constructing "security.foo" xattr names
Thanks, this looks great!
---
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.miscQuoted 6 lines
[1/3] tmpfs: simplify constructing "security.foo" xattr names
https://git.kernel.org/vfs/vfs/c/aba5853b137b [2/3] simple_xattr: change interface to pass struct simple_xattrs ** https://git.kernel.org/vfs/vfs/c/1cd9d2387c05 [3/3] simpe_xattr: use per-sb cache https://git.kernel.org/vfs/vfs/c/12e9e3cd03b5Quoted 5 lines
I have been doing some testing of Chuck's nfsd-testing tree, which includes some vfs changes.
The test systems are reliably crashing, in what looks like it might possibly be something related to these three patches.
Calum, thanks for the report.
Relevant part of call trace is:
kernfs_new_node
__kernfs_new_node
security_kernfs_init_security
selinux_kernfs_init_security
kernfs_xattr_set
kernfs_root
Quoted 4 lines
Since
__parentis assigned aftersecurity_kernfs_init_security()gets called,kernfs_root()will return NULL.Greg, any idea about dealing with this?
Don't call this so early? :)
I really don't know, sorry.
greg k-h
Christian Brauner
maintainerQuoted 34 lines · Calum Mackay
hi Christian, Miklos,
https://lore.kernel.org/all/177945382308.2991556.1256192774754909984.b4-ty@b4/
Quoted 22 lines
Quoted 1 line · Miklos Szeredi
tmpfs: simplify constructing "security.foo" xattr names
Thanks, this looks great!
---
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.miscQuoted 6 lines
[1/3] tmpfs: simplify constructing "security.foo" xattr names
https://git.kernel.org/vfs/vfs/c/aba5853b137b [2/3] simple_xattr: change interface to pass struct simple_xattrs ** https://git.kernel.org/vfs/vfs/c/1cd9d2387c05 [3/3] simpe_xattr: use per-sb cache https://git.kernel.org/vfs/vfs/c/12e9e3cd03b5
Quoted 5 lines
I have been doing some testing of Chuck's nfsd-testing tree, which includes some vfs changes.
The test systems are reliably crashing, in what looks like it might possibly be something related to these three patches.
The appended patch should fix it.
From 6358bc199a5be450bd11dd7607918dcad4030b86 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Tue, 26 May 2026 10:57:06 +0200
Subject: [PATCH] kernfs: link kn to its parent before the LSM init hook
After commit 12e9e3cd03b5 ("simpe_xattr: use per-sb cache"), kernfs_xattr_set() and kernfs_xattr_get() compute the cache via kernfs_root(kn) before any other check. kernfs_root(kn) walks kn->__parent first and falls back to kn->dir.root, both of which are NULL on a freshly kmem_cache_zalloc()'d kn. kn->__parent was being set in kernfs_new_node() after __kernfs_new_node() returned, and kn->dir.root is set even later by kernfs_create_dir_ns() / kernfs_create_empty_dir().
The LSM kernfs_init_security hook is invoked from inside __kernfs_new_node(), before either field has been initialized. selinux_kernfs_init_security() ends with kernfs_xattr_set(kn, XATTR_NAME_SELINUX, ...). kernfs_root(kn) then returns NULL, and &((struct kernfs_root *)NULL)->xa_cache evaluates to offsetof(struct kernfs_root, xa_cache) which faults:
BUG: kernel NULL pointer dereference, address: 00000000000000e0 RIP: 0010:simple_xattr_set+0x27/0x8b0 Call Trace: kernfs_xattr_set+0x63/0xb0 selinux_kernfs_init_security+0x13b/0x270 security_kernfs_init_security+0x36/0xc0 __kernfs_new_node+0x182/0x290 kernfs_new_node+0x80/0xc0 kernfs_create_dir_ns+0x2b/0xa0 cgroup_create+0x116/0x380 cgroup_mkdir+0x7c/0x1a0
Reproduces deterministically at PID 1 (systemd) on an SELinux-enabled distro. The first cgroup mkdir under /sys/fs/cgroup with a labelled parent panics the kernel.
The LSM hook's contract is that the kn_dir argument is the parent of the new kn, so kn->__parent should already point at kn_dir when the hook runs. Move kernfs_get(parent) and rcu_assign_pointer of kn->__parent from kernfs_new_node() into __kernfs_new_node() right before the security hook, and unwind the parent reference on the err_out4 path. kernfs_root(kn) then takes its parent branch during the hook and returns parent->dir.root, which is the correct root.
This also closes the same-shape latent bug in kernfs_xattr_get() (which today is hidden only by kernfs_iattrs_noalloc() returning NULL on a fresh kn).
--- fs/kernfs/dir.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/kernfs/dir.c +5 -4
@@ -698,6 +698,9 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root, }if (parent) { +kernfs_get (parent); +rcu_assign_pointer (kn->__parent, parent); + ret =security_kernfs_init_security (parent, kn);if (ret) goto err_out4;
@@ -706,6 +709,8 @@ static struct kernfs_node *__kernfs_new_node(struct kernfs_root *root,return kn; err_out4: +RCU_INIT_POINTER (kn->__parent,NULL ); +kernfs_put (parent);if (kn->iattr) {simple_xattrs_free (&root->xa_cache, &kn->iattr->xattrs,NULL );kmem_cache_free (kernfs_iattrs_cache, kn->iattr);
@@ -742,10 +747,6 @@ struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, kn =__kernfs_new_node (kernfs_root (parent), parent, name, mode, uid, gid, flags); -if (kn) { -kernfs_get (parent); -rcu_assign_pointer (kn->__parent, parent); - }return kn; }
Signature · 1 line
2.47.3
Calum Mackay
Tested-byQuoted 35 lines · Christian Brauner
Quoted 34 lines · Calum Mackay
hi Christian, Miklos,
https://lore.kernel.org/all/177945382308.2991556.1256192774754909984.b4-ty@b4/
Quoted 28 lines
Quoted 1 line · Miklos Szeredi
tmpfs: simplify constructing "security.foo" xattr names
Thanks, this looks great!
---
Applied to the vfs-7.2.misc branch of the vfs/vfs.git tree. Patches in the vfs-7.2.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-7.2.misc[1/3] tmpfs: simplify constructing "security.foo" xattr names
https://git.kernel.org/vfs/vfs/c/aba5853b137b [2/3] simple_xattr: change interface to pass struct simple_xattrs ** https://git.kernel.org/vfs/vfs/c/1cd9d2387c05 [3/3] simpe_xattr: use per-sb cache https://git.kernel.org/vfs/vfs/c/12e9e3cd03b5
Quoted 7 lines
Quoted 5 lines
I have been doing some testing of Chuck's nfsd-testing tree, which includes some vfs changes.
The test systems are reliably crashing, in what looks like it might possibly be something related to these three patches.
The appended patch should fix it.
Looks good to me, thanks Christian; no more crashes with that patch.
best wishes,
calum.