Commit Graph

215 Commits

Author SHA1 Message Date
maxv
624f3f7406 Add more checks in ip6_pullexthdr, to prevent a panic in m_copydata. The
Rip6 entry point could see a garbage Hop6 option.

Not a big issue, since it's a clean panic only triggerable if the socket
has the IN6P_DSTOPTS/IN6P_RTHDR option.

Reported-by: syzbot+3b07b3511b4ceb8bf1e2@syzkaller.appspotmail.com
2019-11-12 08:11:55 +00:00
ozaki-r
5fd0d56def in6: reset the temporary address timer on a change of the interval period 2019-10-18 04:33:53 +00:00
ozaki-r
367904e3e7 Validate ip6_temp_preferred_lifetime (net.inet6.ip6.temppltime) on a change
ip6_temp_preferred_lifetime is used to calculate an interval period to
regenerate temporary addresse by
  TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE - DESYNC_FACTOR
as per RFC 3041 3.5.  So it must be greater than (REGEN_ADVANCE +
DESYNC_FACTOR), otherwise it will be negative and go wrong, for example
KASSERT(to_ticks >= 0) in callout_schedule_locked fails.
2019-10-16 07:41:28 +00:00
ozaki-r
e32ddc921e Reorganize in6_tmpaddrtimer stuffs
- Move the related functions to where in6_tmpaddrtimer_ch exists
- Hide global variable in6_tmpaddrtimer_ch
- Rename ip6_init2 to in6_tmpaddrtimer_init
- Reduce callers of callout_reset
- Use callout_schedule
2019-10-16 07:40:40 +00:00
ozaki-r
2bcf5b2995 Apply some missing changes lost on the previous commit 2019-09-19 05:31:50 +00:00
ozaki-r
e524fb36a1 Avoid having a rtcache directly in a percpu storage
percpu(9) has a certain memory storage for each CPU and provides it by the piece
to users.  If the storages went short, percpu(9) enlarges them by allocating new
larger memory areas, replacing old ones with them and destroying the old ones.
A percpu storage referenced by a pointer gotten via percpu_getref can be
destroyed by the mechanism after a running thread sleeps even if percpu_putref
has not been called.

Using rtcache, i.e., packet processing, typically involves sleepable operations
such as rwlock so we must avoid dereferencing a rtcache that is directly stored
in a percpu storage during packet processing.  Address this situation by having
just a pointer to a rtcache in a percpu storage instead.

Reviewed by knakahara@ and yamaguchi@
2019-09-19 04:08:29 +00:00
bouyer
183863f5f8 Packet filters can return an mbuf chain with fragmented headers, so
m_pullup() it if needed and remove the KASSERT()s.
2019-09-15 21:00:15 +00:00
ozaki-r
6d8eb4f9d2 Count packets dropped by pfil 2019-05-13 07:47:59 +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
5c98710094 Remove the 't' argument from m_tag_find(). 2018-11-15 10:23:55 +00:00
maxv
a7f3f7dd09 Remove misleading comment. 2018-05-19 06:44:08 +00:00
maxv
a127c0ebdb Add KASSERTs, related to PR/39794. 2018-05-17 11:59:36 +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
86ac125b49 Remove now unused net_osdep.h includes, the other BSDs did the same. 2018-05-01 07:21:39 +00:00
maxv
de9cefcf44 Remove unused mbuf argument from sbsavetimestamp. 2018-04-26 19:22:17 +00:00
maxv
1cf079b88f Move the address checks into one function, ip6_badaddr(). In this function,
reinstate the "IPv4-compatible IPv6 addresses" check; these addresses are
deprecated by RFC4291 (2006).
2018-04-26 07:01:38 +00:00
maxv
ff01fbc78a Remove useless DIAGNOSTIC block, the caller already ensures the
assumptions, and here we're not doing anything (it should be a panic
rather than a printf).
2018-04-15 08:31:18 +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
cc670cf1d8 Add comment about IPsec. 2018-04-11 07:55:19 +00:00
roy
38d01a8d5e Sprinkle more soroverflow(). 2018-03-21 14:23:54 +00:00
maxv
f50e60a23f Perform the IP (src/dst) checks _before_ calling the packet filter, because
if the filter has a "return-icmp" rule it may call icmp6_error with an src
field that was not entirely validated.
2018-03-06 17:39:36 +00:00
ozaki-r
ef58cf2ca2 Avoid a deadlock between softnet_lock and IFNET_LOCK
A deadlock occurs because there is a violation of the rule of lock ordering;
softnet_lock is held with hodling IFNET_LOCK, which violates the rule.
To avoid the deadlock, replace softnet_lock in in_control and in6_control
with KERNEL_LOCK.

We also need to add some KERNEL_LOCKs to protect the network stack surely.
This is required, for example, for PR kern/51356.

Fix PR kern/53043
2018-02-24 07:37:08 +00:00
maxv
f574a1384a Re-make ip6_nexthdr global, it will be used in soon-to-be-added code... 2018-02-14 05:29:39 +00:00
maxv
42fdf13228 Replace bcopy -> memcpy when it is obvious that the areas don't overlap.
Rearrange ip6_splithdr() for clarity.
2018-02-12 12:52:12 +00:00
maxv
f93abcea1a Remove dead code. 2018-02-09 18:31:52 +00:00
maxv
4e9bde34d6 Style, localify, remove dead code, and fix typos. No functional change. 2018-01-30 15:54:02 +00:00
maxv
5b47e99add Kick nested fragments. 2018-01-30 15:35:31 +00:00
maxv
71ad96023a Fix a buffer overflow in ip6_get_prevhdr. Doing
mtod(m, char *) + len

is wrong, an option is allowed to be located in another mbuf of the chain.
If the offset of an option within the chain is bigger than the length of
the first mbuf in that chain, we are reading/writing one byte of packet-
controlled data beyond the end of the first mbuf.

The length of this first mbuf depends on the layout the network driver
chose. In the most difficult case, it will allocate a 2KB cluster, which
is bigger than the Ethernet MTU.

But there is at least one way of exploiting this case: by sending a
special combination of nested IPv6 fragments, the packet can control a
good bunch of 'len'. By luck, the memory pool containing clusters does not
embed the pool header in front of the items, so it is not straightforward
to predict what is located at 'mtod(m, char *) + len'.

However, by sending offending fragments in a loop, it is possible to
crash the kernel - at some point we will hit important data structures.

As far as I can tell, PF protects against this difficult case, because
it kicks nested fragments. NPF does not protect against this. IPF I don't
know.

Then there are the more easy cases, if the MTU is bigger than a cluster,
or if the network driver did not allocate a cluster, or perhaps if the
fragments are received via a tunnel; I haven't investigated these cases.

Change ip6_get_prevhdr so that it returns an offset in the chain, and
always use IP6_EXTHDR_GET to get a writable pointer. IP6_EXTHDR_GET
leaves M_PKTHDR untouched.

This place is still fragile.
2018-01-30 14:49:25 +00:00
maxv
6f5024f576 Start cleaning up ip6_input.c. Several pieces of code have evolved but
their neighboring comments were not updated. So update them, and remove
code that has been disabled for years (it has no use anyway).
2018-01-29 10:57:13 +00:00
kre
814f99dcb6 Attempt to restore v6 networking. Not 100% certain that these
changes are all that is needed, but they're certainly a big part of it
(especially the ip6_input.c change.)
2017-11-25 13:18:02 +00:00
roy
fbb6c0f8fa Allow local communication over DETACHED addresses.
Allow binding to DETACHED or TENTATIVE addresses as we deny
sending upstream from them anyway.
Prefer non DETACHED or TENTATIVE addresses.
2017-11-24 14:03:25 +00:00
ozaki-r
cead3b8854 Provide macros for softnet_lock and KERNEL_LOCK hiding NET_MPSAFE switch
It reduces C&P codes such as "#ifndef NET_MPSAFE KERNEL_LOCK(1, NULL); ..."
scattered all over the source code and makes it easy to identify remaining
KERNEL_LOCK and/or softnet_lock that are held even if NET_MPSAFE.

No functional change
2017-11-17 07:37:12 +00:00
ozaki-r
bbda3ec76e Take softnet_lock on pr_input properly if NET_MPSAFE
Currently softnet_lock is taken unnecessarily in some cases, e.g.,
icmp_input and encap4_input from ip_input, or not taken even if needed,
e.g., udp_input and tcp_input from ipsec4_common_input_cb. Fix them.

NFC if NET_MPSAFE is disabled (default).
2017-09-27 10:05:04 +00:00
ozaki-r
e1c9808fed Don't acquire global locks for IPsec if NET_MPSAFE
Note that the change is just to make testing easy and IPsec isn't MP-safe yet.
2017-07-27 06:59:28 +00:00
christos
1922edaa5b remove unnecessary casts; use sizeof(var) instead of sizeof(type). 2017-07-06 17:14:35 +00:00
christos
2b50acc97b Merge the two copies SO_TIMESTAMP/SO_OTIMESTAMP processing to a single
function, and add a SOOPT_TIMESTAMP define reducing compat pollution from
5 places to 1.
2017-07-06 17:08:57 +00:00
chs
fd34ea77eb remove checks for failure after memory allocation calls that cannot fail:
kmem_alloc() with KM_SLEEP
  kmem_zalloc() with KM_SLEEP
  percpu_alloc()
  pserialize_create()
  psref_class_create()

all of these paths include an assertion that the allocation has not failed,
so callers should not assert that again.
2017-06-01 02:45:05 +00:00
ozaki-r
07a4b673ca Replace DIAGNOSTIC + panic with KASSERT 2017-03-14 04:25:10 +00:00
ozaki-r
ef30413ffd Provide in6_multi_group
Use it when checking if we belong to the group, instead of in6_lookup_multi.

No functional change.
2017-03-01 08:54:12 +00:00
ozaki-r
40914f019e Stop using useless IN6_*_MULTI macros 2017-02-22 07:46:00 +00:00
ozaki-r
1f29833ec6 Sweep unnecessary malloc.h inclusions 2017-02-21 03:59:31 +00:00
christos
35561f6b22 ip6_sprintf -> IN6_PRINT so that we pass the size. 2017-01-16 15:44:46 +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
4c25fb2f83 Add rtcache_unref to release points of rtentry stemming from rtcache
In the MP-safe world, a rtentry stemming from a rtcache can be freed at any
points. So we need to protect rtentries somehow say by reference couting or
passive references. Regardless of the method, we need to call some release
function of a rtentry after using it.

The change adds a new function rtcache_unref to release a rtentry. At this
point, this function does nothing because for now we don't add a reference
to a rtentry when we get one from a rtcache. We will add something useful
in a further commit.

This change is a part of changes for MP-safe routing table. It is separated
to avoid one big change that makes difficult to debug by bisecting.
2016-12-08 05:16:33 +00:00
ozaki-r
d5dc0960bb Reduce the number of return points
No functional change.
2016-11-01 10:32:57 +00:00
ozaki-r
3be3142886 Don't hold global locks if NET_MPSAFE is enabled
If NET_MPSAFE is enabled, don't hold KERNEL_LOCK and softnet_lock in
part of the network stack such as IP forwarding paths. The aim of the
change is to make it easy to test the network stack without the locks
and reduce our local diffs.

By default (i.e., if NET_MPSAFE isn't enabled), the locks are held
as they used to be.

Reviewed by knakahara@
2016-10-18 07:30:30 +00:00
roy
3e6930820d Disallow input to detached addresses because they are not yet valid. 2016-09-07 15:41:44 +00:00
ozaki-r
543e39c0d3 Make ipforward_rt and ip6_forward_rt percpu
Sharing one rtcache between CPUs is just a bad idea.

Reviewed by knakahara@
2016-08-31 09:14:47 +00:00
knakahara
48235e8230 ip6flow refactor like ipflow.
- move ip6flow sysctls into ip6_flow.c like ip_flow.c:r1.64
    - build ip6_flow.c only if GATEWAY kernel option is enabled
2016-08-02 04:50:16 +00:00