Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp54321ybg; Mon, 8 Jun 2020 16:14:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVlfzMvDW5BZIlWY8CgIhlA2JUIzTLPK3FVMtDPX+RGnm4N92G4HC5dEpxCAiD5HoLHW1F X-Received: by 2002:a17:906:4e59:: with SMTP id g25mr22353308ejw.60.1591658099338; Mon, 08 Jun 2020 16:14:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591658099; cv=none; d=google.com; s=arc-20160816; b=G6b6H7M15J5P0Q87AAxSsPbL2o5fGZudeioaG/b+csiw6ALIcgLoqH5U/+GXYxNnaX leWwA8MYvYUBzNbz2CSFTebQzSJJvVi3qSSi5XoW1Gd2wzlKhQemLiMaR0YfiWGopu6w O7+whywg/rA36L81RpDaON0hbJ8wvUfUzOPI8pZCynDFYMFZ6AcGU/OCtqXG5T5kgiWm Vo4v3dul6Eiculc1pDKTTiizgsiuOaxCi/Z9AqInMxeiu/hroNi9SVK6V85s3etyrCjY Uh62SyHshGwrfF5liQ/X5TNGCA4v3au+NIartskDODBmDSO6Hs5P0++qvUh+5GfoEX8q toGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MwA+OXYzfZppUhcyxrVIMqwURze/x/IhUNZIcLw9pkE=; b=MxTL/JBZODb+03L6gPUl4y+jpZ/jzCe4cpk+PcJMrZV93fF50gKDz5JDw9qygnt81+ T3cg9zaOwiPbxOa74Gdb08KPxjRt6atyE4ZudD4Umv3DNj/Hc9Ro4fZV1bpZuV9oeS3Z GhETmf5TYTpGdXdqdD/UDUUBfclqwmDichKwN0kHELAxICkiFi6LELJLZi10vZe4yO63 nA6nuPdIPHvW5SDCNISvwQs4xu2nEN4LK4m8rbiQOpcnIfdDEUpet8bgzJUkFeqOBV7k nSdVSOMzg29tdGgNsULVXn2Dk3D+C2AgPgo3SWPn42gUaE8CqNjOa7RXvGUHFM1khq2s 6fEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Nd4imnCK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s9si10048898edx.608.2020.06.08.16.14.35; Mon, 08 Jun 2020 16:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Nd4imnCK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727898AbgFHXMS (ORCPT + 99 others); Mon, 8 Jun 2020 19:12:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:56694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728696AbgFHXKf (ORCPT ); Mon, 8 Jun 2020 19:10:35 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C7371208FE; Mon, 8 Jun 2020 23:10:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591657834; bh=9hnYe63g3vNUWbLOB/FO/gxg7KJj1oQxrmXrsSdDF5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nd4imnCKWfhHkte7E86OzU32THw1VLSAHe4+4z0gubmwsTCcexzr9zIZlJpy5uCfH Wx02XvTPQeUJXTEfH9sYyX+PhnVsQ29lDmqR2H4QUaydpxbQuM9xFNl7MBrIKC5zCD 4kXCD/MPwAoajyN9smXavItof4IsIhQWFns4I8JI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jesper Dangaard Brouer , Mao Wenan , Alexei Starovoitov , Toshiaki Makita , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Sasha Levin , netdev@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 5.7 204/274] veth: Adjust hard_start offset on redirect XDP frames Date: Mon, 8 Jun 2020 19:04:57 -0400 Message-Id: <20200608230607.3361041-204-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608230607.3361041-1-sashal@kernel.org> References: <20200608230607.3361041-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jesper Dangaard Brouer [ 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 Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Alexei Starovoitov Acked-by: Toshiaki Makita Acked-by: Toke Høiland-Jørgensen Link: https://lore.kernel.org/bpf/158945338331.97035.5923525383710752178.stgit@firesoul Signed-off-by: Sasha Levin --- 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 aece0e5eec8c..d5691bb84448 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -564,13 +564,15 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq, struct veth_stats *stats) { 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)) { @@ -592,7 +594,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, &xdp, bq) < 0)) { trace_xdp_exception(rq->dev, xdp_prog, act); @@ -605,7 +606,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; @@ -629,7 +629,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); stats->rx_drops++; -- 2.25.1