diff options
| author | 2016-05-10 23:54:00 +0000 | |
|---|---|---|
| committer | 2016-05-10 23:54:00 +0000 | |
| commit | 1f03a107808e3522624d77a873bf41f236bde362 (patch) | |
| tree | 60aa9297b122875c0bfb2594001e983b92b855b0 /sys/kern/init_main.c | |
| parent | the bpf_mtap functions take const struct mbuf *s now (diff) | |
| download | wireguard-openbsd-1f03a107808e3522624d77a873bf41f236bde362.tar.xz wireguard-openbsd-1f03a107808e3522624d77a873bf41f236bde362.zip | |
If sendsyslog(2) is called with LOG_CONS before syslogd(8) has been
started and before init(8) has opened the console, the kernel could
crash as the console device has not been initialized. Open
/dev/console in the kernel before starting init(8) and keep it open.
This way sendsyslog(2) can be called early in the system.
OK beck@ deraadt@
Diffstat (limited to 'sys/kern/init_main.c')
| -rw-r--r-- | sys/kern/init_main.c | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 44f73a20e8b..87f76c07bd6 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init_main.c,v 1.251 2016/05/10 18:39:51 deraadt Exp $ */ +/* $OpenBSD: init_main.c,v 1.252 2016/05/10 23:54:00 bluhm Exp $ */ /* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */ /* @@ -120,7 +120,7 @@ struct proc *reaperproc; extern struct user *proc0paddr; -struct vnode *rootvp, *swapdev_vp; +struct vnode *rootvp, *swapdev_vp, *consolevp; int boothowto; struct timespec boottime; int ncpus = 1; @@ -133,7 +133,7 @@ long __guard_local __attribute__((section(".openbsd.randomdata"))); /* XXX return int so gcc -Werror won't complain */ int main(void *); -void check_console(struct proc *); +void open_console(struct proc *); void start_init(void *); void start_cleaner(void *); void start_update(void *); @@ -570,20 +570,30 @@ static char *initpaths[] = { }; void -check_console(struct proc *p) +open_console(struct proc *p) { struct nameidata nd; + struct vnode *vp; int error; NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, "/dev/console", p); - error = namei(&nd); + error = vn_open(&nd, FWRITE, 0); if (error) { if (error == ENOENT) printf("warning: /dev/console does not exist\n"); else printf("warning: /dev/console error %d\n", error); - } else - vrele(nd.ni_vp); + return; + } + vp = nd.ni_vp; + VOP_UNLOCK(vp, p); + if (!ISSET(vp->v_flag, VISTTY)) { + printf("warning: /dev/console is not a tty device\n"); + vn_close(vp, FWRITE, p->p_ucred, p); + return; + } + + consolevp = vp; } /* @@ -616,7 +626,7 @@ start_init(void *arg) while (start_init_exec == 0) (void) tsleep((void *)&start_init_exec, PWAIT, "initexec", 0); - check_console(p); + open_console(p); /* process 0 ignores SIGCHLD, but we can't */ p->p_p->ps_sigacts->ps_flags = 0; |
