Skip to contentSkip to conversation

iio: proximity: Fix use-after-free in hx9023s_send_cfg()

PATCH In review Dheeraj Reddy Jonnalagadda 3 participants 4 messages Jan 7, 2025 – Jan 18, 2025 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: proximity: Fix use-after-free in hx9023s_send_cfg()

Reorder the assignment of fw_size to happen before release_firmware() to avoid accessing the firmware structure after it's been freed.

Fixes e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")
---
 drivers/iio/proximity/hx9023s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/proximity/hx9023s.c +2 -1
index e092a935dbac..5aa8e5a22f32 100644
@@ -1036,12 +1036,13 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data
 		return -ENOMEM;
 
 	memcpy(bin->data, fw->data, fw->size);
-	release_firmware(fw);
 
 	bin->fw_size = fw->size;
 	bin->fw_ver = bin->data[FW_VER_OFFSET];
 	bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET);
 
+	release_firmware(fw);
+
 	return hx9023s_bin_load(data, bin);
 }
 
Signature · 1 line
2.34.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dheeraj Reddy Jonnalagadda

Reorder the assignment of fw_size to happen before release_firmware() to avoid accessing the firmware structure after it's been freed.

Fixes e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")

---

maintainer
#2 lore raw
In reply to Dheeraj Reddy Jonnalagadda
Quoted 6 lines · On Tue, 7 Jan 2025 18:05:10 +0530 Dheeraj Reddy Jonnalagadda…

Reorder the assignment of fw_size to happen before release_firmware() to avoid accessing the firmware structure after it's been freed.

Fixes e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")

Gah. I didn't see this until after I'd sent the pull request. Never mind, we have plenty of time to get this in during the rc1 cycles.

I'll queue it up after rc1.

Thanks,

Jonathan

Quoted 23 lines
---
 drivers/iio/proximity/hx9023s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/proximity/hx9023s.c +2 -1
index e092a935dbac..5aa8e5a22f32 100644
@@ -1036,12 +1036,13 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data
 		return -ENOMEM;
 
 	memcpy(bin->data, fw->data, fw->size);
-	release_firmware(fw);
 
 	bin->fw_size = fw->size;
 	bin->fw_ver = bin->data[FW_VER_OFFSET];
 	bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET);
 
+	release_firmware(fw);
+
 	return hx9023s_bin_load(data, bin);
 }
 
maintainer
#3 lore raw
Quoted 9 lines · On Sun, 12 Jan 2025 11:53:14 +0000 Jonathan Cameron <[email protected]> wrote:
Quoted 6 lines · On Tue, 7 Jan 2025 18:05:10 +0530 Dheeraj Reddy Jonnalagadda…

Reorder the assignment of fw_size to happen before release_firmware() to avoid accessing the firmware structure after it's been freed.

Fixes e9ed97be4fcc ("iio: proximity: hx9023s: Added firmware file parsing functionality")
Quoted 8 lines

Gah. I didn't see this until after I'd sent the pull request. Never mind, we have plenty of time to get this in during the rc1 cycles.

I'll queue it up after rc1.

Thanks,

Jonathan

I've now queued it but on a fixes tree I can't push out just yet because it will make a mess of linux-next (it is ahead of some trees that come later in the merge order for next).

Anyhow, that will all resolve during the merge window and I'll rebase on rc1.

Thanks,

Jonathan

Quoted 26 lines
Quoted 24 lines
---
 drivers/iio/proximity/hx9023s.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/proximity/hx9023s.c +2 -1
index e092a935dbac..5aa8e5a22f32 100644
@@ -1036,12 +1036,13 @@ static int hx9023s_send_cfg(const struct firmware *fw, struct hx9023s_data *data
 		return -ENOMEM;
 
 	memcpy(bin->data, fw->data, fw->size);
-	release_firmware(fw);
 
 	bin->fw_size = fw->size;
 	bin->fw_ver = bin->data[FW_VER_OFFSET];
 	bin->reg_count = get_unaligned_le16(bin->data + FW_REG_CNT_OFFSET);
 
+	release_firmware(fw);
+
 	return hx9023s_bin_load(data, bin);
 }