patch 'bpf: mask shift count in interpreter per RFC 9669' has been queued to stable release 24.11.9
luca.boccassi at gmail.com
luca.boccassi at gmail.com
Tue Oct 27 12:51:23 CET 2026
Hi,
FYI, your patch has been queued to stable release 24.11.9
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 10/29/26. So please
shout if anyone has objections.
Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.
Queued patches are on a temporary branch at:
https://github.com/bluca/dpdk-stable
This queued commit can be viewed at:
https://github.com/bluca/dpdk-stable/commit/589f8ba89489d10557d2e2ad0025d5fbfba711d1
Thanks.
Luca Boccassi
---
>From 589f8ba89489d10557d2e2ad0025d5fbfba711d1 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen at networkplumber.org>
Date: Thu, 27 Aug 2026 14:41:42 -0700
Subject: [PATCH] bpf: mask shift count in interpreter per RFC 9669
[ upstream commit 5bad11d3dd10eb765c7b767dc25a10ae90a84205 ]
The interpreter shifted by the raw immediate or register value, which
is undefined behavior in C when the count is >= the operand width and
trips UBSan. RFC 9669 masks shift counts (0x3f for 64-bit, 0x1f for
32-bit); mask the count in the LSH/RSH/ARSH cases.
Fixes: 94972f35a02e ("bpf: add BPF loading and execution framework")
Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
Acked-by: Marat Khalili <marat.khalili at huawei.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev at huawei.com>
---
lib/bpf/bpf_exec.c | 31 +++++++++++++++++++++----------
1 file changed, 21 insertions(+), 10 deletions(-)
diff --git a/lib/bpf/bpf_exec.c b/lib/bpf/bpf_exec.c
index 5d597ec170b..06847e962c2 100644
--- a/lib/bpf/bpf_exec.c
+++ b/lib/bpf/bpf_exec.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <limits.h>
#include <rte_common.h>
#include <rte_log.h>
@@ -41,6 +42,16 @@
((reg)[(ins)->dst_reg] = \
(type)(reg)[(ins)->dst_reg] op (type)(ins)->imm)
+#define BPF_OP_SHIFT_IMM(reg, ins, op, type) \
+ ((reg)[(ins)->dst_reg] = \
+ (type)(reg)[(ins)->dst_reg] op \
+ ((ins)->imm & (sizeof(type) * CHAR_BIT - 1)))
+
+#define BPF_OP_SHIFT_REG(reg, ins, op, type) \
+ ((reg)[(ins)->dst_reg] = \
+ (type)(reg)[(ins)->dst_reg] op \
+ ((reg)[(ins)->src_reg] & (sizeof(type) * CHAR_BIT - 1)))
+
#define BPF_DIV_ZERO_CHECK(bpf, reg, ins, type) do { \
if ((type)(reg)[(ins)->src_reg] == 0) { \
RTE_BPF_LOG_LINE(ERR, \
@@ -164,10 +175,10 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
BPF_OP_ALU_IMM(reg, ins, |, uint32_t);
break;
case (BPF_ALU | BPF_LSH | BPF_K):
- BPF_OP_ALU_IMM(reg, ins, <<, uint32_t);
+ BPF_OP_SHIFT_IMM(reg, ins, <<, uint32_t);
break;
case (BPF_ALU | BPF_RSH | BPF_K):
- BPF_OP_ALU_IMM(reg, ins, >>, uint32_t);
+ BPF_OP_SHIFT_IMM(reg, ins, >>, uint32_t);
break;
case (BPF_ALU | BPF_XOR | BPF_K):
BPF_OP_ALU_IMM(reg, ins, ^, uint32_t);
@@ -198,10 +209,10 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
BPF_OP_ALU_REG(reg, ins, |, uint32_t);
break;
case (BPF_ALU | BPF_LSH | BPF_X):
- BPF_OP_ALU_REG(reg, ins, <<, uint32_t);
+ BPF_OP_SHIFT_REG(reg, ins, <<, uint32_t);
break;
case (BPF_ALU | BPF_RSH | BPF_X):
- BPF_OP_ALU_REG(reg, ins, >>, uint32_t);
+ BPF_OP_SHIFT_REG(reg, ins, >>, uint32_t);
break;
case (BPF_ALU | BPF_XOR | BPF_X):
BPF_OP_ALU_REG(reg, ins, ^, uint32_t);
@@ -243,13 +254,13 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
BPF_OP_ALU_IMM(reg, ins, |, uint64_t);
break;
case (EBPF_ALU64 | BPF_LSH | BPF_K):
- BPF_OP_ALU_IMM(reg, ins, <<, uint64_t);
+ BPF_OP_SHIFT_IMM(reg, ins, <<, uint64_t);
break;
case (EBPF_ALU64 | BPF_RSH | BPF_K):
- BPF_OP_ALU_IMM(reg, ins, >>, uint64_t);
+ BPF_OP_SHIFT_IMM(reg, ins, >>, uint64_t);
break;
case (EBPF_ALU64 | EBPF_ARSH | BPF_K):
- BPF_OP_ALU_IMM(reg, ins, >>, int64_t);
+ BPF_OP_SHIFT_IMM(reg, ins, >>, int64_t);
break;
case (EBPF_ALU64 | BPF_XOR | BPF_K):
BPF_OP_ALU_IMM(reg, ins, ^, uint64_t);
@@ -280,13 +291,13 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
BPF_OP_ALU_REG(reg, ins, |, uint64_t);
break;
case (EBPF_ALU64 | BPF_LSH | BPF_X):
- BPF_OP_ALU_REG(reg, ins, <<, uint64_t);
+ BPF_OP_SHIFT_REG(reg, ins, <<, uint64_t);
break;
case (EBPF_ALU64 | BPF_RSH | BPF_X):
- BPF_OP_ALU_REG(reg, ins, >>, uint64_t);
+ BPF_OP_SHIFT_REG(reg, ins, >>, uint64_t);
break;
case (EBPF_ALU64 | EBPF_ARSH | BPF_X):
- BPF_OP_ALU_REG(reg, ins, >>, int64_t);
+ BPF_OP_SHIFT_REG(reg, ins, >>, int64_t);
break;
case (EBPF_ALU64 | BPF_XOR | BPF_X):
BPF_OP_ALU_REG(reg, ins, ^, uint64_t);
--
2.47.3
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2026-10-27 11:44:00.946148141 +0000
+++ 0189-bpf-mask-shift-count-in-interpreter-per-RFC-9669.patch 2026-10-27 11:43:53.770067372 +0000
@@ -1 +1 @@
-From 5bad11d3dd10eb765c7b767dc25a10ae90a84205 Mon Sep 17 00:00:00 2001
+From 589f8ba89489d10557d2e2ad0025d5fbfba711d1 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 5bad11d3dd10eb765c7b767dc25a10ae90a84205 ]
+
@@ -12 +13,0 @@
-Cc: stable at dpdk.org
@@ -22 +23 @@
-index 99b37ffa4e..1793906039 100644
+index 5d597ec170b..06847e962c2 100644
@@ -31 +31,0 @@
- #include <eal_export.h>
@@ -33 +33,2 @@
-@@ -44,6 +45,16 @@
+ #include <rte_log.h>
+@@ -41,6 +42,16 @@
@@ -50 +51 @@
-@@ -184,10 +195,10 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
+@@ -164,10 +175,10 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
@@ -63 +64 @@
-@@ -218,10 +229,10 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
+@@ -198,10 +209,10 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
@@ -76 +77 @@
-@@ -263,13 +274,13 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
+@@ -243,13 +254,13 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
@@ -93 +94 @@
-@@ -300,13 +311,13 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
+@@ -280,13 +291,13 @@ bpf_exec(const struct rte_bpf *bpf, uint64_t reg[EBPF_REG_NUM])
More information about the stable
mailing list