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=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 3B027C388F7 for ; Thu, 22 Oct 2020 13:34:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A027E24178 for ; Thu, 22 Oct 2020 13:34:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Fl0Adssb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726025AbgJVNe0 (ORCPT ); Thu, 22 Oct 2020 09:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725971AbgJVNe0 (ORCPT ); Thu, 22 Oct 2020 09:34:26 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6130AC0613CE; Thu, 22 Oct 2020 06:34:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Qxyx+8WuGLMGwiLrpDGgc0hdt6eMPydpMviwqwPoqUg=; b=Fl0AdssbEzOpX7eS1DBwN93QE8 p64WFhpy6pR2iDC/1zS2vumFyDI6RIdwMJQjVXA+shrhJxMMnWhUOl6wIsCwXIaRjW+9RJs4xJMyr G+8PV/UJmCWoYpGpSv9PuIzwKE4CWHeoJRKcuKa0OrrPz9yUUYS1z+G683m7XJIwyATTWg45KDnt6 aZyHcDhdA+2gBMfsU4Fz3kBZrguUBPzEAKmO7F79i7c8JdPu2lmk3ZzYaRehdq6OMkr3Cr5PK0zDD KqsA00IE1Yayi3Wu5VbzZxVKf690ofgUJgrdVXefr60yxRrvn0xSmxqekMx2x7kogGQsfY865vvb6 i3Q6YTpw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVajS-000189-2G; Thu, 22 Oct 2020 13:34:18 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 699363011C6; Thu, 22 Oct 2020 15:34:14 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 60603203CC499; Thu, 22 Oct 2020 15:34:14 +0200 (CEST) Date: Thu, 22 Oct 2020 15:34:14 +0200 From: Peter Zijlstra To: Sai Prakash Ranjan Cc: Mark Rutland , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , linux-arm-msm@vger.kernel.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Stephen Boyd , Ingo Molnar , Namhyung Kim , Jiri Olsa , linux-arm-kernel@lists.infradead.org, Mike Leach Subject: Re: [PATCHv2 2/4] coresight: tmc-etf: Fix NULL ptr dereference in tmc_enable_etf_sink_perf() Message-ID: <20201022133414.GH2611@hirez.programming.kicks-ass.net> References: <20201022113214.GD2611@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Thu, Oct 22, 2020 at 06:19:37PM +0530, Sai Prakash Ranjan wrote: > On 2020-10-22 17:02, Peter Zijlstra wrote: > > On Thu, Oct 22, 2020 at 04:27:52PM +0530, Sai Prakash Ranjan wrote: > > > > > 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. > > > > > @@ -391,6 +392,10 @@ static void *tmc_alloc_etf_buffer(struct > > > coresight_device *csdev, > > > { > > > int node; > > > struct cs_buffers *buf; > > > + struct task_struct *task = READ_ONCE(event->owner); > > > + > > > + if (!task || is_kernel_event(event)) > > > + return NULL; > > > > > > This is *wrong*... why do you care about who owns the events? > > > > The original issue was the owner being NULL and causing > a NULL pointer dereference. I did ask some time back > if it is valid for the owner to be NULL [1] and should > probably be handled in events core? No, what I asked is why do you care about ->owner to begin with? That seems wrong. A driver should not touch ->owner _at_all_. 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=-3.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 986D2C388F2 for ; Thu, 22 Oct 2020 13:35:40 +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 18A98222E9 for ; Thu, 22 Oct 2020 13:35:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="m20fXRiv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18A98222E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org 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-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=57eGqDoO3eQtbFh1tflzibitBYFY6OWN3X844Vnod2Y=; b=m20fXRiv+Yo5c5DcGyjY1Kflv 9XWbQJdihdKoh20yFgWoHGsvEYmTQZW9cW/ti1f8Vl6FUzO6WiqgKobshaftAz/TBBc9tslvdv7e4 WFCAZ1g1ioLwMH1uqAT5ylRtfyJBkznWIn0tcmerwICa4KGZ2uyQFQjaxwQQp8mxgF2gVv2489SsQ bBiE89CnmJ+g2zdmeduRPbMW0nHEAwicMNuntSr5i8DnUMQf7aZ7JVw43totf6OkCvvXLzLgKUyoC EgRCS/P42VbKPgGZmq20diOPepEBKoBDoofuIsUjbUHW0Qy8/kO7YO8fhJWt8daasqbJikw5e7e8R X19LETuYw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVajU-00018x-Ns; Thu, 22 Oct 2020 13:34:20 +0000 Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVajS-000189-2G; Thu, 22 Oct 2020 13:34:18 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 699363011C6; Thu, 22 Oct 2020 15:34:14 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 60603203CC499; Thu, 22 Oct 2020 15:34:14 +0200 (CEST) Date: Thu, 22 Oct 2020 15:34:14 +0200 From: Peter Zijlstra To: Sai Prakash Ranjan Subject: Re: [PATCHv2 2/4] coresight: tmc-etf: Fix NULL ptr dereference in tmc_enable_etf_sink_perf() Message-ID: <20201022133414.GH2611@hirez.programming.kicks-ass.net> References: <20201022113214.GD2611@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: 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: Mark Rutland , Mathieu Poirier , Suzuki K Poulose , Alexander Shishkin , linux-arm-msm@vger.kernel.org, coresight@lists.linaro.org, linux-kernel@vger.kernel.org, Arnaldo Carvalho de Melo , Stephen Boyd , Ingo Molnar , Namhyung Kim , Jiri Olsa , linux-arm-kernel@lists.infradead.org, Mike Leach Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Oct 22, 2020 at 06:19:37PM +0530, Sai Prakash Ranjan wrote: > On 2020-10-22 17:02, Peter Zijlstra wrote: > > On Thu, Oct 22, 2020 at 04:27:52PM +0530, Sai Prakash Ranjan wrote: > > > > > 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. > > > > > @@ -391,6 +392,10 @@ static void *tmc_alloc_etf_buffer(struct > > > coresight_device *csdev, > > > { > > > int node; > > > struct cs_buffers *buf; > > > + struct task_struct *task = READ_ONCE(event->owner); > > > + > > > + if (!task || is_kernel_event(event)) > > > + return NULL; > > > > > > This is *wrong*... why do you care about who owns the events? > > > > The original issue was the owner being NULL and causing > a NULL pointer dereference. I did ask some time back > if it is valid for the owner to be NULL [1] and should > probably be handled in events core? No, what I asked is why do you care about ->owner to begin with? That seems wrong. A driver should not touch ->owner _at_all_. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel