[PATCH 1/5] iio: proximity: hx9023s: fix out-of-bounds access when copying firmware

Yasin Lee posted 5 patches 1 day, 23 hours ago
[PATCH 1/5] iio: proximity: hx9023s: fix out-of-bounds access when copying firmware
Posted by Yasin Lee 1 day, 23 hours ago
Initialize fw_size before copying firmware data into the flexible
array member to match the __counted_by() annotation. This fixes a
potential out-of-bounds access that could lead to a kernel crash.

Signed-off-by: Yasin Lee <yasin.lee.x@gmail.com>
---
 drivers/iio/proximity/hx9023s.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/iio/proximity/hx9023s.c b/drivers/iio/proximity/hx9023s.c
index 2918dfc0df54..ad839db6b326 100644
--- a/drivers/iio/proximity/hx9023s.c
+++ b/drivers/iio/proximity/hx9023s.c
@@ -1034,9 +1034,8 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data
 	if (!bin)
 		return -ENOMEM;
 
-	memcpy(bin->data, fw->data, fw->size);
-
 	bin->fw_size = fw->size;
+	memcpy(bin->data, fw->data, bin->fw_size);
 	bin->fw_ver = bin->data[FW_VER_OFFSET];
 	bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET);
 

-- 
2.43.0
Re: [PATCH 1/5] iio: proximity: hx9023s: fix out-of-bounds access when copying firmware
Posted by Andy Shevchenko 1 day, 18 hours ago
On Mon, Feb 09, 2026 at 11:37:02AM +0800, Yasin Lee wrote:
> Initialize fw_size before copying firmware data into the flexible
> array member to match the __counted_by() annotation. This fixes a
> potential out-of-bounds access that could lead to a kernel crash.

Fixes tag?

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH 1/5] iio: proximity: hx9023s: fix out-of-bounds access when copying firmware
Posted by Yasin Lee 10 hours ago
On Mon, Feb 9, 2026 at 4:45 PM Andy Shevchenko
<andriy.shevchenko@intel.com> wrote:
>
> On Mon, Feb 09, 2026 at 11:37:02AM +0800, Yasin Lee wrote:
> > Initialize fw_size before copying firmware data into the flexible
> > array member to match the __counted_by() annotation. This fixes a
> > potential out-of-bounds access that could lead to a kernel crash.
>
> Fixes tag?
>

This is a proactive fix for an original implementation issue I found
as maintainer.

> --
> With Best Regards,
> Andy Shevchenko
>
>