From patchwork Thu May 3 15:15:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 156718 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3E9F6B6FBB for ; Fri, 4 May 2012 01:16:20 +1000 (EST) Received: from localhost ([::1]:39867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPxlS-0002hh-1B for incoming@patchwork.ozlabs.org; Thu, 03 May 2012 11:16:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54178) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPxlC-0002Uz-Cz for qemu-devel@nongnu.org; Thu, 03 May 2012 11:16:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SPxl5-0004WV-Dj for qemu-devel@nongnu.org; Thu, 03 May 2012 11:16:01 -0400 Received: from afflict.kos.to ([92.243.29.197]:42482) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SPxl5-0004Vv-6T for qemu-devel@nongnu.org; Thu, 03 May 2012 11:15:55 -0400 Received: by afflict.kos.to (Postfix, from userid 1000) id 4CA6D264C0; Thu, 3 May 2012 17:15:52 +0200 (CEST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Thu, 3 May 2012 18:15:52 +0300 Message-Id: <1a49ef2ad3c1c3c50e6aea348260412f98ea862d.1336057827.git.riku.voipio@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 92.243.29.197 Cc: Alexander Graf Subject: [Qemu-devel] [PATCH 2/2] linux-user: fix emulation of /proc/self/maps X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Alexander Graf Improve the emulation of /proc/self/maps by reading the underlying host maps file and passing lines through with addresses adjusted to be guest addresses. This is necessary to avoid false triggers of the glibc check that a format string containing '%n' is not in writable memory. (For an example see the bug reported in https://bugs.launchpad.net/qemu-linaro/+bug/947888 where gpg aborts.) Signed-off-by: Alexander Graf Signed-off-by: Peter Maydell Signed-off-by: Riku Voipio --- linux-user/syscall.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 801b8ed..20d2a74 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -4866,13 +4866,53 @@ int get_osversion(void) static int open_self_maps(void *cpu_env, int fd) { +#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) TaskState *ts = ((CPUArchState *)cpu_env)->opaque; +#endif + FILE *fp; + char *line = NULL; + size_t len = 0; + ssize_t read; + + fp = fopen("/proc/self/maps", "r"); + if (fp == NULL) { + return -EACCES; + } + while ((read = getline(&line, &len, fp)) != -1) { + int fields, dev_maj, dev_min, inode; + uint64_t min, max, offset; + char flag_r, flag_w, flag_x, flag_p; + char path[512] = ""; + fields = sscanf(line, "%"PRIx64"-%"PRIx64" %c%c%c%c %"PRIx64" %x:%x %d" + " %512s", &min, &max, &flag_r, &flag_w, &flag_x, + &flag_p, &offset, &dev_maj, &dev_min, &inode, path); + + if ((fields < 10) || (fields > 11)) { + continue; + } + if (!strncmp(path, "[stack]", 7)) { + continue; + } + if (h2g_valid(min) && h2g_valid(max)) { + dprintf(fd, TARGET_ABI_FMT_lx "-" TARGET_ABI_FMT_lx + " %c%c%c%c %08" PRIx64 " %02x:%02x %d%s%s\n", + h2g(min), h2g(max), flag_r, flag_w, + flag_x, flag_p, offset, dev_maj, dev_min, inode, + path[0] ? " " : "", path); + } + } + + free(line); + fclose(fp); + +#if defined(TARGET_ARM) || defined(TARGET_M68K) || defined(TARGET_UNICORE32) dprintf(fd, "%08llx-%08llx rw-p %08llx 00:00 0 [stack]\n", (unsigned long long)ts->info->stack_limit, (unsigned long long)(ts->stack_base + (TARGET_PAGE_SIZE - 1)) & TARGET_PAGE_MASK, - (unsigned long long)ts->stack_base); + (unsigned long long)0); +#endif return 0; }