Introduced unprivileged getsysinfo variant, to retrieve harmless data

in formats that don't change (or is upwards compatible).
This commit is contained in:
Ben Gras 2006-07-27 16:23:01 +00:00
parent 4d7f2af576
commit 18327f02a8
11 changed files with 90 additions and 6 deletions

View file

@ -1,4 +1,4 @@
#define NCALLS 97 /* number of system calls allowed */
#define NCALLS 98 /* number of system calls allowed */
#define EXIT 1
#define FORK 2
@ -77,6 +77,7 @@
#define FTRUNCATE 94 /* to FS */
#define FCHMOD 95 /* to FS */
#define FCHOWN 96 /* to FS */
#define GETSYSINFO_UP 97 /* to PM or FS */
/* Calls provided by PM and FS that are not part of the API */
#define EXEC_NEWMEM 100 /* from FS or RS to PM: new memory map for

View file

@ -516,6 +516,11 @@
#define SEL_ERRORFDS m8_p3
#define SEL_TIMEOUT m8_p4
/* Field names for GETSYSINFO_UP (PM). */
#define SIU_WHAT m2_i1
#define SIU_LEN m2_i2
#define SIU_WHERE m2_p1
/* Message for SYS_READBIOS */
#define RDB_SIZE m2_i1
#define RDB_ADDR m2_l1

17
include/minix/sysinfo.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef _MINIX_SYSINFO_H
#define _MINIX_SYSINFO_H
#include <minix/endpoint.h>
#include <minix/type.h>
_PROTOTYPE( int getsysinfo, (endpoint_t who, int what, void *where) );
_PROTOTYPE( ssize_t getsysinfo_up, (endpoint_t who, int what, size_t size,
void *where));
#define SIU_LOADINFO 1 /* retrieve load info data */
/* Exported system parameters. */
#endif

View file

@ -116,10 +116,10 @@ struct kinfo {
};
/* Load data accounted every this no. of seconds. */
#define _LOAD_UNIT_SECS 6
#define _LOAD_UNIT_SECS 6 /* Changing this breaks ABI. */
/* Load data history is kept for this long. */
#define _LOAD_HISTORY_MINUTES 15
#define _LOAD_HISTORY_MINUTES 15 /* Changing this breaks ABI. */
#define _LOAD_HISTORY_SECONDS (60*_LOAD_HISTORY_MINUTES)
/* We need this many slots to store the load history. */

View file

@ -1,10 +1,12 @@
#include <lib.h>
#include <minix/endpoint.h>
#define getsysinfo _getsysinfo
#include <unistd.h>
#define getsysinfo_up _getsysinfo_up
#include <minix/sysinfo.h>
PUBLIC int getsysinfo(who, what, where)
int who; /* from whom to request info */
endpoint_t who; /* from whom to request info */
int what; /* what information is requested */
void *where; /* where to put it */
{
@ -15,3 +17,17 @@ void *where; /* where to put it */
return(0);
}
/* Unprivileged variant of getsysinfo. */
PUBLIC ssize_t getsysinfo_up(who, what, size, where)
endpoint_t who; /* from whom to request info */
int what; /* what information is requested */
size_t size; /* input and output size */
void *where; /* where to put it */
{
message m;
m.SIU_WHAT = what;
m.SIU_WHERE = where;
m.SIU_LEN = size;
return _syscall(who, GETSYSINFO_UP, &m);
}

View file

@ -1,5 +1,6 @@
#include <sys/types.h>
#include <minix/sysinfo.h>
#include <stdlib.h>
#include <unistd.h>
#include <lib.h>
@ -11,12 +12,17 @@ int getloadavg(double *loadavg, int nelem)
int h, p, unfilled_ticks;
#define PERIODS 3
int minutes[3] = { 1, 5, 15 };
size_t loadsize;
ssize_t l;
if(nelem < 1) {
errno = ENOSPC;
return -1;
}
if(getsysinfo(PM_PROC_NR, SI_LOADINFO, &loadinfo) < 0)
loadsize = sizeof(loadinfo);
if((l=getsysinfo_up(PM_PROC_NR, SIU_LOADINFO, loadsize, &loadinfo)) < 0)
return -1;
if(l != sizeof(loadinfo))
return -1;
if(nelem > PERIODS)
nelem = PERIODS;

View file

@ -1,7 +1,11 @@
.sect .text
.extern __getsysinfo
.define _getsysinfo
.extern __getsysinfo_up
.define _getsysinfo_up
.align 2
_getsysinfo:
jmp __getsysinfo
_getsysinfo_up:
jmp __getsysinfo_up

View file

@ -114,6 +114,7 @@ PUBLIC _PROTOTYPE (int (*call_vec[]), (void) ) = {
do_ftruncate, /* 94 = truncate */
do_chmod, /* 95 = fchmod */
do_chown, /* 96 = fchown */
no_sys, /* 97 = (getsysinfo_up) */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];

View file

@ -21,6 +21,7 @@
#include <sys/utsname.h>
#include <minix/com.h>
#include <minix/config.h>
#include <minix/sysinfo.h>
#include <minix/type.h>
#include <string.h>
#include <lib.h>
@ -276,6 +277,37 @@ PUBLIC int do_getsysinfo()
return(OK);
}
/*===========================================================================*
* do_getsysinfo_up *
*===========================================================================*/
PUBLIC int do_getsysinfo_up()
{
vir_bytes src_addr, dst_addr;
struct loadinfo loadinfo;
size_t len, real_len;
int s, r;
switch(m_in.SIU_WHAT) {
case SIU_LOADINFO: /* loadinfo is obtained via PM */
sys_getloadinfo(&loadinfo);
src_addr = (vir_bytes) &loadinfo;
real_len = sizeof(struct loadinfo);
break;
default:
return(EINVAL);
}
/* Let application know what the length was. */
len = real_len;
if(len > m_in.SIU_LEN)
len = m_in.SIU_LEN;
dst_addr = (vir_bytes) m_in.SIU_WHERE;
if (OK != (s=sys_datacopy(SELF, src_addr, who_e, dst_addr, len)))
return(s);
return(real_len);
}
/*===========================================================================*
* do_getprocnr *
*===========================================================================*/

View file

@ -66,6 +66,7 @@ _PROTOTYPE( int do_reboot, (void) );
_PROTOTYPE( int do_procstat, (void) );
_PROTOTYPE( int do_sysuname, (void) );
_PROTOTYPE( int do_getsysinfo, (void) );
_PROTOTYPE( int do_getsysinfo_up, (void) );
_PROTOTYPE( int do_getprocnr, (void) );
_PROTOTYPE( int do_svrctl, (void) );
_PROTOTYPE( int do_allocmem, (void) );

View file

@ -112,6 +112,7 @@ _PROTOTYPE (int (*call_vec[NCALLS]), (void) ) = {
no_sys, /* 94 = (ftruncate) */
no_sys, /* 95 = (fchmod) */
no_sys, /* 96 = (fchown) */
do_getsysinfo_up,/* 97 = getsysinfo_up */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];