vmemdup_user(9)
β¨ 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__userannotation, 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. notkfree, notvfree,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:
kfree_const(9)__kmemdup_nul(9)kstrdup(9)kstrdup_const(9)kstrndup(9)kmemdup(9)kmemdup_array(9)kvmemdup(9)kmemdup_nul(9)memdup_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)
bestie reminder:ERR_PTRcheck first,kvfreeto 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
- 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