Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp479715imn; Wed, 27 Jul 2022 11:21:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1smAXgdpsopR3AVgJcAW+jBLatVAApalLcI+7xM2H9F2ohdWBepuSNFpGvqJKJ4wO2mvJYg X-Received: by 2002:a05:6402:84d:b0:435:a764:9aad with SMTP id b13-20020a056402084d00b00435a7649aadmr24744181edz.332.1658946094697; Wed, 27 Jul 2022 11:21:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658946094; cv=none; d=google.com; s=arc-20160816; b=VlKKyf739sPSs+fxEtu2uYZxqqEhzgrOqnuw7nM5s8BjWRi/exKh4F5O/RRw2lpgW1 SihyAi36IKN8keYF2TjQ1IwvxdhFIUvcImtcUlh9uaQTrUAKQ850ZvutUGuBX6KVBJQt tJo11AUA9k3wc8lVHnbt6dRw0ewIQTjGMCcxh9WxQ2KVXekvNVNGhytLiY9C9afOW+kg goMbvWVG6VSCnBmJG0mwLqoBF9WdqHIuXh2JZd3yF8irENtytezlgNVrRJIcDdSrEBOA qzZ2gsMjIjhKvtlLdoC73WCj5HXXVsJDLetSW579m9HAXNASRA28/jv7Lck9i3jtunz2 ylfQ== 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=RjPRD9nMYZqPmdSC6uZM0h0hvrrgpZU6NUJ1mmcneq0=; b=mnHGMSIYRQjlOjwFEPowba9UwMpEBzl7oCCfZ/L8zqJ9aO36ba9gAsyAHq239Op8dU 0RVfGLlTN12/iZbJUzeW8Hkfa70fFdkowXv+lMYjd7LXlNl4T24FQIv0llX1UH1e9tca ikDPWjio2cSw0uxUCoskTDL5qlrJBCpDW5GnYlaQkOUayAdmwPCr8EYHaPom6/YCRexd 6paUgT9DjMNS+nkIhxd3Mrvx8lJ//n+vY51YvulcrPzpEwjIHqLFiXxnegHr2xhPk6rv UJNqHrjxRBqlSYdEk9kYwbagVQThAXeeYRFNf5AowBjT774h7BGylwO0WYaii2/b82fz L4hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fCFlkXne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a056402518e00b0043ac5ba36easi21065172edd.419.2022.07.27.11.21.09; Wed, 27 Jul 2022 11:21:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=fCFlkXne; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S239867AbiG0Qmp (ORCPT + 99 others); Wed, 27 Jul 2022 12:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239220AbiG0QmP (ORCPT ); Wed, 27 Jul 2022 12:42:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 148D75C357; Wed, 27 Jul 2022 09:29:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DF5B261A39; Wed, 27 Jul 2022 16:29:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE92EC433D6; Wed, 27 Jul 2022 16:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658939395; bh=HBTuDHmlNIq/Hz/znquvPZXH2RPXYA59ZP/S06U5vHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fCFlkXne+xvJ4NpRvMhL4G2jqN2oRS8kmNmYqJCBwCFpb0IYaHmsGPbHScLtwLMlP tnU4xovbf+XrwJ6lMdhdgtUPsy5SowECoow7VAQI4QTKEhsFdBO4loLzOkNmWFKgMp 1/5IW7jO6uqS84AICYHj2PSxlfZmZxxtrn2wvwWs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Marc Kleine-Budde , Mark Brown Subject: [PATCH 5.4 55/87] spi: bcm2835: bcm2835_spi_handle_err(): fix NULL pointer deref for non DMA transfers Date: Wed, 27 Jul 2022 18:10:48 +0200 Message-Id: <20220727161011.295157882@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220727161008.993711844@linuxfoundation.org> References: <20220727161008.993711844@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Kleine-Budde commit 4ceaa684459d414992acbefb4e4c31f2dfc50641 upstream. In case a IRQ based transfer times out the bcm2835_spi_handle_err() function is called. Since commit 1513ceee70f2 ("spi: bcm2835: Drop dma_pending flag") the TX and RX DMA transfers are unconditionally canceled, leading to NULL pointer derefs if ctlr->dma_tx or ctlr->dma_rx are not set. Fix the NULL pointer deref by checking that ctlr->dma_tx and ctlr->dma_rx are valid pointers before accessing them. Fixes: 1513ceee70f2 ("spi: bcm2835: Drop dma_pending flag") Cc: Lukas Wunner Signed-off-by: Marc Kleine-Budde Link: https://lore.kernel.org/r/20220719072234.2782764-1-mkl@pengutronix.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-bcm2835.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -1159,10 +1159,14 @@ static void bcm2835_spi_handle_err(struc struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr); /* if an error occurred and we have an active dma, then terminate */ - dmaengine_terminate_sync(ctlr->dma_tx); - bs->tx_dma_active = false; - dmaengine_terminate_sync(ctlr->dma_rx); - bs->rx_dma_active = false; + if (ctlr->dma_tx) { + dmaengine_terminate_sync(ctlr->dma_tx); + bs->tx_dma_active = false; + } + if (ctlr->dma_rx) { + dmaengine_terminate_sync(ctlr->dma_rx); + bs->rx_dma_active = false; + } bcm2835_spi_undo_prologue(bs); /* and reset */