aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/skbuff.h
diff options
context:
space:
mode:
authorReshetova, Elena <elena.reshetova@intel.com>2017-06-30 06:07:58 -0400
committerDavid S. Miller <davem@davemloft.net>2017-07-01 10:39:07 -0400
commit633547973ffc32fd2c815639d4675e1531f0896f (patch)
tree751ca7a379366af93f578d9f35f48339d4d2dd9b /include/linux/skbuff.h
parent53869cebce4bc53f71a080e7830600d4ae1ab712 (diff)
net: convert sk_buff.users 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: Elena Reshetova <elena.reshetova@intel.com> Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com> Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: David Windsor <dwindsor@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/skbuff.h')
-rw-r--r--include/linux/skbuff.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 005793e01bd2..90cbd86152da 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -761,7 +761,7 @@ struct sk_buff {
761 unsigned char *head, 761 unsigned char *head,
762 *data; 762 *data;
763 unsigned int truesize; 763 unsigned int truesize;
764 atomic_t users; 764 refcount_t users;
765}; 765};
766 766
767#ifdef __KERNEL__ 767#ifdef __KERNEL__
@@ -872,9 +872,9 @@ static inline bool skb_unref(struct sk_buff *skb)
872{ 872{
873 if (unlikely(!skb)) 873 if (unlikely(!skb))
874 return false; 874 return false;
875 if (likely(atomic_read(&skb->users) == 1)) 875 if (likely(refcount_read(&skb->users) == 1))
876 smp_rmb(); 876 smp_rmb();
877 else if (likely(!atomic_dec_and_test(&skb->users))) 877 else if (likely(!refcount_dec_and_test(&skb->users)))
878 return false; 878 return false;
879 879
880 return true; 880 return true;
@@ -1283,7 +1283,7 @@ static inline struct sk_buff *skb_queue_prev(const struct sk_buff_head *list,
1283 */ 1283 */
1284static inline struct sk_buff *skb_get(struct sk_buff *skb) 1284static inline struct sk_buff *skb_get(struct sk_buff *skb)
1285{ 1285{
1286 atomic_inc(&skb->users); 1286 refcount_inc(&skb->users);
1287 return skb; 1287 return skb;
1288} 1288}
1289 1289
@@ -1384,7 +1384,7 @@ static inline void __skb_header_release(struct sk_buff *skb)
1384 */ 1384 */
1385static inline int skb_shared(const struct sk_buff *skb) 1385static inline int skb_shared(const struct sk_buff *skb)
1386{ 1386{
1387 return atomic_read(&skb->users) != 1; 1387 return refcount_read(&skb->users) != 1;
1388} 1388}
1389 1389
1390/** 1390/**