memdup_user(9)
π 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'skfree, okay? notvfree, notkfree_const, not vibes.kfree. π
π¦ SEE ALSO π¦
all her friends and mutuals, in the kernel file ./mm/util.c π:
kfree_const(9)__kmemdup_nul(9)kstrdup(9)kstrdup_const(9)kstrndup(9)kmemdup(9)kmemdup_array(9)kvmemdup(9)kmemdup_nul(9)vmemdup_user(9)strndup_user(9)memdup_user_nul(9)randomize_page(9)__account_locked_vm(9)account_locked_vm(9)__vmalloc_array(9)vmalloc_array(9)__vcalloc(9)vcalloc(9)folio_mapping(9)folio_copy(9)get_cmdline(9)mem_dump_obj(9)compat_set_desc_from_vma(9)__compat_vma_mmap(9)compat_vma_mmap(9)snapshot_page(9)mmap_action_prepare(9)mmap_action_complete(9)folio_pte_batch(9)page_range_contiguous(9)
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
- 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