diff options
-rw-r--r-- | bin/ps/Makefile | 4 | ||||
-rw-r--r-- | bin/ps/nlist.c | 7 | ||||
-rw-r--r-- | bin/ps/ps.c | 23 |
3 files changed, 14 insertions, 20 deletions
diff --git a/bin/ps/Makefile b/bin/ps/Makefile index 0b0fdb921f6..4db5969da8b 100644 --- a/bin/ps/Makefile +++ b/bin/ps/Makefile @@ -1,11 +1,9 @@ -# $OpenBSD: Makefile,v 1.7 2001/06/27 06:16:44 art Exp $ +# $OpenBSD: Makefile,v 1.8 2002/06/08 22:41:46 art Exp $ PROG= ps SRCS= fmt.c keyword.c nlist.c print.c ps.c DPADD= ${LIBM} ${LIBKVM} LDADD= -lm -lkvm -BINGRP= kmem -BINMODE=2555 .include <bsd.prog.mk> diff --git a/bin/ps/nlist.c b/bin/ps/nlist.c index 9c74980b9f1..601a0db5a03 100644 --- a/bin/ps/nlist.c +++ b/bin/ps/nlist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nlist.c,v 1.8 2001/12/05 02:23:59 art Exp $ */ +/* $OpenBSD: nlist.c,v 1.9 2002/06/08 22:41:46 art Exp $ */ /* $NetBSD: nlist.c,v 1.11 1995/03/21 09:08:03 cgd Exp $ */ /*- @@ -38,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)nlist.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: nlist.c,v 1.8 2001/12/05 02:23:59 art Exp $"; +static char rcsid[] = "$OpenBSD: nlist.c,v 1.9 2002/06/08 22:41:46 art Exp $"; #endif #endif /* not lint */ @@ -77,6 +77,7 @@ int fscale; /* kernel _fscale variable */ int maxslp; extern kvm_t *kd; +extern int kvm_sysctl_only; #define kread(x, v) \ kvm_read(kd, psnl[x].n_value, &v, sizeof v) != sizeof(v) @@ -90,7 +91,7 @@ donlist() rval = 0; nlistread = 1; - if (kd != NULL) { + if (kd != NULL && !kvm_sysctl_only) { if (kvm_nlist(kd, psnl)) { nlisterr(psnl); eval = 1; diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 1b4f77c2807..d65d24c45a6 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ps.c,v 1.27 2002/04/06 23:55:40 millert Exp $ */ +/* $OpenBSD: ps.c,v 1.28 2002/06/08 22:41:46 art Exp $ */ /* $NetBSD: ps.c,v 1.15 1995/05/18 20:33:25 mycroft Exp $ */ /*- @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)ps.c 8.4 (Berkeley) 4/2/94"; #else -static char rcsid[] = "$OpenBSD: ps.c,v 1.27 2002/04/06 23:55:40 millert Exp $"; +static char rcsid[] = "$OpenBSD: ps.c,v 1.28 2002/06/08 22:41:46 art Exp $"; #endif #endif /* not lint */ @@ -104,6 +104,7 @@ char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command"; char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command"; kvm_t *kd; +int kvm_sysctl_only; int main(argc, argv) @@ -276,22 +277,16 @@ main(argc, argv) } } #endif - /* - * Discard setgid privileges if not the running kernel so that bad - * guys can't print interesting stuff from kernel memory. - */ - if (nlistf != NULL || memf != NULL || swapf != NULL) { - setegid(getgid()); - setgid(getgid()); - } - kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf); + if (nlistf == NULL && memf == NULL && swapf == NULL) { + kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf); + kvm_sysctl_only = 1; + } else { + kd = kvm_openfiles(nlistf, memf, swapf, O_RDONLY, errbuf); + } if (kd == NULL && (nlistf != NULL || memf != NULL || swapf != NULL)) errx(1, "%s", errbuf); - setegid(getgid()); - setgid(getgid()); - if (!fmt) parsefmt(dfmt); |