Author: jamie
Date: Wed Aug 15 21:38:10 2018
New Revision: 337875
URL: https://svnweb.freebsd.org/changeset/base/337875

Log:
  MFC r331332:
  
    If a jail parameter isn't found, try loading a related kernel module.
  
  PR:           192092

Modified:
  stable/11/lib/libjail/jail.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libjail/jail.c
==============================================================================
--- stable/11/lib/libjail/jail.c        Wed Aug 15 21:38:06 2018        
(r337874)
+++ stable/11/lib/libjail/jail.c        Wed Aug 15 21:38:10 2018        
(r337875)
@@ -30,6 +30,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/jail.h>
+#include <sys/linker.h>
 #include <sys/socket.h>
 #include <sys/sysctl.h>
 
@@ -57,6 +58,7 @@ __FBSDID("$FreeBSD$");
 static int jailparam_import_enum(const char **values, int nvalues,
     const char *valstr, size_t valsize, int *value);
 static int jailparam_type(struct jailparam *jp);
+static int kldload_param(const char *name);
 static char *noname(const char *name);
 static char *nononame(const char *name);
 
@@ -885,6 +887,9 @@ jailparam_type(struct jailparam *jp)
                            "sysctl(0.3.%s): %s", name, strerror(errno));
                        return (-1);
                }
+               if (kldload_param(name) >= 0 && sysctl(mib, 2, mib + 2, &miblen,
+                   desc.s, strlen(desc.s)) >= 0)
+                       goto mib_desc;
                /*
                 * The parameter probably doesn't exist.  But it might be
                 * the "no" counterpart to a boolean.
@@ -1021,6 +1026,33 @@ jailparam_type(struct jailparam *jp)
                jp->jp_valuelen = 0;
        }
        return (0);
+}
+
+/*
+ * Attempt to load a kernel module matching an otherwise nonexistent parameter.
+ */
+static int
+kldload_param(const char *name)
+{
+       int kl;
+
+       if (strcmp(name, "linux") == 0 || strncmp(name, "linux.", 6) == 0)
+               kl = kldload("linux");
+       else if (strcmp(name, "sysvmsg") == 0 || strcmp(name, "sysvsem") == 0 ||
+           strcmp(name, "sysvshm") == 0)
+               kl = kldload(name);
+       else {
+               errno = ENOENT;
+               return (-1);
+       }
+       if (kl < 0 && errno == EEXIST) {
+               /*
+                * In the module is already loaded, then it must not contain
+                * the parameter.
+                */
+               errno = ENOENT;
+       }
+       return kl;
 }
 
 /*
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to