Skip to contentSkip to conversation

tools: ynl: c: correct reverse decode of empty attrs

PATCH Applied Jakub Kicinski 3 participants 3 messages Jan 24, 2025 – Jan 27, 2025

Subsystems (3)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 tools: ynl: c: correct reverse decode of empty attrs

netlink reports which attribute was incorrect by sending back an attribute offset. Offset points to the address of struct nlattr, but to interpret the type we also need the nesting path. Attribute IDs have different meaning in different nests of the same message.

Correct the condition for "is the offset within current attribute". ynl_attr_data_len() does not include the attribute header, so the end offset was off by 4 bytes.

This means that we'd always skip over flags and empty nests.

The devmem tests, for example, issues an invalid request with empty queue nests, resulting in the following error:

YNL failed: Kernel error: missing attribute: .queues.ifindex

The message is incorrect, "queues" nest does not have an "ifindex" attribute defined. With this fix we decend correctly into the nest:

YNL failed: Kernel error: missing attribute: .queues.id

Fixes 86878f14d71a ("tools: ynl: user space helpers")

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

---
 tools/net/ynl/lib/ynl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/net/ynl/lib/ynl.c +1 -1
index e16cef160bc2..ce32cb35007d 100644
@@ -95,7 +95,7 @@ ynl_err_walk(struct ynl_sock *ys, void *start, void *end, unsigned int off,
 
 	ynl_attr_for_each_payload(start, data_len, attr) {
 		astart_off = (char *)attr - (char *)start;
-		aend_off = astart_off + ynl_attr_data_len(attr);
+		aend_off = (char *)ynl_attr_data_end(attr) - (char *)start;
 		if (aend_off <= off)
 			continue;
 
Signature · 1 line
2.48.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 37 lines · Jakub Kicinski

netlink reports which attribute was incorrect by sending back an attribute offset. Offset points to the address of struct nlattr, but to interpret the type we also need the nesting path. Attribute IDs have different meaning in different nests of the same message.

Correct the condition for "is the offset within current attribute". ynl_attr_data_len() does not include the attribute header, so the end offset was off by 4 bytes.

This means that we'd always skip over flags and empty nests.

The devmem tests, for example, issues an invalid request with empty queue nests, resulting in the following error:

YNL failed: Kernel error: missing attribute: .queues.ifindex

The message is incorrect, "queues" nest does not have an "ifindex" attribute defined. With this fix we decend correctly into the nest:

YNL failed: Kernel error: missing attribute: .queues.id

Fixes 86878f14d71a ("tools: ynl: user space helpers")

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

---
 tools/net/ynl/lib/ynl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/net/ynl/lib/ynl.c +0 -0
index e16cef160bc2..ce32cb35007d 100644

tools/net/ynl/lib/ynl.c ynl_err_walk(struct ynl_sock *ys, void *start, void *end, unsigned int off, · line 100

Quoted 7 lines
tools/net/ynl/lib/ynl.c +1 -1
@@ -95,7 +95,7 @@ ynl_err_walk(struct ynl_sock *ys, void *start, void *end, unsigned int off,
 
 	ynl_attr_for_each_payload(start, data_len, attr) {
 		astart_off = (char *)attr - (char *)start;
-		aend_off = astart_off + ynl_attr_data_len(attr);
+		aend_off = (char *)ynl_attr_data_end(attr) - (char *)start;
 		if (aend_off <= off)
 			continue;
#2 lore raw
In reply to Jakub Kicinski
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Thu, 23 Jan 2025 17:21:30 -0800 you wrote:

netlink reports which attribute was incorrect by sending back an attribute offset. Offset points to the address of struct nlattr, but to interpret the type we also need the nesting path. Attribute IDs have different meaning in different nests of the same message.

Correct the condition for "is the offset within current attribute". ynl_attr_data_len() does not include the attribute header, so the end offset was off by 4 bytes.

[...]

Here is the summary with links:
- [net] tools: ynl: c: correct reverse decode of empty attrs

    https://git.kernel.org/netdev/net/c/964417a5d4a0

You are awesome, thank you!

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