drm/xe: Add bounds check for num_binds to prevent memory exhaustion
Subsystems (4)
PATCH v4 1/1 drm/xe: Add bounds check for num_binds to prevent memory exhaustion
The xe_vm_bind_ioctl function accepts user-controlled num_binds without any bounds checking. This follows the same pattern that was fixed for num_syncs in commit 8e461304009d ("drm/xe: Limit num_syncs to prevent huge allocations").
While the main allocations (bind_ops, bos, ops arrays) use __GFP_ACCOUNT, vm_bind_ioctl_ops_create makes additional allocations in a loop that don't:
- drm_gpuva_ops (16 bytes) at drm_gpuvm.c:2949
- xe_vma_op (144 bytes) at xe_vm.c:1318
Both use kzalloc_obj() which defaults to GFP_KERNEL without __GFP_ACCOUNT.
For 268M binds, the loop runs 268M times, allocating 160 bytes per iteration. That's about 43 GB allocated without cgroup accounting before the code even hits the main allocation (which will fail due to the 4MB kmalloc limit).
Add DRM_XE_MAX_BINDS (65536) limit, checked before any allocations happen. At 65536 binds, we're allocating ~10MB in the loop, which is reasonable and won't force unnecessary fallbacks in userspace.
Return -ENOBUFS instead of -EINVAL so Mesa can retry with smaller batches if needed.
v4: Increased limit to 65536 (64k) per maintainer feedback, changed error
to -ENOBUFS for graceful retry
v3: Changed to -ENOBUFS, moved check earlier, added allocation analysis
v2: Increased limit from 1024 to 2048 after Mesa source analysis
--- drivers/gpu/drm/xe/xe_vm.c | 7 +++++++ include/uapi/drm/xe_drm.h | 1 + 2 files changed, 8 insertions(+)
drivers/gpu/drm/xe/xe_vm.c +7 -0
@@ -3840,7 +3840,14 @@ int xe_vm_bind_ioctl(struct drm_device *dev, void *data, struct drm_file *file)if (XE_IOCTL_DBG (xe, !vm))return -EINVAL ; +/* Prevent unbounded allocations in vm_bind_ioctl_ops_create loop */ +if (XE_IOCTL_DBG (xe, args->num_binds >DRM_XE_MAX_BINDS )) { + err = -ENOBUFS ; + goto put_vm; + } + err =vm_bind_ioctl_check_args (xe, vm, args, &bind_ops); +if (err) goto put_vm;
include/uapi/drm/xe_drm.h +1 -0
@@ -1606,6 +1606,7 @@ struct drm_xe_exec {__u32 exec_queue_id;#define DRM_XE_MAX_SYNCS 1024 +#define DRM_XE_MAX_BINDS 65536/** @num_syncs: Amount of struct drm_xe_sync in array. */ __u32 num_syncs;
Signature · 1 line
2.43.0
Patchwork
CI✗ LGCI.VerificationFailed: failure for drm/xe: Add bounds check for num_binds to prevent memory exhaustion (rev3)
== Series Details ==
== Series Details ==
Series: drm/xe: Add bounds check for num_binds to prevent memory exhaustion (rev3)
URL : https://patchwork.freedesktop.org/series/166134/
State : failure
== Summary ==
Address '[email protected]' is not on the allowlist, which prevents CI from being triggered for this patch. If you want Intel GFX CI to accept this address, please contact the script maintainers at [email protected]. Exception occurred during validation, bailing out!