New kernel call, SYS_PARAMCTL, that sets parameters of the caller

and is therefore unprivileged. Used to set grant tables.
This commit is contained in:
Ben Gras 2006-06-23 15:07:41 +00:00
parent 8dfac43a75
commit 002922fa4c
10 changed files with 71 additions and 14 deletions

View file

@ -286,11 +286,12 @@
# define SYS_IOPENABLE (KERNEL_CALL + 28) /* sys_enable_iop() */
# define SYS_VM_SETBUF (KERNEL_CALL + 29) /* sys_vm_setbuf() */
# define SYS_VM_MAP (KERNEL_CALL + 30) /* sys_vm_map() */
# define SYS_SAFECOPYFROM (KERNEL_CALL + 31) /* sys_safecopyfrom() */
# define SYS_SAFECOPYTO (KERNEL_CALL + 32) /* sys_safecopyto() */
# define SYS_SAFECOPYFROM (KERNEL_CALL + 31) /* sys_safecopyfrom() */
# define SYS_SAFECOPYTO (KERNEL_CALL + 32) /* sys_safecopyto() */
# define SYS_VSAFECOPY (KERNEL_CALL + 33) /* sys_vsafecopy() */
# define SYS_PARAMCTL (KERNEL_CALL + 34) /* sys_paramctl() */
#define NR_SYS_CALLS 34 /* number of system calls */
#define NR_SYS_CALLS 35 /* number of system calls */
/* Pseudo call for use in kernel/table.c. */
#define SYS_ALL_CALLS (NR_SYS_CALLS)
@ -301,7 +302,9 @@
#define SYS_PRIV_ADD_MEM 3 /* Add memory range (struct mem_range)
*/
#define SYS_PRIV_ADD_IRQ 4 /* Add IRQ */
#define SYS_PRIV_SET_GRANTS 5 /* Set grant table */
/* Subfunctions for SYS_PARAMCTL */
#define SYS_PARAM_SET_GRANT 1 /* Set address and size of grant table */
/* Field names for SYS_MEMSET, SYS_SEGCTL. */
#define MEM_PTR m2_p1 /* base */
@ -444,6 +447,12 @@
#define CTL_ADDRESS m2_l1 /* address at traced process' space */
#define CTL_DATA m2_l2 /* data field for tracing */
/* Field names for SYS_PARAMCTL */
#define PCTL_REQ m2_i1 /* request code */
#define PCTL_INT1 m2_i2 /* int param 1 */
#define PCTL_INT2 m2_i3 /* int param 2 */
#define PCTL_ADDR1 m2_p1 /* address param 1 */
/* Field names for SYS_KILL, SYS_SIGCTL */
#define SIG_REQUEST m2_l2 /* PM signal control request */
#define S_GETSIG 0 /* get pending kernel signal */

View file

@ -37,6 +37,7 @@ _PROTOTYPE( int sys_exit, (endpoint_t proc));
_PROTOTYPE( int sys_trace, (int req, endpoint_t proc, long addr, long *data_p));
_PROTOTYPE( int sys_privctl, (endpoint_t proc, int req, int i, void *p));
_PROTOTYPE( int sys_paramctl, (int req, int int1, void *addr1, int int2));
_PROTOTYPE( int sys_nice, (endpoint_t proc, int priority));
_PROTOTYPE( int sys_int86, (struct reg86u *reg86p));

View file

@ -148,6 +148,7 @@ PRIVATE void initialize(void)
map(SYS_NICE, do_nice); /* set scheduling priority */
map(SYS_PRIVCTL, do_privctl); /* system privileges control */
map(SYS_TRACE, do_trace); /* request a trace operation */
map(SYS_PARAMCTL, do_paramctl); /* get/set own parameters */
/* Signal handling. */
map(SYS_KILL, do_kill); /* cause a process to be signaled */

View file

@ -176,6 +176,7 @@ _PROTOTYPE( int do_setalarm, (message *m_ptr) );
_PROTOTYPE( int do_safecopy, (message *m_ptr) );
_PROTOTYPE( int do_vsafecopy, (message *m_ptr) );
_PROTOTYPE( int do_iopenable, (message *m_ptr) );
_PROTOTYPE( int do_paramctl, (message *m_ptr) );
#endif /* SYSTEM_H */

View file

@ -35,6 +35,7 @@ OBJECTS = \
$(SYSTEM)(do_vcopy.o) \
$(SYSTEM)(do_umap.o) \
$(SYSTEM)(do_memset.o) \
$(SYSTEM)(do_paramctl.o) \
$(SYSTEM)(do_privctl.o) \
$(SYSTEM)(do_segctl.o) \
$(SYSTEM)(do_safecopy.o) \
@ -137,6 +138,9 @@ $(SYSTEM)(do_getinfo.o): do_getinfo.c
$(SYSTEM)(do_abort.o): do_abort.c
$(CC) do_abort.c
$(SYSTEM)(do_paramctl.o): do_paramctl.c
$(CC) do_paramctl.c
$(SYSTEM)(do_privctl.o): do_privctl.c
$(CC) do_privctl.c

View file

@ -0,0 +1,45 @@
/* The kernel call implemented in this file:
* m_type: SYS_PARAMCTL
*
* The parameters for this kernel call are:
* PCTL_REQ request code (SYS_PARAM_*)
* PCTL_INT[12] integer parameters
* PCTL_ADDR1 address parameter
*/
#include "../system.h"
#include <minix/safecopies.h>
/*===========================================================================*
* do_paramctl *
*===========================================================================*/
PUBLIC int do_paramctl(m_ptr)
message *m_ptr;
{
struct proc *rp;
int r;
/* Who wants to set a parameter? */
rp = proc_addr(who_p);
/* Which parameter is it? */
switch(m_ptr->PCTL_REQ) {
case SYS_PARAM_SET_GRANT:
/* Copy grant table set in priv. struct. */
if ((rp->p_rts_flags & NO_PRIV) || !(priv(rp))) {
r = EPERM;
} else {
_K_SET_GRANT_TABLE(rp,
(vir_bytes) m_ptr->PCTL_ADDR1,
m_ptr->PCTL_INT1);
r = OK;
}
break;
default:
r = EINVAL;
break;
}
return r;
}

View file

@ -163,12 +163,6 @@ message *m_ptr; /* pointer to request message */
priv(rp)->s_nr_irq++;
return OK;
case SYS_PRIV_SET_GRANTS:
if ((rp->p_rts_flags & NO_PRIV) || !(priv(rp))) return(EPERM);
_K_SET_GRANT_TABLE(rp,
(vir_bytes) m_ptr->CTL_ARG_PTR, m_ptr->CTL_MM_PRIV);
return OK;
default:
kprintf("do_privctl: bad request %d\n", m_ptr->CTL_REQUEST);
return EINVAL;

View file

@ -1,5 +1,5 @@
/* The kernel call implemented in this file:
* m_type: SYS_SAFECOPYFROM or SYS_SAFECOPYTO
* m_type: SYS_SAFECOPYFROM or SYS_SAFECOPYTO or SYS_VSAFECOPY
*
* The parameters for this kernel call are:
* SCP_FROM_TO other endpoint

View file

@ -49,6 +49,7 @@ libsys_FILES=" \
sys_sigreturn.c \
sys_sigsend.c \
sys_privctl.c \
sys_paramctl.c \
sys_times.c \
sys_trace.c \
sys_umap.c \

View file

@ -12,6 +12,8 @@
#include <stdlib.h>
#include <minix/syslib.h>
#include <minix/safecopies.h>
#include <minix/com.h>
#include <string.h>
PRIVATE cp_grant_t *grants = NULL;
PRIVATE int ngrants = 0, dynamic = 1;
@ -33,8 +35,7 @@ cpf_preallocate(cp_grant_t *new_grants, int new_ngrants)
}
/* Update kernel about the table. */
if((s=sys_privctl(SELF, SYS_PRIV_SET_GRANTS,
new_ngrants, new_grants))) {
if((s=sys_paramctl(SYS_PARAM_SET_GRANT, new_ngrants, new_grants, 0))) {
return -1;
}
@ -79,7 +80,7 @@ cpf_grow(void)
new_grants[g].cp_flags = 0;
/* Inform kernel about new size (and possibly new location). */
if(sys_privctl(SELF, SYS_PRIV_SET_GRANTS, new_size, new_grants)) {
if((sys_paramctl(SYS_PARAM_SET_GRANT, new_size, new_grants, 0))) {
free(new_grants);
return; /* Failed - don't grow then. */
}