mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: Ma Ke <make24@iscas.ac.cn>,
	jie.gan@oss.qualcomm.com, james.clark@linaro.org,
	akpm@linux-foundation.org, alexander.shishkin@linux.intel.com,
	coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, mathieu.poirier@linaro.org,
	mike.leach@linaro.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 RESEND] coresight: etm-perf: Fix reference count leak in etm_setup_aux
Date: Fri, 19 Dec 2025 11:38:03 +0000	[thread overview]
Message-ID: <20251219113803.GC9788@e132581.arm.com> (raw)
In-Reply-To: <d4946831-fc8c-4727-abec-3edd92e357d1@arm.com>

On Fri, Dec 19, 2025 at 09:59:54AM +0000, Suzuki K Poulose wrote:

[...]

> > diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c
> > index 0db64c5f4995..2b34f818ba88 100644
> > --- a/drivers/hwtracing/coresight/coresight-platform.c
> > +++ b/drivers/hwtracing/coresight/coresight-platform.c
> > @@ -107,14 +107,16 @@ coresight_find_device_by_fwnode(struct fwnode_handle *fwnode)
> >   	 * platform bus.
> >   	 */
> >   	dev = bus_find_device_by_fwnode(&platform_bus_type, fwnode);
> > -	if (dev)
> > -		return dev;
> >   	/*
> >   	 * We have a configurable component - circle through the AMBA bus
> >   	 * looking for the device that matches the endpoint node.
> >   	 */
> > -	return bus_find_device_by_fwnode(&amba_bustype, fwnode);
> > +	if (!dev)
> > +		dev = bus_find_device_by_fwnode(&amba_bustype, fwnode);
> > +
> > +	put_device(dev);
> 
> ^^ NAK, see below.
> 
> > +	return dev;
> >   }
> >   /*
> > @@ -274,7 +276,6 @@ static int of_coresight_parse_endpoint(struct device *dev,
> >   	of_node_put(rparent);
> >   	of_node_put(rep);
> > -	put_device(rdev);
> 
> This doesn't look good. We can't use the "dev" reliably without the
> reference count. We are opening up use-after-free.

My understanding is we don't grab a device from
coresight_find_device_by_fwnode().  The callers only check whether the
device is present on the bus; if it isn't, the driver defers probe.

This is similiar to coresight_find_csdev_by_fwnode(), which calls
put_device(dev) to release refcnt immediately.  This is why I
suggested the change, so the two functions behave consistently.

Thanks,
Leo

  reply	other threads:[~2025-12-19 11:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15  2:27 Ma Ke
2025-12-15  9:02 ` James Clark
2025-12-15  9:51   ` Leo Yan
2025-12-15 10:09     ` Jie Gan
2025-12-19  2:39       ` Ma Ke
2025-12-19  9:41         ` Leo Yan
2025-12-19  9:59           ` Suzuki K Poulose
2025-12-19 11:38             ` Leo Yan [this message]
2025-12-19 11:48               ` Suzuki K Poulose
2025-12-19 12:17                 ` Leo Yan
2025-12-15  2:38 Ma Ke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251219113803.GC9788@e132581.arm.com \
    --to=leo.yan@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=coresight@lists.linaro.org \
    --cc=james.clark@linaro.org \
    --cc=jie.gan@oss.qualcomm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=make24@iscas.ac.cn \
    --cc=mathieu.poirier@linaro.org \
    --cc=mike.leach@linaro.org \
    --cc=stable@vger.kernel.org \
    --cc=suzuki.poulose@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®