Skip to contentSkip to conversation

bpf: btf: fix truncated last_member_type_id in btf_struct_resolve

PATCH Applied Lorenz Bauer 2 participants 2 messages Sep 10, 2022 – Sep 11, 2022 BPF

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: btf: fix truncated last_member_type_id in btf_struct_resolve

When trying to finish resolving a struct member, btf_struct_resolve saves the member type id in a u16 temporary variable. This truncates the 32 bit type id value if it exceeds UINT16_MAX.

As a result, structs that have members with type ids > UINT16_MAX and which need resolution will fail with a message like this:

[67414] STRUCT ff_device size=120 vlen=12
effect_owners type_id=67434 bits_offset=960 Member exceeds struct_size

Fix this by changing the type of last_member_type_id to u32.

Fixes a0791f0df7d2 ("bpf: fix BTF limits")
---
 kernel/bpf/btf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
index 7e64447659f3..36fd4b509294 100644
@@ -3128,7 +3128,7 @@ static int btf_struct_resolve(struct btf_verifier_env *env,
 	if (v->next_member) {
 		const struct btf_type *last_member_type;
 		const struct btf_member *last_member;
-		u16 last_member_type_id;
+		u32 last_member_type_id;
 
 		last_member = btf_type_member(v->t) + v->next_member - 1;
 		last_member_type_id = last_member->type;
Signature · 1 line
2.34.1
#1 lore raw
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:

Quoted 8 lines · On Sat, 10 Sep 2022 11:01:20 +0000 you wrote:

When trying to finish resolving a struct member, btf_struct_resolve saves the member type id in a u16 temporary variable. This truncates the 32 bit type id value if it exceeds UINT16_MAX.

As a result, structs that have members with type ids > UINT16_MAX and which need resolution will fail with a message like this:

[...]

Here is the summary with links:
- [bpf,v2] bpf: btf: fix truncated last_member_type_id in btf_struct_resolve

    https://git.kernel.org/bpf/bpf/c/a37a32583e28

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html