Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 13 Jul 2019 00:23:21 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r349961 - stable/12/usr.sbin/bhyve
Message-ID:  <201907130023.x6D0NLem020869@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Sat Jul 13 00:23:20 2019
New Revision: 349961
URL: https://svnweb.freebsd.org/changeset/base/349961

Log:
  MFC 343068:
  Use capsicum_helpers(3) that allow us to simplify the code and its functions
  will return success when the kernel is built without support of
  the capability mode.
  
  It is important to note, that I'm taking a more conservative approach
  with these changes and it will be done in small steps.

Modified:
  stable/12/usr.sbin/bhyve/bhyverun.c
  stable/12/usr.sbin/bhyve/block_if.c
  stable/12/usr.sbin/bhyve/consport.c
  stable/12/usr.sbin/bhyve/dbgport.c
  stable/12/usr.sbin/bhyve/gdb.c
  stable/12/usr.sbin/bhyve/mevent.c
  stable/12/usr.sbin/bhyve/pci_e82545.c
  stable/12/usr.sbin/bhyve/pci_passthru.c
  stable/12/usr.sbin/bhyve/pci_virtio_console.c
  stable/12/usr.sbin/bhyve/pci_virtio_net.c
  stable/12/usr.sbin/bhyve/pci_virtio_rnd.c
  stable/12/usr.sbin/bhyve/rfb.c
  stable/12/usr.sbin/bhyve/uart_emul.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/usr.sbin/bhyve/bhyverun.c
==============================================================================
--- stable/12/usr.sbin/bhyve/bhyverun.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/bhyverun.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -54,7 +54,6 @@ __FBSDID("$FreeBSD$");
 #include <libgen.h>
 #include <unistd.h>
 #include <assert.h>
-#include <errno.h>
 #include <pthread.h>
 #include <pthread_np.h>
 #include <sysexits.h>
@@ -949,15 +948,13 @@ do_open(const char *vmname)
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_IOCTL, CAP_MMAP_RW);
-	if (cap_rights_limit(vm_get_device_fd(ctx), &rights) == -1 &&
-	    errno != ENOSYS)
+	if (caph_rights_limit(vm_get_device_fd(ctx), &rights) == -1) 
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 	vm_get_ioctls(&ncmds);
 	cmds = vm_get_ioctls(NULL);
 	if (cmds == NULL)
 		errx(EX_OSERR, "out of memory");
-	if (cap_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1 &&
-	    errno != ENOSYS)
+	if (caph_ioctls_limit(vm_get_device_fd(ctx), cmds, ncmds) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 	free((cap_ioctl_t *)cmds);
 #endif

Modified: stable/12/usr.sbin/bhyve/block_if.c
==============================================================================
--- stable/12/usr.sbin/bhyve/block_if.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/block_if.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -42,6 +42,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/disk.h>
 
 #include <assert.h>
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -473,7 +476,7 @@ blockif_open(const char *optstr, const char *ident)
 	if (ro)
 		cap_rights_clear(&rights, CAP_FSYNC, CAP_WRITE);
 
-	if (cap_rights_limit(fd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(fd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
@@ -504,7 +507,7 @@ blockif_open(const char *optstr, const char *ident)
 		psectsz = sbuf.st_blksize;
 
 #ifndef WITHOUT_CAPSICUM
-	if (cap_ioctls_limit(fd, cmds, nitems(cmds)) == -1 && errno != ENOSYS)
+	if (caph_ioctls_limit(fd, cmds, nitems(cmds)) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/consport.c
==============================================================================
--- stable/12/usr.sbin/bhyve/consport.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/consport.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -37,6 +37,9 @@ __FBSDID("$FreeBSD$");
 #endif
 #include <sys/select.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <stdio.h>
@@ -138,11 +141,9 @@ console_handler(struct vmctx *ctx, int vcpu, int in, i
 #ifndef WITHOUT_CAPSICUM
 		cap_rights_init(&rights, CAP_EVENT, CAP_IOCTL, CAP_READ,
 		    CAP_WRITE);
-		if (cap_rights_limit(STDIN_FILENO, &rights) == -1 &&
-		    errno != ENOSYS)
+		if (caph_rights_limit(STDIN_FILENO, &rights) == -1)
 			errx(EX_OSERR, "Unable to apply rights for sandbox");
-		if (cap_ioctls_limit(STDIN_FILENO, cmds, nitems(cmds)) == -1 &&
-		    errno != ENOSYS)
+		if (caph_ioctls_limit(STDIN_FILENO, cmds, nitems(cmds)) == -1)
 			errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 		ttyopen();

Modified: stable/12/usr.sbin/bhyve/dbgport.c
==============================================================================
--- stable/12/usr.sbin/bhyve/dbgport.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/dbgport.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -40,6 +40,9 @@ __FBSDID("$FreeBSD$");
 #include <netinet/tcp.h>
 #include <sys/uio.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -167,7 +170,7 @@ init_dbgport(int sport)
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_ACCEPT, CAP_READ, CAP_WRITE);
-	if (cap_rights_limit(listen_fd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(listen_fd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/gdb.c
==============================================================================
--- stable/12/usr.sbin/bhyve/gdb.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/gdb.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -1252,9 +1252,9 @@ limit_gdb_socket(int s)
 
 	cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE,
 	    CAP_SETSOCKOPT, CAP_IOCTL);
-	if (cap_rights_limit(s, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(s, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
-	if (cap_ioctls_limit(s, ioctls, nitems(ioctls)) == -1 && errno != ENOSYS)
+	if (caph_ioctls_limit(s, ioctls, nitems(ioctls)) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 }
 #endif

Modified: stable/12/usr.sbin/bhyve/mevent.c
==============================================================================
--- stable/12/usr.sbin/bhyve/mevent.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/mevent.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -37,6 +37,9 @@
 __FBSDID("$FreeBSD$");
 
 #include <assert.h>
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -420,7 +423,7 @@ mevent_dispatch(void)
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_KQUEUE);
-	if (cap_rights_limit(mfd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(mfd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
@@ -437,9 +440,9 @@ mevent_dispatch(void)
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
-	if (cap_rights_limit(mevent_pipefd[0], &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(mevent_pipefd[0], &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
-	if (cap_rights_limit(mevent_pipefd[1], &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(mevent_pipefd[1], &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/pci_e82545.c
==============================================================================
--- stable/12/usr.sbin/bhyve/pci_e82545.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/pci_e82545.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -43,6 +43,9 @@ __FBSDID("$FreeBSD$");
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -2241,7 +2244,7 @@ e82545_open_tap(struct e82545_softc *sc, char *opts)
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
-	if (cap_rights_limit(sc->esc_tapfd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(sc->esc_tapfd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 	

Modified: stable/12/usr.sbin/bhyve/pci_passthru.c
==============================================================================
--- stable/12/usr.sbin/bhyve/pci_passthru.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/pci_passthru.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -45,6 +45,9 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/iodev.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -674,9 +677,9 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
 	}
 
 #ifndef WITHOUT_CAPSICUM
-	if (cap_rights_limit(pcifd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(pcifd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
-	if (cap_ioctls_limit(pcifd, pci_ioctls, nitems(pci_ioctls)) == -1 && errno != ENOSYS)
+	if (caph_ioctls_limit(pcifd, pci_ioctls, nitems(pci_ioctls)) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
@@ -689,9 +692,9 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
 	}
 
 #ifndef WITHOUT_CAPSICUM
-	if (cap_rights_limit(iofd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(iofd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
-	if (cap_ioctls_limit(iofd, io_ioctls, nitems(io_ioctls)) == -1 && errno != ENOSYS)
+	if (caph_ioctls_limit(iofd, io_ioctls, nitems(io_ioctls)) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 
@@ -706,7 +709,7 @@ passthru_init(struct vmctx *ctx, struct pci_devinst *p
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_clear(&rights, CAP_IOCTL);
 	cap_rights_set(&rights, CAP_MMAP_RW);
-	if (cap_rights_limit(memfd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(memfd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/pci_virtio_console.c
==============================================================================
--- stable/12/usr.sbin/bhyve/pci_virtio_console.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/pci_virtio_console.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -43,6 +43,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -328,7 +331,7 @@ pci_vtcon_sock_add(struct pci_vtcon_softc *sc, const c
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
-	if (cap_rights_limit(s, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(s, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/pci_virtio_net.c
==============================================================================
--- stable/12/usr.sbin/bhyve/pci_virtio_net.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/pci_virtio_net.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -45,6 +45,9 @@ __FBSDID("$FreeBSD$");
 #endif
 #include <net/netmap_user.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -731,7 +734,7 @@ pci_vtnet_tap_setup(struct pci_vtnet_softc *sc, char *
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_EVENT, CAP_READ, CAP_WRITE);
-	if (cap_rights_limit(sc->vsc_tapfd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(sc->vsc_tapfd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/pci_virtio_rnd.c
==============================================================================
--- stable/12/usr.sbin/bhyve/pci_virtio_rnd.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/pci_virtio_rnd.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -43,6 +43,9 @@ __FBSDID("$FreeBSD$");
 #include <sys/linker_set.h>
 #include <sys/uio.h>
 
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
@@ -158,7 +161,7 @@ pci_vtrnd_init(struct vmctx *ctx, struct pci_devinst *
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_READ);
-	if (cap_rights_limit(fd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(fd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/rfb.c
==============================================================================
--- stable/12/usr.sbin/bhyve/rfb.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/rfb.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -45,6 +45,9 @@ __FBSDID("$FreeBSD$");
 #include <netdb.h>
 
 #include <assert.h>
+#ifndef WITHOUT_CAPSICUM
+#include <capsicum_helpers.h>
+#endif
 #include <err.h>
 #include <errno.h>
 #include <pthread.h>
@@ -1026,7 +1029,7 @@ rfb_init(char *hostname, int port, int wait, char *pas
 
 #ifndef WITHOUT_CAPSICUM
 	cap_rights_init(&rights, CAP_ACCEPT, CAP_EVENT, CAP_READ, CAP_WRITE);
-	if (cap_rights_limit(rc->sfd, &rights) == -1 && errno != ENOSYS)
+	if (caph_rights_limit(rc->sfd, &rights) == -1)
 		errx(EX_OSERR, "Unable to apply rights for sandbox");
 #endif
 

Modified: stable/12/usr.sbin/bhyve/uart_emul.c
==============================================================================
--- stable/12/usr.sbin/bhyve/uart_emul.c	Sat Jul 13 00:19:57 2019	(r349960)
+++ stable/12/usr.sbin/bhyve/uart_emul.c	Sat Jul 13 00:23:20 2019	(r349961)
@@ -684,14 +684,12 @@ uart_set_backend(struct uart_softc *sc, const char *op
 #ifndef WITHOUT_CAPSICUM
 		cap_rights_init(&rights, CAP_EVENT, CAP_IOCTL, CAP_READ,
 		    CAP_WRITE);
-		if (cap_rights_limit(sc->tty.fd, &rights) == -1 &&
-		    errno != ENOSYS)
+		if (caph_rights_limit(sc->tty.fd, &rights) == -1)
 			errx(EX_OSERR, "Unable to apply rights for sandbox");
-		if (cap_ioctls_limit(sc->tty.fd, cmds, nitems(cmds)) == -1 &&
-		    errno != ENOSYS)
+		if (caph_ioctls_limit(sc->tty.fd, cmds, nitems(cmds)) == -1)
 			errx(EX_OSERR, "Unable to apply rights for sandbox");
 		if (!uart_stdio) {
-			if (caph_limit_stdin() == -1 && errno != ENOSYS)
+			if (caph_limit_stdin() == -1)
 				errx(EX_OSERR,
 				    "Unable to apply rights for sandbox");
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907130023.x6D0NLem020869>