From: Yuntao Wang <ytcoode@gmail.com>
Date: Sun, 20 Mar 2022 15:52:40 +0800
Subject: bpf: Simplify check in btf_parse_hdr()
Patch-mainline: v5.18-rc1
Git-commit: 583669ab3aed29994e50bde6c66b52d44e1bdb73
References: jsc#PED-1377
Replace offsetof(hdr_len) + sizeof(hdr_len) with offsetofend(hdr_len) to
simplify the check for correctness of btf_data_size in btf_parse_hdr()
Signed-off-by: Yuntao Wang <ytcoode@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20220320075240.1001728-1-ytcoode@gmail.com
Acked-by: Shung-Hsi Yu <shung-hsi.yu@suse.com>
---
kernel/bpf/btf.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -4482,8 +4482,7 @@ static int btf_parse_hdr(struct btf_veri
btf = env->btf;
btf_data_size = btf->data_size;
- if (btf_data_size <
- offsetof(struct btf_header, hdr_len) + sizeof(hdr->hdr_len)) {
+ if (btf_data_size < offsetofend(struct btf_header, hdr_len)) {
btf_verifier_log(env, "hdr_len not found");
return -EINVAL;
}