Subject: Re: osetre{uid,gid} called by root return EPERM?
To: Jonathan Stone <jonathan@DSG.Stanford.EDU>
From: Chris G. Demetriou <cgd@alpha.bostic.com>
List: port-pmax
Date: 08/23/1994 10:59:15
> When I build a kernel with that kern_prot.c, I can't rsh to the
> machine running a NetBSD kernel and the Ultrix rshd. With
> the version I sent last week (the one that sets the effective
> id) I can.
> 
> Looking at the comments in Theo's latest kern/kern_prot.c:
> 
>        *  N,  N: call setuid(N). This is correct emulation.
> 
>        *  N,  N: call setgid(N). This is correct emulation.
> 
> The assertion above, that set{uid,gid}(n) is correct emulation for
> setre{uid,gid}(N, N) is simply NOT TRUE. Theo's code sets either
> an effective or a real id, and never both. That's not correct
> emulation.

from the code for setuid() in kern_prot.c:

        /*
         * Everything's okay, do it.
         * Transfer proc count to new user.
         * Copy credentials so other references do not see our changes.
         */
        (void)chgproccnt(pc->p_ruid, -1);
        (void)chgproccnt(uid, 1);
        pc->pc_ucred = crcopy(pc->pc_ucred);
        pc->pc_ucred->cr_uid = uid;
        pc->p_ruid = uid;
        pc->p_svuid = uid;
        p->p_flag |= P_SUGID;
        return (0);

the pc->pc_ucred->cr_uid assignment sets the effective uid.
the pc->p_ruid assignment sets the real uid.

i.e. calling setuid(N) or setgid(N) sets both the effective
and real id to N.


cgd

------------------------------------------------------------------------------