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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220804175141.GA3858@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
Date:   Thu, 4 Aug 2022 10:51:41 -0700
From:   Brian Robbins <brianrob@...ux.microsoft.com>
To:     Ian Rogers <irogers@...gle.com>
Cc:     Peter Zijlstra <peterz@...radead.org>,
        Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] perf inject jit: Ignore memfd mmap events if jitdump
 present

On Thu, Aug 04, 2022 at 08:22:14AM -0700, Ian Rogers wrote:
> On Tue, Aug 2, 2022 at 11:25 AM Brian Robbins
> <brianrob@...ux.microsoft.com> wrote:
> >
> > Some processes store jitted code in memfd mappings to avoid having rwx
> > mappings.  These processes map the code with a writeable mapping and a
> > read-execute mapping.  They write the code using the writeable mapping
> > and then unmap the writeable mapping.  All subsequent execution is
> > through the read-execute mapping.
> >
> > perf inject --jit ignores //anon* mappings for each process where a
> > jitdump is present because it expects to inject mmap events for each
> > jitted code range, and said jitted code ranges will overlap with the
> > //anon* mappings.
> >
> > Ignore /memfd: mappings so that jitted code contained in /memfd:
> > mappings is treated the same way as jitted code contained in //anon*
> > mappings.
> >
> > Signed-off-by: Brian Robbins <brianrob@...ux.microsoft.com>
> 
> Acked-by: Ian Rogers <irogers@...gle.com>
> 
> > ---
> >  tools/perf/util/jitdump.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/util/jitdump.c b/tools/perf/util/jitdump.c
> > index a23255773c60..335a3c61940b 100644
> > --- a/tools/perf/util/jitdump.c
> > +++ b/tools/perf/util/jitdump.c
> > @@ -845,8 +845,12 @@ jit_process(struct perf_session *session,
> >         if (jit_detect(filename, pid, nsi)) {
> >                 nsinfo__put(nsi);
> >
> > -               // Strip //anon* mmaps if we processed a jitdump for this pid
> > -               if (jit_has_pid(machine, pid) && (strncmp(filename, "//anon", 6) == 0))
> > +               /*
> > +                * Strip //anon* and /memfd:* mmaps if we processed a jitdump for this pid
> > +                */
> > +               if (jit_has_pid(machine, pid) &&
> > +                       ((strncmp(filename, "//anon", 6) == 0) ||
> > +                        (strncmp(filename, "/memfd:", 7) == 0))
> 
> Related to this there is the prctl PR_SET_VMA_ANON_NAME which will
> name mapping to start with "[anon:"
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/proc.rst#n434
> I wonder also we should be checking the pages are executable.
> 
> Thanks,
> Ian
> 
> >                         return 1;
> >
> >                 return 0;
> > --
> > 2.25.1
> >

I have not run into this case yet, but I suspect you are right that this should be handled as well.  I can create a follow-up patch for this.

Thanks.
--Brian

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ