Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp5877481pxu; Wed, 23 Dec 2020 07:38:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQby5BYxxRunp2ic+RO9DPMCn9JgHg96M9uQNq2H+RmMpFvoNjOqmbhlz1+plWj05r2aqg X-Received: by 2002:a05:6402:312c:: with SMTP id dd12mr25602485edb.327.1608737907273; Wed, 23 Dec 2020 07:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608737907; cv=none; d=google.com; s=arc-20160816; b=MHACGkFwO+RH0IHTzA8w1bzV/R5VEqL0DgI42C7sTPXpfKxApuDIo5lzAy2aleYM4m Li4m9i56/Tx0udsAHAybStr9aGXJn8qGXIMbi5o/oeBYOPS/i6hHkVpbLA/W0fB4ChDv pn7OS/iLyeSQKt6YuoYBoTgfujzE5K6EeS3exWIqj9oiU0sIIm4qUJEgdpD1znzhK1yN 0e5ZuPGKdvVigTA2+a348ZCcgdJjXqp3A66Udasp1NUl8ZUv4kceP99HC6sB3xrow5B2 ZlyrYVbhYCW16dTiQwycNpdZBkUJ27kzwdX8mnt1p8ItnWP0GriXGt04k+G3IgTYan/V xzCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GklgdyEow8y4KFbhbVdAQ6dWu+Roq/tYD7B6DL/rByI=; b=R6EW6LQfYVxwa3ZgVBXeAWRTF4af3F3V7EYG8e2wpoeTYGeucv7Hq52dHINwTmQ28I zHmqPDuaiEeyJy3WRA3+/Wt2lPMIEczqn5dPmYwReuiQGH9t9UsnSAGILpAVEEu/jPL5 8xz3UfJ/wVTWknxjeMCVUg5vJmV7jnJlWa591G2hEJjea59h91rjYLZTXdPpcYstKNNj TsOGSX5Ggf3bsVqsiGqnG21h/nL+MiFXaPOBW41BeKPM+t6rICRBbZHKoJ3EhW/ieuRf zMnUh2WcShwRJJWdYJALQeCAQOZ0fXRcXNRDiCoHI1zDug5P35PDmXUKfqA8c8AEUORI atfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ki3QfHMX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z2si14158734ede.501.2020.12.23.07.38.04; Wed, 23 Dec 2020 07:38:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ki3QfHMX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728378AbgLWPeH (ORCPT + 99 others); Wed, 23 Dec 2020 10:34:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:44872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728349AbgLWPeE (ORCPT ); Wed, 23 Dec 2020 10:34:04 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 05ACB23371; Wed, 23 Dec 2020 15:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1608737584; bh=xU/1gEQBhMmzFwy+0MDHIawUXv4l2c99tIP6CZHlV/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ki3QfHMXs+8ea1QYFKFdF34JQ6if7hnJUSico0Jvbwx+gjfi6pgiwU128P0PXTyPc j65nQbD1yBUv7im4fq1NoFbLTo+RgPIgj4Z7lQQHlx9lx63s2UDJdni8J1Sf9R+jq7 F1pL36sBxmZ4ocK4neEVotMgBDphDcYRlcTUY74Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sai Prakash Ranjan , Mathieu Poirier Subject: [PATCH 5.10 18/40] coresight: etb10: Fix possible NULL ptr dereference in etb_enable_perf() Date: Wed, 23 Dec 2020 16:33:19 +0100 Message-Id: <20201223150516.429637132@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201223150515.553836647@linuxfoundation.org> References: <20201223150515.553836647@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sai Prakash Ranjan commit 22b2beaa7f166f550424cbb3b988aeaa7ef0425a upstream. 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: 75d7dbd38824 ("coresight: etb10: Add support for CPU-wide trace scenarios") Cc: stable@vger.kernel.org Signed-off-by: Sai Prakash Ranjan Signed-off-by: Mathieu Poirier Link: https://lore.kernel.org/r/20201127175256.1092685-11-mathieu.poirier@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/coresight/coresight-etb10.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -176,6 +176,7 @@ static int etb_enable_perf(struct coresi unsigned long flags; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct perf_output_handle *handle = data; + struct cs_buffers *buf = etm_perf_sink_config(handle); spin_lock_irqsave(&drvdata->spinlock, flags); @@ -186,7 +187,7 @@ static int etb_enable_perf(struct coresi } /* Get a handle on the pid of the process to monitor */ - pid = task_pid_nr(handle->event->owner); + pid = buf->pid; if (drvdata->pid != -1 && drvdata->pid != pid) { ret = -EBUSY; @@ -383,6 +384,7 @@ static void *etb_alloc_buffer(struct cor if (!buf) return NULL; + buf->pid = task_pid_nr(event->owner); buf->snapshot = overwrite; buf->nr_pages = nr_pages; buf->data_pages = pages;