summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsolene <solene@openbsd.org>2019-01-31 13:36:42 +0000
committersolene <solene@openbsd.org>2019-01-31 13:36:42 +0000
commit3a1cc939d5da71acfd39520311e0216f53168e03 (patch)
tree34ec36554b63003ccba276a4c25ddbecfa032cdf
parentEnable IQ/ADC calibration in the athn(4) driver. (diff)
downloadwireguard-openbsd-3a1cc939d5da71acfd39520311e0216f53168e03.tar.xz
wireguard-openbsd-3a1cc939d5da71acfd39520311e0216f53168e03.zip
restrict commands reload and log to root only
tweaks and ok florian@
-rw-r--r--sbin/unwind/control.c25
-rw-r--r--usr.sbin/unwindctl/unwindctl.c15
2 files changed, 37 insertions, 3 deletions
diff --git a/sbin/unwind/control.c b/sbin/unwind/control.c
index 22a4858b642..0435ab35ecf 100644
--- a/sbin/unwind/control.c
+++ b/sbin/unwind/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.3 2019/01/29 19:13:01 florian Exp $ */
+/* $OpenBSD: control.c,v 1.4 2019/01/31 13:36:42 solene Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -74,7 +74,7 @@ control_init(char *path)
}
umask(old_umask);
- if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
+ if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) == -1) {
log_warn("%s: chmod", __func__);
close(fd);
(void)unlink(path);
@@ -204,6 +204,8 @@ control_dispatch_imsg(int fd, short event, void *bula)
struct imsg imsg;
ssize_t n;
int verbose;
+ uid_t euid;
+ gid_t egid;
if ((c = control_connbyfd(fd)) == NULL) {
log_warnx("%s: fd %d: not found", __func__, fd);
@@ -224,6 +226,11 @@ control_dispatch_imsg(int fd, short event, void *bula)
}
}
+ if (getpeereid(fd, &euid, &egid) == -1) {
+ control_close(fd);
+ return;
+ }
+
for (;;) {
if ((n = imsg_get(&c->iev.ibuf, &imsg)) == -1) {
control_close(fd);
@@ -233,6 +240,20 @@ control_dispatch_imsg(int fd, short event, void *bula)
break;
switch (imsg.hdr.type) {
+ case IMSG_CTL_LOG_VERBOSE:
+ case IMSG_CTL_RELOAD:
+ if (euid != 0) {
+ log_debug("%s: need to be root", __func__);
+ imsg_free(&imsg);
+ control_close(fd);
+ return;
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (imsg.hdr.type) {
case IMSG_CTL_RELOAD:
frontend_imsg_compose_main(imsg.hdr.type, 0, NULL, 0);
break;
diff --git a/usr.sbin/unwindctl/unwindctl.c b/usr.sbin/unwindctl/unwindctl.c
index 7ffc86f42fe..21146b84767 100644
--- a/usr.sbin/unwindctl/unwindctl.c
+++ b/usr.sbin/unwindctl/unwindctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: unwindctl.c,v 1.2 2019/01/27 12:41:39 florian Exp $ */
+/* $OpenBSD: unwindctl.c,v 1.3 2019/01/31 13:36:42 solene Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -108,6 +108,19 @@ main(int argc, char *argv[])
imsg_init(ibuf, ctl_sock);
done = 0;
+ /* Check for root-only actions */
+ switch (res->action) {
+ case LOG_DEBUG:
+ case LOG_VERBOSE:
+ case LOG_BRIEF:
+ case RELOAD:
+ if (geteuid() != 0)
+ errx(1, "need root privileges");
+ break;
+ default:
+ break;
+ }
+
/* Process user request. */
switch (res->action) {
case LOG_DEBUG: