From patchwork Fri Aug 1 03:05:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 4660211 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C2FB49F32F for ; Fri, 1 Aug 2014 03:07:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E17BF2018A for ; Fri, 1 Aug 2014 03:07:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B7642011B for ; Fri, 1 Aug 2014 03:07:57 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XD3AD-0008Dy-1Q; Fri, 01 Aug 2014 03:05:49 +0000 Received: from mail-pd0-f180.google.com ([209.85.192.180]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XD3AA-0008B1-Ty for linux-arm-kernel@lists.infradead.org; Fri, 01 Aug 2014 03:05:47 +0000 Received: by mail-pd0-f180.google.com with SMTP id y13so4649417pdi.25 for ; Thu, 31 Jul 2014 20:05:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=PXbCdqszZoDQJql7cAlmIWRWfGeVgDNZNtuvfYMsZQ8=; b=dkYI+Yzl/hY1HgkbVEQr911HUvHBg+3KGmD/kNL3RbXrwt6R4wlEiX8RFGRk26VrYQ rtd820cDWpeEYJ3iUvC2iA2ARkghZImntjmdjrgPFgl9FebzT+j/AXweLLlONnWqWRWJ kfsYGLObzqIu2kVk+pifbyYv68D7RuzBmWucqp6ddmwnObExA25u1BcTxrnuO2abdIAd 02SqgvIHzbIMqDSDNPuzJ//5A/UNONrLbd/DjWvB9hY2Ddfp/Caymke6xABJC655Y0IK x1MXTpnabdaCnUEOegYGZ2T2uUNZdyYzNVsITBoevQqxsnQw5kRSIabND6mhvjjpaqd4 rk2g== X-Gm-Message-State: ALoCoQnJCwQ855cLPv8PHc+QUEotrs1DbMC0H1co389+0gSfpK0nQmQkbMNpVZgGfCPNRz/ntvUP X-Received: by 10.68.223.1 with SMTP id qq1mr2571263pbc.62.1406862325230; Thu, 31 Jul 2014 20:05:25 -0700 (PDT) Received: from mew ([205.189.0.147]) by mx.google.com with ESMTPSA id i2sm10675236pdk.70.2014.07.31.20.05.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jul 2014 20:05:24 -0700 (PDT) Date: Thu, 31 Jul 2014 20:05:20 -0700 From: Omar Sandoval To: will.deacon@arm.com, linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk, linux-kernel@vger.kernel.org, Catalin.Marinas@arm.com Subject: [PATCH] ARM: don't enter kgdb when userspace executes a kgdb break instruction. Message-ID: <20140801030520.GA27665@mew> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140731_200546_989334_31A624A1 X-CRM114-Status: GOOD ( 11.93 ) X-Spam-Score: -1.4 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Omar Sandoval Acked-by: Will Deacon --- On a kernel running with kgdb enabled, this program reproduces the problem: .globl _start _start: udf #65006 @ KGDB_BREAKINST The same problem has been fixed in ARM64. arch/arm/kernel/kgdb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm/kernel/kgdb.c b/arch/arm/kernel/kgdb.c index 778c2f7..a74b53c 100644 --- a/arch/arm/kernel/kgdb.c +++ b/arch/arm/kernel/kgdb.c @@ -160,12 +160,16 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int instr) static struct undef_hook kgdb_brkpt_hook = { .instr_mask = 0xffffffff, .instr_val = KGDB_BREAKINST, + .cpsr_mask = MODE_MASK, + .cpsr_val = SVC_MODE, .fn = kgdb_brk_fn }; static struct undef_hook kgdb_compiled_brkpt_hook = { .instr_mask = 0xffffffff, .instr_val = KGDB_COMPILED_BREAK, + .cpsr_mask = MODE_MASK, + .cpsr_val = SVC_MODE, .fn = kgdb_compiled_brk_fn };