From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17A5AC433E7 for ; Tue, 13 Oct 2020 16:36:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 93D44252A7 for ; Tue, 13 Oct 2020 16:36:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cxSpjlBT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93D44252A7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=O30xoS6wrMpWS8D5jFdCLMfyN6A5U1ISgqcc8XpClBI=; b=cxSpjlBTCGxp8bj5xH9X6izJJ LaRdtbk0PtekNuIzEvNUrt0aBxzJt9UxPgp6XyxT8+HxiBad5ihvO3duXVUCZXBNshERBU5bMEmG5 wIc7PNQRmmO/2R9Cbfe87CrbmgXU4hvWnq7SCGI19JkjghZMq+jUJHeDxxM6J2hMoDIJKoJIqa4y+ YFOy4hlLmODCABYlnbVdt/D7iU/EYlus9PYugvQZwuQEWVErVcM4Y82WeRg7VBCpyoKTeDMPSRIyY JctTZoiKyE0zJTYFB0aH5lzs3LvA49hNiy2ZKglqLVtCoTGtqqu1yX7hhfqXLGt+NS7kxxHMRiBH1 EQeMjPMpQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSNGj-00057a-OL; Tue, 13 Oct 2020 16:35:21 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kSNGf-00055s-U9 for linux-arm-kernel@lists.infradead.org; Tue, 13 Oct 2020 16:35:19 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D92E931B; Tue, 13 Oct 2020 09:35:15 -0700 (PDT) Received: from [10.57.50.28] (unknown [10.57.50.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B9FA3F66B; Tue, 13 Oct 2020 09:35:13 -0700 (PDT) Subject: Re: [PATCH 1/2] coresight: tmc-etf: Fix NULL ptr dereference in tmc_enable_etf_sink_perf() To: saiprakash.ranjan@codeaurora.org, mathieu.poirier@linaro.org, mike.leach@linaro.org References: From: Suzuki K Poulose Message-ID: <5bbb2d35-3e56-56d7-4722-bf34c5efa2fb@arm.com> Date: Tue, 13 Oct 2020 17:35:11 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201013_123518_035925_86EF3E24 X-CRM114-Status: GOOD ( 19.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peterz@infradead.org, linux-arm-msm@vger.kernel.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, swboyd@chromium.org, denik@google.com, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 10/07/2020 02:00 PM, Sai Prakash Ranjan wrote: > 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 and not ETR. > Currently in a bid to find the pid, the owner is dereferenced > via task_pid_nr() call in tmc_enable_etf_sink_perf() and with > owner being NULL, we get a NULL pointer dereference. > > Looking at the ETR and other places in the kernel, ETF and the > ETB are the only places trying to dereference the task(owner) > in tmc_enable_etf_sink_perf() which is also called from the > sched_in path as in the call trace. Owner(task) is NULL even > in the case of ETR in tmc_enable_etr_sink_perf(), but since we > cache the PID in alloc_buffer() callback and it is done as part > of etm_setup_aux() when allocating buffer for ETR sink, we never > dereference this NULL pointer and we are safe. So lets do the The patch is necessary to fix some of the issues. But I feel it is not complete. Why is it safe earlier and not later ? I believe we are simply reducing the chances of hitting the issue, by doing this earlier than later. I would say we better fix all instances to make sure that the event->owner is valid. (e.g, I can see that the for kernel events event->owner == -1 ?) struct task_struct *tsk = READ_ONCE(event->owner); if (!tsk || is_kernel_event(event)) /* skip ? */ Suzuki _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel