From 31757d5d98b0d66603d264379b0f812171df16a9 Mon Sep 17 00:00:00 2001 From: tb Date: Sat, 3 Jun 2017 04:34:41 +0000 Subject: [PATCH] Avoid printing garbage when aborting a program that tries to use a prohibited sysctl. ok deraadt --- sys/kern/kern_pledge.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_pledge.c b/sys/kern/kern_pledge.c index dae6a1bccb7..d25eb9df103 100644 --- a/sys/kern/kern_pledge.c +++ b/sys/kern/kern_pledge.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_pledge.c,v 1.210 2017/05/30 15:04:45 deraadt Exp $ */ +/* $OpenBSD: kern_pledge.c,v 1.211 2017/06/03 04:34:41 tb Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott @@ -891,6 +891,8 @@ pledge_sendfd(struct proc *p, struct file *fp) int pledge_sysctl(struct proc *p, int miblen, int *mib, void *new) { + int i; + if ((p->p_p->ps_flags & PS_PLEDGE) == 0) return (0); @@ -1053,9 +1055,11 @@ pledge_sysctl(struct proc *p, int miblen, int *mib, void *new) mib[0] == CTL_VM && mib[1] == VM_LOADAVG) return (0); - printf("%s(%d): sysctl %d: %d %d %d %d %d %d\n", - p->p_p->ps_comm, p->p_p->ps_pid, miblen, mib[0], mib[1], - mib[2], mib[3], mib[4], mib[5]); + printf("%s(%d): sysctl %d:", p->p_p->ps_comm, p->p_p->ps_pid, miblen); + for (i = 0; i < miblen; i++) + printf(" %d", mib[i]); + printf("\n"); + return pledge_fail(p, EINVAL, 0); } -- 2.20.1