Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4901634rwb; Wed, 17 Aug 2022 07:53:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR464pRjTn44WF4SOgAA8cB/X3RiDgGgGOmRn3CyhiAjkq9fpnQYoDmTVucpYcMHCeyNirvM X-Received: by 2002:a17:907:6e14:b0:730:a229:f747 with SMTP id sd20-20020a1709076e1400b00730a229f747mr17738895ejc.202.1660748003149; Wed, 17 Aug 2022 07:53:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660748003; cv=none; d=google.com; s=arc-20160816; b=tkB9vOQ0xihkbozaW0ZzDkzUh0wjPkNXwALiXjV3ABuiwMx3JCF588VtwMcd2nKDXb aSiU/rUP57iG9DUXxDQ4Klp1+ShbB9WwAYGsDNk7FvxvTV+CILrlKpU3NkIG5mMJ6QWa Tn+aF8/np7uSVO7bNuT+15ko5OIIXkyRqOL78DGwqEbGP9NGemwyXWbh9fWQygn6TwQN mw6VA4p3XcZCN8NKqC0Gx0BKVeqioxVeISBUx9UY2UgSjd2O8t5ndrnEHRAx+bNGzl+C uMgQQmfciVJ1SZ+FyUUd2eMOwGlcc2Hod9qUojQCZ0/QwTcazIZdHKnNnd7fp+fzGCOY ecZw== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=A8Dy9dqRCHO2gvmsBbWWQyU/a/fdKWKF+GT6zpDw0lM=; b=iJtk4fT6xHAM6rche8jlAaCvcSZHGv4HddTGWUdyiMV1wwi0pdwJHH9AQ3xCXk1rf1 2RW8DzvQIDQ7BKP8XHUgNjF4kBS98BTf9hMBwNEB4fmvrIWqlx1RKE45jwAZL5oTFwfK /gL9WPysaLAbRhlGDbiu9NsZGq2OjP0KWpMj7CwNNNsdMYoudnCDUyeedWdYZhp/Zpuf baCEV+ZvCb7VoIts1jdHOrG330YlaGet3QT4xfKrC8IdCUa6Hh34sHszlV/UIhHK8QdW rXcTb29o/K+Fl3b9uXTjfQM3rmg1s60hPcZ8RlQafXspANezEbOPflQv0r/QMRBNZfAm Rj9w== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz3-20020a1709072ce300b00730ad9d5b21si14693262ejc.376.2022.08.17.07.52.57; Wed, 17 Aug 2022 07:53:23 -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 S240338AbiHQOlh (ORCPT + 99 others); Wed, 17 Aug 2022 10:41:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240343AbiHQOlM (ORCPT ); Wed, 17 Aug 2022 10:41:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 564DD9AFB3 for ; Wed, 17 Aug 2022 07:41:08 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 44AF7614E9 for ; Wed, 17 Aug 2022 14:41:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F38DC433D6; Wed, 17 Aug 2022 14:41:06 +0000 (UTC) Date: Wed, 17 Aug 2022 10:41:15 -0400 From: Steven Rostedt To: Yang Jihong Cc: , Subject: Re: [PATCH] ftrace: Fix NULL pointer dereference in is_ftrace_trampoline when ftrace is dead Message-ID: <20220817104115.0ec6b90b@gandalf.local.home> In-Reply-To: <20220804021610.209791-1-yangjihong1@huawei.com> References: <20220804021610.209791-1-yangjihong1@huawei.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 On Thu, 4 Aug 2022 10:16:10 +0800 Yang Jihong wrote: > @@ -2922,24 +2922,36 @@ int ftrace_startup(struct ftrace_ops *ops, int command) > ops->flags |= FTRACE_OPS_FL_ENABLED | FTRACE_OPS_FL_ADDING; > > ret = ftrace_hash_ipmodify_enable(ops); > - if (ret < 0) { > - /* Rollback registration process */ > - __unregister_ftrace_function(ops); > - ftrace_start_up--; > - ops->flags &= ~FTRACE_OPS_FL_ENABLED; > - if (ops->flags & FTRACE_OPS_FL_DYNAMIC) > - ftrace_trampoline_free(ops); > - return ret; This should stay as is. > - } > + if (ret < 0) > + goto out_rollback_registration; > > if (ftrace_hash_rec_enable(ops, 1)) > command |= FTRACE_UPDATE_CALLS; > > ftrace_startup_enable(command); > > + /* > + * If ftrace_startup_enable fails, > + * we need to rollback registration process. > + */ > + if (unlikely(ftrace_disabled)) { > + ret = -ENODEV; > + goto out_rollback_registration; The only thing to do here is the _unregister_ftrace_function(ops); And that may not even be safe. > + } > + > ops->flags &= ~FTRACE_OPS_FL_ADDING; > > return 0; > + > +out_rollback_registration: > + /* Rollback registration process */ > + __unregister_ftrace_function(ops); > + ftrace_start_up--; > + ops->flags &= ~FTRACE_OPS_FL_ENABLED; > + if (ops->flags & FTRACE_OPS_FL_DYNAMIC) > + ftrace_trampoline_free(ops); > + When ftrace_disabled is set, ftrace is in an undefined state, and a reboot should be done ASAP. Because we have no idea what went wrong. It means something happened that ftrace was not designed for. That means, we do not know if the trampoline can still be called or not. Maybe it enabled some of the functions, but not all. And maybe those functions call the dynamic trampoline directly. Thus, on ftrace_disable being set, only do the bare minimum, as ftrace has now "shutdown" and will not do any more work. Basically, this patch is trying to mitigate a kernel that broke and needs a reboot immediately. -- Steve > + return ret; > } > > int ftrace_shutdown(struct ftrace_ops *ops, int command) > --