lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <aS1wSVFnOE906wLc@google.com>
Date: Mon, 1 Dec 2025 18:39:05 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: James Clark <james.clark@...aro.org>
Cc: suzuki.poulose@....com, mike.leach@...aro.org,
	alexander.shishkin@...ux.intel.com, gregkh@...uxfoundation.org,
	mathieu.poirier@...aro.org, leo.yan@....com, Al.Grant@....com,
	jserv@...s.ncku.edu.tw, marscheng@...gle.com, ericchancf@...gle.com,
	milesjiang@...gle.com, nickpan@...gle.com,
	coresight@...ts.linaro.org, linux-arm-kernel@...ts.infradead.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2] coresight: etm3x: Fix cntr_val_show() to match
 cntr_val_store() behavior

On Mon, Dec 01, 2025 at 10:25:25AM +0000, James Clark wrote:
> 
> 
> On 01/12/2025 9:52 am, Kuan-Wei Chiu wrote:
> > The cntr_val_show() function was intended to print the values of all
> > counters using a loop. However, due to a buffer overwrite issue with
> > sprintf(), it effectively only displayed the value of the last counter.
> > 
> > The companion function, cntr_val_store(), allows users to modify a
> > specific counter selected by 'cntr_idx'. To maintain consistency
> > between read and write operations and to align with the ETM4x driver
> > behavior, modify cntr_val_show() to report only the value of the
> > currently selected counter.
> > 
> > This change removes the loop and the "counter %d:" prefix, printing
> > only the hexadecimal value. It also adopts sysfs_emit() for standard
> > sysfs output formatting.
> > 
> > Fixes: a939fc5a71ad ("coresight-etm: add CoreSight ETM/PTM driver")
> > Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
> > ---
> > Build test only.
> > 
> > Changes in v2:
> > - Redesigned the fix to match cntr_val_store() logic (display only the
> >    currently selected counter) instead of attempting to list all
> >    counters.
> > - Removed the loop and the "counter %d:" prefix.
> > - Switched from sprintf() to sysfs_emit().
> > - Refactored control flow to use a single return point.
> > 
> > v1: https://lore.kernel.org/lkml/20251121002350.1166758-1-visitorckw@gmail.com/
> > 
> >   .../hwtracing/coresight/coresight-etm3x-sysfs.c   | 15 ++++-----------
> >   1 file changed, 4 insertions(+), 11 deletions(-)
> > 
> > diff --git a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > index 762109307b86..a6a650331196 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm3x-sysfs.c
> > @@ -717,26 +717,19 @@ static DEVICE_ATTR_RW(cntr_rld_event);
> >   static ssize_t cntr_val_show(struct device *dev,
> >   			     struct device_attribute *attr, char *buf)
> >   {
> > -	int i, ret = 0;
> >   	u32 val;
> >   	struct etm_drvdata *drvdata = dev_get_drvdata(dev->parent);
> >   	struct etm_config *config = &drvdata->config;
> >   	if (!coresight_get_mode(drvdata->csdev)) {
> >   		spin_lock(&drvdata->spinlock);
> > -		for (i = 0; i < drvdata->nr_cntr; i++)
> > -			ret += sprintf(buf, "counter %d: %x\n",
> > -				       i, config->cntr_val[i]);
> > +		val = config->cntr_val[config->cntr_idx];
> >   		spin_unlock(&drvdata->spinlock);
> > -		return ret;
> > -	}
> > -
> > -	for (i = 0; i < drvdata->nr_cntr; i++) {
> > -		val = etm_readl(drvdata, ETMCNTVRn(i));
> > -		ret += sprintf(buf, "counter %d: %x\n", i, val);
> > +	} else {
> > +		val = etm_readl(drvdata, ETMCNTVRn(config->cntr_idx));
> >   	}
> > -	return ret;
> > +	return sysfs_emit(buf, "%x\n", val);
> 
> Sorry I missed this on the previous version, but this should be %#x to add
> the "0x" prefix. All the other ones in this file have it. Otherwise you
> can't tell the difference between decimal and hex.
> 

Thanks for catching that. I will fix it in v3.

I'll wait a day or two to see if there are any other comments, and then
respin with the Cc stable tag.

Regards,
Kuan-Wei

> >   }
> >   static ssize_t cntr_val_store(struct device *dev,
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ