Commit 55eabed6 authored by Reshetova, Elena's avatar Reshetova, Elena Committed by David S. Miller

net, xfrm: convert sec_path.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
situations.
Signed-off-by: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 850a6212
...@@ -1030,7 +1030,7 @@ struct xfrm_offload { ...@@ -1030,7 +1030,7 @@ struct xfrm_offload {
}; };
struct sec_path { struct sec_path {
atomic_t refcnt; refcount_t refcnt;
int len; int len;
int olen; int olen;
...@@ -1051,7 +1051,7 @@ static inline struct sec_path * ...@@ -1051,7 +1051,7 @@ static inline struct sec_path *
secpath_get(struct sec_path *sp) secpath_get(struct sec_path *sp)
{ {
if (sp) if (sp)
atomic_inc(&sp->refcnt); refcount_inc(&sp->refcnt);
return sp; return sp;
} }
...@@ -1060,7 +1060,7 @@ void __secpath_destroy(struct sec_path *sp); ...@@ -1060,7 +1060,7 @@ void __secpath_destroy(struct sec_path *sp);
static inline void static inline void
secpath_put(struct sec_path *sp) secpath_put(struct sec_path *sp)
{ {
if (sp && atomic_dec_and_test(&sp->refcnt)) if (sp && refcount_dec_and_test(&sp->refcnt))
__secpath_destroy(sp); __secpath_destroy(sp);
} }
......
...@@ -116,7 +116,7 @@ struct sec_path *secpath_dup(struct sec_path *src) ...@@ -116,7 +116,7 @@ struct sec_path *secpath_dup(struct sec_path *src)
for (i = 0; i < sp->len; i++) for (i = 0; i < sp->len; i++)
xfrm_state_hold(sp->xvec[i]); xfrm_state_hold(sp->xvec[i]);
} }
atomic_set(&sp->refcnt, 1); refcount_set(&sp->refcnt, 1);
return sp; return sp;
} }
EXPORT_SYMBOL(secpath_dup); EXPORT_SYMBOL(secpath_dup);
...@@ -126,7 +126,7 @@ int secpath_set(struct sk_buff *skb) ...@@ -126,7 +126,7 @@ int secpath_set(struct sk_buff *skb)
struct sec_path *sp; struct sec_path *sp;
/* Allocate new secpath or COW existing one. */ /* Allocate new secpath or COW existing one. */
if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) { if (!skb->sp || refcount_read(&skb->sp->refcnt) != 1) {
sp = secpath_dup(skb->sp); sp = secpath_dup(skb->sp);
if (!sp) if (!sp)
return -ENOMEM; return -ENOMEM;
......
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