From patchwork Mon Apr 15 19:01:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 162256 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3304540jan; Mon, 15 Apr 2019 12:15:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzYMSSdooWDgtRrdgLsuDdk5gB3wbZrJpeQiaIrFdqM4eCJU1mAEp+ClWOjynNohpFnmhKa X-Received: by 2002:a17:902:b210:: with SMTP id t16mr72507797plr.84.1555355746434; Mon, 15 Apr 2019 12:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355746; cv=none; d=google.com; s=arc-20160816; b=lJ9Kl36Nx2/b98kbtGvlqqp6+IMP1i4hx4OLopdzDNQywNgGb4O20PLB61jjy1hOqy ZiUIeIF5FVBzy3wtpTWH2OusQCqhXNt/PTNhjhBcHSzaiDq+Kimm03ulNcwZ3ffCFYMY RGFXvZB1knGCNKtMMYFpkVatqO0KLmgql6Wo5n0+7U+QuYqb0/On+VeknqnoTNEQTWCW BTLhZksWfIfD0/7VUIbfFTGlRlzDJGKhb3VBMW9oPtP3+Yl6qINS4zMUenrBrdzLPp0W p7LXWlgsbvPC+/LnRU0gX5AmbM6cx4KakxwtiqiMLJ82N5AGHsw/8zuJ1Bf+eeFBvOm+ wnCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=MVyMm5ZKQ+CxJK2Hjx3S2bufHQG+/DzxkLtLWGcjucg=; b=rsysJWvzT9tpIhDcWGOPyoydziYdWk4MyvrPevSxw17WtxmWkRN2DxjuPMoa5XQ6bV K1mhR+NNg0WDSpPjdQ7uCyyMYH+nFZ0OeYEdu5cdXvWUC6SMKIcehT76oWKo1BxMIFRb n/ABrYu2vCBVl61DjdAWIfUb4eSfTCSiLR8OS6OjQHoUlsKzZHuFcwn6QrhF2JHN3yWg TBpK0Xw8IdgFHhZjprIKv8xZHY0MnEQv0H1ryUtj8zqjRwPj9xgHQGVhB1dehpHTZU2G Zqk3LVdMel4FSMMeUcpX+/1eCt0tq/kBdJZmQlUV8ZC+O2gJhi1qMvy0ArmF90oKIDJc EYhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1DhLK5Xd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 v20si45299084pfa.224.2019.04.15.12.15.46; Mon, 15 Apr 2019 12:15:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1DhLK5Xd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731511AbfDOTPo (ORCPT + 30 others); Mon, 15 Apr 2019 15:15:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:51906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731081AbfDOTNx (ORCPT ); Mon, 15 Apr 2019 15:13:53 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1806F2075B; Mon, 15 Apr 2019 19:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355632; bh=OmzfE5MV0cNVsHTEUvFX1PTykvy8XfXmEV8QH4JX4jg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1DhLK5XdymPHZc+llxKrFBXOhGZp7UO3PZhHONPlMyjRLvGh6Wrq8QjCVoWl5DpDs DVZWr19eCHQF9k4PMKoeGlAoha9CfizpWe6+fxCDSSOfdAxs78gUOe5mk7sXoTDnCw g8PUMRqEwyYlCF8+WtwCexpOVS/r5UcYC7XBlUw0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kefeng Wang , Will Deacon Subject: [PATCH 5.0 094/117] arm64: backtrace: Dont bother trying to unwind the userspace stack Date: Mon, 15 Apr 2019 21:01:04 +0200 Message-Id: <20190415183749.624977100@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183744.887851196@linuxfoundation.org> References: <20190415183744.887851196@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon commit 1e6f5440a6814d28c32d347f338bfef68bc3e69d upstream. Calling dump_backtrace() with a pt_regs argument corresponding to userspace doesn't make any sense and our unwinder will simply print "Call trace:" before unwinding the stack looking for user frames. Rather than go through this song and dance, just return early if we're passed a user register state. Cc: Fixes: 1149aad10b1e ("arm64: Add dump_backtrace() in show_regs") Reported-by: Kefeng Wang Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/kernel/traps.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -102,10 +102,16 @@ static void dump_instr(const char *lvl, void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk) { struct stackframe frame; - int skip; + int skip = 0; pr_debug("%s(regs = %p tsk = %p)\n", __func__, regs, tsk); + if (regs) { + if (user_mode(regs)) + return; + skip = 1; + } + if (!tsk) tsk = current; @@ -126,7 +132,6 @@ void dump_backtrace(struct pt_regs *regs frame.graph = 0; #endif - skip = !!regs; printk("Call trace:\n"); do { /* skip until specified stack frame */ @@ -176,15 +181,13 @@ static int __die(const char *str, int er return ret; print_modules(); - __show_regs(regs); pr_emerg("Process %.*s (pid: %d, stack limit = 0x%p)\n", TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk)); + show_regs(regs); - if (!user_mode(regs)) { - dump_backtrace(regs, tsk); + if (!user_mode(regs)) dump_instr(KERN_EMERG, regs); - } return ret; } From patchwork Mon Apr 15 19:01:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 162255 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3302558jan; Mon, 15 Apr 2019 12:13:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxJ9Rihi2PPXdskDXEuJyENh1bVU9D0dVkfWj41JQ+wz7BqA8QNBucXJYUhsWjEIXN3F29 X-Received: by 2002:a62:1701:: with SMTP id 1mr78272481pfx.120.1555355639797; Mon, 15 Apr 2019 12:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555355639; cv=none; d=google.com; s=arc-20160816; b=tx3s4dCU0Hvz5ISldrDhN1cvHsX00A8W/Yyvs6ibfVwg0vtWjAZGql+oEUJQOxQEuv FlvzhL4leTLfG2Yfi4sU+Gd8MFUtOHyB4PzBKnIrUCwxJHnOOdzeAmo0OnxuKqeyd7kM tyu1uMlW6Fo6wx8pBDSoyl1Q0H1hgv0IRKhoktw75GceA1veVlCgYiAZCPT0JDY1Wm4w gm3/JbrBiDnqm309Y2XUo4PGpIRsbNifbUS56kN47QBcx2NRUx4EcqSzIWPkTGHbpG0M 1fKnXPDtYSYbiejHf9O/z7n/+y525K2/8cB2HTQhyz0HI0pgOwEKEjXjJFV4r4R+5nmb wSow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h3nNsQZcffwCcn0boM97aIG0DtM1Hs8SKVH6uINC4Rc=; b=qala/t8J9guJHt7S/d/gWfzqcaj8fmeLZOHE+jpkk1UFnG6jZ9Xb+0ezHpaX+w91bP +rYXNPBNmd4LynazEqm1Xtxzt2ABIoX+WdBohc+7+W1mIj6Gd89vAzphAjP/v/WUaYID Idl7BGT6xNlNnJLzNksa3WhQioQuDKiI9BNy04ktDuJnBtNto51w6lfOBh7eyD5yi+Bc qd1Vq5VPEeJd9tPaUncZSQ/SsD+yebBpDN14KNqeHbBpBREnx6Y6/Eg3k27gv9gKLQJ5 UG6qUFHgF6zWaOBfj9sJkq7ZkbXAS6eePem0eeySbFQ2H8kpB4ISECMo4ZSwXPm2649B 1nYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=osLex4tW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 124si41209128pgi.38.2019.04.15.12.13.59; Mon, 15 Apr 2019 12:13:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=osLex4tW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731667AbfDOTN6 (ORCPT + 30 others); Mon, 15 Apr 2019 15:13:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:51942 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731655AbfDOTNz (ORCPT ); Mon, 15 Apr 2019 15:13:55 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6A9520880; Mon, 15 Apr 2019 19:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355635; bh=5YL+rWJV1VY0G7h6sA/ONOHxtJlgO2PM6OISqDGaYH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=osLex4tWBcirSQgsjgffGOz+pXGVIEeygzgH34XHYe9z2/3gN2sl9cTc3iVLkTak1 6d1gk/ZQdbn+o3phfw2xz9m10m28HIZFQZ89ViWi3G5sclB6Sm7t73CRRlG8/3H9M4 69SCP3UXuMgv2N7h6LwFJd4E1570VqzV9uJbzguw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Ard Biesheuvel , Will Deacon Subject: [PATCH 5.0 095/117] arm64/ftrace: fix inadvertent BUG() in trampoline check Date: Mon, 15 Apr 2019 21:01:05 +0200 Message-Id: <20190415183749.669767123@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183744.887851196@linuxfoundation.org> References: <20190415183744.887851196@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ard Biesheuvel commit 5a3ae7b314a2259b1188b22b392f5eba01e443ee upstream. The ftrace trampoline code (which deals with modules loaded out of BL range of the core kernel) uses plt_entries_equal() to check whether the per-module trampoline equals a zero buffer, to decide whether the trampoline has already been initialized. This triggers a BUG() in the opcode manipulation code, since we end up checking the ADRP offset of a 0x0 opcode, which is not an ADRP instruction. So instead, add a helper to check whether a PLT is initialized, and call that from the frace code. Cc: # v5.0 Fixes: bdb85cd1d206 ("arm64/module: switch to ADRP/ADD sequences for PLT entries") Acked-by: Mark Rutland Signed-off-by: Ard Biesheuvel Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/module.h | 5 +++++ arch/arm64/kernel/ftrace.c | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) --- a/arch/arm64/include/asm/module.h +++ b/arch/arm64/include/asm/module.h @@ -73,4 +73,9 @@ static inline bool is_forbidden_offset_f struct plt_entry get_plt_entry(u64 dst, void *pc); bool plt_entries_equal(const struct plt_entry *a, const struct plt_entry *b); +static inline bool plt_entry_is_initialized(const struct plt_entry *e) +{ + return e->adrp || e->add || e->br; +} + #endif /* __ASM_MODULE_H */ --- a/arch/arm64/kernel/ftrace.c +++ b/arch/arm64/kernel/ftrace.c @@ -107,8 +107,7 @@ int ftrace_make_call(struct dyn_ftrace * trampoline = get_plt_entry(addr, mod->arch.ftrace_trampoline); if (!plt_entries_equal(mod->arch.ftrace_trampoline, &trampoline)) { - if (!plt_entries_equal(mod->arch.ftrace_trampoline, - &(struct plt_entry){})) { + if (plt_entry_is_initialized(mod->arch.ftrace_trampoline)) { pr_err("ftrace: far branches to multiple entry points unsupported inside a single module\n"); return -EINVAL; }