The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Sebastian Reichel <sre@kernel.org>,
	Anton Vorontsov <cbou@mail.ru>, Ian Molton <spyro@f2s.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Hans de Goede <johannes.goede@oss.qualcomm.com>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 07/10] power: supply: core: Reject empty ocv-capacity-table properties
Date: Thu,  3 Dec 2026 16:12:28 +0000	[thread overview]
Message-ID: <20261203161316.319090-8-lee@kernel.org> (raw)
In-Reply-To: <20261203161316.319090-1-lee@kernel.org>

In power_supply_get_battery_info(), an empty ocv-capacity-table
property yields proplen == 0, which passes the current length check.
devm_kcalloc() then returns ZERO_SIZE_PTR and stores it in
info->ocv_table[index] with size 0, causing power_supply_ocv2cap_simple()
to dereference ZERO_SIZE_PTR when indexing table[0].

Reject proplen <= 0 with -EINVAL.

Fixes: 570ba047a654 ("power: supply: core: battery-info: fully switch to fwnode")
Closes: https://sashiko.dev/#/bug/linux-4a0a5d5f-629d-4b0d-b4be-07415bcb018e
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/power/supply/power_supply_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 7488c7b94f40..4280f2aff7f7 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -910,7 +910,7 @@ int power_supply_get_battery_info(struct power_supply *psy,
 			goto out_put_node;
 		}
 		proplen = fwnode_property_count_u32(fwnode, propname);
-		if (proplen < 0 || proplen % 2 != 0) {
+		if (proplen <= 0 || proplen % 2 != 0) {
 			dev_err(&psy->dev, "failed to get %s\n", propname);
 			power_supply_put_battery_info(psy, info);
 			err = -EINVAL;
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-03 16:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 16:12 [PATCH 00/10] power: supply: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03 16:12 ` [PATCH 01/10] power: supply: bq27xxx: Check for short i2c_transfer() in bq27xxx_battery_i2c_read() Lee Jones
2026-12-03 16:12 ` [PATCH 02/10] power: supply: generic-adc-battery: Initialise bat_work before registering supply Lee Jones
2026-12-03 16:12 ` [PATCH 03/10] power: supply: bq24190: Manage teardown order with devm to prevent UAF Lee Jones
2026-12-03 16:12 ` [PATCH 04/10] power: supply: gpio-charger: Avoid printing uninitialised chargetype Lee Jones
2026-12-03 16:12 ` [PATCH 05/10] power: supply: ab8500_btemp: Remove unused global device list Lee Jones
2026-12-03 16:12 ` [PATCH 06/10] power: supply: core: Pack supplied_from densely and bound writes Lee Jones
2026-12-03 16:12 ` Lee Jones [this message]
2026-12-03 16:12 ` [PATCH 08/10] power: supply: cpcap-battery: Release battery info in cpcap_battery_update_battery_data() Lee Jones
2026-12-03 16:12 ` [PATCH 09/10] power: supply: qcom_battmgr: Hold battmgr->lock in qcom_battmgr_enable_worker() Lee Jones
2026-12-03 16:12 ` [PATCH 10/10] power: supply: sbs-battery: Always cancel delayed work on suspend Lee Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203161316.319090-8-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=cbou@mail.ru \
    --cc=johannes.goede@oss.qualcomm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=spyro@f2s.com \
    --cc=sre@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox