From patchwork Tue May 1 15:30:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 8320 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 884B423E23 for ; Tue, 1 May 2012 15:30:35 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 2F300A184FB for ; Tue, 1 May 2012 15:30:35 +0000 (UTC) Received: by yenl4 with SMTP id l4so2383726yen.11 for ; Tue, 01 May 2012 08:30:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:x-gm-message-state; bh=Q6QtP+LhX/8P39ea3krmRmwlWmqDYoPPlQrrfTMbusk=; b=OJFvysqIh5EX8aZjwbr02KJoG8J2x71aoDrc0i3p3ki9TmeJ60uzHVWM3QZ+StjLeM +iXGNjYdZp0F6XIUPHta5lpVBOGV1SiVA6V2tyuKfxLwD8mK9lozOzlP60ur7Iu5yQzc eqgEFvzq+3ufmIuAHeLhnI2LjtRabZQHxm4BEpM+dURqqJcRsimAIDe/YtDueGainigp KO2t6n5B8LUX2L5TozAZInDOiG7RUGIGbssK4czjF42fyWW9Dn+yUXqjnK+32yiYd2XF RA5m1AZvzcfMC/qrh75pJzdBhBfpBzwLerZ2SqeLuoeEg/6GE5Fy/oJpQd+dP1vuE7OT JKNQ== Received: by 10.50.41.196 with SMTP id h4mr2381757igl.33.1335886234265; Tue, 01 May 2012 08:30:34 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp187738ibt; Tue, 1 May 2012 08:30:33 -0700 (PDT) Received: by 10.216.143.209 with SMTP id l59mr5747631wej.87.1335886232732; Tue, 01 May 2012 08:30:32 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id b62si21773346wed.47.2012.05.01.08.30.32 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 01 May 2012 08:30:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SPF24-00082T-I9; Tue, 01 May 2012 16:30:28 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Riku Voipio Subject: [PATCH for-1.1] linux-user: fix emulation of /proc/self/maps Date: Tue, 1 May 2012 16:30:28 +0100 Message-Id: <1335886228-30876-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-Gm-Message-State: ALoCoQkw/AJpk0uhXq3+APbO/WwYTu4jTqo22/W2dXBh44uqtbxTZO8aF2ofALnLPUiypl1W8mqZ 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 --- I've been running this patch in qemu-linaro for a bit and it's also in Alex's SuSE QEMU 1.0 tree, but I hadn't realised until now that it hadn't made it into master. This should go into 1.1 because otherwise we'll regress compared to 1.0, because glibc can cope with "/proc/self/maps doesn't exist" but not with "exists but has almost no content", which is what the current master gives you. linux-user/syscall.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 41 insertions(+), 1 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 7128618..9a86e00 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; }