From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ilya Leoshkevich <iii@linux.ibm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>,
dwarves@vger.kernel.org, bpf@vger.kernel.org,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Heiko Carstens <hca@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>
Subject: Re: [PATCH dwarves] dwarf_loader: Fix heap overflow when accessing variable specification
Date: Fri, 15 Oct 2021 09:53:15 -0300 [thread overview]
Message-ID: <YWl5u2j7kHNLIbPT@kernel.org> (raw)
In-Reply-To: <20211012022521.399302-1-iii@linux.ibm.com>
Em Tue, Oct 12, 2021 at 04:25:21AM +0200, Ilya Leoshkevich escreveu:
> Variables can be allocated with or without specification, however,
> tag__recode_dwarf_type() always tries accessing it, leading to heap
> read overflows and subsequent logic bugs.
>
> Fix by introducing a bit that tracks whether or not specification is
> present.
Thanks, applied.
- Arnaldo
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
> dwarf_loader.c | 15 ++++++++++-----
> dwarves.h | 1 +
> 2 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/dwarf_loader.c b/dwarf_loader.c
> index 48e1bf0..60bdca3 100644
> --- a/dwarf_loader.c
> +++ b/dwarf_loader.c
> @@ -723,6 +723,7 @@ static struct variable *variable__new(Dwarf_Die *die, struct cu *cu, struct conf
> var->external = dwarf_hasattr(die, DW_AT_external);
> /* non-defining declaration of an object */
> var->declaration = dwarf_hasattr(die, DW_AT_declaration);
> + var->has_specification = has_specification;
> var->scope = VSCOPE_UNKNOWN;
> INIT_LIST_HEAD(&var->annots);
> var->ip.addr = 0;
> @@ -2291,12 +2292,16 @@ static int tag__recode_dwarf_type(struct tag *tag, struct cu *cu)
> goto find_type;
> case DW_TAG_variable: {
> struct variable *var = tag__variable(tag);
> - dwarf_off_ref specification = dwarf_tag__spec(dtag);
>
> - if (specification.off) {
> - dtype = dwarf_cu__find_tag_by_ref(cu->priv, &specification);
> - if (dtype)
> - var->spec = tag__variable(dtype->tag);
> + if (var->has_specification) {
> + dwarf_off_ref specification = dwarf_tag__spec(dtag);
> +
> + if (specification.off) {
> + dtype = dwarf_cu__find_tag_by_ref(cu->priv,
> + &specification);
> + if (dtype)
> + var->spec = tag__variable(dtype->tag);
> + }
> }
> }
>
> diff --git a/dwarves.h b/dwarves.h
> index 30d33fa..20608dd 100644
> --- a/dwarves.h
> +++ b/dwarves.h
> @@ -691,6 +691,7 @@ struct variable {
> const char *name;
> uint8_t external:1;
> uint8_t declaration:1;
> + uint8_t has_specification:1;
> enum vscope scope;
> struct location location;
> struct hlist_node tool_hnode;
> --
> 2.31.1
--
- Arnaldo
prev parent reply other threads:[~2021-10-15 12:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-12 2:25 [PATCH dwarves] dwarf_loader: Fix heap overflow when accessing variable specification Ilya Leoshkevich
2021-10-15 12:53 ` Arnaldo Carvalho de Melo [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=YWl5u2j7kHNLIbPT@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dwarves@vger.kernel.org \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=iii@linux.ibm.com \
/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).