How to check root powers on a struct proc ?

Aziz Kezzou french.linuxian at gmail.com
Fri Jun 17 18:23:06 GMT 2005


> Aziz Kezzou wrote:
> > Hi all,
> > I am trying to check that a process (struct proc) has root powers when
> > it calls my KLD system call.
> > I know from kern_jail.c that I can use suser() but this function takes
> > a struct thread* instead of struct proc* although the credentials
> > (struct ucred *p_ucred;) are stored in proc !
> 
> no.. the thread has a credential that it inherrits from the proc.
> when a thread changes the credential of the process as a whole, the
> other threads in the kernel don't notice until they return from their
> syscalls.. in the mean time they continue to use the reference they
> hold to the old credential. This is so that a credential doesn;t change half way
> through a syscall.  the active credential at entry will be the active credential
> for that thread until it completes its time in the kernel.
> 
> >
> > Is there an esay way to get a struct thread* from a struct proc* ? or
> > should I simply use the function:  int suser_cred(struct ucred *cred,
> > int flag); with cred = p-> p_ucred
> 
> why get a struct proc?  the thread has a pointer to the cred it is running
> under.
> 
> 

I probably didn't make myself clear enough.
When my KLD system call is called I get a reference on the calling
process as "struct proc *p". Now how do I check if the calling process
has root powers ?

Would the following work  ? :
static int ukcoe_register_ud( struct proc *p, struct
ukcoe_register_ud_args* arg ) {
int error;
error = suser_cred(p->p_cred, 0);
if(error) return error;

/* do the actual work*/
return 0;
}

Thanks,
-aziz


More information about the freebsd-hackers mailing list