From: Konstantin Ananyev <konstantin.ananyev@huawei.com>
To: Stephen Hemminger <stephen@networkplumber.org>,
"dev@dpdk.org" <dev@dpdk.org>
Subject: RE: [PATCH] bpf: remove dependency on vla
Date: Fri, 15 Aug 2025 14:26:07 +0000 [thread overview]
Message-ID: <7c942773fe30436b888ff37db75880ee@huawei.com> (raw)
In-Reply-To: <20250803161617.36653-1-stephen@networkplumber.org>
> The code for ethdev callbacks was using variable length arrays
> which is a feature not supported on MSVC and later C standards.
> Replace with alloca().
I am not a big fun of such mechanical replacement of vla with alloca()
Specially in that particular case, we can have internal function that uses
fixed size array and in public one just call it several times in a loop.
Again, using VLA here is probably a real security breach,
as we put some assumptions on size of input arrays provided by user,
which we probably shouldn't.
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> lib/bpf/bpf_pkt.c | 16 +++++++++-------
> lib/bpf/meson.build | 2 --
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/lib/bpf/bpf_pkt.c b/lib/bpf/bpf_pkt.c
> index 01f813c56b..6a425d79b6 100644
> --- a/lib/bpf/bpf_pkt.c
> +++ b/lib/bpf/bpf_pkt.c
> @@ -6,6 +6,7 @@
> #include <string.h>
> #include <errno.h>
> #include <stdint.h>
> +#include <alloca.h>
>
> #include <sys/queue.h>
>
> @@ -163,10 +164,11 @@ apply_filter(struct rte_mbuf *mb[], const uint64_t rc[], uint32_t num,
> uint32_t drop)
> {
> uint32_t i, j, k;
> - struct rte_mbuf *dr[num];
> + struct rte_mbuf **dr;
>
> - for (i = 0, j = 0, k = 0; i != num; i++) {
> + dr = alloca(sizeof(struct rte_mbuf *) * num);
>
> + for (i = 0, j = 0, k = 0; i != num; i++) {
> /* filter matches */
> if (rc[i] != 0)
> mb[j++] = mb[i];
> @@ -193,8 +195,8 @@ pkt_filter_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num,
> uint32_t drop)
> {
> uint32_t i;
> - void *dp[num];
> - uint64_t rc[num];
> + void **dp = alloca(sizeof(void *) * num);
> + uint64_t *rc = alloca(sizeof(uint64_t) * num);
>
> for (i = 0; i != num; i++)
> dp[i] = rte_pktmbuf_mtod(mb[i], void *);
> @@ -209,7 +211,7 @@ pkt_filter_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[],
> {
> uint32_t i, n;
> void *dp;
> - uint64_t rc[num];
> + uint64_t *rc = alloca(sizeof(uint64_t) * num);
>
> n = 0;
> for (i = 0; i != num; i++) {
> @@ -228,7 +230,7 @@ static inline uint32_t
> pkt_filter_mb_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num,
> uint32_t drop)
> {
> - uint64_t rc[num];
> + uint64_t *rc = alloca(sizeof(uint64_t) * num);
>
> rte_bpf_exec_burst(bpf, (void **)mb, rc, num);
> return apply_filter(mb, rc, num, drop);
> @@ -239,7 +241,7 @@ pkt_filter_mb_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[],
> uint32_t num, uint32_t drop)
> {
> uint32_t i, n;
> - uint64_t rc[num];
> + uint64_t *rc = alloca(sizeof(uint64_t) * num);
>
> n = 0;
> for (i = 0; i != num; i++) {
> diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
> index 28df7f469a..aa258a9061 100644
> --- a/lib/bpf/meson.build
> +++ b/lib/bpf/meson.build
> @@ -7,8 +7,6 @@ if is_windows
> subdir_done()
> endif
>
> -cflags += no_wvla_cflag
> -
> if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_32')
> build = false
> reason = 'not supported on 32-bit x86'
> --
> 2.47.2
next prev parent reply other threads:[~2025-08-15 14:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-03 16:16 Stephen Hemminger
2025-08-15 14:26 ` Konstantin Ananyev [this message]
2025-08-15 16:03 ` Stephen Hemminger
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=7c942773fe30436b888ff37db75880ee@huawei.com \
--to=konstantin.ananyev@huawei.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
/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).