Commit Graph

1864 Commits

Author SHA1 Message Date
ozaki-r 2050bad43a Don't run DAD on link-up if it's explicitly disabled 2018-11-29 09:54:22 +00:00
ozaki-r 42cd9a0569 Introduce and use ip_dad_enabled() and ip6_dad_enabled() functions 2018-11-29 09:51:20 +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
ozaki-r 1266a13d1c Restore the length check of a sockaddr passed from userland at udp6_output
A sockaddr with invalid length could be passed to the network stack resulting in
a kernel panic like this:

	panic: sockaddr_copy: source too long, 28 < 128 bytes
	fatal breakpoint trap in supervisor mode
	trap type 1 code 0 rip 0xffffffff80216c35 cs 0x8 rflags 0x246 cr2 0x7f7ff7ef3000 ilevel 0x4 rsp 0xffff80003308b690
	curlwp 0xfffffe803e11ca40 pid 48.1 lowest kstack 0xffff8000330852c0
	Stopped in pid 48.1 (a.out) at  netbsd:breakpoint+0x5:  leave
	db{1}> bt
	breakpoint() at netbsd:breakpoint+0x5
	vpanic() at netbsd:vpanic+0x140
	panic() at netbsd:panic+0x3c
	sockaddr_copy() at netbsd:sockaddr_copy+0x95
	rtcache_setdst() at netbsd:rtcache_setdst+0x73
	rtcache_lookup2() at netbsd:rtcache_lookup2+0x56
	in6_selectroute() at netbsd:in6_selectroute+0x184
	in6_selectsrc() at netbsd:in6_selectsrc+0x119
	udp6_output() at netbsd:udp6_output+0x25e
	udp6_send_wrapper() at netbsd:udp6_send_wrapper+0x8a
	sosend() at netbsd:sosend+0x7bf
	do_sys_sendmsg_so() at netbsd:do_sys_sendmsg_so+0x28e
	do_sys_sendmsg() at netbsd:do_sys_sendmsg+0x89
	sys_sendto() at netbsd:sys_sendto+0x5c
	syscall() at netbsd:syscall+0x1ed
	--- syscall (number 133) ---
	7f7ff790173a:

Reported by Paul Ripke
2018-11-06 04:27:41 +00:00
mlelstv 5fdff78694 Fix error path in ip6 source address selection.
in6_selectsrc previously returned a pointer to an ipv6 address,
the pointer was NULL in case of an error and is checked later
instead of the also returned error code. When in6_selectsrc was
changed to store the address into a buffer, the error code
was still ignored, but the buffer pointer was never set to NULL.

As a result send() to an ipv6 address on a system that isn't
configured for ipv6 no longer returns the expected EADDRAVAIL
but fails later in ip6_output with EOPNOTSUPP when trying to
send from an unspecified address. The wrong error code caused
BIND to log the unexpected errors.
2018-11-04 08:48:01 +00:00
ozaki-r cb8a413a5e Use rt_update framework on updating a rtentry 2018-10-30 05:56:02 +00:00
ozaki-r 973496ef18 Avoid double rt_replace_ifa on rtrequest1(RTM_ADD)
Some callers of rtrequest1(RTM_ADD) adjust rt_ifa of an rtentry created by
rtrequest1 that may change rt_ifa (in ifa_rtrequest) with another ifa that is
different from requested one.  It's wasteful and even worse introduces a race
condition.  rtrequest1 should just use a passed ifa as is if a caller hopes so.
2018-10-30 05:54:41 +00:00
ozaki-r 156ab71b7e Remove a leftover debug printf
Pointed out by hannken@
2018-10-25 02:40:45 +00:00
rin 336ead2267 Fix in_undefer_cksum() and in6_undefer_cksum().
The 4th argument for in[46]_cksum() should be length of L4 header +
L4 payload. The previous revisions are wrong

- for IPv4 when hdrlen != 0
- for IPv6 always

These functions are used only in net/if_loop.c and
arch/powerpc/booke/dev/pq3etsec.c under some special circumferences.
This should be why the bugs have not been found until today.

OK maxv
2018-09-19 07:54:11 +00:00
rjs d5ce3ccede Make it compile after change to non-variadic pr_input. 2018-09-15 13:33:15 +00:00
maxv 217d3e2e5c Remove netinet6/ipsec.h. 2018-09-06 19:07:13 +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
knakahara dc759cc87f fix: l2tp(4) cannot receive packets after reset session without reset tunnel. Pointed out by k-goda@IIJ
When the following operations are done after established session, the l2tp0
cannot receive packets until done deletetunnel && tunnel "src" "dst".
====================
ifconfig l2tp0 deletesession
ifconfig l2tp0 deletecookie
ifconfig l2tp0 session 200 100
====================

XXX pullup-8
2018-09-03 02:33:30 +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 735ddbc5b3 Retire EtherIP, we have L2TP instead. 2018-08-14 14:49:13 +00:00
ozaki-r 676214c5ed Don't call find_pfxlist_reachable_router, which may sleep, in a pserialize read section
Found by knakahara@
2018-08-14 01:10:58 +00:00
maxv 1eb85faf83 Remove the callback and localify. Same as IPv4. 2018-08-10 06:55:04 +00:00
maxv d22d69a653 Rename
ip6_undefer_csum  -> in6_undefer_cksum
	in6_delayed_cksum -> in6_undefer_cksum_tcpudp

The two previous names were inconsistent and misleading.

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

Same as IPv4.
2018-08-10 06:46:08 +00:00
kamil fb614f3716 Paper over Undefined Behavior in in6_control1()
Replace calculation of maxexpire (TIME_MAX) with a construct that triggers
UB with a one that uses implementation defined semantics.

No functional change intended.

An attempt to appease KUBSAn.

Detected with Kernel Undefined Behavior Sanitizer.

Reported by <Harry Pantazis>
2018-07-04 00:35:33 +00:00
knakahara a1b205bf0e sbappendaddr() is required any lock. Currently, softnet_lock is appropriate.
When rip_input() is called as inetsw[].pr_input, rip_iput() is always called
with holding softnet_lock, that is, in case of !defined(NET_MPSAFE) it is
acquired in ipintr(), otherwise(defined(NET_MPSAFE)) it is acquire in
PR_WRAP_INPUT macro.
However, some function calls rip_input() directly without holding softnet_lock.
That causes assertion failure in sbappendaddr().
rip6_input() and icmp6_rip6_input() are also required softnet_lock for the same
reason.
2018-06-21 10:37:49 +00:00
maxv ecc6d10cdd Rename
M_CSUM_DATA_IPv6_HL -> M_CSUM_DATA_IPv6_IPHL
	M_CSUM_DATA_IPv6_HL_SET -> M_CSUM_DATA_IPv6_SET

Reduces the diff against IPv4. Also, clarify the definitions.
2018-06-01 08:56:00 +00:00
ozaki-r 28cab72f3d Fix _rt_free via rtrequest(RTM_DELETE) hangs in rt_timer handlers
A rt_timer handler is passed a rtentry with an extra reference that avoids the
rtentry is accidentally released.  So rt_timer handers must release the reference
of a passed rtentry by themselves (but they didn't).
2018-06-01 07:13:35 +00:00
maxv 055894c4bc Remove dead code, we don't care. 2018-05-29 16:21:30 +00:00
prlw1 5c4807153d Mark in6m as used for non-DIAGNOSTIC builds. 2018-05-29 09:10:39 +00:00
ozaki-r 2980d4c808 Avoid double LIST_REMOVE which corrupts lists 2018-05-29 04:39:26 +00:00
ozaki-r d39540d653 Move LIST_REMOVE
mld_stoptimer releases in6_multilock temporarily, so we must LIST_REMOVE first.
2018-05-29 04:38:59 +00:00
ozaki-r 5e90b86ba2 Make a deletion of in6m in nd6_rtrequest atomic 2018-05-29 04:38:29 +00:00
ozaki-r 60862c9462 Make a refcount decrement and a removal from a list of an item atomic
in6m_refcount of an in6m can be incremented if the in6m is on the list
(if_multiaddrs) in in6_addmulti or mld_input.  So we must avoid such an
increment when we try to destroy an in6m.  To this end we must make
an in6m_refcount decrement and a removal of an in6m from if_multiaddrs
atomic.
2018-05-29 04:37:58 +00:00
ozaki-r 8e177fee51 Avoid NULL pointer dereference on imm->i6mm_maddr 2018-05-29 04:37:16 +00:00
ozaki-r 0c65aee4df Improve atomicity of in6_leavegroup and in6_delmulti 2018-05-29 04:36:47 +00:00
ozaki-r b0a3f08ae7 Release in6_multilock on callout_halt of mld_timeo to avoid a deadlock 2018-05-29 04:36:15 +00:00
ozaki-r 121af2983a Don't hold softnet_lock in mld_timeo
Then we can get rid of remaining abuses of mutex_owned(softnet_lock).
2018-05-29 04:35:28 +00:00
maxv ffafb66f54 Remove notyet, we've never had this. 2018-05-20 06:29:43 +00:00
maxv 9a39ca57f2 Style. 2018-05-19 08:22:58 +00:00
maxv a7f3f7dd09 Remove misleading comment. 2018-05-19 06:44:08 +00:00
maxv ae766c8de0 Add missing m_put_rcvif_psref. 2018-05-18 21:03:33 +00:00
maxv a9684b9a92 Fix the KASSERTs. It doesn't matter at all since the packet can't be this
big anyway, and there are many other places that have this kind of typo;
but still fix it, for the sake of closing PR/49834.
2018-05-17 12:07:48 +00:00
maxv a127c0ebdb Add KASSERTs, related to PR/39794. 2018-05-17 11:59:36 +00:00
maxv fbb9ed35f8 When reassembling IPv4/IPv6 packets, ensure each fragment has been subject
to the same IPsec processing. That is to say, that all fragments are ESP,
or AH, or AH+ESP, or none.

The reassembly mechanism can be used both on the wire and inside an IPsec
tunnel, so we need to make sure all fragments of a packet were received
on only one side.

Even though I haven't tried, I believe there are configurations where it
would be possible for an attacker to inject an unencrypted fragment into a
legitimate stream of already-decrypted-and-authenticated fragments.

Typically on IPsec gateways with ESP tunnels, where we can encapsulate
fragments (as opposed to the general case, where we fragment encapsulated
data).

Note, for the record: a funnier thing, under IPv4, would be to send a
zero-sized !MFF fragment at the head of the packet, and manage to trigger
an ICMP error; M_DECRYPTED gets lost by the reassembly, and ICMP will reply
with the packet in clear (not encrypted).
2018-05-15 19:16:38 +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
maxv 7e3f605c35 Dedup: introduce rip6_sbappendaddr. Same as IPv4. 2018-05-11 14:25:50 +00:00
roy 0cac5dca10 Increase the default size of some receive buffers from 8k to 16k.
This mitigates recent reports of socket overflow errors
and fixes PR bin/53247.
2018-05-11 09:43:59 +00:00
maxv 0be2ad1a12 Replace
m_copym(m, 0, M_COPYALL, M_DONTWAIT)
by
	m_copypacket(m, M_DONTWAIT)
when it is clear that we are copying a packet (that has M_PKTHDR) and not
a raw mbuf chain.
2018-05-09 06:35:10 +00:00
maxv 0c71ec6e1e Remove misleading comments. 2018-05-07 10:21:08 +00:00
maxv 04b61f509d Rename m_pkthdr_remove -> m_remove_pkthdr, to match the existing naming
convention, eg m_copy_pkthdr and m_move_pkthdr.
2018-05-03 07:25:49 +00:00
maxv 5d73803e75 Remove now unused tcpip.h includes. Some were already unused before. 2018-05-03 07:13:48 +00:00
maxv 9208f79f61 Remove net_osdep.h completely. 2018-05-03 06:41:30 +00:00
maxv 86ac125b49 Remove now unused net_osdep.h includes, the other BSDs did the same. 2018-05-01 07:21:39 +00:00
maxv d920327205 Remove unused and misleading argument from ipsec_set_policy. 2018-04-29 11:51:08 +00:00