From: Justin Forbes <jmforbes@linuxtx.org>
To: Kees Cook <keescook@chromium.org>
Cc: "Josh Poimboeuf" <jpoimboe@redhat.com>,
"Valdis Klētnieks" <valdis.kletnieks@vt.edu>,
"Arnaldo Carvalho de Melo" <acme@redhat.com>,
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:58:33 -0600 [thread overview]
Message-ID: <YgwT+WEjZS3bfnS7@fedora64.linuxtx.org> (raw)
In-Reply-To: <20220213182443.4037039-1-keescook@chromium.org>
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>
Tested this patch with the Fedora rawhide builds, and this does indeed
fix the issue.
Tested-by: Justin M. Forbes <jforbes@fedoraproject.org>
prev parent reply other threads:[~2022-02-15 20:58 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
2022-02-15 20:58 ` Justin Forbes [this message]
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=YgwT+WEjZS3bfnS7@fedora64.linuxtx.org \
--to=jmforbes@linuxtx.org \
--cc=acme@redhat.com \
--cc=jpoimboe@redhat.com \
--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