Cleaned up table. Moved policies to table.
Small fixes to do_copy, do_privctl and do_fork.
This commit is contained in:
@@ -27,7 +27,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
* are two different system calls so that permissions can be checked.
|
||||
*/
|
||||
struct vir_addr vir_addr[2]; /* virtual source and destination address */
|
||||
vir_bytes bytes; /* number of bytes to copy */
|
||||
phys_bytes bytes; /* number of bytes to copy */
|
||||
int i;
|
||||
|
||||
/* Dismember the command message. */
|
||||
|
||||
@@ -32,17 +32,19 @@ register message *m_ptr; /* pointer to request message */
|
||||
rpc = proc_addr(m_ptr->PR_PROC_NR);
|
||||
if (isemptyp(rpp) || ! isemptyp(rpc)) return(EINVAL);
|
||||
|
||||
/* If this is a system process, make sure the child process gets its own
|
||||
* privilege structure for accounting. This is the only part that can fail,
|
||||
* so do this before allocating the process table slot.
|
||||
#if DEAD_CODE
|
||||
/* If the parent is a privileged process, ensure the child process also gets
|
||||
* its own privilege structure for accounting. This is the only part that can
|
||||
* fail, so do this before allocating the process table slot.
|
||||
*/
|
||||
if (priv(rpc)->s_flags & SYS_PROC) {
|
||||
if (priv(rpp)->s_flags & SYS_PROC) {
|
||||
if (OK != (i=get_priv(rpc, SYS_PROC))) return(i); /* get structure */
|
||||
for (i=0; i< BITMAP_CHUNKS(NR_SYS_PROCS); i++) /* remove pending: */
|
||||
priv(rpc)->s_notify_pending.chunk[i] = 0; /* - notifications */
|
||||
priv(rpc)->s_int_pending = 0; /* - interrupts */
|
||||
sigemptyset(&priv(rpc)->s_sig_pending); /* - signals */
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Copy parent 'proc' struct to child. And reinitialize some fields. */
|
||||
#if (CHIP == INTEL)
|
||||
@@ -63,6 +65,14 @@ register message *m_ptr; /* pointer to request message */
|
||||
rpc->p_user_time = 0; /* set all the accounting times to 0 */
|
||||
rpc->p_sys_time = 0;
|
||||
|
||||
/* If the parent is a privileged process, take away the privileges from the
|
||||
* child process and inhibit it from running by setting the NO_PRIV flag.
|
||||
* The caller should explicitely set the new privileges before executing.
|
||||
*/
|
||||
if (priv(rpp)->s_flags & SYS_PROC) {
|
||||
rpc->p_priv = priv_addr(USER_PRIV_ID);
|
||||
rpc->p_rts_flags |= NO_PRIV;
|
||||
}
|
||||
return(OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
* m_type: SYS_PRIVCTL
|
||||
*
|
||||
* The parameters for this system call are:
|
||||
* m2_i1: CTL_PROC_NR (process number of caller)
|
||||
* m1_i1: PR_PROC_NR (process number of caller)
|
||||
*/
|
||||
|
||||
#include "../system.h"
|
||||
#include "../ipc.h"
|
||||
#include <signal.h>
|
||||
|
||||
#if USE_PRIVCTL
|
||||
|
||||
#define FILLED_MASK (~0)
|
||||
|
||||
/*===========================================================================*
|
||||
* do_privctl *
|
||||
*===========================================================================*/
|
||||
@@ -19,21 +22,40 @@ message *m_ptr; /* pointer to request message */
|
||||
/* Handle sys_privctl(). Update a process' privileges. If the process is not
|
||||
* yet a system process, make sure it gets its own privilege structure.
|
||||
*/
|
||||
register struct proc *caller_ptr;
|
||||
register struct proc *rp;
|
||||
register struct priv *sp;
|
||||
int proc_nr;
|
||||
int priv_id;
|
||||
int old_flags;
|
||||
int i;
|
||||
|
||||
/* Extract message parameters. */
|
||||
proc_nr = m_ptr->CTL_PROC_NR;
|
||||
if (proc_nr == SELF) proc_nr = m_ptr->m_source;
|
||||
/* Check whether caller is allowed to make this call. Privileged proceses
|
||||
* can only update the privileges of processes that are inhibited from
|
||||
* running by the NO_PRIV flag. This flag is set when a privileged process
|
||||
* forks.
|
||||
*/
|
||||
caller_ptr = proc_addr(m_ptr->m_source);
|
||||
if (! (priv(caller_ptr)->s_flags & SYS_PROC)) return(EPERM);
|
||||
proc_nr = m_ptr->PR_PROC_NR;
|
||||
if (! isokprocn(proc_nr)) return(EINVAL);
|
||||
|
||||
rp = proc_addr(proc_nr);
|
||||
if (! (rp->p_rts_flags & NO_PRIV)) return(EPERM);
|
||||
|
||||
/* Make sure this process has its own privileges structure. */
|
||||
if (! (priv(rp)->s_flags & SYS_PROC))
|
||||
if ((i=get_priv(rp, SYS_PROC)) != OK) return(i);
|
||||
/* Make sure this process has its own privileges structure. This may fail,
|
||||
* since there are only a limited number of system processes. Then copy the
|
||||
* privileges from the caller and restore some defaults.
|
||||
*/
|
||||
if ((i=get_priv(rp, SYS_PROC)) != OK) return(i);
|
||||
priv_id = priv(rp)->s_id; /* backup privilege id */
|
||||
*priv(rp) = *priv(caller_ptr); /* copy privileges */
|
||||
priv(rp)->s_id = priv_id; /* restore privilege id */
|
||||
priv(rp)->s_proc_nr = proc_nr; /* reassociate process nr */
|
||||
|
||||
for (i=0; i< BITMAP_CHUNKS(NR_SYS_PROCS); i++) /* remove pending: */
|
||||
priv(rp)->s_notify_pending.chunk[i] = 0; /* - notifications */
|
||||
priv(rp)->s_int_pending = 0; /* - interrupts */
|
||||
sigemptyset(&priv(rp)->s_sig_pending); /* - signals */
|
||||
|
||||
/* Now update the process' privileges as requested. */
|
||||
rp->p_priv->s_call_mask = FILLED_MASK;
|
||||
@@ -50,6 +72,11 @@ message *m_ptr; /* pointer to request message */
|
||||
set_sys_bit(priv_addr(i)->s_send_mask, priv_id(rp));
|
||||
}
|
||||
}
|
||||
|
||||
/* Done. Privileges have been set. Allow process to run again. */
|
||||
old_flags = rp->p_rts_flags; /* save value of the flags */
|
||||
rp->p_rts_flags &= ~NO_PRIV;
|
||||
if (old_flags != 0 && rp->p_rts_flags == 0) lock_ready(rp);
|
||||
return(OK);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user