linux/drivers/net/ethernet/intel/i40e
Björn Töpel 75aab4e10a i40e: avoid premature Rx buffer reuse
The page recycle code, incorrectly, relied on that a page fragment
could not be freed inside xdp_do_redirect(). This assumption leads to
that page fragments that are used by the stack/XDP redirect can be
reused and overwritten.

To avoid this, store the page count prior invoking xdp_do_redirect().

Longer explanation:

Intel NICs have a recycle mechanism. The main idea is that a page is
split into two parts. One part is owned by the driver, one part might
be owned by someone else, such as the stack.

t0: Page is allocated, and put on the Rx ring
              +---------------
used by NIC ->| upper buffer
(rx_buffer)   +---------------
              | lower buffer
              +---------------
  page count  == USHRT_MAX
  rx_buffer->pagecnt_bias == USHRT_MAX

t1: Buffer is received, and passed to the stack (e.g.)
              +---------------
              | upper buff (skb)
              +---------------
used by NIC ->| lower buffer
(rx_buffer)   +---------------
  page count  == USHRT_MAX
  rx_buffer->pagecnt_bias == USHRT_MAX - 1

t2: Buffer is received, and redirected
              +---------------
              | upper buff (skb)
              +---------------
used by NIC ->| lower buffer
(rx_buffer)   +---------------

Now, prior calling xdp_do_redirect():
  page count  == USHRT_MAX
  rx_buffer->pagecnt_bias == USHRT_MAX - 2

This means that buffer *cannot* be flipped/reused, because the skb is
still using it.

The problem arises when xdp_do_redirect() actually frees the
segment. Then we get:
  page count  == USHRT_MAX - 1
  rx_buffer->pagecnt_bias == USHRT_MAX - 2

From a recycle perspective, the buffer can be flipped and reused,
which means that the skb data area is passed to the Rx HW ring!

To work around this, the page count is stored prior calling
xdp_do_redirect().

Note that this is not optimal, since the NIC could actually reuse the
"lower buffer" again. However, then we need to track whether
XDP_REDIRECT consumed the buffer or not.

Fixes: d9314c474d ("i40e: add support for XDP_REDIRECT")
Reported-and-analyzed-by: Li RongQing <lirongqing@baidu.com>
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
Tested-by: George Kuruvinakunnel <george.kuruvinakunnel@intel.com>
Signed-off-by: Tony Nguyen <anthony.l.nguyen@intel.com>
2020-12-09 15:26:58 -08:00
..
i40e_adminq_cmd.h i40e: Allow changing FEC settings on X722 if supported by FW 2020-10-13 19:44:01 -07:00
i40e_adminq.c i40e: Allow changing FEC settings on X722 if supported by FW 2020-10-13 19:44:01 -07:00
i40e_adminq.h intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_alloc.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
i40e_client.c intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_common.c intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_dcb_nl.c i40e/i40evf: cleanup incorrect function doxygen comments 2018-04-30 09:09:04 -07:00
i40e_dcb.c i40e: Fix for persistent lldp support 2019-10-25 13:38:19 -07:00
i40e_dcb.h i40e: remove unused defines 2020-06-25 22:25:13 -07:00
i40e_ddp.c i40e: Implement DDP support in i40e driver 2019-04-16 15:10:21 -07:00
i40e_debugfs.c i40e: use 16B HW descriptors instead of 32B 2020-09-14 09:45:35 -07:00
i40e_devids.h i40e: Add support for 5Gbps cards 2020-06-25 22:25:13 -07:00
i40e_diag.c net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
i40e_diag.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
i40e_ethtool.c i40e: Allow changing FEC settings on X722 if supported by FW 2020-10-13 19:44:01 -07:00
i40e_hmc.c i40e: Implement debug macro hw_dbg using dev_dbg 2019-09-09 11:22:20 -07:00
i40e_hmc.h i40e: remove unused defines 2020-06-25 22:25:13 -07:00
i40e_lan_hmc.c treewide: Use sizeof_field() macro 2019-12-09 10:36:44 -08:00
i40e_lan_hmc.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
i40e_main.c i40e: Fix removing driver while bare-metal VFs pass traffic 2020-11-23 16:52:59 -08:00
i40e_nvm.c i40e: Fix for persistent lldp support 2019-10-25 13:38:19 -07:00
i40e_osdep.h i40e: remove unused defines 2020-06-25 22:25:13 -07:00
i40e_prototype.h i40e: Make i40e_shutdown_adminq() return void 2020-05-28 20:19:47 -07:00
i40e_ptp.c intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_register.h i40e: detect and log info about pre-recovery mode 2020-06-25 22:25:13 -07:00
i40e_status.h net: intel: Cleanup the copyright/license headers 2018-04-27 14:00:04 -04:00
i40e_trace.h intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_txrx_common.h intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_txrx.c i40e: avoid premature Rx buffer reuse 2020-12-09 15:26:58 -08:00
i40e_txrx.h intel-ethernet: clean up W=1 warnings in kdoc 2020-09-25 16:28:59 -07:00
i40e_type.h i40e: Allow changing FEC settings on X722 if supported by FW 2020-10-13 19:44:01 -07:00
i40e_virtchnl_pf.c i40e: Fix removing driver while bare-metal VFs pass traffic 2020-11-23 16:52:59 -08:00
i40e_virtchnl_pf.h i40e: remove unused defines 2020-06-25 22:25:13 -07:00
i40e_xsk.c i40e, xsk: uninitialized variable in i40e_clean_rx_irq_zc() 2020-11-10 15:03:14 -08:00
i40e_xsk.h xsk: i40e: ice: ixgbe: mlx5: Pass buffer pool to driver instead of umem 2020-08-31 21:15:03 +02:00
i40e.h i40e: Fix removing driver while bare-metal VFs pass traffic 2020-11-23 16:52:59 -08:00
Makefile i40e: Implement DDP support in i40e driver 2019-04-16 15:10:21 -07:00