Skip to content

Commit

Permalink
net/xen-netback: prevent UAF in xenvif_flush_hash()
Browse files Browse the repository at this point in the history
During the list_for_each_entry_rcu iteration call of xenvif_flush_hash,
kfree_rcu does not exist inside the rcu read critical section, so if
kfree_rcu is called when the rcu grace period ends during the iteration,
UAF occurs when accessing head->next after the entry becomes free.

Therefore, to solve this, you need to change it to list_for_each_entry_safe.

Signed-off-by: Jeongjun Park <aha310510@gmail.com>
Link: https://patch.msgid.link/20240822181109.2577354-1-aha310510@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jeongjun Park authored and Jakub Kicinski committed Aug 29, 2024
1 parent e5899b6 commit 0fa5e94
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/net/xen-netback/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,15 @@ static u32 xenvif_new_hash(struct xenvif *vif, const u8 *data,

static void xenvif_flush_hash(struct xenvif *vif)
{
struct xenvif_hash_cache_entry *entry;
struct xenvif_hash_cache_entry *entry, *n;
unsigned long flags;

if (xenvif_hash_cache_size == 0)
return;

spin_lock_irqsave(&vif->hash.cache.lock, flags);

list_for_each_entry_rcu(entry, &vif->hash.cache.list, link,
lockdep_is_held(&vif->hash.cache.lock)) {
list_for_each_entry_safe(entry, n, &vif->hash.cache.list, link) {
list_del_rcu(&entry->link);
vif->hash.cache.count--;
kfree_rcu(entry, rcu);
Expand Down

0 comments on commit 0fa5e94

Please sign in to comment.