diff options
author | 2001-06-22 23:55:22 +0000 | |
---|---|---|
committer | 2001-06-22 23:55:22 +0000 | |
commit | 51f754c156583a0ff0f96001697fadcfd8fddecd (patch) | |
tree | 0b6d05e095426691dae1a830982e81cdd93a822d /sys/kern/kern_prot.c | |
parent | exit() from a signal handler is a sin (diff) | |
download | wireguard-openbsd-51f754c156583a0ff0f96001697fadcfd8fddecd.tar.xz wireguard-openbsd-51f754c156583a0ff0f96001697fadcfd8fddecd.zip |
Try again. (this time it's tested).
Add proc_cansugid that checks if a process may raise it's privileges.
Rework exec to remove the old sugid workaround and check proc_cansugid
just before raising privileges.
Diffstat (limited to 'sys/kern/kern_prot.c')
-rw-r--r-- | sys/kern/kern_prot.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index 65b3474d264..b9d15d1a797 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_prot.c,v 1.17 2001/06/22 14:14:09 deraadt Exp $ */ +/* $OpenBSD: kern_prot.c,v 1.18 2001/06/22 23:55:24 art Exp $ */ /* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */ /* @@ -53,6 +53,7 @@ #include <sys/timeb.h> #include <sys/times.h> #include <sys/malloc.h> +#include <sys/filedesc.h> #include <sys/mount.h> #include <sys/syscallargs.h> @@ -655,3 +656,21 @@ sys_setlogin(p, v, retval) error = EINVAL; return (error); } + +/* + * Check if a process is allowed to raise its privileges. + */ +int +proc_cansugid(struct proc *p) +{ + /* ptrace(2)d processes shouldn't. */ + if ((p->p_flag & P_TRACED) != 0) + return (0); + + /* proceses with shared filedescriptors shouldn't. */ + if (p->p_fd->fd_refcnt > 1) + return (0); + + /* Allow. */ + return (1); +} |