[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CADWwUUZkfRL2RpGF3D-gjZjtLwrg=ip4duBqCTYV8jT8bQoNXA@mail.gmail.com>
Date: Tue, 21 Jul 2015 01:53:25 +0900
From: Namhyung Kim <namhyung@...il.com>
To: Josh Poimboeuf <jpoimboe@...hat.com>
Cc: Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>, Michal Marek <mmarek@...e.cz>,
Peter Zijlstra <peterz@...radead.org>,
Andy Lutomirski <luto@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Andi Kleen <andi@...stfloor.org>,
Pedro Alves <palves@...hat.com>, x86@...nel.org,
live-patching@...r.kernel.org, LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v7 2/4] x86/stackvalidate: Compile-time stack validation
Hi,
Just nitpicks below..
On Wed, Jul 15, 2015 at 2:14 AM, Josh Poimboeuf <jpoimboe@...hat.com> wrote:
> +struct elf *elf_open(const char *name)
> +{
> + struct elf *elf;
> +
> + elf_version(EV_CURRENT);
> +
> + elf = malloc(sizeof(*elf));
> + if (!elf) {
> + perror("malloc");
> + return NULL;
> + }
> + memset(elf, 0, sizeof(*elf));
> +
> + INIT_LIST_HEAD(&elf->sections);
> +
> + elf->name = strdup(name);
> + if (!elf->name) {
> + perror("strdup");
> + goto err;
> + }
> +
> + elf->fd = open(name, O_RDONLY);
> + if (elf->fd == -1) {
> + perror("open");
> + goto err;
> + }
> +
> + elf->elf = elf_begin(elf->fd, ELF_C_READ_MMAP, NULL);
> + if (!elf->elf) {
> + perror("elf_begin");
> + goto err;
> + }
> +
> + if (!gelf_getehdr(elf->elf, &elf->ehdr)) {
> + perror("gelf_getehdr");
> + goto err;
> + }
> +
> + if (read_sections(elf))
> + goto err;
> +
> + if (read_symbols(elf))
> + goto err;
> +
> + if (read_relas(elf))
> + goto err;
> +
> + return elf;
> +
> +err:
> + elf_close(elf);
> + return NULL;
> +}
> +
> +void elf_close(struct elf *elf)
> +{
> + struct section *sec, *tmpsec;
> + struct symbol *sym, *tmpsym;
> +
> + list_for_each_entry_safe(sec, tmpsec, &elf->sections, list) {
> + list_for_each_entry_safe(sym, tmpsym, &sec->symbols, list) {
> + list_del(&sym->list);
> + free(sym);
> + }
It seems that it needs to free entries in sec->relas too here.
> + list_del(&sec->list);
> + free(sec);
> + }
> + if (elf->name)
> + free(elf->name);
> + if (elf->fd > 0)
> + close(elf->fd);
> + if (elf->elf)
> + elf_end(elf->elf);
> + free(elf);
> +}
[SNIP]
> +int main(int argc, char *argv[])
> +{
> + struct elf *elf;
> + int ret = 0, warnings = 0;
> +
> + argp_parse(&argp, argc, argv, 0, 0, &args);
> +
> + elf = elf_open(args.args[0]);
> + if (!elf) {
> + fprintf(stderr, "error reading elf file %s\n", args.args[0]);
> + return 1;
> + }
> +
> + ret = decode_sections(elf);
> + if (ret < 0)
> + goto out;
> + warnings += ret;
> +
> + ret = validate_functions(elf);
> + if (ret < 0)
> + goto out;
> + warnings += ret;
> +
> + ret = validate_uncallable_instructions(elf);
> + if (ret < 0)
> + goto out;
> + warnings += ret;
> +
> +out:
elf_close(elf); ??
Thanks,
Namhyung
> + /* ignore warnings for now until we get all the code cleaned up */
> + if (ret || warnings)
> + return 0;
> + return 0;
> +}
> --
> 2.1.0
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@...r.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists