Skip to contentSkip to conversation

bpf: use nla_ok() instead of checking nla_len directly

PATCH Applied Jakub Kicinski 3 participants 3 messages Dec 18, 2023 – Dec 19, 2023

Subsystems (4)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 bpf: use nla_ok() instead of checking nla_len directly

nla_len may also be too short to be sane, in which case after recent changes nla_len() will return a wrapped value.

Reported-by [email protected]
Fixes 172db56d90d2 ("netlink: Return unsigned value for nla_len()")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/core/filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/filter.c +1 -1
index 6d89a9cf33c9..24061f29c9dd 100644
@@ -203,7 +203,7 @@ BPF_CALL_3(bpf_skb_get_nlattr_nest, struct sk_buff *, skb, u32, a, u32, x)
 		return 0;
 
 	nla = (struct nlattr *) &skb->data[a];
-	if (nla->nla_len > skb->len - a)
+	if (!nla_ok(nla, skb->len - a))
 		return 0;
 
 	nla = nla_find_nested(nla, x);
Signature · 1 line
2.43.0
#2 lore raw
In reply to Jakub Kicinski
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · On Mon, 18 Dec 2023 15:19:04 -0800 you wrote:

nla_len may also be too short to be sane, in which case after recent changes nla_len() will return a wrapped value.

Reported-by [email protected]
Fixes 172db56d90d2 ("netlink: Return unsigned value for nla_len()")

[...]

Here is the summary with links:
- [bpf-next] bpf: use nla_ok() instead of checking nla_len directly

    https://git.kernel.org/bpf/bpf-next/c/2130c519a401

You are awesome, thank you!

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