Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9178084pxu; Mon, 28 Dec 2020 08:31:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJySKV/Y6Sb6leXyTKy/C9Mb2BD7RQ/v54zaQwruOEAy81Ln8idLlmvXfDIXhlXhhFhUIMnf X-Received: by 2002:a17:906:15c7:: with SMTP id l7mr42911225ejd.226.1609173074680; Mon, 28 Dec 2020 08:31:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609173074; cv=none; d=google.com; s=arc-20160816; b=A9c3OGIycjDWNnpvvprUKj+x/I+JSuEZe5MvR8BbhCfNv2CvlDKfJaMRShEYXDDbtX aDf695bq1uwHXgLhMtsxWTYhTaHJ856AjY7aO9iDQeeFmdyDmhcr1nbC+Dugw8fbjYKJ 4LUbT7zOu0GgwSNf6kM8hfuMqNI4fT3ZUuCoobduHzlFy5crlN9CYEu7jvfyOw+ziRuf 8gb794IFQ1ml60aRrHg+mBcV/+FfLgk78j9QN+3qJk1MNLP+61G84nMjbwTqwbIfFRwZ yKbPmL49tOrM6TpqIUmexDMIK/kbg1JX3pyWk6laZ+iMBb/ryrGb7yxF6IzFwzqqyqt2 f2Ig== 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=saP2xYQUKLjCzJiZkWuqwTjYJcNNvwr/hiQWCd0P9oI=; b=SIyhR5PfWtnmTies0aEetSGn2gg9NvcRAAQw1GgseEQlzhcX9039jVffhAkllFu05Q hRHijBQ6us4q0Q95gR1G3TeOfs7CeBhm4Nd7q7LOhw5H9q1aWollUtSKIjjXzhTfVsxX rR+2IpVz9WC5vUJlVjHwhxO/sj9vGkNfYqijvQuhV4X7ui+REoL6wJqgTrI8ylBlPao9 EqtEsjaXpDr0tBuITh+P/wzWn8uj0C4WiA8IJL+J57Jx/4HLYNN1Esvemp+7GZKrrdTz keAJNriVK/WtisU6L3nOJ86KhxisdPo7iPzlf9Px8NZpjyxYJliSKGN4PXBdlKSMAY3/ 3IMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="sYT/86JT"; 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 se15si18869962ejb.270.2020.12.28.08.30.52; Mon, 28 Dec 2020 08:31:14 -0800 (PST) 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="sYT/86JT"; 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 S2633558AbgL1Q2c (ORCPT + 99 others); Mon, 28 Dec 2020 11:28:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:34840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729855AbgL1NHX (ORCPT ); Mon, 28 Dec 2020 08:07:23 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 93B5422A84; Mon, 28 Dec 2020 13:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609160828; bh=cp5yAWSsmGzTB6HvGKaK6i/WsFk3L5RGH48JWKlLltg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sYT/86JTNsyyqClw7kGrUc9V9mgwgGAtiN6Ye9nG3VR7xJHIISCDhffKFVU9112Uf 06y3qQ8PKZf+35q7KMiORP5AwhBlHBCuwCkSkP5pZCH1USTcdHoV+mLFNIEfjVcUp/ uBIvnWXNr2EfYbYhzm0VO1XiG/Wo10zEMaj5GSUk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Mark Brown Subject: [PATCH 4.14 001/242] spi: bcm2835aux: Fix use-after-free on unbind Date: Mon, 28 Dec 2020 13:46:46 +0100 Message-Id: <20201228124904.726154851@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore 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: Lukas Wunner [ Upstream commit e13ee6cc4781edaf8c7321bee19217e3702ed481 ] bcm2835aux_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: b9dd3f6d4172 ("spi: bcm2835aux: Fix controller unregister order") Signed-off-by: Lukas Wunner Cc: # v4.4+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v4.4+: b9dd3f6d4172: spi: bcm2835aux: Fix controller unregister order Cc: # v4.4+ Link: https://lore.kernel.org/r/b290b06357d0c0bdee9cecc539b840a90630f101.1605121038.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-bcm2835aux.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) --- a/drivers/spi/spi-bcm2835aux.c +++ b/drivers/spi/spi-bcm2835aux.c @@ -407,7 +407,7 @@ static int bcm2835aux_spi_probe(struct p unsigned long clk_hz; int err; - master = spi_alloc_master(&pdev->dev, sizeof(*bs)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(*bs)); if (!master) { dev_err(&pdev->dev, "spi_alloc_master() failed\n"); return -ENOMEM; @@ -439,30 +439,26 @@ static int bcm2835aux_spi_probe(struct p /* the main area */ res = platform_get_resource(pdev, IORESOURCE_MEM, 0); bs->regs = devm_ioremap_resource(&pdev->dev, res); - if (IS_ERR(bs->regs)) { - err = PTR_ERR(bs->regs); - goto out_master_put; - } + if (IS_ERR(bs->regs)) + return PTR_ERR(bs->regs); bs->clk = devm_clk_get(&pdev->dev, NULL); if ((!bs->clk) || (IS_ERR(bs->clk))) { - err = PTR_ERR(bs->clk); dev_err(&pdev->dev, "could not get clk: %d\n", err); - goto out_master_put; + return PTR_ERR(bs->clk); } bs->irq = platform_get_irq(pdev, 0); if (bs->irq <= 0) { dev_err(&pdev->dev, "could not get IRQ: %d\n", bs->irq); - err = bs->irq ? bs->irq : -ENODEV; - goto out_master_put; + return bs->irq ? bs->irq : -ENODEV; } /* this also enables the HW block */ err = clk_prepare_enable(bs->clk); if (err) { dev_err(&pdev->dev, "could not prepare clock: %d\n", err); - goto out_master_put; + return err; } /* just checking if the clock returns a sane value */ @@ -495,8 +491,6 @@ static int bcm2835aux_spi_probe(struct p out_clk_disable: clk_disable_unprepare(bs->clk); -out_master_put: - spi_master_put(master); return err; }