Subject: Re: lkm problems...
To: None <danaf@cs.rpi.edu>
From: Roland McGrath <roland@frob.com>
List: current-users
Date: 11/22/1995 11:55:58
Here is defeat-securelevel.c; it has been over a year and a half since
I compiled this, so it might need a little tweaking.  When you unload
the module, it resets the securelevel to 0 (singleuser); you can then
change it with sysctl (I think).


/* Trivial loadable kernel module to defeat the "kernel security level".

   Written 21 Jun 94 by Roland McGrath.
   The author places this file in the public domain.

   The module can only be loaded at security level 0 (single user,
   /etc/rc); it does nothing but set the security level to -1.  It can
   be unloaded at any time, which will reset the level to 0 if it is
   still -1.

   Compile with:
     cc -I/sys -c defeat-securelevel.c

   I use the following in /etc/rc.local to load this:
     if [ -r /etc/defeat-securelevel.o ]; then
       # Disable annoying "security".
       modload -e insecure -o /etc/defeat-securelevel /etc/defeat-securelevel.o
     fi
  */

#define KERNEL
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/exec.h>
#include <sys/lkm.h>

MOD_MISC ("defeat-securelevel")

static int
module_handle (struct lkm_table *lkmtp, int cmd)
{
  struct lkm_misc *args = lkmtp->private.lkm_misc;

  switch (cmd)
    {
    case LKM_E_LOAD:
      if (lkmexists (lkmtp))
	return EEXIST;
      if (securelevel > 0)
	return EPERM;
      securelevel = -1;
      return 0;

    case LKM_E_UNLOAD:
      if (securelevel < 0)
	securelevel = 0;
      return 0;

    default:
      return EINVAL;
    }
}

insecure (struct lkm_table *lkmtp,
	  int cmd,
	  int ver)
{
  DISPATCH(lkmtp,cmd,ver,module_handle,module_handle,lkm_nofunc)
}