Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2644225pxj; Mon, 14 Jun 2021 03:53:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygcaTlt1Bo9pbgsJYCDX4ZhnVXcBqeRqF1BFh2sK9xHf3nV9UwtrURBCthYuf7fjdIqqNJ X-Received: by 2002:a17:906:2456:: with SMTP id a22mr14321423ejb.496.1623668023198; Mon, 14 Jun 2021 03:53:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623668023; cv=none; d=google.com; s=arc-20160816; b=qVfsjOgdQSrgy9chfNw3HDeipgyAVeijCEG8R5tZut3VhRduWhWhAkWXbJq59BqicA CLH4gCLICv3XkGPKLT2rfK+Gmf9q3Ea4mav5eEv4lIUy1wtN1j7ZvXGG0HCbnFBqdL5X PeesB9sQH3hAPfoA83mG9pScqp4+QpbtkT+mcfdhx3UaxWNU9yBlM0wHMNZJeBaMVQQ3 zH4dZZxNCvo1Lp1lF8FxwwIobuT5OWx5pyryQ8gi+nmU51Op2Pl/kEXtxGbCP3c5rsgb D0KFu8eLTpUOENuwCikqq3BS2p01KwrdMY5j6b823DKM6RMEsLqpV5m/0ZIHITRPukle xoJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8TthlZySsPt6Vk1ublwN1WmRWg4YuQK6E7CG47xQazM=; b=PUnRR6L51DVSGmBmmnpYZZEccLcFYow5qmGH/m7d7U9nstp/vpoO0LA/gu2iGLeAwh QF9qZt4lKXtJkcU2seRGpN8S++eRTVWhWGQYfxtbjjzX405rdQD6ht0cPVXSPF+2tuiz wZPSNSB/CJn3yExtLzqUk1xgJXg5hPZwsNt95EKTxZMrXACjsLBbJUkC+1C4L9qMiWu0 a7pCLue7YUMiqcOfNxJCGcGMh74b7jXwfcOvUv1AO1kvs3Ai9TCndqljJW6nbsqrqFgS 3tdBDu/r8Hjf72pXxe7CLbBMRQoYrcrwom8f+8sPygCj9a+D2V+bgp9SKd9He9F718B0 kL9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ruspq193; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 11si10140090ejm.189.2021.06.14.03.53.20; Mon, 14 Jun 2021 03:53:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ruspq193; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234447AbhFNKxt (ORCPT + 99 others); Mon, 14 Jun 2021 06:53:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:52488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbhFNKq1 (ORCPT ); Mon, 14 Jun 2021 06:46:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E99166144E; Mon, 14 Jun 2021 10:36:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667022; bh=cpldz21aicz7rJa65XbQWe+pMtlluIUItfA4BjQC7ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ruspq193qITc4mUe96AHAg5+e0h5V75vqeTpIo3wK6cJsE0mEp0sS30wWcLpB0eQg JDjRWVNH6BbhAvrh19gUClKogRCydktw4rOAbHjzinnrBDv8P2Pt2Z3//2GSnTKERk Y5OSGcvySqYbrW6eeDmmliCdaGqLIUbJuBNsTtoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark-PK Tsai , "Steven Rostedt (VMware)" Subject: [PATCH 4.19 66/67] ftrace: Do not blindly read the ip address in ftrace_bug() Date: Mon, 14 Jun 2021 12:27:49 +0200 Message-Id: <20210614102646.004021860@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102643.797691914@linuxfoundation.org> References: <20210614102643.797691914@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Steven Rostedt (VMware) commit 6c14133d2d3f768e0a35128faac8aa6ed4815051 upstream. It was reported that a bug on arm64 caused a bad ip address to be used for updating into a nop in ftrace_init(), but the error path (rightfully) returned -EINVAL and not -EFAULT, as the bug caused more than one error to occur. But because -EINVAL was returned, the ftrace_bug() tried to report what was at the location of the ip address, and read it directly. This caused the machine to panic, as the ip was not pointing to a valid memory address. Instead, read the ip address with copy_from_kernel_nofault() to safely access the memory, and if it faults, report that the address faulted, otherwise report what was in that location. Link: https://lore.kernel.org/lkml/20210607032329.28671-1-mark-pk.tsai@mediatek.com/ Cc: stable@vger.kernel.org Fixes: 05736a427f7e1 ("ftrace: warn on failure to disable mcount callers") Reported-by: Mark-PK Tsai Tested-by: Mark-PK Tsai Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1977,12 +1977,18 @@ static int ftrace_hash_ipmodify_update(s static void print_ip_ins(const char *fmt, const unsigned char *p) { + char ins[MCOUNT_INSN_SIZE]; int i; + if (probe_kernel_read(ins, p, MCOUNT_INSN_SIZE)) { + printk(KERN_CONT "%s[FAULT] %px\n", fmt, p); + return; + } + printk(KERN_CONT "%s", fmt); for (i = 0; i < MCOUNT_INSN_SIZE; i++) - printk(KERN_CONT "%s%02x", i ? ":" : "", p[i]); + printk(KERN_CONT "%s%02x", i ? ":" : "", ins[i]); } enum ftrace_bug_type ftrace_bug_type;