Skip to contentSkip to conversation

efi/cper: Use scnprintf() for avoiding potential buffer overflow

PATCH Applied Takashi Iwai 3 participants 4 messages Mar 11, 2020 – Apr 14, 2020

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

PATCH 1/1 efi/cper: Use scnprintf() for avoiding potential buffer overflow

Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf().

---
 drivers/firmware/efi/cper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/cper.c +1 -1
index b1af0de2e100..9d2512913d25 100644
@@ -101,7 +101,7 @@ void cper_print_bits(const char *pfx, unsigned int bits,
 		if (!len)
 			len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
 		else
-			len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
+			len += scnprintf(buf+len, sizeof(buf)-len, ", %s", str);
 	}
 	if (len)
 		printk("%s\n", buf);
Signature · 1 line
2.16.4
#1 lore raw
Quoted 6 lines · Takashi Iwai

Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf().

A gentle reminder for this forgotten patch.
Let me know if any further changes are needed.

thanks,

Takashi

Quoted 20 lines
---
 drivers/firmware/efi/cper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/cper.c +1 -1
index b1af0de2e100..9d2512913d25 100644
@@ -101,7 +101,7 @@ void cper_print_bits(const char *pfx, unsigned int bits,
 		if (!len)
 			len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
 		else
-			len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
+			len += scnprintf(buf+len, sizeof(buf)-len, ", %s", str);
 	}
 	if (len)
 		printk("%s\n", buf);
Signature · 1 line
2.16.4
maintainer
#2 lore raw
Quoted 4 lines · Takashi Iwai
Quoted 1 line · Takashi Iwai
Quoted 9 lines
Quoted 5 lines

Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf().

A gentle reminder for this forgotten patch.
Let me know if any further changes are needed.

Thanks Takashi, I'll queue this up.

merge bot Applied
#3 lore raw
In reply to Takashi Iwai
The following commit has been merged into the efi/urgent branch of tip:

The following commit has been merged into the efi/urgent branch of tip:

Commit-ID:     b450b30b97010e5c68ab522c6f6c54ef76bd0683
Gitweb:        https://git.kernel.org/tip/b450b30b97010e5c68ab522c6f6c54ef76bd0683
Author:        Takashi Iwai <[email protected]>
AuthorDate:    Thu, 09 Apr 2020 15:04:26 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Tue, 14 Apr 2020 08:32:11 +02:00

efi/cper: Use scnprintf() for avoiding potential buffer overflow

Since snprintf() returns the would-be-output size instead of the actual output size, the succeeding calls may go beyond the given buffer limit. Fix it by replacing with scnprintf().

---
 drivers/firmware/efi/cper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/efi/cper.c +1 -1
index b1af0de..9d25129 100644
@@ -101,7 +101,7 @@ void cper_print_bits(const char *pfx, unsigned int bits,
 		if (!len)
 			len = snprintf(buf, sizeof(buf), "%s%s", pfx, str);
 		else
-			len += snprintf(buf+len, sizeof(buf)-len, ", %s", str);
+			len += scnprintf(buf+len, sizeof(buf)-len, ", %s", str);
 	}
 	if (len)
 		printk("%s\n", buf);