Skip to content

Commit 9c85743

Browse files
Mohammed Mirza Mandayappurath ManzoormikeNG
authored andcommitted
msm: kgsl: Prevent wrap around during user address mapping
When setting svm region during the gpuobj import ioctl call for a usermem address, there is a possibility of a very large input size causing the region's 64-bit end address to wrap around. This can cause the region to incorrectly be considered valid, ultimately allowing a use after free scenario. To prevent this, detect the occurrence of a wrap and reject the import. Change-Id: I4a88f56c58b830d4342e47dc1d1f6290c78ab6b4 Signed-off-by: Mohammed Mirza Mandayappurath Manzoor <quic_mmandaya@quicinc.com> Signed-off-by: Puranam V G Tejaswi <quic_pvgtejas@quicinc.com>
1 parent 81d9db8 commit 9c85743

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

drivers/gpu/msm/kgsl_iommu.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Copyright (c) 2011-2021, The Linux Foundation. All rights reserved.
2-
* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
2+
* Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 2 and
@@ -2422,14 +2422,18 @@ static uint64_t kgsl_iommu_find_svm_region(struct kgsl_pagetable *pagetable,
24222422
static bool iommu_addr_in_svm_ranges(struct kgsl_iommu_pt *pt,
24232423
u64 gpuaddr, u64 size)
24242424
{
2425+
u64 end = gpuaddr + size;
2426+
2427+
/* Make sure size is not zero and we don't wrap around */
2428+
if (end <= gpuaddr)
2429+
return false;
2430+
24252431
if ((gpuaddr >= pt->compat_va_start && gpuaddr < pt->compat_va_end) &&
2426-
((gpuaddr + size) > pt->compat_va_start &&
2427-
(gpuaddr + size) <= pt->compat_va_end))
2432+
(end > pt->compat_va_start && end <= pt->compat_va_end))
24282433
return true;
24292434

24302435
if ((gpuaddr >= pt->svm_start && gpuaddr < pt->svm_end) &&
2431-
((gpuaddr + size) > pt->svm_start &&
2432-
(gpuaddr + size) <= pt->svm_end))
2436+
(end > pt->svm_start && end <= pt->svm_end))
24332437
return true;
24342438

24352439
return false;

0 commit comments

Comments
 (0)