lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CABPqkBQkzyATS_W31-ND6tgB3QBoro-G9rGCSgOJAfBKifdRHQ@mail.gmail.com>
Date:   Thu, 6 Sep 2018 08:04:02 -0700
From:   Stephane Eranian <eranian@...gle.com>
To:     Jiri Olsa <jolsa@...hat.com>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        Arnaldo Carvalho de Melo <acme@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>, mingo@...e.hu,
        Namhyung Kim <namhyung@...nel.org>
Subject: Re: [PATCHv3] perf tools: Add struct ordered_events_buffer layer

On Thu, Sep 6, 2018 at 6:29 AM Jiri Olsa <jolsa@...hat.com> wrote:
>
> On Mon, Sep 03, 2018 at 07:37:56PM -0700, Stephane Eranian wrote:
>
> SNIP
>
> >
> > I think the code is correct now for the issue related to uninitialized pointer.
> > But there is still one problem I found stressing the code with max_alloc_size.
> > The way the following is written:
> >
> >        if (!list_empty(cache)) {
> >                 new = list_entry(cache->next, struct ordered_event, list);
> >                 list_del(&new->list);
> >         } else if (oe->buffer) {
> >                 new = oe->buffer + oe->buffer_idx;
> >                 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER)
> >                         oe->buffer = NULL;
> >         } else if (oe->cur_alloc_size < oe->max_alloc_size) {
> >                 size_t size = sizeof(*oe->buffer) MAX_SAMPLE_BUFFER *
> > sizeof(*new);
> >
> >                 oe->buffer = malloc(size);
> >                 if (!oe->buffer) {
> >                         free_dup_event(oe, new_event);
> >                         return NULL;
> >                 }
> >
> >                 pr("alloc size %" PRIu64 "B (+%zu), max %" PRIu64 "B\n",
> >                    oe->cur_alloc_size, size, oe->max_alloc_size);
> >
> >                 oe->cur_alloc_size += size;
> >
> > You can end up with oe->cur_alloc_size > oe->max_alloc_size in case
> > the max limit is
> > really low (< size_t size = sizeof (*oe->buffer) + MAX_SAMPLE_BUFFER *
> > sizeof(*new);
> > So I think to make sure you can never allocate more than the max, you
> > have to do:
> >
> >       size_t size = sizeof(*oe->buffer) MAX_SAMPLE_BUFFER * sizeof(*new);
> >        if (!list_empty(cache)) {
> >                 new = list_entry(cache->next, struct ordered_event, list);
> >                 list_del(&new->list);
> >         } else if (oe->buffer) {
> >                 new = oe->buffer + oe->buffer_idx;
> >                 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER)
> >                         oe->buffer = NULL;
> >         } else if ((oe->cur_alloc_size + size) < oe->max_alloc_size) {
> >
> > Then you will never allocate more than the max.
> > I think with this change, we are okay.
> > Tested-by: Stephane Eranian <eranian@...gle.com>
>
> yep, makes sense.. something like below then
> I'll post it on top of the previous patch
>
Yes. This works.
Thanks.


> thanks,
> jirka
>
>
> ---
> diff --git a/tools/perf/util/ordered-events.c b/tools/perf/util/ordered-events.c
> index 87171e8fd70d..2d1d0f3c8f77 100644
> --- a/tools/perf/util/ordered-events.c
> +++ b/tools/perf/util/ordered-events.c
> @@ -101,6 +101,7 @@ static struct ordered_event *alloc_event(struct ordered_events *oe,
>         struct list_head *cache = &oe->cache;
>         struct ordered_event *new = NULL;
>         union perf_event *new_event;
> +       size_t size;
>
>         new_event = dup_event(oe, event);
>         if (!new_event)
> @@ -133,6 +134,8 @@ static struct ordered_event *alloc_event(struct ordered_events *oe,
>          * Removal of ordered event object moves it from events to
>          * the cache list.
>          */
> +       size = sizeof(*oe->buffer) + MAX_SAMPLE_BUFFER * sizeof(*new);
> +
>         if (!list_empty(cache)) {
>                 new = list_entry(cache->next, struct ordered_event, list);
>                 list_del(&new->list);
> @@ -140,10 +143,7 @@ static struct ordered_event *alloc_event(struct ordered_events *oe,
>                 new = &oe->buffer->event[oe->buffer_idx];
>                 if (++oe->buffer_idx == MAX_SAMPLE_BUFFER)
>                         oe->buffer = NULL;
> -       } else if (oe->cur_alloc_size < oe->max_alloc_size) {
> -               size_t size = sizeof(*oe->buffer) +
> -                             MAX_SAMPLE_BUFFER * sizeof(*new);
> -
> +       } else if ((oe->cur_alloc_size + size) < oe->max_alloc_size) {
>                 oe->buffer = malloc(size);
>                 if (!oe->buffer) {
>                         free_dup_event(oe, new_event);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ