Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9169754pxu; Mon, 28 Dec 2020 08:18:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwThh/XZWbYo7JpaaYb1hqA5+XiZqeIUym47J6cFH5801PMFYtaW/UwBk4LYyE9WnGqabt2 X-Received: by 2002:a50:f61b:: with SMTP id c27mr42602242edn.61.1609172303755; Mon, 28 Dec 2020 08:18:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609172303; cv=none; d=google.com; s=arc-20160816; b=hZukyhC1tX/VSoXs+icGnvXueplU82e+S58yCmS3XSjGI9srUxu8Wec+SMyWpXGKGg Ry7koZpScIfsY6gQjceQvK0IRNHdDcmJG5VK9pu0DxD26xyWbjpfOEjYWrA0y1EO8WWD /RP9zpHNmJB9dAF8ZfwsZLaI40HdhDE2X3sNroAWfG8uguFjMP2X5N8mDKzm0gaoCsJu DrG+PZ0HcSBYQguk7FrUMemtMGdr5QNtrAtM1no+AwJbXhb6ootuzoYkVJQnpBf8Q246 lzEoGh5XJUjN/QoYdEJOuzV8ohLkVNHSzqXeVcFRVunVL+tvbY4txNMKpIXJE8BBuXwT TQjg== 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=DDQZ6ftX366x26l1H4/ZIQ2c5jfu81M0Xl2zJ2xNx/8=; b=BQdmaXV/JdF+lkygv6ihCdH3208NHSG1FJPmsgj3Yux3Yz1sy5/PvKCisLQnv21Tqg 5/hpHusHI32YbSOKlgVamORJXiiSmzWhDk/36FjVvcwVlDSzYV1fW4SrGdI5Z89vBNY9 2SE/Af7Z6HAU8ja1hqJAdZy/43N+uC57820MMVRyUKvawYgFrgyDFf+2RChfIBsPhzYK QJg2M30QT0mKefnzG/gRACS3HVvzrfRvHfvpYpLxAjYnApxfTnzg763G8Rk5OueGdBw0 P6bI+NdpXJSS1w9f7/0taXWydWp9hFyzW44LckuvPhz2DMQrV1xuPp1NP3ZIU47LIjq/ alTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g3OkQenC; 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 p8si20303977edm.143.2020.12.28.08.17.59; Mon, 28 Dec 2020 08:18:23 -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=g3OkQenC; 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 S2387486AbgL1NSV (ORCPT + 99 others); Mon, 28 Dec 2020 08:18:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:46752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731718AbgL1NSS (ORCPT ); Mon, 28 Dec 2020 08:18:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 082FA206ED; Mon, 28 Dec 2020 13:17:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161457; bh=U8Fj+ddiucHY5sTsAIB4Yu2qi5hTr4vuPIsYSreRKfk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3OkQenCtAWopf41wvMq8CGTAc7V12QXP7/kxcSRybFuoys2h6zPyuj5tHvPZ2J68 2ajfqoMEawfLzHM8CIx11e1ieEqxPbjBcJN+SR2ljZ3qGMuEVLMJAt5Qn7CQd0u0g3 44WfyfM6gYyq/YZPZXVIMGNjyrPwjUZjOQ2pokhI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Axel Lin , Mark Brown Subject: [PATCH 4.14 220/242] spi: spi-sh: Fix use-after-free on unbind Date: Mon, 28 Dec 2020 13:50:25 +0100 Message-Id: <20201228124915.504236405@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 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 commit e77df3eca12be4b17f13cf9f215cff248c57d98f upstream. spi_sh_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: 680c1305e259 ("spi/spi_sh: use spi_unregister_master instead of spi_master_put in remove path") Signed-off-by: Lukas Wunner Cc: # v3.0+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v3.0+ Cc: Axel Lin Link: https://lore.kernel.org/r/6d97628b536baf01d5e3e39db61108f84d44c8b2.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-sh.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) --- a/drivers/spi/spi-sh.c +++ b/drivers/spi/spi-sh.c @@ -450,7 +450,7 @@ static int spi_sh_probe(struct platform_ return irq; } - master = spi_alloc_master(&pdev->dev, sizeof(struct spi_sh_data)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(struct spi_sh_data)); if (master == NULL) { dev_err(&pdev->dev, "spi_alloc_master error.\n"); return -ENOMEM; @@ -468,16 +468,14 @@ static int spi_sh_probe(struct platform_ break; default: dev_err(&pdev->dev, "No support width\n"); - ret = -ENODEV; - goto error1; + return -ENODEV; } ss->irq = irq; ss->master = master; ss->addr = devm_ioremap(&pdev->dev, res->start, resource_size(res)); if (ss->addr == NULL) { dev_err(&pdev->dev, "ioremap error.\n"); - ret = -ENOMEM; - goto error1; + return -ENOMEM; } INIT_LIST_HEAD(&ss->queue); spin_lock_init(&ss->lock); @@ -487,7 +485,7 @@ static int spi_sh_probe(struct platform_ ret = request_irq(irq, spi_sh_irq, 0, "spi_sh", ss); if (ret < 0) { dev_err(&pdev->dev, "request_irq error\n"); - goto error1; + return ret; } master->num_chipselect = 2; @@ -506,9 +504,6 @@ static int spi_sh_probe(struct platform_ error3: free_irq(irq, ss); - error1: - spi_master_put(master); - return ret; }