macvlan: fix possible UAF in macvlan_forward_source()
Subsystems (2)
PATCH 1/1 macvlan: fix possible UAF in macvlan_forward_source()
Add RCU protection on (struct macvlan_source_entry)->vlan.
Whenever macvlan_hash_del_source() is called, we must clear entry->vlan pointer before RCU grace period starts.
This allows macvlan_forward_source() to skip over entries queued for freeing.
Note that macvlan_dev are already RCU protected, as they are embedded in a standard netdev (netdev_priv(ndev)).
https://lore.kernel.org/netdev/[email protected]/T/#u
--- drivers/net/macvlan.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/macvlan.c +13 -7
@@ -59,7 +59,7 @@ struct macvlan_port {struct macvlan_source_entry {struct hlist_node hlist; -struct macvlan_dev *vlan; +struct macvlan_dev __rcu *vlan;unsigned char addr[6 +2 ]__aligned(sizeof(u16)) ;struct rcu_head rcu; };
@@ -146,7 +146,7 @@ static struct macvlan_source_entry *macvlan_hash_lookup_source(hlist_for_each_entry_rcu (entry, h, hlist,lockdep_rtnl_is_held ()) {if (ether_addr_equal_64bits (entry->addr, addr) && - entry->vlan == vlan) +rcu_access_pointer (entry->vlan) == vlan)return entry; }return NULL ;
@@ -168,7 +168,7 @@ static int macvlan_hash_add_source(struct macvlan_dev *vlan,return -ENOMEM ;ether_addr_copy (entry->addr, addr); - entry->vlan = vlan; +RCU_INIT_POINTER (entry->vlan, vlan); h = &port->vlan_source_hash[macvlan_eth_hash (addr)];hlist_add_head_rcu (&entry->hlist, h); vlan->macaddr_count++;
@@ -187,6 +187,7 @@ static void macvlan_hash_add(struct macvlan_dev *vlan)static void macvlan_hash_del_source (struct macvlan_source_entry *entry) { +RCU_INIT_POINTER (entry->vlan,NULL );hlist_del_rcu (&entry->hlist);kfree_rcu (entry, rcu); }
@@ -390,7 +391,7 @@ static void macvlan_flush_sources(struct macvlan_port *port,int i;hash_for_each_safe (port->vlan_source_hash, i, next, entry, hlist) -if (entry->vlan == vlan) +if (rcu_access_pointer (entry->vlan) == vlan)macvlan_hash_del_source (entry); vlan->macaddr_count =0 ;
@@ -433,9 +434,14 @@ static bool macvlan_forward_source(struct sk_buff *skb,hlist_for_each_entry_rcu (entry, h, hlist) {if (ether_addr_equal_64bits (entry->addr, addr)) { -if (entry->vlan->flags &MACVLAN_FLAG_NODST ) +struct macvlan_dev *vlan =rcu_dereference (entry->vlan); + +if (!vlan) +continue ; + +if (vlan->flags &MACVLAN_FLAG_NODST ) consume = true; -macvlan_forward_source_one (skb, entry->vlan); +macvlan_forward_source_one (skb, vlan); } }
@@ -1680,7 +1686,7 @@ static int macvlan_fill_info_macaddr(struct sk_buff *skb,struct macvlan_source_entry *entry;hlist_for_each_entry_rcu (entry, h, hlist,lockdep_rtnl_is_held ()) { -if (entry->vlan != vlan) +if (rcu_access_pointer (entry->vlan) != vlan)continue ;if (nla_put (skb,IFLA_MACVLAN_MACADDR ,ETH_ALEN , entry->addr))return 1 ;
Signature · 1 line
2.52.0.351.gbe84eed79e-goog
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 9 lines · On Thu, 8 Jan 2026 13:36:51 +0000 you wrote:
Add RCU protection on (struct macvlan_source_entry)->vlan.
Whenever
macvlan_hash_del_source()is called, we must clearentry->vlanpointer before RCU grace period starts.This allows
macvlan_forward_source()to skip over
entries queued for freeing.[...]
Here is the summary with links:
- macvlan: fix possible UAF in macvlan_forward_source()
https://git.kernel.org/netdev/net/c/7470a7a63dc1
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html