All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zvi Effron <zeffron@riotgames.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Jesper Dangaard Brouer <hawk@kernel.org>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>,
	Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
	Martin KaFai Lau <kafai@fb.com>, Yonghong Song <yhs@fb.com>,
	Zvi Effron <zeffron@riotgames.com>,
	Cody Haas <chaas@riotgames.com>,
	Lisa Watanabe <lwatanabe@riotgames.com>
Subject: [PATCH bpf-next v5 1/4] bpf: add function for XDP meta data length check
Date: Wed, 16 Jun 2021 22:47:09 +0000	[thread overview]
Message-ID: <20210616224712.3243-2-zeffron@riotgames.com> (raw)
In-Reply-To: <20210616224712.3243-1-zeffron@riotgames.com>

This commit prepares to use the XDP meta data length check in multiple
places by making it into a defined macro instead of a literal.

Co-developed-by: Cody Haas <chaas@riotgames.com>
Signed-off-by: Cody Haas <chaas@riotgames.com>
Co-developed-by: Lisa Watanabe <lwatanabe@riotgames.com>
Signed-off-by: Lisa Watanabe <lwatanabe@riotgames.com>
Signed-off-by: Zvi Effron <zeffron@riotgames.com>
---
 include/net/xdp.h | 5 +++++
 net/core/filter.c | 4 ++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/net/xdp.h b/include/net/xdp.h
index 5533f0ab2afc..8bfd21bfeddc 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -276,6 +276,11 @@ xdp_data_meta_unsupported(const struct xdp_buff *xdp)
 	return unlikely(xdp->data_meta > xdp->data);
 }
 
+static __always_inline int
+xdp_metalen_valid(unsigned long metalen) {
+	return (metalen & (sizeof(__u32) - 1)) || (metalen > 32);
+}
+
 struct xdp_attachment_info {
 	struct bpf_prog *prog;
 	u32 flags;
diff --git a/net/core/filter.c b/net/core/filter.c
index 5b86e47ef079..b4a64a07de88 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -77,6 +77,7 @@
 #include <net/transp_v6.h>
 #include <linux/btf_ids.h>
 #include <net/tls.h>
+#include <net/xdp.h>
 
 static const struct bpf_func_proto *
 bpf_sk_base_func_proto(enum bpf_func_id func_id);
@@ -3905,8 +3906,7 @@ BPF_CALL_2(bpf_xdp_adjust_meta, struct xdp_buff *, xdp, int, offset)
 	if (unlikely(meta < xdp_frame_end ||
 		     meta > xdp->data))
 		return -EINVAL;
-	if (unlikely((metalen & (sizeof(__u32) - 1)) ||
-		     (metalen > 32)))
+	if (unlikely(xdp_metalen_valid(metalen)))
 		return -EACCES;
 
 	xdp->data_meta = meta;
-- 
2.31.1


  reply	other threads:[~2021-06-16 22:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-16 22:47 [PATCH bpf-next v5 0/4] bpf: support input xdp_md context in BPF_PROG_TEST_RUN Zvi Effron
2021-06-16 22:47 ` Zvi Effron [this message]
2021-06-17  6:27   ` [PATCH bpf-next v5 1/4] bpf: add function for XDP meta data length check Yonghong Song
2021-06-16 22:47 ` [PATCH bpf-next v5 2/4] bpf: support input xdp_md context in BPF_PROG_TEST_RUN Zvi Effron
2021-06-17  6:45   ` Yonghong Song
2021-06-16 22:47 ` [PATCH bpf-next v5 3/4] bpf: support specifying ingress via " Zvi Effron
2021-06-17  6:54   ` Yonghong Song
2021-06-17 22:47     ` Zvi Effron
2021-06-16 22:47 ` [PATCH bpf-next v5 4/4] selftests/bpf: Add test for " Zvi Effron
2021-06-17  7:11   ` Yonghong Song
2021-06-17 15:18     ` Zvi Effron
2021-06-17 15:30       ` Yonghong Song

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=20210616224712.3243-2-zeffron@riotgames.com \
    --to=zeffron@riotgames.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chaas@riotgames.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=kafai@fb.com \
    --cc=lwatanabe@riotgames.com \
    --cc=maciej.fijalkowski@intel.com \
    --cc=yhs@fb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.