Skip to content

Commit dab6b5d

Browse files
ereshetovaholtmann
authored andcommitted
Bluetooth: convert rfcomm_dlc.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: Marcel Holtmann <marcel@holtmann.org>
1 parent 9232259 commit dab6b5d

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎include/net/bluetooth/rfcomm.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
SOFTWARE IS DISCLAIMED.
2222
*/
2323

24+
#include <linux/refcount.h>
25+
2426
#ifndef __RFCOMM_H
2527
#define __RFCOMM_H
2628

@@ -174,7 +176,7 @@ struct rfcomm_dlc {
174176
struct mutex lock;
175177
unsigned long state;
176178
unsigned long flags;
177-
atomic_t refcnt;
179+
refcount_t refcnt;
178180
u8 dlci;
179181
u8 addr;
180182
u8 priority;
@@ -247,12 +249,12 @@ struct rfcomm_dlc *rfcomm_dlc_exists(bdaddr_t *src, bdaddr_t *dst, u8 channel);
247249

248250
static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
249251
{
250-
atomic_inc(&d->refcnt);
252+
refcount_inc(&d->refcnt);
251253
}
252254

253255
static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
254256
{
255-
if (atomic_dec_and_test(&d->refcnt))
257+
if (refcount_dec_and_test(&d->refcnt))
256258
rfcomm_dlc_free(d);
257259
}
258260

‎net/bluetooth/rfcomm/core.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio)
311311

312312
skb_queue_head_init(&d->tx_queue);
313313
mutex_init(&d->lock);
314-
atomic_set(&d->refcnt, 1);
314+
refcount_set(&d->refcnt, 1);
315315

316316
rfcomm_dlc_clear_state(d);
317317

@@ -342,7 +342,7 @@ static void rfcomm_dlc_unlink(struct rfcomm_dlc *d)
342342
{
343343
struct rfcomm_session *s = d->session;
344344

345-
BT_DBG("dlc %p refcnt %d session %p", d, atomic_read(&d->refcnt), s);
345+
BT_DBG("dlc %p refcnt %d session %p", d, refcount_read(&d->refcnt), s);
346346

347347
list_del(&d->list);
348348
d->session = NULL;

0 commit comments

Comments
 (0)