Skip to contentSkip to conversation

bpf: Read security.bpf xattrs without caller's permission

PATCH New Daniel Borkmann 2 participants 2 messages Nov 25

Subsystems (2)
lore
Share & tools
lore

Daniel Borkmann

author maintainer
#0 lore raw

PATCH 1/1 bpf: Read security.bpf xattrs without caller's permission

bpf_get_dentry_xattr() and bpf_get_file_xattr() check that the current task may read the inode before they return an xattr, for user. and security.bpf. prefixes. A BPF LSM prog keeps its own labels under security.bpf., yet the permission check is on the task, so the read fails with -EACCES e.g. on exec of an execute-only binary or unlink of a file the task cannot read. SELinux and Smack read their own labels with __vfs_getxattr() and no such check, and xattr_permission() does not restrict security.* reads either. Thus, skip the permission check for security.bpf. names.

Fixes 531118f1ccfc ("fs/xattr: bpf: Introduce security.bpf. xattr name prefix")
Cc Song Liu <[email protected]>
---
 fs/bpf_fs_kfuncs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/bpf_fs_kfuncs.c +3 -2
index 35ccd98a4de6..d60093c1401a 100644
@@ -107,8 +107,9 @@ static int bpf_xattr_read_permission(const char *name, struct inode *inode)
 		return -EINVAL;
 
 	/* Allow reading xattr with user. and security.bpf. prefix */
-	if (strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
-	    !match_security_bpf_prefix(name))
+	if (match_security_bpf_prefix(name))
+		return 0;
+	if (strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
 		return -EPERM;
 
 	return inode_permission(&nop_mnt_idmap, inode, MAY_READ);
Signature · 1 line
2.43.0
#1 lore raw
TL;DR: Skipping inode_permission() for security.bpf. xattrs may let a sleepable BPF LSM program send FUSE_GETXATTR to an untrusted server for disallowed tasks, possibly hanging root's statfs in D…
Quoted 1 line

bpf: Read security.bpf xattrs without caller's permission

TL;DR: Skipping inode_permission() for security.bpf. xattrs may let a sleepable BPF LSM program send FUSE_GETXATTR to an untrusted server for disallowed tasks, possibly hanging root's statfs in D state. Should FUSE still be refused?

Quoted 3 lines
fs/bpf_fs_kfuncs.c +0 -0

[ ... ]

fs/bpf_fs_kfuncs.c static int bpf_xattr_read_permission(const char *name, struct inode *inode) · line 115

Quoted 12 lines
fs/bpf_fs_kfuncs.c +3 -2
@@ -107,8 +107,9 @@ static int bpf_xattr_read_permission(const char *name, struct inode *inode)
 		return -EINVAL;
 
 	/* Allow reading xattr with user. and security.bpf. prefix */
-	if (strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) &&
-	    !match_security_bpf_prefix(name))
+	if (match_security_bpf_prefix(name))
+		return 0;
+	if (strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
 		return -EPERM;
 
 	return inode_permission(&nop_mnt_idmap, inode, MAY_READ);

A subsystem pattern flags this as potentially concerning. For security.bpf. names, bpf_get_dentry_xattr() now goes straight to __vfs_getxattr() without inode_permission(). On FUSE that reaches:

fuse_xattr_get()
fuse_getxattr()
fuse_simple_request(FUSE_GETXATTR)

and fuse_xattr_get() never calls fuse_allow_current_process(). Before this change, inode_permission() reached fuse_permission(), which returns -EACCES without sending a request when !fuse_allow_current_process(fc).

Can this send FUSE_GETXATTR to an untrusted server on behalf of a task the mount owner does not allow? For example, sb_statfs is a sleepable LSM hook that receives a trusted struct dentry *. If a sleepable BPF LSM program calls bpf_get_dentry_xattr(dentry, "security.bpf.<x>", ...) there, and an unprivileged user has mounted a FUSE filesystem without allow_other, then root calling statfs() (e.g. df, or statfs on /proc/<pid>/cwd) goes:

statfs_by_dentry()
security_sb_statfs(dentry)

with no prior inode_permission() on an inode of that connection. Previously the result was -EACCES with no request sent. Now the request is sent, and request_wait_answer() ends in an uninterruptible wait until the server replies, so a non-replying server can hang root's statfs in D state.

The commit message compares this to SELinux and Smack reading labels with __vfs_getxattr(). Those LSMs cache the label in the inode blob at d_instantiate or mount time, in the context of a task that already passed the FUSE checks, whereas a BPF LSM program may read security.bpf. on every hook invocation.

Mitigating context: this only applies when an admin-loaded sleepable BPF LSM program reads security.bpf. xattrs in such a hook, the user. prefix is unaffected, and security.* xattrs are already readable from userspace without read permission.

Should the security.bpf. path keep refusing FUSE inodes whose connection does not allow the current task, or should the kfunc documentation state that it can block on an untrusted FUSE server for any task?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45706851285