Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9417722pxu; Mon, 28 Dec 2020 15:50:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJzwA6XJjLioB8/oVal1MHkP24Jh64WkhlO1PS+UV//Ooq02wTLYVpbgscJ2tqbnpbIeaUCc X-Received: by 2002:a17:906:3a55:: with SMTP id a21mr44017928ejf.516.1609199419523; Mon, 28 Dec 2020 15:50:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609199419; cv=none; d=google.com; s=arc-20160816; b=pvRAgcb/bARd8QL/UrqrD+1SAZ3j/ByP9vS3hPpC3n9NCYAwjdokfNY2NeJ91cK+bH 67d2bxC6np0gMvdKuPFMpTCTCJmMtgxGOP1U8mTCgsr6qgAeUCB3AB8PwcoxtIUSoI8/ FC/S7OEJizNDJL1vsCJ8lL/oiaikM0a3bMOKPV0RDPtNLDw34VsAWwhW7sFZNmk8L7Ug QIHyTORVQ/BgR4IHMMSMY+9uS0fuO8dQVhzdGrfM+EzSKUN4QEFoX6gmZvgSdcqLeZJK zGslT+VkhstklUNBuib3lm+k5iminYPHCNL7xiD/fIoHeiUxGFP2iXhECCJcaQ26qutn oiBg== 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=9B0L+Yk6V6JQ89xPhkh+Dc6TMW0DPG09DixtdUGjCzw=; b=nTOX04Vu3cJIbmPxelfJhMOGunimQVde517aKYtIuMesS93bPK+I1/7FMzbH0eg5OJ EXUqwumB5SPIFIeUMxfNzr/KDIOCjcBEJsHxGHt3wz4gKrIU93kTKm6yplFlWOZYuA0C Axh9vxFZvmNzbBW7HLGR8cFoAZ7dtAxEDh8N8TD0ijppme6fjh00CF/VePrW3I2Frkvj N080YQ+3S0+IoR6E+URP4L4OpNepFE2yIRB3RiRPwWE1DbnVAenU5oZIwpl4oHSSTHdc YZZ6Glvz5OPa6Y8hL4lm6Ewn+19Yfcs5igHU3YjmNv0axIG6ThdTMtC+ncXERUWJbLXV vw9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KBNRQEXo; 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 bt28si20964925edb.269.2020.12.28.15.49.57; Mon, 28 Dec 2020 15:50:19 -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=KBNRQEXo; 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 S2505694AbgL1OjM (ORCPT + 99 others); Mon, 28 Dec 2020 09:39:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:37682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503488AbgL1O35 (ORCPT ); Mon, 28 Dec 2020 09:29:57 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8326B221F0; Mon, 28 Dec 2020 14:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165782; bh=2Bklf9DCJXUl3thJCI/qgi4JWKZUxw/j6HvbSQKMAW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBNRQEXoINT3MAJ9Tu6pt8E6aYCV26WykJ/fIWjFVLWT2mRQRSMBrDnkdnaHeXZR7 +iINHngTD5RVviaRQ6vhARw90vaWr7cgqHI97vBoBrQjyNcN0LO7xQ+3uC85FZ8dS0 FvYKoD/4QpfyMkD0DpBUanpoAQQyzkrkbCwbyTDo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lukas Wunner , Sergei Shtylyov , Mark Brown Subject: [PATCH 5.10 653/717] spi: rpc-if: Fix use-after-free on unbind Date: Mon, 28 Dec 2020 13:50:51 +0100 Message-Id: <20201228125052.229988513@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@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 393f981ca5f797b58b882d42b7621fb6e43c7f5b upstream. rpcif_spi_remove() accesses the driver's private data after calling spi_unregister_controller() even though that function releases the last reference on the spi_controller 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: eb8d6d464a27 ("spi: add Renesas RPC-IF driver") Signed-off-by: Lukas Wunner Cc: # v5.9+: 5e844cc37a5c: spi: Introduce device-managed SPI controller allocation Cc: # v5.9+ Cc: Sergei Shtylyov Link: https://lore.kernel.org/r/c5da472c28021da2f6517441685cef033d40b140.1607286887.git.lukas@wunner.de Signed-off-by: Mark Brown Signed-off-by: Greg Kroah-Hartman --- drivers/spi/spi-rpc-if.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) --- a/drivers/spi/spi-rpc-if.c +++ b/drivers/spi/spi-rpc-if.c @@ -134,7 +134,7 @@ static int rpcif_spi_probe(struct platfo struct rpcif *rpc; int error; - ctlr = spi_alloc_master(&pdev->dev, sizeof(*rpc)); + ctlr = devm_spi_alloc_master(&pdev->dev, sizeof(*rpc)); if (!ctlr) return -ENOMEM; @@ -159,13 +159,8 @@ static int rpcif_spi_probe(struct platfo error = spi_register_controller(ctlr); if (error) { dev_err(&pdev->dev, "spi_register_controller failed\n"); - goto err_put_ctlr; + rpcif_disable_rpm(rpc); } - return 0; - -err_put_ctlr: - rpcif_disable_rpm(rpc); - spi_controller_put(ctlr); return error; }