Skip to content
/ linux Public

Commit 5ce4a38

Browse files
Jie1zhanggregkh
authored andcommitted
drm/amdgpu: Limit BO list entry count to prevent resource exhaustion
commit 6270b1a upstream. Userspace can pass an arbitrary number of BO list entries via the bo_number field. Although the previous multiplication overflow check prevents out-of-bounds allocation, a large number of entries could still cause excessive memory allocation (up to potentially gigabytes) and unnecessarily long list processing times. Introduce a hard limit of 128k entries per BO list, which is more than sufficient for any realistic use case (e.g., a single list containing all buffers in a large scene). This prevents memory exhaustion attacks and ensures predictable performance. Return -EINVAL if the requested entry count exceeds the limit Reviewed-by: Christian König <christian.koenig@amd.com> Suggested-by: Christian König <christian.koenig@amd.com> Signed-off-by: Jesse Zhang <jesse.zhang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 688b87d39e0aa8135105b40dc167d74b5ada5332) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 73908f6 commit 5ce4a38

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#define AMDGPU_BO_LIST_MAX_PRIORITY 32u
3838
#define AMDGPU_BO_LIST_NUM_BUCKETS (AMDGPU_BO_LIST_MAX_PRIORITY + 1)
39+
#define AMDGPU_BO_LIST_MAX_ENTRIES (128 * 1024)
3940

4041
static void amdgpu_bo_list_free_rcu(struct rcu_head *rcu)
4142
{
@@ -190,6 +191,9 @@ int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
190191
const uint32_t bo_number = in->bo_number;
191192
struct drm_amdgpu_bo_list_entry *info;
192193

194+
if (bo_number > AMDGPU_BO_LIST_MAX_ENTRIES)
195+
return -EINVAL;
196+
193197
/* copy the handle array from userspace to a kernel buffer */
194198
if (likely(info_size == bo_info_size)) {
195199
info = vmemdup_array_user(uptr, bo_number, info_size);

0 commit comments

Comments
 (0)