* [PATCH v2 0/2] Limit num_syncs to prevent oversized allocations @ 2025-12-05 22:48 Shuicheng Lin 2025-12-05 22:48 ` [PATCH v2 1/2] drm/xe: " Shuicheng Lin 2025-12-05 22:48 ` [PATCH v2 2/2] drm/xe/oa: " Shuicheng Lin 0 siblings, 2 replies; 4+ messages in thread From: Shuicheng Lin @ 2025-12-05 22:48 UTC (permalink / raw) To: intel-xe; +Cc: Shuicheng Lin Limit num_syncs to prevent oversized allocations Shuicheng Lin (2): drm/xe: Limit num_syncs to prevent oversized allocations drm/xe/oa: Limit num_syncs to prevent oversized allocations drivers/gpu/drm/xe/xe_exec.c | 5 +++++ drivers/gpu/drm/xe/xe_oa.c | 3 +++ drivers/gpu/drm/xe/xe_vm.c | 3 +++ include/uapi/drm/xe_drm.h | 1 + 4 files changed, 12 insertions(+) -- 2.50.1 ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] drm/xe: Limit num_syncs to prevent oversized allocations 2025-12-05 22:48 [PATCH v2 0/2] Limit num_syncs to prevent oversized allocations Shuicheng Lin @ 2025-12-05 22:48 ` Shuicheng Lin 2025-12-05 23:12 ` Matthew Brost 2025-12-05 22:48 ` [PATCH v2 2/2] drm/xe/oa: " Shuicheng Lin 1 sibling, 1 reply; 4+ messages in thread From: Shuicheng Lin @ 2025-12-05 22:48 UTC (permalink / raw) To: intel-xe Cc: Shuicheng Lin, Koen Koning, Peter Senna Tschudin, stable, Matthew Brost, Michal Mrozek, Carl Zhang, José Roberto de Souza, Lionel Landwerlin, Ivan Briano, Thomas Hellström, Ashutosh Dixit The exec and vm_bind ioctl allow userspace to specify an arbitrary num_syncs value. Without bounds checking, a very large num_syncs can force an excessively large allocation, leading to kernel warnings from the page allocator as below. Introduce DRM_XE_MAX_SYNCS (set to 1024) and reject any request exceeding this limit. " ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1217 at mm/page_alloc.c:5124 __alloc_frozen_pages_noprof+0x2f8/0x2180 mm/page_alloc.c:5124 ... Call Trace: <TASK> alloc_pages_mpol+0xe4/0x330 mm/mempolicy.c:2416 ___kmalloc_large_node+0xd8/0x110 mm/slub.c:4317 __kmalloc_large_node_noprof+0x18/0xe0 mm/slub.c:4348 __do_kmalloc_node mm/slub.c:4364 [inline] __kmalloc_noprof+0x3d4/0x4b0 mm/slub.c:4388 kmalloc_noprof include/linux/slab.h:909 [inline] kmalloc_array_noprof include/linux/slab.h:948 [inline] xe_exec_ioctl+0xa47/0x1e70 drivers/gpu/drm/xe/xe_exec.c:158 drm_ioctl_kernel+0x1f1/0x3e0 drivers/gpu/drm/drm_ioctl.c:797 drm_ioctl+0x5e7/0xc50 drivers/gpu/drm/drm_ioctl.c:894 xe_drm_ioctl+0x10b/0x170 drivers/gpu/drm/xe/xe_device.c:224 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:598 [inline] __se_sys_ioctl fs/ioctl.c:584 [inline] __x64_sys_ioctl+0x18b/0x210 fs/ioctl.c:584 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xbb/0x380 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f ... " v2: Add "Reported-by" and Cc stable kernels. v3: Change XE_MAX_SYNCS from 64 to 1024. (Matt & Ashutosh) v4: s/XE_MAX_SYNCS/DRM_XE_MAX_SYNCS/ (Matt) Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs") Reported-by: Koen Koning <koen.koning@intel.com> Reported-by: Peter Senna Tschudin <peter.senna@linux.intel.com> Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/6450 Cc: <stable@vger.kernel.org> # v6.12+ Cc: Matthew Brost <matthew.brost@intel.com> Cc: Michal Mrozek <michal.mrozek@intel.com> Cc: Carl Zhang <carl.zhang@intel.com> Cc: José Roberto de Souza <jose.souza@intel.com> Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Cc: Ivan Briano <ivan.briano@intel.com> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com> Cc: Ashutosh Dixit <ashutosh.dixit@intel.com> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com> --- drivers/gpu/drm/xe/xe_exec.c | 5 +++++ drivers/gpu/drm/xe/xe_vm.c | 3 +++ include/uapi/drm/xe_drm.h | 1 + 3 files changed, 9 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c index 4d81210e41f5..0356d40ee8e4 100644 --- a/drivers/gpu/drm/xe/xe_exec.c +++ b/drivers/gpu/drm/xe/xe_exec.c @@ -162,6 +162,11 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file) } if (args->num_syncs) { + if (XE_IOCTL_DBG(xe, args->num_syncs > DRM_XE_MAX_SYNCS)) { + err = -EINVAL; + goto err_exec_queue; + } + syncs = kcalloc(args->num_syncs, sizeof(*syncs), GFP_KERNEL); if (!syncs) { err = -ENOMEM; diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c index c2012d20faa6..24eced1d970c 100644 --- a/drivers/gpu/drm/xe/xe_vm.c +++ b/drivers/gpu/drm/xe/xe_vm.c @@ -3341,6 +3341,9 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe, struct xe_vm *vm, if (XE_IOCTL_DBG(xe, args->extensions)) return -EINVAL; + if (XE_IOCTL_DBG(xe, args->num_syncs > DRM_XE_MAX_SYNCS)) + return -EINVAL; + if (args->num_binds > 1) { u64 __user *bind_user = u64_to_user_ptr(args->vector_of_binds); diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h index 876a076fa6c0..f7f3573b8d6f 100644 --- a/include/uapi/drm/xe_drm.h +++ b/include/uapi/drm/xe_drm.h @@ -1484,6 +1484,7 @@ struct drm_xe_exec { /** @exec_queue_id: Exec queue ID for the batch buffer */ __u32 exec_queue_id; +#define DRM_XE_MAX_SYNCS 1024 /** @num_syncs: Amount of struct drm_xe_sync in array. */ __u32 num_syncs; -- 2.50.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] drm/xe: Limit num_syncs to prevent oversized allocations 2025-12-05 22:48 ` [PATCH v2 1/2] drm/xe: " Shuicheng Lin @ 2025-12-05 23:12 ` Matthew Brost 0 siblings, 0 replies; 4+ messages in thread From: Matthew Brost @ 2025-12-05 23:12 UTC (permalink / raw) To: Shuicheng Lin Cc: intel-xe, Koen Koning, Peter Senna Tschudin, stable, Michal Mrozek, Carl Zhang, José Roberto de Souza, Lionel Landwerlin, Ivan Briano, Thomas Hellström, Ashutosh Dixit On Fri, Dec 05, 2025 at 10:48:10PM +0000, Shuicheng Lin wrote: > The exec and vm_bind ioctl allow userspace to specify an arbitrary > num_syncs value. Without bounds checking, a very large num_syncs > can force an excessively large allocation, leading to kernel warnings > from the page allocator as below. > > Introduce DRM_XE_MAX_SYNCS (set to 1024) and reject any request > exceeding this limit. > > " > ------------[ cut here ]------------ > WARNING: CPU: 0 PID: 1217 at mm/page_alloc.c:5124 __alloc_frozen_pages_noprof+0x2f8/0x2180 mm/page_alloc.c:5124 > ... > Call Trace: > <TASK> > alloc_pages_mpol+0xe4/0x330 mm/mempolicy.c:2416 > ___kmalloc_large_node+0xd8/0x110 mm/slub.c:4317 > __kmalloc_large_node_noprof+0x18/0xe0 mm/slub.c:4348 > __do_kmalloc_node mm/slub.c:4364 [inline] > __kmalloc_noprof+0x3d4/0x4b0 mm/slub.c:4388 > kmalloc_noprof include/linux/slab.h:909 [inline] > kmalloc_array_noprof include/linux/slab.h:948 [inline] > xe_exec_ioctl+0xa47/0x1e70 drivers/gpu/drm/xe/xe_exec.c:158 > drm_ioctl_kernel+0x1f1/0x3e0 drivers/gpu/drm/drm_ioctl.c:797 > drm_ioctl+0x5e7/0xc50 drivers/gpu/drm/drm_ioctl.c:894 > xe_drm_ioctl+0x10b/0x170 drivers/gpu/drm/xe/xe_device.c:224 > vfs_ioctl fs/ioctl.c:51 [inline] > __do_sys_ioctl fs/ioctl.c:598 [inline] > __se_sys_ioctl fs/ioctl.c:584 [inline] > __x64_sys_ioctl+0x18b/0x210 fs/ioctl.c:584 > do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] > do_syscall_64+0xbb/0x380 arch/x86/entry/syscall_64.c:94 > entry_SYSCALL_64_after_hwframe+0x77/0x7f > ... > " > > v2: Add "Reported-by" and Cc stable kernels. > v3: Change XE_MAX_SYNCS from 64 to 1024. (Matt & Ashutosh) > v4: s/XE_MAX_SYNCS/DRM_XE_MAX_SYNCS/ (Matt) > > Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs") > Reported-by: Koen Koning <koen.koning@intel.com> > Reported-by: Peter Senna Tschudin <peter.senna@linux.intel.com> > Closes: https://gitlab.freedesktop.org/drm/xe/kernel/-/issues/6450 > Cc: <stable@vger.kernel.org> # v6.12+ > Cc: Matthew Brost <matthew.brost@intel.com> > Cc: Michal Mrozek <michal.mrozek@intel.com> > Cc: Carl Zhang <carl.zhang@intel.com> > Cc: José Roberto de Souza <jose.souza@intel.com> > Cc: Lionel Landwerlin <lionel.g.landwerlin@intel.com> > Cc: Ivan Briano <ivan.briano@intel.com> > Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com> > Cc: Ashutosh Dixit <ashutosh.dixit@intel.com> > Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com> > --- > drivers/gpu/drm/xe/xe_exec.c | 5 +++++ > drivers/gpu/drm/xe/xe_vm.c | 3 +++ > include/uapi/drm/xe_drm.h | 1 + > 3 files changed, 9 insertions(+) > > diff --git a/drivers/gpu/drm/xe/xe_exec.c b/drivers/gpu/drm/xe/xe_exec.c > index 4d81210e41f5..0356d40ee8e4 100644 > --- a/drivers/gpu/drm/xe/xe_exec.c > +++ b/drivers/gpu/drm/xe/xe_exec.c > @@ -162,6 +162,11 @@ int xe_exec_ioctl(struct drm_device *dev, void *data, struct drm_file *file) > } > > if (args->num_syncs) { > + if (XE_IOCTL_DBG(xe, args->num_syncs > DRM_XE_MAX_SYNCS)) { I'd put this check at the top of function before looking the exec queue. Matt > + err = -EINVAL; > + goto err_exec_queue; > + } > + > syncs = kcalloc(args->num_syncs, sizeof(*syncs), GFP_KERNEL); > if (!syncs) { > err = -ENOMEM; > diff --git a/drivers/gpu/drm/xe/xe_vm.c b/drivers/gpu/drm/xe/xe_vm.c > index c2012d20faa6..24eced1d970c 100644 > --- a/drivers/gpu/drm/xe/xe_vm.c > +++ b/drivers/gpu/drm/xe/xe_vm.c > @@ -3341,6 +3341,9 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe, struct xe_vm *vm, > if (XE_IOCTL_DBG(xe, args->extensions)) > return -EINVAL; > > + if (XE_IOCTL_DBG(xe, args->num_syncs > DRM_XE_MAX_SYNCS)) > + return -EINVAL; > + > if (args->num_binds > 1) { > u64 __user *bind_user = > u64_to_user_ptr(args->vector_of_binds); > diff --git a/include/uapi/drm/xe_drm.h b/include/uapi/drm/xe_drm.h > index 876a076fa6c0..f7f3573b8d6f 100644 > --- a/include/uapi/drm/xe_drm.h > +++ b/include/uapi/drm/xe_drm.h > @@ -1484,6 +1484,7 @@ struct drm_xe_exec { > /** @exec_queue_id: Exec queue ID for the batch buffer */ > __u32 exec_queue_id; > > +#define DRM_XE_MAX_SYNCS 1024 > /** @num_syncs: Amount of struct drm_xe_sync in array. */ > __u32 num_syncs; > > -- > 2.50.1 > ^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] drm/xe/oa: Limit num_syncs to prevent oversized allocations 2025-12-05 22:48 [PATCH v2 0/2] Limit num_syncs to prevent oversized allocations Shuicheng Lin 2025-12-05 22:48 ` [PATCH v2 1/2] drm/xe: " Shuicheng Lin @ 2025-12-05 22:48 ` Shuicheng Lin 1 sibling, 0 replies; 4+ messages in thread From: Shuicheng Lin @ 2025-12-05 22:48 UTC (permalink / raw) To: intel-xe; +Cc: Shuicheng Lin, Matthew Brost, Ashutosh Dixit The OA open parameters did not validate num_syncs, allowing userspace to pass arbitrarily large values, potentially leading to excessive allocations. Add check to ensure that num_syncs does not exceed DRM_XE_MAX_SYNCS, returning -EINVAL when the limit is violated. v2: use XE_IOCTL_DBG() and drop duplicated check. (Ashutosh) Fixes: c8507a25cebd ("drm/xe/oa/uapi: Define and parse OA sync properties") Cc: Matthew Brost <matthew.brost@intel.com> Cc: Ashutosh Dixit <ashutosh.dixit@intel.com> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com> --- drivers/gpu/drm/xe/xe_oa.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c index cc48663c2b48..92aa25fc0422 100644 --- a/drivers/gpu/drm/xe/xe_oa.c +++ b/drivers/gpu/drm/xe/xe_oa.c @@ -1254,6 +1254,9 @@ static int xe_oa_set_no_preempt(struct xe_oa *oa, u64 value, static int xe_oa_set_prop_num_syncs(struct xe_oa *oa, u64 value, struct xe_oa_open_param *param) { + if (XE_IOCTL_DBG(oa->xe, value > DRM_XE_MAX_SYNCS)) + return -EINVAL; + param->num_syncs = value; return 0; } -- 2.50.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-05 23:12 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-12-05 22:48 [PATCH v2 0/2] Limit num_syncs to prevent oversized allocations Shuicheng Lin 2025-12-05 22:48 ` [PATCH v2 1/2] drm/xe: " Shuicheng Lin 2025-12-05 23:12 ` Matthew Brost 2025-12-05 22:48 ` [PATCH v2 2/2] drm/xe/oa: " Shuicheng Lin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox