Skip to contentSkip to conversation

IOMUX: Fix buffer overflow in iomux_replace_device()

PATCH New Yuichiro Goto 4 participants 4 messages Apr 25, 2021 – Apr 27, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

Fixes 694cd5618c ("IOMUX: Introduce iomux_replace_device()")
Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

---

Changes for v3:
- Add a Fixes tag in commit message
- Refactor the patch per suggestion from Andy Shevchenko

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
common/iomux.c +6 -2
index b9088aa3b5..c428f7110a 100644
@@ -158,8 +158,12 @@ int iomux_replace_device(const int console, const char *old, const char *new)
 			return -ENOMEM;
 		}
 
-		strcat(tmp, ",");
-		strcat(tmp, name);
+		if (arg) {
+			strcat(tmp, ",");
+			strcat(tmp, name);
+		}
+		else
+			strcpy(tmp, name);
 
 		arg = tmp;
 		size = strlen(tmp) + 1;
Signature · 1 line
2.17.1
#1 lore raw

PATCH v3 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.

Quoted 39 lines
Fixes 694cd5618c ("IOMUX: Introduce iomux_replace_device()")
Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

---

Changes for v3:
- Add a Fixes tag in commit message
- Refactor the patch per suggestion from Andy Shevchenko

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
common/iomux.c +6 -2
index b9088aa3b5..c428f7110a 100644
@@ -158,8 +158,12 @@ int iomux_replace_device(const int console, const char *old, const char *new)
 			return -ENOMEM;
 		}
 
-		strcat(tmp, ",");
-		strcat(tmp, name);
+		if (arg) {
+			strcat(tmp, ",");
+			strcat(tmp, name);
+		}
+		else
+			strcpy(tmp, name);
 
 		arg = tmp;
 		size = strlen(tmp) + 1;
Signature · 1 line
2.17.1
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw

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

In reply to Yuichiro Goto
Quoted 9 lines · Yuichiro Goto

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

Fixes 694cd5618c ("IOMUX: Introduce iomux_replace_device()")
Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

On a RPi2/RPi3 and Cubieboard

Quoted 34 lines

---

Changes for v3:
- Add a Fixes tag in commit message
- Refactor the patch per suggestion from Andy Shevchenko

Changes for v2:
- Add "IOMUX" in title

 common/iomux.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
common/iomux.c +6 -3
index b9088aa3b5..c428f7110a 100644
@@ -158,8 +158,12 @@ int iomux_replace_device(const int console, const char *old, const char *new)
                        return -ENOMEM;
                }
 
-               strcat(tmp, ",");
-               strcat(tmp, name);
+               if (arg) {
+                       strcat(tmp, ",");
+                       strcat(tmp, name);
+               }
+               else
+                       strcpy(tmp, name);
 
                arg = tmp;
                size = strlen(tmp) + 1;
--

2.17.1

#3 lore raw

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

In reply to Yuichiro Goto
Quoted 10 lines · Yuichiro Goto

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

Fixes 694cd5618c ("IOMUX: Introduce iomux_replace_device()")
Cc Peter Robinson <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210427/1776de39/attachment.sig>