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 <bsd.own.mk>
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 <sys/cdefs.h>
#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