Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1512297rwl; Wed, 29 Mar 2023 19:55:08 -0700 (PDT) X-Google-Smtp-Source: AKy350YHe+QppkJ8LTOn+9s0N9AWVcvs687nFchW1xes18mpaBzxyREsn2scaBolbTGQtuJYZEpX X-Received: by 2002:a17:90b:1a8f:b0:23b:3682:c899 with SMTP id ng15-20020a17090b1a8f00b0023b3682c899mr22586786pjb.23.1680144908340; Wed, 29 Mar 2023 19:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680144908; cv=none; d=google.com; s=arc-20160816; b=FI/DJuSrb8t6jS7w/llpl0vIxKGgTxOwHdGunPSGb7/yLaIh13l1KdJXjTAW5YJVbv l2Ahz4NJ+biSgN9C8lQvrX7q9kPyLZvXdED1YIeA6rpu/GMnH9WewCFJkBG/Sv0IKUDI zqwmP7JRSec6L8N38c8P8IYy2u8X8cDpVwiPj1bncc8L/sbarXeJdv/lMapS9DZytCR4 zU4zdAVu4Pgkym3GMg+UGpzCms19TBol2T/Ct1EW3DtNa/oSV0Jnuo5ilGozHnHsO12W VsP1x7xZcC7lxyIIvNnGUzDjIXY7CNS2+btkmCxZv/15UMWIQ+dR9Gw+un2OyViE8jbS kApw== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r4-20020a17090aad0400b0023b4483a784si2846437pjq.161.2023.03.29.19.54.56; Wed, 29 Mar 2023 19:55:08 -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 S229658AbjC3CtV (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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 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: -- 2.25.1