bpf_copy_from_user_str(9)
π bpf_copy_from_user_str(9) β Kernel API Manual π
okay so bestie, welcome to the section 9 glow-up: we're talking bpf_copy_from_user_str, the kfunc that grabs a string out of unsafe user space and drops it safely into kernel space. no cap, this one's a little baddie. β¨
πΈ SYNOPSIS πΈ
__bpf_kfunc int bpf_copy_from_user_str (void *dst , u32 dst__sz , const
void __user *unsafe_ptr__ign , u64 flags );
literally the whole vibe in one line. let's break it down π
π«Ά ARGUMENTS π«Ά
dstβ the destination address, and it lives in kernel space. heads up: this buffer must be at leastdst__szbytes long, no exceptions, she needs room to breathe.dst__szβ the maximum number of bytes to copy, and yes that count includes the trailing NUL. the NUL is invited to the party too πunsafe_ptr__ignβ the source address, and it's in user space. hence the name, bestie, it's unsafe β treat it with the respect (and suspicion) it deserves.flagsβ the only supported flag isBPF_F_PAD_ZEROS. that's it. that's the whole menu. π
β DESCRIPTION β
so what does she actually do? she copies a NUL-terminated string from userspace into BPF space. simple, iconic, effective. π
if the user string is too long, she'll still make sure there's zero termination in the dst buffer β the only exception being if the buffer size is 0, in which case, well, there's nowhere to put a NUL. π
and if the BPF_F_PAD_ZEROS flag is set? she goes full main character: memset the tail of dst to 0 on success, and memset all of dst on failure. zeroes everywhere, no crumbs left behind. π
π SEE ALSO π
the kernel file ./kernel/bpf/helpers.c, plus this entire friend group right here (yes, all of them, we're listing every single one, nobody gets left on read π«Ά):
bpf_obj_new(9),bpf_percpu_obj_new(9),bpf_obj_drop(9),bpf_percpu_obj_drop(9)bpf_refcount_acquire(9),bpf_list_push_front(9),bpf_list_push_back(9),bpf_rbtree_add(9)bpf_task_acquire(9),bpf_task_release(9)bpf_cgroup_acquire(9),bpf_cgroup_release(9),bpf_cgroup_ancestor(9),bpf_cgroup_from_id(9),bpf_task_under_cgroup(9),bpf_task_get_cgroup1(9),bpf_task_from_pid(9),bpf_task_from_vpid(9)bpf_dynptr_slice(9),bpf_dynptr_slice_rdwr(9),bpf_dynptr_copy(9),bpf_dynptr_memset(9)bpf_iter_bits_new(9),bpf_iter_bits_next(9),bpf_iter_bits_destroy(9)bpf_copy_from_user_task_str(9)bpf_strcmp(9),bpf_strcasecmp(9),bpf_strnchr(9),bpf_strchr(9),bpf_strchrnul(9),bpf_strrchr(9),bpf_strnlen(9),bpf_strlen(9),bpf_strspn(9),bpf_strcspn(9),bpf_strstr(9),bpf_strcasestr(9),bpf_strnstr(9),bpf_strncasestr(9)bpf_lookup_user_key(9),bpf_lookup_system_key(9),bpf_key_put(9),bpf_verify_pkcs7_signature(9)bpf_task_work_schedule_signal(9),bpf_task_work_schedule_resume(9),bpf_timer_cancel_async(9)
π reminder bestie:unsafe_ptr__ignis a user pointer in a kernel function. the__ignis basically the kernel going "i'm ignoring the address-space annotation on purpose, don't @ me". stay safe out there. π
okay that's the whole page, and now the cute sign-off: this little masterpiece lives in ./kernel/bpf, it's dated October 2026 (yes, future queen behavior β³), from the Kernel API Manual. and page bpf_copy_from_user_str(9)? she ate. periodt. ππ
π¦ 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