Skip to contentSkip to conversation

IOMUX: Fix buffer overflow in iomux_replace_device()

PATCH Superseded Yuichiro Goto 2 participants 3 messages Apr 23, 2021 – Apr 25, 2021

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 IOMUX: Fix buffer overflow in iomux_replace_device()

Use of strcat() against an uninitialized buffer would lead to buffer overflow. This patch fixes it.

Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

---

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
common/iomux.c +4 -1
index b9088aa3b5..27baca6931 100644
@@ -158,7 +158,10 @@ int iomux_replace_device(const int console, const char *old, const char *new)
 			return -ENOMEM;
 		}
 
-		strcat(tmp, ",");
+		if (!arg)
+			strcpy(tmp, ",");
+		else
+			strcat(tmp, ",");
 		strcat(tmp, name);
 
 		arg = tmp;
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 IOMUX: Fix buffer overflow in iomux_replace_device()

Quoted 2 lines · Yuichiro Goto

Use of strcat() against an uninitialized buffer would lead to buffer overflow. This patch fixes it.

Thanks for report!

Can you also add a Fixes tag?

Quoted 17 lines
Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

---

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
common/iomux.c +0 -0
index b9088aa3b5..27baca6931 100644

common/iomux.c int iomux_replace_device(const int console, const char *old, const char *new) · line 165

Quoted 9 lines
common/iomux.c +4 -1
@@ -158,7 +158,10 @@ int iomux_replace_device(const int console, const char *old, const char *new)
 			return -ENOMEM;
 		}
 
-		strcat(tmp, ",");
+		if (!arg)
+			strcpy(tmp, ",");
+		else
+			strcat(tmp, ",");
 		strcat(tmp, name);

It would be better to have it like

	if (arg) {
		strcat(tmp, ",");
		strcat(tmp, name);
	} else
		strcpy(tmp, name);

common/iomux.c int iomux_replace_device(const int console, const char *old, const char *new) · line 167

Quoted 1 line
common/iomux.c +0 -0
 		arg = tmp;

Peter, does it fix your issue seen on ARMv7?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

PATCH v2 1/1 IOMUX: Fix buffer overflow in iomux_replace_device()

Quoted 45 lines · Andy Shevchenko
Quoted 2 lines · Yuichiro Goto

Use of strcat() against an uninitialized buffer would lead to buffer overflow. This patch fixes it.

Thanks for report!

Can you also add a Fixes tag?

Quoted 17 lines
Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

---

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
common/iomux.c +0 -0
index b9088aa3b5..27baca6931 100644

common/iomux.c int iomux_replace_device(const int console, const char *old, const char *new) · line 165

Quoted 9 lines
common/iomux.c +4 -1
@@ -158,7 +158,10 @@ int iomux_replace_device(const int console, const char *old, const char *new)
                      return -ENOMEM;
              }
 
-             strcat(tmp, ",");
+             if (!arg)
+                     strcpy(tmp, ",");
+             else
+                     strcat(tmp, ",");
              strcat(tmp, name);

It would be better to have it like

        if (arg) {
                strcat(tmp, ",");
                strcat(tmp, name);
        } else
                strcpy(tmp, name);
Quoted 9 lines

common/iomux.c int iomux_replace_device(const int console, const char *old, const char *new) · line 167

Quoted 1 line
common/iomux.c +0 -0
              arg = tmp;

Peter, does it fix your issue seen on ARMv7?

--
With Best Regards,
Andy Shevchenko

Hi Andy,

Thank you for your review. I submitted the patch v3 based on you suggestions.

Signature · 2 lines
Kind Regards,
Yuichiro Goto