summaryrefslogtreecommitdiffstats
path: root/sys/netipsec
Commit message (Collapse)AuthorAgeFilesLines
* Fix a typo in the last commit.Luiz Otavio O Souza2017-03-031-2/+2
|
* Pullup the correct length of the ip header.Luiz Otavio O Souza2017-03-031-1/+8
|
* Revert "Fix IPsec to skip the headers as requested by upper layers. This ↵Luiz Otavio O Souza2017-03-031-2/+2
| | | | | | fixes the IP pointer into the mbuf data." This reverts commit d8ce356c1249fed487cc530ef08fbb2047c6d7e0.
* Fix IPsec to skip the headers as requested by upper layers. This fixes the ↵Luiz Otavio O Souza2017-03-031-2/+2
| | | | | | | IP pointer into the mbuf data. Ticket #6937 Ticket #7015
* Fix the transport mode states on enc interface.Luiz Otavio O Souza2017-02-061-2/+6
| | | | | | Due to the filter mask used in pfSense and the way the transport mode works, this hack simplify things and should fix a couple of regressions. Ticket #6937
* MFC r311679:ae2017-01-161-7/+10
| | | | | | | | | | | | | | | | | Add direction argument to ipsec_setspidx_inpcb() function. This function is used only by ipsec_getpolicybysock() to fill security policy index selector for locally generated packets (that have INPCB). The function incorrectly assumes that spidx is the same for both directions. Fix this by using new direction argument to specify correct INPCB security policy - sp_in or sp_out. There is no need to fill both policy indeces, because they are overwritten for each packet. This fixes security policy matching for outbound packets when user has specified TCP/UDP ports in the security policy upperspec. PR: 213869 (cherry picked from commit b1d40028dfe120489903320906bf0587a735fe45)
* Get closer to a VIMAGE network stack teardown from top to bottom ratherbz2016-06-212-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | than removing the network interfaces first. This change is rather larger and convoluted as the ordering requirements cannot be separated. Move the pfil(9) framework to SI_SUB_PROTO_PFIL, move Firewalls and related modules to their own SI_SUB_PROTO_FIREWALL. Move initialization of "physical" interfaces to SI_SUB_DRIVERS, move virtual (cloned) interfaces to SI_SUB_PSEUDO. Move Multicast to SI_SUB_PROTO_MC. Re-work parts of multicast initialisation and teardown, not taking the huge amount of memory into account if used as a module yet. For interface teardown we try to do as many of them as we can on SI_SUB_INIT_IF, but for some this makes no sense, e.g., when tunnelling over a higher layer protocol such as IP. In that case the interface has to go along (or before) the higher layer protocol is shutdown. Kernel hhooks need to go last on teardown as they may be used at various higher layers and we cannot remove them before we cleaned up the higher layers. For interface teardown there are multiple paths: (a) a cloned interface is destroyed (inside a VIMAGE or in the base system), (b) any interface is moved from a virtual network stack to a different network stack ("vmove"), or (c) a virtual network stack is being shut down. All code paths go through if_detach_internal() where we, depending on the vmove flag or the vnet state, make a decision on how much to shut down; in case we are destroying a VNET the individual protocol layers will cleanup their own parts thus we cannot do so again for each interface as we end up with, e.g., double-frees, destroying locks twice or acquiring already destroyed locks. When calling into protocol cleanups we equally have to tell them whether they need to detach upper layer protocols ("ulp") or not (e.g., in6_ifdetach()). Provide or enahnce helper functions to do proper cleanup at a protocol rather than at an interface level. Approved by: re (hrs) Obtained from: projects/vnet Reviewed by: gnn, jhb Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D6747
* netipsec: Fix minor style nitcem2016-05-101-1/+1
| | | | | | | | | Coverity points out that 'continue' is equivalent to 'break' in a do {} while(false) loop. Reported by: Coverity CID: 1354983 Sponsored by: EMC / Isilon Storage Division
* sys/net*: minor spelling fixes.pfg2016-05-033-10/+10
| | | | No functional change.
* netipsec: Don't leak memory when deep copy failscem2016-04-261-0/+1
| | | | | | Reported by: Coverity CID: 1331693 Sponsored by: EMC / Isilon Storage Division
* Fix build for NOINET and NOINET6 kernels.ae2016-04-241-20/+33
| | | | | | | | | Use own protosw structures for both address families. Check proto in encapcheck function and use -1 as proto argument in encap_attach_func(), both address families can have IPPROTO_IPV4 and IPPROTO_IPV6 protocols. Reported by: bz
* Use ipsec_address() function to print IP addresses.ae2016-04-241-16/+8
|
* Handle non-compressed packets for IPComp in tunnel mode.ae2016-04-243-1/+201
| | | | | | | | | | | | | | | | | RFC3173 says that the IP datagram MUST be sent in the original non-compressed form, when the total size of a compressed payload and the IPComp header is not smaller than the size of the original payload. In tunnel mode for small packets IPComp will send encapsulated IP datagrams without IPComp header. Add ip_encap handler for IPPROTO_IPV4 and IPPROTO_IPV6 to handle these datagrams. The handler does lookup for SA related to IPComp protocol and given from mbuf source and destination addresses as tunnel endpoints. It decapsulates packets only when corresponding SA is found. Reported by: gnn Reviewed by: gnn Differential Revision: https://reviews.freebsd.org/D6062
* Remove stale function declarationae2016-04-211-2/+0
|
* Constify mbuf pointer for IPSEC functions where mbuf isn't modified.ae2016-04-215-45/+51
|
* kernel: use our nitems() macro when it is available through param.h.pfg2016-04-192-5/+5
| | | | | | No functional change, only trivial cases are done in this sweep, Discussed in: freebsd-current
* sys/net* : for pointers replace 0 with NULL.pfg2016-04-154-12/+12
| | | | | | Mostly cosmetical, no functional change. Found with devel/coccinelle.
* Fix handling of net.inet.ipsec.dfbit=2 variable.ae2016-03-181-1/+1
| | | | | IP_DF macro is in host bytes order, but ip_off field is in network bytes order. So, use htons() for correct check.
* Put IPSec's anouncement of its successful intialisation under bootverbose:rwatson2016-03-131-1/+2
| | | | | now that it's a default kernel option, we don't really need to tell the world about it on every boot, especially as it won't be used by most users.
* Set tres to NULL to avoid a double free if the m_pullup() below fails.markj2016-03-021-0/+1
| | | | | | Reviewed by: glebius MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D5497
* Fix useless check. m_pkthdr.len should be equal to orglen.ae2016-02-241-2/+1
| | | | MFC after: 2 weeks
* These files were getting sys/malloc.h and vm/uma.h with header pollutionglebius2016-02-012-1/+2
| | | | via sys/mbuf.h
* Overhaul if_enc(4) and make it loadable in run-time.ae2015-11-254-102/+80
| | | | | | | | Use hhook(9) framework to achieve ability of loading and unloading if_enc(4) kernel module. INET and INET6 code on initialization registers two helper hooks points in the kernel. if_enc(4) module uses these helper hook points and registers its hooks. IPSEC code uses these hhook points to call helper hooks implemented in if_enc(4).
* Implement the sadb_x_policy_priority field as it is done in Linux:fabient2015-11-172-7/+31
| | | | | | | | lower priority policies are inserted first. Submitted by: Emeric Poupon <emeric.poupon@stormshield.eu> Reviewed by: ae Sponsored by: Stormshield
* Use explicitly specified ivsize instead of blocksize when we mean IV size.ae2015-11-162-8/+2
| | | | | | | | Set zero ivsize for enc_xform_null and remove special handling from xform_esp.c. Reviewed by: gnn Differential Revision: https://reviews.freebsd.org/D1503
* Turning on IPSEC used to introduce a slight amount of performancegnn2015-10-271-0/+6
| | | | | | | | | | | | | degradation (7%) for host host TCP connections over 10Gbps links, even when there were no secuirty policies in place. There is no change in performance on 1Gbps network links. Testing GENERIC vs. GENERIC-NOIPSEC vs. GENERIC with this change shows that the new code removes any overhead introduced by having IPSEC always in the kernel. Differential Revision: D3993 MFC after: 1 month Sponsored by: Rubicon Communications (Netgate)
* Take extra reference to security policy before calling crypto_dispatch().ae2015-09-304-14/+5
| | | | | | | | | | | | | Currently we perform crypto requests for IPSEC synchronous for most of crypto providers (software, aesni) and only VIA padlock calls crypto callback asynchronous. In synchronous mode it is possible, that security policy will be removed during the processing crypto request. And crypto callback will release the last reference to SP. Then upon return into ipsec[46]_process_packet() IPSECREQUEST_UNLOCK() will be called to already freed request. To prevent this we will take extra reference to SP. PR: 201876 Sponsored by: Yandex LLC
* Make IPsec work with AES-GCM and AES-ICM (aka CTR) in OCF... IPsecjmg2015-08-044-89/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | defines the keys differently than NIST does, so we have to muck with key lengths and nonce/IVs to be standard compliant... Remove the iv from secasvar as it was unused... Add a counter protected by a mutex to ensure that the counter for GCM and ICM will never be repeated.. This is a requirement for security.. I would use atomics, but we don't have a 64bit one on all platforms.. Fix a bug where IPsec was depending upon the OCF to ensure that the blocksize was always at least 4 bytes to maintain alignment... Move this logic into IPsec so changes to OCF won't break IPsec... In one place, espx was always non-NULL, so don't test that it's non-NULL before doing work.. minor style cleanups... drop setting key and klen as they were not used... Enforce that OCF won't pass invalid key lengths to AES that would panic the machine... This was has been tested by others too... I tested this against NetBSD 6.1.5 using mini-test suite in https://github.com/jmgurney/ipseccfgs and the only things that don't pass are keyed md5 and sha1, and 3des-deriv (setkey syntax error), all other modes listed in setkey's man page... The nice thing is that NetBSD uses setkey, so same config files were used on both... Reviewed by: gnn
* these are comparing authenticators and need to be constant time...jmg2015-07-312-2/+2
| | | | | | | This could be a side channel attack... Now that we have a function for this, use it... jmgurney/ipsecgcm: 24d704cc and 7f37a14
* Clean up this header file...jmg2015-07-311-2/+0
| | | | | | | | | | | | | | | | | | | | | use CTASSERTs now that we have them... Replace a draft w/ RFC that's over 10 years old. Note that _AALG and _EALG do not need to match what the IKE daemons think they should be.. This is part of the KABI... I decided to renumber AESCTR, but since we've never had working AESCTR mode, I'm not really breaking anything.. and it shortens a loop by quite a bit.. remove SKIPJACK IPsec support... SKIPJACK never made it out of draft (in 1999), only has 80bit key, NIST recommended it stop being used after 2010, and setkey nor any of the IKE daemons I checked supported it... jmgurney/ipsecgcm: a357a33, c75808b, e008669, b27b6d6 Reviewed by: gnn (earlier version)
* Correct IPSec SA statistic keepingeri2015-07-301-1/+2
| | | | | | | | | | | The IPsec SA statistic keeping is used even for decision making on expiry/rekeying SAs. When there are multiple transformations being done the statistic keeping might be wrong. This mostly impacts multiple encapsulations on IPsec since the usual scenario it is not noticed due to the code path not taken. Differential Revision: https://reviews.freebsd.org/D3239 Reviewed by: ae, gnn Approved by: gnn(mentor)
* RFC4868 section 2.3 requires that the output be half... This fixesjmg2015-07-293-26/+38
| | | | | | | | problems that was introduced in r285336... I have verified that HMAC-SHA2-256 both ah only and w/ AES-CBC interoperate w/ a NetBSD 6.1.5 vm... Reviewed by: gnn
* IPSEC, remove variable argument function its already due.eri2015-07-212-23/+8
| | | | | | Differential Revision: https://reviews.freebsd.org/D3080 Reviewed by: gnn, ae Approved by: gnn(mentor)
* Summary: Fix LINT build. The names of the new AES modes were notgnn2015-07-101-3/+3
| | | | correctly used under the REGRESSION kernel option.
* Add support for AES modes to IPSec. These modes work both in software onlygnn2015-07-092-73/+99
| | | | | | | | mode and with hardware support on systems that have AESNI instructions. Differential Revision: D2936 Reviewed by: jmg, eri, cognet Sponsored by: Rubicon Communications (Netgate)
* Fill the port and protocol information in the SADB_ACQUIRE messageae2015-07-061-8/+60
| | | | | | | | in case when security policy has it as required by RFC 2367. PR: 192774 Differential Revision: https://reviews.freebsd.org/D2972 MFC after: 1 week
* Reduce overhead of IPSEC for traffic generated from hosteri2015-07-031-0/+6
| | | | | | | | | | | | When IPSEC is enabled on the kernel the forwarding path has an optimization to not enter the code paths for checking security policies but first checks if there is any security policy active at all. The patch introduces the same optimization but for traffic generated from the host itself. This reduces the overhead by 50% on my tests for generated host traffic without and SP active. Differential Revision: https://reviews.freebsd.org/D2980 Reviewed by: ae, gnn Approved by: gnn(mentor)
* drop key_sa_stir_iv as it isn't used...jmg2015-06-112-9/+0
| | | | Reviewed by: eri, ae
* CALLOUT_MPSAFE has lost its meaning since r141428, i.e., for more than tenjkim2015-05-221-1/+1
| | | | | | | | | | years for head. However, it is continuously misused as the mpsafe argument for callout_init(9). Deprecate the flag and clean up callout_init() calls to make them more consistent. Differential Revision: https://reviews.freebsd.org/D2613 Reviewed by: jhb MFC after: 2 weeks
* In the reply to SADB_X_SPDGET message use the same sequence number thatae2015-05-201-2/+3
| | | | | | | | was in the request. Some IKE deamons expect it will the same. Linux and NetBSD also follow this behaviour. PR: 137309 MFC after: 2 weeks
* Remove unneded mbuf length adjustment, M_PREPEND() already did that.ae2015-05-191-2/+0
| | | | | PR: 139387 MFC after: 1 week
* Change SA's state before sending SADB_EXPIRE message. This state willae2015-05-191-2/+2
| | | | | | be reported to keying daemon. MFC after: 2 weeks
* Teach key_expire() send SADB_EXPIRE message with the SADB_EXT_LIFETIME_HARDae2015-05-191-40/+38
| | | | | | | | | | | | | extension header type. The key_flush_sad() now will send SADB_EXPIRE message when HARD lifetime expires. This is required by RFC 2367 and some keying daemons rely on these messages. HARD lifetime messages have precedence over SOFT lifetime messages, so now they will be checked first. Also now SADB_EXPIRE messages will be send even the SA has not been used, because keying daemons might want to rekey such SA. PR: 200282, 200283 Submitted by: Tobias Brunner <tobias at strongswan dot org> MFC after: 2 weeks
* Summary: Remove spurious, extra, next header comments.gnn2015-05-151-4/+2
| | | | Correct the name of the pad length field.
* Fix the comment. We will not do SPD lookup again, becauseae2015-04-281-2/+1
| | | | | | ip[6]_ipsec_output() will find PACKET_TAG_IPSEC_OUT_DONE mbuf tag. Sponsored by: Yandex LLC
* Since PFIL can change mbuf pointer, we should update pointers afterae2015-04-282-0/+3
| | | | | | calling ipsec_filter(). Sponsored by: Yandex LLC
* Make ipsec_in_reject() static. We use ipsec[46]_in_reject() instead.ae2015-04-272-2/+2
| | | | Sponsored by: Yandex LLC
* Fix possible use after free due to security policy deletion.ae2015-04-274-8/+30
| | | | | | | | | | | | | | | | When we are passing mbuf to IPSec processing via ipsec[46]_process_packet(), we hold one reference to security policy and release it just after return from this function. But IPSec processing can be deffered and when we release reference to security policy after ipsec[46]_process_packet(), user can delete this security policy from SPDB. And when IPSec processing will be done, xform's callback function will do access to already freed memory. To fix this move KEY_FREESP() into callback function. Now IPSec code will release reference to SP after processing will be finished. Differential Revision: https://reviews.freebsd.org/D2324 No objections from: #network Sponsored by: Yandex LLC
* Change ipsec_address() and ipsec_logsastr() functions to take twoae2015-04-187-132/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | additional arguments - buffer and size of this buffer. ipsec_address() is used to convert sockaddr structure to presentation format. The IPv6 part of this function returns pointer to the on-stack buffer and at the moment when it will be used by caller, it becames invalid. IPv4 version uses 4 static buffers and returns pointer to new buffer each time when it called. But anyway it is still possible to get corrupted data when several threads will use this function. ipsec_logsastr() is used to format string about SA entry. It also uses static buffer and has the same problem with concurrent threads. To fix these problems add the buffer pointer and size of this buffer to arguments. Now each caller will pass buffer and its size to these functions. Also convert all places where these functions are used (except disabled code). And now ipsec_address() uses inet_ntop() function from libkern. PR: 185996 Differential Revision: https://reviews.freebsd.org/D2321 Reviewed by: gnn Sponsored by: Yandex LLC
* Requeue mbuf via netisr when we use IPSec tunnel mode and IPv6.ae2015-04-181-1/+30
| | | | | | | | | | | | | | | | | | | ipsec6_common_input_cb() uses partial copy of ip6_input() to parse headers. But this isn't correct, when we use tunnel mode IPSec. When we stripped outer IPv6 header from the decrypted packet, it can become IPv4 packet and should be handled by ip_input. Also when we use tunnel mode IPSec with IPv6 traffic, we should pass decrypted packet with inner IPv6 header to ip6_input, it will correctly handle it and also can decide to forward it. The "skip" variable points to offset where payload starts. In tunnel mode we reset it to zero after stripping the outer header. So, when it is zero, we should requeue mbuf via netisr. Differential Revision: https://reviews.freebsd.org/D2306 Reviewed by: adrian, gnn Sponsored by: Yandex LLC
OpenPOWER on IntegriCloud