Home | History | Annotate | Download | only in securelevel
History log of /src/sys/secmodel/securelevel/secmodel_securelevel.c
RevisionDateAuthorComments
 1.37  05-Dec-2020  thorpej Remove unnecessary inclusion of <sys/timevar.h>.
 1.36  28-May-2020  riastradh branches: 1.36.2;
Accept ioctl(RNDADDDATA) estimates at securelevel 1 (but not 2).

securelevel=1 is supposed to be a reasonable default for normal
computers. This got in the way of ever getting entropy from a seed
on a machine with no HWRNG -- e.g., from another machine, or by
making the executive decision that what has been sampled is good
enough and issuing `head -c 32 < /dev/urandom > /dev/random'.
 1.35  11-May-2020  alnsn KAUTH_MACHDEP_SVS_DISABLE is deprecated.

sysctl machdep.svs.enabled can't be changed anymore
at runtime because it's now a boot option.
 1.34  16-Mar-2020  pgoyette Use the module subsystem's ability to process SYSCTL_SETUP() entries to
automate installation of sysctl nodes.

Note that there are still a number of device and pseudo-device modules
that create entries tied to individual device units, rather than to the
module itself. These are not changed.
 1.33  21-Feb-2020  joerg Explicitly cast pointers to uintptr_t before casting to enums. They are
not necessarily the same size. Don't cast pointers to bool, check for
NULL instead.
 1.32  15-Jul-2018  maxv branches: 1.32.4; 1.32.6;
Retire ipkdb entirely. The option was removed from the config files
yesterday.

ok kamil christos
 1.31  26-Apr-2018  alnsn branches: 1.31.2;
Add KAUTH_MACHDEP_SVS_DISABLE and add support to secmodel_securelevel(9).

Disabling SVS is denied at securelevel 1 and above.
 1.30  25-Feb-2014  pooka branches: 1.30.22; 1.30.28;
Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
 1.29  28-Jan-2013  jym branches: 1.29.2;
Re-instate backwards compatible security.models.bsd44.{curtain,securelevel}.

They were mistakenly removed when curtain and securelevel moved to
secmodel_extensions(9).

Reported by tls@ on tech-security@.

XXX will ask for pull-up for -6.
 1.28  27-Jun-2012  cheusov branches: 1.28.2;
KNF fix. spaces vs. tab
 1.27  13-Mar-2012  elad Replace the remaining KAUTH_GENERIC_ISSUSER authorization calls with
something meaningful. All relevant documentation has been updated or
written.

Most of these changes were brought up in the following messages:

http://mail-index.netbsd.org/tech-kern/2012/01/18/msg012490.html
http://mail-index.netbsd.org/tech-kern/2012/01/19/msg012502.html
http://mail-index.netbsd.org/tech-kern/2012/02/17/msg012728.html

Thanks to christos, manu, njoly, and jmmv for input.

Huge thanks to pgoyette for spinning these changes through some build
cycles and ATF.
 1.26  17-Jan-2012  cegger branches: 1.26.2; 1.26.6;
fix secmodel implementation of CPU_UCODE.
ok wiz@ for the manpages
ok elad@
 1.25  13-Jan-2012  cegger Support CPU microcode loading via cpuctl(8).
Implemented and enabled via CPU_UCODE kernel config option
for x86 and Xen Dom0.
Tested on different AMD machines with different
CPU families.

ok wiz@ for the manpages
ok releng@
ok core@ via releng@
 1.24  05-Dec-2011  jym secmodel_eval(9) may want to access securelevel before it is set
to the right value, so init it first before registering secmodel(9).
 1.23  04-Dec-2011  jym Implement the register/deregister/evaluation API for secmodel(9). It
allows registration of callbacks that can be used later for
cross-secmodel "safe" communication.

When a secmodel wishes to know a property maintained by another
secmodel, it has to submit a request to it so the other secmodel can
proceed to evaluating the request. This is done through the
secmodel_eval(9) call; example:

bool isroot;
error = secmodel_eval("org.netbsd.secmodel.suser", "is-root",
cred, &isroot);
if (error == 0 && !isroot)
result = KAUTH_RESULT_DENY;

This one asks the suser module if the credentials are assumed to be root
when evaluated by suser module. If the module is present, it will
respond. If absent, the call will return an error.

Args and command are arbitrarily defined; it's up to the secmodel(9) to
document what it expects.

Typical example is securelevel testing: when someone wants to know
whether securelevel is raised above a certain level or not, the caller
has to request this property to the secmodel_securelevel(9) module.
Given that securelevel module may be absent from system's context (thus
making access to the global "securelevel" variable impossible or
unsafe), this API can cope with this absence and return an error.

We are using secmodel_eval(9) to implement a secmodel_extensions(9)
module, which plugs with the bsd44, suser and securelevel secmodels
to provide the logic behind curtain, usermount and user_set_cpu_affinity
modes, without adding hooks to traditional secmodels. This solves a
real issue with the current secmodel(9) code, as usermount or
user_set_cpu_affinity are not really tied to secmodel_suser(9).

The secmodel_eval(9) is also used to restrict security.models settings
when securelevel is above 0, through the "is-securelevel-above"
evaluation:
- curtain can be enabled any time, but cannot be disabled if
securelevel is above 0.
- usermount/user_set_cpu_affinity can be disabled any time, but cannot
be enabled if securelevel is above 0.

Regarding sysctl(7) entries:
curtain and usermount are now found under security.models.extensions
tree. The security.curtain and vfs.generic.usermount are still
accessible for backwards compat.

Documentation is incoming, I am proof-reading my writings.

Written by elad@, reviewed and tested (anita test + interact for rights
tests) by me. ok elad@.

See also
http://mail-index.netbsd.org/tech-security/2011/11/29/msg000422.html

XXX might consider va0 mapping too.

XXX Having a secmodel(9) specific printf (like aprint_*) for reporting
secmodel(9) errors might be a good idea, but I am not sure on how
to design such a function right now.
 1.22  28-Nov-2011  jym branches: 1.22.2;
Whitespace fixes.
 1.21  23-Nov-2011  tls Load entropy at system boot (only works at securelevel < 1); save
at system shutdown. Disable with random_seed=NO in rc.conf if desired.

Goes to some trouble to never load or save to network filesystems.

Entropy should really be loaded by the boot loader but I am still
sorting out how to pass it to the kernel.
 1.20  07-Oct-2009  elad branches: 1.20.12;
Compare against initproc, not pid 1, to check if it's init (unify).
 1.19  06-Oct-2009  elad Unify: >= 0 -> > -1.
 1.18  06-Oct-2009  elad Cosmetic changes to declarations. No functional change.
 1.17  06-Oct-2009  elad Factor out a block of code that appears in three places (Veriexec, keylock,
and securelevel) so that others can use it as well.
 1.16  03-Oct-2009  elad Introduce time_wraps() to check if setting the time will wrap it (or
close to it). Useful for secmodels.

Replace open-coded form with it in secmodel code (securelevel, keylock).

Note: I need to find a way to make secmodel_keylock.c ~<100 lines.
 1.15  02-Oct-2009  elad Create securelevel variable under securelevel node.
 1.14  02-Oct-2009  elad First part of secmodel cleanup and other misc. changes:

- Separate the suser part of the bsd44 secmodel into its own secmodel
and directory, pending even more cleanups. For revision history
purposes, the original location of the files was

src/sys/secmodel/bsd44/secmodel_bsd44_suser.c
src/sys/secmodel/bsd44/suser.h

- Add a man-page for secmodel_suser(9) and update the one for
secmodel_bsd44(9).

- Add a "secmodel" module class and use it. Userland program and
documentation updated.

- Manage secmodel count (nsecmodels) through the module framework.
This eliminates the need for secmodel_{,de}register() calls in
secmodel code.

- Prepare for secmodel modularization by adding relevant module bits.
The secmodels don't allow auto unload. The bsd44 secmodel depends
on the suser and securelevel secmodels. The overlay secmodel depends
on the bsd44 secmodel. As the module class is only cosmetic, and to
prevent ambiguity, the bsd44 and overlay secmodels are prefixed with
"secmodel_".

- Adapt the overlay secmodel to recent changes (mainly vnode scope).

- Stop using link-sets for the sysctl node(s) creation.

- Keep sysctl variables under nodes of their relevant secmodels. In
other words, don't create duplicates for the suser/securelevel
secmodels under the bsd44 secmodel, as the latter is merely used
for "grouping".

- For the suser and securelevel secmodels, "advertise presence" in
relevant sysctl nodes (sysctl.security.models.{suser,securelevel}).

- Get rid of the LKM preprocessor stuff.

- As secmodels are now modules, there's no need for an explicit call
to secmodel_start(); it's handled by the module framework. That
said, the module framework was adjusted to properly load secmodels
early during system startup.

- Adapt rump to changes: Instead of using empty stubs for securelevel,
simply use the suser secmodel. Also replace secmodel_start() with a
call to secmodel_suser_start().

- 5.99.20.

Testing was done on i386 ("release" build). Spearated module_init()
changes were tested on sparc and sparc64 as well by martin@ (thanks!).

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/09/25/msg006135.html
 1.13  03-Sep-2009  elad Implement the vnode scope and adapt tmpfs to use it.

Mailing list reference:

http://mail-index.netbsd.org/tech-kern/2009/07/04/msg005404.html
 1.12  25-Jul-2009  mbalmer Extend the existing security models for upcoming gpio(4) changes.
Reviewed and feedback by Elad Efrat.
 1.11  06-May-2009  elad Sprinkle some switch defaults.
 1.10  11-Jan-2009  christos branches: 1.10.2;
merge christos-time_t
 1.9  12-Nov-2008  ad Remove LKMs and switch to the module framework, pass 1.

Proposed on tech-kern@.
 1.8  23-Jan-2008  elad branches: 1.8.6; 1.8.8; 1.8.12; 1.8.18; 1.8.20;
Tons of process scope changes.

- Add a KAUTH_PROCESS_SCHEDULER action, to handle scheduler related
requests, and add specific requests for set/get scheduler policy and
set/get scheduler parameters.

- Add a KAUTH_PROCESS_KEVENT_FILTER action, to handle kevent(2) related
requests.

- Add a KAUTH_DEVICE_TTY_STI action to handle requests to TIOCSTI.

- Add requests for the KAUTH_PROCESS_CANSEE action, indicating what
process information is being looked at (entry itself, args, env,
open files).

- Add requests for the KAUTH_PROCESS_RLIMIT action indicating set/get.

- Add requests for the KAUTH_PROCESS_CORENAME action indicating set/get.

- Make bsd44 secmodel code handle the newly added rqeuests appropriately.

All of the above make it possible to issue finer-grained kauth(9) calls in
many places, removing some KAUTH_GENERIC_ISSUSER requests.

- Remove the "CAN" from KAUTH_PROCESS_CAN{KTRACE,PROCFS,PTRACE,SIGNAL}.

Discussed with christos@ and yamt@.
 1.7  16-Jan-2008  ad Pull in my modules code for review/test/hacking.
 1.6  14-Jan-2008  ad vp->v_rdev, not vp->v_un.vu_specinfo->si_rdev.
 1.5  31-Dec-2007  ad branches: 1.5.2;
Remove systrace. Ok core@.
 1.4  25-Nov-2007  elad branches: 1.4.2; 1.4.6; 1.4.10; 1.4.14;
Deprecate KAUTH_REQ_SYSTEM_TIME_BACKWARDS, as it was merged into
KAUTH_REQ_SYSTEM_TIME_SYSTEM.
 1.3  25-Nov-2007  elad Refactor time modification checks and place them in the secmodel code.

okay christos@
 1.2  24-Nov-2007  elad Fix a long time issue where the securelevel secmodel would explicitly
allow certain operations.

The suser module of the bsd44 secmodel code was made aware of the missing
operations that were explicitly allowed in the securelevel module, and
the logic in the latter was modified to a default defer, deny where not
allowed.

This concept, which is the correct way to write secmodel code, was first
brought up by pavel@ a long time ago.

okay christos@.
 1.1  21-Nov-2007  elad branches: 1.1.2;
Make securelevel a "secmodel" of its own.

While it's true that it's part of the traditional 4.4BSD security model,
there may come a time where a different "primary" security model used for
fine-grained privileges (ie., splitting root's responsibilities to various
privileges that can be assigned) may want to still have a securelevel
setting.

Idea from Daniel Carosone:

http://mail-index.netbsd.org/tech-security/2006/08/25/0001.html

The location of the removed files, for reference, was:

src/secmodel/bsd44/secmodel_bsd44_securelevel.c
src/secmodel/bsd44/securelevel.h
 1.1.2.2  22-Nov-2007  bouyer Sync with HEAD
 1.1.2.1  21-Nov-2007  bouyer file secmodel_securelevel.c was added on branch bouyer-xenamd64 on 2007-11-22 15:38:35 +0000
 1.4.14.2  18-Feb-2008  mjf Sync with HEAD.
 1.4.14.1  25-Nov-2007  mjf file secmodel_securelevel.c was added on branch mjf-devfs on 2008-02-18 21:07:22 +0000
 1.4.10.3  23-Jan-2008  bouyer Sync with HEAD.
 1.4.10.2  19-Jan-2008  bouyer Sync with HEAD
 1.4.10.1  02-Jan-2008  bouyer Sync with HEAD
 1.4.6.4  04-Feb-2008  yamt sync with head.
 1.4.6.3  21-Jan-2008  yamt sync with head
 1.4.6.2  07-Dec-2007  yamt sync with head
 1.4.6.1  25-Nov-2007  yamt file secmodel_securelevel.c was added on branch yamt-lazymbuf on 2007-12-07 17:34:50 +0000
 1.4.2.2  27-Nov-2007  joerg Sync with HEAD. amd64 Xen support needs testing.
 1.4.2.1  25-Nov-2007  joerg file secmodel_securelevel.c was added on branch jmcneill-pm on 2007-11-27 19:39:10 +0000
 1.5.2.3  23-Mar-2008  matt sync with HEAD
 1.5.2.2  09-Jan-2008  matt sync with HEAD
 1.5.2.1  31-Dec-2007  matt file secmodel_securelevel.c was added on branch matt-armv6 on 2008-01-09 01:58:03 +0000
 1.8.20.1  19-Jan-2009  skrll Sync with HEAD.
 1.8.18.1  13-Dec-2008  haad Update haad-dm branch to haad-dm-base2.
 1.8.12.5  11-Mar-2010  yamt sync with head
 1.8.12.4  16-Sep-2009  yamt sync with head
 1.8.12.3  19-Aug-2009  yamt sync with head.
 1.8.12.2  16-May-2009  yamt sync with head
 1.8.12.1  04-May-2009  yamt sync with head.
 1.8.8.2  20-Nov-2008  christos merge with head.
 1.8.8.1  29-Mar-2008  christos Welcome to the time_t=long long dev_t=uint64_t branch.
 1.8.6.1  17-Jan-2009  mjf Sync with HEAD.
 1.10.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.20.12.3  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.20.12.2  30-Oct-2012  yamt sync with head
 1.20.12.1  17-Apr-2012  yamt sync with head
 1.22.2.2  05-Apr-2012  mrg sync to latest -current.
 1.22.2.1  18-Feb-2012  mrg merge to -current.
 1.26.6.1  08-Feb-2013  riz Pull up following revision(s) (requested by jym in ticket #802):
sys/secmodel/securelevel/secmodel_securelevel.c: revision 1.29
sys/secmodel/extensions/secmodel_extensions.c: revision 1.4
Re-instate backwards compatible security.models.bsd44.{curtain,securelevel}.
They were mistakenly removed when curtain and securelevel moved to
secmodel_extensions(9).
Reported by tls@ on tech-security@.
XXX will ask for pull-up for -6.
 1.26.2.1  08-Feb-2013  riz Pull up following revision(s) (requested by jym in ticket #802):
sys/secmodel/securelevel/secmodel_securelevel.c: revision 1.29
sys/secmodel/extensions/secmodel_extensions.c: revision 1.4
Re-instate backwards compatible security.models.bsd44.{curtain,securelevel}.
They were mistakenly removed when curtain and securelevel moved to
secmodel_extensions(9).
Reported by tls@ on tech-security@.
XXX will ask for pull-up for -6.
 1.28.2.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.28.2.1  25-Feb-2013  tls resync with head
 1.29.2.1  18-May-2014  rmind sync with head
 1.30.28.2  28-Jul-2018  pgoyette Sync with HEAD
 1.30.28.1  02-May-2018  pgoyette Synch with HEAD
 1.30.22.1  05-May-2018  martin Pull up following revision(s) (requested by alnsn in ticket #790):

share/man/man9/secmodel_securelevel.9: revision 1.16
sys/secmodel/suser/secmodel_suser.c: revision 1.44
sys/secmodel/securelevel/secmodel_securelevel.c: revision 1.31
sys/sys/kauth.h: revision 1.76
sys/arch/x86/x86/svs.c: revision 1.18

Add KAUTH_MACHDEP_SVS_DISABLE and add support to secmodel_securelevel(9).
Disabling SVS is denied at securelevel 1 and above.

Add SVS. It may not be disabled at securelevel 1 and above.
 1.31.2.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.31.2.1  10-Jun-2019  christos Sync with HEAD
 1.32.6.1  29-Feb-2020  ad Sync with head.
 1.32.4.1  17-Aug-2020  martin Pull up following revision(s) (requested by riastradh in ticket #1053):

sys/secmodel/securelevel/secmodel_securelevel.c: revision 1.36

Accept ioctl(RNDADDDATA) estimates at securelevel 1 (but not 2).
securelevel=1 is supposed to be a reasonable default for normal
computers. This got in the way of ever getting entropy from a seed
on a machine with no HWRNG -- e.g., from another machine, or by
making the executive decision that what has been sampled is good
enough and issuing `head -c 32 < /dev/urandom > /dev/random'.
 1.36.2.1  14-Dec-2020  thorpej Sync w/ HEAD.

RSS XML Feed