diff options
author | Sebastien Marie <semarie@cvs.openbsd.org> | 2015-09-30 11:36:08 +0000 |
---|---|---|
committer | Sebastien Marie <semarie@cvs.openbsd.org> | 2015-09-30 11:36:08 +0000 |
commit | 79eb9a318258687457f3926a9712aabb34c6c569 (patch) | |
tree | a13675da40ea274cecfee80f0f940cac7718cb35 /sys | |
parent | ded5ecd296e14ad5fdbd36dcd07f55568e05bb34 (diff) |
implement new "prot_exec" tame(2) request:
- by default, a tamed-program don't have the possibility to use PROT_EXEC for
mmap(2) or mprotect(2)
- for that, use the request "prot_exec" (that could be dropped later)
initial idea from deraadt@ and kettenis@
"make complete sense" beck@
ok deraadt@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/kern/kern_tame.c | 5 | ||||
-rw-r--r-- | sys/sys/tame.h | 3 | ||||
-rw-r--r-- | sys/uvm/uvm_mmap.c | 13 |
3 files changed, 17 insertions, 4 deletions
diff --git a/sys/kern/kern_tame.c b/sys/kern/kern_tame.c index c432f48d98b..5a3b17f99d1 100644 --- a/sys/kern/kern_tame.c +++ b/sys/kern/kern_tame.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_tame.c,v 1.44 2015/09/29 14:41:27 deraadt Exp $ */ +/* $OpenBSD: kern_tame.c,v 1.45 2015/09/30 11:36:07 semarie Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -226,7 +226,8 @@ static const struct { { "proc", TAME_PROC }, { "cpath", TAME_CPATH }, { "abort", TAME_ABORT }, - { "fattr", TAME_FATTR } + { "fattr", TAME_FATTR }, + { "prot_exec", TAME_PROTEXEC }, }; int diff --git a/sys/sys/tame.h b/sys/sys/tame.h index f0c886f0ea2..4f3b82edc1a 100644 --- a/sys/sys/tame.h +++ b/sys/sys/tame.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tame.h,v 1.7 2015/09/11 15:29:47 deraadt Exp $ */ +/* $OpenBSD: tame.h,v 1.8 2015/09/30 11:36:07 semarie Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -39,6 +39,7 @@ #define TAME_PROC 0x00001000 /* fork, waitpid, etc */ #define TAME_CPATH 0x00002000 /* allow creat, mkdir, path creations */ #define TAME_FATTR 0x00004000 /* allow explicit file st_* mods */ +#define TAME_PROTEXEC 0x00008000 /* allow use of PROT_EXEC */ #define TAME_ABORT 0x08000000 /* SIGABRT instead of SIGKILL */ diff --git a/sys/uvm/uvm_mmap.c b/sys/uvm/uvm_mmap.c index 23e369172f3..00145afead8 100644 --- a/sys/uvm/uvm_mmap.c +++ b/sys/uvm/uvm_mmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uvm_mmap.c,v 1.118 2015/09/28 18:36:08 tedu Exp $ */ +/* $OpenBSD: uvm_mmap.c,v 1.119 2015/09/30 11:36:07 semarie Exp $ */ /* $NetBSD: uvm_mmap.c,v 1.49 2001/02/18 21:19:08 chs Exp $ */ /* @@ -65,6 +65,7 @@ #include <sys/stat.h> #include <sys/specdev.h> #include <sys/stdint.h> +#include <sys/tame.h> #include <sys/unistd.h> /* for KBIND* */ #include <sys/user.h> @@ -364,6 +365,11 @@ sys_mmap(struct proc *p, void *v, register_t *retval) if (size == 0) return (EINVAL); + if ((p->p_p->ps_flags & PS_TAMED) && + !(p->p_p->ps_tame & TAME_PROTEXEC) && + (prot & PROT_EXEC)) + return (tame_fail(p, EPERM, TAME_PROTEXEC)); + /* align file position and save offset. adjust size. */ ALIGN_ADDR(pos, size, pageoff); @@ -662,6 +668,11 @@ sys_mprotect(struct proc *p, void *v, register_t *retval) if ((prot & PROT_MASK) != prot) return (EINVAL); + if ((p->p_p->ps_flags & PS_TAMED) && + !(p->p_p->ps_tame & TAME_PROTEXEC) && + (prot & PROT_EXEC)) + return (tame_fail(p, EPERM, TAME_PROTEXEC)); + /* * align the address to a page boundary, and adjust the size accordingly */ |