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") Signed-off-by: Daniel Borkmann Cc: Song Liu --- fs/bpf_fs_kfuncs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 35ccd98a4de6..d60093c1401a 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -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); -- 2.43.0