1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

Convert vmd over to check for imsgbuf_init failure and sprinkle a lot of

imsgbuf_allow_fdpass() since vmd and vmctl pass fds left and right.

OK tb@
This commit is contained in:
claudio 2024-11-21 13:39:34 +00:00
parent 81e9819965
commit 0a9d031fce
7 changed files with 47 additions and 17 deletions

View File

@ -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 <reyk@openbsd.org>
@ -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) {

View File

@ -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 <reyk@openbsd.org>
@ -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;

View File

@ -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 <reyk@openbsd.org>
@ -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);
}

View File

@ -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 <dv@openbsd.org>
@ -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;

View File

@ -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 <dv@openbsd.org>
@ -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;

View File

@ -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 <mlarkin@openbsd.org>
@ -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;

View File

@ -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 <mlarkin@openbsd.org>
@ -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);