strnlen_user(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– strnlen_user(9) πŸ’–

okay bestie, welcome to the strnlen_user glow-up ✨ this one lives in the Kernel API Manual and honestly? it's giving "small function, big opinions." let's get into it 🫢


πŸŽ€ NAME πŸŽ€

strnlen_user β€” get the size of a user string INCLUDING the final NUL. literally what it says on the tin πŸ’…


✨ SYNOPSIS ✨

long strnlen_user (const char __user *str , long count );

like yes, that's the whole signature, she's compact πŸ‘‘


🌸 ARGUMENTS 🌸

  • str β€” the string you want measured, bestie. that's it, that's the vibe πŸ“
  • count β€” the maximum count (including the NUL character). so like, the ceiling, the limit, the "don't go past this" energy 🚧

πŸ¦‹ CONTEXT πŸ¦‹

User context only. and heads up β€” this function may sleep if pagefaults are enabled 😴 so don't be calling it from somewhere weird, iykyk.


πŸ’œ DESCRIPTION πŸ’œ

okay so the actual job: get the size of a NUL-terminated string in user space.

It returns the size of the string INCLUDING the terminating NUL. cute, right?

But β€” if the string is too long, it returns a number larger than count. so the user has to check the return value against > count πŸ‘€ do not skip the vibe check on that return value, fr fr.

On exception (or an invalid count), it returns 0. 😭

⚠️ NOTE! You should basically never use this function. like, genuinely. There is almost never any valid case for using the length of a user space string, since the string can be changed at any time by other threads πŸ’€ it's a moving target, bestie. Use strncpy_from_user instead to get a stable copy of the string. that's the main character move πŸ‘‘

🌈 SEE ALSO 🌈

  • Kernel file ./lib/strnlen_user.c πŸ“

and that's the whole page, no cap ✨ this little icon comes to you from ./lib, October 2026 edition πŸ§šβ€β™€οΈ go forth and use strncpy_from_user instead, bestie, ily πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from