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

perf cgroup: Convert cgroup_sel.refcnt from atomic_t to refcount_t

The 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: David Windsor <dwindsor@gmail.com>
Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Kees Kook <keescook@chromium.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: alsa-devel@alsa-project.org
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Windsor <dwindsor@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hans Liljestrand <ishkamiel@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kees Kook <keescook@chromium.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matija Glavinic Pecotic <matija.glavinic-pecotic.ext@nokia.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1487691303-31858-2-git-send-email-elena.reshetova@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Elena Reshetova and committed by
Arnaldo Carvalho de Melo
79c5fe6d 73a9bf95

+5 -5
+3 -3
tools/perf/util/cgroup.c
··· 127 127 goto found; 128 128 n++; 129 129 } 130 - if (atomic_read(&cgrp->refcnt) == 0) 130 + if (refcount_read(&cgrp->refcnt) == 0) 131 131 free(cgrp); 132 132 133 133 return -1; 134 134 found: 135 - atomic_inc(&cgrp->refcnt); 135 + refcount_inc(&cgrp->refcnt); 136 136 counter->cgrp = cgrp; 137 137 return 0; 138 138 } 139 139 140 140 void close_cgroup(struct cgroup_sel *cgrp) 141 141 { 142 - if (cgrp && atomic_dec_and_test(&cgrp->refcnt)) { 142 + if (cgrp && refcount_dec_and_test(&cgrp->refcnt)) { 143 143 close(cgrp->fd); 144 144 zfree(&cgrp->name); 145 145 free(cgrp);
+2 -2
tools/perf/util/cgroup.h
··· 1 1 #ifndef __CGROUP_H__ 2 2 #define __CGROUP_H__ 3 3 4 - #include <linux/atomic.h> 4 + #include <linux/refcount.h> 5 5 6 6 struct option; 7 7 8 8 struct cgroup_sel { 9 9 char *name; 10 10 int fd; 11 - atomic_t refcnt; 11 + refcount_t refcnt; 12 12 }; 13 13 14 14