From patchwork Wed Jul 30 11:24:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 34512 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CCD1E20792 for ; Wed, 30 Jul 2014 11:24:47 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id s7sf2838081qap.2 for ; Wed, 30 Jul 2014 04:24:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:in-reply-to:user-agent:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-disposition; bh=0DfH/FvovDiWGvecSOuFXtpu+D3l8OyiNMv1CJ0Ubo4=; b=VVdaM4g9JDkCTcZ1kL1SEfi6N1/IzAA7Vk/nCWHj47VOWil9Ef5w+eM/U01T1j2jvU EtRXf/xt+iW7XQPT32C46bjDikc1KTZv93aeOilgcRY52YU4OsXAuAXm37zJlpbBiLMD UH8/tMZ83b/DMOY8WvcFgr4LyzWbWvgX+FJf0kNd3vgVvBhT+qRcH1Z3GZBCSwPRH+fn PFegIWmYkV0iWyASUjPHbOvniZhghGLvBDyD1LOSnZj+/CSNMgWNjSF30BABFNRHjV/2 YKc/k6QpEy4vV07ikkNRjxVC6xEaa4N1CgsKot6Ombtp9w0pRigA4HfStoEmqQstvSEv TCBg== X-Gm-Message-State: ALoCoQm2okutxMvhF+AmP2w5ZuiMHrx4LXX6OPWa5+uNIC6beVS+dzcaPIvGebxzBZAdeILEO7KF X-Received: by 10.52.190.129 with SMTP id gq1mr2995209vdc.2.1406719487654; Wed, 30 Jul 2014 04:24:47 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.85.213 with SMTP id n79ls502441qgd.29.gmail; Wed, 30 Jul 2014 04:24:47 -0700 (PDT) X-Received: by 10.52.52.136 with SMTP id t8mr6916075vdo.21.1406719487493; Wed, 30 Jul 2014 04:24:47 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id q7si1298201vcz.47.2014.07.30.04.24.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 30 Jul 2014 04:24:47 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id hy10so1481054vcb.32 for ; Wed, 30 Jul 2014 04:24:47 -0700 (PDT) X-Received: by 10.52.120.38 with SMTP id kz6mr206040vdb.86.1406719487376; Wed, 30 Jul 2014 04:24:47 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp19409vcb; Wed, 30 Jul 2014 04:24:46 -0700 (PDT) X-Received: by 10.70.140.13 with SMTP id rc13mr3661679pdb.127.1406719486551; Wed, 30 Jul 2014 04:24:46 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bp9si1047453pdb.91.2014.07.30.04.24.45 for ; Wed, 30 Jul 2014 04:24:46 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752656AbaG3LYo (ORCPT + 26 others); Wed, 30 Jul 2014 07:24:44 -0400 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:39227 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751716AbaG3LYn (ORCPT ); Wed, 30 Jul 2014 07:24:43 -0400 Received: from arm.com (edgewater-inn.cambridge.arm.com [10.1.203.34]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id s6UBO8wo025412; Wed, 30 Jul 2014 12:24:08 +0100 (BST) Date: Wed, 30 Jul 2014 12:24:14 +0100 From: Will Deacon To: Omar Sandoval Cc: "linux-arm-kernel@lists.infradead.org" , "linux@arm.linux.org.uk" , Catalin Marinas , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] ARM/ARM64: don't enter kgdb when userspace executes a kgdb break instruction. Message-ID: <20140730112414.GJ12239@arm.com> References: <20140730071245.GA8954@mew.web-pass.com> MIME-Version: 1.0 In-Reply-To: <20140730071245.GA8954@mew.web-pass.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: will.deacon@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Content-Disposition: inline Hello, On Wed, Jul 30, 2014 at 08:12:45AM +0100, Omar Sandoval wrote: > The kgdb breakpoint hooks (kgdb_brk_fn and kgdb_compiled_brk_fn) should only be > entered when a kgdb break instruction is executed from the kernel. Otherwise, > if kgdb is enabled, a userspace program can cause the kernel to drop into the > debugger by executing either KGDB_BREAKINST or KGDB_COMPILED_BREAK on ARM, or > brk #KGDB_{DYN,COMPILED}_DGB_BRK_IMM on ARM64. > > Signed-off-by: Omar Sandoval > --- > The following program reproduces the fixed problem on ARM: > .globl _start > _start: > udf #65006 @ KGDB_BREAKINST > > And on ARM64: > .globl _start > _start: > brk #0x400 @ KGDB_DYN_DGB_BRK_IMM > > arch/arm/kernel/kgdb.c | 4 ++++ > arch/arm64/include/asm/debug-monitors.h | 4 +++- > arch/arm64/kernel/debug-monitors.c | 3 ++- > arch/arm64/kernel/kgdb.c | 4 ++++ > 4 files changed, 13 insertions(+), 2 deletions(-) Whilst this sounds like a worrying problem, I've failed to reproduce it on arm64. Executing a brk instruction with either KGDB_DYN_DGB_BRK_IMM or KDBG_COMPILED_DBG_BRK_IMM immediates from userspace results in a SIGTRAP being delivered, assumedly because kgdb_handle_exception simply returns when kgdb isn't active. > diff --git a/arch/arm64/include/asm/debug-monitors.h b/arch/arm64/include/asm/debug-monitors.h > index 6e9b5b3..e1d27ce 100644 > --- a/arch/arm64/include/asm/debug-monitors.h > +++ b/arch/arm64/include/asm/debug-monitors.h > @@ -105,8 +105,10 @@ void unregister_step_hook(struct step_hook *hook); > > struct break_hook { > struct list_head node; > - u32 esr_val; > u32 esr_mask; > + u32 esr_val; > + u64 pstate_mask; > + u64 pstate_val; The following (totally untested) diff is simpler for arm64, but again, I'm not sure we even have a problem here. On which systems have you managed to reproduce this and how? Will --->8 the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index a7fb874b595e..fe5b94078d82 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -315,20 +315,20 @@ static int brk_handler(unsigned long addr, unsigned int esr, { siginfo_t info; - if (call_break_hook(regs, esr) == DBG_HOOK_HANDLED) - return 0; + if (user_mode(regs)) { + info = (siginfo_t) { + .si_signo = SIGTRAP, + .si_errno = 0, + .si_code = TRAP_BRKPT, + .si_addr = (void __user *)instruction_pointer(regs), + }; - if (!user_mode(regs)) + force_sig_info(SIGTRAP, &info, current); + } else if (call_break_hook(regs, esr) != DBG_HOOK_HANDLED) { + pr_warning("Unexpected kernel BRK exception at EL1\n"); return -EFAULT; + } - info = (siginfo_t) { - .si_signo = SIGTRAP, - .si_errno = 0, - .si_code = TRAP_BRKPT, - .si_addr = (void __user *)instruction_pointer(regs), - }; - - force_sig_info(SIGTRAP, &info, current); return 0; } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in