Skip to contentSkip to conversation

drm/ttm: Use scnprintf() for avoiding potential buffer overflow

PATCH In review Takashi Iwai 3 participants 4 messages Mar 11, 2020

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

PATCH 1/1 drm/ttm: 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/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -1
index bf876faea592..faefaaef7909 100644
@@ -604,7 +604,7 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,
 	p = pool->name;
 	for (i = 0; i < ARRAY_SIZE(t); i++) {
 		if (type & t[i]) {
-			p += snprintf(p, sizeof(pool->name) - (p - pool->name),
+			p += scnprintf(p, sizeof(pool->name) - (p - pool->name),
 				      "%s", n[i]);
 		}
 	}
Signature · 6 lines
2.16.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 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 20 lines
---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -1
index bf876faea592..faefaaef7909 100644
@@ -604,7 +604,7 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,
 	p = pool->name;
 	for (i = 0; i < ARRAY_SIZE(t); i++) {
 		if (type & t[i]) {
-			p += snprintf(p, sizeof(pool->name) - (p - pool->name),
+			p += scnprintf(p, sizeof(pool->name) - (p - pool->name),
 				      "%s", n[i]);
 		}
 	}
Signature · 1 line
2.16.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Reviewed-by
#2 lore raw

Am 11.03.20 um 08:52 schrieb Huang Rui:

Quoted 7 lines · Takashi Iwai
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().

Takashi, should I push this to drm-misc-next or do you want to merge that somehow else?

Thanks,
Christian.

Quoted 5 lines
Quoted 5 lines
---
  drivers/gpu/drm/ttm/ttm_page_alloc_dma.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/ttm/ttm_page_alloc_dma.c +1 -1
index bf876faea592..faefaaef7909 100644
@@ -604,7 +604,7 @@ static struct dma_pool *ttm_dma_pool_init(struct device *dev, gfp_t flags,
  	p = pool->name;
  	for (i = 0; i < ARRAY_SIZE(t); i++) {
  		if (type & t[i]) {
-			p += snprintf(p, sizeof(pool->name) - (p - pool->name),
+			p += scnprintf(p, sizeof(pool->name) - (p - pool->name),
  				      "%s", n[i]);
  		}
  	}
Signature · 1 line
2.16.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 7 lines · On Wed, 11 Mar 2020 08:56:11 +0100, Christian K6nig wrote:

Am 11.03.20 um 08:52 schrieb Huang Rui:

Quoted 5 lines · Takashi Iwai
Quoted 4 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().

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Takashi, should I push this to drm-misc-next or do you want to merge that somehow else?

Please take through your tree as you like.

Thanks!

Takashi
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel