From patchwork Mon Sep 24 09:10:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 10612099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8DDC614BD for ; Mon, 24 Sep 2018 09:30:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FE5029EA8 for ; Mon, 24 Sep 2018 09:30:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 63A8829EB8; Mon, 24 Sep 2018 09:30:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B88C529EBB for ; Mon, 24 Sep 2018 09:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=epo815ihJJhz3OEmca62JZPqZ2q66zuD3FmbSKrUe+w=; b=cU3rA/U5W4Z0dr cL2Am6yz+yOG7yk2XwkHQKASwht/xqYxRvXm0rl+sINfMTMzy0HwguOQdiA8IHQocPO7UPgXk2vkG pCKuHM84C2HWPMWI0Xg81mxuTUa5SKJJBHiNAT/NOYpMg/oQbjGG0KLhl6AdVqfNTr6fH0p2IeOBA MwaQLXQmjTQxVpWEkDFY20JsacRLvyj8wcLcZHHWLkl5T+3j0Kz/NSR/ihK3ExW0x/rvi+ag1o0s8 wU6O5uyFOtJQrM9i/TOQo9gj2hiAzP5ZQe/LLraCd0B73MchdmjKZTGVBRTFcyI/fa6LTqFNWNgKM FXjhRr5OYBsI7Ak56ZOw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g4NCK-0000kO-Dk; Mon, 24 Sep 2018 09:30:32 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g4N8L-0006RP-Pz for linux-arm-kernel@bombadil.infradead.org; Mon, 24 Sep 2018 09:26:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Subject:References:In-Reply-To: Message-Id:Date:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mPelqlL7qEyqmvA04qek/UhZCsReq2zvYa6KVg7a96o=; b=eGq7G80QAb+puTgcqN0de1qrx cN+4iHVEyLcYMc13tMCYV7XAV3M3Rs5pWXJpLS2cvk6uK9V0OYVNgViDWp57m1qJnUKu6Nica+nld a5B5lbTblWNkXwiny/Evf8OC6VwZ2WaMKzjYbtaHkycVq7Te9qTl9pu+KNhhofIu4d1GMTcfFa6Jn P7wqBqE0DfFkJOSEcjn+9lYTXSbnLHKvZr+jIF5/gv4eM6hCartWX3WC0V+VEnzNcS7WREZE3BJ75 3o7f/LiKkaBJOYVvQC+7pbgrTLN7a7ftFsseT2WsG+EFGnjaNnsgCSu1K33piq5UfQWXCeglzXeHW i6NU6GwSg==; Received: from out01.mta.xmission.com ([166.70.13.231]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g4MvH-0000ET-GA for linux-arm-kernel@lists.infradead.org; Mon, 24 Sep 2018 09:12:56 +0000 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.87) (envelope-from ) id 1g4Mv4-0002w2-TX; Mon, 24 Sep 2018 03:12:42 -0600 Received: from [105.184.227.67] (helo=x220.Home) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.87) (envelope-from ) id 1g4Mv2-0002zU-QO; Mon, 24 Sep 2018 03:12:42 -0600 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Date: Mon, 24 Sep 2018 11:10:10 +0200 Message-Id: <20180924091015.4458-10-ebiederm@xmission.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <871s9j462u.fsf@xmission.com> References: <871s9j462u.fsf@xmission.com> X-XM-SPF: eid=1g4Mv2-0002zU-QO; ; ; mid=<20180924091015.4458-10-ebiederm@xmission.com>; ; ; hst=in01.mta.xmission.com; ; ; ip=105.184.227.67; ; ; frm=ebiederm@xmission.com; ; ; spf=neutral X-XM-AID: U2FsdGVkX1+9FKMxa0cE5RZwvC7P07Q4dOeDrnFWXKI= X-SA-Exim-Connect-IP: 105.184.227.67 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: [REVIEW][PATCH 10/15] signal/arm64: Add and use arm64_force_sig_fault where appropriate X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180924_051255_642433_9071B812 X-CRM114-Status: GOOD ( 14.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Catalin Marinas , Will Deacon , "Eric W. Biederman" , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Wrap force_sig_fault with a helper that calls arm64_show_signal and call arm64_force_sig_fault where appropraite. Signed-off-by: Eric W. Biederman --- arch/arm64/include/asm/traps.h | 1 + arch/arm64/kernel/debug-monitors.c | 11 +++-------- arch/arm64/kernel/ptrace.c | 11 +++-------- arch/arm64/kernel/traps.c | 27 ++++++++++----------------- arch/arm64/mm/fault.c | 26 ++++++++------------------ 5 files changed, 25 insertions(+), 51 deletions(-) diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h index cd3a2ca9c179..08e99901edbc 100644 --- a/arch/arm64/include/asm/traps.h +++ b/arch/arm64/include/asm/traps.h @@ -37,6 +37,7 @@ void register_undef_hook(struct undef_hook *hook); void unregister_undef_hook(struct undef_hook *hook); void force_signal_inject(int signal, int code, unsigned long address); void arm64_notify_segfault(unsigned long addr); +void arm64_force_sig_fault(int signo, int code, void __user *addr, const char *str); void arm64_force_sig_info(struct siginfo *info, const char *str); /* diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c index e0d9502be5bf..d7bb6aefae0a 100644 --- a/arch/arm64/kernel/debug-monitors.c +++ b/arch/arm64/kernel/debug-monitors.c @@ -210,13 +210,6 @@ NOKPROBE_SYMBOL(call_step_hook); static void send_user_sigtrap(int si_code) { struct pt_regs *regs = current_pt_regs(); - siginfo_t info; - - clear_siginfo(&info); - info.si_signo = SIGTRAP; - info.si_errno = 0; - info.si_code = si_code; - info.si_addr = (void __user *)instruction_pointer(regs); if (WARN_ON(!user_mode(regs))) return; @@ -224,7 +217,9 @@ static void send_user_sigtrap(int si_code) if (interrupts_enabled(regs)) local_irq_enable(); - arm64_force_sig_info(&info, "User debug trap"); + arm64_force_sig_fault(SIGTRAP, si_code, + (void __user *)instruction_pointer(regs), + "User debug trap"); } static int single_step_handler(unsigned long addr, unsigned int esr, diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 20b68cb31ecb..7ab75e78aa08 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -182,13 +182,6 @@ static void ptrace_hbptriggered(struct perf_event *bp, struct pt_regs *regs) { struct arch_hw_breakpoint *bkpt = counter_arch_bp(bp); - siginfo_t info; - - clear_siginfo(&info); - info.si_signo = SIGTRAP; - info.si_errno = 0; - info.si_code = TRAP_HWBKPT; - info.si_addr = (void __user *)(bkpt->trigger); #ifdef CONFIG_COMPAT if (is_compat_task()) { @@ -211,7 +204,9 @@ static void ptrace_hbptriggered(struct perf_event *bp, force_sig_ptrace_errno_trap(si_errno, (void __user *)bkpt->trigger); } #endif - arm64_force_sig_info(&info, "Hardware breakpoint trap (ptrace)"); + arm64_force_sig_fault(SIGTRAP, TRAP_HWBKPT, + (void __user *)(bkpt->trigger), + "Hardware breakpoint trap (ptrace)"); } /* diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index daee8c2ca561..37a3309863e0 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -248,6 +248,13 @@ static void arm64_show_signal(int signo, const char *str) __show_regs(regs); } +void arm64_force_sig_fault(int signo, int code, void __user *addr, + const char *str) +{ + arm64_show_signal(signo, str); + force_sig_fault(signo, code, addr, current); +} + void arm64_force_sig_info(struct siginfo *info, const char *str) { arm64_show_signal(info->si_signo, str); @@ -259,19 +266,11 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, int err) { if (user_mode(regs)) { - struct siginfo info; - WARN_ON(regs != current_pt_regs()); current->thread.fault_address = 0; current->thread.fault_code = err; - clear_siginfo(&info); - info.si_signo = signo; - info.si_errno = 0; - info.si_code = sicode; - info.si_addr = addr; - - arm64_force_sig_info(&info, str); + arm64_force_sig_fault(signo, sicode, addr, str); } else { die(str, regs, err); } @@ -616,19 +615,13 @@ asmlinkage void bad_mode(struct pt_regs *regs, int reason, unsigned int esr) */ asmlinkage void bad_el0_sync(struct pt_regs *regs, int reason, unsigned int esr) { - siginfo_t info; void __user *pc = (void __user *)instruction_pointer(regs); - clear_siginfo(&info); - info.si_signo = SIGILL; - info.si_errno = 0; - info.si_code = ILL_ILLOPC; - info.si_addr = pc; - current->thread.fault_address = 0; current->thread.fault_code = esr; - arm64_force_sig_info(&info, "Bad EL0 synchronous exception"); + arm64_force_sig_fault(SIGILL, ILL_ILLOPC, pc, + "Bad EL0 synchronous exception"); } #ifdef CONFIG_VMAP_STACK diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 959c4a565c8e..66c295019a9a 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -362,15 +362,10 @@ static void do_bad_area(unsigned long addr, unsigned int esr, struct pt_regs *re */ if (user_mode(regs)) { const struct fault_info *inf = esr_to_fault_info(esr); - struct siginfo si; - - clear_siginfo(&si); - si.si_signo = inf->sig; - si.si_code = inf->code; - si.si_addr = (void __user *)addr; set_thread_esr(addr, esr); - arm64_force_sig_info(&si, inf->name); + arm64_force_sig_fault(inf->sig, inf->code, (void __user *)addr, + inf->name); } else { __do_kernel_fault(addr, esr, regs); } @@ -570,11 +565,8 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, * We had some memory, but were unable to successfully fix up * this page fault. */ - clear_siginfo(&si); - si.si_signo = SIGBUS; - si.si_code = BUS_ADRERR; - si.si_addr = (void __user *)addr; - arm64_force_sig_info(&si, inf->name); + arm64_force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)addr, + inf->name); } else if (fault & (VM_FAULT_HWPOISON_LARGE | VM_FAULT_HWPOISON)) { unsigned int lsb; @@ -593,12 +585,10 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, * Something tried to access memory that isn't in our memory * map. */ - clear_siginfo(&si); - si.si_signo = SIGSEGV; - si.si_code = fault == VM_FAULT_BADACCESS ? - SEGV_ACCERR : SEGV_MAPERR; - si.si_addr = (void __user *)addr; - arm64_force_sig_info(&si, inf->name); + arm64_force_sig_fault(SIGSEGV, + fault == VM_FAULT_BADACCESS ? SEGV_ACCERR : SEGV_MAPERR, + (void __user *)addr, + inf->name); } return 0;