netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Jesper Dangaard Brouer" <brouer@redhat.com>,
	"Mao Wenan" <maowenan@huawei.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Toshiaki Makita" <toshiaki.makita1@gmail.com>,
	"Toke Høiland-Jørgensen" <toke@redhat.com>,
	"Sasha Levin" <sashal@kernel.org>,
	netdev@vger.kernel.org, bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 126/175] veth: Adjust hard_start offset on redirect XDP frames
Date: Mon,  8 Jun 2020 19:17:59 -0400	[thread overview]
Message-ID: <20200608231848.3366970-126-sashal@kernel.org> (raw)
In-Reply-To: <20200608231848.3366970-1-sashal@kernel.org>

From: Jesper Dangaard Brouer <brouer@redhat.com>

[ Upstream commit 5c8572251fabc5bb49fd623c064e95a9daf6a3e3 ]

When native XDP redirect into a veth device, the frame arrives in the
xdp_frame structure. It is then processed in veth_xdp_rcv_one(),
which can run a new XDP bpf_prog on the packet. Doing so requires
converting xdp_frame to xdp_buff, but the tricky part is that
xdp_frame memory area is located in the top (data_hard_start) memory
area that xdp_buff will point into.

The current code tried to protect the xdp_frame area, by assigning
xdp_buff.data_hard_start past this memory. This results in 32 bytes
less headroom to expand into via BPF-helper bpf_xdp_adjust_head().

This protect step is actually not needed, because BPF-helper
bpf_xdp_adjust_head() already reserve this area, and don't allow
BPF-prog to expand into it. Thus, it is safe to point data_hard_start
directly at xdp_frame memory area.

Fixes: 9fc8d518d9d5 ("veth: Handle xdp_frames in xdp napi ring")
Reported-by: Mao Wenan <maowenan@huawei.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
Acked-by: Toke Høiland-Jørgensen <toke@redhat.com>
Link: https://lore.kernel.org/bpf/158945338331.97035.5923525383710752178.stgit@firesoul
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/net/veth.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 9f3c839f9e5f..88cfd63f08a6 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -510,13 +510,15 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 					struct veth_xdp_tx_bq *bq)
 {
 	void *hard_start = frame->data - frame->headroom;
-	void *head = hard_start - sizeof(struct xdp_frame);
 	int len = frame->len, delta = 0;
 	struct xdp_frame orig_frame;
 	struct bpf_prog *xdp_prog;
 	unsigned int headroom;
 	struct sk_buff *skb;
 
+	/* bpf_xdp_adjust_head() assures BPF cannot access xdp_frame area */
+	hard_start -= sizeof(struct xdp_frame);
+
 	rcu_read_lock();
 	xdp_prog = rcu_dereference(rq->xdp_prog);
 	if (likely(xdp_prog)) {
@@ -538,7 +540,6 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 			break;
 		case XDP_TX:
 			orig_frame = *frame;
-			xdp.data_hard_start = head;
 			xdp.rxq->mem = frame->mem;
 			if (unlikely(veth_xdp_tx(rq->dev, &xdp, bq) < 0)) {
 				trace_xdp_exception(rq->dev, xdp_prog, act);
@@ -550,7 +551,6 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 			goto xdp_xmit;
 		case XDP_REDIRECT:
 			orig_frame = *frame;
-			xdp.data_hard_start = head;
 			xdp.rxq->mem = frame->mem;
 			if (xdp_do_redirect(rq->dev, &xdp, xdp_prog)) {
 				frame = &orig_frame;
@@ -572,7 +572,7 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq,
 	rcu_read_unlock();
 
 	headroom = sizeof(struct xdp_frame) + frame->headroom - delta;
-	skb = veth_build_skb(head, headroom, len, 0);
+	skb = veth_build_skb(hard_start, headroom, len, 0);
 	if (!skb) {
 		xdp_return_frame(frame);
 		goto err;
-- 
2.25.1


  parent reply	other threads:[~2020-06-09  0:04 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200608231848.3366970-1-sashal@kernel.org>
2020-06-08 23:15 ` [PATCH AUTOSEL 5.4 002/175] ath10k: Fix the race condition in firmware dump work queue Sasha Levin
2020-06-08 23:15 ` [PATCH AUTOSEL 5.4 003/175] ath9x: Fix stack-out-of-bounds Write in ath9k_hif_usb_rx_cb Sasha Levin
2020-06-08 23:15 ` [PATCH AUTOSEL 5.4 004/175] ath9k: Fix use-after-free Write in ath9k_htc_rx_msg Sasha Levin
2020-06-08 23:15 ` [PATCH AUTOSEL 5.4 005/175] ath9k: Fix use-after-free Read in htc_connect_service Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 016/175] libbpf: Fix memory leak and possible double-free in hashmap__clear Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 020/175] net: atlantic: make hw_get_regs optional Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 021/175] net: ena: fix error returning in ena_com_get_hash_function() Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 023/175] ath10k: remove the max_sched_scan_reqs value Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 026/175] rtw88: fix an issue about leak system resources Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 035/175] ixgbe: Fix XDP redirect on archs with PAGE_SIZE above 4K Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 038/175] Bluetooth: Add SCO fallback for invalid LMP parameters error Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 051/175] batman-adv: Revert "disable ethtool link speed detection when auto negotiation off" Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 052/175] ice: Fix memory leak Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 053/175] ice: Fix for memory leaks and modify ICE_FREE_CQ_BUFS Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 058/175] net: vmxnet3: fix possible buffer overflow caused by bad DMA value in vmxnet3_get_rss() Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 059/175] tun: correct header offsets in napi frags mode Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 062/175] ath10k: fix kernel null pointer dereference Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 063/175] ath9k: Fix use-after-free Read in ath9k_wmi_ctrl_rx Sasha Levin
2020-06-08 23:16 ` [PATCH AUTOSEL 5.4 064/175] ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 067/175] brcmfmac: fix wrong location to get firmware feature Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 070/175] e1000: Distribute switch variables for initialization Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 077/175] ath10k: add flush tx packets for SDIO chip Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 081/175] dpaa2-eth: fix return codes used in ndo_setup_tc Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 082/175] netfilter: nft_nat: return EOPNOTSUPP if type or flags are not supported Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 083/175] selftests/bpf: Fix memory leak in extract_build_id() Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 084/175] net: bcmgenet: set Rx mode before starting netif Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 085/175] net: bcmgenet: Fix WoL with password after deep sleep Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 092/175] net: lpc-enet: fix error return code in lpc_mii_init() Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 094/175] drivers: net: davinci_mdio: fix potential NULL dereference in davinci_mdio_probe() Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 096/175] net: allwinner: Fix use correct return type for ndo_start_xmit() Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 098/175] ath9k_htc: Silence undersized packet warnings Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 099/175] libertas_tf: avoid a null dereference in pointer priv Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 112/175] iwlwifi: avoid debug max amsdu config overwriting itself Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 116/175] ath10k: Remove msdu from idr when management pkt send fails Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 117/175] wcn36xx: Fix error handling path in 'wcn36xx_probe()' Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 118/175] net: qed*: Reduce RX and TX default ring count when running inside kdump kernel Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 120/175] mt76: avoid rx reorder buffer overflow Sasha Levin
2020-06-08 23:17 ` [PATCH AUTOSEL 5.4 123/175] net: dsa: mt7530: set CPU port to fallback mode Sasha Levin
2020-06-08 23:17 ` Sasha Levin [this message]
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 127/175] net/mlx5e: IPoIB, Drop multicast packets that this interface sent Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 128/175] rtlwifi: Fix a double free in _rtl_usb_tx_urb_setup() Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 129/175] mwifiex: Fix memory corruption in dump_station Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 140/175] selftests/bpf: CONFIG_IPV6_SEG6_BPF required for test_seg6_loop.o Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 146/175] net: ethernet: fec: move GPR register offset and bit into DT Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 147/175] macvlan: Skip loopback packets in RX handler Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 157/175] ice: fix potential double free in probe unrolling Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 158/175] ixgbe: fix signed-integer-overflow warning Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 159/175] iwlwifi: mvm: fix aux station leak Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 167/175] vxlan: Avoid infinite loop when suppressing NS messages with invalid options Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 168/175] libbpf: Fix perf_buffer__free() API for sparse allocs Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 169/175] bpf: Fix map permissions check Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 170/175] bpf: Refactor sockmap redirect code so its easy to reuse Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 171/175] bpf: Fix running sk_skb program types with ktls Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 172/175] selftests/bpf, flow_dissector: Close TAP device FD after the test Sasha Levin
2020-06-08 23:18 ` [PATCH AUTOSEL 5.4 173/175] net_failover: fixed rollback in net_failover_open() Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200608231848.3366970-126-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=brouer@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maowenan@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=toke@redhat.com \
    --cc=toshiaki.makita1@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).