__scoped_user_access(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ NAME πŸ¦‹

okay so bestie, welcome to the Kernel API Manual ✨ β€” this page is all about __scoped_user_access, and its whole job is literally just opening a scope for user access. That's it. That's the vibe. πŸŽ€


🌸 SYNOPSIS 🌸

__scoped_user_access (mode , uptr , size , elbl );

πŸ’… ARGUMENTS πŸ’…

  • mode β€” the mode of the access class: read, write, or rw. pick your fighter bestie 🫢
  • uptr β€” the pointer to access user space memory. the actual address we're messing with ✨
  • size β€” size of the access. how much we're touching, no cap πŸ“
  • elbl β€” the error label to goto when the access region is rejected. it must be placed outside the scope, okay? outside. don't put it inside, that's the whole point πŸ™ˆ

πŸ”₯ DESCRIPTION πŸ”₯

so if the user access function inside the scope needs a fault label, it can use elbl β€” or a totally different label outside the scope β€” and that requires the user access implemented with ASM GOTO to be properly wrapped. for reference, go look at unsafe_get_user. iykyk πŸ’œ

like, fr fr, here's the shape of it:

scoped_user_rw_access(ptr, efault) {
    unsafe_get_user(rval, ptr->rval, efault);
    unsafe_put_user(wval, ptr->wval, efault);
}
return 0;
efault:
return -EFAULT;

the scope is internally implemented as an autoterminating nested for loop, which can be left with 'return', 'break', and 'goto' at any point. yes bestie, any point. slay πŸ’…

when the scope is left, user_##_mode##_access_end is automatically invoked. no manual cleanup era, it just happens ✨

when the architecture supports masked user access and the access region (determined by uptr and size) is not a valid user space address, i.e. < TASK_SIZE, the scope sets the pointer to a faulting user space address and does not terminate early. this optimizes for the good case and lets the performance uncritical bad case go through the fault. main character optimization energy honestly πŸ‘‘

the eventual modification of the pointer is limited to the scope. outside of the scope the original pointer value is unmodified, so that the original pointer value is available for diagnostic purposes in an out of scope fault path. cute AND useful πŸŽ€

⚠️ nesting scoped user access into a user access scope is invalid and fails the build. like it will not compile, bestie, do not try it 😭 nesting into other guards, e.g. pagefault, is safe though 🫢

the masked variant does not check the size of the access and relies on a mapping hole (e.g. guard page) to catch an out of range pointer β€” the first access to user memory inside the scope has to be within uptr ... uptr + PAGE_SIZE - 1. read that range carefully, it's giving very specific 🧚

πŸ’€ Don't use directly. Use scoped_masked_user_$MODE_access instead. periodt.

🌈 SEE ALSO 🌈

kernel file ./include/linux/uaccess.h, plus all these icons πŸ‘‘:


okay that's the whole page bestie, go be iconic with your scopes πŸ’– this one came from ./include/linux, dated October 2026, and it's the __scoped_user_access(9) page β€” catch you in the next manpage, mwah πŸ“βœ¨

πŸ“¦ where this page comes from