Rewrite of boot process
KERNEL CHANGES: - The kernel only knows about privileges of kernel tasks and the root system process (now RS). - Kernel tasks and the root system process are the only processes that are made schedulable by the kernel at startup. All the other processes in the boot image don't get their privileges set at startup and are inhibited from running by the RTS_NO_PRIV flag. - Removed the assumption on the ordering of processes in the boot image table. System processes can now appear in any order in the boot image table. - Privilege ids can now be assigned both statically or dynamically. The kernel assigns static privilege ids to kernel tasks and the root system process. Each id is directly derived from the process number. - User processes now all share the static privilege id of the root user process (now INIT). - sys_privctl split: we have more calls now to let RS set privileges for system processes. SYS_PRIV_ALLOW / SYS_PRIV_DISALLOW are only used to flip the RTS_NO_PRIV flag and allow / disallow a process from running. SYS_PRIV_SET_SYS / SYS_PRIV_SET_USER are used to set privileges for a system / user process. - boot image table flags split: PROC_FULLVM is the only flag that has been moved out of the privilege flags and is still maintained in the boot image table. All the other privilege flags are out of the kernel now. RS CHANGES: - RS is the only user-space process who gets to run right after in-kernel startup. - RS uses the boot image table from the kernel and three additional boot image info table (priv table, sys table, dev table) to complete the initialization of the system. - RS checks that the entries in the priv table match the entries in the boot image table to make sure that every process in the boot image gets schedulable. - RS only uses static privilege ids to set privileges for system services in the boot image. - RS includes basic memory management support to allocate the boot image buffer dynamically during initialization. The buffer shall contain the executable image of all the system services we would like to restart after a crash. - First step towards decoupling between resource provisioning and resource requirements in RS: RS must know what resources it needs to restart a process and what resources it has currently available. This is useful to tradeoff reliability and resource consumption. When required resources are missing, the process cannot be restarted. In that case, in the future, a system flag will tell RS what to do. For example, if CORE_PROC is set, RS should trigger a system-wide panic because the system can no longer function correctly without a core system process. PM CHANGES: - The process tree built at initialization time is changed to have INIT as root with pid 0, RS child of INIT and all the system services children of RS. This is required to make RS in control of all the system services. - PM no longer registers labels for system services in the boot image. This is now part of RS's initialization process.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <minix/endpoint.h>
|
||||
|
||||
#include "../system.h"
|
||||
#include "../vm.h"
|
||||
@@ -31,6 +32,7 @@ register message *m_ptr; /* pointer to request message */
|
||||
int proc_nr, nr_e, nr, r;
|
||||
struct proc *caller;
|
||||
int wipe_rnd_bin = -1;
|
||||
struct exec e_hdr;
|
||||
|
||||
caller = proc_addr(who_p);
|
||||
|
||||
@@ -84,6 +86,14 @@ register message *m_ptr; /* pointer to request message */
|
||||
src_vir = (vir_bytes) proc_addr(nr);
|
||||
break;
|
||||
}
|
||||
case GET_PRIV: {
|
||||
nr_e = (m_ptr->I_VAL_LEN2_E == SELF) ?
|
||||
who_e : m_ptr->I_VAL_LEN2_E;
|
||||
if(!isokendpt(nr_e, &nr)) return EINVAL; /* validate request */
|
||||
length = sizeof(struct priv);
|
||||
src_vir = (vir_bytes) priv_addr(nr_to_id(nr));
|
||||
break;
|
||||
}
|
||||
case GET_WHOAMI: {
|
||||
int len;
|
||||
/* GET_WHOAMI uses m3 and only uses the message contents for info. */
|
||||
@@ -146,11 +156,6 @@ register message *m_ptr; /* pointer to request message */
|
||||
src_vir = (vir_bytes) irq_actids;
|
||||
break;
|
||||
}
|
||||
case GET_PRIVID: {
|
||||
if (!isokendpt(m_ptr->I_VAL_LEN2_E, &proc_nr))
|
||||
return EINVAL;
|
||||
return proc_addr(proc_nr)->p_priv->s_id;
|
||||
}
|
||||
case GET_IDLETSC: {
|
||||
#ifdef CONFIG_IDLE_TSC
|
||||
length = sizeof(idle_tsc);
|
||||
@@ -161,6 +166,22 @@ register message *m_ptr; /* pointer to request message */
|
||||
return(EINVAL);
|
||||
#endif
|
||||
}
|
||||
case GET_AOUTHEADER: {
|
||||
int hdrindex, index = m_ptr->I_VAL_LEN2_E;
|
||||
if(index < 0 || index >= NR_BOOT_PROCS) {
|
||||
return EINVAL;
|
||||
}
|
||||
if (iskerneln(_ENDPOINT_P(image[index].endpoint))) {
|
||||
hdrindex = 0;
|
||||
} else {
|
||||
hdrindex = 1 + index-NR_TASKS;
|
||||
}
|
||||
arch_get_aout_headers(hdrindex, &e_hdr);
|
||||
length = sizeof(e_hdr);
|
||||
src_vir = (vir_bytes) &e_hdr;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
kprintf("do_getinfo: invalid request %d\n", m_ptr->I_REQUEST);
|
||||
return(EINVAL);
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#if USE_PRIVCTL
|
||||
|
||||
#define FILLED_MASK (~0)
|
||||
|
||||
/*===========================================================================*
|
||||
* do_privctl *
|
||||
*===========================================================================*/
|
||||
@@ -29,6 +27,7 @@ message *m_ptr; /* pointer to request message */
|
||||
register struct proc *rp;
|
||||
int proc_nr;
|
||||
int priv_id;
|
||||
int ipc_to_m, kcalls;
|
||||
int i, r;
|
||||
struct io_range io_range;
|
||||
struct mem_range mem_range;
|
||||
@@ -48,16 +47,49 @@ message *m_ptr; /* pointer to request message */
|
||||
|
||||
switch(m_ptr->CTL_REQUEST)
|
||||
{
|
||||
case SYS_PRIV_INIT:
|
||||
case SYS_PRIV_ALLOW:
|
||||
/* Allow process to run. Make sure its privilege structure has already
|
||||
* been set.
|
||||
*/
|
||||
if (!RTS_ISSET(rp, RTS_NO_PRIV) || priv(rp)->s_proc_nr == NONE) {
|
||||
return(EPERM);
|
||||
}
|
||||
RTS_LOCK_UNSET(rp, RTS_NO_PRIV);
|
||||
return(OK);
|
||||
|
||||
case SYS_PRIV_DISALLOW:
|
||||
/* Disallow process from running. */
|
||||
if (RTS_ISSET(rp, RTS_NO_PRIV)) return(EPERM);
|
||||
RTS_LOCK_SET(rp, RTS_NO_PRIV);
|
||||
return(OK);
|
||||
|
||||
case SYS_PRIV_SET_SYS:
|
||||
/* Set a privilege structure of a blocked system process. */
|
||||
if (! RTS_ISSET(rp, RTS_NO_PRIV)) return(EPERM);
|
||||
|
||||
/* Check whether a static or dynamic privilege id must be allocated. */
|
||||
priv_id = NULL_PRIV_ID;
|
||||
if (m_ptr->CTL_ARG_PTR)
|
||||
{
|
||||
/* Copy privilege structure from caller */
|
||||
if((r=data_copy(who_e, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
SYSTEM, (vir_bytes) &priv, sizeof(priv))) != OK)
|
||||
return r;
|
||||
|
||||
/* See if the caller wants to assign a static privilege id. */
|
||||
if(!(priv.s_flags & DYN_PRIV_ID)) {
|
||||
priv_id = priv.s_id;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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.
|
||||
* Then copy privileges from the caller and restore some defaults.
|
||||
*/
|
||||
if ((i=get_priv(rp, SYS_PROC)) != OK)
|
||||
if ((i=get_priv(rp, priv_id)) != OK)
|
||||
{
|
||||
kprintf("do_privctl: out of priv structures\n");
|
||||
kprintf("do_privctl: unable to allocate priv_id %d: %d\n",
|
||||
priv_id, i);
|
||||
return(i);
|
||||
}
|
||||
priv_id = priv(rp)->s_id; /* backup privilege id */
|
||||
@@ -70,88 +102,109 @@ message *m_ptr; /* pointer to request message */
|
||||
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_trap_mask = FILLED_MASK;
|
||||
|
||||
/* Set a default send mask. */
|
||||
for (i=0; i < NR_SYS_PROCS; i++) {
|
||||
if (i != USER_PRIV_ID)
|
||||
set_sendto_bit(rp, i);
|
||||
else
|
||||
unset_sendto_bit(rp, i);
|
||||
/* Set defaults for privilege bitmaps. */
|
||||
priv(rp)->s_flags= DEF_SYS_F; /* privilege flags */
|
||||
priv(rp)->s_trap_mask= DEF_SYS_T; /* allowed traps */
|
||||
ipc_to_m = DEF_SYS_M; /* allowed targets */
|
||||
kcalls = DEF_SYS_KC; /* allowed kernel calls */
|
||||
for(i = 0; i < CALL_MASK_SIZE; i++) {
|
||||
priv(rp)->s_k_call_mask[i] = (kcalls == NO_C ? 0 : (~0));
|
||||
}
|
||||
|
||||
/* No I/O resources, no memory resources, no IRQs, no grant table */
|
||||
/* Set defaults for resources: no I/O resources, no memory resources,
|
||||
* no IRQs, no grant table
|
||||
*/
|
||||
priv(rp)->s_nr_io_range= 0;
|
||||
priv(rp)->s_nr_mem_range= 0;
|
||||
priv(rp)->s_nr_irq= 0;
|
||||
priv(rp)->s_grant_table= 0;
|
||||
priv(rp)->s_grant_entries= 0;
|
||||
|
||||
/* Override defaults if the caller has supplied a privilege structure. */
|
||||
if (m_ptr->CTL_ARG_PTR)
|
||||
{
|
||||
/* Copy privilege structure from caller */
|
||||
if((r=data_copy(who_e, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
||||
SYSTEM, (vir_bytes) &priv, sizeof(priv))) != OK)
|
||||
return r;
|
||||
|
||||
/* Copy the call mask */
|
||||
for (i= 0; i<CALL_MASK_SIZE; i++)
|
||||
priv(rp)->s_k_call_mask[i]= priv.s_k_call_mask[i];
|
||||
/* Copy s_flags. */
|
||||
priv(rp)->s_flags = priv.s_flags;
|
||||
|
||||
/* Copy IRQs */
|
||||
if (priv.s_nr_irq < 0 || priv.s_nr_irq > NR_IRQ)
|
||||
return EINVAL;
|
||||
priv(rp)->s_nr_irq= priv.s_nr_irq;
|
||||
for (i= 0; i<priv.s_nr_irq; i++)
|
||||
{
|
||||
priv(rp)->s_irq_tab[i]= priv.s_irq_tab[i];
|
||||
if(priv.s_flags & CHECK_IRQ) {
|
||||
if (priv.s_nr_irq < 0 || priv.s_nr_irq > NR_IRQ)
|
||||
return EINVAL;
|
||||
priv(rp)->s_nr_irq= priv.s_nr_irq;
|
||||
for (i= 0; i<priv.s_nr_irq; i++)
|
||||
{
|
||||
priv(rp)->s_irq_tab[i]= priv.s_irq_tab[i];
|
||||
#if 0
|
||||
kprintf("do_privctl: adding IRQ %d for %d\n",
|
||||
priv(rp)->s_irq_tab[i], rp->p_endpoint);
|
||||
kprintf("do_privctl: adding IRQ %d for %d\n",
|
||||
priv(rp)->s_irq_tab[i], rp->p_endpoint);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
priv(rp)->s_flags |= CHECK_IRQ; /* Check requests for IRQs */
|
||||
|
||||
/* Copy I/O ranges */
|
||||
if (priv.s_nr_io_range < 0 || priv.s_nr_io_range > NR_IO_RANGE)
|
||||
return EINVAL;
|
||||
priv(rp)->s_nr_io_range= priv.s_nr_io_range;
|
||||
for (i= 0; i<priv.s_nr_io_range; i++)
|
||||
{
|
||||
priv(rp)->s_io_tab[i]= priv.s_io_tab[i];
|
||||
if(priv.s_flags & CHECK_IO_PORT) {
|
||||
if (priv.s_nr_io_range < 0 || priv.s_nr_io_range > NR_IO_RANGE)
|
||||
return EINVAL;
|
||||
priv(rp)->s_nr_io_range= priv.s_nr_io_range;
|
||||
for (i= 0; i<priv.s_nr_io_range; i++)
|
||||
{
|
||||
priv(rp)->s_io_tab[i]= priv.s_io_tab[i];
|
||||
#if 0
|
||||
kprintf("do_privctl: adding I/O range [%x..%x] for %d\n",
|
||||
priv(rp)->s_io_tab[i].ior_base,
|
||||
priv(rp)->s_io_tab[i].ior_limit,
|
||||
rp->p_endpoint);
|
||||
kprintf("do_privctl: adding I/O range [%x..%x] for %d\n",
|
||||
priv(rp)->s_io_tab[i].ior_base,
|
||||
priv(rp)->s_io_tab[i].ior_limit,
|
||||
rp->p_endpoint);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Check requests for IRQs */
|
||||
priv(rp)->s_flags |= CHECK_IO_PORT;
|
||||
/* Copy memory ranges */
|
||||
if(priv.s_flags & CHECK_MEM) {
|
||||
if (priv.s_nr_mem_range < 0 || priv.s_nr_mem_range > NR_MEM_RANGE)
|
||||
return EINVAL;
|
||||
priv(rp)->s_nr_mem_range= priv.s_nr_mem_range;
|
||||
for (i= 0; i<priv.s_nr_mem_range; i++)
|
||||
{
|
||||
priv(rp)->s_mem_tab[i]= priv.s_mem_tab[i];
|
||||
#if 0
|
||||
kprintf("do_privctl: adding mem range [%x..%x] for %d\n",
|
||||
priv(rp)->s_mem_tab[i].mr_base,
|
||||
priv(rp)->s_mem_tab[i].mr_limit,
|
||||
rp->p_endpoint);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy trap mask. */
|
||||
priv(rp)->s_trap_mask = priv.s_trap_mask;
|
||||
|
||||
/* Copy target mask. */
|
||||
memcpy(&ipc_to_m, &priv.s_ipc_to, sizeof(ipc_to_m));
|
||||
|
||||
/* Copy kernel call mask. */
|
||||
memcpy(priv(rp)->s_k_call_mask, priv.s_k_call_mask,
|
||||
sizeof(priv(rp)->s_k_call_mask));
|
||||
|
||||
/* Set a custom send mask. */
|
||||
for (i=0; i < NR_SYS_PROCS; i++) {
|
||||
if (get_sys_bit(priv.s_ipc_to, i))
|
||||
set_sendto_bit(rp, i);
|
||||
else
|
||||
unset_sendto_bit(rp, i);
|
||||
}
|
||||
}
|
||||
|
||||
/* Done. Privileges have been set. Allow process to run again. */
|
||||
RTS_LOCK_UNSET(rp, RTS_NO_PRIV);
|
||||
/* Fill in target mask. */
|
||||
for (i=0; i < NR_SYS_PROCS; i++) {
|
||||
if (ipc_to_m & (1 << i))
|
||||
set_sendto_bit(rp, i);
|
||||
else
|
||||
unset_sendto_bit(rp, i);
|
||||
}
|
||||
|
||||
return(OK);
|
||||
case SYS_PRIV_USER:
|
||||
/* Make this process an ordinary user process. */
|
||||
|
||||
case SYS_PRIV_SET_USER:
|
||||
/* Set a privilege structure of a blocked user process. */
|
||||
if (!RTS_ISSET(rp, RTS_NO_PRIV)) return(EPERM);
|
||||
if ((i=get_priv(rp, 0)) != OK) return(i);
|
||||
RTS_LOCK_UNSET(rp, RTS_NO_PRIV);
|
||||
|
||||
/* Link the process to the privilege structure of the root user
|
||||
* process all the user processes share.
|
||||
*/
|
||||
priv(rp) = priv_addr(USER_PRIV_ID);
|
||||
|
||||
return(OK);
|
||||
|
||||
case SYS_PRIV_ADD_IO:
|
||||
|
||||
Reference in New Issue
Block a user