KERNACC(9)

✨ KERNACC(9) ✨

okay bestie, so this is a Kernel Developer's Manual page β€” section 9, the deep-magic zone where only the brave hang out πŸ’…. It's called kernacc and useracc, and it's literally just "can we touch this memory or not" energy. Let's get into it 🫢


🌸 NAME 🌸

kernacc, useracc β€” check memory regions for accessibility πŸ‘€


πŸŽ€ SYNOPSIS πŸŽ€

first, the vibes (the includes, don't skip them, they're load-bearing):

#include <sys/param.h>
#include <sys/proc.h>
#include <vm/vm.h>
#include <vm/vm_extern.h>

then the actual icons themselves:

int
kernacc(void *addr, int len, int rw);

int
useracc(void *addr, int len, int rw);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea β˜• β€” kernacc() and useracc() are your little vibe checkers. They look at the range of virtual addresses described by addr and len and ask: is this operation actually allowed here? The operation being checked is whatever you passed in rw.

And what can rw even be, you ask? It's any bitwise combination of these three baddies:

  • VM_PROT_READ
  • VM_PROT_WRITE
  • VM_PROT_EXECUTE

not me saying you can absolutely OR them together like a little permissions smoothie πŸ“

The two functions are basically sisters, but they live in different neighborhoods:

  • kernacc() checks addresses up in the kernel address space πŸ‘‘
  • useracc() treats addr as a user space address 🏠

and here's the plot twist β€” the process context used for this whole operation gets taken from the global variable curproc. not passed in, just… scooped out of the global. we'll circle back to that in BUGS bestie, don't worry 😭


🌈 RETURN VALUES 🌈

both functions keep it simple, iconic, no notes:

  • they return boolean true if the type of access you specified in rw is permitted ✨
  • otherwise they return boolean false πŸ’€

πŸ’€ BUGS πŸ’€

the process pointer should be passed in as an argument to useracc().

fr fr. that's it. that's the bug. it's lowkey just vibing off curproc instead of taking it as a parameter πŸ™ˆ


and that's a wrap, bestie 🫢 this page came from the Debian crew, dated June 16, 1996 β€” yes, 1996, the manual page is older than most of the people reading it, and it's still serving πŸ’œβœ¨ slay, periodt.

πŸ“¦ where this page comes from