From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailapp01.imgtec.com ([195.59.15.196]:58260 "EHLO mailapp01.imgtec.com" rhost-flags-OK-OK-OK-OK) by eddie.linux-mips.org with ESMTP id S23991976AbdAWJSnS2cxc (ORCPT ); Mon, 23 Jan 2017 10:18:43 +0100 From: Marcin Nowakowski Subject: [PATCH v2 2/2] MIPS: ptrace: disable watchpoints if hit in kernel mode Date: Mon, 23 Jan 2017 10:18:33 +0100 Message-ID: <1485163113-21780-2-git-send-email-marcin.nowakowski@imgtec.com> In-Reply-To: <1485163113-21780-1-git-send-email-marcin.nowakowski@imgtec.com> References: <1485163113-21780-1-git-send-email-marcin.nowakowski@imgtec.com> MIME-Version: 1.0 Content-Type: text/plain Return-Path: Sender: linux-mips-bounce@linux-mips.org Errors-to: linux-mips-bounce@linux-mips.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-subscribe: List-owner: List-post: List-archive: To: Ralf Baechle Cc: James Hogan , linux-mips@linux-mips.org Message-ID: <20170123091833.vgpvN3MeMoDC3g-FZCi7sIU185K503_dyx2VWDiBznw@z> If a watchpoint is hit when in kernel mode it is possible for the system to end up in an infinite loop processing the watchpoint. This can happen if a user sets a watchpoint in the kernel addess space (which is possible in certain EVA configurations) or if a user sets a watchpoint in a user area accessed directly by the kernel (eg. a user buffer accessed via a syscall). To prevent the infinite loop ensure that the watchpoint was hit in userspace, and clear the watchpoint registers otherwise. As this change could mean that a watchpoint is not hit when it should be (when returning to the interrupted traced task on exception exit), the resume_userspace path needs to be extended to conditionally restore the watchpoint configuration. If a task switch occurs when returning to userspace, the watchpoints will be restored in a typical way in the switch_to() handler. Signed-off-by: Marcin Nowakowski --- arch/mips/kernel/entry.S | 9 ++++++++- arch/mips/kernel/traps.c | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/mips/kernel/entry.S b/arch/mips/kernel/entry.S index 7791840..1982fc6 100644 --- a/arch/mips/kernel/entry.S +++ b/arch/mips/kernel/entry.S @@ -55,7 +55,14 @@ resume_userspace: LONG_L a2, TI_FLAGS($28) # current->work andi t0, a2, _TIF_WORK_MASK # (ignoring syscall_trace) bnez t0, work_pending - j restore_all +#ifdef CONFIG_HARDWARE_WATCHPOINTS + li t0, _TIF_LOAD_WATCH + and t0, a2, t0 + beqz t0, 1f + PTR_L a0, TI_TASK($28) + jal mips_install_watch_registers +#endif +1: j restore_all #ifdef CONFIG_PREEMPT resume_kernel: diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c index 6c7f9d7..5371cb0 100644 --- a/arch/mips/kernel/traps.c +++ b/arch/mips/kernel/traps.c @@ -1525,7 +1525,7 @@ asmlinkage void do_watch(struct pt_regs *regs) * their values and send SIGTRAP. Otherwise another thread * left the registers set, clear them and continue. */ - if (test_tsk_thread_flag(current, TIF_LOAD_WATCH)) { + if (user_mode(regs) && test_tsk_thread_flag(current, TIF_LOAD_WATCH)) { mips_read_watch_registers(); local_irq_enable(); force_sig_info(SIGTRAP, &info, current); -- 2.7.4