Commit Graph

1896 Commits

Author SHA1 Message Date
kamil 5762fe1be2 Decorate struct in6_addr with the __packed attribute
This avoids undefined behavior when accessing misaligned pointers.

Detected by kUBSan.

Patch by Akul Pillai.
2019-05-28 03:56:46 +00:00
ozaki-r 6c6d1e4f71 Get rid of IFNET_LOCK for if_mcast_op to avoid a deadlock
The IFNET_LOCK was added to avoid data races on if_flags for IFF_ALLMULTI.
Unfortunatetly it caused a deadlock instead.  A known scenario causing a
deadlock is to occur the following two operations concurrently: (a) a removal of
an IP adddres assigned to an interface and (b) a manipulation of multicast
groups to the interface.  The resource dependency graph is like this:
  softnet_lock => IFNET_LOCK => psref_target_destroy => softint => softnet_lock

Thanks to the previous commit that avoids data races on if_flags for
IFF_ALLMULTI by another approach, we can remove IFNET_LOCK and defuse the
deadlock.

PR kern/54189
2019-05-15 02:59:18 +00:00
ozaki-r 6d8eb4f9d2 Count packets dropped by pfil 2019-05-13 07:47:59 +00:00
christos 45108122b9 print the name of the interface that was disabled. 2019-05-13 02:03:07 +00:00
roy 2e9156b7e4 Introduce rt_addrmsg_src which adds RTA_AUTHOR to the message.
Use this when we notify userland of a duplicate address
and set RTA_AUTHOR to the hardware address of the sender.

While here, match the logging diagnostic of INET6 to the simpler one
of INET so it's consistent.
2019-04-29 16:12:30 +00:00
roy 4af7afb834 rtsock: Route address message simplification
Rename rt_newaddrmsg to rt_addrmsg_rt.
Add rt_addrmsg which drops the error and route arguments which are only
needed by one caller.
2019-04-29 11:57:22 +00:00
maxv 2d90f583ce Fix small read overflow; harmless, because since I removed RH0, the memory
access on IPV6_RTHDR that would normally be illegal is not needed, and GCC
automatically removes it.
2019-04-03 19:23:38 +00:00
msaitoh b1b254e088 Fix typos in comment:
- s/paylaod/payload/
- s/dstination/destination/
2019-03-19 13:38:53 +00:00
msaitoh ad2fa80c12 s/pakcet/packet/ in comment. 2019-03-18 11:38:03 +00:00
maxv fa4f0f3678 Fix the order in udp6_attach: soreserve should be called before
in6_pcballoc, otherwise if it fails there is still a PCB attached, and
we hit a KASSERT in socreate. In !DIAGNOSTIC this would have caused a
memory leak.

By the way I find the splsoftnet highly suspicious, in6_pcballoc already
does that.

Triggered by SyzKaller.

Reported-by: syzbot+7bace612ca3cc3e124f8@syzkaller.appspotmail.com
2019-02-25 07:31:32 +00:00
maxv d020c71c0c RIP6, CAN, SCTP and SCTP6 lack a length check in their _send() functions.
Fix RIP6 and CAN, add a big XXX in the SCTP ones.

Found by KASAN, triggered by SyzKaller.

Reported-by: syzbot+0b9692ae0f49f93b7dc7@syzkaller.appspotmail.com
2019-02-25 06:49:44 +00:00
maxv d26f60da72 RIP, RIP6, DDP, SCTP and SCTP6 lack a length check in their _connect()
functions. Fix the first three, and add a big XXX in the SCTP ones.

Found by KASAN, triggered by SyzKaller.

Reported-by: syzbot+9eaf98dad6ca738c250d@syzkaller.appspotmail.com
2019-02-24 07:20:33 +00:00
mrg c9d1af0f71 adjust fallthru comments to appease gcc7. 2019-02-05 04:48:47 +00:00
mrg 3035d148fb rework the #ifdef IPSEC code to not use fallthru.
same number of lines with more local context.
2019-02-04 10:48:46 +00:00
martin dc194ae5f0 Fix memory leaks pointed out by Ilja Van Sprundel: all
sendoob() functions are expted to free both passed
mbuf chains.
2019-01-28 12:53:01 +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
maxv e0e84df697 Fix bug, should be ip6_protox[]. 2019-01-14 18:51:15 +00:00
maxv b9e11ce70c Remove unused arguments. 2018-12-27 16:59:17 +00:00
maxv 5b040abec8 Replace M_ALIGN and MH_ALIGN by m_align. 2018-12-22 14:28:56 +00:00
maxv 7971121357 Replace: M_COPY_PKTHDR -> m_copy_pkthdr. No functional change, since the
former is a macro to the latter.
2018-12-22 14:07:53 +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
roy 4be2a728d1 netinet6: only flush prefixes and routers for the given interface.
Unless it's lo0, where we then flush the lot.
The maintains the status-quo with ndp(8) and allows dhcpcd(8) to at least
try and work with kernel RA on one interface and dhcpcd on another.
2018-12-16 08:54:58 +00:00
roy f609a819ed inet6: discard any received NA with a LL address we own
This matches ARP behaviour.
2018-12-13 10:27:51 +00:00
rin 7f120f6563 Simplify logic in ip{,6}_output().
Now, we have M_CSUM_TSOv[46] bit in ifp->if_csum_flags_tx when
TSO[46] is enabled for the interface. So we can simply check
whether TSO[46] is required in a packet but missing in the
interface by (sw_csum & M_CSUM_TSOv[46]).

Note that this is a very rare case where TSO[46] is suddenly
turned off during a packet passing b/w TCP and IP.

part of PR kern/53562
OK msaitoh
2018-12-12 01:53:52 +00:00
rin 1cfdd1e3e5 PR kern/53562
Add ether_sw_offload_[tr]x: handle TX/RX offload options in software.
Since this violates separation b/w L2 and L3/L4, new files are added
rather than having the routines in sys/net/if_ethersubr.c.

OK msaitoh thorpej
2018-12-12 01:40:20 +00:00
christos 3b7148fe8e need <sys/endian.h> (or arpa/inet.h) for ntohl() used in macros. 2018-12-10 16:28:52 +00:00
roy 9aebb96254 inet6: match NS nonce to any interface
This allows the same address to exist on many interfaces on the same
prefix, matching the inet behaviour.
2018-12-07 14:47:24 +00:00
roy 1ef19928bd inet6: remove needless ifa_release. 2018-12-04 21:16:54 +00:00
roy dff9676926 inet6: use one function for nd6_dad_input
Having different ones for NA and NS is a bit wasteful.
2018-12-04 21:01:48 +00:00
roy 7d7b3bbea7 inet6: simplify NA DaD checking 2018-12-04 20:46:56 +00:00
roy e4ac7437f9 inet6: remove unused dad ns/na counters
The current DaD code triggers when either an NS or NA is directly
received, so the counters themselves do nothing of use.
2018-12-04 12:23:43 +00:00
ozaki-r 74109b2db3 Don't validate the source address of forwarding IPv6 packets (same as IPv4) 2018-11-29 10:02:52 +00:00
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