Skip to contentSkip to conversation

netfilter: nfnetlink_log: collapse both dev log blocks

PATCH In review Florian Westphal 1 participant 2 messages Oct 2

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/1 netfilter: nfnetlink_log: collapse both dev log blocks

Looked like this:

if (indev && skb->dev &&
skb_mac_header_was_set(skb) &&
skb_mac_header_len(skb) != 0) {
...
}

if (indev && skb_mac_header_was_set(skb)) {
...
}

LLM (sashiko) claims there is a NULL deref in the second block, because it dereferences skb->dev without checking skb->dev != NULL.

Don't know if indev && !skb->dev is even possible:
NF_HOOK() invocation normally passes skb->dev as the indev argument.

Instead of cargo-culting additional skb->dev check, lets just merge both blocks into one. This gives 2nd block the tighter guards and results in a small behavioral change:

When skb_mac_header_was_set is true but skb_mac_header_len == 0 HWADDR was not emitted, but HWTYPE/HWLEN was. But given 2nd block also emits NFULA_HWHEADER based off skb->dev->hard_header_len, that change is probably desireable.

---
 net/netfilter/nfnetlink_log.c | 2 --
 1 file changed, 2 deletions(-)
net/netfilter/nfnetlink_log.c +0 -2
index dddbaf6860cc..3df2998b8cc0 100644
@@ -600,9 +600,7 @@ __build_packet_message(struct nfnl_log_net *log,
 			if (nla_put(inst->skb, NFULA_HWADDR, sizeof(phw), &phw))
 				goto nla_put_failure;
 		}
-	}
 
-	if (indev && skb_mac_header_was_set(skb)) {
 		if (nla_put_be16(inst->skb, NFULA_HWTYPE, htons(skb->dev->type)) ||
 		    nla_put_be16(inst->skb, NFULA_HWLEN,
 				 htons(skb->dev->hard_header_len)))
Signature · 1 line
2.55.0
author maintainer
#1 lore raw
Quoted 22 lines · Florian Westphal

Looked like this:

if (indev && skb->dev &&
skb_mac_header_was_set(skb) &&
skb_mac_header_len(skb) != 0) {
...
}

if (indev && skb_mac_header_was_set(skb)) {
...
}

LLM (sashiko) claims there is a NULL deref in the second block, because it dereferences skb->dev without checking skb->dev != NULL.

Don't know if indev && !skb->dev is even possible:
NF_HOOK() invocation normally passes skb->dev as the indev argument.

Instead of cargo-culting additional skb->dev check, lets just merge both blocks into one. This gives 2nd block the tighter guards and results in a small behavioral change:

Quoted 6 lines

When skb_mac_header_was_set is true but skb_mac_header_len == 0 HWADDR was not emitted, but HWTYPE/HWLEN was. But given 2nd block also emits NFULA_HWHEADER based off skb->dev->hard_header_len, that change is probably desireable.

AI review doesn't like this, but I'm not so sure about the comment.

https://sashiko.dev/#/patchset/20261002124132.13387-1-fw%40strlen.de

NFULA_HWADDR (and related) are not univerally available even today, their presence depends on hook/location that invoked nfnl logger.

NFULA_HWHEADER would even contain the l3 header in the LLM-presented case. So I think this patch is fine as-is.