Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3466045pxj; Mon, 7 Jun 2021 11:16:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9V3mABQwsaLUh56RayNUNcpFgOAGwTMVHEH7chti8px2GKk+wyRMrUx9O496nR/rKMW6K X-Received: by 2002:a05:6402:b17:: with SMTP id bm23mr21245507edb.236.1623089782212; Mon, 07 Jun 2021 11:16:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623089782; cv=none; d=google.com; s=arc-20160816; b=GtBTQ6xyTfOE2SSXld2hipeKMopMVgrUnifT6bmVD+b8NqB6L2wT0NEmUy1d2G9HJC b4ZoA3byEtKz/BwS/s7n6gYW7tldZhiAXE9YV9A7P87hBGOvEmz8B0dUoOVmWpl/TC9b 8KBSi6rAGalAfW8IYXTk8w+ifPsq7HkuOtogl+de37XOy6QJunoScDoQ++xZRzJhSOqm cgzjMGlezcMb1Fh4qPyOUYBnDsIelQ8tlBO92iHEzalWi8Cz8gnD19LBR7rC4ufI85v8 s7+3ihZEvOBxYQ23iD8DySqP29x+9i5ubamEOSnPs25zk8ZZbLPO68wKSlFalXn4mO2F NTCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=mfG/MiuG0T/lkv25oT5TvRo/Ns0QyMroeJs2O66wM2A=; b=agjuxrDDEpkXko0OCngdjnUu5G52A9NVqU0vXRRRGHfv85b4YeiW8XFasY4fzr6fto 3hVszIf2wlfT3TK1C2Pa9J1gcshEnzMwR/lLfkwUc6XURLZjElBKxOa5wL7GR3VbpcfJ ePwJmVwvL7xjFfTb0/Xx4OJNXtlo2Kn8FNSte/p2woJQmU4/BhcWV7DZxDU3r+kQ5WHK P+1fK4iXs9NWAF7zREnRJss35tMiwubuUV54XNqLzP8UJwXjCxYAtHUKUsE8utxOzPRA XEeMEGPAzy/gMO1x+f8APv6FLg1cx0d3FvjFEPfJhGAJpw6YQdvzJBb40EIU8RD6pu9D SBTQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bs19si13054932ejb.398.2021.06.07.11.15.58; Mon, 07 Jun 2021 11:16:22 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230407AbhFGSP7 (ORCPT + 99 others); Mon, 7 Jun 2021 14:15:59 -0400 Received: from mailgw01.mediatek.com ([210.61.82.183]:58367 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S230212AbhFGSP6 (ORCPT ); Mon, 7 Jun 2021 14:15:58 -0400 X-UUID: b43cadc9048245d9aaacea593f25c901-20210608 X-UUID: b43cadc9048245d9aaacea593f25c901-20210608 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1890285528; Tue, 08 Jun 2021 02:14:05 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs05n1.mediatek.inc (172.21.101.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 8 Jun 2021 02:14:03 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 8 Jun 2021 02:14:03 +0800 From: Mark-PK Tsai To: CC: , , , , , , , , Subject: Re: [PATCH] arm64: ftrace: don't dereference a probably invalid address Date: Tue, 8 Jun 2021 02:14:03 +0800 Message-ID: <20210607181403.4017-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20210607105217.772214e5@oasis.local.home> References: <20210607105217.772214e5@oasis.local.home> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Mon, 7 Jun 2021 22:15:22 +0800 > Mark-PK Tsai wrote: > > > And the crash is becuase kernel trying to read *rec->ip in print_ip_ins() if > > ftrace_bug() get error code -EINVAL. > > Right, so the actual fix should be something like this: > > [ not tested, nor even compiled ] > > -- Steve > I just test this patch, and turns out it work well. All my modification is only rename copy_from_kernel_nofault into probe_kernel_read because the older kernel version I use. Then the kernel will show the error mesage instead of panic as following. [ 0.000000] ftrace failed to modify [ 0.000000] [<0000000000000020>] 0x20 [ 0.000000] actual: [FAULT](0000000000000020) Should I resend this patch as v2? Or you will upstream this fix? > > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index 2e8a3fde7104..72ef4dccbcc4 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -1967,12 +1967,18 @@ static int ftrace_hash_ipmodify_update(struct ftrace_ops *ops, > > 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)", 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;