From f197bcb435f419c7c92d3c8aff1264b07dd1b50b Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Wed, 2 Dec 2009 10:06:58 +0000 Subject: [PATCH] Allow servers to run with fewer privileges: - allow non-root processes to get their own endpoint - make alloc_contig() call sys_umap() only when requested --- etc/drivers.conf | 1 - include/minix/type.h | 3 +-- lib/syslib/alloc_util.c | 4 ++-- servers/mfs/cache.c | 3 +-- servers/pm/misc.c | 7 +++++++ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/etc/drivers.conf b/etc/drivers.conf index eb0c3e647..ef62bca24 100644 --- a/etc/drivers.conf +++ b/etc/drivers.conf @@ -290,7 +290,6 @@ driver mfs SAFECOPYTO # 32 GETINFO SETGRANT # 34 - UMAP # 14 PROFBUF # 38 SYSCTL ; diff --git a/include/minix/type.h b/include/minix/type.h index 4dd0edfe9..d5a526c3b 100644 --- a/include/minix/type.h +++ b/include/minix/type.h @@ -162,8 +162,7 @@ struct memory { #define STATICINIT(v, n) \ if(!(v)) { \ - phys_bytes myph; \ - if(!((v) = alloc_contig(sizeof(*(v)) * (n), 0, &myph))) { \ + if(!((v) = alloc_contig(sizeof(*(v)) * (n), 0, NULL))) { \ panic(__FILE__, "allocating " #v " failed", n); \ } \ } diff --git a/lib/syslib/alloc_util.c b/lib/syslib/alloc_util.c index 52d7792e5..1fe2e2ec9 100644 --- a/lib/syslib/alloc_util.c +++ b/lib/syslib/alloc_util.c @@ -66,8 +66,8 @@ void *alloc_contig(size_t len, int flags, phys_bytes *phys) buf += align - (buf % align); } - /* Get physical address. */ - if(sys_umap_data_fb(SELF, buf, len, phys) != OK) + /* Get physical address, if requested. */ + if(phys != NULL && sys_umap_data_fb(SELF, buf, len, phys) != OK) panic("alloc_contig.c", "sys_umap_data_fb failed", NO_NUM); return (void *) buf; diff --git a/servers/mfs/cache.c b/servers/mfs/cache.c index 1936479a7..5ccf9aa34 100644 --- a/servers/mfs/cache.c +++ b/servers/mfs/cache.c @@ -82,10 +82,9 @@ int only_search; /* if NO_READ, don't read, else act normal */ if ((bp = front) == NIL_BUF) panic(__FILE__,"all buffers in use", NR_BUFS); if(bp->b_bytes < fs_block_size) { - phys_bytes ph; ASSERT(!bp->bp); ASSERT(bp->b_bytes == 0); - if(!(bp->bp = alloc_contig(fs_block_size, 0, &ph))) { + if(!(bp->bp = alloc_contig(fs_block_size, 0, NULL))) { printf("MFS: couldn't allocate a new block.\n"); for(bp = front; bp && bp->b_bytes < fs_block_size; bp = bp->b_next) diff --git a/servers/pm/misc.c b/servers/pm/misc.c index 2d2c3cdf7..27e0aed91 100644 --- a/servers/pm/misc.c +++ b/servers/pm/misc.c @@ -314,6 +314,13 @@ PUBLIC int do_getprocnr() /* This call should be moved to DS. */ if (mp->mp_effuid != 0) { + /* For now, allow non-root processes to request their own endpoint. */ + if (m_in.pid < 0 && m_in.namelen == 0) { + mp->mp_reply.PM_ENDPT = who_e; + mp->mp_reply.PM_PENDPT = NONE; + return OK; + } + printf("PM: unauthorized call of do_getprocnr by proc %d\n", mp->mp_endpoint); sys_sysctl_stacktrace(mp->mp_endpoint); -- 2.44.0