Skip to content

Commit efc0c21

Browse files
ereshetovaMartin Schwidefsky
authored andcommitted
s390: convert debug_info.ref_count 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: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent d04a4c7 commit efc0c21

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎arch/s390/include/asm/debug.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/spinlock.h>
1111
#include <linux/kernel.h>
1212
#include <linux/time.h>
13+
#include <linux/refcount.h>
1314
#include <uapi/asm/debug.h>
1415

1516
#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
@@ -31,7 +32,7 @@ struct debug_view;
3132
typedef struct debug_info {
3233
struct debug_info* next;
3334
struct debug_info* prev;
34-
atomic_t ref_count;
35+
refcount_t ref_count;
3536
spinlock_t lock;
3637
int level;
3738
int nr_areas;

‎arch/s390/kernel/debug.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
277277
memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
278278
memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS *
279279
sizeof(struct dentry*));
280-
atomic_set(&(rc->ref_count), 0);
280+
refcount_set(&(rc->ref_count), 0);
281281

282282
return rc;
283283

@@ -361,7 +361,7 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
361361
debug_area_last = rc;
362362
rc->next = NULL;
363363

364-
debug_info_get(rc);
364+
refcount_set(&rc->ref_count, 1);
365365
out:
366366
return rc;
367367
}
@@ -416,7 +416,7 @@ static void
416416
debug_info_get(debug_info_t * db_info)
417417
{
418418
if (db_info)
419-
atomic_inc(&db_info->ref_count);
419+
refcount_inc(&db_info->ref_count);
420420
}
421421

422422
/*
@@ -431,7 +431,7 @@ debug_info_put(debug_info_t *db_info)
431431

432432
if (!db_info)
433433
return;
434-
if (atomic_dec_and_test(&db_info->ref_count)) {
434+
if (refcount_dec_and_test(&db_info->ref_count)) {
435435
for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
436436
if (!db_info->views[i])
437437
continue;

0 commit comments

Comments
 (0)