From patchwork Sun Aug 26 22:46:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Cross X-Patchwork-Id: 1376001 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 3A347DFABE for ; Sun, 26 Aug 2012 22:51:09 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T5lcj-0003E0-QT; Sun, 26 Aug 2012 22:48:05 +0000 Received: from mail-fa0-f73.google.com ([209.85.161.73]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T5lcX-0003D5-OL for linux-arm-kernel@lists.infradead.org; Sun, 26 Aug 2012 22:47:54 +0000 Received: by fapp1 with SMTP id p1so159291fap.0 for ; Sun, 26 Aug 2012 15:47:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=ZvZV5z/SED4isUgy2psxLRBFNHjV6Pm5HqPdhz7mQW8=; b=LE/9JPPSszJ0mo7x8Bs9enn5/0QLzVAgopYcUhNYJatDjc67FKukZwsinGzDPj+WCx RNmk5bwgkj8DnWubrJJFbyaU8/gNil4hffw1mgJtYLEle/q7dqDHk1sAruIoha+c93XU UZ3K3kctZT7sOyL16/NGaMQS9wdAdkdjOkfnBjoDvpXMUWEW+TUPdO4p3sc/kPKMXXXD 61+yTRkv+dnNc2A3x3t803WW75bjyJ4Xbx0X4nyWkP2iTRS+ygvvjTkTVmepTuBt3RCH qbjBc8xrP+rHU3hFg64NPCPe4xGwrYRi9LXy1nYW21F1VtgSBGZb684H/uDTCOzWgHXw q1sQ== Received: by 10.180.107.167 with SMTP id hd7mr1403616wib.0.1346021271297; Sun, 26 Aug 2012 15:47:51 -0700 (PDT) Received: by 10.180.107.167 with SMTP id hd7mr1403606wib.0.1346021271217; Sun, 26 Aug 2012 15:47:51 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id cd1si1230589wib.1.2012.08.26.15.47.51 (version=TLSv1/SSLv3 cipher=AES128-SHA); Sun, 26 Aug 2012 15:47:51 -0700 (PDT) Received: from walnut.mtv.corp.google.com (walnut.mtv.corp.google.com [172.18.104.116]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id CC92F200057; Sun, 26 Aug 2012 15:47:50 -0700 (PDT) Received: by walnut.mtv.corp.google.com (Postfix, from userid 99897) id 1D2D8257A35; Sun, 26 Aug 2012 15:47:49 -0700 (PDT) From: Colin Cross To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] ARM: stacktrace: enable dumping stacks for SMP && FRAME_POINTER Date: Sun, 26 Aug 2012 15:46:55 -0700 Message-Id: <1346021216-21979-2-git-send-email-ccross@android.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1346021216-21979-1-git-send-email-ccross@android.com> References: <1346021216-21979-1-git-send-email-ccross@android.com> X-Gm-Message-State: ALoCoQnXJMGbDoXL8t1GIo8hMW4Q3j5eml+N+FGUWzhR3zcfc6ibLe4cI0UULk/z+8WS//XA+4eyL0yGumfJFeOoreXzC4Vk+1J0gxv8Z3bS2NJ0I7jXY+uunBjF4qAJOnSsjuT9clOMgrM5eMlTXtdttIN5/L85/OaIFPNCAbulwaEqTi2gh1wd6Vfq5ir5dVh6oSM6kH5YMCXgyqwuJYuYiDWOF8qAWQ== X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.8 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.161.73 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Rabin Vincent , Catalin Marinas , Russell King , Will Deacon , Colin Cross X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Dumping stacktraces is currently disabled in ARM SMP for all tasks except the current task due to the worry that the task may be running on another CPU and that the unwinder may be unstable when presented with a stack that is being modified. Unwinding with CONFIG_FRAME_POINTER is fairly simple compared to when CONFIG_ARM_UNWIND is set. The next frame's FP and SP registers are read from the stack and can be validated against the current values to ensure that they do not leave the stack and make progress towards the upper end of the stack. This guarantees that accesses do not fault and that execution is bounded. Add additional validations to unwind_frame and enable dumping stacktraces when CONFIG_SMP is set if CONFIG_FRAME_POINTER is set. Signed-off-by: Colin Cross --- arch/arm/kernel/stacktrace.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/arch/arm/kernel/stacktrace.c b/arch/arm/kernel/stacktrace.c index 00f79e5..45e6b7e 100644 --- a/arch/arm/kernel/stacktrace.c +++ b/arch/arm/kernel/stacktrace.c @@ -34,11 +34,24 @@ int notrace unwind_frame(struct stackframe *frame) if (fp < (low + 12) || fp + 4 >= high) return -EINVAL; + if (fp % 4 != 0) + return -EINVAL; + /* restore the registers from the stack frame */ frame->fp = *(unsigned long *)(fp - 12); frame->sp = *(unsigned long *)(fp - 8); frame->pc = *(unsigned long *)(fp - 4); + /* + * ensure the next stack pointer is above this one to guarantee + * bounded execution + */ + if (frame->sp < fp || frame->sp > high) + return -EINVAL; + + if (frame->sp % 4 != 0) + return -EINVAL; + return 0; } #endif @@ -92,7 +105,8 @@ void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace) data.skip = trace->skip; if (tsk != current) { -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP) || \ + (defined(CONFIG_FRAME_POINTER) && !defined(CONFIG_ARM_UNWIND)) /* * What guarantees do we have here that 'tsk' is not * running on another CPU? For now, ignore it as we