]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
software node: Correct a OOB check in software_node_get_reference_args()
authorZijun Hu <quic_zijuhu@quicinc.com>
Mon, 14 Apr 2025 11:36:52 +0000 (19:36 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 27 Jun 2025 10:07:35 +0000 (11:07 +0100)
[ Upstream commit 31e4e12e0e9609850cefd4b2e1adf782f56337d6 ]

software_node_get_reference_args() wants to get @index-th element, so
the property value requires at least '(index + 1) * sizeof(*ref)' bytes
but that can not be guaranteed by current OOB check, and may cause OOB
for malformed property.

Fix by using as OOB check '((index + 1) * sizeof(*ref) > prop->length)'.

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
Link: https://lore.kernel.org/r/20250414-fix_swnode-v2-1-9c9e6ae11eab@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/base/swnode.c

index 44153caa893ad8aa8269b75828b49cf84c01f3ad..fdea6b93eb30ebcd9d5b02502ed8a7f6de8d783e 100644 (file)
@@ -518,7 +518,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
        if (prop->is_inline)
                return -EINVAL;
 
-       if (index * sizeof(*ref) >= prop->length)
+       if ((index + 1) * sizeof(*ref) > prop->length)
                return -ENOENT;
 
        ref_array = prop->pointer;