Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check for user = root within linux kernel?

I am writing linux kernel code. I am in VFS and I want to modify it. I want to add a check to see whether or not the user is root and based on that make a decision. How do I do this? Is there a kernel version of getuid() ? Or does any structure like "current->" contain info on which user it is for the current process?

like image 579
Agnidev Avatar asked Oct 12 '25 20:10

Agnidev


1 Answers

You can use current_cred() as defined in include/linux/cred.h, which will give you a pointer to a struct cred itself defined in the same header. Something like

  if (current_cred()->uid != 0)
     return -EPERM;
like image 84
Quentin Casasnovas Avatar answered Oct 16 '25 06:10

Quentin Casasnovas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!