Commit Graph

737 Commits

Author SHA1 Message Date
christos
38947c9111 fix typo in comment, improve error message, add default case handling to
set error.
2019-06-12 22:23:06 +00:00
christos
6f900861cf Fix double free: key_setsaval() free's newsav by calling key_freesaval()
and key_api_update() calls key_delsav() when key_setsaval() fails which
calls key_freesaval() again...
2019-06-12 01:32:30 +00:00
knakahara
75255032e6 Don't clear calculated Tx tos value for IPv[46] over IPv6. 2019-05-17 05:27:24 +00:00
knakahara
2eeee3a428 remove a variable which is no longer used. 2019-04-12 07:12:12 +00:00
msaitoh
ad2fa80c12 s/pakcet/packet/ in comment. 2019-03-18 11:38:03 +00:00
maxv
516d295318 Fix locking: it is fine if the lock is already key_so_mtx, this can happen
in socketpair. In that case don't take it.

Ok ozaki-r@

Reported-by: syzbot+901e2e5edaaaed21c069@syzkaller.appspotmail.com
2019-02-26 06:52:34 +00:00
pgoyette
d91f98a871 Merge the [pgoyette-compat] branch 2019-01-27 02:08:33 +00:00
knakahara
e2f99c2d1d Fix ipsecif(4) cannot apply input direction packet filter. Reviewed by ozaki-r@n.o and ryo@n.o.
Add ATF later.
2019-01-17 02:47:15 +00:00
knakahara
58c5602068 ipsecif(4) supports multiple peers in the same NAPT.
E.g. ipsec0 connects between NetBSD_A and NetBSD_B, ipsec1 connects
NetBSD_A and NetBSD_C at the following figure.

                                        +----------+
                                   +----| NetBSD_B |
 +----------+           +------+   |    +----------+
 | NetBSD_A |--- ... ---| NAPT |---+
 +----------+           +------+   |    +----------+
                                   +----| NetBSD_C |
                                        +----------+

Add ATF later.
2018-12-26 08:58:51 +00:00
knakahara
64706e18ff Remove unnecessary addresses in PF_KEY message.
MOBIKE Extensions for PF_KEY draft-schilcher-mobike-pfkey-extension-01.txt says
====================
5.  SPD Update
// snip
   SADB_X_SPDADD:
// snip
      sadb_x_ipsecrequest_reqid:

         An ID for that SA can be passed to the kernel in the
         sadb_x_ipsecrequest_reqid field.


      If tunnel mode is specified, the sadb_x_ipsecrequest structure is
      followed by two sockaddr structures that define the tunnel
      endpoint addresses.  In the case that transport mode is used, no
      additional addresses are specified.
====================
see: https://tools.ietf.org/html/draft-schilcher-mobike-pfkey-extension-01

ipsecif(4) uses transport mode, so it should not add addresses.
2018-12-26 08:55:14 +00:00
maxv
8172cc2f5e Remove unused function. 2018-12-24 15:57:15 +00:00
maxv
5b040abec8 Replace M_ALIGN and MH_ALIGN by m_align. 2018-12-22 14:28:56 +00:00
maxv
b1305a6d63 Replace: M_MOVE_PKTHDR -> m_move_pkthdr. No functional change, since the
former is a macro to the latter.
2018-12-22 13:11:37 +00:00
knakahara
d2e69c9963 ipsecif(4) should not increment drop counter by errors not related to if_snd. Pointed out by ozaki-r@n.o, thanks. 2018-12-07 09:11:04 +00:00
knakahara
890dda538a Support IPv6 NAT-T. Implemented by hsuenaga@IIJ and ohishi@IIJ.
Add ATF later.
2018-11-22 04:48:34 +00:00
maxv
5c98710094 Remove the 't' argument from m_tag_find(). 2018-11-15 10:23:55 +00:00
roy
71ebc4ef79 Don't call soroverflow when we return the error to the sender.
Thanks to thorpej@ for a sanity check.
2018-11-08 04:30:37 +00:00
maxv
74fced2cf1 Localify one function, and switch to C99 types while here. 2018-10-27 05:42:23 +00:00
maxv
15652348f3 Use non-variadic function pointer in protosw::pr_input. 2018-09-14 05:09:51 +00:00
riastradh
d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
ozaki-r
f549b43cb1 Don't call key_ismyaddr, which may sleep, in a pserialize read section
Use mutex here instead of pserialize because using mutex is simpler than
using psz+ref, which is another solution, and key_checkspidup isn't called in
any performance-sensitive paths.
2018-08-23 01:55:38 +00:00
msaitoh
61e1eb0d0b - Cleanup for dynamic sysctl:
- Remove unused *_NAMES macros for sysctl.
  - Remove unused *_MAXID for sysctls.
- Move CTL_MACHDEP sysctl definitions for m68k into m68k/include/cpu.h and
  use them on all m68k machines.
2018-08-22 01:05:21 +00:00
maxv
3574e9908d Rename
ip_undefer_csum  -> in_undefer_cksum
	in_delayed_cksum -> in_undefer_cksum_tcpudp

The two previous names were inconsistent and misleading.

Put the two functions into in_offload.c. Add comments to explain what
we're doing.

The same could be done for IPv6.
2018-07-11 05:25:45 +00:00
christos
b1ffb99e21 merge duplicated code, more informative debugging. 2018-07-04 19:20:25 +00:00
maxv
48df35d34b Clarify, remove superfluous things. 2018-05-31 15:34:25 +00:00
maxv
56fc5b5d9b Adapt rev1.75, suggested by Alexander Bluhm. Relax the checks to allow
protocols smaller than two bytes (only IPPROTO_NONE). While here style.
2018-05-31 15:06:45 +00:00
maxv
f645db7adb Remove support for non-IKE markers in the kernel. Discussed on tech-net@,
and now in PR/53334. Basically non-IKE markers come from a deprecated
draft, and our kernel code for them has never worked.

Setsockopt will now reject UDP_ENCAP_ESPINUDP_NON_IKE.

Perhaps we should also add a check in key_handle_natt_info(), to make
sure we also reject UDP_ENCAP_ESPINUDP_NON_IKE in the SADB.
2018-05-31 07:03:57 +00:00
maxv
ec343e4518 Constify ipseczeroes, and remove one use of it. 2018-05-31 06:25:41 +00:00
maxv
80da173622 Add a comment and a KASSERT. I remember wondering whether this check was a
problem, since ARC4 has a blocksize of one. Normally ARC4 can't be used in
IPsec.
2018-05-31 06:14:18 +00:00
maxv
824196ce25 style 2018-05-31 05:52:09 +00:00
maxv
d52acbb31e Correctly handle the padding for IPv6-AH, as specified by RFC4302. Seen in
a FreeBSD bug report, by Jason Mader.

The RFC specifies that under IPv6 the complete AH header must be 64bit-
aligned, and under IPv4 32bit-aligned. That's a rule we've never respected.
The other BSDs and MacOS never have either.

So respect it now.

This makes it possible to set up IPv6-AH between Linux and NetBSD, and also
probably between Windows and NetBSD.

Until now all the tests I made were between two *BSD hosts, and everything
worked "correctly" since both hosts were speaking the same non-standard
AHv6, so they could understand each other.

Tested with Fedora<->NetBSD, hmac-sha2-384.
2018-05-30 18:02:40 +00:00
maxv
7aac0885cf Introduce ah_authsiz, which computes the length of the ICV only. Use it in
esp_hdrsiz, and clarify.

Until now we were using ah_hdrsiz, and were relying on the fact that the
size of the AH header happens to be equal to that of the ESP trailer.

Now the size of the ESP trailer is added manually. This also fixes one
branch in esp_hdrsiz: we always append an ESP trailer, so it must always
be taken into account, and not just when an ICV is here.
2018-05-30 17:17:11 +00:00
maxv
de1c7e1421 Apply the previous change in esp_input too, same as esp_output. 2018-05-30 16:49:38 +00:00
maxv
f4ab40f822 Remove dead code, 'espx' is never NULL and dereferenced earlier, so no need
to NULL-check all the time.
2018-05-30 16:43:29 +00:00
maxv
173a0d4a18 Simplify the padding computation. Until now 'padlen' contained the ESP
Trailer (two bytes), and we were doing minus two all the time.

Declare 'tlen', which contains padlen+ESP_Trailer+ICV, and use 'struct
esptail' instead of hardcoding the construction of the trailer. 'padlen'
now indicates only the length of the padding, so no need to do -2.
2018-05-30 16:32:26 +00:00
maxv
bc40d0f4f9 Rename padding -> padlen, pad -> tail, and clarify. 2018-05-30 16:15:19 +00:00
maxv
4b1bee9844 Strengthen and simplify, once more. 2018-05-29 16:50:38 +00:00
ozaki-r
25ec1e8354 Fix non-INET6 builds 2018-05-29 09:25:44 +00:00
maxv
a1d8c752e7 IP6_EXTHDR_GET -> M_REGION_GET, no functional change. 2018-05-18 18:58:51 +00:00
maxv
00ff305a9c Merge ipsec4_input and ipsec6_input into ipsec_ip_input. Make the argument
a bool for clarity. Optimize the function: if M_CANFASTFWD is not there
(because already removed by the firewall) leave now.

Makes it easier to see that M_CANFASTFWD is not removed on IPv6.
2018-05-14 17:34:26 +00:00
ozaki-r
b51605482b Restore TCP header inclusions for TCP_SIGNATURE 2018-05-14 02:16:29 +00:00
maxv
88bfc8dc97 Remove unused calls to nat_t_ports_get. 2018-05-13 18:34:59 +00:00
maxv
336c2eba16 ENOBUFS -> EACCES when updating the replay counter. 2018-05-11 15:43:07 +00:00
maxv
2bf15a966b Clean up, and panic if we call functions that are not supposed to be
called.
2018-05-11 13:50:38 +00:00
maxv
59275f7378 Replace dumb code by M_VERIFY_PACKET. In fact, perhaps we should not even
call M_VERIFY_PACKET here, there is no particular reason for this place to
be more wrong than the rest.
2018-05-10 05:15:14 +00:00
maxv
f813c44d31 Rename ipsec4_forward -> ipsec_mtu, and switch to void. 2018-05-10 05:08:53 +00:00
maxv
858396682a static const on ipsecif4_encapsw 2018-05-09 07:33:31 +00:00
maxv
436305f8d3 Remove a dummy reference to XF_IP4, explain briefly why we don't use
ipe4_xformsw, and remove unused includes.
2018-05-07 09:33:51 +00:00
maxv
20668b06aa Remove now unused 'isr', 'skip' and 'protoff' arguments from ipip_output. 2018-05-07 09:25:04 +00:00
maxv
defd3aa31c Remove unused 'mp' argument from all the xf_output functions. Also clean
up xform.h a bit.
2018-05-07 09:16:46 +00:00