freebsd-dev/sys/net80211
John Baldwin fb3bc59600 Restructure mbuf send tags to provide stronger guarantees.
- Perform ifp mismatch checks (to determine if a send tag is allocated
  for a different ifp than the one the packet is being output on), in
  ip_output() and ip6_output().  This avoids sending packets with send
  tags to ifnet drivers that don't support send tags.

  Since we are now checking for ifp mismatches before invoking
  if_output, we can now try to allocate a new tag before invoking
  if_output sending the original packet on the new tag if allocation
  succeeds.

  To avoid code duplication for the fragment and unfragmented cases,
  add ip_output_send() and ip6_output_send() as wrappers around
  if_output and nd6_output_ifp, respectively.  All of the logic for
  setting send tags and dealing with send tag-related errors is done
  in these wrapper functions.

  For pseudo interfaces that wrap other network interfaces (vlan and
  lagg), wrapper send tags are now allocated so that ip*_output see
  the wrapper ifp as the ifp in the send tag.  The if_transmit
  routines rewrite the send tags after performing an ifp mismatch
  check.  If an ifp mismatch is detected, the transmit routines fail
  with EAGAIN.

- To provide clearer life cycle management of send tags, especially
  in the presence of vlan and lagg wrapper tags, add a reference count
  to send tags managed via m_snd_tag_ref() and m_snd_tag_rele().
  Provide a helper function (m_snd_tag_init()) for use by drivers
  supporting send tags.  m_snd_tag_init() takes care of the if_ref
  on the ifp meaning that code alloating send tags via if_snd_tag_alloc
  no longer has to manage that manually.  Similarly, m_snd_tag_rele
  drops the refcount on the ifp after invoking if_snd_tag_free when
  the last reference to a send tag is dropped.

  This also closes use after free races if there are pending packets in
  driver tx rings after the socket is closed (e.g. from tcpdrop).

  In order for m_free to work reliably, add a new CSUM_SND_TAG flag in
  csum_flags to indicate 'snd_tag' is set (rather than 'rcvif').
  Drivers now also check this flag instead of checking snd_tag against
  NULL.  This avoids false positive matches when a forwarded packet
  has a non-NULL rcvif that was treated as a send tag.

- cxgbe was relying on snd_tag_free being called when the inp was
  detached so that it could kick the firmware to flush any pending
  work on the flow.  This is because the driver doesn't require ACK
  messages from the firmware for every request, but instead does a
  kind of manual interrupt coalescing by only setting a flag to
  request a completion on a subset of requests.  If all of the
  in-flight requests don't have the flag when the tag is detached from
  the inp, the flow might never return the credits.  The current
  snd_tag_free command issues a flush command to force the credits to
  return.  However, the credit return is what also frees the mbufs,
  and since those mbufs now hold references on the tag, this meant
  that snd_tag_free would never be called.

  To fix, explicitly drop the mbuf's reference on the snd tag when the
  mbuf is queued in the firmware work queue.  This means that once the
  inp's reference on the tag goes away and all in-flight mbufs have
  been queued to the firmware, tag's refcount will drop to zero and
  snd_tag_free will kick in and send the flush request.  Note that we
  need to avoid doing this in the middle of ethofld_tx(), so the
  driver grabs a temporary reference on the tag around that loop to
  defer the free to the end of the function in case it sends the last
  mbuf to the queue after the inp has dropped its reference on the
  tag.

- mlx5 preallocates send tags and was using the ifp pointer even when
  the send tag wasn't in use.  Explicitly use the ifp from other data
  structures instead.

- Sprinkle some assertions in various places to assert that received
  packets don't have a send tag, and that other places that overwrite
  rcvif (e.g. 802.11 transmit) don't clobber a send tag pointer.

Reviewed by:	gallatin, hselasky, rgrimes, ae
Sponsored by:	Netflix
Differential Revision:	https://reviews.freebsd.org/D20117
2019-05-24 22:30:40 +00:00
..
_ieee80211.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_acl.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_action.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_action.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_adhoc.c net80211(4): hide casts for 'i_seq' field offset calculation inside 2019-02-10 23:58:56 +00:00
ieee80211_adhoc.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ageq.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ageq.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_alq.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_alq.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_amrr.c net80211: reuse TICKS_2_MSEC / MSEC_2_TICKS macros from sys/time.h 2019-01-25 01:05:18 +00:00
ieee80211_amrr.h
ieee80211_crypto_ccmp.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_crypto_none.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_crypto_tkip.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_crypto_wep.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_crypto.c net80211: drop m_pullup call from ieee80211_crypto_decap. 2019-01-19 16:04:26 +00:00
ieee80211_crypto.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ddb.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_dfs.c Do not acquire IEEE80211_LOCK twice in cac_timeout(); reuse 2019-02-02 16:21:23 +00:00
ieee80211_dfs.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_freebsd.c Drop unused M_80211_COM malloc(9) type. 2019-02-02 16:23:45 +00:00
ieee80211_freebsd.h net80211: reuse TICKS_2_MSEC / MSEC_2_TICKS macros from sys/time.h 2019-01-25 01:05:18 +00:00
ieee80211_hostap.c net80211(4): hide casts for 'i_seq' field offset calculation inside 2019-02-10 23:58:56 +00:00
ieee80211_hostap.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ht.c net80211: correct check for SMPS node flags updates 2019-03-18 02:40:22 +00:00
ieee80211_ht.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_hwmp.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
ieee80211_input.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_input.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ioctl.c net80211(4): validate supplied roam:rate values from ifconfig(8) 2019-02-06 13:01:21 +00:00
ieee80211_ioctl.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_mesh.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
ieee80211_mesh.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_monitor.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_monitor.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_node.c net80211: fix out-of-bounds read in ieee80211_amrr(9). 2018-12-19 03:08:10 +00:00
ieee80211_node.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_output.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
ieee80211_phy.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_phy.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_power.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_power.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_proto.c net80211(4): do not setup Tx parameters for unsupported modes. 2019-02-03 04:31:50 +00:00
ieee80211_proto.h net80211(4): hide casts for 'i_seq' field offset calculation inside 2019-02-10 23:58:56 +00:00
ieee80211_radiotap.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_radiotap.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ratectl_none.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ratectl.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_ratectl.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_regdomain.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_regdomain.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_rssadapt.c net80211: reuse TICKS_2_MSEC / MSEC_2_TICKS macros from sys/time.h 2019-01-25 01:05:18 +00:00
ieee80211_rssadapt.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_scan_sta.c net80211(4): fix rate check when 'roaming' ifconfig(8) option is set to 'auto' 2019-02-03 02:32:13 +00:00
ieee80211_scan_sw.c
ieee80211_scan_sw.h
ieee80211_scan.c net80211(4): do not setup roaming parameters for unsupported modes. 2019-02-03 01:32:02 +00:00
ieee80211_scan.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_sta.c net80211(4): hide casts for 'i_seq' field offset calculation inside 2019-02-10 23:58:56 +00:00
ieee80211_sta.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_superg.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_superg.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_tdma.c net80211(4): do not setup Tx parameters for unsupported modes. 2019-02-03 04:31:50 +00:00
ieee80211_tdma.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_var.h Remove 2GHz channel list copies from wireless drivers. 2019-01-26 17:00:55 +00:00
ieee80211_vht.c
ieee80211_vht.h
ieee80211_wds.c Restructure mbuf send tags to provide stronger guarantees. 2019-05-24 22:30:40 +00:00
ieee80211_wds.h sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211_wps.h [ifconfig] Print more WPS attributes in verbose "list scan" output 2019-01-20 00:45:44 +00:00
ieee80211_xauth.c sys: general adoption of SPDX licensing ID tags. 2017-11-27 15:23:17 +00:00
ieee80211.c Remove 2GHz channel list copies from wireless drivers. 2019-01-26 17:00:55 +00:00
ieee80211.h [ifconfig] Print more WPS attributes in verbose "list scan" output 2019-01-20 00:45:44 +00:00