Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4406794pxa; Mon, 10 Aug 2020 08:22:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcBLTkcRzBwZFKRTWxzFuiQtBHiczUQSWviI8vJQ6oAV2yC5JGFhOjbWk73A1dLj/PAzw5 X-Received: by 2002:a17:906:c002:: with SMTP id e2mr23099678ejz.244.1597072970931; Mon, 10 Aug 2020 08:22:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597072970; cv=none; d=google.com; s=arc-20160816; b=HQwMGFH19MPRvxwl372IRyrrYZ56KlIMkXAKMXygYb8i0gov+ut6oGl3HlaL2ZfZa0 jcFNGfnyF32Acvc2CrCKm56DqKJYrHrithKgH2gAjbqxvzR2SRS/srEXdoHefP2h7KWc 6wHBAQ0lMd1JP3gNX88qd1eqd7m69RBpaZKzcQmW0mEuCG4OZvPlqAgOqFA75gt8ubn7 iTh/0pf4gpg7kvHg2weQLoo1ADU+H2SehFHRlmhAtBRCNekeGwCyE7GmR0OqKfN9oddS 3ZxDdmZATqpSkYoQtrl6zxw2/iuO6vNoAyhcRojyG9jbkHf/9umhc9z+LAZIauFOtv6N WnWg== 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=21PIt1xKRADp92fGd4R43ctdoVWH7SwZJ4Wem6ZyzLI=; b=woOIct3EqGwmhEfvDPitjd7YSHkFg5vSDtQW/QDEwug98gyKgLEYikGrbM/dCpkYq+ RcUR/kToiQz8tD/l6KhBj8atefVk3fdP5Xw6EufSGPxqjoO+33Qf7c8858nfAiDCTMeE cRayMLlD+q6anBTJh17JORMzUboYm492tRRmu5Pv8eeFPsXFqr3zaS06EZd/Q0ysbt8j rRMR03rkhlU0YPg1Hb9CiDV1KF3nxcmNDI/0G6OzxOHnJUGnrHWsE/XC4cVncbPA4n3y mhopfHMUQ2obuZuWqoj+GILnFwTN0FjWX9gxw5i+SOHJqJtlIT0FCKMEvurWV42gYnmG vdOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QWDFcW8y; 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 qk16si10671928ejb.532.2020.08.10.08.22.28; Mon, 10 Aug 2020 08:22:50 -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=QWDFcW8y; 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 S1728068AbgHJPVN (ORCPT + 99 others); Mon, 10 Aug 2020 11:21:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:51858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728127AbgHJPVE (ORCPT ); Mon, 10 Aug 2020 11:21:04 -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 C93522065D; Mon, 10 Aug 2020 15:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597072864; bh=wkqj1qoeprJlvfQN9/RlfNpdpvKWXthNynLbTT69KSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QWDFcW8ylnkGtc9+FykMh4HI5I844QhFvC+NpIOpkjOfVywG5OVMDLOVIFWQwpBSd UPfxpR6emS3TMgQmL9PgoJj3k0SjVO9CKgYCuL+VGerVQ22syNFTjVsCm7UapHMBac tTYKSt4k69fEhJN0vNsCgTTC01ajoIxkCcSvaqZM= 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 5.8 25/38] leds: wm831x-status: fix use-after-free on unbind Date: Mon, 10 Aug 2020 17:19:15 +0200 Message-Id: <20200810151805.135568635@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 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 @@ -269,12 +269,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; } @@ -283,6 +294,7 @@ static struct platform_driver wm831x_sta .name = "wm831x-status", }, .probe = wm831x_status_probe, + .remove = wm831x_status_remove, }; module_platform_driver(wm831x_status_driver);