Root Cause Analysis
1. Components and Files Involved
- Source File:
fs/tracefs/inode.c
- Functions:
tracefs_permission(), tracefs_getattr(), and set_tracefs_inode_owner()
- Structures and Fields:
struct inode (i_uid, i_gid)
struct tracefs_inode (flags, private)
- Flags:
TRACEFS_UID_PERM_SET (BIT(3)), TRACEFS_GID_PERM_SET (BIT(2))
2. Mechanism and Lifecycle Violation
In tracefs (fs/tracefs/inode.c), the inode_operations structures for tracefs files and directories define .permission = tracefs_permission and .getattr = tracefs_getattr. Both functions invoke set_tracefs_inode_owner(inode):
static void set_tracefs_inode_owner(struct inode *inode)
{
struct tracefs_inode *ti = get_tracefs(inode);
struct inode *root_inode = ti->private;
kuid_t uid;
kgid_t gid;
uid = root_inode->i_uid;
gid = root_inode->i_gid;
...
if (!(ti->flags & TRACEFS_UID_PERM_SET))
inode->i_uid = uid;
if (!(ti->flags & TRACEFS_GID_PERM_SET))
inode->i_gid = gid;
}
This design violates fundamental VFS concurrency and lifecycle rules:
-
Read-Side VFS Operations Lack Inode Serialization:
In Linux VFS, .permission and .getattr are read-side operations. They are called concurrently across CPUs without holding inode->i_rwsem. In particular, .permission is invoked during pathname resolution (link_path_walk() -> may_lookup() -> inode_permission()), which can occur in lockless RCU-walk or ref-walk mode, as well as during may_open(). VFS assumes that an inode's ownership identity (i_uid and i_gid) is not dynamically mutated during these callbacks.
-
Unconditional, Unlocked Stores on Every File Access:
ti->flags only sets TRACEFS_UID_PERM_SET and TRACEFS_GID_PERM_SET when userspace explicitly invokes setattr (such as chown). For all standard tracefs files and directories where explicit ownership has never been altered, !(ti->flags & TRACEFS_UID_PERM_SET) and !(ti->flags & TRACEFS_GID_PERM_SET) evaluate to true on every single call. As a result, every path lookup, open, permission check, or stat call repeatedly performs plain, unsynchronized writes to inode->i_uid (line 186) and inode->i_gid (line 189), even though these fields were already initialized when the inode was created (tracefs_create_file() / __create_dir()).
3. How the Reported Data Races Occur
Because set_tracefs_inode_owner() mutates inode->i_uid and inode->i_gid without synchronization:
- Write-Write Races (
tracefs_permission vs. tracefs_permission):
Two or more concurrent tasks traversing or opening files in tracefs concurrently execute tracefs_permission() on the same inode, causing simultaneous, unsynchronized stores to inode->i_uid and inode->i_gid.
- Read-Write Self-Races (
tracefs_permission on child vs. parent/root):
When one task checks permissions on an inode whose ti->private points to root_inode, it reads root_inode->i_uid and root_inode->i_gid (lines 160–161). Concurrently, another task accessing root_inode executes tracefs_permission(), writing to root_inode->i_uid and root_inode->i_gid (lines 186, 189).
- Read-Write Races with Core VFS Callers:
Core VFS functions (
link_path_walk(), generic_permission(), acl_permission_check(), may_delete_dentry(), HAS_UNMAPPED_ID()) read inode->i_uid or inode->i_gid via helpers such as i_uid_into_vfsuid() and i_gid_into_vfsgid() while another task on a different CPU is inside set_tracefs_inode_owner() writing to the same fields.