Skip to contentSkip to conversation

bcache: Use scnprintf() for avoiding potential buffer overflow

PATCH Superseded Takashi Iwai 2 participants 5 messages Mar 11, 2020 – Mar 19, 2020 bcache (block layer cache)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcache: 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/md/bcache/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/sysfs.c +1 -1
index 3470fae4eabc..323276994aab 100644
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf,
 	size_t i;
 
 	for (i = 0; list[i]; i++)
-		out += snprintf(out, buf + size - out,
+		out += scnprintf(out, buf + size - out,
 				i == selected ? "[%s] " : "%s ", list[i]);
 
 	out[-1] = '\n';
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/md/bcache/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/sysfs.c +1 -1
index 3470fae4eabc..323276994aab 100644
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf,
 	size_t i;
 
 	for (i = 0; list[i]; i++)
-		out += snprintf(out, buf + size - out,
+		out += scnprintf(out, buf + size - out,
 				i == selected ? "[%s] " : "%s ", list[i]);
 
 	out[-1] = '\n';
Signature · 1 line
2.16.4
#2 lore raw
Quoted 12 lines · Takashi Iwai
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.

Hi Takashi,

This is in my for-next list already. Sorry for not reply you yet, just busy on the testing with combined with md raid backend.

Thanks.

Coly Li

Quoted 20 lines
Quoted 20 lines
---
 drivers/md/bcache/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/sysfs.c +1 -1
index 3470fae4eabc..323276994aab 100644
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf,
 	size_t i;
 
 	for (i = 0; list[i]; i++)
-		out += snprintf(out, buf + size - out,
+		out += scnprintf(out, buf + size - out,
 				i == selected ? "[%s] " : "%s ", list[i]);
 
 	out[-1] = '\n';
Signature · 1 line
2.16.4
Signature · 1 line
Coly Li
#3 lore raw
Quoted 11 lines · Coly Li
Quoted 9 lines · Takashi Iwai
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().

Quoted 8 lines
Quoted 3 lines

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

Hi Takashi,

This is in my for-next list already. Sorry for not reply you yet, just busy on the testing with combined with md raid backend.

OK, thanks. I just wondered because it didn't appear on linux-next, either.

Takashi

Quoted 31 lines

Thanks.

Coly Li

Quoted 20 lines
Quoted 20 lines
---
 drivers/md/bcache/sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/bcache/sysfs.c +1 -1
index 3470fae4eabc..323276994aab 100644
@@ -154,7 +154,7 @@ static ssize_t bch_snprint_string_list(char *buf,
 	size_t i;
 
 	for (i = 0; list[i]; i++)
-		out += snprintf(out, buf + size - out,
+		out += scnprintf(out, buf + size - out,
 				i == selected ? "[%s] " : "%s ", list[i]);
 
 	out[-1] = '\n';
Signature · 1 line
2.16.4
Signature · 1 line
Coly Li
#4 lore raw
Quoted 17 lines · Takashi Iwai
Quoted 15 lines · Coly Li
Quoted 12 lines · Takashi Iwai
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.

Quoted 7 lines
Quoted 4 lines

Hi Takashi,

This is in my for-next list already. Sorry for not reply you yet, just busy on the testing with combined with md raid backend.

OK, thanks. I just wondered because it didn't appear on linux-next, either.

I don't submit the patch set to Jens yet, because my local testing not finished yet. Hopefully it may finish in next 2 days.

Signature · 1 line
Coly Li