Commit Graph

789 Commits

Author SHA1 Message Date
andvar f0dcd50e0e fix typos in comments s/iton/tion/ or s/ton/tion/. 2023-08-10 06:44:11 +00:00
knakahara 67794c2fe1 Use kmem_free instead of kmem_intr_free, as key_freesaval() is not called in softint after key.c:r1.223.
E.g. key_freesaval() was called the following call path before SAD MP-ify.
  esp_input_cb()
    KEY_FREESAV()
      key_freesav()
        key_delsav()
          key_freesaval()

ok'ed by ozaki-r@n.o.
2023-07-21 00:44:38 +00:00
ozaki-r 986909fbd3 ipsec: remove unnecessary splsoftnet
Because the code of IPsec itself is already MP-safe.
2023-01-27 09:33:43 +00:00
knakahara fea168e16c Fix: sp->lastused should be updated by time_uptime, and refactor a little. 2022-12-08 08:07:07 +00:00
knakahara 13a5442f36 Fix: update lastused of ipsecif(4) IPv6 out SP. 2022-12-08 08:05:03 +00:00
knakahara 45ca136d96 gif(4), ipsec(4) and l2tp(4) use encap_attach_addr(). 2022-12-07 08:30:15 +00:00
knakahara 4a72762588 Fix IPv4 security policy with port number does not work for forwarding packets. 2022-11-09 08:18:52 +00:00
ozaki-r 2ba9f052f6 inpcb: rename functions to inpcb_*
Inspired by rmind-smpnet patches.
2022-11-04 09:00:58 +00:00
ozaki-r 2fd9c36db0 Remove in_pcb_hdr.h 2022-10-28 05:23:09 +00:00
ozaki-r 0e390eee90 inpcb: integrate data structures of PCB into one
Data structures of network protocol control blocks (PCBs), i.e.,
struct inpcb, in6pcb and inpcb_hdr, are not organized well.  Users of
the data structures have to handle them separately and thus the code
is cluttered and duplicated.

The commit integrates the data structures into one, struct inpcb.  As a
result, users of PCBs only have to handle just one data structure, so
the code becomes simple.

One drawback is that the data size of PCB for IPv4 increases by 40 bytes
(from 248 bytes to 288 bytes).
2022-10-28 05:18:39 +00:00
christos f18b57f7ac PR/56836: Andrew Cagney: IPv6 ESN tunneling IPcomp has corrupt header
Always always send / expect CPI in IPcomp header

Fixes kern/56836 where an IPsec interop combining compression and
ESP|AH would fail.

Since fast ipsec, the outgoing IPcomp header has contained the
compression algorithm instead of the CPI.  Adding the
SADB_X_EXT_RAWCPI flag worked around this but ...

The IPcomp's SADB was unconditionally hashed using the compression
algorithm instead of the CPI.  This meant that an incoming packet with
a valid CPI could never match its SADB.
2022-10-19 21:28:02 +00:00
knakahara 13ced16cf4 Add sadb_x_policy_flags to inform SP origination.
This extension(struct sadb_x_policy) is *not* defined by RFC2367.

OpenBSD does not have reserved fields in struct sadb_x_policy.
Linux does not use this field yet.
FreeBSD uses this field as "sadb_x_policy_scope"; the value range is
from 0x00 to 0x04.

We use from most significant bit to avoid the above usage.
2022-10-11 09:51:47 +00:00
thorpej eca1c11589 Remove unnecessary inclusion of <net/netisr.h>. 2022-09-02 23:48:10 +00:00
knakahara 8b09e22c14 Improve IPsec log when no key association found for SA. Implemented by ohishi@IIJ. 2022-08-23 09:25:10 +00:00
knakahara 6fda1d8cb0 Add sysctl entry to improve interconnectivity to some VPN appliances, pointed out by seil-team@IIJ.
If we want to allow different identifier types on IDii and IDir, set
net.key.allow_different_idtype=1.  Default(=0) is the same as before.
2022-08-09 08:03:22 +00:00
ozaki-r de071f95c0 ipsec: don't assert for the format of incoming packets 2022-05-25 04:15:44 +00:00
andvar cdc507f0d2 fix various typos in comment, documentation and log messages. 2022-05-24 20:50:17 +00:00
riastradh 893f06d42d opencrypto: crypto_dispatch never fails now. Make it return void.
Same with crypto_kdispatch.
2022-05-22 11:40:29 +00:00
riastradh 3bbdee2433 opencrypto: Rip out EAGAIN logic when unregistering crypto drivers.
I'm pretty sure this never worked reliably based on code inspection,
and it's unlikely to have ever been tested because it only applies
when unregistering a driver -- but we have no crypto drivers for
removable devices, so it would only apply if we went out of our way
to trigger detach with drvctl.

Instead, just make the operation fail with ENODEV, and remove all the
callback logic to resubmit the request on EAGAIN.  (Maybe this should
be ENXIO, but crypto_kdispatch already does ENODEV.)
2022-05-22 11:40:03 +00:00
riastradh a1f5e1f25c opencrypto: Make crypto_freesession return void.
No callers use the return value.  It is not sensible to allow this to
fail.
2022-05-22 11:39:37 +00:00
riastradh 56192e56b3 netipsec: Nothing uses xf_zeroize return value. Nix it. 2022-05-22 11:39:08 +00:00
riastradh 3ae8d479fa opencrypto: Make crp_callback, krp_callback return void.
Nothing uses the return values inside opencrypto, so let's stop
making users return them.
2022-05-22 11:30:40 +00:00
christos 0aad2e3580 PR/56840: Andrew Cagney: use the proper polarity hton/ntoh macros (no
functional change).
Factor out spi retrieving code into a function.
2022-05-19 19:18:03 +00:00
christos f59d9812aa PR/56841: Andrew Cagney: debug-log IPcomp CPI lookups:
- debug-logs why an SPI is rejected
    - adds missing __VA_OPT__(,) to some printf macros
    - debug-log SPI+proto when adding/updating entry
2022-05-18 15:20:18 +00:00
andvar 75d2abaeb1 fix various typos in comments and output/log messages. 2022-04-10 09:50:44 +00:00
andvar c45fbc6e3a fix few typos in comments and log message. 2022-02-13 22:20:08 +00:00
andvar 37b43e728a fix few more typos in comments. 2022-01-02 20:28:53 +00:00
andvar ee19b386b5 s/speficication/specification/ 2021-12-08 20:03:26 +00:00
andvar d1c4e519a3 fix various typos in comments, log messages and documentation. 2021-12-03 13:27:37 +00:00
msaitoh c0f6d48ba2 s/assocciation/association/ in comment. 2021-11-10 16:55:20 +00:00
andvar 6584ea569e fix various typos in compatibility, mainly in comments. 2021-08-09 20:49:08 +00:00
knakahara 949f1cae7e Make sequence number of esp header MP-safe for IPsec Tx side. reviewed by ozaki-r@n.o
In IPsec Tx side, one Security Association can be used by multiple CPUs.
On the other hand, in IPsec Rx side, one Security Association is used
by only one CPU.

XXX pullup-{8,9}
2020-10-05 09:51:25 +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
ozaki-r c1e00d7df1 inet, inet6: count packets dropped by IPsec
The counters count packets dropped due to security policy checks.
2020-08-28 06:19:13 +00:00
riastradh 5766dd4aa9 Rename enc_xform_rijndael128 -> enc_xform_aes.
Update netipsec dependency.
2020-06-30 04:14:55 +00:00
rin b203ba4088 Make crypto/rijindael optional again as cprng_strong does no longer
depend on it. Dependency is explicitly declared in files.foo if a
component requires it.
2020-04-22 09:15:39 +00:00
knakahara ddd7ead0f8 Fix kern/55066. Pointed out and fixed by Chuck Zmudzinski, thanks.
ok'ed by ozaki-r@n.o
2020-03-13 06:55:35 +00:00
thorpej b578a8edb0 Use percpu_foreach_xcall() to gather volatile per-cpu counters. These
must be serialized against the interrupts / soft-interrupts in which
they're manipulated, as well as protected from non-atomic 64-bit memory
loads on 32-bit platforms.
2020-02-07 12:35:33 +00:00
knakahara 840a0bbc09 Fix IPv6 over IPv4 ipsecif(4) uses IPv4 SP wrongly. Pointed out by ohishi@IIJ.
XXX pullup-8, pullup-9
2020-01-31 06:54:19 +00:00
knakahara d00f6f3b19 Reduce load for IKE negotiations when the system has many IPv6 addresses.
e.g. the system has many vlan(4), gif(4) or ipsecif(4) with link local address.
2019-11-14 03:17:08 +00:00
knakahara 52329830f1 Fix SA can be expaired wrongly when there are many SPs.
When key_timehandler_spd() spent over one second, the "now" argument of
key_timehandler_sad() could be older than sav->created. That caused SA
was expired immediately.
2019-11-12 05:13:29 +00:00
knakahara 93a28c822d Make global and per-interface ipsecif(4) pmtu tunable like gif(4).
And make hop limit tunable same as gif(4).

See http://mail-index.netbsd.org/source-changes/2019/10/30/msg110426.html
2019-11-01 04:28:14 +00:00
knakahara c535599f70 Fix ipsecif(4) IPV6_MINMTU does not work correctly. 2019-11-01 04:23:21 +00:00
ozaki-r 760452d22f Make panic messages more informative 2019-09-25 09:53:37 +00:00
knakahara 2da350beca Avoid having a rtcache directly in a percpu storage for tunnel protocols.
percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by ozaki-r@ and yamaguchi@
2019-09-19 06:07:24 +00:00
ozaki-r e524fb36a1 Avoid having a rtcache directly in a percpu storage
percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by knakahara@ and yamaguchi@
2019-09-19 04:08:29 +00:00
knakahara 683fe570e3 ipsec_getpolicybysock() should also call key_havesp() like ipsec_getpolicybyaddr().
That can reduce KEYDEBUG messages.
2019-08-07 10:10:00 +00:00
maxv 79bd11acc0 Fix info leaks. 2019-08-04 14:30:36 +00:00
ozaki-r 58b6a74e54 ipsec: fix a regression of the update API
The update API updates an SA by creating a new SA and removing an existing SA.
The previous change removed a newly added SA wrongly if an existing SA had been
created by the getspi API.
2019-07-23 04:29:26 +00:00
ozaki-r 75ffcec5e7 Avoid a race condition between SA (sav) manipulations
An sav can be removed from belonging list(s) twice resulting in an assertion
failure of pslist.  It can occur if the following two operations interleave:
(i) a deletion or a update of an SA via the API, and
(ii) a state change (key_sa_chgstate) of the same SA by the timer.
Note that even (ii) removes an sav once from its list(s) on a update.

The cause of the race condition is that the two operations are not serialized
and (i) doesn't get and remove an sav from belonging list(s) atomically.  So
(ii) can be inserted between an acquisition and a removal of (i).

Avoid the race condition by making (i) atomic.
2019-07-17 07:07:59 +00:00