* [PATCH] drm: etnaviv: fix strncpy sizeof argument
@ 2019-03-19 2:57 Bo YU
2019-03-19 10:22 ` Russell King - ARM Linux admin
0 siblings, 1 reply; 3+ messages in thread
From: Bo YU @ 2019-03-19 2:57 UTC (permalink / raw)
To: l.stach, linux+etnaviv, christian.gmeiner, airlied, daniel, etnaviv
Cc: Bo YU, dri-devel, linux-kernel, yuzibode
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)
Signed-off-by: Bo YU <tsu.yubo@gmail.com>
---
drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
index 4227a4006c34..08ca3c44be48 100644
--- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
+++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
@@ -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)
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm: etnaviv: fix strncpy sizeof argument
2019-03-19 2:57 [PATCH] drm: etnaviv: fix strncpy sizeof argument Bo YU
@ 2019-03-19 10:22 ` Russell King - ARM Linux admin
2019-03-19 11:09 ` Bo YU
0 siblings, 1 reply; 3+ messages in thread
From: Russell King - ARM Linux admin @ 2019-03-19 10:22 UTC (permalink / raw)
To: Bo YU
Cc: l.stach, christian.gmeiner, airlied, daniel, etnaviv, dri-devel,
linux-kernel, yuzibode
On Mon, Mar 18, 2019 at 10:57:55PM -0400, Bo YU wrote:
> 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)
> Signed-off-by: Bo YU <tsu.yubo@gmail.com>
> ---
> drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> index 4227a4006c34..08ca3c44be48 100644
> --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> @@ -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.
--
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm: etnaviv: fix strncpy sizeof argument
2019-03-19 10:22 ` Russell King - ARM Linux admin
@ 2019-03-19 11:09 ` Bo YU
0 siblings, 0 replies; 3+ messages in thread
From: Bo YU @ 2019-03-19 11:09 UTC (permalink / raw)
To: Russell King - ARM Linux admin
Cc: l.stach, Christian Gmeiner, airlied, Daniel Vetter, etnaviv,
dri-devel, open list, 于波
On Tue, Mar 19, 2019 at 6:22 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:
>
> On Mon, Mar 18, 2019 at 10:57:55PM -0400, Bo YU wrote:
> > 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)
> > Signed-off-by: Bo YU <tsu.yubo@gmail.com>
> > ---
> > drivers/gpu/drm/etnaviv/etnaviv_perfmon.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > index 4227a4006c34..08ca3c44be48 100644
> > --- a/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > +++ b/drivers/gpu/drm/etnaviv/etnaviv_perfmon.c
> > @@ -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.
Oops,It seems more worse than original code.
>
> 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?
>
> --
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-19 11:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19 2:57 [PATCH] drm: etnaviv: fix strncpy sizeof argument Bo YU
2019-03-19 10:22 ` Russell King - ARM Linux admin
2019-03-19 11:09 ` Bo YU
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).