From patchwork Fri Mar 1 13:28:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 159478 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp734263jad; Fri, 1 Mar 2019 05:28:18 -0800 (PST) X-Google-Smtp-Source: APXvYqx5gdq1CXJtyF+0Y3fZLZrdq4oQi9WhPbQtgD2MuHPxe8WKQ1xBJCWUSK7W5uFcw0RqHV/l X-Received: by 2002:a63:cc05:: with SMTP id x5mr4798132pgf.31.1551446898735; Fri, 01 Mar 2019 05:28:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551446898; cv=none; d=google.com; s=arc-20160816; b=mVPOtIBEWpeM+LjDh2Y6LmoRQB12LCaluDIUnuqrIYrKw5gtWJL5GtW0MQ80oY/SSN U0do28+bfT1lHhwRCQq30s7ZfWTlPH31Xk/bWS1iEctyLqsTICzbDjy7DJQbiy/ilP3d O69u6goj2UdjWJcwUSWYjFSaeR7j3lBWcj5FBTWNMLbmdCAu66D8X3rBtTmJpUb1+fEK FqBhgYukyKL4hiN7uSA3BYr9kz8TgWmYkRdgg0WBT9rbRsxEY9sFkIDpEgIAlUYz7oSM e+QuHnD1ho5Hbi1OGlEBdaGwvVNN6WOQUkNsQ8L+zEYXNcZK59XvxbpOURT0om0D3q7T eNUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ld0eF/bwt22Oh6ysJeua2FImRA54RdArP7PHKaJ/H4Y=; b=RY8uony7PE0tu4aR+VcrDOwAk6Ov7odDss5JHI0/pIqjHCP2gtQ5fBbIuLjff5m8Xo BeaxQZZg4Q9pE/qwv0vQSPbFA1Hq0W1WUfHCM4Qgn50ami87w2UdulMTNcMphOLwvjTv 0KcOInS5riSiVeTcjFodjvdfdQSOD3a1vbbuCwvvdIeuSG5TSAKqOzOm+LJqQdFW/pOQ 78zA2CNr/ILHh034Atn5E4KfpftMscCun+KTXclBIEUij41XuClaFG3Q0uDyHs3cc6NB Y8w8loBaTsUjQQJu0/b0px2UpWXCe/RT/aye45Eeej/mli6JWZhd6WH8MZVJDt1SATDt pbZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cy1si22781169plb.429.2019.03.01.05.28.18; Fri, 01 Mar 2019 05:28:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728347AbfCAN2S (ORCPT + 14 others); Fri, 1 Mar 2019 08:28:18 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:34748 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728290AbfCAN2R (ORCPT ); Fri, 1 Mar 2019 08:28:17 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A2A4516A3; Fri, 1 Mar 2019 05:28:17 -0800 (PST) Received: from fuggles.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 92C583F5C1; Fri, 1 Mar 2019 05:28:16 -0800 (PST) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: catalin.marinas@arm.com, mark.rutland@arm.com, Will Deacon , stable@vger.kernel.org Subject: [PATCH 02/10] arm64: debug: Ensure debug handlers check triggering exception level Date: Fri, 1 Mar 2019 13:28:01 +0000 Message-Id: <20190301132809.24653-3-will.deacon@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190301132809.24653-1-will.deacon@arm.com> References: <20190301132809.24653-1-will.deacon@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org Debug exception handlers may be called for exceptions generated both by user and kernel code. In many cases, this is checked explicitly, but in other cases things either happen to work by happy accident or they go slightly wrong. For example, executing 'brk #4' from userspace will enter the kprobes code and be ignored, but the instruction will be retried forever in userspace instead of delivering a SIGTRAP. Fix this issue in the most stable-friendly fashion by simply adding explicit checks of the triggering exception level to all of our debug exception handlers. Cc: Signed-off-by: Will Deacon --- arch/arm64/kernel/kgdb.c | 14 ++++++++++---- arch/arm64/kernel/probes/kprobes.c | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) -- 2.11.0 Reviewed-by: Mark Rutland diff --git a/arch/arm64/kernel/kgdb.c b/arch/arm64/kernel/kgdb.c index ce46c4cdf368..691854b77c7f 100644 --- a/arch/arm64/kernel/kgdb.c +++ b/arch/arm64/kernel/kgdb.c @@ -244,27 +244,33 @@ int kgdb_arch_handle_exception(int exception_vector, int signo, static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr) { + if (user_mode(regs)) + return DBG_HOOK_ERROR; + kgdb_handle_exception(1, SIGTRAP, 0, regs); - return 0; + return DBG_HOOK_HANDLED; } NOKPROBE_SYMBOL(kgdb_brk_fn) static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr) { + if (user_mode(regs)) + return DBG_HOOK_ERROR; + compiled_break = 1; kgdb_handle_exception(1, SIGTRAP, 0, regs); - return 0; + return DBG_HOOK_HANDLED; } NOKPROBE_SYMBOL(kgdb_compiled_brk_fn); static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr) { - if (!kgdb_single_step) + if (user_mode(regs) || !kgdb_single_step) return DBG_HOOK_ERROR; kgdb_handle_exception(1, SIGTRAP, 0, regs); - return 0; + return DBG_HOOK_HANDLED; } NOKPROBE_SYMBOL(kgdb_step_brk_fn); diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c index f17afb99890c..7fb6f3aa5ceb 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -450,6 +450,9 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) struct kprobe_ctlblk *kcb = get_kprobe_ctlblk(); int retval; + if (user_mode(regs)) + return DBG_HOOK_ERROR; + /* return error if this is not our step */ retval = kprobe_ss_hit(kcb, instruction_pointer(regs)); @@ -466,6 +469,9 @@ kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr) int __kprobes kprobe_breakpoint_handler(struct pt_regs *regs, unsigned int esr) { + if (user_mode(regs)) + return DBG_HOOK_ERROR; + kprobe_handler(regs); return DBG_HOOK_HANDLED; }