Commit Graph

185 Commits

Author SHA1 Message Date
maxv 2c558888d7 Remove support for '%n' in the kernel printf functions.
It makes vulnerabilities too easily exploitable, is unused and as a sanity
rule should not be used in the kernel to begin with.

Now, "printf(unfiltered_string);" is much less of a problem.
2020-07-11 07:14:53 +00:00
ad 0eaaa024ea Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
2020-05-23 23:42:41 +00:00
riastradh 5084c1b50f Rewrite entropy subsystem.
Primary goals:

1. Use cryptography primitives designed and vetted by cryptographers.
2. Be honest about entropy estimation.
3. Propagate full entropy as soon as possible.
4. Simplify the APIs.
5. Reduce overhead of rnd_add_data and cprng_strong.
6. Reduce side channels of HWRNG data and human input sources.
7. Improve visibility of operation with sysctl and event counters.

Caveat: rngtest is no longer used generically for RND_TYPE_RNG
rndsources.  Hardware RNG devices should have hardware-specific
health tests.  For example, checking for two repeated 256-bit outputs
works to detect AMD's 2019 RDRAND bug.  Not all hardware RNGs are
necessarily designed to produce exactly uniform output.

ENTROPY POOL

- A Keccak sponge, with test vectors, replaces the old LFSR/SHA-1
  kludge as the cryptographic primitive.

- `Entropy depletion' is available for testing purposes with a sysctl
  knob kern.entropy.depletion; otherwise it is disabled, and once the
  system reaches full entropy it is assumed to stay there as far as
  modern cryptography is concerned.

- No `entropy estimation' based on sample values.  Such `entropy
  estimation' is a contradiction in terms, dishonest to users, and a
  potential source of side channels.  It is the responsibility of the
  driver author to study the entropy of the process that generates
  the samples.

- Per-CPU gathering pools avoid contention on a global queue.

- Entropy is occasionally consolidated into global pool -- as soon as
  it's ready, if we've never reached full entropy, and with a rate
  limit afterward.  Operators can force consolidation now by running
  sysctl -w kern.entropy.consolidate=1.

- rndsink(9) API has been replaced by an epoch counter which changes
  whenever entropy is consolidated into the global pool.
  . Usage: Cache entropy_epoch() when you seed.  If entropy_epoch()
    has changed when you're about to use whatever you seeded, reseed.
  . Epoch is never zero, so initialize cache to 0 if you want to reseed
    on first use.
  . Epoch is -1 iff we have never reached full entropy -- in other
    words, the old rnd_initial_entropy is (entropy_epoch() != -1) --
    but it is better if you check for changes rather than for -1, so
    that if the system estimated its own entropy incorrectly, entropy
    consolidation has the opportunity to prevent future compromise.

- Sysctls and event counters provide operator visibility into what's
  happening:
  . kern.entropy.needed - bits of entropy short of full entropy
  . kern.entropy.pending - bits known to be pending in per-CPU pools,
    can be consolidated with sysctl -w kern.entropy.consolidate=1
  . kern.entropy.epoch - number of times consolidation has happened,
    never 0, and -1 iff we have never reached full entropy

CPRNG_STRONG

- A cprng_strong instance is now a collection of per-CPU NIST
  Hash_DRBGs.  There are only two in the system: user_cprng for
  /dev/urandom and sysctl kern.?random, and kern_cprng for kernel
  users which may need to operate in interrupt context up to IPL_VM.

  (Calling cprng_strong in interrupt context does not strike me as a
  particularly good idea, so I added an event counter to see whether
  anything actually does.)

- Event counters provide operator visibility into when reseeding
  happens.

INTEL RDRAND/RDSEED, VIA C3 RNG (CPU_RNG)

- Unwired for now; will be rewired in a subsequent commit.
2020-04-30 03:28:18 +00:00
thorpej 599c240526 - Introduce a new global kernel variable "shutting_down" to indicate that
the system is shutting down or rebooting.
- Set this global in a new function called kern_reboot(), which is currently
  just a basic wrapper around cpu_reboot().
- Call kern_reboot() instead of cpu_reboot() almost everywhere; a few
  places remain where it's still called directly, but those are in early
  pre-main() machdep locations.

Eventually, all of the various cpu_reboot() functions should be re-factored
and common functionality moved to kern_reboot(), but that's for another day.
2020-01-01 22:57:16 +00:00
christos c8305ee1b3 put back line accidentally removed. 2019-05-21 04:57:02 +00:00
christos afe046b05f undo the unintended part of the previous commit. 2019-05-21 04:55:07 +00:00
christos fc64e5540e va_copy list needs va_end; pointed out by kre@ 2019-05-21 04:53:52 +00:00
kre 16462c2c3b Need <sys/kmem.h> for kmem_alloc() 2019-05-21 00:57:54 +00:00
christos 147918d081 Add a simple vasprintf() implementation that uses 2 passes, one to compute
the length and a second to place the data. Requested by rmind@
2019-05-20 20:35:45 +00:00
jdolecek 54f8a68ddf add KASSERT()s to ensure aprint_*_dev() and aprint_*_ifp() is not called
with NULL dv or ifp respectively

related to PR kern/53789
2019-01-14 19:21:54 +00:00
martin 0eae8cc98b Introduce new helper printf functions that get passed output
flags. Add a new kprintf flag to avoid adding time stamps
when outputing to the console. Mostly from Christos, any bugs
added by me.

Use above to print the "twiddle" (when using boot -z) without
timestamps.
2019-01-07 13:09:47 +00:00
martin 95ab685769 More ipkdb removal 2018-07-15 07:24:11 +00:00
jmcneill aeec0e9736 Revert previous 2018-07-01 09:53:54 +00:00
jmcneill ca5cdadb4c When cold, manually update timecounters before calling getnanouptime. Now
kernel printf timestamps are updated properly before interrupts are
enabled.
2018-06-30 17:15:01 +00:00
jakllsch a7c48ad938 Make identification of accounted aprint_error()s possible by putting a
big ugly "autoconfiguration error: " in the log when they occur.
2018-06-03 15:26:03 +00:00
kre acac57976b Change the default precision of timestamps from 9 digits (nanosecs)
to 7 (100's of nanosecs).   This should perhaps depend upon the
port (what resolution is rational) the CPU speed, and the clock
update frequency (no point printing nanoseconds if the value being
brinted is only updated every few microseconds).

Eventually it should be able to be controlled by a sysctl, but
the default still matters, as that's what the autoconf (boot time,
before init starts) messages will use.
2018-04-14 01:53:38 +00:00
kre ceb09b4461 Allow the precision of the sub-second field of timestamps to
be controlled - for now that is done by editing this file and
recompiling (or using gdb or equiv to patch /netbsd or /dev/kmem)
but adding a sysctl to allow dynamic userland control should be easy.

Also reduce the initial seconds field width of timestamp from 5 to 4
(it grows wider as needed.)

Avoid printing timestamps if we cannot be sure there will be
a message to accompany them.   (Observed happening...)
2018-04-14 01:45:37 +00:00
christos ad48bc87a0 make this narrower by popular request. 2018-04-13 09:21:16 +00:00
christos 1211273114 fix type confusion on 32 bits 2018-04-11 23:20:15 +00:00
christos 3ec6e2e2d6 flip the default and enable kernel timestamps. 2018-04-11 15:25:58 +00:00
christos 9c17258d23 Add the ability to prepend a timestamp [ sec.nsec] relative to boottime
in kernel messages if KLOG_TIMESTAMP is enabled.
2018-04-01 19:29:43 +00:00
christos 1771523298 Instead of expanding the syslog level into <level> early, defer expansion
inside putchar; extract the actual character addition function to a separate
function.
2018-04-01 19:28:17 +00:00
christos 2be0b0c7db factor out some repeated code and simplify the logputchar function. 2018-03-31 23:12:01 +00:00
joerg e64612f440 Revert printf return value change. 2017-10-27 12:25:14 +00:00
utkarsh009 f11595bab5 [syzkaller] Cast all the printf's to (void *)
> as a result of new printf(9) declaration.
2017-10-27 09:59:16 +00:00
skrll ac3daeaa4c Bump size of scratchstr - some KASSERTMGS exceed 256 characters 2016-07-27 09:57:26 +00:00
pooka d8e04c9094 to garnish, dust with _KERNEL_OPT 2015-08-24 22:50:32 +00:00
riastradh 67d6ba47fb Convert remaining MI <sys/rnd.h> stragglers. Many MD ones left. 2015-04-13 16:46:33 +00:00
msaitoh 2e202f47c6 Remove useless semicolon reported by Henning Petersen in PR#49635. 2015-02-04 07:10:47 +00:00
apb 5f48354283 If mutex_tryenter() fails, don't call mutex_exit(). 2014-08-15 11:05:35 +00:00
mrg e1e8d3be37 avoid calling into time code when cold, and avoid calling nanotime()
if we're not going to use the result anyway.

XXX: not necessarily the best fix, but better than crashing *early*
boot due to too-early nanotime() calls.

XXX: pullup.
2014-08-15 07:39:25 +00:00
tls ea6af427bd Merge tls-earlyentropy branch into HEAD. 2014-08-10 16:44:32 +00:00
christos e9ba8bc5a2 remove {v,}sprintf 2014-03-26 18:03:47 +00:00
joerg c9ec0f85a6 Revert, breaks the build due to missing rumpns_delay in librump.so. 2014-01-12 00:29:15 +00:00
christos 71826933a0 Sleep 10 seconds before rebooting due to panic()
To give an opportunity to screencap a panic(), or pause a VM to attach
a debugger.  (Richard Hansen)
2014-01-11 17:07:45 +00:00
apb bb0eb3bd82 Move the DDB-specific part of vpanic() to a new db_panic() function,
defined in ddb/db_panic.c and declared in ddb/ddbvar.h.  No functional
change.

The copyright years in db_panic.c are the years in which changes were
made to the code that has now been moved to db_panic.c.  No pre-NetBSD
copyright notice is needed because revision 1.12 of subr_prf.c had only
the trivial "#ifdef DDB \\ Debugger(); \\ #endif"
2013-02-10 11:04:19 +00:00
dholland 48a4d49b28 Repeated typo/varargs anachronism in comments. 2012-03-12 19:21:07 +00:00
christos 947906bba8 - fixed signed/unsigned comparison
- don't write/increment sbuf if NULL
2011-11-24 01:45:39 +00:00
christos 2413151944 - don't let arguments in macros have side effects
- nul terminate properly
2011-11-24 01:14:19 +00:00
christos 32c78aacbc Increment the source buffer when we overflow so that we don't get stuck in
an infinite loop.
2011-11-22 21:25:04 +00:00
christos 9873d290d6 - use va_copy where needed
- always nul terminate vsnprintf()
- make snprintf() call vsnprintf()
2011-11-21 01:44:26 +00:00
christos 3f19719796 snprintf/vsnprintf can accept NULL/0 buffers and work properly as expected.
Before they used to return incorrect length on short buffers. Remove unused
error path.
2011-11-20 23:01:18 +00:00
christos 01035c71fc Add vpanic() 2011-09-29 20:52:39 +00:00
jym 9ce680e4f1 Use a scratch space in panic(9) so we can store a more meaningful
message for panicstr instead of just the format string.

Keep setting the panicstr to fmt beforehand though for safety precaution.

ok joerg@.
2011-09-08 18:15:56 +00:00
joerg 3eb244d801 Retire varargs.h support. Move machine/stdarg.h logic into MI
sys/stdarg.h and expect compiler to provide proper builtins, defaulting
to the GCC interface. lint still has a special fallback.
Reduce abuse of _BSD_VA_LIST_ by defining __va_list by default and
derive va_list as required by standards.
2011-07-17 20:54:30 +00:00
rmind bd5b92d68b - Replace few malloc(9) uses with kmem(9).
- Rename buf_malloc() to buf_alloc(), fix comments.
- Remove some unnecessary inclusions.
2011-04-24 18:46:22 +00:00
dyoung 56f6a5a11c Move device_printf() from ath_netbsd.c to subr_prf.c for reuse in a new
driver.
2011-01-21 17:46:19 +00:00
he ce1061323d On a recursive panic(), don't try to take a dump, as that may very
well have triggered the recursive panic.
Fix the comment for panic() to reflect now-current reality: the code
was already changed never to sync() on panic(), now we avoid dumping
core on a recursive panic.
2010-01-26 12:59:50 +00:00
dyoung e48f8429d1 Add a kernel configuration flag, SPLDEBUG, that activates a per-CPU log
of transitions to IPL_HIGH from lower IPLs.  SPLDEBUG is only available
on i386 and Xen kernels, today.

'options SPLDEBUG' adds instrumentation to spllower() and splraise() as
well as routines to start/stop debugging and to record IPL transitions:
spldebug_start(), spldebug_stop(), spldebug_raise(), spldebug_lower().
2009-11-03 05:23:27 +00:00
rmind fe55ad324c panic: use MI cpu_index(), instead of cpu_number(), which could be sparse. 2009-06-28 15:30:30 +00:00