sync with OpenBSD -current

This commit is contained in:
purplerain 2024-01-19 01:25:19 +00:00
parent 1cefe29c7e
commit fdad81bcfc
Signed by: purplerain
GPG Key ID: F42C07F07E2E35B7
32 changed files with 162 additions and 207 deletions

View File

@ -1,4 +1,4 @@
/* $OpenBSD: init.c,v 1.19 2023/10/12 16:37:05 deraadt Exp $ */ /* $OpenBSD: init.c,v 1.20 2024/01/18 19:00:11 deraadt Exp $ */
/* /*
* Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org> * Copyright (c) 2014,2015 Philip Guenther <guenther@openbsd.org>
* *
@ -35,11 +35,6 @@
#include "init.h" #include "init.h"
#if defined(APIWARN)
__warn_references(syscall,
"syscall() may go away, please rewrite code to use direct calls");
#endif
#define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
#ifdef TIB_EXTRA_ALIGN #ifdef TIB_EXTRA_ALIGN

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tls12_record_layer.c,v 1.40 2023/07/08 20:38:23 beck Exp $ */ /* $OpenBSD: tls12_record_layer.c,v 1.41 2024/01/18 16:30:43 tb Exp $ */
/* /*
* Copyright (c) 2020 Joel Sing <jsing@openbsd.org> * Copyright (c) 2020 Joel Sing <jsing@openbsd.org>
* *
@ -525,7 +525,7 @@ tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl,
goto err; goto err;
/* More special handling for GOST... */ /* More special handling for GOST... */
if (EVP_CIPHER_type(rl->cipher) == NID_gost89_cnt) { if (EVP_CIPHER_nid(rl->cipher) == NID_gost89_cnt) {
gost_param_nid = NID_id_tc26_gost_28147_param_Z; gost_param_nid = NID_id_tc26_gost_28147_param_Z;
if (EVP_MD_type(rl->handshake_hash) == NID_id_GostR3411_94) if (EVP_MD_type(rl->handshake_hash) == NID_id_GostR3411_94)
gost_param_nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet; gost_param_nid = NID_id_Gost28147_89_CryptoPro_A_ParamSet;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ec_point_conversion.c,v 1.14 2023/08/01 17:19:49 tb Exp $ */ /* $OpenBSD: ec_point_conversion.c,v 1.15 2024/01/18 16:49:40 tb Exp $ */
/* /*
* Copyright (c) 2021 Theo Buehler <tb@openbsd.org> * Copyright (c) 2021 Theo Buehler <tb@openbsd.org>
* Copyright (c) 2021 Joel Sing <jsing@openbsd.org> * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
@ -55,7 +55,6 @@ hexdump(const unsigned char *buf, size_t len)
for (i = 1; i <= len; i++) for (i = 1; i <= len; i++)
fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n"); fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n");
if (len % 8) if (len % 8)
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }

View File

@ -135,24 +135,6 @@ int amdgpu_vcn_sw_init(struct amdgpu_device *adev)
} }
} }
/*
* Some Steam Deck's BIOS versions are incompatible with the
* indirect SRAM mode, leading to amdgpu being unable to get
* properly probed (and even potentially crashing the kernel).
* Hence, check for these versions here - notice this is
* restricted to Vangogh (Deck's APU).
*/
if (adev->ip_versions[UVD_HWIP][0] == IP_VERSION(3, 0, 2)) {
const char *bios_ver = dmi_get_system_info(DMI_BIOS_VERSION);
if (bios_ver && (!strncmp("F7A0113", bios_ver, 7) ||
!strncmp("F7A0114", bios_ver, 7))) {
adev->vcn.indirect_sram = false;
dev_info(adev->dev,
"Steam Deck quirk: indirect SRAM disabled on BIOS %s\n", bios_ver);
}
}
hdr = (const struct common_firmware_header *)adev->vcn.fw->data; hdr = (const struct common_firmware_header *)adev->vcn.fw->data;
adev->vcn.fw_version = le32_to_cpu(hdr->ucode_version); adev->vcn.fw_version = le32_to_cpu(hdr->ucode_version);

View File

@ -719,9 +719,7 @@ static const struct i2c_algorithm smu_v11_0_i2c_algo = {
}; };
static const struct i2c_adapter_quirks smu_v11_0_i2c_control_quirks = { static const struct i2c_adapter_quirks smu_v11_0_i2c_control_quirks = {
#ifdef notyet
.flags = I2C_AQ_NO_ZERO_LEN, .flags = I2C_AQ_NO_ZERO_LEN,
#endif
}; };
int smu_v11_0_i2c_control_init(struct amdgpu_device *adev) int smu_v11_0_i2c_control_init(struct amdgpu_device *adev)

View File

@ -1907,7 +1907,7 @@ static void amdgpu_dm_fini(struct amdgpu_device *adev)
#ifdef notyet #ifdef notyet
hdcp_destroy(&adev->dev->kobj, adev->dm.hdcp_workqueue); hdcp_destroy(&adev->dev->kobj, adev->dm.hdcp_workqueue);
#else #else
STUB(); hdcp_destroy(NULL, adev->dm.hdcp_workqueue);
#endif #endif
adev->dm.hdcp_workqueue = NULL; adev->dm.hdcp_workqueue = NULL;
} }

View File

@ -23,7 +23,7 @@
* Rob Clark <robdclark@gmail.com> * Rob Clark <robdclark@gmail.com>
*/ */
#include <sys/stdarg.h> #include <linux/stdarg.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>

View File

@ -188,6 +188,7 @@
*/ */
#include <linux/anon_inodes.h> #include <linux/anon_inodes.h>
#include <linux/dma-fence-unwrap.h>
#include <linux/eventfd.h> #include <linux/eventfd.h>
#include <linux/file.h> #include <linux/file.h>
#include <linux/fs.h> #include <linux/fs.h>

View File

@ -539,9 +539,7 @@ static bool rc6_supported(struct intel_rc6 *rc6)
static void rpm_get(struct intel_rc6 *rc6) static void rpm_get(struct intel_rc6 *rc6)
{ {
GEM_BUG_ON(rc6->wakeref); GEM_BUG_ON(rc6->wakeref);
#ifdef notyet
pm_runtime_get_sync(rc6_to_i915(rc6)->drm.dev); pm_runtime_get_sync(rc6_to_i915(rc6)->drm.dev);
#endif
rc6->wakeref = true; rc6->wakeref = true;
} }

View File

@ -133,17 +133,6 @@ enum intel_platform {
#define INTEL_SUBPLATFORM_M 0 #define INTEL_SUBPLATFORM_M 0
#define INTEL_SUBPLATFORM_P 1 #define INTEL_SUBPLATFORM_P 1
/* ADL */
#define INTEL_SUBPLATFORM_RPL 0
/* ADL-P */
/*
* As #define INTEL_SUBPLATFORM_RPL 0 will apply
* here too, SUBPLATFORM_N will have different
* bit set
*/
#define INTEL_SUBPLATFORM_N 1
enum intel_ppgtt_type { enum intel_ppgtt_type {
INTEL_PPGTT_NONE = I915_GEM_PPGTT_NONE, INTEL_PPGTT_NONE = I915_GEM_PPGTT_NONE,
INTEL_PPGTT_ALIASING = I915_GEM_PPGTT_ALIASING, INTEL_PPGTT_ALIASING = I915_GEM_PPGTT_ALIASING,

View File

@ -34,7 +34,6 @@
#include "radeon.h" #include "radeon.h"
#include "radeon_prime.h" #include "radeon_prime.h"
struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj) struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj)
{ {
struct radeon_bo *bo = gem_to_radeon_bo(obj); struct radeon_bo *bo = gem_to_radeon_bo(obj);
@ -104,6 +103,7 @@ void radeon_gem_prime_unpin(struct drm_gem_object *obj)
radeon_bo_unreserve(bo); radeon_bo_unreserve(bo);
} }
struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj, struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
int flags) int flags)
{ {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: kern_sysctl.c,v 1.422 2024/01/15 15:47:37 mvs Exp $ */ /* $OpenBSD: kern_sysctl.c,v 1.423 2024/01/18 08:48:32 mvs Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*- /*-
@ -1283,13 +1283,8 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
if (so == NULL) { if (so == NULL) {
so = (struct socket *)fp->f_data; so = (struct socket *)fp->f_data;
/* if so is passed as parameter it is already locked */ /* if so is passed as parameter it is already locked */
switch (so->so_proto->pr_domain->dom_family) { solock(so);
case AF_INET:
case AF_INET6:
NET_LOCK();
locked = 1; locked = 1;
break;
}
} }
kf->so_type = so->so_type; kf->so_type = so->so_type;
@ -1312,14 +1307,14 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
kf->so_splicelen = -1; kf->so_splicelen = -1;
if (so->so_pcb == NULL) { if (so->so_pcb == NULL) {
if (locked) if (locked)
NET_UNLOCK(); sounlock(so);
break; break;
} }
switch (kf->so_family) { switch (kf->so_family) {
case AF_INET: { case AF_INET: {
struct inpcb *inpcb = so->so_pcb; struct inpcb *inpcb = so->so_pcb;
NET_ASSERT_LOCKED(); soassertlocked(so);
if (show_pointers) if (show_pointers)
kf->inp_ppcb = PTRTOINT64(inpcb->inp_ppcb); kf->inp_ppcb = PTRTOINT64(inpcb->inp_ppcb);
kf->inp_lport = inpcb->inp_lport; kf->inp_lport = inpcb->inp_lport;
@ -1341,7 +1336,7 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
case AF_INET6: { case AF_INET6: {
struct inpcb *inpcb = so->so_pcb; struct inpcb *inpcb = so->so_pcb;
NET_ASSERT_LOCKED(); soassertlocked(so);
if (show_pointers) if (show_pointers)
kf->inp_ppcb = PTRTOINT64(inpcb->inp_ppcb); kf->inp_ppcb = PTRTOINT64(inpcb->inp_ppcb);
kf->inp_lport = inpcb->inp_lport; kf->inp_lport = inpcb->inp_lport;
@ -1388,7 +1383,7 @@ fill_file(struct kinfo_file *kf, struct file *fp, struct filedesc *fdp,
} }
} }
if (locked) if (locked)
NET_UNLOCK(); sounlock(so);
break; break;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: if_wg.c,v 1.35 2024/01/01 18:47:02 mvs Exp $ */ /* $OpenBSD: if_wg.c,v 1.36 2024/01/18 08:46:41 mvs Exp $ */
/* /*
* Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. * Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
@ -518,7 +518,7 @@ wg_peer_destroy(struct wg_peer *peer)
continue; continue;
} }
NET_UNLOCK(); NET_UNLOCK();
tsleep_nsec(sc, PWAIT, "wg_ifq", 1000); tsleep_nsec(&nowake, PWAIT, "wg_ifq", 1000);
NET_LOCK(); NET_LOCK();
} }
NET_UNLOCK(); NET_UNLOCK();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: in_pcb.c,v 1.284 2024/01/09 19:57:00 bluhm Exp $ */ /* $OpenBSD: in_pcb.c,v 1.285 2024/01/18 11:03:16 claudio Exp $ */
/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */ /* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/* /*
@ -1306,6 +1306,10 @@ in_pcbset_rtableid(struct inpcb *inp, u_int rtableid)
{ {
struct inpcbtable *table = inp->inp_table; struct inpcbtable *table = inp->inp_table;
/* table must exist */
if (!rtable_exists(rtableid))
return (EINVAL);
mtx_enter(&table->inpt_mtx); mtx_enter(&table->inpt_mtx);
if (inp->inp_lport) { if (inp->inp_lport) {
mtx_leave(&table->inpt_mtx); mtx_leave(&table->inpt_mtx);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ip_output.c,v 1.392 2023/12/01 15:30:47 bluhm Exp $ */ /* $OpenBSD: ip_output.c,v 1.393 2024/01/18 11:03:16 claudio Exp $ */
/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/* /*
@ -1077,11 +1077,6 @@ ip_ctloutput(int op, struct socket *so, int level, int optname,
if (rtableid != rtid && rtableid != 0 && if (rtableid != rtid && rtableid != 0 &&
(error = suser(p)) != 0) (error = suser(p)) != 0)
break; break;
/* table must exist */
if (!rtable_exists(rtid)) {
error = EINVAL;
break;
}
error = in_pcbset_rtableid(inp, rtid); error = in_pcbset_rtableid(inp, rtid);
break; break;
case IP_PIPEX: case IP_PIPEX:

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ip6_output.c,v 1.282 2023/12/01 15:30:47 bluhm Exp $ */ /* $OpenBSD: ip6_output.c,v 1.283 2024/01/18 11:03:16 claudio Exp $ */
/* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */
/* /*
@ -1376,11 +1376,6 @@ do { \
if (rtableid != rtid && rtableid != 0 && if (rtableid != rtid && rtableid != 0 &&
(error = suser(p)) != 0) (error = suser(p)) != 0)
break; break;
/* table must exist */
if (!rtable_exists(rtid)) {
error = EINVAL;
break;
}
error = in_pcbset_rtableid(inp, rtid); error = in_pcbset_rtableid(inp, rtid);
break; break;
case IPV6_PIPEX: case IPV6_PIPEX:

View File

@ -1,4 +1,4 @@
/* $OpenBSD: tsort.c,v 1.37 2019/07/11 17:28:32 mestre Exp $ */ /* $OpenBSD: tsort.c,v 1.38 2024/01/18 15:34:29 espie Exp $ */
/* ex:ts=8 sw=4: /* ex:ts=8 sw=4:
* *
* Copyright (c) 1999-2004 Marc Espie <espie@openbsd.org> * Copyright (c) 1999-2004 Marc Espie <espie@openbsd.org>
@ -448,7 +448,7 @@ dequeue(struct array *h)
enqueue((h), (n)); \ enqueue((h), (n)); \
else \ else \
(h)->t[(h)->entries++] = (n); \ (h)->t[(h)->entries++] = (n); \
} while(0); } while(0)
static void static void
enqueue(struct array *h, struct node *n) enqueue(struct array *h, struct node *n)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: bgpctl.c,v 1.299 2024/01/08 15:09:14 claudio Exp $ */ /* $OpenBSD: bgpctl.c,v 1.300 2024/01/18 14:46:21 claudio Exp $ */
/* /*
* Copyright (c) 2003 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003 Henning Brauer <henning@openbsd.org>
@ -459,15 +459,15 @@ main(int argc, char *argv[])
int int
show(struct imsg *imsg, struct parse_result *res) show(struct imsg *imsg, struct parse_result *res)
{ {
struct peer *p; struct peer p;
struct ctl_timer t; struct ctl_timer t;
struct ctl_show_interface *iface; struct ctl_show_interface iface;
struct ctl_show_nexthop *nh; struct ctl_show_nexthop nh;
struct ctl_show_set set; struct ctl_show_set set;
struct ctl_show_rtr rtr; struct ctl_show_rtr rtr;
struct kroute_full *kf; struct kroute_full kf;
struct ktable *kt; struct ktable kt;
struct flowspec *f; struct flowspec f;
struct ctl_show_rib rib; struct ctl_show_rib rib;
struct rde_memstats stats; struct rde_memstats stats;
u_char *asdata; u_char *asdata;
@ -478,60 +478,60 @@ show(struct imsg *imsg, struct parse_result *res)
case IMSG_CTL_SHOW_NEIGHBOR: case IMSG_CTL_SHOW_NEIGHBOR:
if (output->neighbor == NULL) if (output->neighbor == NULL)
break; break;
p = imsg->data; if (imsg_get_data(imsg, &p, sizeof(p)) == -1)
output->neighbor(p, res); err(1, "imsg_get_data");
output->neighbor(&p, res);
break; break;
case IMSG_CTL_SHOW_TIMER: case IMSG_CTL_SHOW_TIMER:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(t))
errx(1, "wrong imsg len");
if (output->timer == NULL) if (output->timer == NULL)
break; break;
memcpy(&t, imsg->data, sizeof(t)); if (imsg_get_data(imsg, &t, sizeof(t)) == -1)
err(1, "imsg_get_data");
if (t.type > 0 && t.type < Timer_Max) if (t.type > 0 && t.type < Timer_Max)
output->timer(&t); output->timer(&t);
break; break;
case IMSG_CTL_SHOW_INTERFACE: case IMSG_CTL_SHOW_INTERFACE:
if (output->interface == NULL) if (output->interface == NULL)
break; break;
iface = imsg->data; if (imsg_get_data(imsg, &iface, sizeof(iface)) == -1)
output->interface(iface); err(1, "imsg_get_data");
output->interface(&iface);
break; break;
case IMSG_CTL_SHOW_NEXTHOP: case IMSG_CTL_SHOW_NEXTHOP:
if (output->nexthop == NULL) if (output->nexthop == NULL)
break; break;
nh = imsg->data; if (imsg_get_data(imsg, &nh, sizeof(nh)) == -1)
output->nexthop(nh); err(1, "imsg_get_data");
output->nexthop(&nh);
break; break;
case IMSG_CTL_KROUTE: case IMSG_CTL_KROUTE:
case IMSG_CTL_SHOW_NETWORK: case IMSG_CTL_SHOW_NETWORK:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(*kf))
errx(1, "wrong imsg len");
if (output->fib == NULL) if (output->fib == NULL)
break; break;
kf = imsg->data; if (imsg_get_data(imsg, &kf, sizeof(kf)) == -1)
output->fib(kf); err(1, "imsg_get_data");
output->fib(&kf);
break; break;
case IMSG_CTL_SHOW_FLOWSPEC: case IMSG_CTL_SHOW_FLOWSPEC:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(*f))
errx(1, "wrong imsg len");
if (output->flowspec == NULL) if (output->flowspec == NULL)
break; break;
f = imsg->data; if (imsg_get_data(imsg, &f, sizeof(f)) == -1)
output->flowspec(f); err(1, "imsg_get_data");
output->flowspec(&f);
break; break;
case IMSG_CTL_SHOW_FIB_TABLES: case IMSG_CTL_SHOW_FIB_TABLES:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(*kt))
errx(1, "wrong imsg len");
if (output->fib_table == NULL) if (output->fib_table == NULL)
break; break;
kt = imsg->data; if (imsg_get_data(imsg, &kt, sizeof(kt)) == -1)
output->fib_table(kt); err(1, "imsg_get_data");
output->fib_table(&kt);
break; break;
case IMSG_CTL_SHOW_RIB: case IMSG_CTL_SHOW_RIB:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(rib)) if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(rib))
errx(1, "wrong imsg len"); errx(1, "wrong imsg len");
if (output->rib == NULL) if (output->rib == NULL)
break; break;
/* XXX */
memcpy(&rib, imsg->data, sizeof(rib)); memcpy(&rib, imsg->data, sizeof(rib));
aslen = imsg->hdr.len - IMSG_HEADER_SIZE - sizeof(rib); aslen = imsg->hdr.len - IMSG_HEADER_SIZE - sizeof(rib);
asdata = imsg->data; asdata = imsg->data;
@ -559,37 +559,31 @@ show(struct imsg *imsg, struct parse_result *res)
output->attr(imsg->data, ilen, res->flags, 0); output->attr(imsg->data, ilen, res->flags, 0);
break; break;
case IMSG_CTL_SHOW_RIB_MEM: case IMSG_CTL_SHOW_RIB_MEM:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(stats))
errx(1, "wrong imsg len");
if (output->rib_mem == NULL) if (output->rib_mem == NULL)
break; break;
memcpy(&stats, imsg->data, sizeof(stats)); if (imsg_get_data(imsg, &stats, sizeof(stats)) == -1)
err(1, "imsg_get_data");
output->rib_mem(&stats); output->rib_mem(&stats);
return (1); return (1);
case IMSG_CTL_SHOW_SET: case IMSG_CTL_SHOW_SET:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(set))
errx(1, "wrong imsg len");
if (output->set == NULL) if (output->set == NULL)
break; break;
memcpy(&set, imsg->data, sizeof(set)); if (imsg_get_data(imsg, &set, sizeof(set)) == -1)
err(1, "imsg_get_data");
output->set(&set); output->set(&set);
break; break;
case IMSG_CTL_SHOW_RTR: case IMSG_CTL_SHOW_RTR:
if (imsg->hdr.len < IMSG_HEADER_SIZE + sizeof(rtr))
errx(1, "wrong imsg len");
if (output->rtr == NULL) if (output->rtr == NULL)
break; break;
memcpy(&rtr, imsg->data, sizeof(rtr)); if (imsg_get_data(imsg, &rtr, sizeof(rtr)) == -1)
err(1, "imsg_get_data");
output->rtr(&rtr); output->rtr(&rtr);
break; break;
case IMSG_CTL_RESULT: case IMSG_CTL_RESULT:
if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(rescode)) {
warnx("got IMSG_CTL_RESULT with wrong len");
break;
}
if (output->result == NULL) if (output->result == NULL)
break; break;
memcpy(&rescode, imsg->data, sizeof(rescode)); if (imsg_get_data(imsg, &rescode, sizeof(rescode)) == -1)
err(1, "imsg_get_data");
output->result(rescode); output->result(rescode);
return (1); return (1);
case IMSG_CTL_END: case IMSG_CTL_END:

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rtr.c,v 1.19 2024/01/04 16:38:18 claudio Exp $ */ /* $OpenBSD: rtr.c,v 1.20 2024/01/18 09:39:36 claudio Exp $ */
/* /*
* Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org>
@ -530,12 +530,10 @@ rtr_recalc(void)
/* walk tree in reverse because aspa_add_set requires that */ /* walk tree in reverse because aspa_add_set requires that */
RB_FOREACH_REVERSE(aspa, aspa_tree, &at) { RB_FOREACH_REVERSE(aspa, aspa_tree, &at) {
uint32_t as[2]; struct aspa_set as = { .as = aspa->as, .num = aspa->num };
as[0] = aspa->as;
as[1] = aspa->num;
imsg_compose(ibuf_rde, IMSG_RECONF_ASPA, 0, 0, -1, imsg_compose(ibuf_rde, IMSG_RECONF_ASPA, 0, 0, -1,
&as, sizeof(as)); &as, offsetof(struct aspa_set, tas));
imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_TAS, 0, 0, -1, imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_TAS, 0, 0, -1,
aspa->tas, aspa->num * sizeof(*aspa->tas)); aspa->tas, aspa->num * sizeof(*aspa->tas));
imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_DONE, 0, 0, -1, imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_DONE, 0, 0, -1,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: session.c,v 1.460 2024/01/16 13:15:31 claudio Exp $ */ /* $OpenBSD: session.c,v 1.461 2024/01/18 14:56:44 claudio Exp $ */
/* /*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@ -73,7 +73,7 @@ struct bgp_msg *session_newmsg(enum msg_type, uint16_t);
int session_sendmsg(struct bgp_msg *, struct peer *); int session_sendmsg(struct bgp_msg *, struct peer *);
void session_open(struct peer *); void session_open(struct peer *);
void session_keepalive(struct peer *); void session_keepalive(struct peer *);
void session_update(uint32_t, void *, size_t); void session_update(uint32_t, struct ibuf *);
void session_notification(struct peer *, uint8_t, uint8_t, struct ibuf *); void session_notification(struct peer *, uint8_t, uint8_t, struct ibuf *);
void session_notification_data(struct peer *, uint8_t, uint8_t, void *, void session_notification_data(struct peer *, uint8_t, uint8_t, void *,
size_t); size_t);
@ -1640,7 +1640,7 @@ session_keepalive(struct peer *p)
} }
void void
session_update(uint32_t peerid, void *data, size_t datalen) session_update(uint32_t peerid, struct ibuf *ibuf)
{ {
struct peer *p; struct peer *p;
struct bgp_msg *buf; struct bgp_msg *buf;
@ -1653,12 +1653,13 @@ session_update(uint32_t peerid, void *data, size_t datalen)
if (p->state != STATE_ESTABLISHED) if (p->state != STATE_ESTABLISHED)
return; return;
if ((buf = session_newmsg(UPDATE, MSGSIZE_HEADER + datalen)) == NULL) { if ((buf = session_newmsg(UPDATE, MSGSIZE_HEADER + ibuf_size(ibuf))) ==
NULL) {
bgp_fsm(p, EVNT_CON_FATAL); bgp_fsm(p, EVNT_CON_FATAL);
return; return;
} }
if (ibuf_add(buf->buf, data, datalen)) { if (ibuf_add_buf(buf->buf, ibuf)) {
ibuf_free(buf->buf); ibuf_free(buf->buf);
free(buf); free(buf);
bgp_fsm(p, EVNT_CON_FATAL); bgp_fsm(p, EVNT_CON_FATAL);
@ -2973,6 +2974,7 @@ session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt)
struct listen_addr *la, *next, nla; struct listen_addr *la, *next, nla;
struct session_dependon sdon; struct session_dependon sdon;
struct bgpd_config tconf; struct bgpd_config tconf;
size_t len;
uint32_t peerid; uint32_t peerid;
int n, fd, depend_ok, restricted; int n, fd, depend_ok, restricted;
uint16_t t; uint16_t t;
@ -3251,14 +3253,13 @@ session_dispatch_imsg(struct imsgbuf *imsgbuf, int idx, u_int *listener_cnt)
case IMSG_UPDATE: case IMSG_UPDATE:
if (idx != PFD_PIPE_ROUTE) if (idx != PFD_PIPE_ROUTE)
fatalx("update request not from RDE"); fatalx("update request not from RDE");
if (imsg.hdr.len > IMSG_HEADER_SIZE + len = imsg_get_len(&imsg);
MAX_PKTSIZE - MSGSIZE_HEADER || if (imsg_get_ibuf(&imsg, &ibuf) == -1 ||
imsg.hdr.len < IMSG_HEADER_SIZE + len > MAX_PKTSIZE - MSGSIZE_HEADER ||
MSGSIZE_UPDATE_MIN - MSGSIZE_HEADER) len < MSGSIZE_UPDATE_MIN - MSGSIZE_HEADER)
log_warnx("RDE sent invalid update"); log_warnx("RDE sent invalid update");
else else
session_update(imsg.hdr.peerid, imsg.data, session_update(peerid, &ibuf);
imsg.hdr.len - IMSG_HEADER_SIZE);
break; break;
case IMSG_UPDATE_ERR: case IMSG_UPDATE_ERR:
if (idx != PFD_PIPE_ROUTE) if (idx != PFD_PIPE_ROUTE)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: privsep.c,v 1.24 2020/01/23 00:17:27 dlg Exp $ */ /* $OpenBSD: privsep.c,v 1.25 2024/01/18 09:58:23 claudio Exp $ */
/* /*
* Copyright (c) 2010 Yasuoka Masahiko <yasuoka@openbsd.org> * Copyright (c) 2010 Yasuoka Masahiko <yasuoka@openbsd.org>
@ -526,7 +526,7 @@ privsep_recvfd(void)
if (r->retval != 0) if (r->retval != 0)
errno = r->rerrno; errno = r->rerrno;
else else
retval = imsg.fd; retval = imsg_get_fd(&imsg);
} }
imsg_free(&imsg); imsg_free(&imsg);
@ -646,18 +646,19 @@ privsep_priv_dispatch_imsg(struct imsgbuf *ibuf)
case PRIVSEP_BIND: { case PRIVSEP_BIND: {
struct PRIVSEP_BIND_ARG *a = imsg.data; struct PRIVSEP_BIND_ARG *a = imsg.data;
struct PRIVSEP_COMMON_RESP r = { -1, 0 }; struct PRIVSEP_COMMON_RESP r = { -1, 0 };
int fd;
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(*a) || if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(*a) ||
imsg.fd < 0) (fd = imsg_get_fd(&imsg)) < 0)
r.rerrno = EINVAL; r.rerrno = EINVAL;
else if (privsep_npppd_check_bind(a)) else if (privsep_npppd_check_bind(a))
r.rerrno = EACCES; r.rerrno = EACCES;
else { else {
if ((r.retval = bind(imsg.fd, if ((r.retval = bind(fd,
(struct sockaddr *)&a->name, a->namelen)) (struct sockaddr *)&a->name, a->namelen))
!= 0) != 0)
r.rerrno = errno; r.rerrno = errno;
close(imsg.fd); close(fd);
} }
(void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1, (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1,
&r, sizeof(r)); &r, sizeof(r));
@ -744,28 +745,29 @@ on_broken_entry:
case PRIVSEP_SENDTO: { case PRIVSEP_SENDTO: {
struct PRIVSEP_SENDTO_ARG *a = imsg.data; struct PRIVSEP_SENDTO_ARG *a = imsg.data;
struct PRIVSEP_COMMON_RESP r = { -1, 0 }; struct PRIVSEP_COMMON_RESP r = { -1, 0 };
int fd;
if (imsg.hdr.len < IMSG_HEADER_SIZE + sizeof(*a) || if (imsg.hdr.len < IMSG_HEADER_SIZE + sizeof(*a) ||
imsg.hdr.len < IMSG_HEADER_SIZE + imsg.hdr.len < IMSG_HEADER_SIZE +
offsetof(struct PRIVSEP_SENDTO_ARG, offsetof(struct PRIVSEP_SENDTO_ARG,
msg[a->len])) msg[a->len]))
r.rerrno = EMSGSIZE; r.rerrno = EMSGSIZE;
else if (imsg.fd < 0) else if ((fd = imsg_get_fd(&imsg)) < 0)
r.rerrno = EINVAL; r.rerrno = EINVAL;
else if (privsep_npppd_check_sendto(a)) else if (privsep_npppd_check_sendto(a))
r.rerrno = EACCES; r.rerrno = EACCES;
else { else {
if (a->tolen > 0) if (a->tolen > 0)
r.retval = sendto(imsg.fd, a->msg, r.retval = sendto(fd, a->msg,
a->len, a->flags, a->len, a->flags,
(struct sockaddr *)&a->to, (struct sockaddr *)&a->to,
a->tolen); a->tolen);
else else
r.retval = send(imsg.fd, a->msg, a->len, r.retval = send(fd, a->msg, a->len,
a->flags); a->flags);
if (r.retval < 0) if (r.retval < 0)
r.rerrno = errno; r.rerrno = errno;
close(imsg.fd); close(fd);
} }
(void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1, (void)imsg_compose(ibuf, PRIVSEP_OK, 0, 0, -1,
&r, sizeof(r)); &r, sizeof(r));

View File

@ -1,4 +1,4 @@
/* $OpenBSD: crl.c,v 1.30 2023/12/10 14:18:23 job Exp $ */ /* $OpenBSD: crl.c,v 1.31 2024/01/18 14:34:26 job Exp $ */
/* /*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* *
@ -96,7 +96,7 @@ crl_parse(const char *fn, const unsigned char *der, size_t len)
warnx("%s: X509_CRL_get0_lastUpdate failed", fn); warnx("%s: X509_CRL_get0_lastUpdate failed", fn);
goto out; goto out;
} }
if (!x509_get_time(at, &crl->lastupdate)) { if (!x509_get_time(at, &crl->thisupdate)) {
warnx("%s: ASN1_TIME_to_tm failed", fn); warnx("%s: ASN1_TIME_to_tm failed", fn);
goto out; goto out;
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: extern.h,v 1.198 2024/01/07 09:48:29 tb Exp $ */ /* $OpenBSD: extern.h,v 1.199 2024/01/18 14:34:26 job Exp $ */
/* /*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
* *
@ -435,7 +435,7 @@ struct crl {
char *aki; char *aki;
char *number; char *number;
X509_CRL *x509_crl; X509_CRL *x509_crl;
time_t lastupdate; /* do not use before */ time_t thisupdate; /* do not use before */
time_t nextupdate; /* do not use after */ time_t nextupdate; /* do not use after */
}; };
/* /*

View File

@ -1,4 +1,4 @@
/* $OpenBSD: parser.c,v 1.107 2024/01/08 19:46:19 tb Exp $ */ /* $OpenBSD: parser.c,v 1.108 2024/01/18 14:34:26 job Exp $ */
/* /*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -429,7 +429,7 @@ proc_parser_mft(struct entity *entp, struct mft **mp, char **crlfile,
} }
if (*mp != NULL) { if (*mp != NULL) {
*crlmtime = crl->lastupdate; *crlmtime = crl->thisupdate;
if (!crl_insert(&crlt, crl)) { if (!crl_insert(&crlt, crl)) {
warnx("%s: duplicate AKI %s", file, crl->aki); warnx("%s: duplicate AKI %s", file, crl->aki);
crl_free(crl); crl_free(crl);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: print.c,v 1.44 2023/11/16 11:18:47 tb Exp $ */ /* $OpenBSD: print.c,v 1.45 2024/01/18 14:34:26 job Exp $ */
/* /*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@ -352,12 +352,12 @@ crl_print(const struct crl *p)
free(issuer); free(issuer);
if (outformats & FORMAT_JSON) { if (outformats & FORMAT_JSON) {
json_do_int("valid_since", p->lastupdate); json_do_int("valid_since", p->thisupdate);
json_do_int("valid_until", p->nextupdate); json_do_int("valid_until", p->nextupdate);
json_do_array("revoked_certs"); json_do_array("revoked_certs");
} else { } else {
printf("CRL last update: %s\n", printf("CRL this update: %s\n",
time2str(p->lastupdate)); time2str(p->thisupdate));
printf("CRL next update: %s\n", printf("CRL next update: %s\n",
time2str(p->nextupdate)); time2str(p->nextupdate));
printf("Revoked Certificates:\n"); printf("Revoked Certificates:\n");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: config.c,v 1.73 2024/01/03 22:34:39 dv Exp $ */ /* $OpenBSD: config.c,v 1.74 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@ -552,10 +552,12 @@ config_getvm(struct privsep *ps, struct imsg *imsg)
{ {
struct vmop_create_params vmc; struct vmop_create_params vmc;
struct vmd_vm *vm = NULL; struct vmd_vm *vm = NULL;
int fd;
IMSG_SIZE_CHECK(imsg, &vmc); IMSG_SIZE_CHECK(imsg, &vmc);
memcpy(&vmc, imsg->data, sizeof(vmc)); memcpy(&vmc, imsg->data, sizeof(vmc));
vmc.vmc_kernel = imsg->fd; fd = imsg_get_fd(imsg);
vmc.vmc_kernel = fd;
errno = 0; errno = 0;
if (vm_register(ps, &vmc, &vm, imsg->hdr.peerid, 0) == -1) if (vm_register(ps, &vmc, &vm, imsg->hdr.peerid, 0) == -1)
@ -563,14 +565,12 @@ config_getvm(struct privsep *ps, struct imsg *imsg)
vm->vm_state |= VM_STATE_RUNNING; vm->vm_state |= VM_STATE_RUNNING;
vm->vm_peerid = (uint32_t)-1; vm->vm_peerid = (uint32_t)-1;
vm->vm_kernel = imsg->fd; vm->vm_kernel = fd;
return (0); return (0);
fail: fail:
if (imsg->fd != -1) { if (fd != -1)
close(imsg->fd); close(fd);
imsg->fd = -1;
}
vm_remove(vm, __func__); vm_remove(vm, __func__);
if (errno == 0) if (errno == 0)
@ -584,6 +584,7 @@ config_getdisk(struct privsep *ps, struct imsg *imsg)
{ {
struct vmd_vm *vm; struct vmd_vm *vm;
unsigned int n, idx; unsigned int n, idx;
int fd;
errno = 0; errno = 0;
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
@ -593,8 +594,9 @@ config_getdisk(struct privsep *ps, struct imsg *imsg)
IMSG_SIZE_CHECK(imsg, &n); IMSG_SIZE_CHECK(imsg, &n);
memcpy(&n, imsg->data, sizeof(n)); memcpy(&n, imsg->data, sizeof(n));
fd = imsg_get_fd(imsg);
if (n >= vm->vm_params.vmc_ndisks || imsg->fd == -1) { if (n >= vm->vm_params.vmc_ndisks || fd == -1) {
log_warnx("invalid disk id"); log_warnx("invalid disk id");
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
@ -605,7 +607,7 @@ config_getdisk(struct privsep *ps, struct imsg *imsg)
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
vm->vm_disks[n][idx] = imsg->fd; vm->vm_disks[n][idx] = fd;
return (0); return (0);
} }
@ -614,6 +616,7 @@ config_getif(struct privsep *ps, struct imsg *imsg)
{ {
struct vmd_vm *vm; struct vmd_vm *vm;
unsigned int n; unsigned int n;
int fd;
errno = 0; errno = 0;
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
@ -623,16 +626,18 @@ config_getif(struct privsep *ps, struct imsg *imsg)
IMSG_SIZE_CHECK(imsg, &n); IMSG_SIZE_CHECK(imsg, &n);
memcpy(&n, imsg->data, sizeof(n)); memcpy(&n, imsg->data, sizeof(n));
fd = imsg_get_fd(imsg);
if (n >= vm->vm_params.vmc_nnics || if (n >= vm->vm_params.vmc_nnics ||
vm->vm_ifs[n].vif_fd != -1 || imsg->fd == -1) { vm->vm_ifs[n].vif_fd != -1 || fd == -1) {
log_warnx("invalid interface id"); log_warnx("invalid interface id");
goto fail; goto fail;
} }
vm->vm_ifs[n].vif_fd = imsg->fd; vm->vm_ifs[n].vif_fd = fd;
return (0); return (0);
fail: fail:
if (imsg->fd != -1) if (fd != -1)
close(imsg->fd); close(fd);
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
@ -641,6 +646,7 @@ int
config_getcdrom(struct privsep *ps, struct imsg *imsg) config_getcdrom(struct privsep *ps, struct imsg *imsg)
{ {
struct vmd_vm *vm; struct vmd_vm *vm;
int fd;
errno = 0; errno = 0;
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
@ -648,16 +654,15 @@ config_getcdrom(struct privsep *ps, struct imsg *imsg)
return (-1); return (-1);
} }
if (imsg->fd == -1) { fd = imsg_get_fd(imsg);
if (fd == -1) {
log_warnx("invalid cdrom id"); log_warnx("invalid cdrom id");
goto fail; goto fail;
} }
vm->vm_cdrom = imsg->fd; vm->vm_cdrom = fd;
return (0); return (0);
fail: fail:
if (imsg->fd != -1)
close(imsg->fd);
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }

View File

@ -1,4 +1,4 @@
/* $OpenBSD: control.c,v 1.41 2023/04/28 19:46:42 dv Exp $ */ /* $OpenBSD: control.c,v 1.42 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2010-2015 Reyk Floeter <reyk@openbsd.org>
@ -440,7 +440,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
case IMSG_VMDOP_RELOAD: case IMSG_VMDOP_RELOAD:
case IMSG_CTL_RESET: case IMSG_CTL_RESET:
if (proc_compose_imsg(ps, PROC_PARENT, -1, if (proc_compose_imsg(ps, PROC_PARENT, -1,
imsg.hdr.type, fd, imsg.fd, imsg.hdr.type, fd, imsg_get_fd(&imsg),
imsg.data, IMSG_DATA_SIZE(&imsg)) == -1) imsg.data, IMSG_DATA_SIZE(&imsg)) == -1)
goto fail; goto fail;
break; break;
@ -453,7 +453,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
/* imsg.fd may contain kernel image fd. */ /* imsg.fd may contain kernel image fd. */
if (proc_compose_imsg(ps, PROC_PARENT, -1, if (proc_compose_imsg(ps, PROC_PARENT, -1,
imsg.hdr.type, fd, imsg.fd, &vmc, imsg.hdr.type, fd, imsg_get_fd(&imsg), &vmc,
sizeof(vmc)) == -1) { sizeof(vmc)) == -1) {
control_close(fd, cs); control_close(fd, cs);
return; return;
@ -508,7 +508,7 @@ control_dispatch_imsg(int fd, short event, void *arg)
vid.vid_uid); vid.vid_uid);
if (proc_compose_imsg(ps, PROC_PARENT, -1, if (proc_compose_imsg(ps, PROC_PARENT, -1,
imsg.hdr.type, fd, imsg.fd, imsg.hdr.type, fd, imsg_get_fd(&imsg),
&vid, sizeof(vid)) == -1) &vid, sizeof(vid)) == -1)
goto fail; goto fail;
break; break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: priv.c,v 1.23 2023/07/13 18:31:59 dv Exp $ */ /* $OpenBSD: priv.c,v 1.24 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2016 Reyk Floeter <reyk@openbsd.org>
@ -94,6 +94,7 @@ priv_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
struct vmop_addr_req vareq; struct vmop_addr_req vareq;
struct vmop_addr_result varesult; struct vmop_addr_result varesult;
char type[IF_NAMESIZE]; char type[IF_NAMESIZE];
int ifd;
switch (imsg->hdr.type) { switch (imsg->hdr.type) {
case IMSG_VMDOP_PRIV_IFDESCR: case IMSG_VMDOP_PRIV_IFDESCR:
@ -254,14 +255,15 @@ priv_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
varesult.var_vmid = vareq.var_vmid; varesult.var_vmid = vareq.var_vmid;
varesult.var_nic_idx = vareq.var_nic_idx; varesult.var_nic_idx = vareq.var_nic_idx;
ifd = imsg_get_fd(imsg);
/* resolve lladdr for the tap(4) and send back to parent */ /* resolve lladdr for the tap(4) and send back to parent */
if (ioctl(imsg->fd, SIOCGIFADDR, &varesult.var_addr) != 0) if (ioctl(ifd, SIOCGIFADDR, &varesult.var_addr) != 0)
log_warn("SIOCGIFADDR"); log_warn("SIOCGIFADDR");
else else
proc_compose_imsg(ps, PROC_PARENT, -1, proc_compose_imsg(ps, PROC_PARENT, -1,
IMSG_VMDOP_PRIV_GET_ADDR_RESPONSE, imsg->hdr.peerid, IMSG_VMDOP_PRIV_GET_ADDR_RESPONSE, imsg->hdr.peerid,
-1, &varesult, sizeof(varesult)); -1, &varesult, sizeof(varesult));
close(imsg->fd); close(ifd);
break; break;
case IMSG_VMDOP_CONFIG: case IMSG_VMDOP_CONFIG:
config_getconfig(env, imsg); config_getconfig(env, imsg);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: proc.c,v 1.21 2023/09/26 01:53:54 dv Exp $ */ /* $OpenBSD: proc.c,v 1.22 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2010 - 2016 Reyk Floeter <reyk@openbsd.org>
@ -661,7 +661,7 @@ proc_dispatch(int fd, short event, void *arg)
case IMSG_CTL_PROCFD: case IMSG_CTL_PROCFD:
IMSG_SIZE_CHECK(&imsg, &pf); IMSG_SIZE_CHECK(&imsg, &pf);
memcpy(&pf, imsg.data, sizeof(pf)); memcpy(&pf, imsg.data, sizeof(pf));
proc_accept(ps, imsg.fd, pf.pf_procid, proc_accept(ps, imsg_get_fd(&imsg), pf.pf_procid,
pf.pf_instance); pf.pf_instance);
break; break;
default: default:
@ -792,7 +792,8 @@ proc_forward_imsg(struct privsep *ps, struct imsg *imsg,
enum privsep_procid id, int n) enum privsep_procid id, int n)
{ {
return (proc_compose_imsg(ps, id, n, imsg->hdr.type, return (proc_compose_imsg(ps, id, n, imsg->hdr.type,
imsg->hdr.peerid, imsg->fd, imsg->data, IMSG_DATA_SIZE(imsg))); imsg->hdr.peerid, imsg_get_fd(imsg), imsg->data,
IMSG_DATA_SIZE(imsg)));
} }
struct imsgbuf * struct imsgbuf *

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vm.c,v 1.95 2024/01/10 04:13:59 dv Exp $ */ /* $OpenBSD: vm.c,v 1.96 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@ -596,7 +596,7 @@ vm_dispatch_vmm(int fd, short event, void *arg)
break; break;
case IMSG_VMDOP_SEND_VM_REQUEST: case IMSG_VMDOP_SEND_VM_REQUEST:
vmr.vmr_id = vm->vm_vmid; vmr.vmr_id = vm->vm_vmid;
vmr.vmr_result = send_vm(imsg.fd, vm); vmr.vmr_result = send_vm(imsg_get_fd(&imsg), vm);
imsg_compose_event(&vm->vm_iev, imsg_compose_event(&vm->vm_iev,
IMSG_VMDOP_SEND_VM_RESPONSE, IMSG_VMDOP_SEND_VM_RESPONSE,
imsg.hdr.peerid, imsg.hdr.pid, -1, &vmr, imsg.hdr.peerid, imsg.hdr.pid, -1, &vmr,

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmd.c,v 1.152 2023/09/26 01:53:54 dv Exp $ */ /* $OpenBSD: vmd.c,v 1.153 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@ -97,6 +97,7 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
{ {
struct privsep *ps = p->p_ps; struct privsep *ps = p->p_ps;
int res = 0, ret = 0, cmd = 0, verbose; int res = 0, ret = 0, cmd = 0, verbose;
int ifd;
unsigned int v = 0, flags; unsigned int v = 0, flags;
struct vmop_create_params vmc; struct vmop_create_params vmc;
struct vmop_id vid; struct vmop_id vid;
@ -111,7 +112,7 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
case IMSG_VMDOP_START_VM_REQUEST: case IMSG_VMDOP_START_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vmc); IMSG_SIZE_CHECK(imsg, &vmc);
memcpy(&vmc, imsg->data, sizeof(vmc)); memcpy(&vmc, imsg->data, sizeof(vmc));
vmc.vmc_kernel = imsg->fd; vmc.vmc_kernel = imsg_get_fd(imsg);
/* Try registering our VM in our list of known VMs. */ /* Try registering our VM in our list of known VMs. */
if (vm_register(ps, &vmc, &vm, 0, vmc.vmc_owner.uid)) { if (vm_register(ps, &vmc, &vm, 0, vmc.vmc_owner.uid)) {
@ -257,11 +258,12 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
IMSG_SIZE_CHECK(imsg, &vid); IMSG_SIZE_CHECK(imsg, &vid);
memcpy(&vid, imsg->data, sizeof(vid)); memcpy(&vid, imsg->data, sizeof(vid));
id = vid.vid_id; id = vid.vid_id;
ifd = imsg_get_fd(imsg);
if (vid.vid_id == 0) { if (vid.vid_id == 0) {
if ((vm = vm_getbyname(vid.vid_name)) == NULL) { if ((vm = vm_getbyname(vid.vid_name)) == NULL) {
res = ENOENT; res = ENOENT;
cmd = IMSG_VMDOP_SEND_VM_RESPONSE; cmd = IMSG_VMDOP_SEND_VM_RESPONSE;
close(imsg->fd); close(ifd);
break; break;
} else { } else {
vid.vid_id = vm->vm_vmid; vid.vid_id = vm->vm_vmid;
@ -269,43 +271,42 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
} else if ((vm = vm_getbyvmid(vid.vid_id)) == NULL) { } else if ((vm = vm_getbyvmid(vid.vid_id)) == NULL) {
res = ENOENT; res = ENOENT;
cmd = IMSG_VMDOP_SEND_VM_RESPONSE; cmd = IMSG_VMDOP_SEND_VM_RESPONSE;
close(imsg->fd); close(ifd);
break; break;
} }
vmr.vmr_id = vid.vid_id; vmr.vmr_id = vid.vid_id;
log_debug("%s: sending fd to vmm", __func__); log_debug("%s: sending fd to vmm", __func__);
proc_compose_imsg(ps, PROC_VMM, -1, imsg->hdr.type, proc_compose_imsg(ps, PROC_VMM, -1, imsg->hdr.type,
imsg->hdr.peerid, imsg->fd, &vid, sizeof(vid)); imsg->hdr.peerid, ifd, &vid, sizeof(vid));
break; break;
case IMSG_VMDOP_RECEIVE_VM_REQUEST: case IMSG_VMDOP_RECEIVE_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vid); IMSG_SIZE_CHECK(imsg, &vid);
memcpy(&vid, imsg->data, sizeof(vid)); memcpy(&vid, imsg->data, sizeof(vid));
if (imsg->fd == -1) { ifd = imsg_get_fd(imsg);
if (ifd == -1) {
log_warnx("%s: invalid fd", __func__); log_warnx("%s: invalid fd", __func__);
return (-1); return (-1);
} }
if (atomicio(read, imsg->fd, &vmh, sizeof(vmh)) != if (atomicio(read, ifd, &vmh, sizeof(vmh)) != sizeof(vmh)) {
sizeof(vmh)) {
log_warnx("%s: error reading vmh from received vm", log_warnx("%s: error reading vmh from received vm",
__func__); __func__);
res = EIO; res = EIO;
close(imsg->fd); close(ifd);
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
break; break;
} }
if (vmd_check_vmh(&vmh)) { if (vmd_check_vmh(&vmh)) {
res = ENOENT; res = ENOENT;
close(imsg->fd); close(ifd);
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
break; break;
} }
if (atomicio(read, imsg->fd, &vmc, sizeof(vmc)) != if (atomicio(read, ifd, &vmc, sizeof(vmc)) != sizeof(vmc)) {
sizeof(vmc)) {
log_warnx("%s: error reading vmc from received vm", log_warnx("%s: error reading vmc from received vm",
__func__); __func__);
res = EIO; res = EIO;
close(imsg->fd); close(ifd);
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
break; break;
} }
@ -317,14 +318,14 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg)
if (ret != 0) { if (ret != 0) {
res = errno; res = errno;
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
close(imsg->fd); close(ifd);
} else { } else {
vm->vm_state |= VM_STATE_RECEIVED; vm->vm_state |= VM_STATE_RECEIVED;
config_setvm(ps, vm, imsg->hdr.peerid, config_setvm(ps, vm, imsg->hdr.peerid,
vmc.vmc_owner.uid); vmc.vmc_owner.uid);
log_debug("%s: sending fd to vmm", __func__); log_debug("%s: sending fd to vmm", __func__);
proc_compose_imsg(ps, PROC_VMM, -1, proc_compose_imsg(ps, PROC_VMM, -1,
IMSG_VMDOP_RECEIVE_VM_END, vm->vm_vmid, imsg->fd, IMSG_VMDOP_RECEIVE_VM_END, vm->vm_vmid, ifd,
NULL, 0); NULL, 0);
} }
break; break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: vmm.c,v 1.116 2024/01/03 22:34:39 dv Exp $ */ /* $OpenBSD: vmm.c,v 1.117 2024/01/18 14:49:59 claudio Exp $ */
/* /*
* Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org> * Copyright (c) 2015 Mike Larkin <mlarkin@openbsd.org>
@ -252,7 +252,7 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
} }
imsg_compose_event(&vm->vm_iev, imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid, imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
imsg->fd, &vid, sizeof(vid)); imsg_get_fd(imsg), &vid, sizeof(vid));
break; break;
case IMSG_VMDOP_UNPAUSE_VM: case IMSG_VMDOP_UNPAUSE_VM:
IMSG_SIZE_CHECK(imsg, &vid); IMSG_SIZE_CHECK(imsg, &vid);
@ -265,7 +265,7 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
} }
imsg_compose_event(&vm->vm_iev, imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid, imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
imsg->fd, &vid, sizeof(vid)); imsg_get_fd(imsg), &vid, sizeof(vid));
break; break;
case IMSG_VMDOP_SEND_VM_REQUEST: case IMSG_VMDOP_SEND_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vid); IMSG_SIZE_CHECK(imsg, &vid);
@ -273,13 +273,13 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
id = vid.vid_id; id = vid.vid_id;
if ((vm = vm_getbyvmid(id)) == NULL) { if ((vm = vm_getbyvmid(id)) == NULL) {
res = ENOENT; res = ENOENT;
close(imsg->fd); close(imsg_get_fd(imsg)); /* XXX */
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
break; break;
} }
imsg_compose_event(&vm->vm_iev, imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid, imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
imsg->fd, &vid, sizeof(vid)); imsg_get_fd(imsg), &vid, sizeof(vid));
break; break;
case IMSG_VMDOP_RECEIVE_VM_REQUEST: case IMSG_VMDOP_RECEIVE_VM_REQUEST:
IMSG_SIZE_CHECK(imsg, &vmc); IMSG_SIZE_CHECK(imsg, &vmc);
@ -290,18 +290,18 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
break; break;
} }
vm->vm_tty = imsg->fd; vm->vm_tty = imsg_get_fd(imsg);
vm->vm_state |= VM_STATE_RECEIVED; vm->vm_state |= VM_STATE_RECEIVED;
vm->vm_state |= VM_STATE_PAUSED; vm->vm_state |= VM_STATE_PAUSED;
break; break;
case IMSG_VMDOP_RECEIVE_VM_END: case IMSG_VMDOP_RECEIVE_VM_END:
if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) { if ((vm = vm_getbyvmid(imsg->hdr.peerid)) == NULL) {
res = ENOENT; res = ENOENT;
close(imsg->fd); close(imsg_get_fd(imsg)); /* XXX */
cmd = IMSG_VMDOP_START_VM_RESPONSE; cmd = IMSG_VMDOP_START_VM_RESPONSE;
break; break;
} }
vm->vm_receive_fd = imsg->fd; vm->vm_receive_fd = imsg_get_fd(imsg);
res = vmm_start_vm(imsg, &id, &pid); res = vmm_start_vm(imsg, &id, &pid);
/* Check if the ID can be mapped correctly */ /* Check if the ID can be mapped correctly */
if ((id = vm_id2vmid(id, NULL)) == 0) if ((id = vm_id2vmid(id, NULL)) == 0)
@ -318,12 +318,12 @@ vmm_dispatch_parent(int fd, struct privsep_proc *p, struct imsg *imsg)
/* Forward hardware address details to the guest vm */ /* Forward hardware address details to the guest vm */
imsg_compose_event(&vm->vm_iev, imsg_compose_event(&vm->vm_iev,
imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid, imsg->hdr.type, imsg->hdr.peerid, imsg->hdr.pid,
imsg->fd, &var, sizeof(var)); imsg_get_fd(imsg), &var, sizeof(var));
break; break;
case IMSG_VMDOP_RECEIVE_VMM_FD: case IMSG_VMDOP_RECEIVE_VMM_FD:
if (env->vmd_fd > -1) if (env->vmd_fd > -1)
fatalx("already received vmm fd"); fatalx("already received vmm fd");
env->vmd_fd = imsg->fd; env->vmd_fd = imsg_get_fd(imsg);
/* Get and terminate all running VMs */ /* Get and terminate all running VMs */
get_info_vm(ps, NULL, 1); get_info_vm(ps, NULL, 1);
@ -656,7 +656,7 @@ vmm_start_vm(struct imsg *imsg, uint32_t *id, pid_t *pid)
vcp = &vm->vm_params.vmc_params; vcp = &vm->vm_params.vmc_params;
if (!(vm->vm_state & VM_STATE_RECEIVED)) { if (!(vm->vm_state & VM_STATE_RECEIVED)) {
if ((vm->vm_tty = imsg->fd) == -1) { if ((vm->vm_tty = imsg_get_fd(imsg)) == -1) {
log_warnx("%s: can't get tty", __func__); log_warnx("%s: can't get tty", __func__);
goto err; goto err;
} }