Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2633353pxj; Mon, 14 Jun 2021 03:35:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbJr5sVRFGE/lYL4JZib3GFXj+Uh8Nz9QMIfj7x8sc7LBwWAfTtwPWT/5aqYerh4HbsKN+ X-Received: by 2002:a17:907:628a:: with SMTP id nd10mr14777066ejc.326.1623666935215; Mon, 14 Jun 2021 03:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623666935; cv=none; d=google.com; s=arc-20160816; b=ZoA6DoE4ORad6W0LEgG0VAxRthKgb+3NvElw6myajCNMXENuW81ZAbProVHikYwcB2 S7mKgKn2LD+p1OIQn9Jz7RMPRtvRlkkSamTxmEIRXMKCiquA7VdphXXqCl2Bu2DAGtvK j3iUg9Hy6JNxceL0gO4MMRsB3V791rbFEt13xUujw8XH4rxrCkLIe3oqfEZNQwu0xRg4 YzCRrXaWI8qSpadBh4CCJF97KHB3zV99g3azJSzeNpxwuPaef7GBfYX57D4HNQrnETg0 oaLdYSVrYgA/GAb7sVTqgwjlTGfMi7k8OV9kIwUKg8h0tr2w/yQBs0w4a0vP26lt4ffa nCPQ== 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=UrkfCEU5DcT2tQ5SyMmUlKSl98Ai+MTnek6BSEAfEiY=; b=G1rYIYHfJoXjWrx4vfZW8DddXfhTAjauNaX12VPYsT26qNeDXpQBHom79/WP4OmHOX P3iOnw8dkMs41nKuCTTnkhZ0O1tK/SFeLckFEFLXbUvCvayOnYS7Db8bV3YaZAbWy/41 PBofUJBUrNsNxJabUMMD2PESnPtihX9FpLAIJhqo4QZC5nEjjQuLOOvM7r94QMPraK0A q3RsZqCiVYe4t484XHQDkjDJ1RKUD0oAMsA+wvW8ke/J/iCMee2vMXc78Bb2M7UAGQUp xl8ZHmHd38aYMUqjBOjERo0XUa6jIn4WQAXeMGnV5ZpKQXpj5iQmBGyfhk56M7P5u/cG 7H/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WHCPgHJo; 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 e16si11355809ejl.322.2021.06.14.03.35.12; Mon, 14 Jun 2021 03:35:35 -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=WHCPgHJo; 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 S233023AbhFNKdL (ORCPT + 99 others); Mon, 14 Jun 2021 06:33:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:38654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232849AbhFNKbx (ORCPT ); Mon, 14 Jun 2021 06:31:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E5FE561245; Mon, 14 Jun 2021 10:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623666591; bh=EgHBOKPa1VR7ueQvBTaHZ2pNhJCTpuwY/RABMEZcPn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WHCPgHJo4OncgN/pG6bOeugHWz3O+/7KKgJy3G+nlR1QZ1Ykrc76/0TRRgxP6hdZE uE47Baa/esTIWgEoKaFBHHvNxYOft9RRBzq88zdSPNqYlS8odODgrbwAlzZGFXxiPm DQCMtiTTBGgKiX74mEgj0N3NtqsmMYoG7ICna2kw= 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.4 34/34] ftrace: Do not blindly read the ip address in ftrace_bug() Date: Mon, 14 Jun 2021 12:27:25 +0200 Message-Id: <20210614102642.674418435@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210614102641.582612289@linuxfoundation.org> References: <20210614102641.582612289@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 @@ -1943,12 +1943,18 @@ static int ftrace_hash_ipmodify_update(s static void print_ip_ins(const char *fmt, 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]); } static struct ftrace_ops *