Commit b2662e7
net: nexthop: fix percpu use-after-free in remove_nh_grp_entry
When removing a nexthop from a group, remove_nh_grp_entry() publishes
the new group via rcu_assign_pointer() then immediately frees the
removed entry's percpu stats with free_percpu(). However, the
synchronize_net() grace period in the caller remove_nexthop_from_groups()
runs after the free. RCU readers that entered before the publish still
see the old group and can dereference the freed stats via
nh_grp_entry_stats_inc() -> get_cpu_ptr(nhge->stats), causing a
use-after-free on percpu memory.
Fix by deferring the free_percpu() until after synchronize_net() in the
caller. Removed entries are chained via nh_list onto a local deferred
free list. After the grace period completes and all RCU readers have
finished, the percpu stats are safely freed.
Fixes: f4676ea ("net: nexthop: Add nexthop group entry stats")
Cc: [email protected]
Signed-off-by: Mehul Rao <[email protected]>
Reviewed-by: Eric Dumazet <[email protected]>
Reviewed-by: Ido Schimmel <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>1 parent 288598d commit b2662e7
1 file changed
Lines changed: 11 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2002 | 2002 | | |
2003 | 2003 | | |
2004 | 2004 | | |
2005 | | - | |
| 2005 | + | |
| 2006 | + | |
2006 | 2007 | | |
2007 | 2008 | | |
2008 | 2009 | | |
| |||
2062 | 2063 | | |
2063 | 2064 | | |
2064 | 2065 | | |
2065 | | - | |
2066 | 2066 | | |
| 2067 | + | |
2067 | 2068 | | |
2068 | 2069 | | |
2069 | 2070 | | |
| |||
2083 | 2084 | | |
2084 | 2085 | | |
2085 | 2086 | | |
| 2087 | + | |
2086 | 2088 | | |
2087 | 2089 | | |
2088 | 2090 | | |
| |||
2091 | 2093 | | |
2092 | 2094 | | |
2093 | 2095 | | |
2094 | | - | |
| 2096 | + | |
2095 | 2097 | | |
2096 | 2098 | | |
2097 | 2099 | | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
2098 | 2106 | | |
2099 | 2107 | | |
2100 | 2108 | | |
| |||
0 commit comments