Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4408303pxa; Mon, 10 Aug 2020 08:24:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS+XL+injt71xunniLo4VhQPtrvPNIbQO04pB2dqxkjVAPiuB7ohDzjakfk86TC1eMB91/ X-Received: by 2002:a05:6402:308e:: with SMTP id de14mr21193114edb.344.1597073091385; Mon, 10 Aug 2020 08:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073091; cv=none; d=google.com; s=arc-20160816; b=YrsiPY4u7jUTbMZ980sYNKmpPi7HkRTiys+EULxohTyI/MlLpoOfLvPzBdx3LGkoUZ dlJAm8WItqkVof2gJJySaDBowkXLB+r0K4LvNMsyDaQCzdqRn+fwXE4GoqX5hJ2dMkSf 9M8S4qhtY6LbXjg1PfDJc3uD485wjXTeUA0hsmBHFTjrPp0yQKWcKvi02d51mT9FpaJ2 h9QEvA2rHXeuEdUmziRzcawit+89tY0sl2z4gfeNcmz+2fC8oNozIWxiy5HOEkO0ZtIx Mb6qIk1KtrZnqHPiK5e92EDkS2sLsPBxQnvCpKor1ujmVYmQaUI6XbB8AT1tSsip5/Eh ZbvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TBFfGn5a1GaK6CCr5Uu9uOO2feqDUJYHPJKXMDloNzQ=; b=oYhYJ9hwerGI1Yi0CRg691ouGJJKxrXZ6v7sYNrfFWMysBvESz+N2fNLWhXBELPi93 MfSMelYkTmYiE9vnAUdij/bnsGIdx6K8cxVkIx1WX61WywVDSPq/HOU88cr06JkCX6GG R09GOPCdca5vr8rPAN7klv81SZho8C08dC3BQOvwCF2krqdRinzEqp/vFnCqbPlZmTEX AzITnxSLeSfvm7/CE2NDxkkGtypv43NQwq0ZE54JULulY0vjihFLRFxZO0R42y9qaP/l H4xdmH0gQCMOt5r4M4UCP3tmHB3mig+xDXmW0f3cfoHqWsB/5EeaoUbE8tcw+wqZ7gQX hs3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o5srTFp9; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r14si11180215ejy.577.2020.08.10.08.24.28; Mon, 10 Aug 2020 08:24:51 -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=@kernel.org header.s=default header.b=o5srTFp9; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728164AbgHJPVO (ORCPT + 99 others); Mon, 10 Aug 2020 11:21:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:51922 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727981AbgHJPVH (ORCPT ); Mon, 10 Aug 2020 11:21:07 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C89BD20768; Mon, 10 Aug 2020 15:21:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597072867; bh=317EpMwDFiRhWwkPj/R6GWOmMwQrCN5rBjTVaLkskPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5srTFp9lsv3Nt7IZ/DQ/4nRba2NrKGT6WgoP2zJ3yhlaWoRgwtdnS85IfkQXYpat gpAMlZl8FBd99w8FhZtbpwCqI1jOVPkv0ATtZ6MdPuL2h5z5XXbjl3HAKOM/ZomMCn OBJ9WnwJj+ynyMHbOExqTEFWyn+M96R66+fn61pA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Murphy , Johan Hovold , Pavel Machek Subject: [PATCH 5.8 26/38] leds: lm36274: fix use-after-free on unbind Date: Mon, 10 Aug 2020 17:19:16 +0200 Message-Id: <20200810151805.185190710@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151803.920113428@linuxfoundation.org> References: <20200810151803.920113428@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Johan Hovold commit a0972fff09479dd09b731360a3a0b09e4fb4d415 upstream. Several MFD child drivers register their class devices directly under the parent device. This means you cannot use devres so that deregistration ends up being tied to the parent device, something which leads to use-after-free on driver unbind when the class device is released while still being registered. Fixes: 11e1bbc116a7 ("leds: lm36274: Introduce the TI LM36274 LED driver") Cc: stable # 5.3 Cc: Dan Murphy Signed-off-by: Johan Hovold Signed-off-by: Pavel Machek Signed-off-by: Greg Kroah-Hartman --- drivers/leds/leds-lm36274.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/drivers/leds/leds-lm36274.c +++ b/drivers/leds/leds-lm36274.c @@ -133,7 +133,7 @@ static int lm36274_probe(struct platform lm36274_data->pdev = pdev; lm36274_data->dev = lmu->dev; lm36274_data->regmap = lmu->regmap; - dev_set_drvdata(&pdev->dev, lm36274_data); + platform_set_drvdata(pdev, lm36274_data); ret = lm36274_parse_dt(lm36274_data); if (ret) { @@ -147,8 +147,16 @@ static int lm36274_probe(struct platform return ret; } - return devm_led_classdev_register(lm36274_data->dev, - &lm36274_data->led_dev); + return led_classdev_register(lm36274_data->dev, &lm36274_data->led_dev); +} + +static int lm36274_remove(struct platform_device *pdev) +{ + struct lm36274 *lm36274_data = platform_get_drvdata(pdev); + + led_classdev_unregister(&lm36274_data->led_dev); + + return 0; } static const struct of_device_id of_lm36274_leds_match[] = { @@ -159,6 +167,7 @@ MODULE_DEVICE_TABLE(of, of_lm36274_leds_ static struct platform_driver lm36274_driver = { .probe = lm36274_probe, + .remove = lm36274_remove, .driver = { .name = "lm36274-leds", },