Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp786920ybt; Fri, 19 Jun 2020 13:48:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLq21h+urM7WtbYQFiqIgrxROJhB7FB8gqWuqje5Duv6KuE73e11rX54gu86eLE08uFhCj X-Received: by 2002:a17:906:1149:: with SMTP id i9mr5677643eja.100.1592599718285; Fri, 19 Jun 2020 13:48:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592599718; cv=none; d=google.com; s=arc-20160816; b=zfEMQ0A5Oz3hKIfMZqZLyWz92Z1+z7ze2L4/isivPT65c7pkGoVQsMA2/nSHuzftgZ i/ufdl9VZsJJCjXrQUWF9xfMn4dW+PndXjhj7IIedrwp6y4zm5KwZMqYH1bGTVR5/9Vh iG1sUmBcn+/pfZAn7wh8063wA6Wf1AomwMEupm8Ryy+qjtvwknjpS+WL8AdbbUObTot+ ddNBVNjTjRy4bUZurVC83y+SRPsDHTs6q4CGcUhVLd1LslTYBSIaCsvFzIqqA2MBC1qI KNGg5riWYXZzhbJYA8N+0n9ilelh3aTsWJ+D1VMFnCb+WAjQpbDOnEi7eSKKJ9UG6vQZ 5nnA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tjsUu9b3FY2TTuxdvFjpMMyX+tWbXjs527n7Jn/rF9g=; b=0B4gnfTRrTjOpMns3yP+UgaQxGD0tTsvOgM3C3hdtTTUtiLiiv59e931iA/ixj2K5Q mUevAsPfshjZ5JWGYCjlM4TLGzy4OHUD365r0HUV1M76xGNRwvO6SDTDElG0P07WnzYt 4Fir3XRgAJtue4DAyJ02QFcEa5iDN5r2qXMOzyN2rNmlkKhvkj4aV2oCSiFyOdvPzfNQ M+EF17+itWQaI3UCygyze9dpPcMiiVjg/CUBAkqXu1LO/pvkvj3hfBH4D2+kXoG9Runb BMKkiSM9gyWxsSTyjTPzTbuxDZ6U6BStW2DD03sSXRaC1nvem1u5V/a6iSGdZtDY6FV7 iN4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=d3bSpIiP; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e18si4583547eds.250.2020.06.19.13.48.09; Fri, 19 Jun 2020 13:48:38 -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=d3bSpIiP; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390750AbgFSPB6 (ORCPT + 99 others); Fri, 19 Jun 2020 11:01:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:57632 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390685AbgFSPBL (ORCPT ); Fri, 19 Jun 2020 11:01:11 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EDFFF218AC; Fri, 19 Jun 2020 15:01:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592578871; bh=roViRovz+ySXxtyVFp7quuCERrlKwSGt4JrFFfEiK+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d3bSpIiPmjA8QyRMPvtgRsGUNXM36+v3nZki3AkQEOooHseUSa58M0+s1rm6LZDZx +KHq5fpqLVNUGG7W7v3HPDOuqdLJedsrcEUmImOPxvGgx/8UHIiZVs2z9lzQ08sZ9O 5oPheu8bcRAM/K2TD8IF3y3+RVxjEYkuaefx79lI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mao Wenan , Jesper Dangaard Brouer , Alexei Starovoitov , Toshiaki Makita , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Sasha Levin Subject: [PATCH 4.19 159/267] veth: Adjust hard_start offset on redirect XDP frames Date: Fri, 19 Jun 2020 16:32:24 +0200 Message-Id: <20200619141656.438501327@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200619141648.840376470@linuxfoundation.org> References: <20200619141648.840376470@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 41a00cd76955..2abbad1abaf2 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -377,13 +377,15 @@ static struct sk_buff *veth_xdp_rcv_one(struct veth_rq *rq, unsigned int *xdp_xmit) { 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)) { @@ -405,7 +407,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) < 0)) { trace_xdp_exception(rq->dev, xdp_prog, act); @@ -417,7 +418,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; @@ -437,7 +437,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