Commit 27e41fcf authored by Robert Shearman's avatar Robert Shearman Committed by David S. Miller

ipv6: fix possible use after free of dev stats

The memory pointed to by idev->stats.icmpv6msgdev,
idev->stats.icmpv6dev and idev->stats.ipv6 can each be used in an RCU
read context without taking a reference on idev. For example, through
IP6_*_STATS_* calls in ip6_rcv. These memory blocks are freed without
waiting for an RCU grace period to elapse. This could lead to the
memory being written to after it has been freed.

Fix this by using call_rcu to free the memory used for stats, as well
as idev after an RCU grace period has elapsed.
Signed-off-by: default avatarRobert Shearman <rshearma@brocade.com>
Acked-by: default avatarHannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1489bdee
...@@ -133,6 +133,14 @@ static void snmp6_free_dev(struct inet6_dev *idev) ...@@ -133,6 +133,14 @@ static void snmp6_free_dev(struct inet6_dev *idev)
free_percpu(idev->stats.ipv6); free_percpu(idev->stats.ipv6);
} }
static void in6_dev_finish_destroy_rcu(struct rcu_head *head)
{
struct inet6_dev *idev = container_of(head, struct inet6_dev, rcu);
snmp6_free_dev(idev);
kfree(idev);
}
/* Nobody refers to this device, we may destroy it. */ /* Nobody refers to this device, we may destroy it. */
void in6_dev_finish_destroy(struct inet6_dev *idev) void in6_dev_finish_destroy(struct inet6_dev *idev)
...@@ -151,7 +159,6 @@ void in6_dev_finish_destroy(struct inet6_dev *idev) ...@@ -151,7 +159,6 @@ void in6_dev_finish_destroy(struct inet6_dev *idev)
pr_warn("Freeing alive inet6 device %p\n", idev); pr_warn("Freeing alive inet6 device %p\n", idev);
return; return;
} }
snmp6_free_dev(idev); call_rcu(&idev->rcu, in6_dev_finish_destroy_rcu);
kfree_rcu(idev, rcu);
} }
EXPORT_SYMBOL(in6_dev_finish_destroy); EXPORT_SYMBOL(in6_dev_finish_destroy);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment