virtual_oss(8): Fix cuse.ko check

virtual_oss(8) checks if cuse(3) is loaded. However, kldload(2) ends up calling
kern_kldload that checks permissions first. It is only later on in
linker_load_module that -EEXIST is returned if the module is already loaded.
That means that users that can't load modules, always get a -EPERM error first
even if cuse.ko is already loaded and ready to use.

Change it to check if the kernel module is already loaded and try load it if it
isn't.

In addition move the program's arguments parsing early on because otherwise, a
user can't even access the program's help if cuse.ko is not loaded and the
user doesn't have permissions to do it.

Approved by:		obiwac@
Differential Revision:	https://reviews.freebsd.org/D59621
This commit is contained in:
Fernando Apesteguía committed 2026-09-18 20:00:37 +02:00
1 parent 1181ac7089
commit f014795ec3
1 file changed
+11 -5
+11 -5
View File
@@ -2564,6 +2564,7 @@ int
main(int argc, char **argv)
{
const char *ptrerr;
const char *cuse_mod = "cuse.ko";
struct sigaction sa;
struct cuse_dev *pdev = NULL;
struct virtual_profile *pvp;
@@ -2583,9 +2584,17 @@ main(int argc, char **argv)
atomic_init();
if (kldload("cuse.ko") < 0 && errno != EEXIST)
err(1, "Failed to load cuse kernel module");
ptrerr = parse_options(argc, argv, 1);
if (ptrerr != NULL)
errx(EX_USAGE, "%s", ptrerr);
if (kldfind(cuse_mod) < 0 && errno == ENOENT) {
/* module is not loaded */
if (kldload(cuse_mod) < 0 && errno != EEXIST)
err(1, "Failed to load cuse kernel module");
}
/* cuse is loaded, initialize it */
if (cuse_init() != 0)
errx(EX_USAGE, "Could not connect to cuse module");
@@ -2599,9 +2608,6 @@ main(int argc, char **argv)
if (sigaction(SIGTERM, &sa, NULL) < 0)
err(1, "sigaction(SIGTERM)");
ptrerr = parse_options(argc, argv, 1);
if (ptrerr != NULL)
errx(EX_USAGE, "%s", ptrerr);
if (voss_dsp_rx_device[0] == 0 || voss_dsp_tx_device[0] == 0)
errx(EX_USAGE, "Missing -f argument");