diff options
Diffstat (limited to 'usr.sbin/vmd/config.c')
-rw-r--r-- | usr.sbin/vmd/config.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/usr.sbin/vmd/config.c b/usr.sbin/vmd/config.c index fc8114a9e5e..5f6db1afba8 100644 --- a/usr.sbin/vmd/config.c +++ b/usr.sbin/vmd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.46 2018/07/11 13:19:47 reyk Exp $ */ +/* $OpenBSD: config.c,v 1.47 2018/07/13 10:26:57 reyk Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -173,7 +173,6 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid) struct vmd_if *vif; struct vmop_create_params *vmc = &vm->vm_params; struct vm_create_params *vcp = &vmc->vmc_params; - struct stat stat_buf; unsigned int i; int fd = -1, vmboot = 0; int kernfd = -1, *diskfds = NULL, *tapfds = NULL; @@ -241,6 +240,15 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid) errno = VMD_BIOS_MISSING; goto fail; } + + if (vm_checkaccess(kernfd, + vmc->vmc_checkaccess & VMOP_CREATE_KERNEL, + uid, R_OK) == -1) { + log_warnx("vm \"%s\" no read access to %s", + vcp->vcp_name, vcp->vcp_kernel); + errno = EPERM; + goto fail; + } } /* Open CDROM image for child */ @@ -253,16 +261,13 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid) errno = VMD_CDROM_MISSING; goto fail; } - if (fstat(cdromfd, &stat_buf) == -1) { - log_warn("%s: can't open cdrom %s", __func__, - vcp->vcp_cdrom); - errno = VMD_CDROM_MISSING; - goto fail; - } - if (S_ISREG(stat_buf.st_mode) == 0) { - log_warnx("%s: cdrom %s is not a regular file", - __func__, vcp->vcp_cdrom); - errno = VMD_CDROM_INVALID; + + if (vm_checkaccess(cdromfd, + vmc->vmc_checkaccess & VMOP_CREATE_CDROM, + uid, R_OK) == -1) { + log_warnx("vm \"%s\" no read access to %s", + vcp->vcp_name, vcp->vcp_cdrom); + errno = EPERM; goto fail; } } @@ -277,16 +282,13 @@ config_setvm(struct privsep *ps, struct vmd_vm *vm, uint32_t peerid, uid_t uid) errno = VMD_DISK_MISSING; goto fail; } - if (fstat(diskfds[i], &stat_buf) == -1) { - log_warn("%s: can't open disk %s", __func__, - vcp->vcp_disks[i]); - errno = VMD_DISK_INVALID; - goto fail; - } - if (S_ISREG(stat_buf.st_mode) == 0) { - log_warnx("%s: disk %s is not a regular file", __func__, - vcp->vcp_disks[i]); - errno = VMD_DISK_INVALID; + + if (vm_checkaccess(diskfds[i], + vmc->vmc_checkaccess & VMOP_CREATE_DISK, + uid, R_OK|W_OK) == -1) { + log_warnx("vm \"%s\" no read access to %s", + vcp->vcp_name, vcp->vcp_kernel); + errno = EPERM; goto fail; } } |