From: Ibrahim Zein <zeroxjacks@gmail.com>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net,
Ibrahim Zein <zeroxjacks@gmail.com>
Subject: [PATCH] bpf/btf: fix u32 subtraction overflow in btf_sec_info_cmp
Date: Wed, 18 Mar 2026 10:15:46 -0400 [thread overview]
Message-ID: <20260318141546.1893776-1-zeroxjacks@gmail.com> (raw)
The comparison function btf_sec_info_cmp() uses direct subtraction
of u32 values cast to int, which can produce incorrect results due
to integer overflow when values exceed 0x7FFFFFFF.
Replace with explicit comparisons to guarantee correct behavior
across all u32 value ranges.
Reported-by: Ibrahim Zein <zeroxjacks@gmail.com>
Signed-off-by: Ibrahim Zein <zeroxjacks@gmail.com>
---
kernel/bpf/btf.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 4872d2a..5b3e1af 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -5548,7 +5548,11 @@ static int btf_sec_info_cmp(const void *a, const void *b)
const struct btf_sec_info *x = a;
const struct btf_sec_info *y = b;
- return (int)(x->off - y->off) ? : (int)(x->len - y->len);
+ if (x->off != y->off)
+ return x->off < y->off ? -1 : 1;
+ if (x->len != y->len)
+ return x->len < y->len ? -1 : 1;
+ return 0;
}
static int btf_check_sec_info(struct btf_verifier_env *env,
--
2.51.0
next reply other threads:[~2026-03-18 14:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-18 14:15 Ibrahim Zein [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-03-18 14:02 [PATCH] bpf/btf: fix u32 subtraction overflow in btf_sec_info_cmp ibrahim zein
2026-03-18 14:11 ` Daniel Borkmann
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=20260318141546.1893776-1-zeroxjacks@gmail.com \
--to=zeroxjacks@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
/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.