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 34B6B1863 for ; Wed, 28 Dec 2022 15:36:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B09E8C433D2; Wed, 28 Dec 2022 15:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672241775; bh=EISk3vffaebLwNiIXktc+CP2gkOQ+8B8Ouwyx1EBlqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0H7bILzj88+0dI2h70T4VAW+RzvSoj0FQH+FwlXoPL26En0jNxIauT/0WMluxa1wq fI4lQiuFCcP6V5zxNllxfDzkw8HC2gbyqHj2Vy6IN5jf8qo/EVrRBUMkXEQJyYn+5j sYV6x9noaL7vTo9oiS9SalASaNPTUEPtSD4PQFo4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, ruanjinjie , Baolin Wang , Sebastian Reichel , Sasha Levin Subject: [PATCH 5.15 521/731] power: supply: fix null pointer dereferencing in power_supply_get_battery_info Date: Wed, 28 Dec 2022 15:40:28 +0100 Message-Id: <20221228144311.648913301@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144256.536395940@linuxfoundation.org> References: <20221228144256.536395940@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: ruanjinjie [ Upstream commit 104bb8a663451404a26331263ce5b96c34504049 ] when kmalloc() fail to allocate memory in kasprintf(), propname will be NULL, strcmp() called by of_get_property() will cause null pointer dereference. So return ENOMEM if kasprintf() return NULL pointer. Fixes: 3afb50d7125b ("power: supply: core: Add some helpers to use the battery OCV capacity table") Signed-off-by: ruanjinjie Reviewed-by: Baolin Wang Signed-off-by: Sebastian Reichel Signed-off-by: Sasha Levin --- drivers/power/supply/power_supply_core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index c3af54421840..3f9c60c5b250 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -696,6 +696,11 @@ int power_supply_get_battery_info(struct power_supply *psy, int i, tab_len, size; propname = kasprintf(GFP_KERNEL, "ocv-capacity-table-%d", index); + if (!propname) { + power_supply_put_battery_info(psy, info); + err = -ENOMEM; + goto out_put_node; + } list = of_get_property(battery_np, propname, &size); if (!list || !size) { dev_err(&psy->dev, "failed to get %s\n", propname); -- 2.35.1