Skip to content

Commit 58951dd

Browse files
ereshetovadavem330
authored andcommitted
net, llc: convert llc_sap.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: 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>
1 parent bf72ace commit 58951dd

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

‎include/net/llc.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct llc_sap {
5555
unsigned char state;
5656
unsigned char p_bit;
5757
unsigned char f_bit;
58-
atomic_t refcnt;
58+
refcount_t refcnt;
5959
int (*rcv_func)(struct sk_buff *skb,
6060
struct net_device *dev,
6161
struct packet_type *pt,
@@ -113,14 +113,14 @@ struct llc_sap *llc_sap_open(unsigned char lsap,
113113
struct net_device *orig_dev));
114114
static inline void llc_sap_hold(struct llc_sap *sap)
115115
{
116-
atomic_inc(&sap->refcnt);
116+
refcount_inc(&sap->refcnt);
117117
}
118118

119119
void llc_sap_close(struct llc_sap *sap);
120120

121121
static inline void llc_sap_put(struct llc_sap *sap)
122122
{
123-
if (atomic_dec_and_test(&sap->refcnt))
123+
if (refcount_dec_and_test(&sap->refcnt))
124124
llc_sap_close(sap);
125125
}
126126

‎net/llc/llc_core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static struct llc_sap *llc_sap_alloc(void)
4141
spin_lock_init(&sap->sk_lock);
4242
for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++)
4343
INIT_HLIST_NULLS_HEAD(&sap->sk_laddr_hash[i], i);
44-
atomic_set(&sap->refcnt, 1);
44+
refcount_set(&sap->refcnt, 1);
4545
}
4646
return sap;
4747
}

0 commit comments

Comments
 (0)