Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp3968266img; Mon, 25 Mar 2019 23:45:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqyD2DlhtEWfq44QuwLd5VvKDsOSrz+HV8su1rIiJKZVGkUov9Y6dFeOjmLe+31bOj/3cty6 X-Received: by 2002:a63:c00c:: with SMTP id h12mr27635574pgg.423.1553582751983; Mon, 25 Mar 2019 23:45:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553582751; cv=none; d=google.com; s=arc-20160816; b=aEj8cSIZ+QfQg0saWmx0GDi2vKW/3pzrvt6B9TjKinJBwYqsb7SUVwe1TfLUIP3bbU cpNt4GoGyUy6xho2RtpAlSXHgZ9nVIAQ8Traxf1AGPErjFB67gYP7PXAgwiRRcBRPNJi 08NwbgSLjo5k+fWsKnhZbXZyF18IFnjBcoqRy6rkNUhmp7UM6OxBXtuUS+nvIWX/3ngn a10ig0sP7XFpduzIO6rR29j82zpw9xOTEd+sJyflbtAGz3ue7YsWqtOIhrTGAlsaWCqO YKwHvF42hm86ZN+kSoEezov+DYY5pTqfHo0piHUlQ971cB+5B5SyBKG7lgsQCCMwxICX r8Tw== 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=rktWIVGMVz3QzN99ZLB6QYuE3dfkQGF1fcMdWR9pAqI=; b=NjSK0jPxJRC2lQzoEQxXTsLO+7630rqOOLQorWJV6/W9Y/jO9QmU9uWnWm109CyFX7 2VVS3+dHO6sBcHTABQwxr42P+6ZPcB0R4mFNHmg5cT8zi4LcKgLmZ+2SrjqfaBuVNS8n 4EwfsLzv1R/3u9FUIjTf0K6/JpXXYFvYFYHHVyrfzNp/zktGZ81Z9sAJsapb43DhhN8a UqlOGbVG5RJX7+EUB8msUPtX8hHToitDUFKQoWR4J0vRXhqh+kibU6uYN0K3PUPry5nO TkP8UDjvqpTSmkvn5e4ReRy5oloAUwvrzX7gTxg03pdw8dnZpJ9DYRZl0s4zgvbnnlRZ eRyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IwEdEXYp; 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 c10si5232341pfg.172.2019.03.25.23.45.37; Mon, 25 Mar 2019 23:45:51 -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=IwEdEXYp; 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 S1731972AbfCZGfE (ORCPT + 99 others); Tue, 26 Mar 2019 02:35:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:45978 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731961AbfCZGe6 (ORCPT ); Tue, 26 Mar 2019 02:34:58 -0400 Received: from localhost (unknown [104.132.152.111]) (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 AB2E02070B; Tue, 26 Mar 2019 06:34:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553582097; bh=eKPjG5RZoVn91nXw0hhZLiAf67wlvNhrqqY54zit7jY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IwEdEXYp2Ocm5KKiJkz1bIFINHrZSHwCft10akclAQFsOCsdi7RFXa95bJiVeC6Ed E/1Qa2pdvpqxg63TZ1LvU4r5+7ktCAN/puRD8BWUvrx6JlYUrXgHYZWuP9ySA08AeW mo382O99u0UNcytrwMbbDCVU5BtXpClZIiJp0Jp4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Thomas Gleixner , Josh Poimboeuf , Borislav Petkov , Andrew Morton , syzbot , "H. Peter Anvin" , Masahiro Yamada , Michal Marek , linux-kbuild@vger.kernel.org Subject: [PATCH 4.14 26/41] x86/unwind: Add hardcoded ORC entry for NULL Date: Tue, 26 Mar 2019 15:30:03 +0900 Message-Id: <20190326042651.358404094@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190326042649.889479098@linuxfoundation.org> References: <20190326042649.889479098@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jann Horn commit ac5ceccce5501e43d217c596e4ee859f2a3fef79 upstream. When the ORC unwinder is invoked for an oops caused by IP==0, it currently has no idea what to do because there is no debug information for the stack frame of NULL. But if RIP is NULL, it is very likely that the last successfully executed instruction was an indirect CALL/JMP, and it is possible to unwind out in the same way as for the first instruction of a normal function. Hardcode a corresponding ORC entry. With an artificially-added NULL call in prctl_set_seccomp(), before this patch, the trace is: Call Trace: ? __x64_sys_prctl+0x402/0x680 ? __ia32_sys_prctl+0x6e0/0x6e0 ? __do_page_fault+0x457/0x620 ? do_syscall_64+0x6d/0x160 ? entry_SYSCALL_64_after_hwframe+0x44/0xa9 After this patch, the trace looks like this: Call Trace: __x64_sys_prctl+0x402/0x680 ? __ia32_sys_prctl+0x6e0/0x6e0 ? __do_page_fault+0x457/0x620 do_syscall_64+0x6d/0x160 entry_SYSCALL_64_after_hwframe+0x44/0xa9 prctl_set_seccomp() still doesn't show up in the trace because for some reason, tail call optimization is only disabled in builds that use the frame pointer unwinder. Signed-off-by: Jann Horn Signed-off-by: Thomas Gleixner Acked-by: Josh Poimboeuf Cc: Borislav Petkov Cc: Andrew Morton Cc: syzbot Cc: "H. Peter Anvin" Cc: Masahiro Yamada Cc: Michal Marek Cc: linux-kbuild@vger.kernel.org Link: https://lkml.kernel.org/r/20190301031201.7416-2-jannh@google.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/unwind_orc.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -74,11 +74,28 @@ static struct orc_entry *orc_module_find } #endif +/* + * If we crash with IP==0, the last successfully executed instruction + * was probably an indirect function call with a NULL function pointer, + * and we don't have unwind information for NULL. + * This hardcoded ORC entry for IP==0 allows us to unwind from a NULL function + * pointer into its parent and then continue normally from there. + */ +static struct orc_entry null_orc_entry = { + .sp_offset = sizeof(long), + .sp_reg = ORC_REG_SP, + .bp_reg = ORC_REG_UNDEFINED, + .type = ORC_TYPE_CALL +}; + static struct orc_entry *orc_find(unsigned long ip) { if (!orc_init) return NULL; + if (ip == 0) + return &null_orc_entry; + /* For non-init vmlinux addresses, use the fast lookup table: */ if (ip >= LOOKUP_START_IP && ip < LOOKUP_STOP_IP) { unsigned int idx, start, stop;