From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: "Kees Cook" <keescook@chromium.org>,
"Valdis Klētnieks" <valdis.kletnieks@vt.edu>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
"Justin Forbes" <jmforbes@linuxtx.org>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v2] tools: Fix use-after-free for realloc(..., 0)
Date: Tue, 15 Feb 2022 14:14:24 -0800 [thread overview]
Message-ID: <20220215221424.hmnei74ar5gtqfy2@treble> (raw)
In-Reply-To: <YgwQO1Z0UmV241vg@kernel.org>
On Tue, Feb 15, 2022 at 05:42:35PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Mon, Feb 14, 2022 at 12:07:30PM -0800, Josh Poimboeuf escreveu:
> > On Sun, Feb 13, 2022 at 10:24:43AM -0800, Kees Cook wrote:
> > > GCC 12 was correctly reporting a potential use-after-free condition in
> > > the xrealloc helper. Fix the warning by avoiding an implicit "free(ptr)"
> > > when size == 0:
> > >
> > > In file included from help.c:12:
> > > In function 'xrealloc',
> > > inlined from 'add_cmdname' at help.c:24:2: subcmd-util.h:56:23: error: pointer may be used after 'realloc' [-Werror=use-after-free]
> > > 56 | ret = realloc(ptr, size);
> > > | ^~~~~~~~~~~~~~~~~~
> > > subcmd-util.h:52:21: note: call to 'realloc' here
> > > 52 | void *ret = realloc(ptr, size);
> > > | ^~~~~~~~~~~~~~~~~~
> > > subcmd-util.h:58:31: error: pointer may be used after 'realloc' [-Werror=use-after-free]
> > > 58 | ret = realloc(ptr, 1);
> > > | ^~~~~~~~~~~~~~~
> > > subcmd-util.h:52:21: note: call to 'realloc' here
> > > 52 | void *ret = realloc(ptr, size);
> > > | ^~~~~~~~~~~~~~~~~~
> > >
> > > Reported-by: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>
> > > Fixes: 2f4ce5ec1d44 ("perf tools: Finalize subcmd independence")
> > > Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> > > Signed-off-by: Kees Cook <keescook@chromium.org>
> > > ---
> > > v1: https://lore.kernel.org/lkml/20220212181855.3460176-1-keescook@chromium.org/
> > > v2: simplify logic (josh)
> >
> > Thanks, running through testing now.
>
> I assume that testing went ok, may I add a Tested-by: you?
Yes, feel free to add:
Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
--
Josh
next prev parent reply other threads:[~2022-02-15 22:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-13 18:24 [PATCH v2] tools: Fix use-after-free for realloc(..., 0) Kees Cook
2022-02-14 20:07 ` Josh Poimboeuf
2022-02-15 20:42 ` Arnaldo Carvalho de Melo
2022-02-15 22:14 ` Josh Poimboeuf [this message]
2022-02-15 20:58 ` Justin Forbes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220215221424.hmnei74ar5gtqfy2@treble \
--to=jpoimboe@redhat.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=jmforbes@linuxtx.org \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=valdis.kletnieks@vt.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).