From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 979D11EB5E1; Wed, 25 Feb 2026 01:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771983317; cv=none; b=uQUVMtc+5ExT9zrPDR63LpDkBQKvBFr6rmpe6FoRmgC45Z9azh/dcNgoWgA1lCxzNdwgZswvZMN6MllShpML5gs2hgmcFdTOLATSqvJyEAbpBKZKRArq+KF/xeoaq/H2+UV6ehozMeDNy4Ln28NrMNB5paDAhHRoNH+bnwrwKNs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771983317; c=relaxed/simple; bh=f7TnaVGrNOdXsDKjh9yU19RWfoW5KelcBecrAZs1XSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZYeIpqLM0ExiiXNbBhQDypgJKOazy3WnkW0uNSmaPnscBfm9woFcf6TE3YqYr6/WxI6lrXY8HW6OPgBgRxmwjqZjMauVzNBrDIGzR1OnvV/8YIaVjpL0xKkofPHyonvUvvZ1Z6FWmnbvhaY+2xoAxUc1xADPrNSl5rKJaGqw8Yw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HnrSaOLM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HnrSaOLM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53BEEC116D0; Wed, 25 Feb 2026 01:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1771983317; bh=f7TnaVGrNOdXsDKjh9yU19RWfoW5KelcBecrAZs1XSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HnrSaOLM4C/41vM+lJSDY2k9yJvRvlZmAjM6opAHvtPugNroJrusPllW8aeOGugIk derfAWIX6ysH5KB78xbWUSmw1IL0kusPPRpDc3MsSpPd3cz30oIhZTWwjYI4mli8sj ylRdVCCJPmuL1V8en2aSFliwEVY74W+nvNUoRHzg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Waqar Hameed , Sebastian Reichel , Sasha Levin Subject: [PATCH 6.19 451/781] power: supply: cpcap-battery: Fix use-after-free in power_supply_changed() Date: Tue, 24 Feb 2026 17:19:20 -0800 Message-ID: <20260225012410.775053903@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260225012359.695468795@linuxfoundation.org> References: <20260225012359.695468795@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Waqar Hameed [ Upstream commit 642f33e34b969eedec334738fd5df95d2dc42742 ] Using the `devm_` variant for requesting IRQ _before_ the `devm_` variant for allocating/registering the `power_supply` handle, means that the `power_supply` handle will be deallocated/unregistered _before_ the interrupt handler (since `devm_` naturally deallocates in reverse allocation order). This means that during removal, there is a race condition where an interrupt can fire just _after_ the `power_supply` handle has been freed, *but* just _before_ the corresponding unregistration of the IRQ handler has run. This will lead to the IRQ handler calling `power_supply_changed()` with a freed `power_supply` handle. Which usually crashes the system or otherwise silently corrupts the memory... Note that there is a similar situation which can also happen during `probe()`; the possibility of an interrupt firing _before_ registering the `power_supply` handle. This would then lead to the nasty situation of using the `power_supply` handle *uninitialized* in `power_supply_changed()`. Fix this racy use-after-free by making sure the IRQ is requested _after_ the registration of the `power_supply` handle. Fixes: 874b2adbed12 ("power: supply: cpcap-battery: Add a battery driver") Signed-off-by: Waqar Hameed Link: https://patch.msgid.link/81db58d610c9a51a68184f856cd431a934cccee2.1766268280.git.waqar.hameed@axis.com Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/cpcap-battery.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/power/supply/cpcap-battery.c b/drivers/power/supply/cpcap-battery.c index 8106d1edcbc26..507fdc1c866d5 100644 --- a/drivers/power/supply/cpcap-battery.c +++ b/drivers/power/supply/cpcap-battery.c @@ -1122,10 +1122,6 @@ static int cpcap_battery_probe(struct platform_device *pdev) platform_set_drvdata(pdev, ddata); - error = cpcap_battery_init_interrupts(pdev, ddata); - if (error) - return error; - error = cpcap_battery_init_iio(ddata); if (error) return error; @@ -1142,6 +1138,10 @@ static int cpcap_battery_probe(struct platform_device *pdev) return error; } + error = cpcap_battery_init_interrupts(pdev, ddata); + if (error) + return error; + atomic_set(&ddata->active, 1); error = cpcap_battery_calibrate(ddata); -- 2.51.0