strnlen_user_nofault(9)
π strnlen_user_nofault π
okay bestie, welcome to the kernel API manual for strnlen_user_nofault β yes that name is a mouthful, yes it's iconic, and yes we're gonna get through it together π«Ά
β¨ NAME β¨
strnlen_user_nofault β get the size of a user string INCLUDING the final NUL π
πΈ SYNOPSIS πΈ
long strnlen_user_nofault (const void __user *unsafe_addr , long count );
that's the whole signature, no cap. take it in. π
π¦ ARGUMENTS π¦
unsafe_addrβ the string we're measuring, literally. give it the address, it gives you the length π§countβ the maximum count, and yes that includes the NUL bestie, don't forget the NUL π
π DESCRIPTION π
So what does it do? It gets the size of a NUL-terminated string in user space without pagefault β¨ like, it just does it. no faulting, no drama.
It returns the size of the string INCLUDING the terminating NUL, periodt π
Now here's the part where you gotta pay attention: if the string is too long, it returns a number larger than count. so you, the caller, have to check the return value against "> count" yourself. that's on you, bestie π
And on exception (or an invalid count), it returns 0. zero. zilch. π
Unlike strnlen_user, this one can be used from an IRQ handler etc. because it disables pagefaults π₯ that's the whole glow-up, iykyk. (and also, lowkey, the reason it's "nofault" β the name is giving exactly what it should π
)
π SEE ALSO π
- the kernel file
./mm/maccess.cβ go read it, bestie, it's where the magic lives π copy_from_user_nofault(9)copy_to_user_nofault(9)strncpy_from_user_nofault(9)
and that's the page!! π this lil' beauty lives in ./mm and it's dated October 2026 β so yeah, mark your calendar, screenshot it, send it to the group chat, whatever you gotta do ππ mwah, go measure those strings responsibly π
β¨
π¦ 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