public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Coverity: kfd_parse_subtype_cache(): Memory - corruptions
@ 2022-11-04 19:41 coverity-bot
  2022-11-04 20:40 ` Felix Kuehling
  0 siblings, 1 reply; 3+ messages in thread
From: coverity-bot @ 2022-11-04 19:41 UTC (permalink / raw)
  To: Harish Kasiviswanathan
  Cc: Alex Deucher, Christian König, David Airlie, amd-gfx,
	Oded Gabbay, Jay Cornwall, Ben Goz, dri-devel, linux-kernel,
	Kent Russell, Felix Kuehling, Pan, Xinhui, Daniel Vetter,
	Amber Lin, Gustavo A. R. Silva, linux-next, linux-hardening

Hello!

This is an experimental semi-automated report about issues detected by
Coverity from a scan of next-20221104 as part of the linux-next scan project:
https://scan.coverity.com/projects/linux-next-weekly-scan

You're getting this email because you were associated with the identified
lines of code (noted below) that were touched by commits:

  Fri Dec 8 23:08:59 2017 -0500
    3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")

Coverity reported the following:

*** CID 1527133:  Memory - corruptions  (OVERRUN)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c:1113 in kfd_parse_subtype_cache()
1107     			props->cache_size = cache->cache_size;
1108     			props->cacheline_size = cache->cache_line_size;
1109     			props->cachelines_per_tag = cache->lines_per_tag;
1110     			props->cache_assoc = cache->associativity;
1111     			props->cache_latency = cache->cache_latency;
1112
vvv     CID 1527133:  Memory - corruptions  (OVERRUN)
vvv     Overrunning array "cache->sibling_map" of 32 bytes by passing it to a function which accesses it at byte offset 63 using argument "64UL". [Note: The source code implementation of the function has been overridden by a builtin model.]
1113     			memcpy(props->sibling_map, cache->sibling_map,
1114     					sizeof(props->sibling_map));
1115
1116     			/* set the sibling_map_size as 32 for CRAT from ACPI */
1117     			props->sibling_map_size = CRAT_SIBLINGMAP_SIZE;
1118

If this is a false positive, please let us know so we can mark it as
such, or teach the Coverity rules to be smarter. If not, please make
sure fixes get into linux-next. :) For patches fixing this, please
include these lines (but double-check the "Fixes" first):

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527133 ("Memory - corruptions")
Fixes: 3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")

I'm not sure why this suddenly appeared after 5 years, but the read
over-run looks legit:

struct crat_subtype_cache {
        ...
        uint8_t         sibling_map[CRAT_SIBLINGMAP_SIZE];

#define CRAT_SIBLINGMAP_SIZE    32


struct kfd_cache_properties {
        ...
        uint8_t                 sibling_map[CACHE_SIBLINGMAP_SIZE];

#define CACHE_SIBLINGMAP_SIZE 64

Thanks for your attention!

-- 
Coverity-bot

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Coverity: kfd_parse_subtype_cache(): Memory - corruptions
  2022-11-04 19:41 Coverity: kfd_parse_subtype_cache(): Memory - corruptions coverity-bot
@ 2022-11-04 20:40 ` Felix Kuehling
  2022-11-07  6:41   ` Ma, Jun
  0 siblings, 1 reply; 3+ messages in thread
From: Felix Kuehling @ 2022-11-04 20:40 UTC (permalink / raw)
  To: coverity-bot, Harish Kasiviswanathan, Ma, Jun
  Cc: Alex Deucher, Christian König, David Airlie, amd-gfx,
	Oded Gabbay, Jay Cornwall, Ben Goz, dri-devel, linux-kernel,
	Kent Russell, Pan, Xinhui, Daniel Vetter, Amber Lin,
	Gustavo A. R. Silva, linux-next, linux-hardening

On 2022-11-04 15:41, coverity-bot wrote:
> Hello!
>
> This is an experimental semi-automated report about issues detected by
> Coverity from a scan of next-20221104 as part of the linux-next scan project:
> https://scan.coverity.com/projects/linux-next-weekly-scan
>
> You're getting this email because you were associated with the identified
> lines of code (noted below) that were touched by commits:
>
>    Fri Dec 8 23:08:59 2017 -0500
>      3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")
>
> Coverity reported the following:
>
> *** CID 1527133:  Memory - corruptions  (OVERRUN)
> drivers/gpu/drm/amd/amdkfd/kfd_crat.c:1113 in kfd_parse_subtype_cache()
> 1107     			props->cache_size = cache->cache_size;
> 1108     			props->cacheline_size = cache->cache_line_size;
> 1109     			props->cachelines_per_tag = cache->lines_per_tag;
> 1110     			props->cache_assoc = cache->associativity;
> 1111     			props->cache_latency = cache->cache_latency;
> 1112
> vvv     CID 1527133:  Memory - corruptions  (OVERRUN)
> vvv     Overrunning array "cache->sibling_map" of 32 bytes by passing it to a function which accesses it at byte offset 63 using argument "64UL". [Note: The source code implementation of the function has been overridden by a builtin model.]
> 1113     			memcpy(props->sibling_map, cache->sibling_map,
> 1114     					sizeof(props->sibling_map));
> 1115
> 1116     			/* set the sibling_map_size as 32 for CRAT from ACPI */
> 1117     			props->sibling_map_size = CRAT_SIBLINGMAP_SIZE;
> 1118
>
> If this is a false positive, please let us know so we can mark it as
> such, or teach the Coverity rules to be smarter. If not, please make
> sure fixes get into linux-next. :) For patches fixing this, please
> include these lines (but double-check the "Fixes" first):
>
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1527133 ("Memory - corruptions")
> Fixes: 3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")
>
> I'm not sure why this suddenly appeared after 5 years, but the read
> over-run looks legit:


I think this was introduced by a more recent patch that was in fact 
meant to fix an array overrun on HW that is outgrowing the CRAT sibling 
map size:

> commit 0938fbeb6f53fc44bc9b19784dee28496e68ba0c
> Author: Ma Jun <Jun.Ma2@amd.com>
> Date:   Wed Nov 2 15:53:26 2022 +0800
>
>     drm/amdkfd: Fix the warning of array-index-out-of-bounds
>
>     For some GPUs with more CUs, the original sibling_map[32]
>     in struct crat_subtype_cache is not enough
>     to save the cache information when create the VCRAT table,
>     so skip filling the struct crat_subtype_cache info instead
>     fill struct kfd_cache_properties directly to fix this problem.
>
>     Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
>     Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
>     Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
I added Ma Jun to the email.

Regards,
   Felix


>
> struct crat_subtype_cache {
>          ...
>          uint8_t         sibling_map[CRAT_SIBLINGMAP_SIZE];
>
> #define CRAT_SIBLINGMAP_SIZE    32
>
>
> struct kfd_cache_properties {
>          ...
>          uint8_t                 sibling_map[CACHE_SIBLINGMAP_SIZE];
>
> #define CACHE_SIBLINGMAP_SIZE 64
>
> Thanks for your attention!
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Coverity: kfd_parse_subtype_cache(): Memory - corruptions
  2022-11-04 20:40 ` Felix Kuehling
@ 2022-11-07  6:41   ` Ma, Jun
  0 siblings, 0 replies; 3+ messages in thread
From: Ma, Jun @ 2022-11-07  6:41 UTC (permalink / raw)
  To: Felix Kuehling, coverity-bot, Harish Kasiviswanathan, Ma, Jun
  Cc: majun, Alex Deucher, Christian König, David Airlie, amd-gfx,
	Oded Gabbay, Jay Cornwall, Ben Goz, dri-devel, linux-kernel,
	Kent Russell, Pan, Xinhui, Daniel Vetter, Amber Lin,
	Gustavo A. R. Silva, linux-next, linux-hardening

Thanks, I will send the fix patch.

Regards,
Ma Jun

On 11/5/2022 4:40 AM, Felix Kuehling wrote:
> On 2022-11-04 15:41, coverity-bot wrote:
>> Hello!
>>
>> This is an experimental semi-automated report about issues detected by
>> Coverity from a scan of next-20221104 as part of the linux-next scan project:
>> https://scan.coverity.com/projects/linux-next-weekly-scan
>>
>> You're getting this email because you were associated with the identified
>> lines of code (noted below) that were touched by commits:
>>
>>    Fri Dec 8 23:08:59 2017 -0500
>>      3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")
>>
>> Coverity reported the following:
>>
>> *** CID 1527133:  Memory - corruptions  (OVERRUN)
>> drivers/gpu/drm/amd/amdkfd/kfd_crat.c:1113 in kfd_parse_subtype_cache()
>> 1107     			props->cache_size = cache->cache_size;
>> 1108     			props->cacheline_size = cache->cache_line_size;
>> 1109     			props->cachelines_per_tag = cache->lines_per_tag;
>> 1110     			props->cache_assoc = cache->associativity;
>> 1111     			props->cache_latency = cache->cache_latency;
>> 1112
>> vvv     CID 1527133:  Memory - corruptions  (OVERRUN)
>> vvv     Overrunning array "cache->sibling_map" of 32 bytes by passing it to a function which accesses it at byte offset 63 using argument "64UL". [Note: The source code implementation of the function has been overridden by a builtin model.]
>> 1113     			memcpy(props->sibling_map, cache->sibling_map,
>> 1114     					sizeof(props->sibling_map));
>> 1115
>> 1116     			/* set the sibling_map_size as 32 for CRAT from ACPI */
>> 1117     			props->sibling_map_size = CRAT_SIBLINGMAP_SIZE;
>> 1118
>>
>> If this is a false positive, please let us know so we can mark it as
>> such, or teach the Coverity rules to be smarter. If not, please make
>> sure fixes get into linux-next. :) For patches fixing this, please
>> include these lines (but double-check the "Fixes" first):
>>
>> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
>> Addresses-Coverity-ID: 1527133 ("Memory - corruptions")
>> Fixes: 3a87177eb141 ("drm/amdkfd: Add topology support for dGPUs")
>>
>> I'm not sure why this suddenly appeared after 5 years, but the read
>> over-run looks legit:
> 
> 
> I think this was introduced by a more recent patch that was in fact 
> meant to fix an array overrun on HW that is outgrowing the CRAT sibling 
> map size:
>
>> commit 0938fbeb6f53fc44bc9b19784dee28496e68ba0c
>> Author: Ma Jun <Jun.Ma2@amd.com>
>> Date:   Wed Nov 2 15:53:26 2022 +0800
>>
>>     drm/amdkfd: Fix the warning of array-index-out-of-bounds
>>
>>     For some GPUs with more CUs, the original sibling_map[32]
>>     in struct crat_subtype_cache is not enough
>>     to save the cache information when create the VCRAT table,
>>     so skip filling the struct crat_subtype_cache info instead
>>     fill struct kfd_cache_properties directly to fix this problem.
>>
>>     Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
>>     Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
>>     Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> I added Ma Jun to the email.
> 
> Regards,
>    Felix
> 
> 
>>
>> struct crat_subtype_cache {
>>          ...
>>          uint8_t         sibling_map[CRAT_SIBLINGMAP_SIZE];
>>
>> #define CRAT_SIBLINGMAP_SIZE    32
>>
>>
>> struct kfd_cache_properties {
>>          ...
>>          uint8_t                 sibling_map[CACHE_SIBLINGMAP_SIZE];
>>
>> #define CACHE_SIBLINGMAP_SIZE 64
>>
>> Thanks for your attention!
>>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-07  6:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-04 19:41 Coverity: kfd_parse_subtype_cache(): Memory - corruptions coverity-bot
2022-11-04 20:40 ` Felix Kuehling
2022-11-07  6:41   ` Ma, Jun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox