We need to track the pid of the connecting control connection to be
authorflorian <florian@openbsd.org>
Wed, 24 Feb 2021 18:34:14 +0000 (18:34 +0000)
committerflorian <florian@openbsd.org>
Wed, 24 Feb 2021 18:34:14 +0000 (18:34 +0000)
able to send answers back to the correct client in case two are
connecting at the same time. We also need to pass the pid around to
the resolver process so that it can hand it back to us.
Debugged by deraadt and dlg who noticed that answers would always
arrive on the first control connection.

deraadt@ points out that tracking the pid is not the best choice in
case one process wants to hold open two connections but at least this
brings us in line with all the other privsep daemons with control
tools. If we change this we should change it in all daemons.

sbin/unwind/control.c

index 0739bee..a5b2d96 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: control.c,v 1.16 2021/01/19 16:52:12 florian Exp $    */
+/*     $OpenBSD: control.c,v 1.17 2021/02/24 18:34:14 florian Exp $    */
 
 /*
  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -272,9 +272,11 @@ control_dispatch_imsg(int fd, short event, void *bula)
                        break;
                }
 
+               c->iev.ibuf.pid = imsg.hdr.pid;
                switch (imsg.hdr.type) {
                case IMSG_CTL_RELOAD:
-                       frontend_imsg_compose_main(imsg.hdr.type, 0, NULL, 0);
+                       frontend_imsg_compose_main(imsg.hdr.type, imsg.hdr.pid,
+                           NULL, 0);
                        break;
                case IMSG_CTL_LOG_VERBOSE:
                        if (IMSG_DATA_SIZE(imsg) != sizeof(verbose))
@@ -294,8 +296,8 @@ control_dispatch_imsg(int fd, short event, void *bula)
                case IMSG_CTL_MEM:
                        if (IMSG_DATA_SIZE(imsg) != 0)
                                break;
-                       frontend_imsg_compose_resolver(imsg.hdr.type, 0, NULL,
-                           0);
+                       frontend_imsg_compose_resolver(imsg.hdr.type,
+                           imsg.hdr.pid, NULL, 0);
                        break;
                default:
                        log_debug("%s: error handling imsg %d", __func__,