Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp623914rwi; Wed, 2 Nov 2022 16:20:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6c2+XYeAyxX/dQlRuF82heOlOtEEeFLFrfghUe2qHTn6v2LaRFbXrFiSAsAW1PPXiAlK8P X-Received: by 2002:a63:5559:0:b0:464:a987:8365 with SMTP id f25-20020a635559000000b00464a9878365mr23739535pgm.479.1667431242113; Wed, 02 Nov 2022 16:20:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667431242; cv=none; d=google.com; s=arc-20160816; b=SwoDt/UGABVNlefUjOXvMSWVyvy/n4/dmNR6OM07OnbO0ZJNuKbpRn7vSRpatnI7gI SxU/yeMQ/0DZK05onLE28Dqi0t5lZdw4F+HwYqxRsgJ0ogh/RVbvZRKichLYNClALHeD LkCFU3rg7WCypaebP5bw7Tq8ZB4RRV/lVlXcLlL1b5H7L/cENK4myMytoXogYZ1OJJXl eYA87TYFN7bJ9AVE5Mcp04qyHzpKS+ZtMpSVyEW7EK/A30r6mwvDml+TMiDVJWbk5x+K zU5ZzJRST7eQt6i8z5kdS1t3GmvnASk2Uvv1xd7qpHk51EH1AhA0NnZWrQ3awP/QtI2Y 3BMQ== 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=EIRk52bHBQUJrQUd7RZc8jImrPvAg3gM4W8MYWO7jyY=; b=QkYupQaNHFL+xjnMPSOeZe/VD6R85B3iXZ0UtmkkG0aW2WoSh5pZuwvf7VSKcd2AOL zOslX83Fqn6lumAaHPfPPmqpB72hO1/C4RzmYw7fyCbAPU+CBAwdFiiq1ePfuiUEZw5R gxdUO0wOT/xaM/pcbymDrLqzg0cEh/YGqlVLXGez1XdNSlzw+rbocb+R2yqfQnTHQsMt 7TMF2f9kjFLJIW6dM3zW9UOR3qRyJXTrLNXkGVd9848I5FCXsvcMoGO+rPStJcVBmjx9 /3z7JkrbupcMBdcKONbMEzflWlhmgkWvi1bilJkYWD0RdnAeFxqInx0h+lfbsVDz6SRA M35Q== 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 f192-20020a636ac9000000b004626957c3c7si17695571pgc.193.2022.11.02.16.20.29; Wed, 02 Nov 2022 16:20:42 -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 S230345AbiKBWyT (ORCPT + 97 others); Wed, 2 Nov 2022 18:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230513AbiKBWx7 (ORCPT ); Wed, 2 Nov 2022 18:53:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A0F2DF80; Wed, 2 Nov 2022 15:53:53 -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 3AD8FB82521; Wed, 2 Nov 2022 22:53:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFB4AC433C1; Wed, 2 Nov 2022 22:53:50 +0000 (UTC) Date: Wed, 2 Nov 2022 18:53:48 -0400 From: Steven Rostedt To: Li Huafei Cc: , , , Subject: Re: [PATCH] ftrace: Fix use-after-free for dynamic ftrace_ops Message-ID: <20221102185348.40f9deab@rorschach.local.home> In-Reply-To: <20221101064146.69551-1-lihuafei1@huawei.com> References: <20221101064146.69551-1-lihuafei1@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 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 Tue, 1 Nov 2022 14:41:46 +0800 Li Huafei wrote: > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c > index fbf2543111c0..4219cc2a04a6 100644 > --- a/kernel/trace/ftrace.c > +++ b/kernel/trace/ftrace.c > @@ -3030,13 +3030,16 @@ int ftrace_shutdown(struct ftrace_ops *ops, int command) > > if (!command || !ftrace_enabled) { ftrace_enabled is seldom not set. I don't think we even need to check it. It's just the value of /proc/sys/kernel/ftrace_enabled, where most people don't even know that file exists. I do want to get rid of it one day too. So let's not optimize for it. > /* > - * If these are dynamic or per_cpu ops, they still > - * need their data freed. Since, function tracing is > - * not currently active, we can just free them > - * without synchronizing all CPUs. > + * If these are dynamic, they still need their data freed. If > + * function tracing is currently active, we neet to synchronize > + * all CPUs before we can release them. > */ > - if (ops->flags & FTRACE_OPS_FL_DYNAMIC) > + if (ops->flags & FTRACE_OPS_FL_DYNAMIC) { > + if (ftrace_enabled) > + goto sync_rcu; > + > goto free_ops; Change the above just to "goto out;" > + } > > return 0; > } > @@ -3083,6 +3086,7 @@ int ftrace_shutdown(struct ftrace_ops *ops, int command) > * ops. > */ Add here: out: > if (ops->flags & FTRACE_OPS_FL_DYNAMIC) { > + sync_rcu: > /* > * We need to do a hard force of sched synchronization. > * This is because we use preempt_disable() to do RCU, but And get rid of the labels in the if block. Thanks! -- Steve