dwarf_loader: Fix heap overflow when accessing variable specification
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. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andrii Nakryiko <andrii.nakryiko@gmail.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: bpf@vger.kernel.org Cc: dwarves@vger.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
a9c99e9881
commit
3cde0135ca
|
@ -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);
|
var->external = dwarf_hasattr(die, DW_AT_external);
|
||||||
/* non-defining declaration of an object */
|
/* non-defining declaration of an object */
|
||||||
var->declaration = dwarf_hasattr(die, DW_AT_declaration);
|
var->declaration = dwarf_hasattr(die, DW_AT_declaration);
|
||||||
|
var->has_specification = has_specification;
|
||||||
var->scope = VSCOPE_UNKNOWN;
|
var->scope = VSCOPE_UNKNOWN;
|
||||||
INIT_LIST_HEAD(&var->annots);
|
INIT_LIST_HEAD(&var->annots);
|
||||||
var->ip.addr = 0;
|
var->ip.addr = 0;
|
||||||
|
@ -2291,12 +2292,16 @@ static int tag__recode_dwarf_type(struct tag *tag, struct cu *cu)
|
||||||
goto find_type;
|
goto find_type;
|
||||||
case DW_TAG_variable: {
|
case DW_TAG_variable: {
|
||||||
struct variable *var = tag__variable(tag);
|
struct variable *var = tag__variable(tag);
|
||||||
dwarf_off_ref specification = dwarf_tag__spec(dtag);
|
|
||||||
|
|
||||||
if (specification.off) {
|
if (var->has_specification) {
|
||||||
dtype = dwarf_cu__find_tag_by_ref(cu->priv, &specification);
|
dwarf_off_ref specification = dwarf_tag__spec(dtag);
|
||||||
if (dtype)
|
|
||||||
var->spec = tag__variable(dtype->tag);
|
if (specification.off) {
|
||||||
|
dtype = dwarf_cu__find_tag_by_ref(cu->priv,
|
||||||
|
&specification);
|
||||||
|
if (dtype)
|
||||||
|
var->spec = tag__variable(dtype->tag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -693,6 +693,7 @@ struct variable {
|
||||||
const char *name;
|
const char *name;
|
||||||
uint8_t external:1;
|
uint8_t external:1;
|
||||||
uint8_t declaration:1;
|
uint8_t declaration:1;
|
||||||
|
uint8_t has_specification:1;
|
||||||
enum vscope scope;
|
enum vscope scope;
|
||||||
struct location location;
|
struct location location;
|
||||||
struct hlist_node tool_hnode;
|
struct hlist_node tool_hnode;
|
||||||
|
|
Loading…
Reference in New Issue