Commit d12f3827 authored by Reshetova, Elena's avatar Reshetova, Elena Committed by David S. Miller
Browse files

net, ipv6: convert xfrm6_tunnel_spi.refcnt from atomic_t to refcount_t

refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
Signed-off-by: default avatarElena Reshetova <>
Signed-off-by: default avatarHans Liljestrand <>
Signed-off-by: default avatarKees Cook <>
Signed-off-by: default avatarDavid Windsor <>
Signed-off-by: default avatarDavid S. Miller <>
parent affa78bc
......@@ -59,7 +59,7 @@ struct xfrm6_tunnel_spi {
struct hlist_node list_byspi;
xfrm_address_t addr;
u32 spi;
atomic_t refcnt;
refcount_t refcnt;
struct rcu_head rcu_head;
......@@ -160,7 +160,7 @@ static u32 __xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr)
memcpy(&x6spi->addr, saddr, sizeof(x6spi->addr));
x6spi->spi = spi;
atomic_set(&x6spi->refcnt, 1);
refcount_set(&x6spi->refcnt, 1);
hlist_add_head_rcu(&x6spi->list_byspi, &xfrm6_tn->spi_byspi[index]);
......@@ -178,7 +178,7 @@ __be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr)
x6spi = __xfrm6_tunnel_spi_lookup(net, saddr);
if (x6spi) {
spi = x6spi->spi;
} else
spi = __xfrm6_tunnel_alloc_spi(net, saddr);
......@@ -207,7 +207,7 @@ static void xfrm6_tunnel_free_spi(struct net *net, xfrm_address_t *saddr)
if (xfrm6_addr_equal(&x6spi->addr, saddr)) {
if (atomic_dec_and_test(&x6spi->refcnt)) {
if (refcount_dec_and_test(&x6spi->refcnt)) {
call_rcu(&x6spi->rcu_head, x6spi_destroy_rcu);
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