Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1585419 > unrolled thread
| Started by | Elena Reshetova <elena.reshetova@intel.com> |
|---|---|
| First post | 2017-02-21 16:40 +0100 |
| Last post | 2017-02-22 22:00 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH 6/9] tools: convert map_groups.refcnt from atomic_t to refcount_t Elena Reshetova <elena.reshetova@intel.com> - 2017-02-21 16:40 +0100
Re: [PATCH 6/9] tools: convert map_groups.refcnt from atomic_t to refcount_t Arnaldo Carvalho de Melo <acme@kernel.org> - 2017-02-22 22:00 +0100
| From | Elena Reshetova <elena.reshetova@intel.com> |
|---|---|
| Date | 2017-02-21 16:40 +0100 |
| Subject | [PATCH 6/9] tools: convert map_groups.refcnt from atomic_t to refcount_t |
| Message-ID | <tdkHL-4r9-11@gated-at.bofh.it> |
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>
---
tools/perf/util/map.c | 4 ++--
tools/perf/util/map.h | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index f0e2428..1d9ebcf 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -485,7 +485,7 @@ void map_groups__init(struct map_groups *mg, struct machine *machine)
maps__init(&mg->maps[i]);
}
mg->machine = machine;
- atomic_set(&mg->refcnt, 1);
+ refcount_set(&mg->refcnt, 1);
}
static void __maps__purge(struct maps *maps)
@@ -547,7 +547,7 @@ void map_groups__delete(struct map_groups *mg)
void map_groups__put(struct map_groups *mg)
{
- if (mg && atomic_dec_and_test(&mg->refcnt))
+ if (mg && refcount_dec_and_test(&mg->refcnt))
map_groups__delete(mg);
}
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 9545ff3..c8a5a64 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -67,7 +67,7 @@ struct maps {
struct map_groups {
struct maps maps[MAP__NR_TYPES];
struct machine *machine;
- atomic_t refcnt;
+ refcount_t refcnt;
};
struct map_groups *map_groups__new(struct machine *machine);
@@ -77,7 +77,7 @@ bool map_groups__empty(struct map_groups *mg);
static inline struct map_groups *map_groups__get(struct map_groups *mg)
{
if (mg)
- atomic_inc(&mg->refcnt);
+ refcount_inc(&mg->refcnt);
return mg;
}
--
2.7.4
[toc] | [next] | [standalone]
| From | Arnaldo Carvalho de Melo <acme@kernel.org> |
|---|---|
| Date | 2017-02-22 22:00 +0100 |
| Subject | Re: [PATCH 6/9] tools: convert map_groups.refcnt from atomic_t to refcount_t |
| Message-ID | <tdMb1-7mE-35@gated-at.bofh.it> |
| In reply to | #1585419 |
Em Tue, Feb 21, 2017 at 05:35:00PM +0200, Elena Reshetova escreveu:
> 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.
You missed tools/perf/tests/thread-mg-share.c
I fixed it up.
> 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>
> ---
> tools/perf/util/map.c | 4 ++--
> tools/perf/util/map.h | 4 ++--
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index f0e2428..1d9ebcf 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -485,7 +485,7 @@ void map_groups__init(struct map_groups *mg, struct machine *machine)
> maps__init(&mg->maps[i]);
> }
> mg->machine = machine;
> - atomic_set(&mg->refcnt, 1);
> + refcount_set(&mg->refcnt, 1);
> }
>
> static void __maps__purge(struct maps *maps)
> @@ -547,7 +547,7 @@ void map_groups__delete(struct map_groups *mg)
>
> void map_groups__put(struct map_groups *mg)
> {
> - if (mg && atomic_dec_and_test(&mg->refcnt))
> + if (mg && refcount_dec_and_test(&mg->refcnt))
> map_groups__delete(mg);
> }
>
> diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
> index 9545ff3..c8a5a64 100644
> --- a/tools/perf/util/map.h
> +++ b/tools/perf/util/map.h
> @@ -67,7 +67,7 @@ struct maps {
> struct map_groups {
> struct maps maps[MAP__NR_TYPES];
> struct machine *machine;
> - atomic_t refcnt;
> + refcount_t refcnt;
> };
>
> struct map_groups *map_groups__new(struct machine *machine);
> @@ -77,7 +77,7 @@ bool map_groups__empty(struct map_groups *mg);
> static inline struct map_groups *map_groups__get(struct map_groups *mg)
> {
> if (mg)
> - atomic_inc(&mg->refcnt);
> + refcount_inc(&mg->refcnt);
> return mg;
> }
>
> --
> 2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web