Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp86364pxu; Wed, 14 Oct 2020 21:11:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJ0YOKAHglzruX5B3bAM6w8yBXzaR7AC3GcUuk5S1OiP9dSzJw2Zxdg7YWQ448wdWzuKVs X-Received: by 2002:a05:6402:293:: with SMTP id l19mr2334473edv.227.1602735117994; Wed, 14 Oct 2020 21:11:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602735117; cv=none; d=google.com; s=arc-20160816; b=l3zQk4FNRGuui9qlP5rsPTLIui4u0Node925NLmyWfpvoD1XVAAU/B33Nj29v5i/2j mJWGUCTWkWn8Ph8flPmNOgUuQohUY0sDG2i/9pF0UuVRynpJujhgiF1oZo386nV24rGe eiW6Do804pejPmbgrt9lQQLEHhZrzkuqcvCG5016/TvKM9cBBaTsInwu8H3X5bNtqaF5 tJ5YbJa56r2yCFBw+3LhT21F0SJiGlxmpAuUwDrD3Gqciz9RDQUxEVdkQlqAmDiNaO6g wxJmkaXiECNn2sR3oMkkWEn9YKZbwYHajSxY2N2Gr984HcFk7jGlMSQSuYqteKk4SLyJ hVow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:in-reply-to:mime-version :user-agent:date:message-id:autocrypt:from:references:cc:to:subject :dkim-signature; bh=EJ2PeMhfc4rmZlGA6v6wKoYQzDqFqC0A/22GiKcGyRg=; b=J0ErQyQBvs4j224ZDx7cxiP3WCJFmuqOIV3i6QqYZdQss5MKC6CaTcTdpV/ujdH5mg Vy5gMHq7ZR1kDbXRLwcproIUeBad/0wm3VtejsM6QbQ0Eahd7AoUiPqWf1jRwwcsMKnW e81Dk9mQ2Dl3hERNZk8zA1GvW3zVT8gzu5kL/+XtZDuD28tFK8VUSvaMMin981oyUDGP c+nUut0za0bYzXV0KTClLwCgHSH8a4/GzfCzwRRTPdJge+o4CeTHNQc9q6ionq/h8vPb Xrrdax7lTbKRwmxPZIeIrsmfNZZeffv4X+81DgXlZ568JVfywhUwhXM6v8rHAnH19ee/ ewiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=trE29uCY; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si1308041eja.468.2020.10.14.21.11.35; Wed, 14 Oct 2020 21:11:57 -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=@gmail.com header.s=20161025 header.b=trE29uCY; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729837AbgJOCJi (ORCPT + 99 others); Wed, 14 Oct 2020 22:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726115AbgJOCJh (ORCPT ); Wed, 14 Oct 2020 22:09:37 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEE6BC0613B0; Wed, 14 Oct 2020 14:20:19 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id p11so384817pld.5; Wed, 14 Oct 2020 14:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:autocrypt:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=EJ2PeMhfc4rmZlGA6v6wKoYQzDqFqC0A/22GiKcGyRg=; b=trE29uCY5w5HHbZlzdkeWcnWNM9IqcWz2fl3QTWt+Ug1H7p1DmtZy2RvTrCXHoYFa/ mdCNe78aAoAYVL53Se/iq0m6mKwFdG0MHXsa7yCqdtWfwL0czVeAfjEwjH0RF7Nq6NRF GV0dk4+YMgm3ADnE6cnV2pK1CsyG7Zu5B1WZ2PBUUEzHKNHp3oXHe+P24sHIdELvmRSW iH2T7pqBygCIqPHBi/LSDF2SQpyGAcQFNbzFlU/NLNhcZ4PkhDnPziMLEPOABwwzcAor bhk4BEAYmQClZbEYfT2S9VxZkpnjoUBkhKmK9fw4ARUMLODQhtbFs4sM0r9PibcxpdJu CQhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language; bh=EJ2PeMhfc4rmZlGA6v6wKoYQzDqFqC0A/22GiKcGyRg=; b=CQiQVhTdK2VljWPssIhiP1N6HvOxDTI6SxVk0Q1qsLwAMbx4nv2NP01NH/37epGbQ+ XfRBsM1dsHl5kV95VQM2jbZvDSwz/jF2IusW17BcCHbxUBxRJe8qDcrCntmDZWTkCnWZ IYFe6tEBIGN12rLc/VyRG8fzIfEUqIr26ZkGVEO0CygzpnrB0rcU0wNBA1fySwbDcuxl Nuk0dklrC2N1k9ad66WJ3qi1U6sc5YG+rrcktDNeEwizdP2SwYS0goTwc2fNY2HtT0DY JhfQU4Lqi+r/8JvoJKv+ghvYD//D0GRDl6QtzwYP+eaNu77+z0QwNBI4fA+mC0dDM7DY vjRQ== X-Gm-Message-State: AOAM5315lvaVe6NAG8JvnaAJK6a1chXSDEmIaDbs4GeNySY3UJegZoKa KBVKnjm2fGprqq311rywNg1J8CEzPEY= X-Received: by 2002:a17:90a:9ec:: with SMTP id 99mr1079971pjo.138.1602710419036; Wed, 14 Oct 2020 14:20:19 -0700 (PDT) Received: from [10.67.48.230] ([192.19.223.252]) by smtp.googlemail.com with ESMTPSA id y13sm537705pfl.166.2020.10.14.14.20.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Oct 2020 14:20:18 -0700 (PDT) Subject: Re: Use after free in bcm2835_spi_remove() To: Mark Brown , Vladimir Oltean Cc: Lukas Wunner , "linux-kernel@vger.kernel.org" , linux-spi References: <20201014140912.GB24850@wunner.de> <20201014194035.ukduovokggu37uba@skbuf> <20201014202505.GF4580@sirena.org.uk> From: Florian Fainelli Autocrypt: addr=f.fainelli@gmail.com; prefer-encrypt=mutual; keydata= mQGiBEjPuBIRBACW9MxSJU9fvEOCTnRNqG/13rAGsj+vJqontvoDSNxRgmafP8d3nesnqPyR xGlkaOSDuu09rxuW+69Y2f1TzjFuGpBk4ysWOR85O2Nx8AJ6fYGCoeTbovrNlGT1M9obSFGQ X3IzRnWoqlfudjTO5TKoqkbOgpYqIo5n1QbEjCCwCwCg3DOH/4ug2AUUlcIT9/l3pGvoRJ0E AICDzi3l7pmC5IWn2n1mvP5247urtHFs/uusE827DDj3K8Upn2vYiOFMBhGsxAk6YKV6IP0d ZdWX6fqkJJlu9cSDvWtO1hXeHIfQIE/xcqvlRH783KrihLcsmnBqOiS6rJDO2x1eAgC8meAX SAgsrBhcgGl2Rl5gh/jkeA5ykwbxA/9u1eEuL70Qzt5APJmqVXR+kWvrqdBVPoUNy/tQ8mYc nzJJ63ng3tHhnwHXZOu8hL4nqwlYHRa9eeglXYhBqja4ZvIvCEqSmEukfivk+DlIgVoOAJbh qIWgvr3SIEuR6ayY3f5j0f2ejUMYlYYnKdiHXFlF9uXm1ELrb0YX4GMHz7QnRmxvcmlhbiBG YWluZWxsaSA8Zi5mYWluZWxsaUBnbWFpbC5jb20+iGYEExECACYCGyMGCwkIBwMCBBUCCAME Fg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0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20201014202505.GF4580@sirena.org.uk> Content-Type: multipart/mixed; boundary="------------2A71BE36EEA37111A733C50F" Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a multi-part message in MIME format. --------------2A71BE36EEA37111A733C50F Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit On 10/14/20 1:25 PM, Mark Brown wrote: > On Wed, Oct 14, 2020 at 10:40:35PM +0300, Vladimir Oltean wrote: >> On Wed, Oct 14, 2020 at 04:09:12PM +0200, Lukas Wunner wrote: > >>> Apparently the problem is that spi_unregister_controller() drops the >>> last ref on the controller, causing it to be freed, and afterwards we >>> access the controller's private data, which is part of the same >>> allocation as struct spi_controller: > >>> bcm2835_spi_remove() >>> spi_unregister_controller() >>> device_unregister() >>> put_device() >>> spi_controller_release() # spi_master_class.dev_release() >>> kfree(ctlr) >>> bcm2835_dma_release(ctlr, bs) > >> Also see these threads: >> https://lore.kernel.org/linux-spi/20200922112241.GO4792@sirena.org.uk/T/#t >> https://lore.kernel.org/linux-spi/270b94fd1e546d0c17a735c1f55500e58522da04.camel@suse.de/T/#u > > Right, the proposed patch is yet another way to fix the issue - it all > comes back to the fact that you shouldn't be using the driver data after > unregistering if it was allocated as part of allocating the controller. > This framework feature is unfortunately quite error prone. Lukas, your patch works fine for me and is only two lines, so maybe better suited for stable. How about the attached patch? -- Florian --------------2A71BE36EEA37111A733C50F Content-Type: text/x-patch; charset=UTF-8; name="0001-spi-bcm2835-Fix-use-after-free-in-bcm2835_spi_remove.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0001-spi-bcm2835-Fix-use-after-free-in-bcm2835_spi_remove.pa"; filename*1="tch" =46rom a4ee9da1ef09f9ddb04060e644b9c34fd532c189 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Wed, 14 Oct 2020 14:15:28 -0700 Subject: [PATCH] spi: bcm2835: Fix use-after-free in bcm2835_spi_remove()= In bcm2835_spi_remove(), spi_controller_unregister() will free the ctlr reference which will lead to an use after free in bcm2835_release_dma(). To avoid this use after free, allocate the bcm2835_spi structure with a different lifecycle than the spi_controller structure such that we unregister the SPI controller, free up all the resources and finally let device managed allocations free the bcm2835_spi structure. Fixes: 05897c710e8e ("spi: bcm2835: Tear down DMA before turning off SPI = controller") Fixes: 3ecd37edaa2a ("spi: bcm2835: enable dma modes for transfers meetin= g certain conditions") Signed-off-by: Florian Fainelli --- drivers/spi/spi-bcm2835.c | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 41986ac0fbfb..d66358e6b5cd 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -847,42 +847,41 @@ static bool bcm2835_spi_can_dma(struct spi_controll= er *ctlr, return true; } =20 -static void bcm2835_dma_release(struct spi_controller *ctlr, - struct bcm2835_spi *bs) +static void bcm2835_dma_release(struct bcm2835_spi *bs, + struct dma_chan *dma_tx, + struct dma_chan *dma_rx) { int i; =20 - if (ctlr->dma_tx) { - dmaengine_terminate_sync(ctlr->dma_tx); + if (dma_tx) { + dmaengine_terminate_sync(dma_tx); =20 if (bs->fill_tx_desc) dmaengine_desc_free(bs->fill_tx_desc); =20 if (bs->fill_tx_addr) - dma_unmap_page_attrs(ctlr->dma_tx->device->dev, + dma_unmap_page_attrs(dma_tx->device->dev, bs->fill_tx_addr, sizeof(u32), DMA_TO_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); =20 - dma_release_channel(ctlr->dma_tx); - ctlr->dma_tx =3D NULL; + dma_release_channel(dma_tx); } =20 - if (ctlr->dma_rx) { - dmaengine_terminate_sync(ctlr->dma_rx); + if (dma_rx) { + dmaengine_terminate_sync(dma_rx); =20 for (i =3D 0; i < BCM2835_SPI_NUM_CS; i++) if (bs->clear_rx_desc[i]) dmaengine_desc_free(bs->clear_rx_desc[i]); =20 if (bs->clear_rx_addr) - dma_unmap_single(ctlr->dma_rx->device->dev, + dma_unmap_single(dma_rx->device->dev, bs->clear_rx_addr, sizeof(bs->clear_rx_cs), DMA_TO_DEVICE); =20 - dma_release_channel(ctlr->dma_rx); - ctlr->dma_rx =3D NULL; + dma_release_channel(dma_rx); } } =20 @@ -1010,7 +1009,7 @@ static int bcm2835_dma_init(struct spi_controller *= ctlr, struct device *dev, dev_err(dev, "issue configuring dma: %d - not using DMA mode\n", ret); err_release: - bcm2835_dma_release(ctlr, bs); + bcm2835_dma_release(bs, ctlr->dma_tx, ctlr->dma_rx); err: /* * Only report error for deferred probing, otherwise fall back to @@ -1291,12 +1290,17 @@ static int bcm2835_spi_probe(struct platform_devi= ce *pdev) struct bcm2835_spi *bs; int err; =20 + bs =3D devm_kzalloc(&pdev->dev, sizeof(*bs), GFP_KERNEL); + if (!bs) + return -ENOMEM; + ctlr =3D spi_alloc_master(&pdev->dev, ALIGN(sizeof(*bs), dma_get_cache_alignment())); if (!ctlr) return -ENOMEM; =20 - platform_set_drvdata(pdev, ctlr); + spi_controller_set_devdata(ctlr, bs); + platform_set_drvdata(pdev, bs); =20 ctlr->use_gpio_descriptors =3D true; ctlr->mode_bits =3D BCM2835_SPI_MODE_BITS; @@ -1308,7 +1312,6 @@ static int bcm2835_spi_probe(struct platform_device= *pdev) ctlr->prepare_message =3D bcm2835_spi_prepare_message; ctlr->dev.of_node =3D pdev->dev.of_node; =20 - bs =3D spi_controller_get_devdata(ctlr); bs->ctlr =3D ctlr; =20 bs->regs =3D devm_platform_ioremap_resource(pdev, 0); @@ -1362,7 +1365,7 @@ static int bcm2835_spi_probe(struct platform_device= *pdev) return 0; =20 out_dma_release: - bcm2835_dma_release(ctlr, bs); + bcm2835_dma_release(bs, ctlr->dma_tx, ctlr->dma_rx); out_clk_disable: clk_disable_unprepare(bs->clk); out_controller_put: @@ -1372,14 +1375,19 @@ static int bcm2835_spi_probe(struct platform_devi= ce *pdev) =20 static int bcm2835_spi_remove(struct platform_device *pdev) { - struct spi_controller *ctlr =3D platform_get_drvdata(pdev); - struct bcm2835_spi *bs =3D spi_controller_get_devdata(ctlr); + struct bcm2835_spi *bs =3D platform_get_drvdata(pdev); + struct spi_controller *ctlr =3D bs->ctlr; + struct dma_chan *tx_chan =3D ctlr->dma_tx; + struct dma_chan *rx_chan =3D ctlr->dma_rx; =20 bcm2835_debugfs_remove(bs); =20 spi_unregister_controller(ctlr); =20 - bcm2835_dma_release(ctlr, bs); + /* ctlr is freed by spi_unregister_controller() use the cached dma_chan= + * references. + */ + bcm2835_dma_release(bs, tx_chan, rx_chan); =20 /* Clear FIFOs, and disable the HW block */ bcm2835_wr(bs, BCM2835_SPI_CS, --=20 2.25.1 --------------2A71BE36EEA37111A733C50F--