Skip to contentSkip to conversation

selinux: fix potential use-after-free in sel_netif_flush()

PATCH In review [email protected] 3 participants 3 messages Nov 9 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: fix potential use-after-free in sel_netif_flush()

From: Mohammad Shahid <[email protected]>

sel_netif_flush() use list_for_each_entry() while deleting entries from the network interface list.

Use list_for_each_entry_safe() to save the next entry before deleting the current one and avoid accessing freed memory.

The issue is reported by smatch as potential use-after-free.

---
 security/selinux/netif.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
security/selinux/netif.c +2 -2
index fa6d24a37c39..d5e258fd52aa 100644
@@ -242,11 +242,11 @@ static void sel_netif_kill(const struct net *ns, int ifindex)
 void sel_netif_flush(void)
 {
 	int idx;
-	struct sel_netif *netif;
+	struct sel_netif *netif, *tmp;
 
 	spin_lock_bh(&sel_netif_lock);
 	for (idx = 0; idx < SEL_NETIF_HASH_SIZE; idx++)
-		list_for_each_entry(netif, &sel_netif_hash[idx], list)
+		list_for_each_entry_safe(netif, tmp, &sel_netif_hash[idx], list)
 			sel_netif_destroy(netif);
 	spin_unlock_bh(&sel_netif_lock);
 }
Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

From: Mohammad Shahid <[email protected]>

sel_netif_flush() use list_for_each_entry() while deleting entries from the network interface list.

Use list_for_each_entry_safe() to save the next entry before deleting the current one and avoid accessing freed memory.

The issue is reported by smatch as potential use-after-free.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to [email protected]
Quoted 6 lines · On Mon, Nov 9, 2026 at 12:00 PM <[email protected]> wrote:

From: Mohammad Shahid <[email protected]>

sel_netif_flush() use list_for_each_entry() while deleting entries from the network interface list.

Quoted 6 lines

Use list_for_each_entry_safe() to save the next entry before deleting the current one and avoid accessing freed memory.

The issue is reported by smatch as potential use-after-free.

This isn't actually necessary AFAICT - sel_netif_destroy() preserves the forward link with list_del_rcu() and defers reclamation with kfree_rcu(). The loop holds spin_lock_bh() throughout, so the current entry remains alive through the iterator increment.