public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] coresight: tmc: Explicit type conversions to prevent integer overflow
@ 2023-07-14  8:43 Ruidong Tian
  2023-07-24 15:38 ` James Clark
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Ruidong Tian @ 2023-07-14  8:43 UTC (permalink / raw)
  To: tianruidong, coresight
  Cc: suzuki.poulose, mike.leach, alexander.shishkin, linux-arm-kernel,
	linux-kernel

Perf cs_etm session will failed when AUX buffer > 1G.

  perf record -C 0 -m ,2G -e cs_etm// -- taskset -c 0 ls
  failed to mmap with 12 (Cannot allocate memory)

In coresight tmc driver, "nr_pages << PAGE_SHIFT" will overflow when
nr_pages >= 0x80000(correspond to 1G AUX buffer). Explicit convert nr_pages
to 64 bit to avoid overflow.

Signed-off-by: Ruidong Tian <tianruidong@linux.alibaba.com>
---
 drivers/hwtracing/coresight/coresight-tmc-etr.c | 2 +-
 drivers/hwtracing/coresight/coresight-tmc.h     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index 766325de0e29..1425ecd1cf78 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -1267,7 +1267,7 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event,
 	 * than the size requested via sysfs.
 	 */
 	if ((nr_pages << PAGE_SHIFT) > drvdata->size) {
-		etr_buf = tmc_alloc_etr_buf(drvdata, (nr_pages << PAGE_SHIFT),
+		etr_buf = tmc_alloc_etr_buf(drvdata, ((ssize_t)nr_pages << PAGE_SHIFT),
 					    0, node, NULL);
 		if (!IS_ERR(etr_buf))
 			goto done;
diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h
index b97da39652d2..0ee48c5ba764 100644
--- a/drivers/hwtracing/coresight/coresight-tmc.h
+++ b/drivers/hwtracing/coresight/coresight-tmc.h
@@ -325,7 +325,7 @@ ssize_t tmc_sg_table_get_data(struct tmc_sg_table *sg_table,
 static inline unsigned long
 tmc_sg_table_buf_size(struct tmc_sg_table *sg_table)
 {
-	return sg_table->data_pages.nr_pages << PAGE_SHIFT;
+	return (unsigned long)sg_table->data_pages.nr_pages << PAGE_SHIFT;
 }
 
 struct coresight_device *tmc_etr_get_catu_device(struct tmc_drvdata *drvdata);
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-08-04 13:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-14  8:43 [RESEND PATCH] coresight: tmc: Explicit type conversions to prevent integer overflow Ruidong Tian
2023-07-24 15:38 ` James Clark
2023-08-02 12:25   ` Ruidong Tian
2023-08-02 12:32     ` James Clark
2023-08-03  2:33 ` [PATCH v2] " Ruidong Tian
2023-08-03 16:19   ` Suzuki K Poulose
2023-08-04  3:06     ` Ruidong Tian
2023-08-04  8:15 ` [PATCH v3 0/1] coresight: tmc: Explicit type conversions to Ruidong Tian
2023-08-04  8:15   ` [PATCH v3 1/1] coresight: tmc: Explicit type conversions to prevent integer overflow Ruidong Tian
2023-08-04 13:16     ` Suzuki K Poulose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox