diff --git a/usr.sbin/vmctl/main.c b/usr.sbin/vmctl/main.c index 444477f0ff6..18f15368851 100644 --- a/usr.sbin/vmctl/main.c +++ b/usr.sbin/vmctl/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.83 2024/11/21 13:26:25 claudio Exp $ */ +/* $OpenBSD: main.c,v 1.84 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -209,7 +209,9 @@ vmmaction(struct parse_result *res) if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL) err(1, "malloc"); - imsgbuf_init(ibuf, ctl_sock); + if (imsgbuf_init(ibuf, ctl_sock) == -1) + err(1, "imsgbuf_init"); + imsgbuf_allow_fdpass(ibuf); } switch (res->action) { diff --git a/usr.sbin/vmd/control.c b/usr.sbin/vmd/control.c index e3dd2ad36b6..84d4b183f57 100644 --- a/usr.sbin/vmd/control.c +++ b/usr.sbin/vmd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.48 2024/11/21 13:25:30 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.49 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2010-2015 Reyk Floeter @@ -305,7 +305,13 @@ control_accept(int listenfd, short event, void *arg) return; } - imsgbuf_init(&c->iev.ibuf, connfd); + if (imsgbuf_init(&c->iev.ibuf, connfd) == -1) { + log_warn("%s: failed to init imsgbuf", __func__); + close(connfd); + free(c); + return; + } + imsgbuf_allow_fdpass(&c->iev.ibuf); c->iev.handler = control_dispatch_imsg; c->iev.events = EV_READ; c->iev.data = cs; diff --git a/usr.sbin/vmd/proc.c b/usr.sbin/vmd/proc.c index 1c9b1eb2dc8..7d58baa9190 100644 --- a/usr.sbin/vmd/proc.c +++ b/usr.sbin/vmd/proc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proc.c,v 1.32 2024/11/21 13:25:30 claudio Exp $ */ +/* $OpenBSD: proc.c,v 1.33 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2010 - 2016 Reyk Floeter @@ -154,8 +154,10 @@ proc_connect(struct privsep *ps) for (inst = 0; inst < ps->ps_instances[dst]; inst++) { iev = &ps->ps_ievs[dst][inst]; - imsgbuf_init(&iev->ibuf, - ps->ps_pp->pp_pipes[dst][inst]); + if (imsgbuf_init(&iev->ibuf, + ps->ps_pp->pp_pipes[dst][inst]) == -1) + fatal("imsgbuf_init"); + imsgbuf_allow_fdpass(&iev->ibuf); event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data); event_add(&iev->ev, NULL); @@ -264,7 +266,9 @@ proc_accept(struct privsep *ps, int fd, enum privsep_procid dst, pp->pp_pipes[dst][n] = fd; iev = &ps->ps_ievs[dst][n]; - imsgbuf_init(&iev->ibuf, fd); + if (imsgbuf_init(&iev->ibuf, fd) == -1) + fatal("imsgbuf_init"); + imsgbuf_allow_fdpass(&iev->ibuf); event_set(&iev->ev, iev->ibuf.fd, iev->events, iev->handler, iev->data); event_add(&iev->ev, NULL); } diff --git a/usr.sbin/vmd/vioblk.c b/usr.sbin/vmd/vioblk.c index fe9f39f5b8e..42d57b20a4c 100644 --- a/usr.sbin/vmd/vioblk.c +++ b/usr.sbin/vmd/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.19 2024/11/21 13:25:30 claudio Exp $ */ +/* $OpenBSD: vioblk.c,v 1.20 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -174,7 +174,11 @@ vioblk_main(int fd, int fd_vmm) /* Configure our sync channel event handler. */ log_debug("%s: wiring in sync channel handler (fd=%d)", __func__, dev.sync_fd); - imsgbuf_init(&dev.sync_iev.ibuf, dev.sync_fd); + if (imsgbuf_init(&dev.sync_iev.ibuf, dev.sync_fd) == -1) { + log_warn("imsgbuf_init"); + goto fail; + } + imsgbuf_allow_fdpass(&dev.sync_iev.ibuf); dev.sync_iev.handler = handle_sync_io; dev.sync_iev.data = &dev; dev.sync_iev.events = EV_READ; diff --git a/usr.sbin/vmd/vionet.c b/usr.sbin/vmd/vionet.c index 00dd732c6a0..283f9827d42 100644 --- a/usr.sbin/vmd/vionet.c +++ b/usr.sbin/vmd/vionet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vionet.c,v 1.21 2024/11/21 13:25:30 claudio Exp $ */ +/* $OpenBSD: vionet.c,v 1.22 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2023 Dave Voutila @@ -241,7 +241,11 @@ vionet_main(int fd, int fd_vmm) /* Configure our sync channel event handler. */ log_debug("%s: wiring in sync channel handler (fd=%d)", __func__, dev.sync_fd); - imsgbuf_init(&dev.sync_iev.ibuf, dev.sync_fd); + if (imsgbuf_init(&dev.sync_iev.ibuf, dev.sync_fd) == -1) { + log_warnx("imsgbuf_init"); + goto fail; + } + imsgbuf_allow_fdpass(&dev.sync_iev.ibuf); dev.sync_iev.handler = handle_sync_io; dev.sync_iev.data = &dev; dev.sync_iev.events = EV_READ; diff --git a/usr.sbin/vmd/virtio.c b/usr.sbin/vmd/virtio.c index 4806407b087..37185b7f96d 100644 --- a/usr.sbin/vmd/virtio.c +++ b/usr.sbin/vmd/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.121 2024/11/21 13:25:30 claudio Exp $ */ +/* $OpenBSD: virtio.c,v 1.122 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -1381,7 +1381,11 @@ virtio_dev_launch(struct vmd_vm *vm, struct virtio_dev *dev) * communication will be synchronous. We expect the child to * report itself "ready" to confirm the launch was a success. */ - imsgbuf_init(&iev->ibuf, sync_fds[0]); + if (imsgbuf_init(&iev->ibuf, sync_fds[0]) == -1) { + log_warn("%s: failed to init imsgbuf", __func__); + goto err; + } + imsgbuf_allow_fdpass(&iev->ibuf); ret = imsgbuf_read_one(&iev->ibuf, &imsg); if (ret == 0 || ret == -1) { log_warnx("%s: failed to receive ready message from " @@ -1496,7 +1500,9 @@ vm_device_pipe(struct virtio_dev *dev, void (*cb)(int, short, void *), log_debug("%s: initializing '%c' device pipe (fd=%d)", __func__, dev->dev_type, fd); - imsgbuf_init(&iev->ibuf, fd); + if (imsgbuf_init(&iev->ibuf, fd) == -1) + fatal("imsgbuf_init"); + imsgbuf_allow_fdpass(&iev->ibuf); iev->handler = cb; iev->data = dev; iev->events = EV_READ; diff --git a/usr.sbin/vmd/vmm.c b/usr.sbin/vmd/vmm.c index 06d9ead0933..3113766c30a 100644 --- a/usr.sbin/vmd/vmm.c +++ b/usr.sbin/vmd/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.129 2024/11/21 13:25:30 claudio Exp $ */ +/* $OpenBSD: vmm.c,v 1.130 2024/11/21 13:39:34 claudio Exp $ */ /* * Copyright (c) 2015 Mike Larkin @@ -470,7 +470,11 @@ vmm_pipe(struct vmd_vm *vm, int fd, void (*cb)(int, short, void *)) return (-1); } - imsgbuf_init(&iev->ibuf, fd); + if (imsgbuf_init(&iev->ibuf, fd) == -1) { + log_warn("failed to init imsgbuf"); + return (-1); + } + imsgbuf_allow_fdpass(&iev->ibuf); iev->handler = cb; iev->data = vm; imsg_event_add(iev);