]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mfd: syscon: Add check for invalid resource size
authorEder Zulian <ezulian@redhat.com>
Wed, 12 Feb 2025 18:45:24 +0000 (19:45 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:12:42 +0000 (11:12 +0200)
[ Upstream commit ba09916efb29f80e438a54e634970209ce12750f ]

Add a consistency check to avoid assigning an invalid value to
max_register due to a possible DT misconfiguration.

Suggested-by: Mark Langsdorf <mlangsdo@redhat.com>
Signed-off-by: Eder Zulian <ezulian@redhat.com>
Link: https://lore.kernel.org/r/20250212184524.585882-1-ezulian@redhat.com
Signed-off-by: Lee Jones <lee@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/mfd/syscon.c

index aa4a9940b569a33c22846008e372f0444cffd8e7..ae71a2710bed8bb6522d8be0624c3941c12715f1 100644 (file)
@@ -47,6 +47,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
        struct regmap_config syscon_config = syscon_regmap_config;
        struct resource res;
        struct reset_control *reset;
+       resource_size_t res_size;
 
        WARN_ON(!mutex_is_locked(&syscon_list_lock));
 
@@ -96,6 +97,12 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
                }
        }
 
+       res_size = resource_size(&res);
+       if (res_size < reg_io_width) {
+               ret = -EFAULT;
+               goto err_regmap;
+       }
+
        syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%pa", np, &res.start);
        if (!syscon_config.name) {
                ret = -ENOMEM;
@@ -103,7 +110,7 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
        }
        syscon_config.reg_stride = reg_io_width;
        syscon_config.val_bits = reg_io_width * 8;
-       syscon_config.max_register = resource_size(&res) - reg_io_width;
+       syscon_config.max_register = res_size - reg_io_width;
        if (!syscon_config.max_register)
                syscon_config.max_register_is_0 = true;