netlabel: fix a race in netlbl_unlhsh_condremove_iface()
Subsystems (4)
PATCH 1/1 netlabel: fix a race in netlbl_unlhsh_condremove_iface()
From: Linkui Xiao <[email protected]>
netlbl_unlhsh_condremove_iface() unlinks an interface entry and queues it for freeing without checking ->valid, so it can do both a second time for an entry that somebody else has already removed.
netlbl_unlhsh_remove() looks the entry up under RCU, drops the lock, removes the address entry and only then calls condremove_iface(). If a NETDEV_DOWN notifier runs in between it takes netlbl_unlhsh_lock, clears ->valid and does list_del_rcu() plus call_rcu() on the same entry, and nothing serialises the notifier against a STATICREMOVE doit, which only holds genl_lock. The second list_del_rcu() then dereferences the LIST_POISON2 that the first one left in ->prev, and the second call_rcu() queues an rcu_head that is already queued, so the entry is freed twice.
The default entry can hit the same thing without any notifier: smackfs reaches netlbl_unlhsh_remove() through netlbl_cfg_unlbl_static_del() and is not serialised against a concurrent STATICREMOVEDEF, so two callers can each remove one address from the same entry and both find it empty.
Check ->valid before unlinking, the way netlbl_unlhsh_netdev_handler() and netlbl_domhsh_remove_entry() already do. Everything that invalidates an entry does so under netlbl_unlhsh_lock, so the check is reliable.
--- net/netlabel/netlabel_unlabeled.c | 2 ++ 1 file changed, 2 insertions(+)
net/netlabel/netlabel_unlabeled.c +2 -0
@@ -582,6 +582,8 @@ static void netlbl_unlhsh_condremove_iface(struct netlbl_unlhsh_iface *iface)#endif /* IPv6 */ spin_lock (&netlbl_unlhsh_lock); +if (!iface->valid) + goto unlhsh_condremove_failure; netlbl_af4list_foreach_rcu(iter4, &iface->addr4_list) goto unlhsh_condremove_failure;#if IS_ENABLED (CONFIG_IPV6 )
Signature · 1 line
2.25.1
PATCH 1/1 netlabel: fix duplicate IPv4 entries in the staticlist dump
From: Linkui Xiao <[email protected]>
netlbl_unlabel_staticlist() keeps its dump progress in cb->args[]: the bucket, the offset of the interface in that bucket, and the IPv4 and IPv6 offsets in that interface. It clears iter_addr4 once the whole IPv4 list of an interface has been walked, so if the skb fills up while the IPv6 list of the same interface is being dumped, cb->args[2] is saved as zero. The next round resumes on that interface and dumps its IPv4 entries a second time, which shows up as duplicated lines in "netlbl_unlabel -l".
This needs an interface that carries both IPv4 and IPv6 static entries and a configuration large enough for the dump to span more than one netlink message, but once it does the duplication is reproducible on every dump.
Clear both address counters when an interface is started instead of when it is finished. The skip counters still have to be cleared only after their own list has been walked in full, otherwise the offset saved for the interface where the previous dump stopped would also be applied to the interfaces that follow it.
netlbl_unlabel_staticlistdef() dumps a single interface and never resets these counters, so it is not affected.
--- net/netlabel/netlabel_unlabeled.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/netlabel/netlabel_unlabeled.c +6 -2
@@ -1171,6 +1171,12 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb,if (!iface->valid || iter_chain++ < skip_chain)continue ; +/* Restart the address counters for this interface, the +* skip counters stay until their own list has been +* walked in full. +*/ + iter_addr4 =0 ; + iter_addr6 =0 ;netlbl_af4list_foreach_rcu (addr4, &iface->addr4_list) {if (iter_addr4++ < skip_addr4)
@@ -1186,7 +1192,6 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb, goto unlabel_staticlist_return; } } - iter_addr4 =0 ; skip_addr4 =0 ;#if IS_ENABLED (CONFIG_IPV6 ) netlbl_af6list_foreach_rcu(addr6,
@@ -1204,7 +1209,6 @@ static int netlbl_unlabel_staticlist(struct sk_buff *skb, goto unlabel_staticlist_return; } } - iter_addr6 =0 ; skip_addr6 =0 ;#endif /* IPv6 */ }
Signature · 1 line
2.25.1
[email protected]
AI reviewRe: [PATCH net] netlabel: fix duplicate IPv4 entries in the staticlist dump
Sashiko has reviewed this patch and found no issues.
Quoted 20 lines
From: Linkui Xiao <[email protected]>
netlbl_unlabel_staticlist()keeps its dump progress in cb->args[]: the bucket, the offset of the interface in that bucket, and the IPv4 and IPv6 offsets in that interface. It clearsiter_addr4once the whole IPv4 list of an interface has been walked, so if the skb fills up while the IPv6 list of the same interface is being dumped, cb->args[2] is saved as zero. The next round resumes on that interface and dumps its IPv4 entries a second time, which shows up as duplicated lines in "netlbl_unlabel-l".This needs an interface that carries both IPv4 and IPv6 static entries and a configuration large enough for the dump to span more than one netlink message, but once it does the duplication is reproducible on every dump.
Clear both address counters when an interface is started instead of when it is finished. The skip counters still have to be cleared only after their own list has been walked in full, otherwise the offset saved for the interface where the previous dump stopped would also be applied to the interfaces that follow it.
Quoted 5 lines
netlbl_unlabel_staticlistdef()dumps a single interface and never resets these counters, so it is not affected.Fixes 866358ec331f ("netlabel: fix our progress tracking in netlbl_unlabel_staticlist()")Signed-off-by Linkui Xiao <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH net] netlabel: fix duplicate IPv4 entries in the staticlist dump
In reply to Linkui XiaoThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Re: [PATCH net] netlabel: fix duplicate IPv4 entries in the staticlist dump
Hi,
Quoted 9 lines · On 2026/11/27 17:30, [email protected] wrote:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
Quoted 6 lines
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Thanks for the reminder. The issue was discovered during manual code inspection while reviewing the netlabel IPv4 staticlist dump path. There was no production report or syzbot report.
I will not repost the series just for this. If a v2 is needed for other reasons, I will include this information in the cover letter and/or commit message.
Thanks,
Linkui Xiao
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 20 lines
From: Linkui Xiao <[email protected]>
netlbl_unlhsh_condremove_iface()unlinks an interface entry and queues it for freeing without checking ->valid, so it can do both a second time for an entry that somebody else has already removed.
netlbl_unlhsh_remove()looks the entry up under RCU, drops the lock, removes the address entry and only then callscondremove_iface(). If aNETDEV_DOWNnotifier runs in between it takesnetlbl_unlhsh_lock, clears ->valid and doeslist_del_rcu()pluscall_rcu()on the same entry, and nothing serialises the notifier against a STATICREMOVE doit, which only holdsgenl_lock. The secondlist_del_rcu()then dereferences theLIST_POISON2that the first one left in ->prev, and the secondcall_rcu()queues anrcu_headthat is already queued, so the entry is freed twice.The default entry can hit the same thing without any notifier: smackfs reaches
netlbl_unlhsh_remove()throughnetlbl_cfg_unlbl_static_del()and is not serialised against a concurrent STATICREMOVEDEF, so two callers can each remove one address from the same entry and both find it empty.
Quoted 6 lines
Check ->valid before unlinking, the way
netlbl_unlhsh_netdev_handler()andnetlbl_domhsh_remove_entry()already do. Everything that invalidates an entry does so undernetlbl_unlhsh_lock, so the check is reliable.Fixes 8cc44579d1bd ("NetLabel: Introduce static network labels for unlabeled connections")Signed-off-by Linkui Xiao <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewThis is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Signature · 2 lines
The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.
Hi,
Quoted 13 lines · On 2026/11/27 17:30, [email protected] wrote:
Hi!
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:
- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.
- Whether the issue was actually triggered, or is only theoretical (e.g. found by LLM and not proven at runtime). If it was triggered please include the symptoms, like the stack trace or kernel messages.
Quoted 6 lines
Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include the relevant info in the cover letter or commit messages.
Thanks for the reminder. The issue was discovered during manual code inspection while reviewing the netlabel IPv4 staticlist dump path. There was no production report or syzbot report.
I will not repost the series just for this. If a v2 is needed for other reasons, I will include this information in the cover letter and/or commit message.
Thanks,
Linkui Xiao