diff options
| author | Fei Yu <fei.yu@intel.com> | 2026-11-09 09:48:52 +0800 |
|---|---|---|
| committer | Christian König <christian.koenig@amd.com> | 2026-11-16 16:26:50 +0100 |
| commit | 6ca87397aeebcfae3057653c3e7c008ccb0bb926 (patch) | |
| tree | a6d8845e8b1cd15410ee945d2f5b81fafb958fb7 /rust/kernel/alloc | |
| parent | b4d01c788bfa50dc65ffb5fbc9db4135004c0e01 (diff) | |
drm/syncobj: Limit the number of handles and use kvmalloc for user-sized arrays
The syncobj ioctls allocate several temporary arrays whose size is taken
directly from the u32 count_handles provided by userspace:
- handles and syncobjs in drm_syncobj_array_find()
- points and entries in drm_syncobj_array_wait_timeout()
- points and chains in drm_syncobj_timeline_signal_ioctl()
These are kmalloc() allocations, so a count above KMALLOC_MAX_SIZE /
element size trips the WARN_ON_ONCE_GFP() in ___kmalloc_large_node():
WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0x10c/0x170 mm/slub.c:5459
Call Trace:
__kmalloc_large_node_noprof+0x18/0x90 mm/slub.c:5502
__do_kmalloc_node mm/slub.c:5519 [inline]
__kmalloc_noprof+0x3f6/0x710 mm/slub.c:5556
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kmalloc_array_noprof include/linux/slab.h:1211 [inline]
drm_syncobj_array_find+0x3a/0x440 drivers/gpu/drm/drm_syncobj.c:1241
drm_syncobj_timeline_wait_ioctl+0x18a/0x640 drivers/gpu/drm/drm_syncobj.c:1356
drm_ioctl_kernel+0x2df/0x3b0 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x70e/0xba0 drivers/gpu/drm/drm_ioctl.c:914
The wait entries are 64 bytes each on 64-bit, so with a 4 MiB
KMALLOC_MAX_SIZE a wait on more than about 64K handles already fails
today, with a warning.
Fix this in two parts:
- Reject more than DRM_SYNCOBJ_MAX_HANDLES (1M) handles with -EINVAL in
drm_syncobj_array_find(), which every ioctl taking a handle array goes
through. The limit is a fixed number, so it is the same on all
architectures. It is above what these ioctls can handle today: with a
4 MiB KMALLOC_MAX_SIZE the 8-byte arrays already fail above 512K
handles on 64-bit, so no request that succeeds now is rejected. A
static_assert() makes sure that the largest per-handle allocation, the
wait entries, stays below the INT_MAX size limit of kvmalloc().
- Switch the six allocations to kvmalloc(), so that handle counts up to
the limit (64 MiB of wait entries for 1M handles) no longer depend on
physically contiguous memory.
Using kvmalloc() alone is not enough: the reproducer asks for more than
INT_MAX bytes, which hits the WARN_ON_ONCE() in __kvmalloc_node_noprof()
instead.
Fixes: 3e6fb72d6cef ("drm/syncobj: Add a syncobj_array_find helper")
Reported-by: syzbot+95416f957d84e858b377@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=95416f957d84e858b377
Suggested-by: Christian König <christian.koenig@amd.com>
Cc: stable@vger.kernel.org
Signed-off-by: Fei Yu <fei.yu@intel.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
Link: https://lore.kernel.org/r/20261109014852.2127723-1-fei.yu@intel.com
Diffstat (limited to 'rust/kernel/alloc')
0 files changed, 0 insertions, 0 deletions
