CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: christos Date: Wed Aug 26 22:57:56 UTC 2020 Modified Files: src/usr.bin/sockstat: Makefile sockstat.c Log Message: undo previous, now sockstat works without privs To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/sockstat/Makefile cvs rdiff -u -r1.22 -r1.23 src/usr.bin/sockstat/sockstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/Makefile diff -u src/usr.bin/sockstat/Makefile:1.6 src/usr.bin/sockstat/Makefile:1.7 --- src/usr.bin/sockstat/Makefile:1.6 Tue Aug 25 12:39:16 2020 +++ src/usr.bin/sockstat/Makefile Wed Aug 26 18:57:55 2020 @@ -1,11 +1,8 @@ -# $NetBSD: Makefile,v 1.6 2020/08/25 16:39:16 christos Exp $ +# $NetBSD: Makefile,v 1.7 2020/08/26 22:57:55 christos Exp $ .include RUMPPRG= sockstat -BINGRP= kmem -BINMODE=2555 -USE_FORT?= yes # setgid .PATH: ${.CURDIR}/../../lib/libc/gen CPPFLAGS+= -DRUMP_ACTION Index: src/usr.bin/sockstat/sockstat.c diff -u src/usr.bin/sockstat/sockstat.c:1.22 src/usr.bin/sockstat/sockstat.c:1.23 --- src/usr.bin/sockstat/sockstat.c:1.22 Tue Aug 25 10:05:17 2020 +++ src/usr.bin/sockstat/sockstat.c Wed Aug 26 18:57:55 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sockstat.c,v 1.22 2020/08/25 14:05:17 christos Exp $ */ +/* $NetBSD: sockstat.c,v 1.23 2020/08/26 22:57:55 christos Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: sockstat.c,v 1.22 2020/08/25 14:05:17 christos Exp $"); +__RCSID("$NetBSD: sockstat.c,v 1.23 2020/08/26 22:57:55 christos Exp $"); #endif #define _KMEMUSER @@ -179,11 +179,6 @@ main(int argc, char *argv[]) if (prog_init && prog_init() == -1) err(1, "init"); - /* Not used, but we set the PK_KMEM flag like this */ - int fd = open("/dev/mem", O_RDONLY); - if (fd == -1) - err(EXIT_FAILURE, "Can't open `/dev/mem'"); - close(fd); if ((portmap != NULL) && (pf_list == 0)) { pf_list = PF_LIST_INET; #ifdef INET6
CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: christos Date: Tue Aug 25 16:39:16 UTC 2020 Modified Files: src/usr.bin/sockstat: Makefile Log Message: turn on fortify since it is setgid (from scole_mail) To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/sockstat/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/Makefile diff -u src/usr.bin/sockstat/Makefile:1.5 src/usr.bin/sockstat/Makefile:1.6 --- src/usr.bin/sockstat/Makefile:1.5 Tue Aug 25 10:05:17 2020 +++ src/usr.bin/sockstat/Makefile Tue Aug 25 12:39:16 2020 @@ -1,10 +1,11 @@ -# $NetBSD: Makefile,v 1.5 2020/08/25 14:05:17 christos Exp $ +# $NetBSD: Makefile,v 1.6 2020/08/25 16:39:16 christos Exp $ .include RUMPPRG= sockstat BINGRP= kmem BINMODE=2555 +USE_FORT?= yes # setgid .PATH: ${.CURDIR}/../../lib/libc/gen CPPFLAGS+= -DRUMP_ACTION
CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: christos Date: Tue Aug 25 14:05:17 UTC 2020 Modified Files: src/usr.bin/sockstat: Makefile sockstat.c Log Message: RR/54971: scole_mail: sockstat command output incorrect for normal user As the PR hints, it is not enough to have kern.expose_address=1 to see kernel addresses, we also need to have the PK_KMEM bit set which we achieve by installing sockstat setgid kmem and opening and closing /dev/mem. (/usr/src/sys/kern/kern_proc.c:311). It is unfortunate that we need to give the program more privilege, to prove to the kernel that we have the privilege to see the data. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/sockstat/Makefile cvs rdiff -u -r1.21 -r1.22 src/usr.bin/sockstat/sockstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/Makefile diff -u src/usr.bin/sockstat/Makefile:1.4 src/usr.bin/sockstat/Makefile:1.5 --- src/usr.bin/sockstat/Makefile:1.4 Sun Aug 18 00:13:24 2019 +++ src/usr.bin/sockstat/Makefile Tue Aug 25 10:05:17 2020 @@ -1,8 +1,10 @@ -# $NetBSD: Makefile,v 1.4 2019/08/18 04:13:24 kamil Exp $ +# $NetBSD: Makefile,v 1.5 2020/08/25 14:05:17 christos Exp $ .include RUMPPRG= sockstat +BINGRP= kmem +BINMODE=2555 .PATH: ${.CURDIR}/../../lib/libc/gen CPPFLAGS+= -DRUMP_ACTION Index: src/usr.bin/sockstat/sockstat.c diff -u src/usr.bin/sockstat/sockstat.c:1.21 src/usr.bin/sockstat/sockstat.c:1.22 --- src/usr.bin/sockstat/sockstat.c:1.21 Sun Aug 18 00:13:24 2019 +++ src/usr.bin/sockstat/sockstat.c Tue Aug 25 10:05:17 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: sockstat.c,v 1.21 2019/08/18 04:13:24 kamil Exp $ */ +/* $NetBSD: sockstat.c,v 1.22 2020/08/25 14:05:17 christos Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: sockstat.c,v 1.21 2019/08/18 04:13:24 kamil Exp $"); +__RCSID("$NetBSD: sockstat.c,v 1.22 2020/08/25 14:05:17 christos Exp $"); #endif #define _KMEMUSER @@ -179,6 +179,11 @@ main(int argc, char *argv[]) if (prog_init && prog_init() == -1) err(1, "init"); + /* Not used, but we set the PK_KMEM flag like this */ + int fd = open("/dev/mem", O_RDONLY); + if (fd == -1) + err(EXIT_FAILURE, "Can't open `/dev/mem'"); + close(fd); if ((portmap != NULL) && (pf_list == 0)) { pf_list = PF_LIST_INET; #ifdef INET6
CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: christos Date: Sat Jan 14 01:01:48 UTC 2017 Modified Files: src/usr.bin/sockstat: sockstat.c Log Message: don't do _KERNEL; hides bswap stuff. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/sockstat/sockstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/sockstat.c diff -u src/usr.bin/sockstat/sockstat.c:1.18 src/usr.bin/sockstat/sockstat.c:1.19 --- src/usr.bin/sockstat/sockstat.c:1.18 Thu Jan 12 13:52:15 2017 +++ src/usr.bin/sockstat/sockstat.c Fri Jan 13 20:01:48 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: sockstat.c,v 1.18 2017/01/12 18:52:15 christos Exp $ */ +/* $NetBSD: sockstat.c,v 1.19 2017/01/14 01:01:48 christos Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,12 +31,12 @@ #include #ifndef lint -__RCSID("$NetBSD: sockstat.c,v 1.18 2017/01/12 18:52:15 christos Exp $"); +__RCSID("$NetBSD: sockstat.c,v 1.19 2017/01/14 01:01:48 christos Exp $"); #endif -#define _KERNEL +#define _KMEMUSER #include -#undef _KERNEL +#undef _KMEMUSER #include #include #include
CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: christos Date: Thu Jan 12 18:52:15 UTC 2017 Modified Files: src/usr.bin/sockstat: sockstat.c Log Message: fix compilation To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/sockstat/sockstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/sockstat.c diff -u src/usr.bin/sockstat/sockstat.c:1.17 src/usr.bin/sockstat/sockstat.c:1.18 --- src/usr.bin/sockstat/sockstat.c:1.17 Sun May 29 00:45:08 2011 +++ src/usr.bin/sockstat/sockstat.c Thu Jan 12 13:52:15 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: sockstat.c,v 1.17 2011/05/29 04:45:08 manu Exp $ */ +/* $NetBSD: sockstat.c,v 1.18 2017/01/12 18:52:15 christos Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,10 +31,12 @@ #include #ifndef lint -__RCSID("$NetBSD: sockstat.c,v 1.17 2011/05/29 04:45:08 manu Exp $"); +__RCSID("$NetBSD: sockstat.c,v 1.18 2017/01/12 18:52:15 christos Exp $"); #endif +#define _KERNEL #include +#undef _KERNEL #include #include #include @@ -48,10 +50,10 @@ __RCSID("$NetBSD: sockstat.c,v 1.17 2011 #include #include -#define _KERNEL +#define _KMEMUSER /* want DTYPE_* defines */ #include -#undef _KERNEL +#undef _KMEMUSER #include
CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: manu Date: Sun May 29 04:54:45 UTC 2011 Modified Files: src/usr.bin/sockstat: sockstat.1 Log Message: Document that localsocket may be of type SOCK_SEQPACKET To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/sockstat/sockstat.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/sockstat.1 diff -u src/usr.bin/sockstat/sockstat.1:1.7 src/usr.bin/sockstat/sockstat.1:1.8 --- src/usr.bin/sockstat/sockstat.1:1.7 Sun May 4 19:43:06 2008 +++ src/usr.bin/sockstat/sockstat.1 Sun May 29 04:54:45 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: sockstat.1,v 1.7 2008/05/04 19:43:06 martin Exp $ +.\" $NetBSD: sockstat.1,v 1.8 2011/05/29 04:54:45 manu Exp $ .\"- .\" Copyright (c) 2005 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -152,7 +152,7 @@ The file descriptor number of the socket. .It Li PROTO The transport protocol associated with the socket for Internet -sockets, or the type of socket (stream or datagram) for +sockets, or the type of socket (stream, seqpacket or datagram) for .Ux sockets. .It Li LOCAL ADDRESS
CVS commit: src/usr.bin/sockstat
Module Name:src Committed By: lukem Date: Mon Apr 13 10:56:57 UTC 2009 Modified Files: src/usr.bin/sockstat: sockstat.c Log Message: Fix WARNS=4 issues (-Wshadow -Wsign-compare) To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/sockstat/sockstat.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/sockstat/sockstat.c diff -u src/usr.bin/sockstat/sockstat.c:1.14 src/usr.bin/sockstat/sockstat.c:1.15 --- src/usr.bin/sockstat/sockstat.c:1.14 Tue Apr 29 06:53:03 2008 +++ src/usr.bin/sockstat/sockstat.c Mon Apr 13 10:56:56 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sockstat.c,v 1.14 2008/04/29 06:53:03 martin Exp $ */ +/* $NetBSD: sockstat.c,v 1.15 2009/04/13 10:56:56 lukem Exp $ */ /* * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: sockstat.c,v 1.14 2008/04/29 06:53:03 martin Exp $"); +__RCSID("$NetBSD: sockstat.c,v 1.15 2009/04/13 10:56:56 lukem Exp $"); #endif #include @@ -97,7 +97,7 @@ }; struct kinfo_file *flist; -u_int nfiles; +size_t flistc; int pf_list, only, nonames; bitstr_t *portmap; @@ -114,7 +114,8 @@ main(int argc, char *argv[]) { struct kinfo_pcb *kp; - int i, ch; + int ch; + size_t i; struct kinfo_proc2 p; pf_list = only = 0; @@ -210,7 +211,7 @@ get_files(); p.p_pid = 0; - for (i = 0; i < nfiles; i++) + for (i = 0; i < flistc; i++) if ((kp = pick_socket(&flist[i])) != NULL && get_proc(&p, flist[i].ki_pid) == 0) print_socket(&flist[i], kp, &p); @@ -326,9 +327,9 @@ sysctl_sucker(&name[0], namelen, &v, &sz); flist = v; - nfiles = sz / sizeof(struct kinfo_file); + flistc = sz / sizeof(struct kinfo_file); - qsort(flist, nfiles, sizeof(*flist), sort_files); + qsort(flist, flistc, sizeof(*flist), sort_files); } int