From patchwork Wed Nov 16 01:52:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiu Jianfeng X-Patchwork-Id: 20655 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3044631wru; Tue, 15 Nov 2022 18:00:07 -0800 (PST) X-Google-Smtp-Source: AA0mqf7lorl3qteZj4joDtZvYe79Zjk+o5d2SQsagOpDusvaTROHodqQe+8a6VhdfNMHtWmC4d5/ X-Received: by 2002:a17:906:3551:b0:7ae:43f5:a2a3 with SMTP id s17-20020a170906355100b007ae43f5a2a3mr15479965eja.595.1668564007113; Tue, 15 Nov 2022 18:00:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668564007; cv=none; d=google.com; s=arc-20160816; b=A+DE0IO91PpRVIJSr44tPRG6AfMNwjd46QB+dDNli/LEQs8yP5dbMs8yxYpABa6cI4 TYIPAcU7mhzi9c0oZy/oqu9oqJQTRcGOQlMOifZ+Jalws7OF58SiclWTZcBN2iQQbAC9 09jdlhn3S8tStaLf5LXM2FJ1nyqO+5wLHA97q9Pj1e3+d+dn2V57biOL1OdfzQPhEwaj DxTaup5zbhXq/OKXC9ZEdbEC3ZcHVcoru9h6YLhjwmdC39xyE4lxKA1lmdd+/z7QBI14 Ct4eSrBzKr7UH93DodlQXxvFzt+/gh2mKbeGCYS3mCu+NUqZH0GH5EwVTSMAa355YY60 shwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=0e1UvJk2uPYTxWxYF9ldUBT8JF51hQO1XB9vZVmAYVo=; b=DuaCaj3Mc1/YVcqIflHJNkwKDgNV5Osq15PmoW38S1qsLCpVN8dJ+hWDbIvof6sAam //HwBrOvdx/6JkWQkj90jAF10WRRUaNFcG6Oimnz/AsC3BSS8PdPaU0iFQLuroZBgnwR f/UZtooF+Q7YikEGvwwOj2za76P7m+F2LNdmMBHNVWj+RMPyCpxvA/qtf13wp3keFGcR SlI824NXJTxfRKc839pTL5glMspGHv321cEgq4SnCd5H2UgxN54z1wZzk8uM6OSBZ2RN 215NON+iwn1JCOAEUOEXlnDpGKSW1UpzZWs2GtAYlw4WonxHVi0YfdGcbQmZavUi5rSH 6lLw== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a50d551000000b0046453c385e4si11756525edj.365.2022.11.15.17.59.38; Tue, 15 Nov 2022 18:00:07 -0800 (PST) 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231492AbiKPBzU (ORCPT + 99 others); Tue, 15 Nov 2022 20:55:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiKPBzT (ORCPT ); Tue, 15 Nov 2022 20:55:19 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3391C24F3B for ; Tue, 15 Nov 2022 17:55:18 -0800 (PST) Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NBmML3jRdzmW1d; Wed, 16 Nov 2022 09:54:54 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 16 Nov 2022 09:55:16 +0800 From: Xiu Jianfeng To: , , CC: Subject: [PATCH] ftrace: Fix null pointer dereference in ftrace_add_mod() Date: Wed, 16 Nov 2022 09:52:07 +0800 Message-ID: <20221116015207.30858-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749616172309969951?= X-GMAIL-MSGID: =?utf-8?q?1749616172309969951?= The @ftrace_mod is allocated by kzalloc(), so both the members {prev,next} of @ftrace_mode->list are NULL, it's not a valid state to call list_del(). If kstrdup() for @ftrace_mod->{func|module} fails, it goes to @out_free tag and calls free_ftrace_mod() to destroy @ftrace_mod, then list_del() will write prev->next and next->prev, where null pointer dereference happens. BUG: kernel NULL pointer dereference, address: 0000000000000008 Oops: 0002 [#1] PREEMPT SMP NOPTI Call Trace: ftrace_mod_callback+0x20d/0x220 ? do_filp_open+0xd9/0x140 ftrace_process_regex.isra.51+0xbf/0x130 ftrace_regex_write.isra.52.part.53+0x6e/0x90 vfs_write+0xee/0x3a0 ? __audit_filter_op+0xb1/0x100 ? auditd_test_task+0x38/0x50 ksys_write+0xa5/0xe0 do_syscall_64+0x3a/0x90 entry_SYSCALL_64_after_hwframe+0x63/0xcd Kernel panic - not syncing: Fatal exception So call INIT_LIST_HEAD() to initialize the list member to fix this issue. Fixes: 673feb9d76ab ("ftrace: Add :mod: caching infrastructure to trace_array") Signed-off-by: Xiu Jianfeng --- kernel/trace/ftrace.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 705b990d264d..9af0c4065b4e 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1289,6 +1289,7 @@ static int ftrace_add_mod(struct trace_array *tr, if (!ftrace_mod) return -ENOMEM; + INIT_LIST_HEAD(&ftrace_mod->list); ftrace_mod->func = kstrdup(func, GFP_KERNEL); ftrace_mod->module = kstrdup(module, GFP_KERNEL); ftrace_mod->enable = enable;