From patchwork Thu Mar 30 02:52:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zheng Yejian X-Patchwork-Id: 76876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp832452vqo; Wed, 29 Mar 2023 19:55:36 -0700 (PDT) X-Google-Smtp-Source: AKy350ZTszgvg+mt/LNnw36OKBBtxpMBLjjw5XOZucEBmtcSgzWDfDjO1ouIo/qHWGeJP53/sY1C X-Received: by 2002:aa7:c98b:0:b0:4cd:e84d:1e74 with SMTP id c11-20020aa7c98b000000b004cde84d1e74mr25837925edt.0.1680144935813; Wed, 29 Mar 2023 19:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680144935; cv=none; d=google.com; s=arc-20160816; b=j2Ler718BsqL/dWy1mKQHPPQpkxilcL0ZQR6BzhZNrsOpyOxgzGjXVpRZ+5HkBfbDk PcFa9f56AAFAiFBBZ/mxdAVed81zm1mXyhj46mvmIG0zmu9Skfxi0+ktW0lInzvcXidA 5aFx3jMvWk9ZGNgHpYlwjQzZQLj5vw+hoeIW1j6Y9POzyGtUws7Ke/3CSTuTIzpHsxCY cL0/vCS1qrg1kOYxfADF1ufQLcig01s1KJjYO+VdbtuoVVWk6CeBHsexxAb5qMv7vEBl JdnjHNW+23FZcS8kYhkT6OVQQ3sBMf5FY0ZRix0RRBqs9eOh6Ohh9Zgh62nQSTmWMDZB 52ZA== 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 :message-id:date:subject:cc:to:from; bh=VsWX9b1RmegJ4smSPR8h9/yfHXhHlQL9IUg46av5saI=; b=LfNP2l2CKhrdMX5MMn4U4UB9299N/PZ8Ks9SEXewHMut322GWFfh6Br58X6xGrxxs7 UBOFY4XqbT4nZ7kekHSivlFVnHBK1DrP4CPiLyDbD+lNidODFhR1O4Jc8wYVi5CX8O+d Jie99RSX6/kqZzQ82hJSjvmnzSbNTbkTm6hJxSN6tTIcR3CyP2VYo5Lvf+fnL02UKdu+ hCChxW4qjDrG9N2DoVCkoCxweGg/jc0q/GoxMTmyvhXqP6Patmxk6mFDdPRivDW5vG2u /kyPQq8LTbUftIELZl1N9PqQ+WmZSCPuUVoZ9rtVnPgzi5DynhD2vEe6ad2GVyW7uGfT PHtA== 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 j11-20020aa7c40b000000b005022494af87si13769132edq.429.2023.03.29.19.55.11; Wed, 29 Mar 2023 19:55:35 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229668AbjC3CtV (ORCPT + 99 others); Wed, 29 Mar 2023 22:49:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjC3CtU (ORCPT ); Wed, 29 Mar 2023 22:49:20 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFB7C4EEF; Wed, 29 Mar 2023 19:49:18 -0700 (PDT) Received: from dggpeml100012.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Pn7Cf1j4TzKqYF; Thu, 30 Mar 2023 10:48:46 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Thu, 30 Mar 2023 10:49:16 +0800 From: Zheng Yejian To: , , , , CC: , , Subject: [PATCH] ftrace: Fix issue that 'direct->addr' not restored in modify_ftrace_direct() Date: Thu, 30 Mar 2023 10:52:23 +0800 Message-ID: <20230330025223.1046087-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1761759655924359777?= X-GMAIL-MSGID: =?utf-8?q?1761759655924359777?= Syzkaller report a WARNING: "WARN_ON(!direct)" in modify_ftrace_direct(). Root cause is 'direct->addr' was changed from 'old_addr' to 'new_addr' but not restored if error happened on calling ftrace_modify_direct_caller(). Then it can no longer find 'direct' by that 'old_addr'. To fix it, restore 'direct->addr' to 'old_addr' explicitly in error path. Cc: stable@vger.kernel.org Fixes: 8a141dd7f706 ("ftrace: Fix modify_ftrace_direct.") Signed-off-by: Zheng Yejian --- kernel/trace/ftrace.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 0feea145bb29..c67bcc89a771 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5667,12 +5667,15 @@ int modify_ftrace_direct(unsigned long ip, ret = 0; } - if (unlikely(ret && new_direct)) { - direct->count++; - list_del_rcu(&new_direct->next); - synchronize_rcu_tasks(); - kfree(new_direct); - ftrace_direct_func_count--; + if (ret) { + direct->addr = old_addr; + if (unlikely(new_direct)) { + direct->count++; + list_del_rcu(&new_direct->next); + synchronize_rcu_tasks(); + kfree(new_direct); + ftrace_direct_func_count--; + } } out_unlock: