aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElena Reshetova <elena.reshetova@intel.com>2017-03-02 06:23:45 -0500
committerMartin Schwidefsky <schwidefsky@de.ibm.com>2017-05-11 10:35:32 -0400
commitefc0c21c9ea786d6f019d7df7b4e3932f3578d90 (patch)
tree8d116630c8560d2b1398235a1d501082aa1b88b0
parentd04a4c76f71dd5335f8e499b59617382d84e2b8d (diff)
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>
-rw-r--r--arch/s390/include/asm/debug.h3
-rw-r--r--arch/s390/kernel/debug.c8
2 files changed, 6 insertions, 5 deletions
diff --git a/arch/s390/include/asm/debug.h b/arch/s390/include/asm/debug.h
index 0206c8052328..df7b54ea956d 100644
--- a/arch/s390/include/asm/debug.h
+++ b/arch/s390/include/asm/debug.h
@@ -10,6 +10,7 @@
10#include <linux/spinlock.h> 10#include <linux/spinlock.h>
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/time.h> 12#include <linux/time.h>
13#include <linux/refcount.h>
13#include <uapi/asm/debug.h> 14#include <uapi/asm/debug.h>
14 15
15#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */ 16#define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */
@@ -31,7 +32,7 @@ struct debug_view;
31typedef struct debug_info { 32typedef struct debug_info {
32 struct debug_info* next; 33 struct debug_info* next;
33 struct debug_info* prev; 34 struct debug_info* prev;
34 atomic_t ref_count; 35 refcount_t ref_count;
35 spinlock_t lock; 36 spinlock_t lock;
36 int level; 37 int level;
37 int nr_areas; 38 int nr_areas;
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index 530226b6cb19..86b3e74f569e 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -277,7 +277,7 @@ debug_info_alloc(const char *name, int pages_per_area, int nr_areas,
277 memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *)); 277 memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *));
278 memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS * 278 memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS *
279 sizeof(struct dentry*)); 279 sizeof(struct dentry*));
280 atomic_set(&(rc->ref_count), 0); 280 refcount_set(&(rc->ref_count), 0);
281 281
282 return rc; 282 return rc;
283 283
@@ -361,7 +361,7 @@ debug_info_create(const char *name, int pages_per_area, int nr_areas,
361 debug_area_last = rc; 361 debug_area_last = rc;
362 rc->next = NULL; 362 rc->next = NULL;
363 363
364 debug_info_get(rc); 364 refcount_set(&rc->ref_count, 1);
365out: 365out:
366 return rc; 366 return rc;
367} 367}
@@ -416,7 +416,7 @@ static void
416debug_info_get(debug_info_t * db_info) 416debug_info_get(debug_info_t * db_info)
417{ 417{
418 if (db_info) 418 if (db_info)
419 atomic_inc(&db_info->ref_count); 419 refcount_inc(&db_info->ref_count);
420} 420}
421 421
422/* 422/*
@@ -431,7 +431,7 @@ debug_info_put(debug_info_t *db_info)
431 431
432 if (!db_info) 432 if (!db_info)
433 return; 433 return;
434 if (atomic_dec_and_test(&db_info->ref_count)) { 434 if (refcount_dec_and_test(&db_info->ref_count)) {
435 for (i = 0; i < DEBUG_MAX_VIEWS; i++) { 435 for (i = 0; i < DEBUG_MAX_VIEWS; i++) {
436 if (!db_info->views[i]) 436 if (!db_info->views[i])
437 continue; 437 continue;