Commit Graph

3240 Commits

Author SHA1 Message Date
chs
ffc294f923 make rump's uvm_aio_aiodone_pages() look more like the kernel version.
fixes some more rumpy assertions.
2020-12-09 00:03:32 +00:00
skrll
a4c9665c21 Fix build after interval timers refectoring by thorpej@ 2020-12-06 09:03:29 +00:00
chs
4650d4123d update the rump copy of uvm_page_unbusy() to match the real version,
in particular handle PG_PAGEOUT.  fixes a few atf tests.
2020-12-05 19:08:50 +00:00
christos
39d08fed26 PR/55789: Ruslan Nikolaev: New rump drivers 2020-11-06 15:35:33 +00:00
christos
99d114a9bf PR/55777: Ruslan Nikolaev: Move the unp_sysctl_create to uipc_usrreq.c to
facilitate splitting rump modules and does not require a dummy function.
2020-11-06 14:50:13 +00:00
christos
2a72b2ad75 PR/55781: Ruslan Nikolaev: rump_init() does differentiate when all CPUs are
initialized
2020-11-04 22:06:38 +00:00
martin
5f6c9b1187 Add turnstile_print prototype for LOCKDEBUG 2020-11-04 19:27:53 +00:00
christos
0881e80663 PR/55777: Ruslan Nikolaev: use MIN() from <sys/param.h> instead of min() 2020-11-02 18:58:06 +00:00
christos
a7bda7d7ba regen 2020-11-02 18:56:15 +00:00
christos
e71b1b1e70 PR/55664: Ruslan Nikolaev: Fix:
1. A race condition (bug) in sys/rump/librump/rumpkern/intr.c since
   rumpuser_cv_signal() is called without holding a mutex
2. sleepq is implemented using a single (global) conditional
   variable; that should be done per each sleepq separately
2020-11-01 20:58:38 +00:00
chs
72d70d6a9f fix an incorrect assertion in the previous commit. 2020-10-22 03:05:17 +00:00
chs
9d18193c79 Move the handling of PG_PAGEOUT from uvm_aio_aiodone_pages() to
uvm_page_unbusy() so that all callers of uvm_page_unbusy() don't need to
handle this flag separately.  Split out the pages part of uvm_aio_aiodone()
into uvm_aio_aiodone_pages() in rump just like in the real kernel.
In ZFS functions that can fail to copy data between the ARC and VM pages,
use uvm_aio_aiodone_pages() rather than uvm_page_unbusy() so that we can
handle these "I/O" errors.  Fixes PR 55702.
2020-10-18 18:22:29 +00:00
roy
6c00c3be34 rumpify vether(4) 2020-09-29 18:33:22 +00:00
roy
5f960c42fc libtap: Improve comment 2020-09-29 18:31:31 +00:00
roy
13422f008b rump: Add weak alias for bridge_calc_link_state 2020-09-27 00:34:44 +00:00
roy
0fb7a2c416 rump: Try to fix build 2020-09-27 00:17:56 +00:00
roy
58e262a6e6 rump: Add nd.c to libnet 2020-09-12 10:44:32 +00:00
mrg
c2082ece61 remove GCC_NO_ADDR_OF_PACKED_MEMBER for several subdir builds
that are now handled by lfs_accessors.h internally.
2020-09-07 03:09:53 +00:00
mrg
cb93b81028 add support for new GCC 9 warnings that may be too much to fix
right now.  new address-of-packed-member and format-overflow
warnings have new GCC_NO_ADDR_OF_PACKED_MEMBER amd
GCC_NO_FORMAT_OVERFLOW variables to remove these warnings.

apply to a bunch of the tree.  mostly, these are real bugs that
should be fixed, but in many cases, only by removing the 'packed'
attribute from some structure that doesn't really need it.  (i
looked at many different ones, and while perhaps 60-80% were
already properly aligned, it wasn't clear to me that the uses
were always coming from sane data vs network alignment, so it
doesn't seem safe to remove packed without careful research for
each affect struct.)  clang already warned (and was not erroring)
for many of these cases, but gcc picked up dozens more.
2020-09-06 07:20:26 +00:00
riastradh
9fc453562f Round of uvm.h cleanup.
The poorly named uvm.h is generally supposed to be for uvm-internal
users only.

- Narrow it to files that actually need it -- mostly files that need
  to query whether curlwp is the pagedaemon, which should maybe be
  exposed by an external header.

- Use uvm_extern.h where feasible and uvm_*.h for things not exposed
  by it.  We should split up uvm_extern.h but this will serve for now
  to reduce the uvm.h dependencies.

- Use uvm_stat.h and #ifdef UVMHIST uvm.h for files that use
  UVMHIST(ubchist), since ubchist is declared in uvm.h but the
  reference evaporates if UVMHIST is not defined, so we reduce header
  file dependencies.

- Make uvm_device.h and uvm_swap.h independently includable while
  here.

ok chs@
2020-09-05 16:30:10 +00:00
ozaki-r
b494441ddd ipsec: rename ipsec_ip_input to ipsec_ip_input_checkpolicy
Because it just checks if a packet passes security policies.
2020-08-28 06:20:44 +00:00
riastradh
adaf68a3d1 Sort includes, nix trailing whitespace, fix comment. 2020-08-27 14:11:57 +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
e88ecca629 Fix order of cleanup actions in rumpuser_wg_create error branch. 2020-08-27 02:51:15 +00:00
riastradh
efb788bb64 Paranoia: use strlcpy rather than strcpy here and detect truncation.
Not an issue for the one caller in tree, but let's not leave rakes to
step on.
2020-08-27 02:50:44 +00:00
riastradh
25154f5f0c Clarify wg(4)'s relation to WireGuard, pending further discussion.
Still planning to replace wgconfig(8) and wg-keygen(8) by one wg(8)
tool compatible with wireguard-tools; update wg(4) for the minor
changes from the 2018-06-30 spec to the 2020-06-01 spec; &c.  This just
clarifies the current state of affairs as it exists in the development
tree for now.

Mark the man page EXPERIMENTAL for extra clarity.
2020-08-26 16:03:40 +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
61fd7d67f5 [ozaki-r] Add wg files 2020-08-20 21:28:00 +00:00
riastradh
a14187eca5 [ozaki-r] Changes to the kernel core for wireguard 2020-08-20 21:21:31 +00:00
riastradh
d18c7c1a89 regen 2020-08-14 00:55:02 +00:00
riastradh
bdad8b2721 New system call getrandom() compatible with Linux and others.
Three ways to call:

getrandom(p, n, 0)              Blocks at boot until full entropy.
                                Returns up to n bytes at p; guarantees
                                up to 256 bytes even if interrupted
                                after blocking.  getrandom(0,0,0)
                                serves as an entropy barrier: return
                                only after system has full entropy.

getrandom(p, n, GRND_INSECURE)  Never blocks.  Guarantees up to 256
                                bytes even if interrupted.  Equivalent
                                to /dev/urandom.  Safe only after
                                successful getrandom(...,0),
                                getrandom(...,GRND_RANDOM), or read
                                from /dev/random.

getrandom(p, n, GRND_RANDOM)    May block at any time.  Returns up to n
                                bytes at p, but no guarantees about how
                                many -- may return as short as 1 byte.
                                Equivalent to /dev/random.  Legacy.
                                Provided only for source compatibility
                                with Linux.

Can also use flags|GRND_NONBLOCK to fail with EWOULDBLOCK/EAGAIN
without producing any output instead of blocking.

- The combination GRND_INSECURE|GRND_NONBLOCK is the same as
  GRND_INSECURE, since GRND_INSECURE never blocks anyway.

- The combinations GRND_INSECURE|GRND_RANDOM and
  GRND_INSECURE|GRND_RANDOM|GRND_NONBLOCK are nonsensical and fail
  with EINVAL.

As proposed on tech-userlevel, tech-crypto, tech-security, and
tech-kern, and subsequently adopted by core (minus the getentropy part
of the proposal, because other operating systems and participants in
the discussion couldn't come to an agreement about getentropy and
blocking semantics):

https://mail-index.netbsd.org/tech-userlevel/2020/05/02/msg012333.html
2020-08-14 00:53:15 +00:00
riastradh
394a3a3319 Define kthread_fpu_enter/exit for rump.
XXX Not 100% sure that it's safe to touch curlwp->l_flag in this
context, but this change will make progress, at least.
2020-08-01 22:30:57 +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
pgoyette
95e145a85a Remove spurious call to canloopinit() in an attempt to fix kern/55489
This attempt at fixing is a result of IRC discussions with martin@ and
riastradh@
2020-07-21 18:38:18 +00:00
riastradh
8747f41571 copystr is now in libkern; don't redefine it in rumpcopy.c.
Should fix build breakage from the copystr changes.
2020-07-01 00:42:13 +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
msaitoh
a0e0efb77d Serialize rdtsc using with lfence, mfence or cpuid to read TSC more precisely.
x86/x86/tsc.c rev. 1.67 reduced cache problem and got big improvement, but it
 still has room. I measured the effect of lfence, mfence, cpuid and rdtscp.
The impact to TSC skew and/or drift is:

	AMD:   mfence > rdtscp > cpuid > lfence-serialize > lfence = nomodify
	Intel: lfence > rdtscp > cpuid > nomodify

So, mfence is the best on AMD and lfence is the best on Intel. If it has no
SSE2, we can use cpuid.

NOTE:
  - An AMD's document says DE_CFG_LFENCE_SERIALIZE bit can be used for
    serializing, but it's not so good.
  - On Intel i386(not amd64), it seems the improvement is very little.
  - rdtscp instruct can be used as serializing instruction + rdtsc, but
    it's not good as [lm]fence. Both Intel and AMD's document say that
    the latency of rdtscp is bigger than rdtsc, so I suspect the difference
    of the result comes from it.
2020-06-15 09:09:23 +00:00
kamil
52d61e4d3d Remove old compat include of rump_syscallshotgun.h
It was separated in 2016 and is no longer needed.
2020-06-14 23:38:25 +00:00
kamil
f39d324fdc Fix header compatibility with C++
This file is OS-agnostic and cannot include OS specific headers.

The fallback for NetBSD specific symbol __BEGIN_DECLS didn't work as it was
misspelled as _BEGIN_DECLS.
2020-06-14 22:12:58 +00:00
roy
b05648aa26 Remove in-kernel handling of Router Advertisements
This is much better handled by a user-land tool.
Proposed on tech-net here:
https://mail-index.netbsd.org/tech-net/2020/04/22/msg007766.html

Note that the ioctl SIOCGIFINFO_IN6 no longer sets flags. That now
needs to be done using the pre-existing SIOCSIFINFO_FLAGS ioctl.

Compat is fully provided where it makes sense, but trying to turn on
RA handling will obviously throw an error as it no longer exists.

Note that if you use IPv6 temporary addresses, this now needs to be
turned on in dhcpcd.conf(5) rather than in sysctl.conf(5).
2020-06-12 11:04:44 +00:00