Commit Graph

65 Commits

Author SHA1 Message Date
maxv e294edec3f Remove unused malloc.h include. 2018-04-18 07:38:02 +00:00
maxv 3233810064 fix comments 2018-04-17 17:56:08 +00:00
maxv f75d3c0566 Introduce a m_verify_packet function, that verifies the mbuf chain of a
packet to ensure it is not malformed. Call this function in "points of
interest", that are the IPv4/IPv6/IPsec entry points. There could be more.

We use M_VERIFY_PACKET(m), declared under DIAGNOSTIC only.

This function should not be called everywhere, especially not in places
that temporarily manipulate (and clobber) the mbuf structure; once they're
done they put the mbuf back in a correct format.
2018-04-15 07:35:49 +00:00
maxv b39a0dd1f8 Dedup: merge ipsec4_in_reject and ipsec6_in_reject into ipsec_in_reject.
While here fix misleading comment.

ok ozaki-r@
2018-02-26 09:04:29 +00:00
maxv 0f3ae0526d If 'skip' is lower than sizeof(struct ip), we are in trouble. So remove a
nonsensical branch, and add a panic at the beginning of the function.
2018-02-26 06:58:56 +00:00
maxv 1d337420b7 m is never allowed to be NULL, so turn the KASSERT (and the null check)
to a panic.
2018-02-26 06:53:22 +00:00
maxv 16a6b57077 Merge some minor (mostly stylistic) changes from last week. 2018-02-26 06:17:01 +00:00
maxv 8084c6496d Argh, in my previous commit in this file I forgot to fix the IPv6
entry point; apply the same fix there.
2018-02-21 16:48:28 +00:00
maxv ff46a2a32a Extend these #ifdef notyet. The m_copydata's in these branches are wrong,
we are not guaranteed to have enough room for another struct ip, and we
may crash here. Triggerable remotely, but after authentication, by sending
an AH packet that has a one-byte-sized IPIP payload.
2018-02-21 16:08:55 +00:00
maxv 5104ba25f8 Remove unused net_osdep.h include. 2018-02-08 20:57:41 +00:00
maxv 61a2b14b11 Fix the iteration: IPPROTO_FRAGMENT options are special, in the sense
that they don't have a 'length' field. It is therefore incorrect to
read ip6e.ip6e_len, it contains garbage.

I'm not sure whether this an exploitable vulnerability. Because of this
bug you could theoretically craft 'protoff', which means that you can
have the kernel patch the nxt value at the wrong place once the packet
is decrypted. Perhaps it can be used in some unusual MITM - a router that
happens to be between two IPsec hosts adds a frag6 option in the outer
IPv6 header to trigger the bug in the receiver -, but I couldn't come up
with anything worrying.
2018-01-24 14:28:13 +00:00
maxv 99712ef7e1 ipsec4_fixup_checksum calls m_pullup, so don't forget to do mtod() again,
to prevent use-after-free.

In fact, the m_pullup call is never reached: it is impossible for 'skip'
to be zero in this function, so add an XXX for now.
2018-01-24 14:01:40 +00:00
ozaki-r 9d97a0eb4e Add missing NULL-checking for m_pullup (CID 1427770: Null pointer dereferences (NULL_RETURNS)) 2018-01-23 02:21:49 +00:00
ozaki-r 7a24d65640 KNF: replace soft tabs with hard tabs 2018-01-23 02:18:57 +00:00
ozaki-r 8be5cabc41 Introduce KEY_SA_UNREF and replace KEY_FREESAV with it where sav will never be actually freed in the future
KEY_SA_UNREF is still key_freesav so no functional change for now.

This change reduces diff of further changes.
2017-08-03 06:32:51 +00:00
ozaki-r 894072c9be Remove unnecessary KEY_FREESAV in an error path
sav should be freed (unreferenced) by the caller.
2017-08-03 04:42:26 +00:00
ozaki-r 5d60cbbbf8 Stop setting mtag of PACKET_TAG_IPSEC_IN_DONE because there is no users anymore 2017-07-21 04:55:36 +00:00
ozaki-r 7ec82a4369 Omit unnecessary NULL checks for sav->sah 2017-07-12 07:00:40 +00:00
ozaki-r 6f13f59f2e Rename key_alloc* functions (NFC)
We shouldn't use the term "alloc" for functions that just look up
data and actually don't allocate memory.
2017-07-07 01:37:34 +00:00
ozaki-r 765c1e87d3 Simplify; we can assume sav->tdb_xform cannot be NULL while it's valid 2017-07-06 09:49:46 +00:00
ozaki-r 2b6b0bfccb Remove codes for PACKET_TAG_IPSEC_IN_CRYPTO_DONE
It seems that PACKET_TAG_IPSEC_IN_CRYPTO_DONE is for network adapters
that have IPsec accelerators; a driver sets the mtag to a packet
when its device has already encrypted the packet.

Unfortunately no driver implements such offload features for long
years and seems unlikely to implement them soon. (Note that neither
FreeBSD nor Linux doesn't have such drivers.) Let's remove related
(unused) codes and simplify the IPsec code.
2017-07-05 03:44:59 +00:00
christos c4c3d29fe2 PR/52346: Frank Kardel: Fix checksumming for NAT-T
See XXX for improvements.
2017-06-28 13:12:37 +00:00
ozaki-r 290dc4927e Introduce IPSECLOG and replace ipseclog and DPRINTF with it 2017-05-19 04:34:09 +00:00
ryo dd8c81f5bb Make ipsec_address() and ipsec_logsastr() mpsafe. 2017-05-11 05:55:14 +00:00
ozaki-r ef67739a78 Retire ipsec_osdep.h
We don't need to care other OSes (FreeBSD) anymore.

Some macros are alive in ipsec_private.h.
2017-04-19 03:39:14 +00:00
ozaki-r 2620e166df Convert IPSEC_ASSERT to KASSERT or KASSERTMSG
IPSEC_ASSERT just discarded specified message...
2017-04-18 05:26:41 +00:00
ozaki-r b4d2d2c260 Remove __FreeBSD__ and __NetBSD__ switches
No functional changes (except for a debug printf).

Note that there remain some __FreeBSD__ for sysctl knobs which counerparts
to NetBSD don't exist. And ipsec_osdep.h isn't touched yet; tidying it up
requires actual code changes.
2017-04-18 05:25:32 +00:00
ozaki-r 80d40a78b4 Prepare netipsec for rump-ification
- Include "opt_*.h" only if _KERNEL_OPT is defined
- Allow encapinit to be called twice (by ifinit and ipe4_attach)
  - ifinit didn't call encapinit if IPSEC is enabled (ipe4_attach called
    it instead), however, on a rump kernel ipe4_attach may not be called
    even if IPSEC is enabled. So we need to allow ifinit to call it anyway
- Setup sysctls in ipsec_attach explicitly instead of using SYSCTL_SETUP
- Call ip6flow_invalidate_all in key_spdadd only if in6_present
  - It's possible that a rump kernel loads the ipsec library but not
    the inet6 library
2017-04-06 09:20:07 +00:00
ryo 28f4c24cc2 Make ip6_sprintf(), in_fmtaddr(), lla_snprintf() and icmp6_redirect_diag() mpsafe.
Reviewed by ozaki-r@
2017-01-16 07:33:36 +00:00
ozaki-r fe6d427551 Avoid storing a pointer of an interface in a mbuf
Having a pointer of an interface in a mbuf isn't safe if we remove big
kernel locks; an interface object (ifnet) can be destroyed anytime in any
packet processing and accessing such object via a pointer is racy. Instead
we have to get an object from the interface collection (ifindex2ifnet) via
an interface index (if_index) that is stored to a mbuf instead of an
pointer.

The change provides two APIs: m_{get,put}_rcvif_psref that use psref(9)
for sleep-able critical sections and m_{get,put}_rcvif that use
pserialize(9) for other critical sections. The change also adds another
API called m_get_rcvif_NOMPSAFE, that is NOT MP-safe and for transition
moratorium, i.e., it is intended to be used for places where are not
planned to be MP-ified soon.

The change adds some overhead due to psref to performance sensitive paths,
however the overhead is not serious, 2% down at worst.

Proposed on tech-kern and tech-net.
2016-06-10 13:31:43 +00:00
riastradh 7c7b1739c8 Revert previous: ran cvs commit when I meant cvs diff. Sorry!
Hit up-arrow one too few times.
2016-01-21 15:41:29 +00:00
riastradh b41d562bd0 Give proper prototype to ip_output. 2016-01-21 15:27:48 +00:00
ozaki-r 48b3acd885 Tidy up opt_ipsec.h inclusions
Some inclusions of opt_ipsec.h were for IPSEC_NAT_T and are now unnecessary.
Add inclusions to some C files for IPSEC_DEBUG.
2015-03-30 03:51:50 +00:00
ozaki-r 81f1fa87b7 Mark a variable __diagused 2014-03-08 12:18:04 +00:00
mrg a370d57c87 - apply some __diagused
- remove unused variables
- move some variables inside their relevant use #ifdef
2013-11-03 18:37:10 +00:00
christos 213e873fd6 PR/47886: Dr. Wolfgang Stukenbrock: IPSEC_NAT_T enabled kernels may access
outdated pointers and pass ESP data to UPD-sockets.
While here, simplify the code and remove the IPSEC_NAT_T option; always
compile nat-traversal in so that it does not bitrot.
2013-06-04 22:47:37 +00:00
drochner 00cbca9cf5 After IPSEC input processing, pass a decoded/authenticated IPv4 packet
to upper layers through the IP protosw, as done for IPv6.
Before it was reinjected into the IP netisr queue which caused more
overhead and caused artefacts like double IP option processing.
Works well for me, should get more testing and review.
2012-01-25 21:58:10 +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
drochner 4b552d0b1b adopt a fix from OpenBSD: when scanning the IPv6 header chain, take
into account that the extension header type is not in the extension
header itself but in the previous one -- this makes a difference
because (a) the length field is different for AH than for all others
and (b) the offset of the "next type" field isn't the same in primary
and extension headers.
(I didn't manage to trigger the bug in my tests, no extension headers
besides AH made it to that point. Didn't try hard enough -- the fix
is still valid.)
2011-02-21 22:54:45 +00:00
drochner a301ba8826 deal with IPv6 address scope, so that SA lookup for
link-local addresses works
(PR kern/43071 is related, but refers to KAME IPSEC)
2011-02-18 16:10:11 +00:00
drochner cd9bf26d13 handle some unlikely IPv6 error case like everywhere else:
free mbuf, inc statcounter. from OpenBSD
being here, fix a diagnostic output
2011-02-17 20:20:18 +00:00
drochner 443d341d0f remove some unnecessary pointer typecasts
(one was wrong on BE systems, but was harmless here because the
result is effectively unused)
2011-02-16 18:39:33 +00:00
tsutsui d779b85d3e Remove extra whitespace added by a stupid tool.
XXX: more in src/sys/arch
2009-04-18 14:58:02 +00:00
cegger e2cb85904d bcopy -> memcpy 2009-03-18 17:06:41 +00:00
cegger c363a9cb62 bzero -> memset 2009-03-18 16:00:08 +00:00
thorpej caf49ea572 Make IPSEC and FAST_IPSEC stats per-cpu. Use <net/net_stats.h> and
netstat_sysctl().
2008-04-23 06:09:04 +00:00
thorpej 680fd6866d Make ip6 and icmp6 stats per-cpu. 2008-04-15 04:43:53 +00:00
thorpej 3f466bce48 Change IPv6 stats from a structure to an array of uint64_t's.
Note: This is ABI-compatible with the old ip6stat structure; old netstat
binaries will continue to work properly.
2008-04-08 23:37:43 +00:00
degroote 4ddfe916ff Add support for options IPSEC_NAT_T (RFC 3947 and 3948) for fast_ipsec(4).
No objection on tech-net@
2007-06-27 20:38:32 +00:00
degroote dd86ba7231 Remove useless cast
Use NULL instead of (void*) 0
2007-03-04 21:17:54 +00:00