Skip to content

Commit 07f2282

Browse files
ereshetovadavem330
authored andcommitted
net, ax25: convert ax25_uid_assoc.refcount 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 c638457 commit 07f2282

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

‎include/net/ax25.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <linux/timer.h>
1212
#include <linux/list.h>
1313
#include <linux/slab.h>
14-
#include <linux/atomic.h>
14+
#include <linux/refcount.h>
1515
#include <net/neighbour.h>
1616
#include <net/sock.h>
1717

@@ -158,7 +158,7 @@ enum {
158158

159159
typedef struct ax25_uid_assoc {
160160
struct hlist_node uid_node;
161-
atomic_t refcount;
161+
refcount_t refcount;
162162
kuid_t uid;
163163
ax25_address call;
164164
} ax25_uid_assoc;
@@ -167,11 +167,11 @@ typedef struct ax25_uid_assoc {
167167
hlist_for_each_entry(__ax25, list, uid_node)
168168

169169
#define ax25_uid_hold(ax25) \
170-
atomic_inc(&((ax25)->refcount))
170+
refcount_inc(&((ax25)->refcount))
171171

172172
static inline void ax25_uid_put(ax25_uid_assoc *assoc)
173173
{
174-
if (atomic_dec_and_test(&assoc->refcount)) {
174+
if (refcount_dec_and_test(&assoc->refcount)) {
175175
kfree(assoc);
176176
}
177177
}

‎net/ax25/ax25_uid.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int ax25_uid_ioctl(int cmd, struct sockaddr_ax25 *sax)
107107
if ((ax25_uid = kmalloc(sizeof(*ax25_uid), GFP_KERNEL)) == NULL)
108108
return -ENOMEM;
109109

110-
atomic_set(&ax25_uid->refcount, 1);
110+
refcount_set(&ax25_uid->refcount, 1);
111111
ax25_uid->uid = sax25_kuid;
112112
ax25_uid->call = sax->sax25_call;
113113

0 commit comments

Comments
 (0)