drm/amdgpu/df: fix potential array out-of-bounds read
authorColin Ian King <colin.king@canonical.com>
Wed, 30 May 2018 16:41:44 +0000 (17:41 +0100)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 1 Jun 2018 14:45:05 +0000 (09:45 -0500)
The comparison with the number of elements in array df_v3_7_channel_number
is off-by-one and can produce an array out-of-bounds read if
fb_channel_number is equal to the number of elements of the array. Fix
this by changing the comparison to >= instead of >.

Detected by CoverityScan, CID#1469489 ("Out-of-bounds read")

Fixes: 13b581502d51 ("drm/amdgpu/df: implement df v3_6 callback functions (v2)")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/df_v3_6.c

index 60608b3df881202651ae8cba2f4f9720c0dd8217..d5ebe566809b22e401f88582a7b73d9caf4faf81 100644 (file)
@@ -64,7 +64,7 @@ static u32 df_v3_6_get_hbm_channel_number(struct amdgpu_device *adev)
        int fb_channel_number;
 
        fb_channel_number = adev->df_funcs->get_fb_channel_number(adev);
-       if (fb_channel_number > ARRAY_SIZE(df_v3_6_channel_number))
+       if (fb_channel_number >= ARRAY_SIZE(df_v3_6_channel_number))
                fb_channel_number = 0;
 
        return df_v3_6_channel_number[fb_channel_number];