Skip to contentSkip to conversation

drm: etnaviv: fix strncpy sizeof argument

PATCH Superseded Bo YU 2 participants 3 messages Mar 19, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Bo YU

author
#0 lore raw

PATCH 1/1 drm: etnaviv: fix strncpy sizeof argument

Calling strncpy with a maximum size argument of 64 bytes on destination array "domain->name" of size 64 bytes might leave the destination string unterminated.

Detected by CoverityScan, CID# 1443992: Memory - illegal accesses (BUFFER_SIZE_WARNING)

Fixes 9e2c2e2730126 (drm/etnaviv: add infrastructure to query perf counter)
---
 drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c +1 -1
index 4227a4006c34..08ca3c44be48 100644
@@ -414,7 +414,7 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
 
 	domain->id = domain->iter;
 	domain->nr_signals = dom->nr_signals;
-	strncpy(domain->name, dom->name, sizeof(domain->name));
+	strncpy(domain->name, dom->name, sizeof(dom->name));
 
 	domain->iter++;
 	if (domain->iter == meta->nr_domains)
Signature · 1 line
2.11.0
#1 lore raw
Quoted 18 lines · Bo YU

Calling strncpy with a maximum size argument of 64 bytes on destination array "domain->name" of size 64 bytes might leave the destination string unterminated.

Detected by CoverityScan, CID# 1443992: Memory - illegal accesses (BUFFER_SIZE_WARNING)

Fixes 9e2c2e2730126 (drm/etnaviv: add infrastructure to query perf counter)
---
 drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c +0 -0
index 4227a4006c34..08ca3c44be48 100644

drivers/gpu/drm/etnaviv/etnaviv_perfmon.c int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu, · line 417

Quoted 5 lines
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c +1 -1
@@ -414,7 +414,7 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
 
 	domain->id = domain->iter;
 	domain->nr_signals = dom->nr_signals;
-	strncpy(domain->name, dom->name, sizeof(domain->name));
+	strncpy(domain->name, dom->name, sizeof(dom->name));

This introduces an overflow bug if sizeof(dom->name) > sizeof(domain->name). If both sizes are the same, then there is no effect.

strlcpy() would be a better replacement, it guarantees that the destination will be correctly terminated.

Signature · 3 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
author
#2 lore raw
Quoted 21 lines · Russell King - ARM Linux admin
Quoted 19 lines · Bo YU

Calling strncpy with a maximum size argument of 64 bytes on destination array "domain->name" of size 64 bytes might leave the destination string unterminated.

Detected by CoverityScan, CID# 1443992: Memory - illegal accesses (BUFFER_SIZE_WARNING)

Fixes 9e2c2e2730126 (drm/etnaviv: add infrastructure to query perf counter)
---
 drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c +0 -0
index 4227a4006c34..08ca3c44be48 100644
@@ -414,7 +414,7 @@ int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu,
 
Quoted 8 lines

drivers/gpu/drm/etnaviv/etnaviv_perfmon.c int etnaviv_pm_query_dom(struct etnaviv_gpu *gpu, · line 417

Quoted 4 lines
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c +1 -1
      domain->id = domain->iter;
      domain->nr_signals = dom->nr_signals;
-     strncpy(domain->name, dom->name, sizeof(domain->name));
+     strncpy(domain->name, dom->name, sizeof(dom->name));

This introduces an overflow bug if sizeof(dom->name) > sizeof(domain->name). If both sizes are the same, then there is no effect.

Oops,It seems more worse than original code.

Quoted 3 lines

strlcpy() would be a better replacement, it guarantees that the destination will be correctly terminated.

But there are too many strcpy like usage in kernel, Does it matter?

Quoted 5 lines

--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up