Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4417497pxa; Mon, 10 Aug 2020 08:36:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0U3cV91no1u493vnqfeqrBXo9CcX6DBrJueXSK+stfl0/ZA7EhWsYhAcXB8klhiyus0z1 X-Received: by 2002:a17:906:b2d0:: with SMTP id cf16mr21767676ejb.476.1597073796444; Mon, 10 Aug 2020 08:36:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597073796; cv=none; d=google.com; s=arc-20160816; b=Qsgrn5eu9LhN6GnmnD+t9Q6xuD4rrkj8ajmQUJlEEmkO8YhMOsAKRjeSUlgIGRjLMo hB4vlVTw0Ecepq2xQsWLNNfv0VJB5O/405yKKU5N4kQ4knJTFAq2R6gsjyYPwt0OnzAX geDb3gSSt72N6xeF1gom3A1FOqk3YwjCUnll8GCvE/jojXikaIWnUMi28l+4L/b9s7ru wBmvTBvFI1l+ErUSb3EzBnBUwzSZlImrujaM/c8mSZb2Yn7cAkrnBqEhSqAHFZmuCYCo f/gztpPn47e0UT9qZaR+l31BbNLDZuTuaLjyA+Sa1frsxj3Zqj5dGeceAFKVhTJ2vPfN Q30Q== 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=BSkxrAj/BrPLH8uLaG/3UP/WNQ0EkGYUc5nnbw5uCNE=; b=HUI2xop8/Dc4/2kI0uKq+IoNihVh/qK6w9Zx3WNOGx3cc7aoxJdCyS+VhSl28TXC5X ncJ8DJ4vYN97/i9BER2S5qhNzCsexHQPjd016UQXPu/AKX80pWzueJ8yK8RiVJAZoGrq FVTlqoqlbcV8PaM5ZzriE5wg7rGTSrdx/zzbsoK8COU2Nl4dHWxtHp1dtOVQoPadbgYF IkhUruTeMQCgzFnZwpDDhTub4nnpHtbHyjQFJbAr85+TFxCCnCSCWaWglnvZ+jEIZuVa mofQ5yhhC+QejdnTRR7Xx+cqbTEE+B3YQRDyz16aBV6R4P0RhnAnHeTrnjHqikoib+hG ybzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R4cVIcEn; 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 dd10si7978862edb.66.2020.08.10.08.36.13; Mon, 10 Aug 2020 08:36:36 -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=R4cVIcEn; 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 S1729007AbgHJPdt (ORCPT + 99 others); Mon, 10 Aug 2020 11:33:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:36040 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728968AbgHJP3d (ORCPT ); Mon, 10 Aug 2020 11:29:33 -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 916B822EBD; Mon, 10 Aug 2020 15:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597073373; bh=E9e+b6nOC+nrI0dB8hflg2VpIRpGqLRK2yj0Sw9Wt8g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R4cVIcEn5G5DdqIVK726v19WEosS/QJKCdq3b6P23K8hWuCReFXt3ccAqJRkj96ly t+oInERZIvxAjz+10jULNSXUiVUMpcQP/rGtd8UFaDu1LXWMl+xDvirUrk0hhO3L3t yOzAp6748k+sy0tprto8WB9+42UF4HdN8+doO/Ko= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Amitoj Kaur Chawla , Johan Hovold , Pavel Machek Subject: [PATCH 4.19 15/48] leds: wm831x-status: fix use-after-free on unbind Date: Mon, 10 Aug 2020 17:21:37 +0200 Message-Id: <20200810151804.963646027@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151804.199494191@linuxfoundation.org> References: <20200810151804.199494191@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 47a459ecc800a17109d0c496a4e21e478806ee40 upstream. Several MFD child drivers register their class devices directly under the parent device. This means you cannot blindly do devres conversions 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: 8d3b6a4001ce ("leds: wm831x-status: Use devm_led_classdev_register") Cc: stable # 4.6 Cc: Amitoj Kaur Chawla Signed-off-by: Johan Hovold Signed-off-by: Pavel Machek Signed-off-by: Greg Kroah-Hartman --- drivers/leds/leds-wm831x-status.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/drivers/leds/leds-wm831x-status.c +++ b/drivers/leds/leds-wm831x-status.c @@ -273,12 +273,23 @@ static int wm831x_status_probe(struct pl drvdata->cdev.blink_set = wm831x_status_blink_set; drvdata->cdev.groups = wm831x_status_groups; - ret = devm_led_classdev_register(wm831x->dev, &drvdata->cdev); + ret = led_classdev_register(wm831x->dev, &drvdata->cdev); if (ret < 0) { dev_err(&pdev->dev, "Failed to register LED: %d\n", ret); return ret; } + platform_set_drvdata(pdev, drvdata); + + return 0; +} + +static int wm831x_status_remove(struct platform_device *pdev) +{ + struct wm831x_status *drvdata = platform_get_drvdata(pdev); + + led_classdev_unregister(&drvdata->cdev); + return 0; } @@ -287,6 +298,7 @@ static struct platform_driver wm831x_sta .name = "wm831x-status", }, .probe = wm831x_status_probe, + .remove = wm831x_status_remove, }; module_platform_driver(wm831x_status_driver);