netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jesper Dangaard Brouer <brouer@redhat.com>
To: sameehj@amazon.com
Cc: "Jesper Dangaard Brouer" <brouer@redhat.com>,
	netdev@vger.kernel.org, bpf@vger.kernel.org, zorik@amazon.com,
	akiyano@amazon.com, gtzalik@amazon.com,
	"Toke Høiland-Jørgensen" <toke@toke.dk>,
	"Daniel Borkmann" <borkmann@iogearbox.net>,
	"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"Alexander Duyck" <alexander.duyck@gmail.com>,
	"Jeff Kirsher" <jeffrey.t.kirsher@intel.com>,
	"David Ahern" <dsahern@gmail.com>,
	"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
	"Ilias Apalodimas" <ilias.apalodimas@linaro.org>,
	"Lorenzo Bianconi" <lorenzo@kernel.org>
Subject: [PATCH RFC v1 08/15] xdp: allow bpf_xdp_adjust_tail() to grow packet size
Date: Tue, 17 Mar 2020 18:29:48 +0100	[thread overview]
Message-ID: <158446618833.702578.690455723873770827.stgit@firesoul> (raw)
In-Reply-To: <158446612466.702578.2795159620575737080.stgit@firesoul>

FIXME: This patch MUST be LAST after all drivers have been updated!!!

Finally, after all drivers have a frame size, allow BPF-helper
bpf_xdp_adjust_tail() to grow or extend packet size at frame tail.

Remember that helper/macro xdp_data_hard_end have reserved some
tailroom.  Thus, this helper makes sure that the BPF-prog don't have
access to this tailroom area.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
---
 include/uapi/linux/bpf.h |    4 ++--
 net/core/filter.c        |   18 ++++++++++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 14dc4f9fb3c8..1fa6ab616ec3 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1942,8 +1942,8 @@ union bpf_attr {
  * int bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
  * 	Description
  * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
- * 		only possible to shrink the packet as of this writing,
- * 		therefore *delta* must be a negative integer.
+ * 		possible to both shrink and grow the packet tail.
+ * 		Shrink done via *delta* being a negative integer.
  *
  * 		A call to this helper is susceptible to change the underlying
  * 		packet buffer. Therefore, at load time, all checks on pointers
diff --git a/net/core/filter.c b/net/core/filter.c
index 4a08c9fb2be7..0ceddee0c678 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3409,12 +3409,26 @@ static const struct bpf_func_proto bpf_xdp_adjust_head_proto = {
 
 BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
 {
+	void *data_hard_end = xdp_data_hard_end(xdp);
 	void *data_end = xdp->data_end + offset;
 
-	/* only shrinking is allowed for now. */
-	if (unlikely(offset >= 0))
+	/* Notice that xdp_data_hard_end have reserved some tailroom */
+	if (unlikely(data_end >= data_hard_end))
 		return -EINVAL;
 
+	/* DANGER: ALL drivers MUST be converted to init xdp->frame_sz
+	 * - Adding some chicken checks below
+	 * - Will (likely) not be for upstream
+	 */
+	if (unlikely(xdp->frame_sz < (xdp->data_end - xdp->data_hard_start))) {
+		WARN(1, "Too small xdp->frame_sz = %d\n", xdp->frame_sz);
+		return -EINVAL;
+	}
+	if (unlikely(xdp->frame_sz > PAGE_SIZE)) {
+		WARN(1, "Too BIG xdp->frame_sz = %d\n", xdp->frame_sz);
+		return -EINVAL;
+	}
+
 	if (unlikely(data_end < xdp->data + ETH_HLEN))
 		return -EINVAL;
 



  parent reply	other threads:[~2020-03-17 17:30 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-17 17:29 [PATCH RFC v1 00/15] XDP extend with knowledge of frame size Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 01/15] xdp: add frame size to xdp_buff Jesper Dangaard Brouer
2020-03-17 20:42   ` Jakub Kicinski
2020-03-18  6:58     ` Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 02/15] mvneta: add XDP frame size to driver Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 03/15] bnxt: " Jesper Dangaard Brouer
2020-03-20 19:22   ` Andy Gospodarek
2020-03-23 14:18   ` Andy Gospodarek
2020-03-23 14:44     ` Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 04/15] ixgbe: fix XDP redirect on archs with PAGE_SIZE above 4K Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 05/15] ixgbe: add XDP frame size to driver Jesper Dangaard Brouer
2020-03-18 20:03   ` Maciej Fijalkowski
2020-03-18 21:23     ` Alexander Duyck
2020-03-20 21:44       ` Jesper Dangaard Brouer
2020-03-20 22:37         ` Alexander Duyck
2020-03-17 17:29 ` [PATCH RFC v1 06/15] sfc: fix XDP-redirect in this driver Jesper Dangaard Brouer
2020-03-17 17:29 ` [PATCH RFC v1 07/15] sfc: add XDP frame size Jesper Dangaard Brouer
2020-03-17 17:29 ` Jesper Dangaard Brouer [this message]
2020-03-17 17:29 ` [PATCH RFC v1 09/15] xdp: clear grow memory in bpf_xdp_adjust_tail() Jesper Dangaard Brouer
2020-03-17 20:38   ` Jakub Kicinski
2020-03-18  9:15   ` Toke Høiland-Jørgensen
2020-03-18 10:25     ` Jesper Dangaard Brouer
2020-03-19  5:35       ` Alexei Starovoitov
2020-03-17 17:29 ` [PATCH RFC v1 10/15] net: XDP-generic determining XDP frame size Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 11/15] xdp: xdp_frame add member frame_sz and handle in convert_to_xdp_frame Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 12/15] xdp: cpumap redirect use frame_sz and increase skb_tailroom Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 13/15] tun: add XDP frame size Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 14/15] veth: xdp using frame_sz in veth driver Jesper Dangaard Brouer
2020-03-17 17:30 ` [PATCH RFC v1 15/15] dpaa2-eth: add XDP frame size Jesper Dangaard Brouer

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=158446618833.702578.690455723873770827.stgit@firesoul \
    --to=brouer@redhat.com \
    --cc=akiyano@amazon.com \
    --cc=alexander.duyck@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=borkmann@iogearbox.net \
    --cc=bpf@vger.kernel.org \
    --cc=dsahern@gmail.com \
    --cc=gtzalik@amazon.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jeffrey.t.kirsher@intel.com \
    --cc=john.fastabend@gmail.com \
    --cc=lorenzo@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sameehj@amazon.com \
    --cc=toke@toke.dk \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=zorik@amazon.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).