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: <Z1uR2EhgfuzLL3a4@google.com>
Date: Thu, 12 Dec 2024 17:46:00 -0800
From: Namhyung Kim <namhyung@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Arnaldo Carvalho de Melo <acme@...nel.org>,
	Kan Liang <kan.liang@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
	Adrian Hunter <adrian.hunter@...el.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...nel.org>, LKML <linux-kernel@...r.kernel.org>,
	linux-perf-users@...r.kernel.org
Subject: Re: [PATCH] perf tools: Avoid unaligned pointer operations

On Thu, Dec 12, 2024 at 03:56:31PM -0800, Ian Rogers wrote:
> On Wed, Nov 27, 2024 at 1:26 PM Namhyung Kim <namhyung@...nel.org> wrote:
> >
> > The sample data is 64-bit aligned basically but raw data starts with
> > 32-bit length field and data follows.  In perf_event__synthesize_sample
> > it treats the sample data as a 64-bit array.  And it needs some trick
> > to update the raw data properly.
> >
> > But it seems some compilers are not happy with this and the program dies
> > siliently.  I found the sample parsing test failed without any messages
> > on affected systems.
> >
> > Let's update the code to use a 32-bit pointer directly and make sure the
> > result is 64-bit aligned again.  No functional changes intended.
> >
> > Signed-off-by: Namhyung Kim <namhyung@...nel.org>
> > ---
> >  tools/perf/util/synthetic-events.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
> > index a58444c4aed1f1ea..385383ef6cf1edaf 100644
> > --- a/tools/perf/util/synthetic-events.c
> > +++ b/tools/perf/util/synthetic-events.c
> > @@ -1686,12 +1686,16 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo
> >         }
> >
> >         if (type & PERF_SAMPLE_RAW) {
> > -               u.val32[0] = sample->raw_size;
> > -               *array = u.val64;
> > -               array = (void *)array + sizeof(u32);
> > +               u32 *array32 = (void *)array;
> > +
> > +               *array32 = sample->raw_size;
> > +               array32++;
> > +
> > +               memcpy(array32, sample->raw_data, sample->raw_size);
> > +               array = (void *)(array32 + (sample->raw_size / sizeof(u32)));
> >
> > -               memcpy(array, sample->raw_data, sample->raw_size);
> > -               array = (void *)array + sample->raw_size;
> > +               /* make sure the array is 64-bit aligned */
> > +               BUG_ON(((long)array) / sizeof(u64));
> 
> I think you intended:
> 
> BUG_ON(((long)array) % sizeof(u64));

Yep, fixed in v2.

https://lore.kernel.org/r/20241128010325.946897-1-namhyung@kernel.org

Thanks,
Namhyung


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ