From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752020AbcBWXfb (ORCPT ); Tue, 23 Feb 2016 18:35:31 -0500 Received: from v094114.home.net.pl ([79.96.170.134]:57035 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751155AbcBWXfa (ORCPT ); Tue, 23 Feb 2016 18:35:30 -0500 From: "Rafael J. Wysocki" To: "Shevchenko, Andriy" Cc: "heikki.krogerus@linux.intel.com" , "mika.westerberg@linux.intel.com" , "linux-kernel@vger.kernel.org" , "John.Youn@synopsys.com" Subject: Re: [PATCH 2/2] device property: fix for a case of use-after-free Date: Wed, 24 Feb 2016 00:37:01 +0100 Message-ID: <1786876.W1t3Uy8JAQ@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/4.5.0-rc1+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1456160688.13244.30.camel@intel.com> References: <1456152641-127948-1-git-send-email-heikki.krogerus@linux.intel.com> <1456155650.13244.24.camel@linux.intel.com> <1456160688.13244.30.camel@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday, February 22, 2016 05:04:04 PM Shevchenko, Andriy wrote: > On Mon, 2016-02-22 at 17:40 +0200, Andy Shevchenko wrote: > > On Mon, 2016-02-22 at 16:50 +0200, Heikki Krogerus wrote: > > > In device_remove_property_set(), if the primary fwnode is > > > of type "pset", it has to be set pointing to NULL before > > > calling set_secondary_fwnode(). Otherwise > > > set_secondary_fwnode() will attempt to set the > > > fwnode->secondary member after the fwnode has been freed. > > > > > > Reported-by: John Youn > > > Signed-off-by: Heikki Krogerus > > > --- > > > drivers/base/property.c | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/base/property.c b/drivers/base/property.c > > > index a163f2c..ddf2987 100644 > > > --- a/drivers/base/property.c > > > +++ b/drivers/base/property.c > > > @@ -820,7 +820,9 @@ void device_remove_property_set(struct device > > > *dev) > > > * the pset. If there is no real firmware node (ACPI/DT) > > > primary > > > * will hold the pset. > > > */ > > > - if (!is_pset_node(fwnode)) > > > + if (is_pset_node(fwnode)) > > > + dev->fwnode = NULL; > > > + else > > > fwnode = fwnode->secondary; > > > if (!IS_ERR(fwnode) && is_pset_node(fwnode)) > > > pset_free_set(to_pset_node(fwnode)); > > > > > > What if we do the following > > > > --- a/drivers/base/property.c > > +++ b/drivers/base/property.c > > @@ -818,9 +818,13 @@ void device_remove_property_set(struct device > > *dev) > > */ > > if (!is_pset_node(fwnode)) > > fwnode = fwnode->secondary; > > + > > + /* Set device fwnode to NULL before we free it */ > > + set_secondary_fwnode(dev, NULL); > > + > > + /* Free property set for the given device */ > > if (!IS_ERR(fwnode) && is_pset_node(fwnode)) > > pset_free_set(to_pset_node(fwnode)); > > - set_secondary_fwnode(dev, NULL); > > } > > EXPORT_SYMBOL_GPL(device_remove_property_set); > > > > ? > > > > Just noticed that there is another potential bug is hidden, if we call > this function on non-pset fwnode we will silently get fwnode set to > NULL. > > Considering this, perhaps better solution is to convert last lines to > > if (!IS_ERR(fwnode) && is_pset_node(fwnode)) { > set_secondary_fwnode(dev, NULL); > pset_free_set(to_pset_node(fwnode)); > } > > I didn't check if we do serialize access to fwnode. It might be more > bugs with access to it in racing manner. The core doesn't serialize those. If the callers need serialization, they should use some locking around those calls. Thanks, Rafael