memdup_user(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– memdup_user(9) β€” or, "bestie, let's copy that user memory" πŸ’–

okay so picture this: you're in kernel land (Kernel API Manual energy ✨), and there's a blob of memory sitting over in user space that you desperately need a copy of. memdup_user is literally the ✨ icon ✨ that does that for you. It duplicates a memory region from user space. periodt. 🫢


✨ SYNOPSIS ✨

void * memdup_user (const void __user *src , size_t len );

like, that's it. that's the whole vibe check. πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • src β€” the source address in user space 🌸 (yes, user space, hence the __user β€” she knows where she's from)
  • len β€” the number of bytes to copy πŸ“ (count them, bestie, don't guess)

πŸ’€ RETURN πŸ’€

so on failure you get an ERR_PTR back 😭 β€” check it, fr fr, don't just start dereferencing and hope for the best.

the result you do get is physically contiguous, and it's meant to be freed by kfree. so like, that's her designated cleanup routine, no cap. πŸ‘‘

⚠️ heads up bestie: it's kfree, okay? not vfree, not kfree_const, not vibes. kfree. πŸ’…

πŸ¦‹ SEE ALSO πŸ¦‹

all her friends and mutuals, in the kernel file ./mm/util.c πŸ’œ:

like, the whole group chat is in there 🌈 go say hi πŸ‘‹


and that's the page, bestie πŸ§šβ€β™€οΈ this whole thing lives under ./mm and it's dated October 2026 ⭐ β€” memdup_user(9), signing off πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from