Skip to content

Commit 22b2bea

Browse files
Sai Prakash Ranjangregkh
authored andcommitted
coresight: etb10: Fix possible NULL ptr dereference in etb_enable_perf()
There was a report of NULL pointer dereference in ETF enable path for perf CS mode with PID monitoring. It is almost 100% reproducible when the process to monitor is something very active such as chrome and with ETF as the sink, not ETR. But code path shows that ETB has a similar path as ETF, so there could be possible NULL pointer dereference crash in ETB as well. Currently in a bid to find the pid, the owner is dereferenced via task_pid_nr() call in etb_enable_perf() and with owner being NULL, we can get a NULL pointer dereference, so have a similar fix as ETF where we cache PID in alloc_buffer() callback which is called as the part of etm_setup_aux(). Fixes: 75d7dbd ("coresight: etb10: Add support for CPU-wide trace scenarios") Cc: [email protected] Signed-off-by: Sai Prakash Ranjan <[email protected]> Signed-off-by: Mathieu Poirier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 868663d commit 22b2bea

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/hwtracing/coresight/coresight-etb10.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int etb_enable_perf(struct coresight_device *csdev, void *data)
176176
unsigned long flags;
177177
struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
178178
struct perf_output_handle *handle = data;
179+
struct cs_buffers *buf = etm_perf_sink_config(handle);
179180

180181
spin_lock_irqsave(&drvdata->spinlock, flags);
181182

@@ -186,7 +187,7 @@ static int etb_enable_perf(struct coresight_device *csdev, void *data)
186187
}
187188

188189
/* Get a handle on the pid of the process to monitor */
189-
pid = task_pid_nr(handle->event->owner);
190+
pid = buf->pid;
190191

191192
if (drvdata->pid != -1 && drvdata->pid != pid) {
192193
ret = -EBUSY;
@@ -383,6 +384,7 @@ static void *etb_alloc_buffer(struct coresight_device *csdev,
383384
if (!buf)
384385
return NULL;
385386

387+
buf->pid = task_pid_nr(event->owner);
386388
buf->snapshot = overwrite;
387389
buf->nr_pages = nr_pages;
388390
buf->data_pages = pages;

0 commit comments

Comments
 (0)