Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp2945836pxk; Mon, 28 Sep 2020 04:39:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAd1mCHVD94n7KaJFVbDQgZxcyWn4YvPicg6aZscvHerm3kRJLz4rM17Yxg2hj0BFxMvTX X-Received: by 2002:a17:906:17c6:: with SMTP id u6mr1220932eje.95.1601293141093; Mon, 28 Sep 2020 04:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601293141; cv=none; d=google.com; s=arc-20160816; b=cYzor7ecTHQj3HYXf+mbu8WcdAwesRntOgjh4EliBJMSE59bXWBrfAEZ0QxDjEMCHr hsLsOP/El2vQqIfyzmlABFY6HkDVRPvq7ZV4BJROb6WRo2s3Ha3rXbCltyU3106nVrag pVa/SrlWv8gS5IVAs49wRjsPT1CpGI19Vkgna/HXwZxPGH4JjQNv8eMcfO6AQANQtOyA f9YJt2CDQcnFvPEmGuk2Fw2MAAImZ5MAnK19EYcKrC98ZgZs3jXfbrhjCzJWHNnYHaPx r71gX6ngOMRMrPYFurS3dKa1T/ZjElygy6pMFwd1UBvRYq0kXAw6cccjCU5JAkV16n81 Ft7w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dmarc-filter:sender:dkim-signature; bh=oBL3zjdoQKbI5iunkmrCy1l5QeBCHIZ2wF9I7tpKlC4=; b=LFpBgro0Th7/won5hzE+1yuvl5f0Nr78OduYAO5MVTyX2xiIRWcRZ6YWLksQ+FrV0O lQa36YPEMQIkqEjJjp3PgGUuL8w9zFFjaIQ5h57G7hUvhXZixqe/3SfkHelAcpe/CWgd zC3EvfGTiPl7QhyNvS03JXmEZ+6TviBQax0Qmqy1yEKz9Q7JWV+3a5lmbs9/9ftUSSsZ f5gfRpSzrCRI0du4QyFcrWauH49+WLTMFkRgHfwG8PBwmk9753H52suZEeln6ajVaRO2 OLdFGjQWtRIZx4pRTzOcV5ECMCKCR3B9iRHH7TLe1k76pCxT+nBLmRn/YkPiZYW7Epys YwjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=YmtwZHns; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j17si438508ejs.0.2020.09.28.04.38.38; Mon, 28 Sep 2020 04:39:01 -0700 (PDT) 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=@mg.codeaurora.org header.s=smtp header.b=YmtwZHns; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726736AbgI1Lhf (ORCPT + 99 others); Mon, 28 Sep 2020 07:37:35 -0400 Received: from z5.mailgun.us ([104.130.96.5]:25399 "EHLO z5.mailgun.us" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726461AbgI1Lhd (ORCPT ); Mon, 28 Sep 2020 07:37:33 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1601293052; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=oBL3zjdoQKbI5iunkmrCy1l5QeBCHIZ2wF9I7tpKlC4=; b=YmtwZHns4HHo/1HtxiEXfZfvRb9zuQi27H7c0Tjw1+skYZ8WLXHdSGlwEO6/SLpXEepxctk8 tzRXpKm1glSuXh1bkhKzFJ49oK1MC9HkordylO+RcwihnvnTZdwkQ+2DNHs8fLvrMeNEenEy fqqY2licahacKbFAuDXPU/0iWeo= X-Mailgun-Sending-Ip: 104.130.96.5 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n04.prod.us-east-1.postgun.com with SMTP id 5f71cafca965393f18d330ec (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 28 Sep 2020 11:37:32 GMT Sender: saiprakash.ranjan=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 7ABDDC433F1; Mon, 28 Sep 2020 11:37:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from blr-ubuntu-253.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: saiprakash.ranjan) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8BA89C433C8; Mon, 28 Sep 2020 11:37:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8BA89C433C8 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=saiprakash.ranjan@codeaurora.org From: Sai Prakash Ranjan To: Mathieu Poirier , Suzuki K Poulose , Mike Leach Cc: coresight@lists.linaro.org, leo.yan@linaro.org, alexander.shishkin@linux.intel.com, peterz@infradead.org, Stephen Boyd , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Sai Prakash Ranjan Subject: [RFC PATCHv2 1/2] coresight: tmc-etf: Fix NULL pointer dereference in tmc_enable_etf_sink_perf() Date: Mon, 28 Sep 2020 17:07:08 +0530 Message-Id: <751bd7d9fc65cdd3f1d118814193e9d925e2f56f.1601292571.git.saiprakash.ranjan@codeaurora.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There was a report of NULL pointer dereference in ETF enable path for perf CS mode with PID. It is almost 100% reproducible when the process to monitor is something very active such as chrome and only with ETF as the sink. Currently in a bid to find the pid, the owner is dereferenced via task_pid_nr() call in tmc_enable_etf_sink_perf(). With owner being NULL, we get a NULL pointer dereference, so check the owner before dereferencing it to prevent the system crash. perf record -e cs_etm/@tmc_etf0/ -N -p Unable to handle kernel NULL pointer dereference at virtual address 0000000000000548 Mem abort info: ESR = 0x96000006 EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0 EA = 0, S1PTW = 0 Data abort info: ISV = 0, ISS = 0x00000006 CM = 0, WnR = 0 Call trace: tmc_enable_etf_sink+0xe4/0x280 coresight_enable_path+0x168/0x1fc etm_event_start+0x8c/0xf8 etm_event_add+0x38/0x54 event_sched_in+0x194/0x2ac group_sched_in+0x54/0x12c flexible_sched_in+0xd8/0x120 visit_groups_merge+0x100/0x16c ctx_flexible_sched_in+0x50/0x74 ctx_sched_in+0xa4/0xa8 perf_event_sched_in+0x60/0x6c perf_event_context_sched_in+0x98/0xe0 __perf_event_task_sched_in+0x5c/0xd8 finish_task_switch+0x184/0x1cc schedule_tail+0x20/0xec ret_from_fork+0x4/0x18 Signed-off-by: Sai Prakash Ranjan --- I am not sure of this incomplete solution hence the RFC. This issue was also reported when this code was first added [1] but somehow it didn't get much notice at the time. So the NULL pointer is propagated from as far as flexible_sched_in() (might even be earlier than this) in events core and deferenced in ETF code where it crashes. So I am not sure if its a problem with the core code or the etf driver. Plus it is not reproducible with all the processes, just something which is quite active ones such as chrome. This is with 5.4 kernel with all the coresight patches backported, I did go through events/core code from latest kernel to see if we are missing any fixes related to this but I couldn't find any so I believe this problem should also exist on latest kernel as well. [1] https://lists.linaro.org/pipermail/coresight/2019-March/002278.html --- drivers/hwtracing/coresight/coresight-tmc-etf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 44402d413ebb..32f141d943ca 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -242,6 +242,9 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev, void *data) break; } + if (!handle->event->owner) + break; + /* Get a handle on the pid of the process to monitor */ pid = task_pid_nr(handle->event->owner); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation