Author: jhb
Date: Fri May 18 18:53:28 2012
New Revision: 235621
URL: http://svn.freebsd.org/changeset/base/235621

Log:
  MFC 234186
  If a linker file contains at least one module, but all of the modules
  fail to load (the MOD_LOAD event fails) during a kldload(2), unload the
  linker file and fail the kldload(2) with ENOEXEC.

Modified:
  stable/8/sys/kern/kern_linker.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/boot/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/e1000/   (props changed)
  stable/8/sys/i386/conf/XENHVM   (props changed)

Modified: stable/8/sys/kern/kern_linker.c
==============================================================================
--- stable/8/sys/kern/kern_linker.c     Fri May 18 18:51:13 2012        
(r235620)
+++ stable/8/sys/kern/kern_linker.c     Fri May 18 18:53:28 2012        
(r235621)
@@ -376,7 +376,7 @@ linker_load_file(const char *filename, l
 {
        linker_class_t lc;
        linker_file_t lf;
-       int foundfile, error;
+       int foundfile, error, modules;
 
        /* Refuse to load modules if securelevel raised */
        if (prison0.pr_securelevel > 0)
@@ -415,11 +415,22 @@ linker_load_file(const char *filename, l
                                linker_file_unload(lf, LINKER_UNLOAD_FORCE);
                                return (error);
                        }
+                       modules = !TAILQ_EMPTY(&lf->modules);
                        KLD_UNLOCK();
                        linker_file_register_sysctls(lf);
                        linker_file_sysinit(lf);
                        KLD_LOCK();
                        lf->flags |= LINKER_FILE_LINKED;
+
+                       /*
+                        * If all of the modules in this file failed
+                        * to load, unload the file and return an
+                        * error of ENOEXEC.
+                        */
+                       if (modules && TAILQ_EMPTY(&lf->modules)) {
+                               linker_file_unload(lf, LINKER_UNLOAD_FORCE);
+                               return (ENOEXEC);
+                       }
                        *result = lf;
                        return (0);
                }
@@ -623,7 +634,7 @@ linker_file_unload(linker_file_t file, i
 
        /*
         * Inform any modules associated with this file that they are
-        * being be unloaded.
+        * being unloaded.
         */
        MOD_XLOCK;
        for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to