Skip to contentSkip to conversation

i2c: amd-asf: Validate firmware-reported length

PATCH New Paritosh Potukuchi 3 participants 5 messages Jun 12 – Jun 17

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: amd-asf: Validate firmware-reported length

The firmware may sometimes return a length greater than the allocated buffer size, which can lead to out-of-bounds access and a kernel panic.

Currently, the driver does not validate the length read from firmware.

Add a check to ensure the firmware-reported length stays within the bounds of the data buffer.

---
 drivers/i2c/busses/i2c-amd-asf-plat.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-amd-asf-plat.c +3 -0
index ca45f0f23321..3d355e880d54 100644
@@ -90,6 +90,9 @@ static void amd_asf_process_target(struct work_struct *work)
 		outb_p(reg, ASFDATABNKSEL);
 		cmd = inb_p(ASFINDEX);
 		len = inb_p(ASFDATARWPTR);
+	if (len > ASF_BLOCK_MAX_BYTES)
+		return;
+
 		for (idx = 0; idx < len; idx++)
 			data[idx] = inb_p(ASFINDEX);
 
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/1 i2c: amd-asf: Validate firmware-reported length

The firmware may sometimes return a length greater than the allocated buffer size, which can lead to out-of-bounds access and a kernel panic.

Currently, the driver does not validate the length read from firmware.

Add a check to ensure the firmware-reported length stays within the bounds of the data buffer.

Fix indentation issues reported by checkpatch.

---
 drivers/i2c/busses/i2c-amd-asf-plat.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-amd-asf-plat.c +3 -0
index ca45f0f23321..e1699da838c2 100644
@@ -90,6 +90,9 @@ static void amd_asf_process_target(struct work_struct *work)
 		outb_p(reg, ASFDATABNKSEL);
 		cmd = inb_p(ASFINDEX);
 		len = inb_p(ASFDATARWPTR);
+		if (len > ASF_BLOCK_MAX_BYTES)
+			return;
+
 		for (idx = 0; idx < len; idx++)
 			data[idx] = inb_p(ASFINDEX);
 
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Hi Paritosh,

Quoted 3 lines · Paritosh Potukuchi

The firmware may sometimes return a length greater than the allocated buffer size, which can lead to out-of-bounds access and a kernel panic.

How often does it happen? Should it be considered a fix?

Shyam, any comments on this?

Quoted 7 lines

Currently, the driver does not validate the length read from firmware.

Add a check to ensure the firmware-reported length stays within the bounds of the data buffer.

Fix indentation issues reported by checkpatch.

I'm going to remove this comment here as I'm going to take only this patch and it's a meaningless information to leave in the log history.

Quoted 10 lines
---
 drivers/i2c/busses/i2c-amd-asf-plat.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-amd-asf-plat.c +0 -0
index ca45f0f23321..e1699da838c2 100644

drivers/i2c/busses/i2c-amd-asf-plat.c static void amd_asf_process_target(struct work_struct *work) · line 95

Quoted 6 lines
drivers/i2c/busses/i2c-amd-asf-plat.c +3 -0
@@ -90,6 +90,9 @@ static void amd_asf_process_target(struct work_struct *work)
 		outb_p(reg, ASFDATABNKSEL);
 		cmd = inb_p(ASFINDEX);
 		len = inb_p(ASFDATARWPTR);
+		if (len > ASF_BLOCK_MAX_BYTES)
+			return;
+

Your patch makes sense to me. I'd just like a blank line before the 'if' statement. No need to resend it; I'll add it while applying the patch unless you disagree.

Besides that, the patch is not properly formatted. It is missing:

1. Versioning: this should have been "[PATCH v2] ...".

2. Changelog: for a single patch, it should be added below the '---' line, after your Signed-off-by. You added "Fix indentation issues..." as a sort of changelog, but it is in the wrong place and it is not clear that it is a changelog.

3. Please don't send a new version as a reply to the previous one. From a maintainer's point of view, that makes it more difficult to track and apply.

That said, I believe this is your first patch, and that's perfectly fine. Welcome to the community :-)

Unless there are further comments, I'll apply your patch to i2c/i2c-for-7.2.

Thanks,
Andi

maintainer Acked-by
#3 lore raw
Quoted 10 lines · Andi Shyti

Hi Paritosh,

Quoted 3 lines · Paritosh Potukuchi

The firmware may sometimes return a length greater than the allocated buffer size, which can lead to out-of-bounds access and a kernel panic.

How often does it happen? Should it be considered a fix?

Shyam, any comments on this?

Looks good to me.

Thanks,
Shyam

Quoted 56 lines
Quoted 8 lines

Currently, the driver does not validate the length read from firmware.

Add a check to ensure the firmware-reported length stays within the bounds of the data buffer.

Fix indentation issues reported by checkpatch.

I'm going to remove this comment here as I'm going to take only this patch and it's a meaningless information to leave in the log history.

Quoted 10 lines
---
 drivers/i2c/busses/i2c-amd-asf-plat.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/i2c/busses/i2c-amd-asf-plat.c +0 -0
index ca45f0f23321..e1699da838c2 100644

drivers/i2c/busses/i2c-amd-asf-plat.c static void amd_asf_process_target(struct work_struct *work) · line 95

Quoted 6 lines
drivers/i2c/busses/i2c-amd-asf-plat.c +3 -0
@@ -90,6 +90,9 @@ static void amd_asf_process_target(struct work_struct *work)
 		outb_p(reg, ASFDATABNKSEL);
 		cmd = inb_p(ASFINDEX);
 		len = inb_p(ASFDATARWPTR);
+		if (len > ASF_BLOCK_MAX_BYTES)
+			return;
+

Your patch makes sense to me. I'd just like a blank line before the 'if' statement. No need to resend it; I'll add it while applying the patch unless you disagree.

Besides that, the patch is not properly formatted. It is missing:

1. Versioning: this should have been "[PATCH v2] ...".

2. Changelog: for a single patch, it should be added below the '---' line, after your Signed-off-by. You added "Fix indentation issues..." as a sort of changelog, but it is in the wrong place and it is not clear that it is a changelog.

3. Please don't send a new version as a reply to the previous one. From a maintainer's point of view, that makes it more difficult to track and apply.

That said, I believe this is your first patch, and that's perfectly fine. Welcome to the community :-)

Unless there are further comments, I'll apply your patch to i2c/i2c-for-7.2.

Thanks,
Andi

maintainer Applied
#4 lore raw
In reply to Paritosh Potukuchi

Hi Paritosh,

Quoted 7 lines · Paritosh Potukuchi

The firmware may sometimes return a length greater than the allocated buffer size, which can lead to out-of-bounds access and a kernel panic.

Currently, the driver does not validate the length read from firmware.

Quoted 6 lines

Add a check to ensure the firmware-reported length stays within the bounds of the data buffer.

Fix indentation issues reported by checkpatch.

merged to i2c/i2c-for-7.2

Thanks,
Andi