bpf_copy_from_user_str(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 least dst__sz bytes 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 is BPF_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 🫢):


πŸ“ reminder bestie: unsafe_ptr__ign is a user pointer in a kernel function. the __ign is 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