Message ID | 20230314190310.070032647@goodmis.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1943254wrd; Tue, 14 Mar 2023 12:26:56 -0700 (PDT) X-Google-Smtp-Source: AK7set81qSuW9fGIrncK8+A49bchrwH7qpcdRHGNuY8Te/zqp/C86mAdAR8WZ/xLpeWJlabehoWf X-Received: by 2002:a05:6a20:3c9f:b0:d4:964d:34f3 with SMTP id b31-20020a056a203c9f00b000d4964d34f3mr6960226pzj.7.1678822015812; Tue, 14 Mar 2023 12:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678822015; cv=none; d=google.com; s=arc-20160816; b=gBHbxjZmFePmm8vWqkf6nZ0sd2O+MCdpLUP9Q0BnisFvsGc+Ds4XfOU+8mAHmsqv03 Z8Rjv2uke67ukv0ejKyYeNvi7a05TGqwbRbsbUDlHwttArGW7QlDoD+/tFzptDL9rtCt RiL0qz98z9Hwdhgde9uAuHj9gxKxjO8B022Lrl3mQvw3l2SRJJ52YeIAkCbneli/CqLQ 7F6EteEsxqPpJXxo+CcDiPs/6msimf57nmlXJoAQIfOfDrbvRtG/NxfgMD6yWVJZ8ITU kZfjfywvIyNJekO6vK2M3rL9Fo+/RROTc/49mThi92IMJuk3zKRAs4ZB/U+xVy78Kpd5 WpRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=46DEfBE1o6GwIB0nSD/mfoPd+QVDJCma1skTPR7O7Iw=; b=ExQoH1Le7pmNSLzNGhxP/0n5f/oh2faesGksJN8Xmo7c/wPI/LTBePMZ1zDSd8zbJd g4/7L0n97XrdVAgPXwyGv8KJZ3ne3JlQNYZwd5SzUbkFHLr+UUd+3Tq9opVeIelszcOf Rtk8v+oy6lK5NhSbbAgGS9pXVdWpZ7006J7cPMsVADdpn9JBGqbGAvV+CeHk5M1+LMel 7P1E5Z2Hsgzzyk0coLKE3Mc9OW+Du1dIlvzXW8S/VnOrQOwqVo+7+BqGNZOwiY9prTYP Ey8JxvLku2Xt+ShTdGjNx6F1KX6vAoDfy3CIG7hoG6F50cX46FUa3lZwe3Yk3ajulqWn JGzw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p68-20020a622947000000b005a8dcaeba57si2696442pfp.371.2023.03.14.12.26.43; Tue, 14 Mar 2023 12:26:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbjCNTES (ORCPT <rfc822;realc9580@gmail.com> + 99 others); Tue, 14 Mar 2023 15:04:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231247AbjCNTEM (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 14 Mar 2023 15:04:12 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29087193C5; Tue, 14 Mar 2023 12:03:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A6356B81B61; Tue, 14 Mar 2023 19:03:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AFBDC433D2; Tue, 14 Mar 2023 19:03:11 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from <rostedt@goodmis.org>) id 1pc9vS-009tyf-0p; Tue, 14 Mar 2023 15:03:10 -0400 Message-ID: <20230314190310.070032647@goodmis.org> User-Agent: quilt/0.66 Date: Tue, 14 Mar 2023 15:02:39 -0400 From: Steven Rostedt <rostedt@goodmis.org> To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu <mhiramat@kernel.org>, Andrew Morton <akpm@linux-foundation.org>, stable@vger.kernel.org, Chen Zhongjin <chenzhongjin@huawei.com> Subject: [for-linus][PATCH 3/5] ftrace: Fix invalid address access in lookup_rec() when index is 0 References: <20230314190236.203370742@goodmis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760372473894436741?= X-GMAIL-MSGID: =?utf-8?q?1760372473894436741?= |
Series |
tracing: Fixes for v6.3
|
|
Commit Message
Steven Rostedt
March 14, 2023, 7:02 p.m. UTC
From: Chen Zhongjin <chenzhongjin@huawei.com> KASAN reported follow problem: BUG: KASAN: use-after-free in lookup_rec Read of size 8 at addr ffff000199270ff0 by task modprobe CPU: 2 Comm: modprobe Call trace: kasan_report __asan_load8 lookup_rec ftrace_location arch_check_ftrace_location check_kprobe_address_safe register_kprobe When checking pg->records[pg->index - 1].ip in lookup_rec(), it can get a pg which is newly added to ftrace_pages_start in ftrace_process_locs(). Before the first pg->index++, index is 0 and accessing pg->records[-1].ip will cause this problem. Don't check the ip when pg->index is 0. Link: https://lore.kernel.org/linux-trace-kernel/20230309080230.36064-1-chenzhongjin@huawei.com Cc: stable@vger.kernel.org Fixes: 9644302e3315 ("ftrace: Speed up search by skipping pages by address") Suggested-by: Steven Rostedt (Google) <rostedt@goodmis.org> Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> --- kernel/trace/ftrace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 750aa3f08b25..a47f7d93e32d 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1537,7 +1537,8 @@ static struct dyn_ftrace *lookup_rec(unsigned long start, unsigned long end) key.flags = end; /* overload flags, as it is unsigned long */ for (pg = ftrace_pages_start; pg; pg = pg->next) { - if (end < pg->records[0].ip || + if (pg->index == 0 || + end < pg->records[0].ip || start >= (pg->records[pg->index - 1].ip + MCOUNT_INSN_SIZE)) continue; rec = bsearch(&key, pg->records, pg->index,