bpf_sock_read_xattr(9)
π bpf_sock_read_xattr(9) π
okay so bestie, welcome to bpf_sock_read_xattr from the Kernel API Manual (section 9, kernel-space kfuncs, we're in the cool part of the manual) π this one's a lil baddie that reads an extended attribute off a socket's inode over in sockfs, and it's honestly so useful. let's get into it β¨
πΈ SYNOPSIS πΈ
__bpf_kfunc int bpf_sock_read_xattr (struct socket *sock , const char
*name__str , struct bpf_dynptr *value_p );
literally three args, that's it, no cap. signature copied exactly, don't @ me π
π¦ ARGUMENTS π¦
sockβ the socket you wanna pull the xattr off of 𧦠this is your main character.name__strβ the name of the xattr you're asking for. yes, the double underscore is real, it's not a typo, keep it fr fr.value_pβ your output buffer where the xattr value lands. the dynptr holds the goods π«Ά
β¨ DESCRIPTION β¨
so what it does: it grabs the xattr name__str belonging to sock and stashes the output into value_p. simple, iconic, done π
but π β for security reasons, only name__str values with the prefix "user." are allowed. like, that's the whole vibe check. anything without that prefix? not happening. the kernel said no π so name your xattrs accordingly, bestie.
β οΈ lowkey important: that"user."prefix restriction isn't a suggestion, it's the rule. don't come crying to me when your"trusted."or"security."name gets rejected π security stays winning.
π₯ RETURN π₯
- on success π β the length of the xattr value
- on error π β a negative value
so like, > 0 (or zero-length, whatever the value length is) = slay, negative = nope. check your returns, always, periodt.
π SEE ALSO π
the whole friend group, all of them, no one left out π«Ά the kernel file lives at ./fs/bpf_fs_kfuncs.c and here's the full squad:
bpf_get_task_exe_file(9)bpf_put_file(9)bpf_path_d_path(9)bpf_get_dentry_xattr(9)bpf_get_file_xattr(9)bpf_set_dentry_xattr_locked(9)bpf_remove_dentry_xattr_locked(9)bpf_set_dentry_xattr(9)bpf_remove_dentry_xattr(9)bpf_cgroup_read_xattr(9)bpf_real_data_inode(9)
and that's the page!! mwah π this drop came straight out of ./fs and it's dated October 2026, so go forth and read those socket xattrs responsibly, bestie πβ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms