* [PATCH] selinux: fix potential use-after-free in sel_netif_flush()
@ 2026-11-09 16:59 mdshahid03
2026-11-09 17:58 ` Stephen Smalley
0 siblings, 1 reply; 2+ messages in thread
From: mdshahid03 @ 2026-11-09 16:59 UTC (permalink / raw)
To: Paul Moore, Stephen Smalley
Cc: Ondrej Mosnáček, selinux, linux-kernel, Mohammad Shahid
From: Mohammad Shahid <mdshahid03@gmail.com>
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.
Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
---
security/selinux/netif.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/security/selinux/netif.c b/security/selinux/netif.c
index fa6d24a37c39..d5e258fd52aa 100644
--- a/security/selinux/netif.c
+++ b/security/selinux/netif.c
@@ -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);
}
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] selinux: fix potential use-after-free in sel_netif_flush()
2026-11-09 16:59 [PATCH] selinux: fix potential use-after-free in sel_netif_flush() mdshahid03
@ 2026-11-09 17:58 ` Stephen Smalley
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Smalley @ 2026-11-09 17:58 UTC (permalink / raw)
To: mdshahid03; +Cc: Paul Moore, Ondrej Mosnáček, selinux, linux-kernel
On Mon, Nov 9, 2026 at 12:00 PM <mdshahid03@gmail.com> wrote:
>
> From: Mohammad Shahid <mdshahid03@gmail.com>
>
> 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.
>
> Signed-off-by: Mohammad Shahid <mdshahid03@gmail.com>
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-09 17:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 16:59 [PATCH] selinux: fix potential use-after-free in sel_netif_flush() mdshahid03
2026-11-09 17:58 ` Stephen Smalley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®