patch 'bpf/validate: fix BPF_SUB signed max zero case' has been queued to stable release 24.11.7
luca.boccassi at gmail.com
luca.boccassi at gmail.com
Mon Jul 6 12:21:11 CEST 2026
Hi,
FYI, your patch has been queued to stable release 24.11.7
Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 07/05/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/4bb2f51eb1a5f10d79f7b8f47425084e598eca50
Thanks.
Luca Boccassi
---
>From 4bb2f51eb1a5f10d79f7b8f47425084e598eca50 Mon Sep 17 00:00:00 2001
From: Marat Khalili <marat.khalili at huawei.com>
Date: Wed, 24 Jun 2026 13:17:54 +0100
Subject: [PATCH] bpf/validate: fix BPF_SUB signed max zero case
[ upstream commit b418ce39015349544b10743c7cb68e84595e2f89 ]
Function `eval_sub` used source register signed minimum to detect
overflow of the difference (operation result) signed minimum, and source
register signed maximum to detect overflow of the difference signed
maximum. However in the actual formula for difference source register
bounds are swapped (correctly, since we subtract it), so in overflow
detection we should also have swapped them. It caused false negatives in
certain cases.
E.g. consider the following program with the current validation code:
Tested program:
0: mov r0, #0x0
1: ldxdw r2, [r1 + 0]
2: jsgt r2, #0x0, L7
3: ldxdw r3, [r1 + 8]
4: jsgt r3, #0x0, L7
5: sub r2, r3 ; tested instruction
6: mov r0, #0x1
7: exit
Pre-state:
r2: INT64_MIN..0
r3: INT64_MIN..0
Post-state:
r2: INT64_MIN
Validator ignores overflow of signed minimum and considers result to
always equal INT64_MIN. However, if -1 was loaded on step 1 and -2 was
loaded on step 3 it is possible for the difference to equal 1.
Swap source register signed minimum and maximum in the overflow
condition to match the new range formula, add test.
Fixes: 8021917293d0 ("bpf: add extra validation for input BPF program")
Reported-by: Claudia Cauli <claudiacauli at gmail.com>
Signed-off-by: Marat Khalili <marat.khalili at huawei.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev at huawei.com>
---
lib/bpf/bpf_validate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/bpf/bpf_validate.c b/lib/bpf/bpf_validate.c
index 63f710cf28..09d610eaa3 100644
--- a/lib/bpf/bpf_validate.c
+++ b/lib/bpf/bpf_validate.c
@@ -296,9 +296,9 @@ eval_sub(struct bpf_reg_val *rd, const struct bpf_reg_val *rs, uint64_t msk)
eval_umax_bound(&rv, msk);
if ((rd->s.min != rd->s.max || rs->s.min != rs->s.max) &&
- (((rs->s.min < 0 && rv.s.min < rd->s.min) ||
+ (((rs->s.max < 0 && rv.s.min < rd->s.min) ||
rv.s.min > rd->s.min) ||
- ((rs->s.max < 0 && rv.s.max < rd->s.max) ||
+ ((rs->s.min < 0 && rv.s.max < rd->s.max) ||
rv.s.max > rd->s.max)))
eval_smax_bound(&rv, msk);
--
2.47.3
---
Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- - 2026-07-03 12:55:49.673265352 +0100
+++ 0079-bpf-validate-fix-BPF_SUB-signed-max-zero-case.patch 2026-07-03 12:55:46.730575555 +0100
@@ -1 +1 @@
-From b418ce39015349544b10743c7cb68e84595e2f89 Mon Sep 17 00:00:00 2001
+From 4bb2f51eb1a5f10d79f7b8f47425084e598eca50 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit b418ce39015349544b10743c7cb68e84595e2f89 ]
+
@@ -39 +40,0 @@
-Cc: stable at dpdk.org
@@ -45,32 +46,3 @@
- app/test/test_bpf_validate.c | 17 +++++++++++++++++
- lib/bpf/bpf_validate.c | 4 ++--
- 2 files changed, 19 insertions(+), 2 deletions(-)
-
-diff --git a/app/test/test_bpf_validate.c b/app/test/test_bpf_validate.c
-index dfcf49ccb9..5cf8d99eff 100644
---- a/app/test/test_bpf_validate.c
-+++ b/app/test/test_bpf_validate.c
-@@ -1747,6 +1747,23 @@ test_alu64_or_k_positive(void)
- REGISTER_FAST_TEST(bpf_validate_alu64_or_k_positive_autotest, NOHUGE_OK, ASAN_OK,
- test_alu64_or_k_positive);
-
-+/* 64-bit difference between two negative ranges.. */
-+static int
-+test_alu64_sub_x_src_signed_max_zero(void)
-+{
-+ return verify_instruction((struct verify_instruction_param){
-+ .tested_instruction = {
-+ .code = (EBPF_ALU64 | BPF_SUB | BPF_X),
-+ },
-+ .pre.dst = make_signed_domain(INT64_MIN, 0),
-+ .pre.src = make_signed_domain(INT64_MIN, 0),
-+ .post.dst = unknown,
-+ });
-+}
-+
-+REGISTER_FAST_TEST(bpf_validate_alu64_sub_x_src_signed_max_zero_autotest, NOHUGE_OK, ASAN_OK,
-+ test_alu64_sub_x_src_signed_max_zero);
-+
- /* Jump if greater than immediate. */
- static int
- test_jmp64_jeq_k(void)
+ lib/bpf/bpf_validate.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
@@ -78 +50 @@
-index abb39cfd32..131a5468db 100644
+index 63f710cf28..09d610eaa3 100644
@@ -81 +53 @@
-@@ -716,9 +716,9 @@ eval_sub(struct bpf_reg_val *rd, const struct bpf_reg_val *rs, uint64_t msk)
+@@ -296,9 +296,9 @@ eval_sub(struct bpf_reg_val *rd, const struct bpf_reg_val *rs, uint64_t msk)
More information about the stable
mailing list