Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4610697pxj; Wed, 12 May 2021 09:12:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRuQWp3o4rD7heLu2R/6mM4JdMct68sfifmqp3WOjQVtnIRIt+LZB96TFlDxrJ9tqcbiPH X-Received: by 2002:a17:906:5855:: with SMTP id h21mr38927451ejs.522.1620835932074; Wed, 12 May 2021 09:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620835932; cv=none; d=google.com; s=arc-20160816; b=SqmESAyIA/LnWcimJNV9Csg3yy51wTDG5ElP1+rwCjwpIhBOCzTj/62KJhxbAF7Usy VpxpXGxn5Yu3H1TN3vUqIUEFe06kFOIaWJiH0XVEpOdVr1sUdU2TIHZDmxcr3/SO2QN/ mSLBGBbYxuacdIkhHv2LrYicq/e4zO0N7G1qoA+XB0l/HQRNVwx30Ueza1lJwYrRxW09 d5Hn/MOLTL9XlJQjrK4PLQIC25T5Snneka5NGt2apoAAzT0R2g9aL5NS61Tdr7PLs0PI IgyiXCi5E7pB9ZyFRKwvOie0IsNQnx4JdXj4e0/kYxnXvyuDT08BazeSqRYUFQnanh07 yJiQ== 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=NIBdMHQId8RIzd2YolgXOwdXXoCjjJ6rPYsaeY7J3+w=; b=Fb4atkqZZxqIwt2ifbZvLHkVNQ5txud2vcfIlXZO6vXxbNcVelzb9ppYQHVktSokD2 6xy9vYXjtuW5SzSjoVNRdb1iQMvDzfSmg2Oj/4eaHP2VrD0u6pxhsc6NSZnlUbsA3uYF abvDP2jIjcHYJlcY3QKzy/9eRadWkBHCB5yeT1j31LSGxolMZwDlHBYMHLIBlCHouh1W R6oVyuMnbT78P509Uo40zQRW6I/I61rw2M2nMhbX6EKVvsxcs7umSOYDeLNWgLlwyVug e8cqXRVksmZvz/bu9VGrC7w2NGOq/llbcYUePqJzRAOrBulIzibLOf/3Nkt4HteVxbBv S7nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=I0B60Yio; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x22si100300eds.436.2021.05.12.09.11.46; Wed, 12 May 2021 09:12:12 -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=@linuxfoundation.org header.s=korg header.b=I0B60Yio; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238626AbhELQFf (ORCPT + 99 others); Wed, 12 May 2021 12:05:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:60684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233130AbhELPWZ (ORCPT ); Wed, 12 May 2021 11:22:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1D608619A9; Wed, 12 May 2021 15:09:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832158; bh=nXDLBNMrHYxJwDY+JVZ/Pfhp5PNeJ7cfxZNcM0lP47I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I0B60YioYHlFbJC7+uk6vC5I8xOWSmcAbkovET7e2Oa1gCHziA3iY5JH/NnwWf2nP GgxROLeYcVu1YMLXYXvMvx27nzwcPdKd/+E2DaANttoDA+6mbTIVjAZZgCOwYJNKtp uYDhPIljZPaai302UgPB0DJnk6czCdUrBmAan0mU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Alain Volmat , Mark Brown , Sasha Levin Subject: [PATCH 5.10 165/530] spi: stm32: Fix use-after-free on unbind Date: Wed, 12 May 2021 16:44:35 +0200 Message-Id: <20210512144825.262262954@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alain Volmat [ Upstream commit 79c6246ae8793448c05da86a4c82298eed8549b0 ] stm32_spi_remove() accesses the driver's private data after calling spi_unregister_master() even though that function releases the last reference on the spi_master and thereby frees the private data. Fix by switching over to the new devm_spi_alloc_master() helper which keeps the private data accessible until the driver has unbound. Fixes: 8d559a64f00b ("spi: stm32: drop devres version of spi_register_master") Reported-by: Lukas Wunner Signed-off-by: Alain Volmat Link: https://lore.kernel.org/r/1616052290-10887-1-git-send-email-alain.volmat@foss.st.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-stm32.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 8d8a32d46f2d..0318f02d6212 100644 --- a/drivers/spi/spi-stm32.c +++ b/drivers/spi/spi-stm32.c @@ -1830,7 +1830,7 @@ static int stm32_spi_probe(struct platform_device *pdev) struct resource *res; int ret; - master = spi_alloc_master(&pdev->dev, sizeof(struct stm32_spi)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(struct stm32_spi)); if (!master) { dev_err(&pdev->dev, "spi master allocation failed\n"); return -ENOMEM; @@ -1848,18 +1848,16 @@ static int stm32_spi_probe(struct platform_device *pdev) res = platform_get_resource(pdev, IORESOURCE_MEM, 0); spi->base = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(spi->base)) { - ret = PTR_ERR(spi->base); - goto err_master_put; - } + if (IS_ERR(spi->base)) + return PTR_ERR(spi->base); spi->phys_addr = (dma_addr_t)res->start; spi->irq = platform_get_irq(pdev, 0); - if (spi->irq <= 0) { - ret = dev_err_probe(&pdev->dev, spi->irq, "failed to get irq\n"); - goto err_master_put; - } + if (spi->irq <= 0) + return dev_err_probe(&pdev->dev, spi->irq, + "failed to get irq\n"); + ret = devm_request_threaded_irq(&pdev->dev, spi->irq, spi->cfg->irq_handler_event, spi->cfg->irq_handler_thread, @@ -1867,20 +1865,20 @@ static int stm32_spi_probe(struct platform_device *pdev) if (ret) { dev_err(&pdev->dev, "irq%d request failed: %d\n", spi->irq, ret); - goto err_master_put; + return ret; } spi->clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(spi->clk)) { ret = PTR_ERR(spi->clk); dev_err(&pdev->dev, "clk get failed: %d\n", ret); - goto err_master_put; + return ret; } ret = clk_prepare_enable(spi->clk); if (ret) { dev_err(&pdev->dev, "clk enable failed: %d\n", ret); - goto err_master_put; + return ret; } spi->clk_rate = clk_get_rate(spi->clk); if (!spi->clk_rate) { @@ -1976,8 +1974,6 @@ err_dma_release: dma_release_channel(spi->dma_rx); err_clk_disable: clk_disable_unprepare(spi->clk); -err_master_put: - spi_master_put(master); return ret; } -- 2.30.2