Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Elena Reshetova and committed by
Martin Schwidefsky
efc0c21c d04a4c76

+6 -5
+2 -1
arch/s390/include/asm/debug.h
··· 10 10 #include <linux/spinlock.h> 11 11 #include <linux/kernel.h> 12 12 #include <linux/time.h> 13 + #include <linux/refcount.h> 13 14 #include <uapi/asm/debug.h> 14 15 15 16 #define DEBUG_MAX_LEVEL 6 /* debug levels range from 0 to 6 */ ··· 32 31 typedef struct debug_info { 33 32 struct debug_info* next; 34 33 struct debug_info* prev; 35 - atomic_t ref_count; 34 + refcount_t ref_count; 36 35 spinlock_t lock; 37 36 int level; 38 37 int nr_areas;
+4 -4
arch/s390/kernel/debug.c
··· 277 277 memset(rc->views, 0, DEBUG_MAX_VIEWS * sizeof(struct debug_view *)); 278 278 memset(rc->debugfs_entries, 0 ,DEBUG_MAX_VIEWS * 279 279 sizeof(struct dentry*)); 280 - atomic_set(&(rc->ref_count), 0); 280 + refcount_set(&(rc->ref_count), 0); 281 281 282 282 return rc; 283 283 ··· 361 361 debug_area_last = rc; 362 362 rc->next = NULL; 363 363 364 - debug_info_get(rc); 364 + refcount_set(&rc->ref_count, 1); 365 365 out: 366 366 return rc; 367 367 } ··· 416 416 debug_info_get(debug_info_t * db_info) 417 417 { 418 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 431 432 432 if (!db_info) 433 433 return; 434 - if (atomic_dec_and_test(&db_info->ref_count)) { 434 + if (refcount_dec_and_test(&db_info->ref_count)) { 435 435 for (i = 0; i < DEBUG_MAX_VIEWS; i++) { 436 436 if (!db_info->views[i]) 437 437 continue;