drm/amdgpu: fix potential integer overflow on shift of a int
Subsystems (3)
PATCH 1/1 drm/amdgpu: fix potential integer overflow on shift of a int
From: Colin Ian King <[email protected]>
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to an unsigned 64 bit integer. In the case where *frag is 32 or more this can lead to an oveflow. Avoid this by shifting 1ULL.
Addresses-Coverity: ("Unintentional integer overflow")
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -1412,7 +1412,7 @@ static void amdgpu_vm_fragment(struct amdgpu_vm_update_params *params, *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) -1 ); }else { - *frag_end = start + (1 << *frag); + *frag_end = start + (1ULL << *frag); } }
Signature · 1 line
2.29.2
Christian König
maintainerAm 08.02.21 um 00:07 schrieb Colin King:
Quoted 6 lines
From: Colin Ian King <[email protected]>
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to an unsigned 64 bit integer. In the case where *frag is 32 or more this can lead to an oveflow. Avoid this by shifting 1ULL.
Well that can't happen. Take a look at the code in that function:
Quoted 1 line
max_frag= 31;
...
Quoted 6 lines
if (*frag >=
max_frag) {
*frag =max_frag;
*frag_end= end & ~((1ULL <<max_frag) - 1); } else {
*frag_end= start + (1 << *frag); }
But I'm fine with applying the patch if it silences your warning.
Regards,
Christian.
Quoted 21 lines
Addresses-Coverity: ("Unintentional integer overflow")
Fixes dfcd99f6273e ("drm/amdgpu: meld together VM fragment and huge page handling")Signed-off-by Colin Ian King <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1412,7 +1412,7 @@ static void amdgpu_vm_fragment(struct amdgpu_vm_update_params *params, *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) -1 ); }else { - *frag_end = start + (1 << *frag); + *frag_end = start + (1ULL << *frag); } }
i am curious:
what is the win to have a unsigned 64 bit integer in the first place ?
re,
wh
________________________________________
Von: Christian König <[email protected]>
Gesendet: Montag, 8. Februar 2021 10:17:42
An: Colin King; Alex Deucher; David Airlie; Daniel Vetter; Huang Rui; Junwei Zhang; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Betreff: Re: [PATCH] drm/amdgpu: fix potential integer overflow on shift of a int
Am 08.02.21 um 00:07 schrieb Colin King:
Quoted 6 lines
From: Colin Ian King <[email protected]>
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to an unsigned 64 bit integer. In the case where *frag is 32 or more this can lead to an oveflow. Avoid this by shifting 1ULL.
Well that can't happen. Take a look at the code in that function:
Quoted 1 line
max_frag = 31;
...
Quoted 6 lines
if (*frag >= max_frag) {
*frag = max_frag;
*frag_end = end & ~((1ULL << max_frag) - 1);
} else {
*frag_end = start + (1 << *frag);
}But I'm fine with applying the patch if it silences your warning.
Regards,
Christian.
Quoted 21 lines
Addresses-Coverity: ("Unintentional integer overflow")
Fixes dfcd99f6273e ("drm/amdgpu: meld together VM fragment and huge page handling")Signed-off-by Colin Ian King <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1412,7 +1412,7 @@ static void amdgpu_vm_fragment(struct amdgpu_vm_update_params *params, *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) -1 ); }else { - *frag_end = start + (1 << *frag); + *frag_end = start + (1ULL << *frag); } }
Christian König
maintainerFor start and end? The hardware has 48 bit address space and that won't fit into 32bits.
Only the fragment handling can't do more than 2GB at the same time.
Christian.
Am 08.02.21 um 12:05 schrieb Walter Harms:
Quoted 55 lines
i am curious:
what is the win to have a unsigned 64 bit integer in the first place ?re,
wh
________________________________________
Von: Christian König <[email protected]>
Gesendet: Montag, 8. Februar 2021 10:17:42
An: Colin King; Alex Deucher; David Airlie; Daniel Vetter; Huang Rui; Junwei Zhang; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Betreff: Re: [PATCH] drm/amdgpu: fix potential integer overflow on shift of a intAm 08.02.21 um 00:07 schrieb Colin King:
Quoted 6 lines
From: Colin Ian King <[email protected]>
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to an unsigned 64 bit integer. In the case where *frag is 32 or more this can lead to an oveflow. Avoid this by shifting 1ULL.
Well that can't happen. Take a look at the code in that function:
Quoted 1 line
max_frag = 31;...
Quoted 6 lines
if (*frag >= max_frag) { *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) - 1); } else { *frag_end = start + (1 << *frag); }But I'm fine with applying the patch if it silences your warning.
Regards,
Christian.Quoted 20 lines
Addresses-Coverity: ("Unintentional integer overflow")
Fixes dfcd99f6273e ("drm/amdgpu: meld together VM fragment and huge page handling")Signed-off-by Colin Ian King <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1412,7 +1412,7 @@ static void amdgpu_vm_fragment(struct amdgpu_vm_update_params *params, *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) -1 ); }else { - *frag_end = start + (1 << *frag); + *frag_end = start + (1ULL << *frag); } }
thx for info
________________________________________
Von: Christian König <[email protected]>
Gesendet: Montag, 8. Februar 2021 13:14:49
An: Walter Harms; Colin King; Alex Deucher; David Airlie; Daniel Vetter; Huang Rui; Junwei Zhang; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Betreff: Re: [PATCH] drm/amdgpu: fix potential integer overflow on shift of a int
For start and end? The hardware has 48 bit address space and that won't fit into 32bits.
Only the fragment handling can't do more than 2GB at the same time.
Christian.
Am 08.02.21 um 12:05 schrieb Walter Harms:
Quoted 55 lines
i am curious:
what is the win to have a unsigned 64 bit integer in the first place ?re,
wh
________________________________________
Von: Christian König <[email protected]>
Gesendet: Montag, 8. Februar 2021 10:17:42
An: Colin King; Alex Deucher; David Airlie; Daniel Vetter; Huang Rui; Junwei Zhang; [email protected]; [email protected]
Cc: [email protected]; [email protected]
Betreff: Re: [PATCH] drm/amdgpu: fix potential integer overflow on shift of a intAm 08.02.21 um 00:07 schrieb Colin King:
Quoted 6 lines
From: Colin Ian King <[email protected]>
The left shift of int 32 bit integer constant 1 is evaluated using 32 bit arithmetic and then assigned to an unsigned 64 bit integer. In the case where *frag is 32 or more this can lead to an oveflow. Avoid this by shifting 1ULL.
Well that can't happen. Take a look at the code in that function:
Quoted 1 line
max_frag = 31;...
Quoted 6 lines
if (*frag >= max_frag) { *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) - 1); } else { *frag_end = start + (1 << *frag); }But I'm fine with applying the patch if it silences your warning.
Regards,
Christian.Quoted 20 lines
Addresses-Coverity: ("Unintentional integer overflow")
Fixes dfcd99f6273e ("drm/amdgpu: meld together VM fragment and huge page handling")Signed-off-by Colin Ian King <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1412,7 +1412,7 @@ static void amdgpu_vm_fragment(struct amdgpu_vm_update_params *params, *frag = max_frag; *frag_end = end & ~((1ULL << max_frag) -1 ); }else { - *frag_end = start + (1 << *frag); + *frag_end = start + (1ULL << *frag); } }