Commit efc0c21c authored by Elena Reshetova's avatar Elena Reshetova Committed by Martin Schwidefsky

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: default avatarElena Reshetova <elena.reshetova@intel.com>
Signed-off-by: default avatarHans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarDavid Windsor <dwindsor@gmail.com>
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent d04a4c76
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/refcount.h>
#include <uapi/asm/debug.h> #include <uapi/asm/debug.h>
#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */ #define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
...@@ -31,7 +32,7 @@ struct debug_view; ...@@ -31,7 +32,7 @@ struct debug_view;
typedef struct debug_info { typedef struct debug_info {
struct debug_info* next; struct debug_info* next;
struct debug_info* prev; struct debug_info* prev;
atomic_t ref_count; refcount_t ref_count;
spinlock_t lock; spinlock_t lock;
int level; int level;
int nr_areas; int nr_areas;
......
...@@ -277,7 +277,7 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas, ...@@ -277,7 +277,7 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *)); memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS * memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS *
sizeof(struct dentry*)); sizeof(struct dentry*));
atomic_set(&(rc->ref_count), 0); refcount_set(&(rc->ref_count), 0);
return rc; return rc;
...@@ -361,7 +361,7 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas, ...@@ -361,7 +361,7 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
debug_area_last = rc; debug_area_last = rc;
rc->next = NULL; rc->next = NULL;
debug_info_get(rc); refcount_set(&rc->ref_count, 1);
out: out:
return rc; return rc;
} }
...@@ -416,7 +416,7 @@ static void ...@@ -416,7 +416,7 @@ static void
debug_info_get(debug_info_t * db_info) debug_info_get(debug_info_t * db_info)
{ {
if (db_info) if (db_info)
atomic_inc(&db_info->ref_count); refcount_inc(&db_info->ref_count);
} }
/* /*
...@@ -431,7 +431,7 @@ debug_info_put(debug_info_t *db_info) ...@@ -431,7 +431,7 @@ debug_info_put(debug_info_t *db_info)
if (!db_info) if (!db_info)
return; return;
if (atomic_dec_and_test(&db_info->ref_count)) { if (refcount_dec_and_test(&db_info->ref_count)) {
for (i = 0; i < DEBUG_MAX_VIEWS; i++) { for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
if (!db_info->views[i]) if (!db_info->views[i])
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment