Commit Graph

136 Commits

Author SHA1 Message Date
yamaguchi 5256dbbccb Added tests for the linear hook APIs 2021-09-30 02:00:19 +00:00
christos d9f886e2fb rename glue.c to sodium_module.c 2021-08-21 09:08:55 +00:00
christos ddf60632c4 Add glue.c for libsodium (suggested by riastradh). Tidy up. 2021-08-21 08:47:23 +00:00
christos 0f62dc0eb2 fix reversed comment 2021-04-15 17:31:15 +00:00
christos 4ddba2f693 - Define NEED_ISYSTEM here
- include <bsd.init.mk> now that we can do it, because we need Makefile.rump
  to be included first, so that NOLINT gets defined, so that we don't end up
  building lint modules just for this.
2021-04-15 17:28:09 +00:00
riastradh 261d3f19e6 Move address hashing from init_main.c to kern_sysctl.c.
This way rump gets it automatically.  Make sure blake2s is in
librumpkern.so, not just in librumpkern_crypto.so, for this to work.
2020-08-27 14:01:36 +00:00
riastradh 062505bfdf Tidy up libsodium makefile and config fragments. 2020-08-26 15:49:56 +00:00
riastradh 465b1b1b98 Disable libsodium HAVE_TI_MODE for now.
This may reduce performance by not taking advantage of 64x64->128
multiplications on some platforms, but let's worry about that later
and fix the build on the other platforms instead.
2020-08-21 06:37:30 +00:00
riastradh 588821d8ae Split flags onto separate lines, sorted, to make diffs easier. 2020-08-21 06:30:46 +00:00
riastradh 9bd7cf68e1 Disable -Wshadow for libsodium.
Evidently ed25519_ref10.c has a global and a local both named `d'.
2020-08-21 06:27:41 +00:00
riastradh 18c1858be1 Missed a spot -- add sys/crypto/blake2 to .PATH here. 2020-08-20 21:33:43 +00:00
riastradh 1ce89b900a Fix vestiges of libb2. 2020-08-20 21:30:32 +00:00
riastradh a14187eca5 [ozaki-r] Changes to the kernel core for wireguard 2020-08-20 21:21:31 +00:00
riastradh 8748ca0e56 Rewrite cprng_fast in terms of new ChaCha API. 2020-07-28 20:15:07 +00:00
riastradh 985de54c7c Fix more sort order. 2020-07-26 04:25:49 +00:00
riastradh 4fd8ff038b Add missing aes_ccm.c, aes_ccm_mbuf.c. Fix sort order. 2020-07-26 04:25:14 +00:00
riastradh 314627761e Add chacha to rump libcrypto. 2020-07-26 04:03:45 +00:00
riastradh 7e7db0caf8 Remove now-unused legacy rijndael API. 2020-07-25 22:40:08 +00:00
riastradh 04a6492d1e New cgd cipher adiantum.
Adiantum is a wide-block cipher, built out of AES, XChaCha12,
Poly1305, and NH, defined in

   Paul Crowley and Eric Biggers, `Adiantum: length-preserving
   encryption for entry-level processors', IACR Transactions on
   Symmetric Cryptology 2018(4), pp. 39--61.

Adiantum provides better security than a narrow-block cipher with CBC
or XTS, because every bit of each sector affects every other bit,
whereas with CBC each block of plaintext only affects the following
blocks of ciphertext in the disk sector, and with XTS each block of
plaintext only affects its own block of ciphertext and nothing else.

Adiantum generally provides much better performance than
constant-time AES-CBC or AES-XTS software do without hardware
support, and performance comparable to or better than the
variable-time (i.e., leaky) AES-CBC and AES-XTS software we had
before.  (Note: Adiantum also uses AES as a subroutine, but only once
per disk sector.  It takes only a small fraction of the time spent by
Adiantum, so there's relatively little performance impact to using
constant-time AES software over using variable-time AES software for
it.)

Adiantum naturally scales to essentially arbitrary disk sector sizes;
sizes >=1024-bytes take the most advantage of Adiantum's design for
performance, so 4096-byte sectors would be a natural choice if we
taught cgd to change the disk sector size.  (However, it's a
different cipher for each disk sector size, so it _must_ be a cgd
parameter.)

The paper presents a similar construction HPolyC.  The salient
difference is that HPolyC uses Poly1305 directly, whereas Adiantum
uses Poly1395(NH(...)).  NH is annoying because it requires a
1072-byte key, which means the test vectors are ginormous, and
changing keys is costly; HPolyC avoids these shortcomings by using
Poly1305 directly, but HPolyC is measurably slower, costing about
1.5x what Adiantum costs on 4096-byte sectors.

For the purposes of cgd, we will reuse each key for many messages,
and there will be very few keys in total (one per cgd volume) so --
except for the annoying verbosity of test vectors -- the tradeoff
weighs in the favour of Adiantum, especially if we teach cgd to do
>>512-byte sectors.

For now, everything that Adiantum needs beyond what's already in the
kernel is gathered into a single file, including NH, Poly1305, and
XChaCha12.  We can split those out -- and reuse them, and provide MD
tuned implementations, and so on -- as needed; this is just a first
pass to get Adiantum implemented for experimentation.
2020-06-29 23:44:01 +00:00
riastradh 5dcdae413b Rework AES in kernel to finally address CVE-2005-1797.
1. Rip out old variable-time reference implementation.
2. Replace it by BearSSL's constant-time 32-bit logic.
   => Obtained from commit dda1f8a0c46e15b4a235163470ff700b2f13dcc5.
   => We could conditionally adopt the 64-bit logic too, which would
      likely give a modest performance boost on 64-bit platforms
      without AES-NI, but that's a bit more trouble.
3. Select the AES implementation at boot-time; allow an MD override.
   => Use self-tests to verify basic correctness at boot.
   => The implementation selection policy is rather rudimentary at
      the moment but it is isolated to one place so it's easy to
      change later on.

This (a) plugs a host of timing attacks on, e.g., cgd, and (b) paves
the way to take advantage of CPU support for AES -- both things we
should've done a decade ago.  Downside: Computing AES takes 2-3x the
CPU time.  But that's what hardware support will be coming for.

Rudimentary measurement of performance impact done by:

mount -t tmpfs tmpfs /tmp
dd if=/dev/zero of=/tmp/disk bs=1m count=512
vnconfig -cv vnd0 /tmp/disk
cgdconfig -s cgd0 /dev/vnd0 aes-cbc 256 < /dev/zero
dd if=/dev/rcgd0d of=/dev/null bs=64k
dd if=/dev/zero of=/dev/rcgd0d bs=64k

The AES-CBC encryption performance impact is closer to 3x because it
is inherently sequential; the AES-CBC decryption impact is closer to
2x because the bitsliced AES logic can process two blocks at once.

Discussed on tech-kern:

https://mail-index.NetBSD.org/tech-kern/2020/06/18/msg026505.html
2020-06-29 23:27:52 +00:00
riastradh 38e3ff59e6 Missed a spot in the crypto/arc4 deletion. 2019-12-05 03:57:55 +00:00
uwe edcef67ec2 xc_barrier - convenience function to xc_broadcast() a nop.
Make the intent more clear and also avoid a bunch of (xcfunc_t)nullop
casts that gcc 8 -Wcast-function-type is not happy about.
2019-10-06 15:11:16 +00:00
mrg 21303c93e9 convert HAVE_GCC == 7 to HAVE_GCC >= 7. 2019-09-29 23:44:58 +00:00
bad 0f1e944e9e define sysautoload here too, to catch up with kern/makesyscalls.sh r1.173
XXX: This needs to be re-thought
2019-09-11 20:31:30 +00:00
riastradh 8e07b51739 Switch from NIST CTR_DRBG with AES to NIST Hash_DRBG with SHA-256.
Benefits:

- larger seeds -- a 128-bit key alone is not enough for `128-bit security'
- better resistance to timing side channels than AES
- a better-understood security story (https://eprint.iacr.org/2018/349)
- no loss in compliance with US government standards that nobody ever
  got fired for choosing, at least in the US-dominated western world
- no dirty endianness tricks
- self-tests

Drawbacks:

- performance hit: throughput is reduced to about 1/3 in naive measurements
  => possible to mitigate by using hardware SHA-256 instructions
  => all you really need is 32 bytes to seed a userland PRNG anyway
  => if we just used ChaCha this would go away...

XXX pullup-7
XXX pullup-8
XXX pullup-9
2019-09-02 20:09:29 +00:00
ozaki-r 7fc219a5ee Implement an aggressive psref leak detector
It is yet another psref leak detector that enables to tell where a leak occurs
while a simpler version that is already committed just tells an occurrence of a
leak.

Investigating of psref leaks is hard because once a leak occurs a percpu list of
psref that tracks references can be corrupted.  A reference to a tracking object
is memorized in the list via an intermediate object (struct psref) that is
normally allocated on a stack of a thread.  Thus, the intermediate object can be
overwritten on a leak resulting in corruption of the list.

The tracker makes a shadow entry to an intermediate object and stores some hints
into it (currently it's a caller address of psref_acquire).  We can detect a
leak by checking the entries on certain points where any references should be
released such as the return point of syscalls and the end of each softint
handler.

The feature is expensive and enabled only if the kernel is built with
PSREF_DEBUG.

Proposed on tech-kern
2019-05-17 03:34:26 +00:00
ozaki-r 3843688c40 Implement a simple psref leak detector
It detects leaks by counting up the number of held psref by an LWP and checking
its zeroness at the end of syscalls and softint handlers.  For the counter, a
unused field of struct lwp is reused.

The detector runs only if DIAGNOSTIC is turned on.
2019-04-19 01:52:55 +00:00
ozaki-r 7a39609d2e rump: add missing sanity checks at the end of syscalls 2019-04-18 08:31:44 +00:00
mrg 978a4e65e0 be sure to only apply zlib.c's -Wno-error=implicit-fallthrough to GCC 7.
push the setting into the rump and module version too.
2019-02-05 09:29:19 +00:00
rin d9d37bdb59 Fix merge botches. I hope there's no more left... 2019-01-27 09:19:36 +00:00
pgoyette d91f98a871 Merge the [pgoyette-compat] branch 2019-01-27 02:08:33 +00:00
alnsn 3eaf14fed6 Cast register_t to uintptr_t before casting to void *.
Not sure what's going on here but evbmips64-el build fails
without this cast.
2019-01-22 01:25:53 +00:00
alnsn 11498dee00 Sync the first argument type with mco_icache_sync_range. 2019-01-22 00:36:02 +00:00
alnsn 8cef4130c5 Add sljit rump glue for aarch64.
XXX arm_icache_sync_range() and mips_icache_sync_range() call

	(void)rumpcomp_sync_icache((void *)va, (uint64_t)sz);

but linking fails if I do the same on aarch64 (I suspect it also
fails on 32bit arm and mips).

As a workaround, I call __builtin___clear_cache().
2019-01-21 00:30:14 +00:00
alnsn a57097d054 Add missing RCSIDs. 2018-12-12 00:48:43 +00:00
rmind b07949e890 Add rumpkern_nv (in-kernel RUMP libnv). 2018-09-22 12:54:34 +00:00
pgoyette 3cd7406ad8 Allow syscall_establish() to install new syscalls when the existing
entry-point is either sys_nomodule or sys_nosys.  Update the
makesyscalls.sh script to create a const array of bits to allow
syscall_disestablish() to properly restore the original entry-point.
Update all the initializers of struct emul to initialize the pointer
to the bit array struct emul.

XXX Regen of all files created by makesyscalls.sh will come soon,
XXX followed by a kernel version bump (since struct emul is being
XXX modified).

This commit should address PR kern/45781 and also removes the need
for the work-around for that PR in file

	sys/arch/usermode/modules/syscallemu/syscallemu.c
2018-08-10 21:44:58 +00:00
chs ba2539a980 merge a new version of the CDDL dtrace and ZFS code.
this changes the upstream vendor from OpenSolaris to FreeBSD,
and this version is based on FreeBSD svn r315983.

in addition to the 10 years of improvements from upstream,
this version also has these NetBSD-specific enhancements:
 - dtrace FBT probes can now be placed in kernel modules.
 - ZFS now supports mmap().
2018-05-28 21:04:59 +00:00
riastradh 39f1e86852 Fail, don't panic, on bad dirents from file system.
Controllable via puffs from userland.

From Ilja Van Sprundel.
2017-07-28 15:34:06 +00:00
pooka 6bb5142288 Put the kernelside rump kernel headers into <rump-sys> instead of
sprinkling them around the faction directories.  Avoids having
to add a CPPFLAGS (or several) to pretty much every component
Makefile.

Leave compat headers around in the old locations.

The commit changes some autogenerated files, but I'll fix the
generators shortly and regen.
2016-01-26 23:12:14 +00:00
pooka 13f1407fea Initialize non-VFS parts of tty subsystem already at RUMP_COMPONENT_KERN.
That way components under RUMP__FACTION_DEV can call tty routines.
2016-01-07 21:09:01 +00:00
christos 8ec658f57a - Change LDADD/DPADD in library dependencies to LIBDPLIBS
- Fix some LDADD abuse and remove useless dependencies
- include <bsd.init.mk> in the right place where appropriate
From Rin Okuyama
2016-01-05 13:07:46 +00:00
pooka d97f016d89 Always descend into component directories for rumpdescribe. 2015-11-15 16:54:16 +00:00
pooka b2b6f2602e Add a COMMENT describing what each component roughly does.
"make describe" prints the comment.

Requested/inspired by Vincent Schwarzer on rumpkernel-users
2015-10-19 16:16:32 +00:00
christos 1a4eecf195 use ioconf.h for pseudo-device attach prototypes 2015-08-20 11:59:16 +00:00
pooka a757287dfa Rewrite rules so that makesyscalls.sh will not be executed multiple
times in a parallel make.

Hopefully fixes sporadic build failures reported by Justin
2015-05-18 17:49:16 +00:00
pooka 48121ce977 remove files which are autogenerated in every build 2015-05-09 12:03:34 +00:00
pooka 8c13dec0ff Make the cool syscall autogeneration feature work with the
newfangled r/o src feature.
2015-05-09 12:03:10 +00:00
pooka ac0dac8111 Rename RUMP_COMPAT to RUMP_NBCOMBAT to better signify what the
variable does.
2015-04-23 14:49:26 +00:00
pooka b13c75b964 Build compat code only when specified by RUMP_COMPAT 2015-04-22 17:57:49 +00:00