vmemdup_user(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ vmemdup_user β€” the kernel API manual, but make it make sense ✨

okay so bestie, this is a page from the Kernel API Manual (section 9, the kernel-API girlies) and we're talking about vmemdup_user β€” literally one of the most useful little functions in the whole mm friend group πŸ’–


🌸 NAME 🌸

vmemdup_user β€” duplicate a memory region that lives in user space 🫢

like, you've got a blob of memory over in userspace and you want your very own kernel-side copy? that's her. that's the whole job.


πŸŽ€ SYNOPSIS πŸŽ€

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

so you hand her a src and a len and she hands you back a void *. iconique. no cap.


πŸ¦‹ ARGUMENTS πŸ¦‹

  • src β€” the source address, and bestie it is in user space. mind the __user annotation, she's not kidding around πŸ’…
  • len β€” number of bytes to copy. that's it. that's the size. how many bytes. πŸ“

🌈 RETURN 🌈

lowkey the important part, so pay attention:

  • on failure you get back an ERR_PTR β€” so fr fr check it, don't just start dereferencing 😭
  • heads up: the result may be not physically contiguous 🫠 so don't go assuming anything about physical layout
  • and when you're done with it, free it with kvfree. periodt. not kfree, not vfree, kvfree. πŸ‘‘

πŸ’œ SEE ALSO πŸ’œ

this list is long but we do not skip, we do not summarise, we respect the whole squad. the kernel file is ./mm/util.c and here's everybody:


bestie reminder: ERR_PTR check first, kvfree to clean up, and don't assume it's physically contiguous. that's the whole vibe check πŸ’€

and that's the page!! sourced from the ./mm directory, dated October 2026, and filed under vmemdup_user(9) β€” mwah, go write some good kernel code, i'm obsessed with you already πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from