Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp764280ybz; Wed, 15 Apr 2020 18:27:22 -0700 (PDT) X-Google-Smtp-Source: APiQypIoGPKYirrTklUlpO9vMoUAizc0MJRadaL1MK/iSt39atTZH2DJyjJq+s9C5a3imGT8aHx5 X-Received: by 2002:a17:906:855a:: with SMTP id h26mr7840163ejy.56.1587000441957; Wed, 15 Apr 2020 18:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587000441; cv=none; d=google.com; s=arc-20160816; b=n0uE8LthEZzWiR0gXFkkqAFAOBwIZZl/KI1JrdCyz1gFkgsPEB25qunbxrlQ421c8q lni+kXKwrgHPVrUAlv4JmYVvE34qUrGv0Niu5UYou5r+CpO8nyZzlji2lX5rB0cU35CO Cq41LL7kpUkRUUzFYD9KcM6fr+RfyB0Vh0aPCiy1qMlaoAYUff/VwmC9NtpYOrzLxHMc jlXZEYNc+3ck5ngVJOPw3qXCCmSU3W2NZVySw/Z86qtiOFaFqCkgJZF0xRCTP++J3CVM oXd69YnPT5nUBUBBBHPM6eXX5HW8ZIIZnTBAzkX7SSIk7XNFKprdnBbvlqzmGwKZQZc0 1RLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=RxZRKpxOmKcZjSCbnxYjD2rdt4rlGopulDzVw+F85Pg=; b=OjJSL3DwXnjpIN1HT8ZVyvlYXjg7BmfbiRjpTrguQknnhnrkJEOnisOr9fWXOwdp/p z4NNmsGbO4aYNHbPh2yIKxdP5mJQhFI/i3MwzWmWbUla8Xl4yhPgWZLYR83v22o6W1HU 12Dx0hY6Kk3/K2oXwUO9yNcmvVmdhkdyfsYpSQHSJoiwqcpB7K7QJyN37M8/CWEv/FUj vBKW3np21j19/7/fhwkuNLdEUfLkxmV2JarE+OYPfB9Yg4MBT/slWMhWL7fTgDSaZ2Cm KE87wICQ7FWCvO+6TuvFwBDNezLHXlDZHzLe+JL5IW9GYHZYUGOwIWNNaHulzOR38EMy D22A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e2si11310688edy.55.2020.04.15.18.26.59; Wed, 15 Apr 2020 18:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731502AbgDPBZa (ORCPT + 99 others); Wed, 15 Apr 2020 21:25:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:33830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730677AbgDPBY6 (ORCPT ); Wed, 15 Apr 2020 21:24:58 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F1FB72076D; Thu, 16 Apr 2020 01:24:56 +0000 (UTC) Date: Wed, 15 Apr 2020 21:24:55 -0400 From: Steven Rostedt To: Bjorn Andersson Cc: John Stultz , "Paul E. McKenney" , Josh Triplett , lkml , Saravana Kannan , Todd Kjos , Stephen Boyd , Peter Zijlstra , Thomas Gleixner Subject: Re: On trace_*_rcuidle functions in modules Message-ID: <20200415212455.28f22041@oasis.local.home> In-Reply-To: <20200416010258.GM20625@builder.lan> References: <20200415161424.584d07d3@gandalf.local.home> <20200415164116.40564f2c@gandalf.local.home> <20200415174918.154a86d0@gandalf.local.home> <20200415220459.GE17661@paulmck-ThinkPad-P72> <20200415185121.381a4bc3@gandalf.local.home> <20200415204827.24f2c548@oasis.local.home> <20200416010258.GM20625@builder.lan> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 15 Apr 2020 18:02:58 -0700 Bjorn Andersson wrote: > Forgive me, but how is this problem related to the fact that the code is > dynamically loaded, i.e. encapsulated in a module? It's not. > > Per the example earlier in this thread, the thing we're worried about is > a use after free in the following scenario, right? > > cpu_pm_unregister_notifier(my_notifier); > kfree(my_data); > > But a driver implementing this snippet might do this regardless of being > builtin or module and afaict exiting probe() unsuccessfully or unbinding > the device would risk triggering this issue? I know my email was confusing. I was talking about a bug that does not exist. (There is no bug!) The reason is that rcu is enabled during the call to the notifiers. The above assumes that the my_data usage in the notifier callback is surrounded by rcu_read_lock() (otherwise it's broken regardless of this code or not). The above unregister will call synchronize_rcu() after it removes the notifier which will guarantee that the rcu_read_lock() critical sections would be completed. Then the kfree(my_data) can free my_data with no possible users. -- Steve