From: Yeoreum Yun <yeoreum.yun@arm.com>
To: Leo Yan <leo.yan@arm.com>
Cc: suzuki.poulose@arm.com, mike.leach@linaro.org,
james.clark@linaro.org, alexander.shishkin@linux.intel.com,
coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 3/3] coresight: prevent deactivate active config while enabling the config
Date: Wed, 14 May 2025 12:04:39 +0100 [thread overview]
Message-ID: <aCR4x/+Wp8JoqG9P@e129823.arm.com> (raw)
In-Reply-To: <20250514093019.GE26114@e132581.arm.com>
Hi Leo,
> On Tue, May 13, 2025 at 06:06:22PM +0100, Yeoreum Yun wrote:
> > While enable active config via cscfg_csdev_enable_active_config(),
> > active config could be deactivated via configfs' sysfs interface.
> > This could make UAF issue in below scenario:
> >
> > CPU0 CPU1
> > (sysfs enable) load module
> > cscfg_load_config_sets()
> > activate config. // sysfs
> > (sys_active_cnt == 1)
> > ...
> > cscfg_csdev_enable_active_config()
> > lock(csdev->cscfg_csdev_lock)
> > // here load config activate by CPU1
> > unlock(csdev->cscfg_csdev_lock)
> >
> > deactivate config // sysfs
> > (sys_activec_cnt == 0)
> > cscfg_unload_config_sets()
> > unload module
> >
> > // access to config_desc which freed
> > // while unloading module.
> > cscfg_csdev_enable_config
> >
> > To address this, use cscfg_config_desc's active_cnt as a reference count
> > which will be holded when
> > - activate the config.
> > - enable the activated config.
> > and put the module reference when config_active_cnt == 0.
> >
> > Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
> > ---
> > .../hwtracing/coresight/coresight-config.h | 2 +-
> > .../hwtracing/coresight/coresight-syscfg.c | 49 +++++++++++++------
> > 2 files changed, 35 insertions(+), 16 deletions(-)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h
> > index b9ebc9fcfb7f..90fd937d3bd8 100644
> > --- a/drivers/hwtracing/coresight/coresight-config.h
> > +++ b/drivers/hwtracing/coresight/coresight-config.h
> > @@ -228,7 +228,7 @@ struct cscfg_feature_csdev {
> > * @feats_csdev:references to the device features to enable.
> > */
> > struct cscfg_config_csdev {
> > - const struct cscfg_config_desc *config_desc;
> > + struct cscfg_config_desc *config_desc;
> > struct coresight_device *csdev;
> > bool enabled;
> > struct list_head node;
> > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
> > index 5d194b9269f5..6d8c212ad434 100644
> > --- a/drivers/hwtracing/coresight/coresight-syscfg.c
> > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c
> > @@ -870,6 +870,25 @@ void cscfg_csdev_reset_feats(struct coresight_device *csdev)
> > }
> > EXPORT_SYMBOL_GPL(cscfg_csdev_reset_feats);
> >
> > +static bool cscfg_config_desc_get(struct cscfg_config_desc *config_desc)
>
> I would like to change the return type to int, so the error is handled
> within the function. As a result, the caller _cscfg_activate_config()
> does not need to explicitly return an error value.
I think it's not good since cscfg_config_desc_get() failed only when
try_module_get() failed and its return type is "bool".
also, If we make defines error type in here it would make different
error code compared before this patch in some function
(i.e) cscfg_csdev_enable_active_config() want to receive -EBUSY when
cscfg_config_desc_get() failed but _cscfg_activate_config() want to
return -EINVAL.
So I think it would be good to sustain current return type.
>
> Otherwise, the patch looks good to me.
Thanks ;)
--
Sincerely,
Yeoreum Yun
next prev parent reply other threads:[~2025-05-14 11:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-13 17:06 [PATCH v5] " Yeoreum Yun
2025-05-13 17:06 ` [PATCH v5 1/3] coresight/etm4: fix missing disable active config Yeoreum Yun
2025-05-13 17:06 ` [PATCH v5 2/3] coresight: holding cscfg_csdev_lock while removing cscfg from csdev Yeoreum Yun
2025-05-13 17:06 ` [PATCH v5 3/3] coresight: prevent deactivate active config while enabling the config Yeoreum Yun
2025-05-14 9:30 ` Leo Yan
2025-05-14 9:39 ` Leo Yan
2025-05-14 11:14 ` Yeoreum Yun
2025-05-14 11:04 ` Yeoreum Yun [this message]
2025-05-14 12:47 ` Leo Yan
2025-05-14 9:15 ` [PATCH v5 2/3] coresight: holding cscfg_csdev_lock while removing cscfg from csdev Leo Yan
2025-05-14 11:13 ` Yeoreum Yun
2025-05-14 9:05 ` [PATCH v5 1/3] coresight/etm4: fix missing disable active config Leo Yan
2025-05-14 11:16 ` Yeoreum Yun
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=aCR4x/+Wp8JoqG9P@e129823.arm.com \
--to=yeoreum.yun@arm.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=coresight@lists.linaro.org \
--cc=james.clark@linaro.org \
--cc=leo.yan@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mike.leach@linaro.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®