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=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham 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 53F83C43461 for ; Tue, 8 Sep 2020 15:24:43 +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 E151B221F0 for ; Tue, 8 Sep 2020 15:24:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QAaHVE3U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E151B221F0 Authentication-Results: mail.kernel.org; dmarc=none (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-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=urYemkzHSCounHCGrzEWciKFFrspGfkMvfPeQ4GkRCI=; b=QAaHVE3UtuMk/w2GTb9bS8JTo vTI5AbHxzpg83NSfDOKbolXQUAzQGaAfzo52E/nK4NxvtPd4xp7X/bp7m92yYYBWSWc57H9AXYmF8 GeicSmIoShlFAGQL00jrGhJR3Yd44DdhDbJ5jcdT/2W2WX36HkuzvUfCHQHs4MLBQp4qHGE3VChic G8CUhQFESNwLunYk28mfEfNRLHO4CyhVshTP4PDG/T6oYpdt2+lMDqv/A1iQ5Be7GMU/OnGPEu6Hs M5GE/7aC8YEIzXM7lVY/K6Tf1YdMZ5RmTqWHYvVHTzGkGQQZfEa0/ItYmfUVGd7l1pdkmsUkVmy1l pffhfxChQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kFfT2-0003A6-J7; Tue, 08 Sep 2020 15:23:32 +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 1kFfSy-00039K-TE for linux-arm-kernel@lists.infradead.org; Tue, 08 Sep 2020 15:23:29 +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 24C35169C; Tue, 8 Sep 2020 08:23:28 -0700 (PDT) Received: from e119603-lin.cambridge.arm.com (unknown [10.57.50.217]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B46B3F73C; Tue, 8 Sep 2020 08:23:26 -0700 (PDT) Date: Tue, 8 Sep 2020 16:24:22 +0100 From: Cristian Marussi To: Sudeep Holla Subject: Re: [PATCH] firmware: arm_scmi: Fix NULL pointer dereference in mailbox_chan_free Message-ID: <20200908152422.GA13913@e119603-lin.cambridge.arm.com> References: <20200908112611.31515-1-sudeep.holla@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200908112611.31515-1-sudeep.holla@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200908_112328_990491_F169AF45 X-CRM114-Status: GOOD ( 22.07 ) 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: Viresh Kumar , linux-arm-kernel@lists.infradead.org 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 Tue, Sep 08, 2020 at 12:26:11PM +0100, Sudeep Holla wrote: > scmi_mailbox is obtained from cinfo->transport_info and the first > call to mailbox_chan_free frees the channel and sets cinfo->transport_info > to NULL. Care is taken to check for non NULL smbox->chan but smbox can > itself be NULL. Fix it by checking for it without which, kernel crashes > with below NULL pointer dereference and eventually kernel panic. > LGTM. Reviewed-by: Cristian Marussi Tested-by: Cristian Marussi Cheers Cristian > Unable to handle kernel NULL pointer dereference at > virtual address 0000000000000038 > Modules linked in: scmi_module(-) > Hardware name: ARM LTD ARM Juno Development Platform/ARM Juno > Development Platform, BIOS EDK II Sep 2 2020 > pstate: 80000005 (Nzcv daif -PAN -UAO BTYPE=--) > pc : mailbox_chan_free+0x2c/0x70 [scmi_module] > lr : idr_for_each+0x6c/0xf8 > Call trace: > mailbox_chan_free+0x2c/0x70 [scmi_module] > idr_for_each+0x6c/0xf8 > scmi_remove+0xa8/0xf0 [scmi_module] > platform_drv_remove+0x34/0x58 > device_release_driver_internal+0x118/0x1f0 > driver_detach+0x58/0xe8 > bus_remove_driver+0x64/0xe0 > driver_unregister+0x38/0x68 > platform_driver_unregister+0x1c/0x28 > scmi_driver_exit+0x38/0x44 [scmi_module] > ---[ end trace 17bde19f50436de9 ]--- > Kernel panic - not syncing: Fatal exception > SMP: stopping secondary CPUs > Kernel Offset: 0x1d0000 from 0xffff800010000000 > PHYS_OFFSET: 0x80000000 > CPU features: 0x0240022,25806004 > Memory Limit: none > ---[ end Kernel panic - not syncing: Fatal exception ]--- > > Cc: Cristian Marussi > Cc: Viresh Kumar > Fixes: 5c8a47a5a91d ("firmware: arm_scmi: Make scmi core independent of the transport type") > Signed-off-by: Sudeep Holla > --- > drivers/firmware/arm_scmi/mailbox.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/firmware/arm_scmi/mailbox.c b/drivers/firmware/arm_scmi/mailbox.c > index cc2de207fe10..4626404be541 100644 > --- a/drivers/firmware/arm_scmi/mailbox.c > +++ b/drivers/firmware/arm_scmi/mailbox.c > @@ -110,7 +110,7 @@ static int mailbox_chan_free(int id, void *p, void *data) > struct scmi_chan_info *cinfo = p; > struct scmi_mailbox *smbox = cinfo->transport_info; > > - if (!IS_ERR(smbox->chan)) { > + if (smbox && !IS_ERR(smbox->chan)) { > mbox_free_channel(smbox->chan); > cinfo->transport_info = NULL; > smbox->chan = NULL; > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel