Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2658469pxj; Mon, 14 Jun 2021 04:14:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPZDsGaTOa6rsjWFudL3U0A+9KquLEHYRbrFERCudJAYRtUcN+rXtq8PZDjFqINKEDfvO/ X-Received: by 2002:a05:6402:145a:: with SMTP id d26mr16438196edx.151.1623669247266; Mon, 14 Jun 2021 04:14:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623669247; cv=none; d=google.com; s=arc-20160816; b=vSOhnBOtRc8mGWDjSj0HlF1/4Nl3TpI8XaIfEGRM10IpuRZqZqQ7ylV6ZqaAMDhd7N 8l7qC1kIVQSKSV2lc4ze/6xtEbHyCDKA28B6qdNGPSUIpGhP+EinjuTvWwbwd+CmTyXY 6QRkztaoUB+0KxJgZ4q/GAOKWxeszsyiAxJAyQFSxn5EMRVJIoCmrw/cK1i13fmnZnK7 BoaLrfhA+RhJH3DO5tRoPfAX5fxFHyxH/4en6bpviFKj2PJj9dGPBtbPwKLRo+lS9QLO 2dIdRgJxYa260QcY4cNbnTFwl7lJNVd2LezZEunAHn1tNqEEvKldHwo5EpKH5rIiPUc9 vS+w== 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=3eCEduWaIqEynodhlLVWo3eyD6dwlgNCcdqYF1/i0SQ=; b=DI7F6u2Q8UtybswrSg6skm4/g1VKoo6U+i6oZzMCPfCbdVh6Vt83+Yg8VuZBBHCnx1 St8WLDvziKxaAbCNaNp0i0JmRpczcUawsY425WTiXRACWq4KIp3goZjVBpZHg1BAXff5 wUzzm0yKflYhsmp7FSsklRUhe0vLtkc5rWCGgcGxP/Wz3FXLTPFta5GzQsoiwBva7Faz e7snkR4R14gn4ZFbWpPbGx1ZEEgpg0OwlvFQhqmkt5PRd2jOkjyF1bZeH8bAVLy8Re4q 0eS8/A/hq8ymmix7jDFRZBTJtKwipN1ZMQ5MEQZfFQrF4pNjeXxj4BWLQxb73jkdCIrs DnpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ea8Aue61; 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 u21si11282395ejz.696.2021.06.14.04.13.44; Mon, 14 Jun 2021 04:14:07 -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=ea8Aue61; 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 S235457AbhFNLOJ (ORCPT + 99 others); Mon, 14 Jun 2021 07:14:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:38268 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbhFNLCL (ORCPT ); Mon, 14 Jun 2021 07:02:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F8C36190A; Mon, 14 Jun 2021 10:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623667421; bh=hYvpvnY69XNqIy5q9W9se4DgvuawRvaneL4ZUD92l8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ea8Aue61QYAcDX32uitQfvY4VLWAt8yEeeZmtbKmFD5az2ttTnIovJ+x4VkUpYyWn ZNqtFyuiTj0qoAmmupTU3MXAkJHyg1Ime2DspDLggIsASECPdUQfUI4wiwieuvkBrX NNek/4EZ2qqNPrqrbCmcGmfMJdyu9pj09MWTbt5c= 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 5.10 064/131] ftrace: Do not blindly read the ip address in ftrace_bug() Date: Mon, 14 Jun 2021 12:27:05 +0200 Message-Id: <20210614102655.199325002@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102652.964395392@linuxfoundation.org> References: <20210614102652.964395392@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 @@ -1968,12 +1968,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 (copy_from_kernel_nofault(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;