The branch main has been updated by fernape:

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

commit f014795ec3bd5efb88dfc249599e9665dc10a59e
Author:     Fernando Apesteguía <[email protected]>
AuthorDate: 2026-09-16 15:22:54 +0000
Commit:     Fernando Apesteguía <[email protected]>
CommitDate: 2026-09-18 18:00:37 +0000

    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
---
 usr.sbin/virtual_oss/virtual_oss/main.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/usr.sbin/virtual_oss/virtual_oss/main.c 
b/usr.sbin/virtual_oss/virtual_oss/main.c
index 1b03e2c8cf37..41658d0af325 100644
--- a/usr.sbin/virtual_oss/virtual_oss/main.c
+++ b/usr.sbin/virtual_oss/virtual_oss/main.c
@@ -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");

Reply via email to