2005-10-14 10:58:59 +02:00
|
|
|
/* The kernel call implemented in this file:
|
2005-07-22 11:20:43 +02:00
|
|
|
* m_type: SYS_PRIVCTL
|
|
|
|
*
|
2005-10-14 10:58:59 +02:00
|
|
|
* The parameters for this kernel call are:
|
2009-09-06 14:37:13 +02:00
|
|
|
* m2_i1: CTL_ENDPT (process endpoint of target)
|
|
|
|
* m2_i2: CTL_REQUEST (privilege control request)
|
|
|
|
* m2_p1: CTL_ARG_PTR (pointer to request data)
|
2005-07-22 11:20:43 +02:00
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/system.h"
|
|
|
|
#include "kernel/ipc.h"
|
2005-08-02 17:28:09 +02:00
|
|
|
#include <signal.h>
|
2006-10-30 16:53:38 +01:00
|
|
|
#include <string.h>
|
2010-02-03 10:04:48 +01:00
|
|
|
#include <minix/endpoint.h>
|
2005-07-22 11:20:43 +02:00
|
|
|
|
|
|
|
#if USE_PRIVCTL
|
|
|
|
|
2010-07-07 00:05:21 +02:00
|
|
|
#define PRIV_DEBUG 0
|
|
|
|
|
|
|
|
FORWARD _PROTOTYPE(int update_priv, (struct proc *rp, struct priv *priv));
|
|
|
|
|
2005-07-22 11:20:43 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_privctl *
|
|
|
|
*===========================================================================*/
|
2010-02-03 10:04:48 +01:00
|
|
|
PUBLIC int do_privctl(struct proc * caller, message * m_ptr)
|
2005-07-22 11:20:43 +02:00
|
|
|
{
|
|
|
|
/* Handle sys_privctl(). Update a process' privileges. If the process is not
|
|
|
|
* yet a system process, make sure it gets its own privilege structure.
|
|
|
|
*/
|
2010-02-03 10:04:48 +01:00
|
|
|
struct proc *rp;
|
2010-05-25 09:23:24 +02:00
|
|
|
proc_nr_t proc_nr;
|
|
|
|
sys_id_t priv_id;
|
2009-12-11 01:08:19 +01:00
|
|
|
int ipc_to_m, kcalls;
|
2008-11-19 13:26:10 +01:00
|
|
|
int i, r;
|
2006-01-27 14:21:12 +01:00
|
|
|
struct io_range io_range;
|
|
|
|
struct mem_range mem_range;
|
2006-10-20 16:42:48 +02:00
|
|
|
struct priv priv;
|
2009-09-06 14:37:13 +02:00
|
|
|
int irq;
|
2005-07-22 11:20:43 +02:00
|
|
|
|
2005-08-02 17:28:09 +02:00
|
|
|
/* Check whether caller is allowed to make this call. Privileged proceses
|
|
|
|
* can only update the privileges of processes that are inhibited from
|
2009-11-10 10:11:13 +01:00
|
|
|
* running by the RTS_NO_PRIV flag. This flag is set when a privileged process
|
2005-08-02 17:28:09 +02:00
|
|
|
* forks.
|
|
|
|
*/
|
2010-02-03 10:04:48 +01:00
|
|
|
if (! (priv(caller)->s_flags & SYS_PROC)) return(EPERM);
|
|
|
|
if(m_ptr->CTL_ENDPT == SELF) proc_nr = _ENDPOINT_P(caller->p_endpoint);
|
2009-09-06 14:37:13 +02:00
|
|
|
else if(!isokendpt(m_ptr->CTL_ENDPT, &proc_nr)) return(EINVAL);
|
2005-07-22 11:20:43 +02:00
|
|
|
rp = proc_addr(proc_nr);
|
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
switch(m_ptr->CTL_REQUEST)
|
|
|
|
{
|
2009-12-11 01:08:19 +01:00
|
|
|
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);
|
|
|
|
}
|
2010-02-09 16:26:58 +01:00
|
|
|
RTS_UNSET(rp, RTS_NO_PRIV);
|
2009-12-11 01:08:19 +01:00
|
|
|
return(OK);
|
|
|
|
|
2010-07-09 20:29:04 +02:00
|
|
|
case SYS_PRIV_YIELD:
|
|
|
|
/* Allow process to run and suspend the caller. */
|
|
|
|
if (!RTS_ISSET(rp, RTS_NO_PRIV) || priv(rp)->s_proc_nr == NONE) {
|
|
|
|
return(EPERM);
|
|
|
|
}
|
|
|
|
RTS_SET(caller, RTS_NO_PRIV);
|
|
|
|
RTS_UNSET(rp, RTS_NO_PRIV);
|
|
|
|
return(OK);
|
|
|
|
|
2009-12-11 01:08:19 +01:00
|
|
|
case SYS_PRIV_DISALLOW:
|
|
|
|
/* Disallow process from running. */
|
|
|
|
if (RTS_ISSET(rp, RTS_NO_PRIV)) return(EPERM);
|
2010-02-09 16:26:58 +01:00
|
|
|
RTS_SET(rp, RTS_NO_PRIV);
|
2009-12-11 01:08:19 +01:00
|
|
|
return(OK);
|
|
|
|
|
|
|
|
case SYS_PRIV_SET_SYS:
|
|
|
|
/* Set a privilege structure of a blocked system process. */
|
2009-11-10 10:11:13 +01:00
|
|
|
if (! RTS_ISSET(rp, RTS_NO_PRIV)) return(EPERM);
|
2005-07-26 14:48:34 +02:00
|
|
|
|
2009-12-11 01:08:19 +01:00
|
|
|
/* 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 */
|
2010-02-03 10:04:48 +01:00
|
|
|
if((r=data_copy(caller->p_endpoint, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
2010-02-09 16:20:09 +01:00
|
|
|
KERNEL, (vir_bytes) &priv, sizeof(priv))) != OK)
|
2009-12-11 01:08:19 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
/* Make sure this process has its own privileges structure. This may
|
|
|
|
* fail, since there are only a limited number of system processes.
|
2009-12-11 01:08:19 +01:00
|
|
|
* Then copy privileges from the caller and restore some defaults.
|
2006-01-27 14:21:12 +01:00
|
|
|
*/
|
2009-12-11 01:08:19 +01:00
|
|
|
if ((i=get_priv(rp, priv_id)) != OK)
|
2008-02-22 11:58:27 +01:00
|
|
|
{
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("do_privctl: unable to allocate priv_id %d: %d\n",
|
2009-12-11 01:08:19 +01:00
|
|
|
priv_id, i);
|
2008-02-22 11:58:27 +01:00
|
|
|
return(i);
|
|
|
|
}
|
2006-01-27 14:21:12 +01:00
|
|
|
priv_id = priv(rp)->s_id; /* backup privilege id */
|
2010-02-03 10:04:48 +01:00
|
|
|
*priv(rp) = *priv(caller); /* copy from caller */
|
2006-01-27 14:21:12 +01:00
|
|
|
priv(rp)->s_id = priv_id; /* restore privilege id */
|
|
|
|
priv(rp)->s_proc_nr = proc_nr; /* reassociate process nr */
|
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
for (i=0; i< NR_SYS_CHUNKS; i++) /* remove pending: */
|
2006-01-27 14:21:12 +01:00
|
|
|
priv(rp)->s_notify_pending.chunk[i] = 0; /* - notifications */
|
|
|
|
priv(rp)->s_int_pending = 0; /* - interrupts */
|
2010-07-06 13:59:19 +02:00
|
|
|
(void) sigemptyset(&priv(rp)->s_sig_pending); /* - signals */
|
2010-05-26 09:10:28 +02:00
|
|
|
reset_timer(&priv(rp)->s_alarm_timer); /* - alarm */
|
2010-01-14 16:24:16 +01:00
|
|
|
priv(rp)->s_asyntab= -1; /* - asynsends */
|
|
|
|
priv(rp)->s_asynsize= 0;
|
2006-01-27 14:21:12 +01:00
|
|
|
|
2009-12-11 01:08:19 +01:00
|
|
|
/* Set defaults for privilege bitmaps. */
|
2010-07-13 23:11:44 +02:00
|
|
|
priv(rp)->s_flags= DSRV_F; /* privilege flags */
|
|
|
|
priv(rp)->s_trap_mask= DSRV_T; /* allowed traps */
|
|
|
|
ipc_to_m = DSRV_M; /* allowed targets */
|
2010-07-07 00:05:21 +02:00
|
|
|
fill_sendto_mask(rp, ipc_to_m);
|
2010-07-13 23:11:44 +02:00
|
|
|
kcalls = DSRV_KC; /* allowed kernel calls */
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
for(i = 0; i < SYS_CALL_MASK_SIZE; i++) {
|
2009-12-11 01:08:19 +01:00
|
|
|
priv(rp)->s_k_call_mask[i] = (kcalls == NO_C ? 0 : (~0));
|
2007-04-23 15:30:04 +02:00
|
|
|
}
|
|
|
|
|
2010-07-07 00:05:21 +02:00
|
|
|
/* Set the default signal managers. */
|
2010-07-13 23:11:44 +02:00
|
|
|
priv(rp)->s_sig_mgr = DSRV_SM;
|
2010-07-07 00:05:21 +02:00
|
|
|
priv(rp)->s_bak_sig_mgr = NONE;
|
New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
2010-03-17 02:15:29 +01:00
|
|
|
|
2009-12-11 01:08:19 +01:00
|
|
|
/* Set defaults for resources: no I/O resources, no memory resources,
|
|
|
|
* no IRQs, no grant table
|
|
|
|
*/
|
2006-01-27 14:21:12 +01:00
|
|
|
priv(rp)->s_nr_io_range= 0;
|
|
|
|
priv(rp)->s_nr_mem_range= 0;
|
|
|
|
priv(rp)->s_nr_irq= 0;
|
2006-06-20 12:03:10 +02:00
|
|
|
priv(rp)->s_grant_table= 0;
|
|
|
|
priv(rp)->s_grant_entries= 0;
|
2006-01-27 14:21:12 +01:00
|
|
|
|
2009-12-11 01:08:19 +01:00
|
|
|
/* Override defaults if the caller has supplied a privilege structure. */
|
2006-10-20 16:42:48 +02:00
|
|
|
if (m_ptr->CTL_ARG_PTR)
|
|
|
|
{
|
2010-07-07 00:05:21 +02:00
|
|
|
if((r = update_priv(rp, &priv)) != OK) {
|
|
|
|
return r;
|
|
|
|
}
|
2006-10-20 16:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return(OK);
|
2009-12-11 01:08:19 +01:00
|
|
|
|
|
|
|
case SYS_PRIV_SET_USER:
|
|
|
|
/* Set a privilege structure of a blocked user process. */
|
2009-11-10 10:11:13 +01:00
|
|
|
if (!RTS_ISSET(rp, RTS_NO_PRIV)) return(EPERM);
|
2009-12-11 01:08:19 +01:00
|
|
|
|
|
|
|
/* Link the process to the privilege structure of the root user
|
|
|
|
* process all the user processes share.
|
|
|
|
*/
|
|
|
|
priv(rp) = priv_addr(USER_PRIV_ID);
|
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
return(OK);
|
2006-10-20 16:42:48 +02:00
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
case SYS_PRIV_ADD_IO:
|
2009-11-10 10:11:13 +01:00
|
|
|
if (RTS_ISSET(rp, RTS_NO_PRIV))
|
2006-01-27 14:21:12 +01:00
|
|
|
return(EPERM);
|
|
|
|
|
|
|
|
/* Only system processes get I/O resources? */
|
|
|
|
if (!(priv(rp)->s_flags & SYS_PROC))
|
|
|
|
return EPERM;
|
|
|
|
|
2008-02-22 11:58:27 +01:00
|
|
|
#if 0 /* XXX -- do we need a call for this? */
|
|
|
|
if (strcmp(rp->p_name, "fxp") == 0 ||
|
|
|
|
strcmp(rp->p_name, "rtl8139") == 0)
|
|
|
|
{
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("setting ipc_stats_target to %d\n", rp->p_endpoint);
|
2008-02-22 11:58:27 +01:00
|
|
|
ipc_stats_target= rp->p_endpoint;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
/* Get the I/O range */
|
2010-02-03 10:04:48 +01:00
|
|
|
data_copy(caller->p_endpoint, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
2010-02-09 16:20:09 +01:00
|
|
|
KERNEL, (vir_bytes) &io_range, sizeof(io_range));
|
2006-01-27 14:21:12 +01:00
|
|
|
priv(rp)->s_flags |= CHECK_IO_PORT; /* Check I/O accesses */
|
|
|
|
i= priv(rp)->s_nr_io_range;
|
2010-04-29 10:50:52 +02:00
|
|
|
if (i >= NR_IO_RANGE) {
|
|
|
|
printf("do_privctl: %d already has %d i/o ranges.\n",
|
|
|
|
rp->p_endpoint, i);
|
2006-01-27 14:21:12 +01:00
|
|
|
return ENOMEM;
|
2010-04-29 10:50:52 +02:00
|
|
|
}
|
2006-01-27 14:21:12 +01:00
|
|
|
|
|
|
|
priv(rp)->s_io_tab[i].ior_base= io_range.ior_base;
|
|
|
|
priv(rp)->s_io_tab[i].ior_limit= io_range.ior_limit;
|
|
|
|
priv(rp)->s_nr_io_range++;
|
|
|
|
|
|
|
|
return OK;
|
2005-08-02 17:28:09 +02:00
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
case SYS_PRIV_ADD_MEM:
|
2009-11-10 10:11:13 +01:00
|
|
|
if (RTS_ISSET(rp, RTS_NO_PRIV))
|
2006-01-27 14:21:12 +01:00
|
|
|
return(EPERM);
|
|
|
|
|
|
|
|
/* Only system processes get memory resources? */
|
|
|
|
if (!(priv(rp)->s_flags & SYS_PROC))
|
|
|
|
return EPERM;
|
|
|
|
|
|
|
|
/* Get the memory range */
|
2010-02-03 10:04:48 +01:00
|
|
|
if((r=data_copy(caller->p_endpoint, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
2010-02-09 16:20:09 +01:00
|
|
|
KERNEL, (vir_bytes) &mem_range, sizeof(mem_range))) != OK)
|
2008-11-19 13:26:10 +01:00
|
|
|
return r;
|
2009-11-03 12:12:23 +01:00
|
|
|
priv(rp)->s_flags |= CHECK_MEM; /* Check memory mappings */
|
2006-01-27 14:21:12 +01:00
|
|
|
i= priv(rp)->s_nr_mem_range;
|
2010-04-29 10:50:52 +02:00
|
|
|
if (i >= NR_MEM_RANGE) {
|
|
|
|
printf("do_privctl: %d already has %d mem ranges.\n",
|
|
|
|
rp->p_endpoint, i);
|
2006-01-27 14:21:12 +01:00
|
|
|
return ENOMEM;
|
2010-04-29 10:50:52 +02:00
|
|
|
}
|
2006-01-27 14:21:12 +01:00
|
|
|
|
|
|
|
priv(rp)->s_mem_tab[i].mr_base= mem_range.mr_base;
|
|
|
|
priv(rp)->s_mem_tab[i].mr_limit= mem_range.mr_limit;
|
|
|
|
priv(rp)->s_nr_mem_range++;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
case SYS_PRIV_ADD_IRQ:
|
2009-11-10 10:11:13 +01:00
|
|
|
if (RTS_ISSET(rp, RTS_NO_PRIV))
|
2006-01-27 14:21:12 +01:00
|
|
|
return(EPERM);
|
|
|
|
|
|
|
|
/* Only system processes get IRQs? */
|
|
|
|
if (!(priv(rp)->s_flags & SYS_PROC))
|
|
|
|
return EPERM;
|
|
|
|
|
2010-02-03 10:04:48 +01:00
|
|
|
data_copy(caller->p_endpoint, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
2010-02-09 16:20:09 +01:00
|
|
|
KERNEL, (vir_bytes) &irq, sizeof(irq));
|
2006-01-27 14:21:12 +01:00
|
|
|
priv(rp)->s_flags |= CHECK_IRQ; /* Check IRQs */
|
|
|
|
|
|
|
|
i= priv(rp)->s_nr_irq;
|
2010-04-29 10:50:52 +02:00
|
|
|
if (i >= NR_IRQ) {
|
|
|
|
printf("do_privctl: %d already has %d irq's.\n",
|
|
|
|
rp->p_endpoint, i);
|
2006-01-27 14:21:12 +01:00
|
|
|
return ENOMEM;
|
2010-04-29 10:50:52 +02:00
|
|
|
}
|
2009-09-06 14:37:13 +02:00
|
|
|
priv(rp)->s_irq_tab[i]= irq;
|
2006-01-27 14:21:12 +01:00
|
|
|
priv(rp)->s_nr_irq++;
|
|
|
|
|
|
|
|
return OK;
|
2009-11-03 12:12:23 +01:00
|
|
|
case SYS_PRIV_QUERY_MEM:
|
|
|
|
{
|
|
|
|
phys_bytes addr, limit;
|
|
|
|
struct priv *sp;
|
|
|
|
/* See if a certain process is allowed to map in certain physical
|
|
|
|
* memory.
|
|
|
|
*/
|
|
|
|
addr = (phys_bytes) m_ptr->CTL_PHYSSTART;
|
|
|
|
limit = addr + (phys_bytes) m_ptr->CTL_PHYSLEN - 1;
|
|
|
|
if(limit < addr)
|
|
|
|
return EPERM;
|
|
|
|
if(!(sp = priv(rp)))
|
|
|
|
return EPERM;
|
|
|
|
if (!(sp->s_flags & SYS_PROC))
|
|
|
|
return EPERM;
|
|
|
|
for(i = 0; i < sp->s_nr_mem_range; i++) {
|
|
|
|
if(addr >= sp->s_mem_tab[i].mr_base &&
|
|
|
|
limit <= sp->s_mem_tab[i].mr_limit)
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
return EPERM;
|
|
|
|
}
|
2010-07-07 00:05:21 +02:00
|
|
|
|
|
|
|
case SYS_PRIV_UPDATE_SYS:
|
|
|
|
/* Update the privilege structure of a system process. */
|
|
|
|
if(!m_ptr->CTL_ARG_PTR) return EINVAL;
|
|
|
|
|
|
|
|
/* Copy privilege structure from caller */
|
|
|
|
if((r=data_copy(caller->p_endpoint, (vir_bytes) m_ptr->CTL_ARG_PTR,
|
|
|
|
KERNEL, (vir_bytes) &priv, sizeof(priv))) != OK)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* Override settings in existing privilege structure. */
|
|
|
|
if((r = update_priv(rp, &priv)) != OK) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(OK);
|
|
|
|
|
2006-01-27 14:21:12 +01:00
|
|
|
default:
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("do_privctl: bad request %d\n", m_ptr->CTL_REQUEST);
|
2006-01-27 14:21:12 +01:00
|
|
|
return EINVAL;
|
|
|
|
}
|
2005-07-22 11:20:43 +02:00
|
|
|
}
|
|
|
|
|
2010-07-07 00:05:21 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* update_priv *
|
|
|
|
*===========================================================================*/
|
|
|
|
PRIVATE int update_priv(struct proc *rp, struct priv *priv)
|
|
|
|
{
|
|
|
|
/* Update the privilege structure of a given process. */
|
|
|
|
|
|
|
|
int ipc_to_m, i;
|
|
|
|
|
|
|
|
/* Copy s_flags and signal managers. */
|
|
|
|
priv(rp)->s_flags = priv->s_flags;
|
|
|
|
priv(rp)->s_sig_mgr = priv->s_sig_mgr;
|
|
|
|
priv(rp)->s_bak_sig_mgr = priv->s_bak_sig_mgr;
|
|
|
|
|
|
|
|
/* Copy IRQs. */
|
|
|
|
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 PRIV_DEBUG
|
|
|
|
printf("do_privctl: adding IRQ %d for %d\n",
|
|
|
|
priv(rp)->s_irq_tab[i], rp->p_endpoint);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy I/O ranges. */
|
|
|
|
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 PRIV_DEBUG
|
|
|
|
printf("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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 PRIV_DEBUG
|
|
|
|
printf("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. */
|
2010-07-13 23:11:44 +02:00
|
|
|
#if PRIV_DEBUG
|
|
|
|
printf("do_privctl: Setting ipc target mask for %d:");
|
|
|
|
for (i=0; i < NR_SYS_PROCS; i += BITCHUNK_BITS) {
|
|
|
|
printf(" %04x", get_sys_bits(priv->s_ipc_to, i));
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2010-07-07 00:05:21 +02:00
|
|
|
memcpy(&ipc_to_m, &priv->s_ipc_to, sizeof(ipc_to_m));
|
|
|
|
fill_sendto_mask(rp, ipc_to_m);
|
|
|
|
|
2010-07-13 23:11:44 +02:00
|
|
|
#if PRIV_DEBUG
|
|
|
|
printf("do_privctl: Set ipc target mask for %d:");
|
|
|
|
for (i=0; i < NR_SYS_PROCS; i += BITCHUNK_BITS) {
|
|
|
|
printf(" %04x", get_sys_bits(priv(rp)->s_ipc_to, i));
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
2010-07-07 00:05:21 +02:00
|
|
|
/* Copy kernel call mask. */
|
|
|
|
memcpy(priv(rp)->s_k_call_mask, priv->s_k_call_mask,
|
|
|
|
sizeof(priv(rp)->s_k_call_mask));
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-07-22 11:20:43 +02:00
|
|
|
#endif /* USE_PRIVCTL */
|
|
|
|
|