From 2949597251fea7f17a0e46c1c885e34b53395d18 Mon Sep 17 00:00:00 2001 From: Wenji Huang Date: Mon, 6 Oct 2008 03:07:09 -0400 Subject: PR4886: check build-id if able. This provides sanity check of debuginfo file based on build-id. Many cases are considered, whether build-id exists in debuginfo file or not, whether module is loaded or not, whether build-id exists in runtime kernel/module. It will do work when LD >= 2.18 and kernel >=2.6.23, otherwise no check. --- runtime/sym.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 1a9e26b2..97243929 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -160,6 +160,72 @@ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbo return NULL; } +/* Validate module/kernel based on build-id if there +* The completed case is the following combination: +* Debuginfo Module Kernel +* X X +* has build-id/not unloaded has build-id/not +* loaded && (has build-id/not) +* +* NB: build-id exists only if ld>=2.18 and kernel>= 2.6.23 +*/ +static int _stp_module_check(void) +{ + struct _stp_module *m = NULL; + unsigned long notes_addr, base_addr; + unsigned i,j; + + for (i = 0; i < _stp_num_modules; i++) + { + m = _stp_modules[i]; + + /* unloaded module */ + if (m->notes_sect == 0) { + _stp_warn("skip checking %s\n", m->name); + continue; + } + if (m->build_id_len > 0) { /* build-id in debuginfo file */ + dbug_sym(1, "validate %s based on build-id\n", m->name); + + /* loaded module/kernel, but without build-id */ + if (m->notes_sect == 1) { + _stp_error("missing build-id in %s\n", m->name); + return 1; + } + /* notes end address */ + if (!strcmp(m->name, "kernel")) { + notes_addr = m->build_id_offset; + base_addr = _stp_module_relocate("kernel", + "_stext", 0); + } else { + notes_addr = m->notes_sect + m->build_id_offset; + base_addr = m->notes_sect; + } + /* notes start address */ + notes_addr -= m->build_id_len; + if (notes_addr > base_addr) { + for (j = 0; j < m->build_id_len; j++) + if (*((unsigned char *) notes_addr+j) != + *(m->build_id_bits+j)) + { + _stp_error("inconsistent bit (0x%x [%s] vs 0x%x [debuginfo]) of build-id\n", *((unsigned char *) notes_addr+j), m->name, *(m->build_id_bits+j)); + return 1; + } + } else { /* bug, shouldn't come here */ + _stp_error("unknown failure in checking %s\n", + m->name); + return 1; + } /* end comparing */ + } else { + /* build-id in module/kernel, absent in debuginfo */ + if (m->notes_sect > 1) { + _stp_error("unexpected build-id in %s\n", m->name); + return 1; + } + } /* end checking */ + } /* end loop */ + return 0; +} /** Print an address symbolically. * @param address The address to lookup. -- cgit From 0d633db21595f7160d0f7a767ab92181284d8adb Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Tue, 7 Oct 2008 13:06:17 -0400 Subject: PR4886: weaken build-id failure semantics --- runtime/sym.c | 60 +++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 33 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 97243929..d7b079d2 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -177,21 +177,10 @@ static int _stp_module_check(void) for (i = 0; i < _stp_num_modules; i++) { - m = _stp_modules[i]; - - /* unloaded module */ - if (m->notes_sect == 0) { - _stp_warn("skip checking %s\n", m->name); - continue; - } - if (m->build_id_len > 0) { /* build-id in debuginfo file */ - dbug_sym(1, "validate %s based on build-id\n", m->name); - - /* loaded module/kernel, but without build-id */ - if (m->notes_sect == 1) { - _stp_error("missing build-id in %s\n", m->name); - return 1; - } + m = _stp_modules[i]; + if (m->build_id_len > 0 && m->notes_sect != 0) { + dbug_sym(1, "build-id validation [%s]\n", m->name); + /* notes end address */ if (!strcmp(m->name, "kernel")) { notes_addr = m->build_id_offset; @@ -201,28 +190,33 @@ static int _stp_module_check(void) notes_addr = m->notes_sect + m->build_id_offset; base_addr = m->notes_sect; } - /* notes start address */ + + /* build-id note payload start address */ + /* XXX: But see https://bugzilla.redhat.com/show_bug.cgi?id=465872; + dwfl_module_build_id was not intended to return the end address. */ notes_addr -= m->build_id_len; + if (notes_addr > base_addr) { for (j = 0; j < m->build_id_len; j++) - if (*((unsigned char *) notes_addr+j) != - *(m->build_id_bits+j)) - { - _stp_error("inconsistent bit (0x%x [%s] vs 0x%x [debuginfo]) of build-id\n", *((unsigned char *) notes_addr+j), m->name, *(m->build_id_bits+j)); - return 1; + { + unsigned char theory, practice; + theory = m->build_id_bits [j]; + practice = ((unsigned char*) notes_addr) [j]; + /* XXX: consider using kread() instead of above. */ + if (theory != practice) + { + printk(KERN_WARNING + "%s: inconsistent %s build-id byte #%d " + "(0x%x [actual] vs. 0x%x [debuginfo])\n", + THIS_MODULE->name, m->name, j, + practice, theory); + break; /* Note just the first mismatch. */ + /* XXX: If it were not for Fedora bug #465873, + we could "return 1;" here to abort the script. */ + } } - } else { /* bug, shouldn't come here */ - _stp_error("unknown failure in checking %s\n", - m->name); - return 1; - } /* end comparing */ - } else { - /* build-id in module/kernel, absent in debuginfo */ - if (m->notes_sect > 1) { - _stp_error("unexpected build-id in %s\n", m->name); - return 1; - } - } /* end checking */ + } + } /* end checking */ } /* end loop */ return 0; } -- cgit