Date: Sat, 23 Feb 2008 15:30:04 GMT From: "Alexander V. Chernikov" <admin@su29.net> To: freebsd-i386@FreeBSD.org Subject: Re: i386/120872: fstat exit on signall 11 Message-ID: <200802231530.m1NFU4HL008346@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR i386/120872; it has been noted by GNATS. From: "Alexander V. Chernikov" <admin@su29.net> To: bug-followup@FreeBSD.org, 666.root@gmail.com Cc: Subject: Re: i386/120872: fstat exit on signall 11 Date: Sat, 23 Feb 2008 18:26:52 +0300 This is a multi-part message in MIME format. --------------090107020803020707010507 Content-Type: text/plain; charset=KOI8-R; format=flowed Content-Transfer-Encoding: 7bit The following patch fixes an issue on i386/amd64 platforms kvm_checkheader is a simple cut-n-paste from imgact_elf.c check_header --------------090107020803020707010507 Content-Type: text/plain; name="kvm_elf2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kvm_elf2.diff" diff -urN lib/libkvm.orig/kvm.c lib/libkvm/kvm.c --- lib/libkvm.orig/kvm.c 2008-02-23 17:48:27.000000000 +0300 +++ lib/libkvm/kvm.c 2008-02-23 17:48:33.000000000 +0300 @@ -64,6 +64,8 @@ #include <string.h> #include <unistd.h> +#include <machine/elf.h> + #include "kvm_private.h" /* from src/lib/libc/gen/nlist.c */ @@ -136,6 +138,21 @@ return (p); } +int +_kvm_checkheader(void *e) +{ + Elf_Ehdr *hdr = e; + if (!IS_ELF(*hdr) || + hdr->e_ident[EI_CLASS] != ELF_TARG_CLASS || + hdr->e_ident[EI_DATA] != ELF_TARG_DATA || + hdr->e_ident[EI_VERSION] != EV_CURRENT || + hdr->e_phentsize != sizeof(Elf_Phdr) || + hdr->e_version != ELF_TARG_VER || + hdr->e_machine > MAX_BRANDS) + return (ENOEXEC); +return (0); +} + static kvm_t * _kvm_open(kd, uf, mf, flag, errout) kvm_t *kd; diff -urN lib/libkvm.orig/kvm_amd64.c lib/libkvm/kvm_amd64.c --- lib/libkvm.orig/kvm_amd64.c 2008-02-23 17:48:27.000000000 +0300 +++ lib/libkvm/kvm_amd64.c 2008-02-23 17:51:27.000000000 +0300 @@ -170,6 +170,11 @@ return (-1); ehdr = kd->vmst->mmapbase; + if (_kvm_checkheader(ehdr) != 0) { + _kvm_err(kd, kd->program, "core is not valid ELF core"); + return (-1); + } + hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum; if (_kvm_maphdrs(kd, hdrsz) == -1) return (-1); diff -urN lib/libkvm.orig/kvm_i386.c lib/libkvm/kvm_i386.c --- lib/libkvm.orig/kvm_i386.c 2008-02-23 17:51:03.000000000 +0300 +++ lib/libkvm/kvm_i386.c 2008-02-23 17:51:14.000000000 +0300 @@ -177,6 +177,11 @@ return (-1); ehdr = kd->vmst->mmapbase; + if (_kvm_checkheader(ehdr) != 0) { + _kvm_err(kd, kd->program, "core is not valid ELF core"); + return (-1); + } + hdrsz = ehdr->e_phoff + ehdr->e_phentsize * ehdr->e_phnum; if (_kvm_maphdrs(kd, hdrsz) == -1) return (-1); diff -urN lib/libkvm.orig/kvm_private.h lib/libkvm/kvm_private.h --- lib/libkvm.orig/kvm_private.h 2008-02-23 17:48:28.000000000 +0300 +++ lib/libkvm/kvm_private.h 2008-02-23 17:48:33.000000000 +0300 @@ -79,6 +79,9 @@ __printflike(3, 4); int _kvm_uvatop(kvm_t *, const struct proc *, u_long, u_long *); +#define MAX_BRANDS 8 /* from sys/imgact_elf.h */ +int _kvm_checkheader(void *); + #if defined(__amd64__) || defined(__i386__) void _kvm_minidump_freevtop(kvm_t *); int _kvm_minidump_initvtop(kvm_t *); --------------090107020803020707010507--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802231530.m1NFU4HL008346>