Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Oct 2025 15:31:22 GMT
From:      Mariusz Zaborski <oshogbo@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: a0c709ab5af4 - main - lsvfs(1): Capsicumise
Message-ID:  <202510061531.596FVMQ2060354@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by oshogbo:

URL: https://cgit.FreeBSD.org/src/commit/?id=a0c709ab5af4e87ce4579404c4ffbd4295ad12c5

commit a0c709ab5af4e87ce4579404c4ffbd4295ad12c5
Author:     Faraz Vahedi <kfv@kfv.io>
AuthorDate: 2025-08-11 17:53:55 +0000
Commit:     Mariusz Zaborski <oshogbo@FreeBSD.org>
CommitDate: 2025-10-06 15:30:17 +0000

    lsvfs(1): Capsicumise
    
    Signed-off-by: Faraz Vahedi <kfv@kfv.io>
    
    Reviewed by:    asomers, markj
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1498
---
 usr.bin/lsvfs/lsvfs.c | 51 +++++++++++++++++++++++++++------------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/usr.bin/lsvfs/lsvfs.c b/usr.bin/lsvfs/lsvfs.c
index 5477d96434ac..8925b8988cd3 100644
--- a/usr.bin/lsvfs/lsvfs.c
+++ b/usr.bin/lsvfs/lsvfs.c
@@ -5,10 +5,12 @@
  *
  */
 
+#include <sys/capsicum.h>
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/sysctl.h>
 
+#include <capsicum_helpers.h>
 #include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -38,41 +40,42 @@ static const char *fmt_flags(int);
 int
 main(int argc, char **argv)
 {
-	struct xvfsconf vfc, *xvfsp;
+	struct xvfsconf *xvfsp;
 	size_t cnt, buflen;
 	int rv = 0;
 
 	argc--, argv++;
 
+	if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
+		err(EXIT_FAILURE, "sysctl(vfs.conflist)");
+	if ((xvfsp = malloc(buflen)) == NULL)
+		errx(EXIT_FAILURE, "malloc failed");
+	if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
+		err(EXIT_FAILURE, "sysctl(vfs.conflist)");
+	cnt = buflen / sizeof(struct xvfsconf);
+
+	caph_cache_catpages();
+	if (caph_enter() != 0)
+		err(EXIT_FAILURE, "failed to enter capability mode");
+
 	printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
 	fputs(DASHES, stdout);
 
-	if (argc > 0) {
-		for (; argc > 0; argc--, argv++) {
-			if (getvfsbyname(*argv, &vfc) == 0) {
-				printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
-				    vfc.vfc_refcount, fmt_flags(vfc.vfc_flags));
-			} else {
-				warnx("VFS %s unknown or not loaded", *argv);
-				rv++;
+	for (size_t i = 0; i < cnt; i++) {
+		if (argc > 0) {
+			int j;
+			for (j = 0; j < argc; j++) {
+				if (strcmp(argv[j], xvfsp[i].vfc_name) == 0)
+					break;
 			}
+			if (j == argc)
+				continue;
 		}
-	} else {
-		if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
-			err(EXIT_FAILURE, "sysctl(vfs.conflist)");
-		if ((xvfsp = malloc(buflen)) == NULL)
-			errx(EXIT_FAILURE, "malloc failed");
-		if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
-			err(EXIT_FAILURE, "sysctl(vfs.conflist)");
-		cnt = buflen / sizeof(struct xvfsconf);
-
-		for (size_t i = 0; i < cnt; i++) {
-			printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
-			    xvfsp[i].vfc_refcount,
-			    fmt_flags(xvfsp[i].vfc_flags));
-		}
-		free(xvfsp);
+
+		printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
+		    xvfsp[i].vfc_refcount, fmt_flags(xvfsp[i].vfc_flags));
 	}
+	free(xvfsp);
 
 	return (rv);
 }



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