2023-06-19 08:43:57

by Li Dong

[permalink] [raw]
Subject: [PATCH] tools: Fix incorrect calculation of object size by sizeof

What we need to calculate is the size of the object, not the size of the
pointer.

Signed-off-by: Li Dong <[email protected]>
---
tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
index 59063ec98619..25fcd6630a4d 100644
--- a/tools/perf/util/scripting-engines/trace-event-python.c
+++ b/tools/perf/util/scripting-engines/trace-event-python.c
@@ -771,12 +771,12 @@ static void set_regs_in_dict(PyObject *dict,
int size = __sw_hweight64(attr->sample_regs_intr) * 28;
char *bf = malloc(size);

- regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
+ regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size);

pydict_set_item_string_decref(dict, "iregs",
_PyUnicode_FromString(bf));

- regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
+ regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, size);

pydict_set_item_string_decref(dict, "uregs",
_PyUnicode_FromString(bf));
--
2.31.1.windows.1



2023-06-20 19:56:05

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH] tools: Fix incorrect calculation of object size by sizeof

Hello,

On Mon, Jun 19, 2023 at 1:21 AM Li Dong <[email protected]> wrote:
>
> What we need to calculate is the size of the object, not the size of the
> pointer.
>
> Signed-off-by: Li Dong <[email protected]>

Since this problem was introduced in the current dev cycle and not in the
mainline yet, I think we can skip the Fixes tag.

Acked-by: Namhyung Kim <[email protected]>

Thanks,
Namhyung


> ---
> tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c
> index 59063ec98619..25fcd6630a4d 100644
> --- a/tools/perf/util/scripting-engines/trace-event-python.c
> +++ b/tools/perf/util/scripting-engines/trace-event-python.c
> @@ -771,12 +771,12 @@ static void set_regs_in_dict(PyObject *dict,
> int size = __sw_hweight64(attr->sample_regs_intr) * 28;
> char *bf = malloc(size);
>
> - regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
> + regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size);
>
> pydict_set_item_string_decref(dict, "iregs",
> _PyUnicode_FromString(bf));
>
> - regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
> + regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, size);
>
> pydict_set_item_string_decref(dict, "uregs",
> _PyUnicode_FromString(bf));
> --
> 2.31.1.windows.1
>

2023-06-20 22:55:19

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH] tools: Fix incorrect calculation of object size by sizeof

Hi Arnaldo,

On Tue, Jun 20, 2023 at 3:06 PM Arnaldo Carvalho de Melo
<[email protected]> wrote:
>
>
>
> On Tue, Jun 20, 2023, 3:19 PM Namhyung Kim <[email protected]> wrote:
>>
>> Hello,
>>
>> On Mon, Jun 19, 2023 at 1:21 AM Li Dong <[email protected]> wrote:
>> >
>> > What we need to calculate is the size of the object, not the size of the
>> > pointer.
>> >
>> > Signed-off-by: Li Dong <[email protected]>
>>
>> Since this problem was introduced in the current dev cycle and not in the
>> mainline yet, I think we can skip the Fixes tag.
>>
>> Acked-by: Namhyung Kim <[email protected]>
>
>
> I think we should have it anyway, if not for the stable guys to pick it up, for documentation sake :-)

Ok, I'll add that. Thanks for the reply while on your vacation. :)

Thanks,
Namhyung

2023-06-21 17:52:15

by Namhyung Kim

[permalink] [raw]
Subject: Re: [PATCH] tools: Fix incorrect calculation of object size by sizeof

On Tue, Jun 20, 2023 at 3:42 PM Namhyung Kim <[email protected]> wrote:
>
> Hi Arnaldo,
>
> On Tue, Jun 20, 2023 at 3:06 PM Arnaldo Carvalho de Melo
> <[email protected]> wrote:
> >
> >
> >
> > On Tue, Jun 20, 2023, 3:19 PM Namhyung Kim <[email protected]> wrote:
> >>
> >> Hello,
> >>
> >> On Mon, Jun 19, 2023 at 1:21 AM Li Dong <[email protected]> wrote:
> >> >
> >> > What we need to calculate is the size of the object, not the size of the
> >> > pointer.
> >> >
> >> > Signed-off-by: Li Dong <[email protected]>
> >>
> >> Since this problem was introduced in the current dev cycle and not in the
> >> mainline yet, I think we can skip the Fixes tag.
> >>
> >> Acked-by: Namhyung Kim <[email protected]>
> >
> >
> > I think we should have it anyway, if not for the stable guys to pick it up, for documentation sake :-)
>
> Ok, I'll add that. Thanks for the reply while on your vacation. :)

Applied to perf-tools-next with the below tag, thanks!

Fixed: 51cfe7a3e87e ("perf python: Avoid 2 leak sanitizer issues")