| 0/0 |
2026/10/13 20:55 |
flow |
patching |
3h44m
Results: map[AckedBy:[] Fixes:map[AuthorEmail:keithp@keithp.com AuthorName:Keith Packard Hash:62884cd386b876638720ef88374b31a84ca7ee5f Title:drm: Add four ioctls for managing drm mode object leases [v7]] KernelBranch:master KernelCommit:24a19b953e2a3d0ea5a8c4951a0ab8f32720c907 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git PatchDescription:drm/lease: Use kvmalloc and bound object_count in create lease ioctl
In drm_mode_create_lease_ioctl(), user space supplies an object_count and
an array of object_ids to be leased. The kernel copies the IDs from user
space using memdup_array_user(), and then fill_object_idr() allocates a
temporary array of pointers using kzalloc_objs(struct drm_mode_object *,
object_count).
Because kzalloc_objs() performs a kmalloc-family allocation with GFP_KERNEL
(which lacks __GFP_NOWARN), if user space requests a sufficiently large
object_count (for example, 1,000,000 mode objects), the allocation for the
pointer array (1,000,000 * 8 = 8,000,000 bytes on 64-bit systems) requires
order 11 pages. This exceeds MAX_PAGE_ORDER and triggers a warning in the
page allocator:
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340
[inline]
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640
mm/page_alloc.c:5397
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline]
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
Furthermore, cl->object_count is an unbounded __u32, whereas
fill_object_idr() and validate_lease() treat object_count as a signed
integer. A value of cl->object_count greater than or equal to 2^31 results
in signed integer overflow. In addition, an allocation size exceeding
INT_MAX would trigger a WARN_ON_ONCE inside __kvmalloc_node_noprof().
Fix these issues by validating cl->object_count early in
drm_mode_create_lease_ioctl() so that requests with cl->object_count >
INT_MAX / sizeof(struct drm_mode_object *) are rejected with -EINVAL.
Additionally, switch the object_ids allocation to vmemdup_array_user() and
the objects pointer array allocation to kvzalloc_objs(), freeing both with
kvfree(), so that large allocations can fall back to vmalloc without
triggering allocator warnings or failing under memory fragmentation. PatchDiff:diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -3,6 +3,9 @@
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
@@ -386,7 +389,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +465,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
@@ -496,6 +499,11 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
@@ -509,8 +517,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
@@ -520,7 +528,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
Recipients:[map[Email:airlied@gmail.com Name:David Airlie To:true] map[Email:dri-devel@lists.freedesktop.org Name: To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:maarten.lankhorst@linux.intel.com Name:Maarten Lankhorst To:true] map[Email:mripard@kernel.org Name:Maxime Ripard To:true] map[Email:simona@ffwll.ch Name:Simona Vetter To:true] map[Email:tzimmermann@suse.de Name:Thomas Zimmermann To:true] map[Email:keithp@keithp.com Name:Keith Packard To:true]] ReportedBy:[] ReviewedBy:[] SuggestedBy:[] TestedBy:[]]
|
| 1/1 |
2026/10/13 20:55 |
action |
base-commit-picker |
0m
Results: map[KernelBranch:master KernelCommit:24a19b953e2a3d0ea5a8c4951a0ab8f32720c907 KernelRepo:git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git]
|
| 2/1 |
2026/10/13 20:55 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_ioctl
#define __NR_ioctl 29
#endif
#ifndef __NR_mmap
#define __NR_mmap 222
#endif
static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
if (a0 == 0xc || a0 == 0xb) {
char buf[128];
sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2);
return open(buf, O_RDWR, 0);
} else {
unsigned long nb = a1;
char buf[1024];
char* hash;
strncpy(buf, (char*)a0, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(nb % 10);
nb /= 10;
}
return open(buf, a2 & ~O_CREAT, 0);
}
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_open_dev$dri arguments: [
// dev: ptr[in, buffer] {
// buffer: {2f 64 65 76 2f 64 72 69 2f 63 61 72 64 23 00} (length 0xf)
// }
// id: intptr = 0x1f (8 bytes)
// flags: open_flags = 0x0 (8 bytes)
// ]
// returns fd_dri
memcpy((void*)0x20000000, "/dev/dri/card#\000", 15);
res = -1;
res = syz_open_dev(/*dev=*/0x20000000, /*id=*/0x1f, /*flags=*/0);
if (res != -1)
r[0] = res;
// ioctl$DRM_IOCTL_MODE_CREATE_LEASE arguments: [
// fd: fd_dri (resource)
// cmd: const = 0xc01864c6 (4 bytes)
// arg: ptr[inout, drm_mode_create_lease] {
// drm_mode_create_lease {
// object_ids: ptr[in, array[drm_obj_id]] {
// array[drm_obj_id] {
// drm_obj_id (resource)
// }
// }
// object_count: len = 0xf4240 (4 bytes)
// flags: drm_mode_create_lease_flag = 0x0 (4 bytes)
// lessee_id: drm_lessee_id (resource)
// fd: fd (resource)
// }
// }
// ]
*(uint64_t*)0x200003c0 = 0x20000280;
*(uint32_t*)0x20000280 = 0;
*(uint32_t*)0x200003c8 = 0xf4240;
*(uint32_t*)0x200003cc = 0;
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc01864c6, /*arg=*/0x200003c0ul);
return 0;
}
]
|
| 3/1 |
2026/10/13 20:55 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/b40b16009ab47f464bda3fd2225415bcd6bb334b]
|
| 4/1 |
2026/10/13 20:55 |
action |
kernel-builder |
45m
Results: map[KernelObj:/app/workdir/cache/build/0fe9a23712023dd69a64fd3143b6d5c65ff16a57]
|
| 5/1 |
2026/10/13 21:41 |
action |
crash-reproducer |
6m
Results: map[OtherCrashReports:<nil> ReproducedBugTitle:WARNING in alloc_frozen_pages_noprof ReproducedCrashReport:------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
ReproducedFaultInjection:]
|
| 6/1 |
2026/10/13 21:47 |
action |
codesearch-prepare |
19m
Results: map[Index:codesearch-index]
|
| 7/1 |
2026/10/13 22:06 |
agent |
debugger |
25m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with debugging a kernel crash root cause.
You need to provide a detailed explanation of the root cause for another developer to be
able to write a fix for the bug based on your explanation. Include all relevant details
into the response: function/struct/field/etc names, code snippets, line numbers,
macro/enum values, etc.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
The following C code is a draft of the vulnerable syscall sequence. Keep in mind that
it may lack the precise threading, sandboxing, and some arguments of a working reproducer:
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_ioctl
#define __NR_ioctl 29
#endif
#ifndef __NR_mmap
#define __NR_mmap 222
#endif
static long syz_open_dev(volatile long a0, volatile long a1, volatile long a2)
{
if (a0 == 0xc || a0 == 0xb) {
char buf[128];
sprintf(buf, "/dev/%s/%d:%d", a0 == 0xc ? "char" : "block", (uint8_t)a1, (uint8_t)a2);
return open(buf, O_RDWR, 0);
} else {
unsigned long nb = a1;
char buf[1024];
char* hash;
strncpy(buf, (char*)a0, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = 0;
while ((hash = strchr(buf, '#'))) {
*hash = '0' + (char)(nb % 10);
nb /= 10;
}
return open(buf, a2 & ~O_CREAT, 0);
}
}
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// syz_open_dev$dri arguments: [
// dev: ptr[in, buffer] {
// buffer: {2f 64 65 76 2f 64 72 69 2f 63 61 72 64 23 00} (length 0xf)
// }
// id: intptr = 0x1f (8 bytes)
// flags: open_flags = 0x0 (8 bytes)
// ]
// returns fd_dri
memcpy((void*)0x20000000, "/dev/dri/card#\000", 15);
res = -1;
res = syz_open_dev(/*dev=*/0x20000000, /*id=*/0x1f, /*flags=*/0);
if (res != -1)
r[0] = res;
// ioctl$DRM_IOCTL_MODE_CREATE_LEASE arguments: [
// fd: fd_dri (resource)
// cmd: const = 0xc01864c6 (4 bytes)
// arg: ptr[inout, drm_mode_create_lease] {
// drm_mode_create_lease {
// object_ids: ptr[in, array[drm_obj_id]] {
// array[drm_obj_id] {
// drm_obj_id (resource)
// }
// }
// object_count: len = 0xf4240 (4 bytes)
// flags: drm_mode_create_lease_flag = 0x0 (4 bytes)
// lessee_id: drm_lessee_id (resource)
// fd: fd (resource)
// }
// }
// ]
*(uint64_t*)0x200003c0 = 0x20000280;
*(uint32_t*)0x20000280 = 0;
*(uint32_t*)0x200003c8 = 0xf4240;
*(uint32_t*)0x200003cc = 0;
syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc01864c6, /*arg=*/0x200003c0ul);
return 0;
}
Reply: An analysis of the crash reveals that it is caused by an unbounded user-controlled allocation size in the DRM lease creation ioctl, which attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` using the `kmalloc` family of functions.
### Root Cause Analysis
The crash is a warning triggered in `alloc_order_allowed()` because `__alloc_frozen_pages_noprof()` is called with an allocation order that exceeds `MAX_PAGE_ORDER` (typically 10, which corresponds to 4MB on systems with 4KB pages).
This happens in `fill_object_idr()` when allocating the `objects` array:
```c
// drivers/gpu/drm/drm_lease.c:389
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
The `kzalloc_objs` macro expands to a `kmalloc`-family allocation (equivalent to `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`).
The `object_count` comes directly from the user-space `drm_mode_create_lease` struct via `cl->object_count` in `drm_mode_create_lease_ioctl()`. There is no upper bound check on this value.
Before calling `fill_object_idr()`, `drm_mode_create_lease_ioctl()` allocates the `object_ids` array using `memdup_array_user()`:
```c
// drivers/gpu/drm/drm_lease.c:512
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user()` uses `memdup_user()`, which allocates memory with `GFP_USER | __GFP_NOWARN`. Because of the `__GFP_NOWARN` flag, if `object_count` is extremely large (e.g., requiring > 4MB), `memdup_array_user()` will silently fail and return `-ENOMEM` without triggering any warnings.
However, there is a specific window where `object_count` is large enough to require more than 4MB for the `objects` array (which has 8-byte pointers on 64-bit systems), but small enough that the `object_ids` array (which has 4-byte `__u32` elements) fits within 4MB.
In the provided syzkaller reproducer:
```c
*(uint32_t*)0x200003c8 = 0xf4240; // object_count = 1,000,000
```
1. `object_count` is set to `1,000,000`.
2. `memdup_array_user()` allocates `1,000,000 * 4 = 4,000,000` bytes. This is order 10, which is `<= MAX_PAGE_ORDER`. The allocation succeeds.
3. `fill_object_idr()` then calls `kzalloc_objs()` to allocate `1,000,000 * 8 = 8,000,000` bytes. This requires order 11, which is `> MAX_PAGE_ORDER`.
4. Since `kzalloc_objs()` uses `GFP_KERNEL` without `__GFP_NOWARN`, the page allocator loudly complains and triggers the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` warning.
### Proposed Fix
To fix this, the allocation of the `objects` array in `fill_object_idr()` should be changed to use `kvzalloc_objs()`, which gracefully falls back to `vmalloc()` for large allocations and does not trigger the page allocator warning. The corresponding `kfree()` must also be updated to `kvfree()`.
```c
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,7 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +462,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
```
*(Note: While adding an arbitrary upper bound check to `object_count` in `drm_mode_create_lease_ioctl()` is another option, using `kvzalloc_objs()` is the standard kernel pattern for handling user-controlled array sizes without imposing artificial limits).*
|
| 8/2 |
2026/10/13 22:06 |
llm |
debugger |
0m
Model:
Tokens:
input: 7505
output: 41
thoughts: 503
Thoughts: **Analyzing a Kernel Crash During Lease Creation**
Okay, so I've got a crash, and the kernel's telling me it's happening during memory allocation β specifically, a warning at `mm/page_alloc.c:5340`. The crucial thing here is the stack trace. I see `alloc_order_allowed` and `__alloc_frozen_pages_noprof` at the top, which immediately points me towards memory management issues related to a specific allocation order and frozen pages. This suggests we're running into limits or contention within the page allocator, possibly when the system is under memory pressure or during a critical allocation phase. It looks like CPU#1, running a syzbot process (likely a fuzzer), triggered this.
The stack unwinds through `alloc_pages_mpol`, indicating memory policy is also involved. The use of `__kmalloc_large_node`, followed by `fill_object_idr`, confirms that this is kmalloc, and specifically indicates a large allocation. Now, since this leads to `drm_mode_create_lease_ioctl`, the core of the problem *likely* lies within the Direct Rendering Manager (DRM) lease creation path. It looks like we're calling `drm_mode_create_lease_ioctl` and that function is calling `fill_object_idr`.
My instinct is to dive into `drivers/gpu/drm/drm_lease.c`, specifically the `fill_object_idr` function, and see how memory is being allocated there. It's likely we're requesting a large allocation that isn't feasible, or there's a leak or a contention issue within the lease mechanism itself. The combination of large kmalloc, the freeze path, and the DRM context, points me to DRM lease creation as the root of the issue. I'll probably look at what object is being passed to the `fill_object_idr` function.
|
| 9/2 |
2026/10/13 22:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:fill_object_idr]
Results: map[SourceCode: 378: static int fill_object_idr(struct drm_device *dev,
379: struct drm_file *lessor_priv,
380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 10/2 |
2026/10/13 22:07 |
llm |
debugger |
0m
Model:
Tokens:
input: 9962
output: 20
thoughts: 69
Thoughts: Here's my summary, as if I were thinking it:
**Digging into the Memory Allocation**
Okay, the crash is happening right at `kzalloc_objs(struct drm_mode_object *, object_count);`. That's a red flag β clearly a memory allocation issue. Now, `kzalloc_objs` is almost certainly a macro, so I need to see what it expands to. My guess is it's using something like `kcalloc` or `kzalloc_array`, or a wrapper around `kzalloc`. I need to inspect the definition of `kzalloc_objs` to confirm my suspicion and understand *exactly* how the memory is being requested and initialized. This is the starting point to understand this allocation's role and potential problems.
|
| 11/2 |
2026/10/13 22:08 |
tool |
grepper |
0m
Args: map[Expression:#define kzalloc_objs]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1156- __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1157:#define kzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1158- __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
]
|
| 12/2 |
2026/10/13 22:08 |
llm |
debugger |
0m
Model:
Tokens:
input: 10372
output: 44
thoughts: 16
Thoughts: Okay, here's my summary, taking the perspective of someone deeply familiar with kernel development, specifically the DRM subsystem:
**Diving into `drm_mode_create_lease_ioctl`**
Alright, let's get into the weeds with `drm_mode_create_lease_ioctl`. I need to really dig into this one, understand its purpose, and ensure it's functioning as expected, and ideally that it is as efficient as possible. This is a critical interface, so the details here *matter*. I'm thinking about the implications for resource allocation, concurrency, and security. What are the key data structures involved? What's the flow of execution? I'm already mentally tracing the call stack, thinking about how this fits into the larger framework of KMS and the interaction between the kernel and userspace. Is this ioctl properly handling error conditions? Are there any potential race conditions I need to be aware of? I'll probably need to consult the relevant documentation, the code itself, and maybe even some existing test cases. I'll need to think about performance, memory usage, and all the edge cases. I'll also be considering how it interacts with the underlying hardware, and how it is all linked into the DRM. I can already see some spots where improvements could be made. I'm going to start reading.
|
| 13/2 |
2026/10/13 22:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_create_lease_ioctl]
Results: map[SourceCode: 469: /*
470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
475: int drm_mode_create_lease_ioctl(struct drm_device *dev,
476: void *data, struct drm_file *lessor_priv)
477: {
478: struct drm_mode_create_lease *cl = data;
479: size_t object_count;
480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
540: /* lessee will take the ownership of leases */
541: lessee = drm_lease_create(lessor, &leases);
542:
543: if (IS_ERR(lessee)) {
544: ret = PTR_ERR(lessee);
545: idr_destroy(&leases);
546: goto out_leases;
547: }
548:
549: /* Clone the lessor file to create a new file for us */
550: drm_dbg_lease(dev, "Allocating lease file\n");
551: lessee_file = file_clone_open(lessor_file);
552: if (IS_ERR(lessee_file)) {
553: ret = PTR_ERR(lessee_file);
554: goto out_lessee;
555: }
556:
557: lessee_priv = lessee_file->private_data;
558: /* Change the file to a master one */
559: drm_master_put(&lessee_priv->master);
560: lessee_priv->master = lessee;
561: lessee_priv->is_master = 1;
562: lessee_priv->authenticated = 1;
563:
564: /* Pass fd back to userspace */
565: drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
566: cl->fd = fd;
567: cl->lessee_id = lessee->lessee_id;
568:
569: /* Hook up the fd */
570: fd_install(fd, lessee_file);
571:
572: drm_master_put(&lessor);
573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
574: return 0;
575:
576: out_lessee:
577: drm_master_put(&lessee);
578:
579: out_leases:
580: put_unused_fd(fd);
581:
582: out_lessor:
583: drm_master_put(&lessor);
584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
585: return ret;
586: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 14/2 |
2026/10/13 22:09 |
llm |
debugger |
0m
Model:
Tokens:
input: 12531
output: 41
thoughts: 453
Thoughts: **Analyzing the Allocation Failure**
Okay, so I'm looking at this crash log. The kernel's screaming about an allocation failure deep within `mm/page_alloc.c`, specifically at `alloc_order_allowed`. The backtrace points to `__alloc_frozen_pages_noprof` and, tracing back, it's triggered by `kzalloc_objs` in `fill_object_idr`. That `kzalloc_objs` call is the critical point.
The `object_count` for this `kzalloc_objs` call is clearly the culprit. It's coming from `cl->object_count`. And looking at the reproducer, it looks like this is set to 0xf4240, or 1,000,000. So we are calling `kzalloc_objs` with `1000000` as the size.
Doing the math, a call to `kzalloc_objs` with 1,000,000 of the `drm_mode_object` struct (8 bytes) means we are trying to allocate 8,000,000 bytes, or roughly 8MB. Right, that's an order 11 allocation (2048 pages). That's where the problem arises: `alloc_order_allowed` is likely failing because the system's `MAX_PAGE_ORDER` is typically 10 (4MB). Order 11 is exceeding that limit. It makes sense, generally you wouldn't be able to allocate an 8MB contiguous block directly from the page allocator, especially in a system under load.
But wait, I see `memdup_array_user` is used to allocate `object_ids`. Doesn't `memdup_array_user` use `kvmalloc` or something similar for potentially very large allocations? I need to check how `memdup_array_user` is implemented to be sure. That may provide a hint, as perhaps it's not being used consistently for large sizes. I will need to verify this assumption.
|
| 15/2 |
2026/10/13 22:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:memdup_array_user]
Results: map[SourceCode: 22: /**
23: * memdup_array_user - duplicate array from user space
24: * @src: source address in user space
25: * @n: number of array members to copy
26: * @size: size of one array member
27: *
28: * Return: an ERR_PTR() on failure. Result is physically
29: * contiguous, to be freed by kfree().
30: */
31: static inline __realloc_size(2, 3)
32: void *memdup_array_user(const void __user *src, size_t n, size_t size)
33: {
34: size_t nbytes;
35:
36: if (check_mul_overflow(n, size, &nbytes))
37: return ERR_PTR(-EOVERFLOW);
38:
39: return memdup_user(src, nbytes);
40: }
SourceFile:include/linux/string.h]
|
| 16/2 |
2026/10/13 22:09 |
llm |
debugger |
3m
Model:
Tokens:
input: 13770
output: 35
thoughts: 37
Thoughts: Here's my thought process, as if I were considering this code:
**Analyzing `memdup_user` and Memory Allocation**
Okay, hold on a second. I need to be absolutely sure about how `memdup_user` handles memory allocation. It looks like it uses `kmalloc_track_caller`, which could introduce some potential issues. `kmalloc_track_caller` could either fail outright (returning NULL) or, if configured to do so, it might actually fall back to using `kvmalloc` under certain circumstances. That's something I need to verify. My assumption, at this point, is that the code may not perform as expected under heavy system loads. Let me quickly examine the implementation of `memdup_user` to confirm how it's behaving. I need to understand its memory allocation strategy to ensure the code's robustness.
|
| 17/2 |
2026/10/13 22:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:memdup_user]
Results: map[SourceCode: 208: /**
209: * memdup_user - duplicate memory region from user space
210: *
211: * @src: source address in user space
212: * @len: number of bytes to copy
213: *
214: * Return: an ERR_PTR() on failure. Result is physically
215: * contiguous, to be freed by kfree().
216: */
217: void *memdup_user(const void __user *src, size_t len)
218: {
219: void *p;
220:
221: p = kmem_buckets_alloc_track_caller(user_buckets, len, GFP_USER | __GFP_NOWARN);
222: if (!p)
223: return ERR_PTR(-ENOMEM);
224:
225: if (copy_from_user(p, src, len)) {
226: kfree(p);
227: return ERR_PTR(-EFAULT);
228: }
229:
230: return p;
231: }
SourceFile:mm/util.c]
|
| 18/2 |
2026/10/13 22:13 |
llm |
debugger |
2m
Model:
Tokens:
input: 14377
output: 36
thoughts: 610
Thoughts: **Analyzing Memory Allocation in the DRM Driver**
Okay, so I'm looking at this code and immediately I see `memdup_user` uses `__GFP_NOWARN`. That's good, it avoids flooding the logs with warnings if it can't get a big contiguous block, but I need to understand why it might be failing silently. The trace shows a crash *after* `memdup_user` which suggests the `memdup_user` is succeeding.
Then I see `kzalloc_objs` is being used in `fill_object_idr`. That call is concerning because it's using the standard `kcalloc` or `kmalloc_array`, *not* `__GFP_NOWARN`. Looking deeper, `kzalloc_objs` actually expands to `__alloc_objs`, using `default_gfp`. Given the context, that's almost certainly `GFP_KERNEL`. This is where I need to focus. So `kzalloc_objs` called with a large object count is equivalent to allocating an array using `kcalloc`.
Specifically, `kzalloc_objs(struct drm_mode_object *, object_count)` becomes `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`. With an `object_count` of 1,000,000, that means we're trying to allocate 8MB, using `GFP_KERNEL`, which *does* trigger warnings if the allocation size is too large.
Initially, I had a hunch that `memdup_user` was failing and causing the issue, but if it fails it returns `-ENOMEM` which is subsequently handled, so the `memdup_user` must be working. Now, `memdup_user` allocates `object_count * sizeof(__u32)` which is 4MB (1,000,000 * 4). This results in an order 10 allocation which *should* work since `MAX_PAGE_ORDER` is 10. So `memdup_user` either succeeds or fails silently, but if it fails the return is handled.
The crash *has* to be in `kzalloc_objs` then. If `memdup_user` succeeded, that means 4MB allocation worked, and the subsequent call to `fill_object_idr` with a *similar* object count (1,000,000), but allocating *pointers* instead of 4 byte integers, explains the crash. We are now trying to allocate `object_count * sizeof(struct drm_mode_object *)`, which is on a 64-bit system, 8MB, i.e. 1,000,000 * 8 bytes. That's order 11, and that's the problem. Since `MAX_PAGE_ORDER` is 10, the `kzalloc_objs` is generating the warning in `alloc_order_allowed` because we are trying to allocate an order that is too high. Time to double-check `mm/page_alloc.c` to confirm my suspicion.
|
| 19/2 |
2026/10/13 22:15 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/page_alloc.c Name:alloc_order_allowed]
Results: map[SourceCode:5330: static inline bool alloc_order_allowed(gfp_t gfp, unsigned int order,
5331: unsigned int alloc_flags)
5332: {
5333: if (alloc_flags & ALLOC_NOLOCK)
5334: return pcp_allowed_order(order);
5335:
5336: /*
5337: * There are several places where we assume that the order value is sane
5338: * so bail out early if the request is out of bound.
5339: */
5340: return !(WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp));
5341: }
SourceFile:mm/page_alloc.c]
|
| 20/2 |
2026/10/13 22:15 |
llm |
debugger |
1m
Model:
Tokens:
input: 15918
output: 52
thoughts: 558
Thoughts: **Analyzing Potential Memory Allocation Issues in DRM Lease Handling**
Okay, so if the requested `order` exceeds `MAX_PAGE_ORDER`, that's definitely a red flag, triggering a warning. Let's dig deeper into `fill_object_idr`. Specifically, I'm concerned about this section:
```c
objects = kzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
```
It seems like `object_count` comes from user space, and while it's a `size_t` internally, it's derived from a `__u32` (`cl->object_count`) in `drm_mode_create_lease_ioctl`. So, we're theoretically looking at up to 4,294,967,295 objects, but potentially less due to size limitations.
The initial thought was that `memdup_array_user` might fail with `-ENOMEM` (or maybe even `-EOVERFLOW`) if `object_count` is large. However, because it uses `__GFP_NOWARN`, there wouldn't be a warning. The core problem, however, is that if we provide a `object_count` large enough that `memdup_array_user` works, like a 4MB array (order 10), but `kzalloc_objs` needs 8MB (order 11), we hit a potential warning because the `kzalloc_objs` call doesn't use `__GFP_NOWARN` and the allocation is larger than `MAX_PAGE_ORDER`.
Now, wait a minute, `kzalloc_objs` is a macro using `kzalloc`. Shouldn't we be using `kvzalloc` or `kvmalloc_array` for large allocations? Yes, those are standard for this scenario. Thinking about it, the `objects` array here is just a temporary container for `drm_mode_object` pointers. It's allocated, populated, validated, and then freed.
```c
objects = kzalloc_objs(struct drm_mode_object *, object_count);
...
out_free_objects:
for (o = 0; o < object_count; o++) {
if (objects[o])
drm_mode_object_put(objects[o]);
}
kfree(objects);
```
So, yes, absolutely, this array *could* be allocated with `kvmalloc_array` or `kvzalloc` and freed with `kvfree`! Let's just make sure that `kzalloc_objs` is a macro, and take a look at it to be sure.
|
| 21/2 |
2026/10/13 22:16 |
tool |
codesearch-find-references |
0m
Error:
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c IncludeSnippetLines:0 Name:kzalloc_objs SourceTreePrefix:]
Results: map[References:<nil> TruncatedOutput:false]
|
| 22/2 |
2026/10/13 22:16 |
llm |
debugger |
0m
Model:
Tokens:
input: 17139
output: 45
thoughts: 29
Thoughts: Here's my thought process, as requested:
**Investigating the Origins of `kzalloc_objs`**
Okay, so I see `kzalloc_objs` is defined in `include/linux/slab.h`. That's the key. Knowing the header file tells me a lot. Now, my immediate instinct is to figure out *when* this thing was introduced. Understanding the commit history is often crucial for diagnosing potential bugs or understanding the evolution of a particular slab allocator feature. I need to trace this back to its roots. Time to dig into the git logs and see when `kzalloc_objs` first made its appearance. Let's start the hunt for that defining commit.
|
| 23/2 |
2026/10/13 22:17 |
tool |
git-log |
0m
Args: map[CodeRegexp:kzalloc_objs Count:10 SourcePath:include/linux/slab.h SymbolName:]
Results: map[Output:27c0f718d3b3 scsi: ch: Do not keep references to data transfer element devices
17637e1a581a bpf: Skip detached progs in trampoline images that are still in use
59e0cc31cc5c clk: ti: composite: resolve parent clocks by name again
c0aceaf65b70 bnxt_en: Bound SW TPA IDs to prevent crashes
3a2c4d55e32a treewide: refresh kmalloc_obj() conversions
f7f11bdddaba doc:it_IT: align Italian documentation in process
8c59f5c467af scripts: coccinelle: devm_free: reduce false positives
1beb81947eb4 net/sched: account classifier filter allocations to memcg
8fa4804fe62c NFSv4.1: zero referring call lists before decoding
992cc9f94ca9 net/packet: defer vmalloc TX_RING free until skbs finish
]
|
| 24/2 |
2026/10/13 22:17 |
llm |
debugger |
0m
Model:
Tokens:
input: 17613
output: 31
thoughts: 31
Thoughts: Okay, let's dive into this. Here's my take on those commit thoughts:
**Analyzing Commit 3a2c4d55e32a**
Alright, let's take a look at commit `3a2c4d55e32a`. The description says it's a "treewide: refresh kmalloc_obj() conversions". Right away, I'm thinking about the potential scope and impact here. A "treewide" change always raises a flag; it means this isn't isolated, but potentially touches a substantial portion of the codebase. So, the first question is, what specifically *is* being converted? Are we talking about `kmalloc_obj()` calls themselves, the structures/usages surrounding them, or some other associated process? Understanding the "refresh" aspect is key. Is this an effort to update to new kernel API or best practices, perhaps optimizing memory allocation or addressing some past issue related to object management? I'll need to dig into the commit itself to see what's changed and why. I'm looking for the 'before and after' to understand the rationale and verify the correctness of the change. This is critical for assessing the potential for regressions or side effects. Ultimately, I'll need to assess the correctness of this commit as a whole, focusing on how this conversion impacts memory management in the system, and any performance differences this conversion offers, and if any.
|
| 25/2 |
2026/10/13 22:18 |
tool |
git-show |
0m
Args: map[Commit:3a2c4d55e32a Stat:true]
Results: map[Output:commit 3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d
Author: Kees Cook <kees+treewide@kernel.org>
Date: Wed Sep 2 15:31:14 2026 -0700
treewide: refresh kmalloc_obj() conversions
This is another run of the Coccinelle script for converting kmalloc()
family of allocations to kmalloc_obj() via the existing rules in
scripts/coccinelle/api/kmalloc_objs.cocci
This catches both the set of kmalloc() uses added since the first
kmalloc_obj() conversions in v7.0 and adds a large group missed in the
first pass due to Coccinelle not interacting well with the cleanup.h
scoped_...() family of macros[1]. I worked around this with spatch's
"--macro-file" argument to a file with all the scoped_...() macros mapped
to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control
flow indicator I could find.
Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc,
riscv, and s390 with no new warnings.
Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1]
Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2]
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
arch/arm64/crypto/aes-neonbs-glue.c | 4 +-
arch/arm64/kvm/nested.c | 2 +-
arch/loongarch/kvm/intc/dmsintc.c | 2 +-
arch/mips/bcm47xx/buttons.c | 8 ++--
arch/powerpc/sysdev/xive/common.c | 2 +-
arch/riscv/kvm/vcpu_pmu.c | 4 +-
arch/s390/kvm/s390/s390.c | 4 +-
drivers/accel/rocket/rocket_job.c | 2 +-
drivers/acpi/irq.c | 8 ++--
drivers/base/property.c | 2 +-
drivers/block/drbd/drbd_nl_gen.c | 40 +++++++++--------
drivers/block/ublk_drv.c | 4 +-
drivers/block/zram/backend_lz4.c | 2 +-
drivers/clk/ti/composite.c | 2 +-
drivers/clk/ti/mux.c | 2 +-
drivers/cpufreq/amd-pstate.c | 2 +-
drivers/crypto/inside-secure/eip93/eip93-common.c | 5 +--
.../crypto/intel/qat/qat_common/qat_comp_algs.c | 3 +-
drivers/crypto/ti/dthev2-aes.c | 8 ++--
drivers/devfreq/hisi_uncore_freq.c | 2 +-
drivers/dma-buf/st-dma-fence.c | 2 +-
drivers/dma-buf/udmabuf.c | 4 +-
drivers/dma/switchtec_dma.c | 7 ++-
drivers/edac/versalnet_edac.c | 2 +-
drivers/firmware/arm_scmi/driver.c | 2 +-
drivers/firmware/qcom/qcom_tzmem.c | 8 ++--
drivers/firmware/ti_sci.c | 2 +-
drivers/fpga/dfl-afu-dma-region.c | 2 +-
drivers/gpio/gpio-aggregator.c | 4 +-
drivers/gpio/gpio-mpsse.c | 2 +-
drivers/gpio/gpio-sim.c | 3 +-
drivers/gpio/gpio-virtuser.c | 3 +-
drivers/gpio/gpiolib-cdev.c | 2 +-
drivers/gpio/gpiolib.c | 4 +-
drivers/gpu/buddy.c | 13 ++----
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c | 5 +--
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_lockdep.c | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 2 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +--
drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c | 4 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 6 +--
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 6 +--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 12 ++---
.../amdgpu_dm/tests/amdgpu_dm_connector_test.c | 2 +-
.../display/amdgpu_dm/tests/amdgpu_dm_crtc_test.c | 8 ++--
.../display/amdgpu_dm/tests/amdgpu_dm_irq_test.c | 18 ++++----
.../display/amdgpu_dm/tests/amdgpu_dm_plane_test.c | 4 +-
.../amd/display/amdgpu_dm/tests/amdgpu_dm_test.c | 2 +-
drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c | 2 +-
.../amd/display/dc/clk_mgr/dcn60/dcn60_clk_mgr.c | 4 +-
drivers/gpu/drm/amd/display/dc/core/dc.c | 3 +-
drivers/gpu/drm/amd/display/dc/core/dc_surface.c | 2 +-
.../gpu/drm/amd/display/dc/dccg/dcn42/dcn42_dccg.c | 2 +-
.../gpu/drm/amd/display/dc/dccg/dcn60/dcn60_dccg.c | 2 +-
drivers/gpu/drm/amd/display/dc/gpio/hw_ddc.c | 2 +-
.../amd/display/dc/irq/dcn42/irq_service_dcn42.c | 2 +-
.../amd/display/dc/irq/dcn60/irq_service_dcn60.c | 3 +-
.../drm/amd/display/dc/pg/dcn42/dcn42_pg_cntl.c | 2 +-
.../amd/display/dc/resource/dcn30/dcn30_resource.c | 4 +-
.../display/dc/resource/dcn302/dcn302_resource.c | 4 +-
.../display/dc/resource/dcn303/dcn303_resource.c | 4 +-
.../amd/display/dc/resource/dcn31/dcn31_resource.c | 4 +-
.../display/dc/resource/dcn314/dcn314_resource.c | 4 +-
.../display/dc/resource/dcn315/dcn315_resource.c | 4 +-
.../display/dc/resource/dcn316/dcn316_resource.c | 4 +-
.../amd/display/dc/resource/dcn32/dcn32_resource.c | 4 +-
.../display/dc/resource/dcn321/dcn321_resource.c | 4 +-
.../amd/display/dc/resource/dcn35/dcn35_resource.c | 4 +-
.../display/dc/resource/dcn351/dcn351_resource.c | 4 +-
.../amd/display/dc/resource/dcn36/dcn36_resource.c | 4 +-
.../display/dc/resource/dcn401/dcn401_resource.c | 4 +-
.../amd/display/dc/resource/dcn42/dcn42_resource.c | 50 ++++++++++-----------
.../display/dc/resource/dcn42b/dcn42b_resource.c | 46 +++++++++----------
.../amd/display/dc/resource/dcn60/dcn60_resource.c | 42 +++++++++--------
drivers/gpu/drm/amd/display/modules/power/power.c | 5 +--
.../gpu/drm/amd/display/modules/power/power_abm.c | 3 +-
.../gpu/drm/amd/pm/powerplay/hwmgr/smu7_hwmgr.c | 2 +-
.../gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c | 4 +-
drivers/gpu/drm/amd/ras/core/cmd.c | 4 +-
drivers/gpu/drm/drm_exec.c | 2 +-
drivers/gpu/drm/drm_syncobj.c | 2 +-
drivers/gpu/drm/qxl/qxl_display.c | 2 +-
drivers/gpu/drm/tilcdc/tilcdc_panel_legacy.c | 2 +-
drivers/gpu/drm/verisilicon/vs_plane.c | 4 +-
drivers/gpu/drm/virtio/virtgpu_prime.c | 4 +-
drivers/gpu/drm/vkms/vkms_configfs.c | 8 ++--
drivers/gpu/drm/xe/xe_amc.c | 2 +-
drivers/gpu/drm/xe/xe_vm.c | 2 +-
drivers/hid/hid-asus.c | 6 +--
drivers/hid/hid-steam.c | 4 +-
drivers/hid/hid-steelseries-arctis.c | 2 +-
drivers/hv/channel.c | 5 +--
drivers/hv/hv_balloon.c | 2 +-
drivers/hwmon/applesmc.c | 17 ++++---
drivers/hwtracing/coresight/coresight-core.c | 2 +-
drivers/i2c/busses/i2c-gpio.c | 2 +-
drivers/i3c/master/amd-i3c-master.c | 4 +-
drivers/iio/adc/ad7280a.c | 4 +-
drivers/iio/buffer/industrialio-buffer-dmaengine.c | 2 +-
drivers/iio/inkern.c | 2 +-
drivers/infiniband/core/nldev.c | 2 +-
drivers/infiniband/hw/hns/hns_roce_debugfs.c | 3 +-
drivers/input/input.c | 2 +-
drivers/input/keyboard/adp5585-keys.c | 4 +-
drivers/input/keyboard/atkbd.c | 2 +-
drivers/input/misc/ims-pcu.c | 2 +-
drivers/input/mouse/psmouse-smbus.c | 2 +-
drivers/input/serio/serio_raw.c | 2 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +-
drivers/iommu/iommufd/device.c | 2 +-
drivers/iommu/iommufd/driver.c | 2 +-
drivers/iommu/iommufd/hwpt_noiommu.c | 2 +-
drivers/iommu/vsi-iommu.c | 2 +-
drivers/irqchip/irq-gic-v5-irs.c | 2 +-
drivers/irqchip/irq-loongarch-ir.c | 2 +-
drivers/irqchip/irq-realtek-rtl.c | 2 +-
drivers/mailbox/riscv-sbi-mpxy-mbox.c | 2 +-
drivers/md/dm-inlinecrypt.c | 2 +-
drivers/md/md-llbitmap.c | 4 +-
drivers/media/platform/allegro-dvt/allegro-core.c | 2 +-
drivers/media/platform/amd/isp4/isp4_interface.c | 6 +--
drivers/media/platform/renesas/rcar-isp/core.c | 2 +-
drivers/media/rc/igorplugusb.c | 2 +-
drivers/mfd/mfd-core.c | 4 +-
drivers/mfd/ucb1x00-assabet.c | 2 +-
drivers/mtd/mtd_virt_concat.c | 4 +-
drivers/mtd/mtdconcat.c | 2 +-
drivers/net/dsa/mv88e6xxx/tcflower.c | 2 +-
drivers/net/ethernet/alibaba/eea/eea_adminq.c | 7 ++-
drivers/net/ethernet/alibaba/eea/eea_net.c | 8 ++--
drivers/net/ethernet/alibaba/eea/eea_pci.c | 2 +-
drivers/net/ethernet/alibaba/eea/eea_ring.c | 2 +-
drivers/net/ethernet/alibaba/eea/eea_rx.c | 5 +--
drivers/net/ethernet/alibaba/eea/eea_tx.c | 3 +-
drivers/net/ethernet/amd/pds_core/core.c | 3 +-
drivers/net/ethernet/amd/pds_core/fw.c | 6 +--
drivers/net/ethernet/cadence/macb_main.c | 2 +-
drivers/net/ethernet/cisco/enic/enic_admin.c | 2 +-
drivers/net/ethernet/cisco/enic/enic_main.c | 6 +--
.../net/ethernet/freescale/dpaa2/dpaa2-switch.c | 5 +--
drivers/net/ethernet/intel/libie/controlq.c | 3 +-
.../net/ethernet/marvell/octeontx2/af/cn20k/npc.c | 13 +++---
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 3 +-
.../ethernet/mellanox/mlx5/core/eswitch_offloads.c | 2 +-
.../net/ethernet/mellanox/mlx5/core/sf/hw_table.c | 2 +-
.../mellanox/mlx5/core/steering/sws/dr_icm_pool.c | 2 +-
drivers/net/ethernet/meta/fbnic/fbnic_irq.c | 2 +-
drivers/net/ethernet/microsoft/mana/gdma_main.c | 8 ++--
drivers/net/ntb_netdev.c | 3 +-
drivers/net/wireless/ath/ath12k/ahb.c | 2 +-
.../net/wireless/intel/iwlwifi/mld/regulatory.c | 3 +-
drivers/net/wireless/mediatek/mt76/mt7921/regd.c | 2 +-
drivers/net/wireless/mediatek/mt76/mt7925/main.c | 2 +-
drivers/net/wireless/mediatek/mt76/mt7925/regd.c | 2 +-
drivers/net/wireless/morsemicro/mm81x/mac.c | 9 ++--
drivers/net/wireless/morsemicro/mm81x/yaps.c | 10 ++---
drivers/net/wireless/nxp/nxpwifi/cfg80211.c | 14 +++---
drivers/net/wireless/nxp/nxpwifi/cmdevt.c | 2 +-
drivers/net/wireless/nxp/nxpwifi/ie.c | 14 +++---
drivers/net/wireless/nxp/nxpwifi/init.c | 2 +-
drivers/net/wireless/nxp/nxpwifi/main.c | 8 ++--
drivers/net/wireless/nxp/nxpwifi/scan.c | 13 +++---
drivers/net/wireless/nxp/nxpwifi/sta_cfg.c | 2 +-
drivers/net/wireless/nxp/nxpwifi/sta_cmd.c | 2 +-
drivers/net/wireless/nxp/nxpwifi/uap_event.c | 2 +-
drivers/nvdimm/region_devs.c | 3 +-
drivers/nvme/host/core.c | 3 +-
drivers/nvme/host/pci.c | 2 +-
drivers/opp/core.c | 4 +-
drivers/pci/endpoint/pci-ep-msi.c | 4 +-
drivers/platform/x86/amd/hsmp/acpi.c | 5 +--
.../platform/x86/hp/hp-bioscfg/enum-attributes.c | 4 +-
drivers/platform/x86/intel/pmc/pwrm_telemetry.c | 3 +-
drivers/pmdomain/core.c | 2 +-
drivers/power/reset/reboot-mode.c | 6 +--
drivers/power/sequencing/core.c | 2 +-
drivers/power/sequencing/pwrseq-pcie-m2.c | 2 +-
drivers/power/supply/power_supply_core.c | 6 +--
drivers/ptp/ptp_chardev.c | 2 +-
drivers/s390/block/dasd.c | 2 +-
drivers/scsi/fnic/fnic_debugfs.c | 2 +-
drivers/scsi/leapraid/leapraid_func.c | 52 +++++++++-------------
drivers/scsi/scsi_scan.c | 2 +-
drivers/soc/bcm/brcmstb/common.c | 2 +-
drivers/spi/spi-offload.c | 2 +-
drivers/staging/greybus/raw.c | 2 +-
drivers/staging/media/atomisp/pci/sh_css.c | 30 +++++--------
.../staging/media/atomisp/pci/sh_css_firmware.c | 4 +-
drivers/tee/qcomtee/user_obj.c | 3 +-
drivers/thunderbolt/stream.c | 12 +++--
drivers/tty/moxa.c | 3 +-
drivers/tty/vt/consolemap.c | 3 +-
drivers/ufs/core/ufs-txeq.c | 2 +-
drivers/ufs/host/ufs-qcom.c | 2 +-
drivers/usb/gadget/function/f_ncm.c | 2 +-
drivers/usb/usbip/usbip_common.c | 2 +-
drivers/xen/grant-table.c | 2 +-
fs/9p/vfs_dentry.c | 3 +-
fs/afs/dir.c | 2 +-
fs/afs/symlink.c | 3 +-
fs/binfmt_misc.c | 7 ++-
fs/ceph/addr.c | 2 +-
fs/ceph/mds_client.c | 2 +-
fs/ceph/subvolume_metrics.c | 2 +-
fs/coredump.c | 2 +-
fs/ext4/fast_commit.c | 4 +-
fs/fuse/file.c | 3 +-
fs/fuse/readdir.c | 2 +-
fs/hfs/bnode.c | 2 +-
fs/namespace.c | 2 +-
fs/nfsd/export.c | 7 ++-
fs/nfsd/nfs4callback.c | 4 +-
fs/nfsd/nfs4state.c | 7 +--
fs/nfsd/nfsctl.c | 2 +-
fs/ntfs/bitmap.c | 2 +-
fs/ntfs/compress.c | 8 ++--
fs/ntfs/dir.c | 16 +++----
fs/ntfs/ea.c | 2 +-
fs/ntfs/index.c | 2 +-
fs/ntfs/logfile.c | 2 +-
fs/ntfs/mft.c | 10 +++--
fs/ntfs/runlist.c | 14 +++---
fs/ntfs/super.c | 2 +-
fs/overlayfs/readdir.c | 2 +-
fs/smb/client/cifs_swn.c | 2 +-
fs/smb/client/dfs_cache.c | 2 +-
fs/smb/client/smb2inode.c | 2 +-
fs/smb/server/ksmbd_work.c | 2 +-
fs/smb/server/smb2pdu.c | 2 +-
fs/xfs/libxfs/xfs_da_btree.c | 4 +-
init/initramfs_test.c | 2 +-
io_uring/napi.c | 2 +-
io_uring/zcrx.c | 4 +-
kernel/bpf/diagnostics.c | 2 +-
kernel/bpf/hashtab.c | 2 +-
kernel/bpf/liveness.c | 2 +-
kernel/bpf/log.c | 2 +-
kernel/bpf/verifier.c | 5 +--
kernel/dma/map_benchmark.c | 3 +-
kernel/events/core.c | 5 +--
kernel/futex/core.c | 6 +--
kernel/irq/manage.c | 2 +-
kernel/jump_label.c | 5 +--
kernel/kthread.c | 2 +-
kernel/sched/ext/cid.c | 16 +++----
kernel/sched/ext/ext.c | 2 +-
kernel/sched/ext/sub.c | 2 +-
kernel/trace/fprobe.c | 2 +-
kernel/trace/ring_buffer.c | 4 +-
kernel/trace/trace_eprobe.c | 2 +-
kernel/trace/trace_remote.c | 10 ++---
lib/test_rhashtable.c | 2 +-
lib/test_workqueue.c | 4 +-
lib/tests/kunit_iov_iter.c | 2 +-
mm/damon/tests/vaddr-kunit.h | 2 +-
net/batman-adv/hard-interface.c | 2 +-
net/bluetooth/hci_sync.c | 3 +-
net/devlink/netlink.c | 2 +-
net/devlink/param.c | 7 ++-
net/ipv4/tcp_ipv4.c | 4 +-
net/mac80211/nan.c | 3 +-
net/mctp/test/route-test.c | 2 +-
net/mctp/test/utils.c | 2 +-
net/netfilter/nf_tables_api.c | 2 +-
net/netfilter/nfnetlink_cttimeout.c | 2 +-
net/rds/info.c | 2 +-
net/rxrpc/key.c | 2 +-
net/sched/act_gate.c | 4 +-
net/sched/act_tunnel_key.c | 2 +-
net/sunrpc/auth_gss/gss_krb5_crypto.c | 5 +--
net/sunrpc/svcauth_unix.c | 4 +-
net/sunrpc/xdr.c | 3 +-
net/unix/af_unix.c | 4 +-
net/wireless/core.c | 5 +--
net/wireless/nl80211.c | 9 ++--
security/integrity/ima/ima_queue.c | 3 +-
sound/core/compress_offload.c | 4 +-
sound/core/control.c | 6 +--
sound/core/control_led.c | 2 +-
sound/core/init.c | 2 +-
sound/core/misc.c | 2 +-
sound/core/oss/mixer_oss.c | 2 +-
sound/core/pcm_native.c | 2 +-
sound/core/seq/oss/seq_oss_synth.c | 2 +-
sound/core/seq/seq_clientmgr.c | 2 +-
sound/core/seq/seq_virmidi.c | 2 +-
sound/core/timer.c | 2 +-
sound/drivers/aloop.c | 4 +-
sound/isa/gus/gus_dma.c | 2 +-
sound/pci/cs46xx/cs46xx_lib.c | 2 +-
sound/pci/ctxfi/ctamixer.c | 4 +-
sound/pci/ctxfi/ctdaio.c | 4 +-
sound/pci/ctxfi/ctsrc.c | 4 +-
sound/pci/ctxfi/cttimer.c | 2 +-
sound/pci/emu10k1/emufx.c | 2 +-
sound/soc/codecs/simple-amplifier.c | 2 +-
sound/soc/generic/simple-card-utils.c | 2 +-
sound/soc/meson/gx-formatter.c | 2 +-
sound/soc/qcom/qdsp6/q6afe.c | 2 +-
sound/soc/sdca/sdca_functions.c | 19 ++++----
sound/soc/sof/sof-client-probes-ipc4.c | 2 +-
sound/soc/sof/sof-client.c | 2 +-
sound/sparc/amd7930.c | 2 +-
304 files changed, 637 insertions(+), 726 deletions(-)
]
|
| 26/2 |
2026/10/13 22:18 |
llm |
debugger |
0m
Model:
Tokens:
input: 24691
output: 44
thoughts: 201
Thoughts: Here's my analysis of the code snippet, thinking out loud as an expert:
**Investigating `kzalloc_objs` Usage and Potential Vulnerability**
Okay, so `kzalloc_objs`... right, it's essentially a wrapper around `kcalloc` or `kmalloc_array` with the `__GFP_ZERO` flag, ensuring the allocated memory is zeroed out. No surprises there. But, looking at where it's *used* is key. Hmm, it's in `fill_object_idr`:
```c
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
Before this, the code probably used `kcalloc` with `GFP_KERNEL`. Got it. The line of code is interesting; it is allocating memory for an array of `drm_mode_object` pointers. Now, if `object_count` is large, `kzalloc_objs` will attempt a large, contiguous allocation using `GFP_KERNEL`. That's where things get potentially dicey.
The real question is, where does `object_count` come from? Is it user-controlled? That's the critical point. If it's derived from user space without a robust upper bound check, we could have a vulnerability. A maliciously crafted `object_count` value could lead to a massive allocation request, potentially leading to a denial-of-service or even system instability. I need to trace this back. Is there an upper bound check for `object_count`? Let me see... I'll check `drm_mode_create_lease_ioctl`, which is probably the source of the `object_count` value.
|
| 27/2 |
2026/10/13 22:19 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_create_lease_ioctl]
Results: map[SourceCode: 469: /*
470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
475: int drm_mode_create_lease_ioctl(struct drm_device *dev,
476: void *data, struct drm_file *lessor_priv)
477: {
478: struct drm_mode_create_lease *cl = data;
479: size_t object_count;
480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
540: /* lessee will take the ownership of leases */
541: lessee = drm_lease_create(lessor, &leases);
542:
543: if (IS_ERR(lessee)) {
544: ret = PTR_ERR(lessee);
545: idr_destroy(&leases);
546: goto out_leases;
547: }
548:
549: /* Clone the lessor file to create a new file for us */
550: drm_dbg_lease(dev, "Allocating lease file\n");
551: lessee_file = file_clone_open(lessor_file);
552: if (IS_ERR(lessee_file)) {
553: ret = PTR_ERR(lessee_file);
554: goto out_lessee;
555: }
556:
557: lessee_priv = lessee_file->private_data;
558: /* Change the file to a master one */
559: drm_master_put(&lessee_priv->master);
560: lessee_priv->master = lessee;
561: lessee_priv->is_master = 1;
562: lessee_priv->authenticated = 1;
563:
564: /* Pass fd back to userspace */
565: drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
566: cl->fd = fd;
567: cl->lessee_id = lessee->lessee_id;
568:
569: /* Hook up the fd */
570: fd_install(fd, lessee_file);
571:
572: drm_master_put(&lessor);
573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
574: return 0;
575:
576: out_lessee:
577: drm_master_put(&lessee);
578:
579: out_leases:
580: put_unused_fd(fd);
581:
582: out_lessor:
583: drm_master_put(&lessor);
584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
585: return ret;
586: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 28/2 |
2026/10/13 22:19 |
llm |
debugger |
0m
Model:
Tokens:
input: 27118
output: 39
thoughts: 189
Thoughts: **Vulnerability Analysis: Object Count Integer Overflow**
Okay, so I'm looking at this code and immediately I see a potential issue. There's no upper bound check on `object_count` before it's assigned here:
```c
object_count = cl->object_count;
...
if (object_count != 0) {
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
That's a red flag. It looks like it's just grabbing the value directly from `cl->object_count`. Then, if it isn't zero, it goes on to allocate memory with `memdup_array_user`, which is going to be the source of the problem. `memdup_array_user` is crucial here because it uses `memdup_user`, and I know from experience that `memdup_user` ultimately calls `kmem_buckets_alloc_track_caller` with `GFP_USER | __GFP_NOWARN`. And that's what's got me concerned. `kmem_buckets_alloc_track_caller`... hmm, I recall that being linked to `kvmalloc` in some contexts.
I need to confirm if `kmem_buckets_alloc_track_caller` *can* use `kvmalloc`. Time to double-check the `mm/util.c` or `include/linux/slab.h` source to be absolutely sure what that function is doing. Integer overflow, particularly when combined with memory allocation, is a classic vulnerability vector. This needs a closer look.
|
| 29/2 |
2026/10/13 22:19 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:mm/util.c Name:kmem_buckets_alloc_track_caller]
Results: map[SourceCode: SourceFile:]
|
| 30/2 |
2026/10/13 22:19 |
llm |
debugger |
1m
Model:
Tokens:
input: 27732
output: 33
thoughts: 12
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind the audience is an expert:
**Revisiting `memdup_user`**
Alright, time to circle back to `memdup_user`. I've been working on this area, and I want to re-examine that specific function. I'm probably picking it apart for a reason - likely a subtle bug report, performance issue, or security concern has piqued my interest. Perhaps a recent patch related to memory handling sparked a new line of thinking. It could be I am trying to determine if I missed something during the initial code review, or have a deeper understanding after further context has presented itself. Let's see if the assumptions I had before hold up to another close look. It warrants a fresh perspective.
|
| 31/2 |
2026/10/13 22:21 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/util.c Name:memdup_user]
Results: map[SourceCode: 208: /**
209: * memdup_user - duplicate memory region from user space
210: *
211: * @src: source address in user space
212: * @len: number of bytes to copy
213: *
214: * Return: an ERR_PTR() on failure. Result is physically
215: * contiguous, to be freed by kfree().
216: */
217: void *memdup_user(const void __user *src, size_t len)
218: {
219: void *p;
220:
221: p = kmem_buckets_alloc_track_caller(user_buckets, len, GFP_USER | __GFP_NOWARN);
222: if (!p)
223: return ERR_PTR(-ENOMEM);
224:
225: if (copy_from_user(p, src, len)) {
226: kfree(p);
227: return ERR_PTR(-EFAULT);
228: }
229:
230: return p;
231: }
SourceFile:mm/util.c]
|
| 32/2 |
2026/10/13 22:21 |
llm |
debugger |
1m
Model:
Tokens:
input: 28297
output: 26
thoughts: 17
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Kernel Memory Allocation Analysis: Grepping for Clues**
Alright, I'm diving in to diagnose a kernel memory issue. My first instinct, given my experience, is to zero in on potential memory allocation problems. And the most direct way to start that investigation is to look for clues in the allocation calls. I'm thinking of focusing my grep query on `kmem_buckets_alloc_track_caller`. Itβs a pretty good starting point to identify specific points in the kernel code where memory is being allocated, and tracking down the call path with the addition of the "track_caller" variant should give me a specific stack trace. This should give me a quick way to pinpoint the problematic code. This is definitely my starting point. From there, I can refine the search, look at callers, and start building a more comprehensive picture. Let's see what we find.
|
| 33/2 |
2026/10/13 22:22 |
tool |
grepper |
0m
Args: map[Expression:#define kmem_buckets_alloc_track_caller]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1183-
include/linux/slab.h:1184:#define kmem_buckets_alloc_track_caller(_b, _size, _flags) \
include/linux/slab.h-1185- kmem_buckets_alloc_node_track_caller(_b, _size, _flags, NUMA_NO_NODE)
]
|
| 34/2 |
2026/10/13 22:22 |
llm |
debugger |
1m
Model:
Tokens:
input: 28694
output: 28
thoughts: 19
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person:
**Diving into Kernel Memory Allocation Tracking**
Alright, so I'm thinking about digging into kernel memory allocation tracking. My initial instinct is to use `grep`. Specifically, I'm going to search for the string `kmem_buckets_alloc_node_track_caller`. That's a good starting point, right? It's a key function related to tracking kernel memory allocations, likely tied to the `kmem_cache` subsystem and its associated debugging features, specifically aimed at identifying the caller responsible for a particular allocation. Searching for this function should quickly pinpoint relevant code paths. It's a quick and dirty, but effective way, to get a handle on where allocation tracking is being used in the current codebase. From there, I can refine the search, depending on what the results give me. I'm hoping to quickly identify the locations involved in this particular allocation path!
|
| 35/2 |
2026/10/13 22:24 |
tool |
grepper |
0m
Args: map[Expression:#define kmem_buckets_alloc_node_track_caller]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1180-
include/linux/slab.h:1181:#define kmem_buckets_alloc_node_track_caller(_b, _size, _flags, _node) \
include/linux/slab.h-1182- alloc_hooks(__kmalloc_node_track_caller_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, _node, _RET_IP_))
]
|
| 36/2 |
2026/10/13 22:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 29121
output: 35
thoughts: 726
Thoughts: **Analyzing Memory Allocation in `fill_object_idr`**
Okay, let's break this down. It seems we're seeing an interesting interaction between `memdup_user` (and consequently, `memdup_array_user`) and `kzalloc_objs` within `fill_object_idr`. The key issue is how they handle memory allocation size limits imposed by `kmalloc` versus `kvmalloc`.
First, I realize `memdup_user` is using `kmalloc`, not `kvmalloc`. Because of this, it can only allocate up to `MAX_PAGE_ORDER` which is usually around 4MB. Now, if the `object_count` is 1,000,000, then the data to be copied by `memdup_user` is `4,000,000` bytes, which, in this case, is safely within the `4MB` limit and `memdup_user` succeeds.
However, after that, `fill_object_idr` calls `kzalloc_objs`, which then attempts to allocate memory for the object pointers. This allocation size is `1,000,000 * 8 = 8,000,000` bytes, which exceeds the `kmalloc` limit and requires order 11, which exceeds the allowed order. Since `kzalloc_objs` uses `kmalloc` without `__GFP_NOWARN`, it triggers a warning in `alloc_order_allowed`.
My first thought is to fix this by using `kvmalloc_array` or `kvzalloc` for `objects` in `fill_object_idr`.
But wait, `memdup_array_user` *also* uses `kmalloc` (through `memdup_user`), which is relevant here. If `object_count` is larger than 1,048,576 (for example, 2,000,000), `memdup_array_user` will attempt to allocate 8MB, and because it uses `__GFP_NOWARN`, it will simply fail and return `-ENOMEM` silently. `kzalloc_objs` does *not* use `__GFP_NOWARN`, leading to the warning, but only if `memdup_array_user` *succeeds*, yet `kzalloc_objs` *fails*. This creates a particular window of vulnerability, it looks like `sizeof(__u32)` is 4, and `sizeof(struct drm_mode_object *)` is 8. So, when the `object_count` is between `4MB / 8 = 524,288` and `4MB / 4 = 1,048,576`, `memdup_array_user` succeeds, but `kzalloc_objs` fails, thus the warning!
So, the optimal fix is to replace `kmalloc` with `kvmalloc_array` for this allocation:
```c
objects = kvmalloc_array(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL | __GFP_ZERO);
```
While `kvmalloc_array` is the better solution, maybe we can just limit the size of `object_count`? I should probably check if there is an upper limit to the number of objects we can support in a lease. Let me look at that.
|
| 37/2 |
2026/10/13 22:24 |
tool |
grepper |
0m
Args: map[Expression:object_count PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results: map[Output:drivers/gpu/drm/drm_lease.c=346=static int validate_lease(struct drm_device *dev,
drivers/gpu/drm/drm_lease.c:347: int object_count,
drivers/gpu/drm/drm_lease.c-348- struct drm_mode_object **objects,
--
drivers/gpu/drm/drm_lease.c-358-
drivers/gpu/drm/drm_lease.c:359: for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c-360- if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
--
drivers/gpu/drm/drm_lease.c=378=static int fill_object_idr(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-380- struct idr *leases,
drivers/gpu/drm/drm_lease.c:381: int object_count,
drivers/gpu/drm/drm_lease.c-382- u32 *object_ids)
--
drivers/gpu/drm/drm_lease.c-388-
drivers/gpu/drm/drm_lease.c:389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
drivers/gpu/drm/drm_lease.c-390- if (!objects)
--
drivers/gpu/drm/drm_lease.c-394- and check for validity. */
drivers/gpu/drm/drm_lease.c:395: for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c-396- objects[o] = drm_mode_object_find(dev, lessor_priv,
--
drivers/gpu/drm/drm_lease.c-410-
drivers/gpu/drm/drm_lease.c:411: ret = validate_lease(dev, object_count, objects, universal_planes);
drivers/gpu/drm/drm_lease.c-412- if (ret) {
--
drivers/gpu/drm/drm_lease.c-418- universal planes */
drivers/gpu/drm/drm_lease.c:419: for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c-420- struct drm_mode_object *obj = objects[o];
--
drivers/gpu/drm/drm_lease.c-460-out_free_objects:
drivers/gpu/drm/drm_lease.c:461: for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c-462- if (objects[o])
--
drivers/gpu/drm/drm_lease.c=475=int drm_mode_create_lease_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-478- struct drm_mode_create_lease *cl = data;
drivers/gpu/drm/drm_lease.c:479: size_t object_count;
drivers/gpu/drm/drm_lease.c-480- int ret = 0;
--
drivers/gpu/drm/drm_lease.c-506-
drivers/gpu/drm/drm_lease.c:507: object_count = cl->object_count;
drivers/gpu/drm/drm_lease.c-508-
--
drivers/gpu/drm/drm_lease.c-510- idr_init(&leases);
drivers/gpu/drm/drm_lease.c:511: if (object_count != 0) {
drivers/gpu/drm/drm_lease.c-512- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
drivers/gpu/drm/drm_lease.c:513: object_count, sizeof(__u32));
drivers/gpu/drm/drm_lease.c-514- if (IS_ERR(object_ids)) {
--
drivers/gpu/drm/drm_lease.c-521- ret = fill_object_idr(dev, lessor_priv, &leases,
drivers/gpu/drm/drm_lease.c:522: object_count, object_ids);
drivers/gpu/drm/drm_lease.c-523- kfree(object_ids);
]
|
| 38/2 |
2026/10/13 22:24 |
llm |
debugger |
0m
Model:
Tokens:
input: 31782
output: 37
thoughts: 510
Thoughts: **Analyzing Memory Allocation in DRM Lease Creation**
Okay, so I'm looking at this code and initially thought there wasn't a hard limit on `object_count`. But hold on, `memdup_array_user` is using `kmalloc` internally (through `memdup_user`), which means a large `object_count` could lead to an `-ENOMEM` error, although it won't warn due to the use of `__GFP_NOWARN`. However, the `kzalloc_objs` function *does* warn due to using `kmalloc` without `__GFP_NOWARN`. And of course, `object_ids` is freed with `kfree()`.
The immediate thought is to switch `kzalloc_objs` to `kvmalloc_array`, which would squash that warning. But then I remember `memdup_array_user` has its own limit due to its use of `kmalloc` (around 4MB). If we *really* need to handle more than 4MB for `object_ids`, then we'd need to consider `vmemdup_user` or something similar, which I doubt.
Actually, does a lease even *need* a large number of objects? DRM leases are usually about a few CRTCs, connectors, and planes. The total number of objects in a DRM device is typically small, often under a thousand. So, in practice, `object_count` likely won't be enormous. It's user space that we're talking about, so we have to consider what they *could* pass.
So, if we use `kvmalloc_array` for `objects`, we can at least avoid the warning. Wait, `kvmalloc_array` doesn't warn on large sizes; it just falls back to `vmalloc`. I wonder if there is a `kvzalloc_objs`? No, there isn't. So we can use `kvzalloc` or `kvmalloc_array`, either of those look good. I just need to make sure to free `objects` using `kvfree` if I use `kvmalloc_array`, since that's what's allocated.
Okay, let me double-check that `memdup_array_user` really uses `kmalloc` and not `kvmalloc`. Gotta be certain about this!
|
| 39/2 |
2026/10/13 22:24 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:memdup_array_user]
Results: map[SourceCode: 22: /**
23: * memdup_array_user - duplicate array from user space
24: * @src: source address in user space
25: * @n: number of array members to copy
26: * @size: size of one array member
27: *
28: * Return: an ERR_PTR() on failure. Result is physically
29: * contiguous, to be freed by kfree().
30: */
31: static inline __realloc_size(2, 3)
32: void *memdup_array_user(const void __user *src, size_t n, size_t size)
33: {
34: size_t nbytes;
35:
36: if (check_mul_overflow(n, size, &nbytes))
37: return ERR_PTR(-EOVERFLOW);
38:
39: return memdup_user(src, nbytes);
40: }
SourceFile:include/linux/string.h]
|
| 40/2 |
2026/10/13 22:25 |
llm |
debugger |
0m
Model:
Tokens:
input: 33122
output: 34
thoughts: 671
Thoughts: **Analyzing Potential Memory Allocation Issues in DRM Lease Creation**
Okay, so here's the situation. I'm looking at the memory allocation within `drm_mode_create_lease_ioctl`, specifically the handling of `object_ids`. I see that `memdup_array_user` is used, and the memory returned is subsequently freed using `kfree()`, which means `object_ids` is initially allocated via `kmalloc`, presumably through `memdup_user`.
Now, if `object_count` is set to something large, like 1,000,000, `memdup_array_user` allocates a significant chunk β 4MB in this case. Given that `MAX_PAGE_ORDER` is 10, 4MB falls within that limit, so `memdup_array_user` succeeds, which seems reasonable.
The follow-up allocation in `fill_object_idr` attempts to grab 8MB. Since `kzalloc_objs` uses `kmalloc` without `__GFP_NOWARN`, it triggers a warning because it's exceeding the `MAX_PAGE_ORDER` limit for `kmalloc`.
My first thought is, "Well, if we change `kzalloc_objs` to `kvmalloc_array`, we can handle larger allocations." But I also realize that the `memdup_array_user` step has a limit of 4MB. If the userspace code gives us `object_count = 2,000,000`, the allocation needed would be 8MB. Will `memdup_array_user` itself cause a warning? No. It uses `GFP_USER | __GFP_NOWARN` so it won't warn, but will simply return `-ENOMEM`.
So, the only warning we're seeing originates from `kzalloc_objs` because of the lack of `__GFP_NOWARN` and because it can be larger than what's allocated by `memdup_array_user`, which is only 4 bytes per element instead of 8.
The next question I have is whether such a large `object_count` even makes sense. A DRM device has a finite number of objects, limited by things like `dev->mode_config.num_crtc` and `num_connector`. The total number is likely a few thousand at most. But the `drm_mode_create_lease_ioctl` doesn't seem to validate `object_count` against any upper bound.
So here's what I'm thinking: we could simply use `kvmalloc_array` for `objects` and `kvfree` to free it. Alternatively, we could consider using `kvmalloc_array` for *both* `object_ids` and `objects`. Wait, `memdup_array_user` is used for `object_ids`, so we have to use `kvmalloc` for that too. There's `vmemdup_user` which uses `kvmalloc`, but there's no array version of `vmemdup_user`, `vmemdup_array_user`.
Ultimately, using `kvmalloc_array` for `objects` seems like the most standard approach to deal with large allocations that may exceed `MAX_PAGE_ORDER`. I need to check if `kvmalloc_array` is used elsewhere in `drm_lease.c` as a sanity check.
|
| 41/2 |
2026/10/13 22:25 |
tool |
grepper |
0m
Error:
Args: map[Expression:kvmalloc PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results:
|
| 42/2 |
2026/10/13 22:25 |
llm |
debugger |
0m
Model:
Tokens:
input: 34569
output: 41
thoughts: 22
Thoughts: Okay, here's my summary, tailored for an expert audience, as if it were my thought process:
**Internal Review of Functionality**
No, that's not quite right. It's not behaving as expected. Time to take a fresh look at `fill_object_idr`. I need to re-examine the logic within that function, specifically how it handles object identification and potential IDR conflicts. I'm going to start by reviewing the assumptions made about input data and the control flow within `fill_object_idr` to pinpoint the source of the deviation. I have a hunch, but need to rule out certain areas first. It's frustrating to run into this.
|
| 43/2 |
2026/10/13 22:25 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:fill_object_idr]
Results: map[SourceCode: 378: static int fill_object_idr(struct drm_device *dev,
379: struct drm_file *lessor_priv,
380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 44/2 |
2026/10/13 22:26 |
llm |
debugger |
0m
Model:
Tokens:
input: 36272
output: 31
thoughts: 743
Thoughts: **Reflecting on Memory Allocation Strategies**
Okay, so I'm looking at changing `kzalloc_objs` to `kvmalloc_array` with `__GFP_ZERO` in this DRM code, and the corresponding `kfree` to `kvfree`. Seems straightforward enough, right? But then I remember `memdup_array_user` uses `kmalloc`, and that's going to fail if the `object_count` gets too large β like, over 1,048,576 elements, assuming a 4MB limit. Using `kvmalloc_array` for `objects` means it could potentially be allocated with `vmalloc` if it's a very large array.
Now I remember that `memdup_array_user` is used for `object_ids` within `drm_mode_create_lease_ioctl`, which is a problem:
```c
if (object_count != 0) {
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
goto out_lessor;
}
```
If `object_count` gets big, `memdup_array_user` will quietly fail with `-ENOMEM`. The question is, how do we handle situations where we *might* have a large `object_count`?
Realistically, though, `object_count` *shouldn't* be enormous. Let's see if we can establish an upper limit. I'll check if there's any implicit limit on the total number of DRM objects. Typically, DRM devices have just a few dozen. Maybe we can set a reasonable cap, say, 1024 or 4096?
Wait, `object_count` represents the number of objects a user wants to lease. If we restrict it, there's a risk of breaking some userspace applications that need to lease many objects, like those managing multiple planes. But, a million objects? Probably not.
However, using `kvmalloc_array` and `kvfree` is the proper, standard approach for arrays where the size is user-controlled, without imposing arbitrary limits.
Thinking back to `memdup_array_user`, which uses `kmalloc`, if we need to support very large arrays, we should be using `vmemdup_user` instead. But that code path is already using `memdup_array_user`, which means it doesn't support the case of `object_count` > 1,048,576 anyway.
So, if I just swap `kzalloc_objs` for `kvmalloc_array` and `kfree` for `kvfree`, it should resolve the warning I was getting.
Hold on a sec... `kzalloc_objs` is a macro expanding to `__alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)`. Is there a `kvzalloc_objs`? No.
Actually, `kvmalloc_array` *is* perfectly fine here.
Let me just quickly verify `kvmalloc_array` is actually available. Yep, it's in `include/linux/slab.h`. Wait, `kvcalloc` is also available. Let me check `kvcalloc`.
|
| 45/2 |
2026/10/13 22:26 |
tool |
grepper |
0m
Args: map[Expression:kvcalloc PathPrefixes:[include/linux/slab.h]]
Results: map[Output:include/linux/slab.h=1367=_kvmalloc_array_node_noprof(size_t n, size_t size, gfp_t flags, int node, kmalloc_token_t token)
--
include/linux/slab.h-1377-#define kvmalloc_array_noprof(...) kvmalloc_array_node_noprof(__VA_ARGS__, NUMA_NO_NODE)
include/linux/slab.h:1378:#define kvcalloc_node_noprof(_n,_s,_f,_node) kvmalloc_array_node_noprof(_n,_s,(_f)|__GFP_ZERO,_node)
include/linux/slab.h:1379:#define kvcalloc_noprof(...) kvcalloc_node_noprof(__VA_ARGS__, NUMA_NO_NODE)
include/linux/slab.h-1380-
include/linux/slab.h-1381-#define kvmalloc_array(...) alloc_hooks(kvmalloc_array_noprof(__VA_ARGS__))
include/linux/slab.h:1382:#define kvcalloc_node(...) alloc_hooks(kvcalloc_node_noprof(__VA_ARGS__))
include/linux/slab.h:1383:#define kvcalloc(...) alloc_hooks(kvcalloc_noprof(__VA_ARGS__))
include/linux/slab.h-1384-
]
|
| 46/2 |
2026/10/13 22:26 |
llm |
debugger |
0m
Model:
Tokens:
input: 38167
output: 44
thoughts: 418
Thoughts: **Considering Memory Allocation Strategies**
Okay, so `kvcalloc` is definitely an option here. I can use `kvcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)` to allocate the initial array and then use `kvfree(objects)` to free it later. That's straightforward enough.
But hold on, what about `memdup_array_user`? I need to think through the potential impact of different `object_count` values. If `object_count` is really large, say 2,000,000, `memdup_array_user` is likely to silently fail with `-ENOMEM`. That's not ideal, so I'll need to handle that. On the other hand, if `object_count` is 1,000,000, `memdup_array_user` *should* succeed because it allocates 4,000,000 bytes, which is of order 10 and therefore, <= MAX_PAGE_ORDER. Then `kvcalloc` will allocate 8,000,000 bytes using `vmalloc` because it's > 4MB.
I'm starting to get to the details. This `vmalloc` will succeed, but will it trigger a warning? Not necessarily. Then the loop I have will run 1,000,000 times. That is what I need to consider.
Now I'm looking at the core of the problem. If `object_count` is 1,000,000, the loop itself will take a significant amount of time. I do not have a problem with `drm_mode_object_find` as it is relatively fast (idr lookup). But if it takes too long, it might trigger a soft lockup. I need to keep that in mind.
Hmm, does `drm_mode_object_find` acquire a spinlock or a mutex? That's critical information, and I need to check the source code for `drm_mode_object_find` to be sure.
|
| 47/2 |
2026/10/13 22:26 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_mode_object.c Name:drm_mode_object_find]
Results: map[SourceCode: 166: /**
167: * drm_mode_object_find - look up a drm object with static lifetime
168: * @dev: drm device
169: * @file_priv: drm file
170: * @id: id of the mode object
171: * @type: type of the mode object
172: *
173: * This function is used to look up a modeset object. It will acquire a
174: * reference for reference counted objects. This reference must be dropped again
175: * by callind drm_mode_object_put().
176: */
177: struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
178: struct drm_file *file_priv,
179: uint32_t id, uint32_t type)
180: {
181: struct drm_mode_object *obj = NULL;
182:
183: obj = __drm_mode_object_find(dev, file_priv, id, type);
184: return obj;
185: }
SourceFile:drivers/gpu/drm/drm_mode_object.c]
|
| 48/2 |
2026/10/13 22:26 |
llm |
debugger |
0m
Model:
Tokens:
input: 39439
output: 45
thoughts: 14
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Diving into `__drm_mode_object_find`**
Alright, let's take a look at `__drm_mode_object_find`. I'm going to start by confirming its basic purpose β it's the core function for locating a specific DRM mode object, right? I'll probably be checking how it handles various object types and their associated IDs. My immediate concern is usually the robustness of the search: does it correctly handle potential null pointers or invalid ID inputs? Are there any obvious race conditions or locking issues that I should be aware of, especially if this function is called concurrently from different threads? I'll be keen on examining the internal data structures it's traversing, verifying how it handles different driver implementations. Finally, I'll be looking for any potential optimization opportunities. Can we do a more efficient lookup?
|
| 49/2 |
2026/10/13 22:27 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_mode_object.c Name:__drm_mode_object_find]
Results: map[SourceCode: 138: struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,
139: struct drm_file *file_priv,
140: uint32_t id, uint32_t type)
141: {
142: struct drm_mode_object *obj = NULL;
143:
144: mutex_lock(&dev->mode_config.idr_mutex);
145: obj = idr_find(&dev->mode_config.object_idr, id);
146: if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type)
147: obj = NULL;
148: if (obj && obj->id != id)
149: obj = NULL;
150:
151: if (obj && drm_mode_object_lease_required(obj->type) &&
152: !_drm_lease_held(file_priv, obj->id)) {
153: drm_dbg_kms(dev, "[OBJECT:%d] not included in lease", id);
154: obj = NULL;
155: }
156:
157: if (obj && obj->free_cb) {
158: if (!kref_get_unless_zero(&obj->refcount))
159: obj = NULL;
160: }
161: mutex_unlock(&dev->mode_config.idr_mutex);
162:
163: return obj;
164: }
SourceFile:drivers/gpu/drm/drm_mode_object.c]
|
| 50/2 |
2026/10/13 22:27 |
llm |
debugger |
0m
Model:
Tokens:
input: 40163
output: 51
thoughts: 383
Thoughts: **Analyzing Potential Performance Issues in DRM Lease Handling**
Okay, so I'm looking at this `__drm_mode_object_find` function, and the first thing that jumps out is that it's taking the `dev->mode_config.idr_mutex`. If the `object_count` happens to be massive β say, a million β this thing is going to lock and unlock that mutex *a million times*. That could introduce a significant delay. I had to pause though, because I wasn't completely clear whether that `mutex_lock` was interruptible, but no it is not. The good news is that it drops the lock between iterations so it's not a complete hard lockup, but stillβ¦it seems like we should probably cap `object_count` at some reasonable value to prevent pathological cases.
But then I see the `idr_alloc` calls within the loop and, shoot, that could be a performance bottleneck too!
```c
for (o = 0; o < object_count; o++) {
struct drm_mode_object *obj = objects[o];
u32 object_id = objects[o]->id;
...
ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
```
A large `object_count` means a lot of memory being allocated for the IDR. I'm getting a bad feeling about this; is there any similar limitation I can check for elsewhere?
Let me just quickly re-examine the `drm_mode_create_lease_ioctl` and make sure it has the fix. Oh, I see that replacing the `kcalloc` with `kvcalloc` seems to clear up that warning. But wait, this `kzalloc_objs` variable wasn't always around, it was introduced in commit `3a2c4d55e32a`. Before that, it was just `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`. Maybe I should check the history of `fill_object_idr` just to get some more context on what changes have been happening there.
|
| 51/2 |
2026/10/13 22:28 |
tool |
git-log |
0m
Args: map[CodeRegexp: Count:10 SourcePath:drivers/gpu/drm/drm_lease.c SymbolName:fill_object_idr]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
948de84233d3 drm : Insert blank lines after declarations.
e40b76428842 drm/leases: Drop object_id validation for negative ids
b5f06893c499 drm: Rename crtc_idr as object_idr to KMS cleanups
968029057192 drm/lease: look at ->universal_planes only once
a0c1af46e9d7 drm/lease: debug output for lease creation
7591844c197c drm: Fix kerneldoc warnings for drm_lease
]
|
| 52/2 |
2026/10/13 22:28 |
llm |
debugger |
0m
Model:
Tokens:
input: 41348
output: 31
thoughts: 18
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:
**Analyzing the Commit Hash: 32a92f8c8932**
Alright, let's dive into this specific commit hash: `32a92f8c8932`. My immediate instinct is to treat this as a potentially critical piece of the puzzle. I'll need to rapidly ascertain its significance. First, I'm thinking about the repository and branch context. Is this a recent commit, or something older? What's the merge history around it? Knowing that will drastically affect my interpretation.
Next, I'll automatically run through a mental checklist of potential areas this could touch. Is this code, documentation, or configuration? Based on past experience, could this be a security fix, a performance optimization, a refactor, or perhaps a completely innocuous change like a comment update? The format of the hash itself doesnβt tell me much, though a quick scan of the characters might trigger my memory for similar or related commits.
My next step would be to quickly pull up the commit diff, mentally parsing the changes. I'll look for specific keywords or patterns that stand out: API calls, data structure alterations, library updates, or anything that seems outside the ordinary. Are there any potential vulnerabilities that jump out, even in a cursory glance? Iβll immediately look for regressions or introduced bugs. If this commit modifies core functionality, I'll need to give it more attention than minor documentation change.
Depending on what I discover in the diff, my analysis path might diverge. If it looks benign, I'll likely file it away, noting it down for future reference in case any issues pop up. If it raises any red flags, I'll start digging deeper, perhaps by checking related commits or running tests to confirm the impact of these changes. My expertise is knowing where to look and what to look for based on my overall knowledge of the system. I have to make a quick judgement on how much attention to give to this commit.
|
| 53/2 |
2026/10/13 22:28 |
tool |
git-show |
0m
Args: map[Commit:32a92f8c8932 Stat:true]
Results: map[Output:commit 32a92f8c89326985e05dce8b22d3f0aa07a3e1bd
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat Feb 21 20:03:00 2026 -0800
Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
This converts some of the visually simpler cases that have been split
over multiple lines. I only did the ones that are easy to verify the
resulting diff by having just that final GFP_KERNEL argument on the next
line.
Somebody should probably do a proper coccinelle script for this, but for
me the trivial script actually resulted in an assertion failure in the
middle of the script. I probably had made it a bit _too_ trivial.
So after fighting that far a while I decided to just do some of the
syntactically simpler cases with variations of the previous 'sed'
scripts.
The more syntactically complex multi-line cases would mostly really want
whitespace cleanup anyway.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/arm/mach-omap1/mcbsp.c | 3 +-
arch/arm64/kernel/vdso.c | 3 +-
arch/loongarch/kernel/vdso.c | 3 +-
arch/powerpc/kvm/book3s_pr.c | 3 +-
arch/powerpc/mm/book3s64/mmu_context.c | 6 ++--
arch/powerpc/perf/hv-24x7.c | 3 +-
arch/powerpc/perf/imc-pmu.c | 12 +++----
arch/powerpc/platforms/powernv/idle.c | 3 +-
arch/powerpc/platforms/powernv/memtrace.c | 3 +-
arch/powerpc/platforms/powernv/opal-imc.c | 3 +-
arch/powerpc/platforms/powernv/opal-powercap.c | 6 ++--
arch/powerpc/platforms/powernv/opal-psr.c | 3 +-
.../powerpc/platforms/powernv/opal-sensor-groups.c | 6 ++--
arch/powerpc/sysdev/mpic.c | 3 +-
arch/powerpc/sysdev/mpic_msgr.c | 3 +-
arch/riscv/kernel/vdso.c | 3 +-
arch/s390/kvm/pci.c | 3 +-
arch/s390/pci/pci.c | 3 +-
arch/sh/drivers/pci/pcie-sh7786.c | 3 +-
arch/sparc/kernel/smp_64.c | 3 +-
arch/sparc/kernel/sys_sparc_64.c | 6 ++--
arch/um/drivers/vector_kern.c | 6 ++--
arch/x86/events/intel/uncore_snbep.c | 3 +-
arch/x86/hyperv/hv_init.c | 3 +-
arch/x86/kernel/amd_nb.c | 3 +-
arch/x86/kernel/cpu/sgx/main.c | 3 +-
arch/x86/kvm/cpuid.c | 3 +-
arch/x86/kvm/vmx/tdx.c | 3 +-
block/blk-crypto-fallback.c | 3 +-
block/blk-crypto-profile.c | 3 +-
drivers/accel/amdxdna/amdxdna_gem.c | 3 +-
drivers/accel/ethosu/ethosu_drv.c | 3 +-
drivers/accel/ethosu/ethosu_gem.c | 3 +-
.../accel/habanalabs/common/command_submission.c | 3 +-
drivers/accel/habanalabs/common/debugfs.c | 3 +-
drivers/accel/habanalabs/common/hw_queue.c | 3 +-
drivers/accel/habanalabs/common/mmu/mmu.c | 3 +-
drivers/accel/habanalabs/common/security.c | 12 +++----
drivers/accel/habanalabs/gaudi2/gaudi2_security.c | 3 +-
drivers/accel/qaic/qaic_ssr.c | 3 +-
drivers/acpi/apei/einj-core.c | 3 +-
drivers/acpi/cppc_acpi.c | 3 +-
drivers/acpi/mipi-disco-img.c | 3 +-
drivers/acpi/platform_profile.c | 3 +-
drivers/acpi/processor_perflib.c | 3 +-
drivers/acpi/processor_throttling.c | 3 +-
drivers/acpi/riscv/irq.c | 3 +-
drivers/acpi/scan.c | 3 +-
drivers/ata/libahci_platform.c | 3 +-
drivers/atm/he.c | 3 +-
drivers/atm/iphase.c | 12 +++----
drivers/base/physical_location.c | 3 +-
drivers/block/drbd/drbd_receiver.c | 3 +-
drivers/block/ps3vram.c | 3 +-
drivers/block/xen-blkback/blkback.c | 3 +-
drivers/block/xen-blkback/xenbus.c | 9 ++---
drivers/block/xen-blkfront.c | 3 +-
drivers/block/z2ram.c | 3 +-
drivers/bus/mhi/ep/main.c | 3 +-
drivers/bus/mhi/host/boot.c | 3 +-
drivers/bus/mhi/host/init.c | 6 ++--
drivers/char/agp/sworks-agp.c | 3 +-
drivers/char/agp/uninorth-agp.c | 3 +-
drivers/char/virtio_console.c | 3 +-
drivers/clk/aspeed/clk-aspeed.c | 3 +-
drivers/clk/bcm/clk-iproc-asiu.c | 3 +-
drivers/clk/clk-gemini.c | 3 +-
drivers/clk/clk-milbeaut.c | 3 +-
drivers/clk/clk-stm32f4.c | 3 +-
drivers/clk/imx/clk-imx6q.c | 3 +-
drivers/clk/imx/clk-imx6sl.c | 3 +-
drivers/clk/imx/clk-imx6sll.c | 3 +-
drivers/clk/imx/clk-imx6sx.c | 3 +-
drivers/clk/imx/clk-imx6ul.c | 3 +-
drivers/clk/imx/clk-imx7ulp.c | 12 +++----
drivers/clk/imx/clk-imx8mm.c | 3 +-
drivers/clk/ingenic/cgu.c | 3 +-
drivers/clk/mvebu/common.c | 3 +-
drivers/clk/st/clk-flexgen.c | 3 +-
drivers/clk/st/clkgen-pll.c | 3 +-
drivers/clk/tegra/clk.c | 3 +-
drivers/clocksource/dw_apb_timer.c | 3 +-
drivers/clocksource/sh_cmt.c | 3 +-
drivers/clocksource/sh_mtu2.c | 3 +-
drivers/clocksource/sh_tmu.c | 3 +-
drivers/comedi/drivers/ni_670x.c | 3 +-
drivers/connector/cn_proc.c | 3 +-
drivers/cpufreq/acpi-cpufreq.c | 3 +-
drivers/cpufreq/armada-37xx-cpufreq.c | 3 +-
drivers/cpufreq/longhaul.c | 3 +-
drivers/cpufreq/sparc-us2e-cpufreq.c | 3 +-
drivers/cpufreq/sparc-us3-cpufreq.c | 3 +-
drivers/crypto/amcc/crypto4xx_core.c | 3 +-
drivers/crypto/cavium/nitrox/nitrox_mbx.c | 3 +-
drivers/crypto/hisilicon/qm.c | 6 ++--
drivers/crypto/hisilicon/sec2/sec_crypto.c | 3 +-
drivers/crypto/hisilicon/zip/zip_crypto.c | 3 +-
.../crypto/intel/qat/qat_common/adf_fw_counters.c | 3 +-
drivers/crypto/intel/qat/qat_common/adf_sriov.c | 3 +-
drivers/crypto/marvell/octeontx2/otx2_cptpf_main.c | 3 +-
drivers/crypto/stm32/stm32-cryp.c | 3 +-
drivers/crypto/virtio/virtio_crypto_core.c | 3 +-
drivers/devfreq/governor_userspace.c | 3 +-
drivers/dma-buf/udmabuf.c | 3 +-
drivers/dma/amba-pl08x.c | 3 +-
drivers/dma/plx_dma.c | 3 +-
drivers/dma/xilinx/zynqmp_dma.c | 3 +-
drivers/edac/edac_device.c | 9 ++---
drivers/edac/edac_mc.c | 3 +-
drivers/edac/i7core_edac.c | 6 ++--
drivers/extcon/extcon.c | 12 +++----
drivers/firmware/efi/apple-properties.c | 3 +-
drivers/firmware/efi/test/efi_test.c | 3 +-
drivers/firmware/qcom/qcom_tzmem.c | 3 +-
drivers/fpga/dfl.c | 6 ++--
drivers/gpib/agilent_82350b/agilent_82350b.c | 3 +-
drivers/gpib/agilent_82357a/agilent_82357a.c | 3 +-
drivers/gpib/common/gpib_os.c | 3 +-
drivers/gpio/gpio-sim.c | 3 +-
drivers/gpio/gpio-virtuser.c | 3 +-
drivers/gpio/gpiolib-shared.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_acp.c | 12 +++----
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c | 18 ++++------
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c | 3 +-
drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 3 +-
drivers/gpu/drm/amd/amdgpu/atombios_encoders.c | 3 +-
drivers/gpu/drm/amd/amdgpu/dce_v10_0.c | 3 +-
drivers/gpu/drm/amd/amdgpu/dce_v6_0.c | 3 +-
drivers/gpu/drm/amd/amdgpu/dce_v8_0.c | 3 +-
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c | 3 +-
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c | 3 +-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 3 +-
drivers/gpu/drm/amd/amdkfd/kfd_events.c | 3 +-
drivers/gpu/drm/amd/amdkfd/kfd_process.c | 3 +-
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 +++----
drivers/gpu/drm/amd/display/dc/basics/dce_calcs.c | 9 ++---
drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c | 42 ++++++++--------------
.../amd/display/dc/clk_mgr/dcn30/dcn30_clk_mgr.c | 3 +-
.../amd/display/dc/clk_mgr/dcn32/dcn32_clk_mgr.c | 3 +-
.../amd/display/dc/clk_mgr/dcn401/dcn401_clk_mgr.c | 6 ++--
drivers/gpu/drm/amd/display/dc/core/dc.c | 3 +-
.../gpu/drm/amd/display/dc/dce/dce_clock_source.c | 6 ++--
.../display/dc/resource/dce100/dce100_resource.c | 3 +-
.../display/dc/resource/dce110/dce110_resource.c | 9 ++---
.../display/dc/resource/dce112/dce112_resource.c | 3 +-
.../display/dc/resource/dce120/dce120_resource.c | 3 +-
.../amd/display/dc/resource/dce60/dce60_resource.c | 3 +-
.../amd/display/dc/resource/dce80/dce80_resource.c | 3 +-
.../amd/display/dc/resource/dcn10/dcn10_resource.c | 3 +-
.../amd/display/dc/resource/dcn20/dcn20_resource.c | 9 ++---
.../display/dc/resource/dcn201/dcn201_resource.c | 3 +-
.../amd/display/dc/resource/dcn21/dcn21_resource.c | 3 +-
.../amd/display/dc/resource/dcn30/dcn30_resource.c | 9 ++---
.../display/dc/resource/dcn301/dcn301_resource.c | 9 ++---
.../display/dc/resource/dcn302/dcn302_resource.c | 27 +++++---------
.../display/dc/resource/dcn303/dcn303_resource.c | 27 +++++---------
.../amd/display/dc/resource/dcn31/dcn31_resource.c | 12 +++----
.../display/dc/resource/dcn314/dcn314_resource.c | 12 +++----
.../display/dc/resource/dcn315/dcn315_resource.c | 12 +++----
.../display/dc/resource/dcn316/dcn316_resource.c | 12 +++----
.../amd/display/dc/resource/dcn32/dcn32_resource.c | 12 +++----
.../display/dc/resource/dcn321/dcn321_resource.c | 12 +++----
.../amd/display/dc/resource/dcn35/dcn35_resource.c | 12 +++----
.../display/dc/resource/dcn351/dcn351_resource.c | 12 +++----
.../amd/display/dc/resource/dcn36/dcn36_resource.c | 12 +++----
.../display/dc/resource/dcn401/dcn401_resource.c | 12 +++----
.../drm/amd/display/modules/color/color_gamma.c | 6 ++--
drivers/gpu/drm/amd/pm/legacy-dpm/legacy_dpm.c | 3 +-
drivers/gpu/drm/amd/pm/legacy-dpm/si_dpm.c | 3 +-
.../amd/pm/powerplay/hwmgr/process_pptables_v1_0.c | 3 +-
.../drm/amd/pm/powerplay/hwmgr/processpptables.c | 21 ++++-------
.../pm/powerplay/hwmgr/vega10_processpptables.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 3 +-
.../drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 3 +-
.../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 3 +-
.../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0.c | 3 +-
.../gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c | 3 +-
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0.c | 3 +-
.../gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c | 3 +-
drivers/gpu/drm/arm/malidp_mw.c | 3 +-
drivers/gpu/drm/ast/ast_dp.c | 3 +-
drivers/gpu/drm/drm_atomic.c | 3 +-
drivers/gpu/drm/drm_atomic_helper.c | 3 +-
drivers/gpu/drm/drm_atomic_state_helper.c | 3 +-
drivers/gpu/drm/drm_buddy.c | 6 ++--
drivers/gpu/drm/drm_client_modeset.c | 3 +-
drivers/gpu/drm/drm_gem_atomic_helper.c | 3 +-
drivers/gpu/drm/drm_lease.c | 3 +-
drivers/gpu/drm/drm_plane.c | 3 +-
drivers/gpu/drm/drm_plane_helper.c | 3 +-
drivers/gpu/drm/drm_writeback.c | 3 +-
drivers/gpu/drm/etnaviv/etnaviv_flop_reset.c | 3 +-
drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 3 +-
drivers/gpu/drm/exynos/exynos_drm_g2d.c | 3 +-
drivers/gpu/drm/gma500/intel_gmbus.c | 3 +-
drivers/gpu/drm/gma500/psb_intel_sdvo.c | 12 +++----
drivers/gpu/drm/gud/gud_connector.c | 6 ++--
drivers/gpu/drm/gud/gud_drv.c | 3 +-
drivers/gpu/drm/i915/display/intel_bios.c | 3 +-
drivers/gpu/drm/i915/display/intel_dp_tunnel.c | 3 +-
drivers/gpu/drm/i915/gem/i915_gem_create.c | 3 +-
drivers/gpu/drm/i915/gt/intel_ggtt_fencing.c | 3 +-
drivers/gpu/drm/i915/gt/intel_workarounds.c | 3 +-
drivers/gpu/drm/i915/gt/selftest_execlists.c | 3 +-
drivers/gpu/drm/i915/gt/selftest_timeline.c | 6 ++--
drivers/gpu/drm/i915/gt/uc/intel_guc_capture.c | 3 +-
drivers/gpu/drm/i915/i915_cmd_parser.c | 3 +-
drivers/gpu/drm/i915/selftests/i915_request.c | 3 +-
drivers/gpu/drm/mgag200/mgag200_mode.c | 3 +-
drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 3 +-
drivers/gpu/drm/nouveau/dispnv04/overlay.c | 6 ++--
drivers/gpu/drm/nouveau/nouveau_svm.c | 3 +-
drivers/gpu/drm/nouveau/nvif/fifo.c | 3 +-
drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 3 +-
drivers/gpu/drm/qxl/qxl_display.c | 3 +-
drivers/gpu/drm/qxl/qxl_ioctl.c | 3 +-
drivers/gpu/drm/radeon/atombios_encoders.c | 6 ++--
drivers/gpu/drm/radeon/btc_dpm.c | 3 +-
drivers/gpu/drm/radeon/ci_dpm.c | 3 +-
drivers/gpu/drm/radeon/ni_dpm.c | 3 +-
drivers/gpu/drm/radeon/r600_dpm.c | 3 +-
drivers/gpu/drm/radeon/radeon_atombios.c | 12 +++----
drivers/gpu/drm/radeon/radeon_combios.c | 3 +-
drivers/gpu/drm/radeon/radeon_connectors.c | 18 ++++------
drivers/gpu/drm/radeon/radeon_cs.c | 3 +-
drivers/gpu/drm/radeon/radeon_display.c | 15 +++-----
drivers/gpu/drm/radeon/radeon_vm.c | 3 +-
drivers/gpu/drm/radeon/si_dpm.c | 3 +-
drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 3 +-
drivers/gpu/drm/scheduler/sched_main.c | 3 +-
drivers/gpu/drm/tiny/appletbdrm.c | 3 +-
drivers/gpu/drm/ttm/ttm_tt.c | 3 +-
drivers/gpu/drm/v3d/v3d_submit.c | 12 +++----
drivers/gpu/drm/vc4/vc4_bo.c | 3 +-
drivers/gpu/drm/virtio/virtgpu_fence.c | 3 +-
drivers/gpu/drm/virtio/virtgpu_prime.c | 3 +-
drivers/gpu/drm/vkms/vkms_crtc.c | 6 ++--
drivers/gpu/drm/vmwgfx/vmwgfx_blit.c | 6 ++--
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c | 3 +-
drivers/gpu/drm/vmwgfx/vmwgfx_surface.c | 3 +-
drivers/gpu/drm/xe/xe_eu_stall.c | 3 +-
drivers/gpu/drm/xe/xe_oa.c | 3 +-
drivers/gpu/drm/xe/xe_pt.c | 3 +-
drivers/gpu/drm/xe/xe_vm_madvise.c | 3 +-
drivers/gpu/drm/xen/xen_drm_front_gem.c | 3 +-
drivers/gpu/host1x/channel.c | 3 +-
drivers/greybus/manifest.c | 3 +-
drivers/greybus/svc.c | 3 +-
drivers/hid/hid-google-hammer.c | 3 +-
drivers/hid/hid-haptic.c | 3 +-
drivers/hid/intel-ish-hid/ishtp/hbm.c | 3 +-
drivers/hv/hv.c | 3 +-
drivers/hv/ring_buffer.c | 3 +-
drivers/hwmon/coretemp.c | 3 +-
drivers/hwmon/ibmpex.c | 3 +-
drivers/hwtracing/coresight/coresight-tmc-etr.c | 3 +-
drivers/i2c/busses/i2c-qcom-geni.c | 3 +-
drivers/i2c/i2c-dev.c | 3 +-
drivers/i3c/master.c | 3 +-
drivers/i3c/master/mipi-i3c-hci/dma.c | 3 +-
drivers/infiniband/core/cache.c | 3 +-
drivers/infiniband/core/cm.c | 3 +-
drivers/infiniband/core/cma.c | 9 ++---
drivers/infiniband/core/roce_gid_mgmt.c | 3 +-
drivers/infiniband/core/rw.c | 6 ++--
drivers/infiniband/core/sa_query.c | 3 +-
drivers/infiniband/core/sysfs.c | 9 ++---
drivers/infiniband/core/user_mad.c | 3 +-
drivers/infiniband/core/uverbs_cmd.c | 3 +-
drivers/infiniband/hw/bng_re/bng_fw.c | 3 +-
drivers/infiniband/hw/bnxt_re/ib_verbs.c | 6 ++--
drivers/infiniband/hw/bnxt_re/qplib_fp.c | 3 +-
drivers/infiniband/hw/bnxt_re/qplib_rcfw.c | 3 +-
drivers/infiniband/hw/cxgb4/qp.c | 9 ++---
drivers/infiniband/hw/efa/efa_verbs.c | 3 +-
drivers/infiniband/hw/hfi1/pio.c | 6 ++--
drivers/infiniband/hw/hfi1/user_exp_rcv.c | 3 +-
drivers/infiniband/hw/hns/hns_roce_main.c | 3 +-
drivers/infiniband/hw/ionic/ionic_admin.c | 6 ++--
drivers/infiniband/hw/ionic/ionic_controlpath.c | 6 ++--
drivers/infiniband/hw/ionic/ionic_hw_stats.c | 9 ++---
drivers/infiniband/hw/irdma/cm.c | 6 ++--
drivers/infiniband/hw/irdma/icrdma_if.c | 3 +-
drivers/infiniband/hw/irdma/ig3rdma_if.c | 3 +-
drivers/infiniband/hw/irdma/verbs.c | 6 ++--
drivers/infiniband/hw/mlx4/alias_GUID.c | 3 +-
drivers/infiniband/hw/mlx4/mad.c | 3 +-
drivers/infiniband/hw/mlx4/main.c | 3 +-
drivers/infiniband/hw/mlx4/sysfs.c | 3 +-
drivers/infiniband/hw/mlx5/counters.c | 6 ++--
drivers/infiniband/hw/mlx5/fs.c | 6 ++--
drivers/infiniband/hw/mlx5/gsi.c | 3 +-
drivers/infiniband/hw/mlx5/mr.c | 3 +-
drivers/infiniband/hw/mlx5/qp.c | 3 +-
drivers/infiniband/hw/mthca/mthca_allocator.c | 3 +-
drivers/infiniband/hw/mthca/mthca_mr.c | 3 +-
drivers/infiniband/hw/ocrdma/ocrdma_main.c | 6 ++--
drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 3 +-
drivers/infiniband/hw/vmw_pvrdma/pvrdma_main.c | 9 ++---
drivers/infiniband/ulp/ipoib/ipoib_main.c | 3 +-
drivers/infiniband/ulp/isert/ib_isert.c | 3 +-
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 3 +-
drivers/infiniband/ulp/rtrs/rtrs-srv.c | 6 ++--
drivers/infiniband/ulp/srpt/ib_srpt.c | 3 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 +-
drivers/ipack/carriers/tpci200.c | 3 +-
drivers/irqchip/irq-alpine-msi.c | 3 +-
drivers/irqchip/irq-bcm6345-l1.c | 3 +-
drivers/irqchip/irq-bcm7038-l1.c | 3 +-
drivers/irqchip/irq-bcm7120-l2.c | 3 +-
drivers/irqchip/irq-gic-v3-its.c | 3 +-
drivers/irqchip/irq-gic-v5-iwb.c | 3 +-
drivers/irqchip/irq-riscv-intc.c | 3 +-
drivers/isdn/capi/capi.c | 3 +-
drivers/macintosh/windfarm_pm121.c | 3 +-
drivers/macintosh/windfarm_pm91.c | 6 ++--
drivers/md/dm-snap-persistent.c | 3 +-
drivers/md/dm-snap.c | 3 +-
drivers/md/dm-zoned-metadata.c | 3 +-
drivers/md/raid0.c | 3 +-
drivers/md/raid1.c | 6 ++--
drivers/md/raid5-ppl.c | 3 +-
drivers/md/raid5.c | 3 +-
drivers/media/common/b2c2/flexcop.c | 3 +-
drivers/media/dvb-core/dvbdev.c | 6 ++--
drivers/media/dvb-frontends/dib0070.c | 3 +-
drivers/media/dvb-frontends/dib0090.c | 3 +-
drivers/media/dvb-frontends/s5h1420.c | 3 +-
drivers/media/dvb-frontends/stv0900_core.c | 6 ++--
.../media/platform/nxp/imx8-isi/imx8-isi-core.c | 3 +-
drivers/media/platform/renesas/vsp1/vsp1_video.c | 3 +-
drivers/media/test-drivers/vidtv/vidtv_psi.c | 3 +-
drivers/media/test-drivers/vimc/vimc-core.c | 3 +-
drivers/media/usb/dvb-usb/cinergyT2-fe.c | 3 +-
drivers/media/usb/dvb-usb/vp702x-fe.c | 3 +-
drivers/media/usb/dvb-usb/vp7045-fe.c | 3 +-
drivers/media/usb/pvrusb2/pvrusb2-hdw.c | 3 +-
drivers/media/v4l2-core/v4l2-ctrls-core.c | 3 +-
drivers/media/v4l2-core/v4l2-flash-led-class.c | 3 +-
drivers/media/v4l2-core/v4l2-subdev.c | 3 +-
drivers/message/fusion/mptlan.c | 6 ++--
drivers/message/fusion/mptsas.c | 3 +-
drivers/mfd/timberdale.c | 3 +-
drivers/misc/altera-stapl/altera.c | 3 +-
drivers/misc/fastrpc.c | 6 ++--
drivers/misc/genwqe/card_ddcb.c | 6 ++--
drivers/misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.c | 6 ++--
drivers/misc/mei/interrupt.c | 3 +-
drivers/misc/sgi-xp/xpc_main.c | 6 ++--
drivers/misc/sgi-xp/xpc_uv.c | 3 +-
drivers/mtd/chips/cfi_cmdset_0001.c | 3 +-
drivers/mtd/chips/cfi_probe.c | 3 +-
drivers/mtd/chips/jedec_probe.c | 3 +-
drivers/mtd/ftl.c | 3 +-
drivers/mtd/mtdconcat.c | 3 +-
drivers/mtd/parsers/bcm47xxpart.c | 3 +-
drivers/mtd/parsers/parser_trx.c | 3 +-
drivers/mtd/parsers/scpart.c | 3 +-
drivers/mtd/rfd_ftl.c | 3 +-
drivers/mtd/sm_ftl.c | 3 +-
drivers/mtd/ubi/eba.c | 6 ++--
drivers/net/bonding/bond_main.c | 6 ++--
drivers/net/dsa/ocelot/felix.c | 3 +-
drivers/net/dsa/sja1105/sja1105_devlink.c | 3 +-
drivers/net/ethernet/amd/pcnet32.c | 6 ++--
drivers/net/ethernet/apm/xgene-v2/main.c | 3 +-
drivers/net/ethernet/aquantia/atlantic/aq_ptp.c | 3 +-
drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c | 3 +-
drivers/net/ethernet/broadcom/bcm63xx_enet.c | 6 ++--
drivers/net/ethernet/broadcom/bcmsysport.c | 3 +-
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c | 18 ++++------
drivers/net/ethernet/broadcom/bnge/bnge_rmem.c | 3 +-
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 9 ++---
drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 3 +-
drivers/net/ethernet/broadcom/bnx2x/bnx2x_sriov.c | 6 ++--
drivers/net/ethernet/broadcom/bnxt/bnxt.c | 12 +++----
drivers/net/ethernet/broadcom/bnxt/bnxt_ulp.c | 3 +-
drivers/net/ethernet/broadcom/cnic.c | 9 ++---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 6 ++--
drivers/net/ethernet/broadcom/sb1250-mac.c | 3 +-
drivers/net/ethernet/brocade/bna/bnad.c | 3 +-
drivers/net/ethernet/calxeda/xgmac.c | 6 ++--
drivers/net/ethernet/cavium/liquidio/lio_core.c | 6 ++--
drivers/net/ethernet/chelsio/cxgb4/cxgb4_ethtool.c | 3 +-
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 3 +-
.../net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c | 3 +-
.../net/ethernet/chelsio/cxgb4/cxgb4_tc_mqprio.c | 6 ++--
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c | 9 ++---
drivers/net/ethernet/cisco/enic/enic_main.c | 9 ++---
drivers/net/ethernet/emulex/benet/be_main.c | 6 ++--
.../net/ethernet/freescale/dpaa2/dpaa2-switch.c | 6 ++--
drivers/net/ethernet/freescale/enetc/enetc.c | 3 +-
drivers/net/ethernet/freescale/gianfar.c | 6 ++--
drivers/net/ethernet/google/gve/gve_ethtool.c | 3 +-
drivers/net/ethernet/google/gve/gve_main.c | 3 +-
drivers/net/ethernet/google/gve/gve_rx.c | 3 +-
drivers/net/ethernet/google/gve/gve_rx_dqo.c | 3 +-
drivers/net/ethernet/google/gve/gve_tx.c | 3 +-
drivers/net/ethernet/google/gve/gve_tx_dqo.c | 3 +-
drivers/net/ethernet/hisilicon/hns/hnae.c | 3 +-
drivers/net/ethernet/huawei/hinic3/hinic3_cmdq.c | 3 +-
.../net/ethernet/huawei/hinic3/hinic3_netdev_ops.c | 3 +-
.../ethernet/huawei/hinic3/hinic3_queue_common.c | 3 +-
drivers/net/ethernet/huawei/hinic3/hinic3_rx.c | 3 +-
drivers/net/ethernet/huawei/hinic3/hinic3_tx.c | 3 +-
drivers/net/ethernet/ibm/ibmvnic.c | 15 +++-----
drivers/net/ethernet/intel/e1000/e1000_ethtool.c | 12 +++----
drivers/net/ethernet/intel/e1000e/ethtool.c | 6 ++--
drivers/net/ethernet/intel/fm10k/fm10k_main.c | 3 +-
drivers/net/ethernet/intel/i40e/i40e_debugfs.c | 3 +-
drivers/net/ethernet/intel/i40e/i40e_ethtool.c | 3 +-
drivers/net/ethernet/intel/iavf/iavf_main.c | 9 ++---
drivers/net/ethernet/intel/ice/ice_arfs.c | 6 ++--
drivers/net/ethernet/intel/ice/ice_common.c | 3 +-
drivers/net/ethernet/intel/ice/ice_lib.c | 9 ++---
drivers/net/ethernet/intel/idpf/idpf_controlq.c | 3 +-
.../net/ethernet/intel/idpf/idpf_controlq_setup.c | 6 ++--
drivers/net/ethernet/intel/idpf/idpf_lib.c | 3 +-
drivers/net/ethernet/intel/idpf/idpf_txrx.c | 24 +++++--------
drivers/net/ethernet/intel/idpf/idpf_virtchnl.c | 12 +++----
.../net/ethernet/intel/idpf/idpf_virtchnl_ptp.c | 3 +-
drivers/net/ethernet/intel/igc/igc_main.c | 3 +-
drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c | 6 ++--
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c | 3 +-
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 3 +-
drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c | 3 +-
drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 3 +-
drivers/net/ethernet/intel/libie/fwlog.c | 3 +-
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 3 +-
.../net/ethernet/marvell/octeon_ep/octep_main.c | 3 +-
.../ethernet/marvell/octeon_ep_vf/octep_vf_main.c | 3 +-
.../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 6 ++--
.../ethernet/marvell/prestera/prestera_counter.c | 3 +-
drivers/net/ethernet/marvell/sky2.c | 6 ++--
drivers/net/ethernet/mellanox/mlx4/alloc.c | 3 +-
drivers/net/ethernet/mellanox/mlx4/cmd.c | 9 ++---
drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 6 ++--
drivers/net/ethernet/mellanox/mlx4/main.c | 6 ++--
.../net/ethernet/mellanox/mlx4/resource_tracker.c | 12 +++----
drivers/net/ethernet/mellanox/mlx5/core/en/qos.c | 3 +-
.../net/ethernet/mellanox/mlx5/core/en/xsk/pool.c | 3 +-
drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 3 +-
.../net/ethernet/mellanox/mlx5/core/fpga/conn.c | 6 ++--
drivers/net/ethernet/mellanox/mlx5/core/rl.c | 3 +-
.../mellanox/mlx5/core/steering/hws/action.c | 3 +-
.../ethernet/mellanox/mlx5/core/steering/hws/bwc.c | 3 +-
.../mellanox/mlx5/core/steering/hws/fs_hws.c | 9 ++---
.../mellanox/mlx5/core/steering/hws/matcher.c | 3 +-
.../mellanox/mlx5/core/steering/hws/send.c | 3 +-
.../mellanox/mlx5/core/steering/sws/dr_buddy.c | 6 ++--
.../mellanox/mlx5/core/steering/sws/dr_icm_pool.c | 3 +-
.../mellanox/mlx5/core/steering/sws/fs_dr.c | 6 ++--
.../ethernet/mellanox/mlxsw/core_acl_flex_keys.c | 3 +-
drivers/net/ethernet/mellanox/mlxsw/core_hwmon.c | 3 +-
drivers/net/ethernet/mellanox/mlxsw/core_thermal.c | 3 +-
drivers/net/ethernet/mellanox/mlxsw/pci.c | 3 +-
drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 6 ++--
.../mellanox/mlxsw/spectrum_acl_bloom_filter.c | 3 +-
.../net/ethernet/mellanox/mlxsw/spectrum_buffers.c | 3 +-
drivers/net/ethernet/mellanox/mlxsw/spectrum_dcb.c | 9 ++---
drivers/net/ethernet/mellanox/mlxsw/spectrum_nve.c | 3 +-
.../net/ethernet/mellanox/mlxsw/spectrum_router.c | 6 ++--
drivers/net/ethernet/micrel/ksz884x.c | 3 +-
.../net/ethernet/microchip/lan966x/lan966x_fdma.c | 3 +-
.../net/ethernet/microchip/sparx5/sparx5_main.c | 3 +-
drivers/net/ethernet/microsoft/mana/mana_en.c | 6 ++--
drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 3 +-
drivers/net/ethernet/netronome/nfp/bpf/offload.c | 3 +-
.../net/ethernet/netronome/nfp/flower/lag_conf.c | 3 +-
drivers/net/ethernet/netronome/nfp/nfd3/rings.c | 3 +-
drivers/net/ethernet/netronome/nfp/nfdk/rings.c | 3 +-
.../net/ethernet/netronome/nfp/nfp_net_common.c | 3 +-
drivers/net/ethernet/netronome/nfp/nfp_net_main.c | 3 +-
.../net/ethernet/netronome/nfp/nfp_shared_buf.c | 3 +-
drivers/net/ethernet/nvidia/forcedeth.c | 6 ++--
drivers/net/ethernet/pasemi/pasemi_mac.c | 6 ++--
.../net/ethernet/qlogic/netxen/netxen_nic_init.c | 3 +-
drivers/net/ethernet/qlogic/qed/qed_cxt.c | 6 ++--
drivers/net/ethernet/qlogic/qed/qed_debug.c | 3 +-
.../net/ethernet/qlogic/qed/qed_init_fw_funcs.c | 3 +-
drivers/net/ethernet/qlogic/qede/qede_main.c | 9 ++---
drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 3 +-
.../ethernet/qlogic/qlcnic/qlcnic_sriov_common.c | 3 +-
drivers/net/ethernet/renesas/ravb_main.c | 3 +-
drivers/net/ethernet/renesas/rswitch_main.c | 6 ++--
drivers/net/ethernet/renesas/sh_eth.c | 6 ++--
drivers/net/ethernet/rocker/rocker_main.c | 3 +-
drivers/net/ethernet/samsung/sxgbe/sxgbe_main.c | 3 +-
drivers/net/ethernet/sfc/falcon/rx.c | 3 +-
drivers/net/ethernet/sfc/falcon/selftest.c | 3 +-
drivers/net/ethernet/sfc/mcdi_mon.c | 3 +-
drivers/net/ethernet/sfc/rx_common.c | 3 +-
drivers/net/ethernet/sfc/selftest.c | 3 +-
drivers/net/ethernet/sfc/siena/mcdi_mon.c | 3 +-
drivers/net/ethernet/sfc/siena/rx_common.c | 3 +-
drivers/net/ethernet/sfc/siena/selftest.c | 3 +-
drivers/net/ethernet/smsc/smsc9420.c | 6 ++--
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 ++--
drivers/net/ethernet/synopsys/dwc-xlgmac-desc.c | 9 ++---
drivers/net/ethernet/ti/k3-cppi-desc-pool.c | 3 +-
drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++--
drivers/net/hyperv/netvsc_drv.c | 3 +-
drivers/net/ieee802154/ca8210.c | 3 +-
drivers/net/ipa/gsi_trans.c | 3 +-
drivers/net/pcs/pcs-rzn1-miic.c | 3 +-
drivers/net/usb/hso.c | 3 +-
drivers/net/usb/smsc75xx.c | 3 +-
drivers/net/wan/fsl_ucc_hdlc.c | 6 ++--
drivers/net/wireless/ath/ath10k/ce.c | 12 +++----
drivers/net/wireless/ath/ath10k/mac.c | 3 +-
drivers/net/wireless/ath/ath12k/dp.c | 3 +-
drivers/net/wireless/ath/ath12k/mac.c | 6 ++--
drivers/net/wireless/ath/ath5k/eeprom.c | 12 +++----
drivers/net/wireless/ath/wil6210/fw_inc.c | 3 +-
drivers/net/wireless/ath/wil6210/pmc.c | 3 +-
drivers/net/wireless/ath/wil6210/txrx_edma.c | 3 +-
drivers/net/wireless/broadcom/b43/debugfs.c | 3 +-
drivers/net/wireless/broadcom/b43/dma.c | 3 +-
drivers/net/wireless/broadcom/b43legacy/dma.c | 3 +-
.../wireless/broadcom/brcm80211/brcmfmac/pcie.c | 3 +-
drivers/net/wireless/intel/ipw2x00/ipw2100.c | 3 +-
drivers/net/wireless/intel/ipw2x00/libipw_module.c | 3 +-
drivers/net/wireless/intel/iwlegacy/common.c | 9 ++---
drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 3 +-
drivers/net/wireless/intel/iwlwifi/iwl-nvm-parse.c | 15 +++-----
drivers/net/wireless/intel/iwlwifi/mld/d3.c | 6 ++--
drivers/net/wireless/intel/iwlwifi/mld/sta.c | 3 +-
drivers/net/wireless/intel/iwlwifi/mld/time_sync.c | 3 +-
drivers/net/wireless/intel/iwlwifi/mvm/sta.c | 3 +-
.../net/wireless/intel/iwlwifi/pcie/gen1_2/rx.c | 3 +-
.../net/wireless/intel/iwlwifi/pcie/gen1_2/tx.c | 3 +-
drivers/net/wireless/intersil/p54/eeprom.c | 6 ++--
drivers/net/wireless/marvell/mwifiex/scan.c | 3 +-
drivers/net/wireless/microchip/wilc1000/cfg80211.c | 9 ++---
drivers/net/wireless/quantenna/qtnfmac/commands.c | 12 +++----
drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 3 +-
.../net/wireless/realtek/rtlwifi/rtl8192du/sw.c | 6 ++--
drivers/net/wireless/realtek/rtw88/sdio.c | 3 +-
drivers/net/wireless/realtek/rtw89/usb.c | 3 +-
drivers/net/wireless/st/cw1200/debug.c | 3 +-
drivers/net/wireless/st/cw1200/queue.c | 6 ++--
drivers/net/wireless/st/cw1200/scan.c | 3 +-
drivers/net/wireless/ti/wl1251/init.c | 3 +-
drivers/net/wwan/iosm/iosm_ipc_protocol.c | 3 +-
drivers/net/xen-netfront.c | 3 +-
drivers/nvdimm/btt.c | 6 ++--
drivers/nvdimm/nd_perf.c | 3 +-
drivers/nvdimm/region_devs.c | 3 +-
drivers/nvme/host/auth.c | 3 +-
drivers/nvme/host/rdma.c | 3 +-
drivers/nvme/host/tcp.c | 3 +-
drivers/nvme/target/configfs.c | 3 +-
drivers/nvme/target/core.c | 6 ++--
drivers/nvme/target/fc.c | 3 +-
drivers/nvme/target/loop.c | 3 +-
drivers/nvme/target/pci-epf.c | 6 ++--
drivers/opp/core.c | 3 +-
drivers/opp/of.c | 3 +-
drivers/pci/hotplug/cpqphp_nvram.c | 3 +-
drivers/pci/hotplug/cpqphp_pci.c | 21 ++++-------
drivers/pci/hotplug/ibmphp_ebda.c | 9 ++---
drivers/pci/hotplug/ibmphp_pci.c | 36 +++++++------------
drivers/pci/hotplug/ibmphp_res.c | 21 ++++-------
drivers/perf/riscv_pmu_sbi.c | 3 +-
drivers/pinctrl/bcm/pinctrl-bcm2835.c | 3 +-
drivers/pinctrl/berlin/berlin.c | 3 +-
drivers/pinctrl/pinctrl-apple-gpio.c | 3 +-
drivers/pinctrl/sunxi/pinctrl-sunxi.c | 3 +-
drivers/pinctrl/vt8500/pinctrl-wmt.c | 3 +-
drivers/platform/chrome/chromeos_laptop.c | 3 +-
drivers/platform/x86/asus-armoury.c | 6 ++--
drivers/platform/x86/dell/dell-smbios-base.c | 3 +-
drivers/platform/x86/intel/int3472/tps68470.c | 3 +-
.../x86/intel/speed_select_if/isst_if_common.c | 6 ++--
.../x86/intel/uncore-frequency/uncore-frequency.c | 3 +-
drivers/platform/x86/sony-laptop.c | 3 +-
drivers/platform/x86/uv_sysfs.c | 12 +++----
drivers/platform/x86/x86-android-tablets/core.c | 3 +-
drivers/powercap/intel_rapl_common.c | 3 +-
drivers/regulator/of_regulator.c | 3 +-
drivers/s390/block/dcssblk.c | 6 ++--
drivers/s390/block/scm_blk.c | 3 +-
drivers/s390/char/con3270.c | 3 +-
drivers/s390/cio/css.c | 3 +-
drivers/s390/cio/qdio_thinint.c | 3 +-
drivers/s390/cio/vfio_ccw_ops.c | 3 +-
drivers/scsi/53c700.c | 3 +-
drivers/scsi/BusLogic.c | 3 +-
drivers/scsi/aacraid/linit.c | 3 +-
drivers/scsi/be2iscsi/be_main.c | 9 ++---
drivers/scsi/bnx2fc/bnx2fc_fcoe.c | 3 +-
drivers/scsi/bnx2fc/bnx2fc_io.c | 3 +-
drivers/scsi/csiostor/csio_lnode.c | 3 +-
drivers/scsi/elx/efct/efct_hw.c | 3 +-
drivers/scsi/esas2r/esas2r_init.c | 6 ++--
drivers/scsi/ibmvscsi/ibmvfc.c | 3 +-
drivers/scsi/ipr.c | 3 +-
drivers/scsi/lpfc/lpfc_els.c | 6 ++--
drivers/scsi/lpfc/lpfc_init.c | 3 +-
drivers/scsi/lpfc/lpfc_mbox.c | 3 +-
drivers/scsi/lpfc/lpfc_mem.c | 3 +-
drivers/scsi/lpfc/lpfc_sli.c | 3 +-
drivers/scsi/lpfc/lpfc_vport.c | 3 +-
drivers/scsi/megaraid/megaraid_mm.c | 6 ++--
drivers/scsi/megaraid/megaraid_sas_base.c | 6 ++--
drivers/scsi/megaraid/megaraid_sas_fusion.c | 6 ++--
drivers/scsi/mpi3mr/mpi3mr_fw.c | 3 +-
drivers/scsi/mpi3mr/mpi3mr_transport.c | 3 +-
drivers/scsi/mpt3sas/mpt3sas_base.c | 3 +-
drivers/scsi/mpt3sas/mpt3sas_ctl.c | 6 ++--
drivers/scsi/mpt3sas/mpt3sas_scsih.c | 6 ++--
drivers/scsi/mvumi.c | 3 +-
drivers/scsi/qedf/qedf_io.c | 6 ++--
drivers/scsi/qedf/qedf_main.c | 3 +-
drivers/scsi/qedi/qedi_main.c | 3 +-
drivers/scsi/qla2xxx/qla_init.c | 6 ++--
drivers/scsi/qla2xxx/qla_inline.h | 3 +-
drivers/scsi/qla2xxx/qla_isr.c | 3 +-
drivers/scsi/qla2xxx/qla_mid.c | 3 +-
drivers/scsi/qla2xxx/qla_os.c | 9 ++---
drivers/scsi/qla2xxx/qla_target.c | 3 +-
drivers/scsi/scsi_debug.c | 6 ++--
drivers/scsi/ses.c | 3 +-
drivers/scsi/smartpqi/smartpqi_init.c | 3 +-
drivers/scsi/vmw_pvscsi.c | 3 +-
drivers/soc/qcom/pdr_interface.c | 3 +-
drivers/soc/renesas/rz-sysc.c | 3 +-
drivers/soundwire/amd_init.c | 6 ++--
drivers/soundwire/amd_manager.c | 3 +-
drivers/soundwire/intel.c | 3 +-
drivers/soundwire/intel_ace2x.c | 3 +-
drivers/soundwire/intel_init.c | 3 +-
drivers/spi/spi-bcm-qspi.c | 3 +-
drivers/spi/spi-mpc52xx.c | 3 +-
drivers/spi/spi-virtio.c | 3 +-
drivers/staging/greybus/light.c | 9 ++---
drivers/staging/greybus/power_supply.c | 3 +-
drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 9 ++---
drivers/staging/media/atomisp/pci/sh_css.c | 6 ++--
.../staging/media/atomisp/pci/sh_css_firmware.c | 3 +-
drivers/staging/media/atomisp/pci/sh_css_params.c | 3 +-
drivers/staging/vme_user/vme_tsi148.c | 3 +-
drivers/target/target_core_iblock.c | 3 +-
drivers/target/target_core_pr.c | 3 +-
drivers/tee/qcomtee/call.c | 3 +-
drivers/tee/qcomtee/mem_obj.c | 3 +-
drivers/tee/tee_core.c | 9 ++---
drivers/thermal/intel/intel_hfi.c | 3 +-
drivers/thermal/testing/zone.c | 15 +++-----
drivers/thermal/thermal_of.c | 3 +-
drivers/thunderbolt/switch.c | 3 +-
drivers/tty/goldfish.c | 3 +-
drivers/tty/serial/8250/8250_platform.c | 6 ++--
drivers/tty/serial/jsm/jsm_tty.c | 3 +-
drivers/tty/serial/serial_core.c | 3 +-
drivers/tty/tty_io.c | 3 +-
drivers/tty/vt/keyboard.c | 3 +-
drivers/usb/core/hcd.c | 6 ++--
drivers/usb/gadget/function/f_midi.c | 3 +-
drivers/usb/gadget/function/f_midi2.c | 3 +-
drivers/usb/gadget/udc/bdc/bdc_core.c | 3 +-
drivers/usb/host/uhci-hcd.c | 3 +-
drivers/usb/host/xhci-mtk-sch.c | 3 +-
drivers/usb/mon/mon_bin.c | 3 +-
drivers/usb/serial/mos7840.c | 3 +-
drivers/usb/typec/ucsi/ucsi.c | 3 +-
drivers/usb/usbip/vhci_sysfs.c | 6 ++--
drivers/vdpa/mlx5/net/mlx5_vnet.c | 3 +-
drivers/vdpa/vdpa_sim/vdpa_sim.c | 6 ++--
drivers/vfio/pci/pds/dirty.c | 3 +-
drivers/vfio/pci/vfio_pci_dmabuf.c | 3 +-
drivers/vhost/net.c | 3 +-
drivers/vhost/scsi.c | 6 ++--
drivers/vhost/vhost.c | 3 +-
drivers/video/fbdev/arkfb.c | 3 +-
drivers/video/fbdev/mmp/fb/mmpfb.c | 3 +-
drivers/video/fbdev/omap2/omapfb/dss/manager.c | 3 +-
drivers/video/fbdev/smscufx.c | 3 +-
drivers/video/fbdev/udlfb.c | 3 +-
drivers/video/fbdev/uvesafb.c | 3 +-
drivers/video/of_display_timing.c | 3 +-
drivers/virt/acrn/mm.c | 3 +-
drivers/virt/nitro_enclaves/ne_misc_dev.c | 3 +-
drivers/virtio/virtio_pci_common.c | 6 ++--
drivers/xen/gntdev.c | 6 ++--
drivers/xen/grant-table.c | 3 +-
drivers/xen/xen-acpi-processor.c | 6 ++--
drivers/xen/xen-scsiback.c | 3 +-
fs/aio.c | 3 +-
fs/binfmt_elf.c | 3 +-
fs/btrfs/ioctl.c | 3 +-
fs/btrfs/tests/btrfs-tests.c | 3 +-
fs/btrfs/zoned.c | 3 +-
fs/cachefiles/ondemand.c | 3 +-
fs/coredump.c | 3 +-
fs/erofs/xattr.c | 3 +-
fs/exfat/balloc.c | 3 +-
fs/ext2/super.c | 3 +-
fs/ext4/orphan.c | 3 +-
fs/fhandle.c | 6 ++--
fs/jbd2/journal.c | 3 +-
fs/jffs2/summary.c | 12 +++----
fs/jffs2/xattr.c | 3 +-
fs/mbcache.c | 3 +-
fs/nfsd/nfs4proc.c | 3 +-
fs/nfsd/nfs4state.c | 6 ++--
fs/ocfs2/cluster/heartbeat.c | 6 ++--
fs/ocfs2/journal.c | 3 +-
fs/ocfs2/slot_map.c | 3 +-
fs/orangefs/orangefs-bufmap.c | 3 +-
fs/pstore/ram.c | 3 +-
fs/select.c | 3 +-
fs/smb/client/misc.c | 3 +-
fs/xfs/xfs_super.c | 3 +-
fs/xfs/xfs_zone_gc.c | 3 +-
fs/zonefs/super.c | 6 ++--
include/net/udp.h | 3 +-
kernel/bpf/core.c | 3 +-
kernel/gcov/fs.c | 3 +-
kernel/gcov/gcc_4_7.c | 3 +-
kernel/locking/locktorture.c | 3 +-
kernel/padata.c | 3 +-
kernel/params.c | 3 +-
kernel/rcu/rcuscale.c | 6 ++--
kernel/rcu/rcutorture.c | 3 +-
kernel/sched/ext.c | 3 +-
kernel/trace/trace.c | 9 ++---
kernel/trace/trace_events_hist.c | 3 +-
kernel/trace/trace_probe.c | 3 +-
kernel/unwind/deferred.c | 3 +-
lib/assoc_array.c | 3 +-
lib/kunit/executor.c | 3 +-
lib/tests/test_ratelimit.c | 3 +-
mm/damon/sysfs-schemes.c | 18 ++++------
mm/damon/sysfs.c | 3 +-
mm/damon/tests/core-kunit.h | 6 ++--
mm/damon/vaddr.c | 3 +-
mm/ksm.c | 3 +-
mm/memory-tiers.c | 3 +-
mm/mempolicy.c | 9 ++---
mm/mmu_notifier.c | 3 +-
mm/swapfile.c | 3 +-
net/bluetooth/l2cap_sock.c | 3 +-
net/can/af_can.c | 6 ++--
net/ceph/mon_client.c | 3 +-
net/core/dev.c | 3 +-
net/core/drop_monitor.c | 3 +-
net/core/flow_offload.c | 3 +-
net/ethtool/mse.c | 3 +-
net/ipv4/af_inet.c | 3 +-
net/ipv4/fib_semantics.c | 3 +-
net/ipv4/nexthop.c | 3 +-
net/ipv6/addrconf.c | 3 +-
net/ipv6/af_inet6.c | 3 +-
net/ipv6/ip6_fib.c | 6 ++--
net/mac80211/util.c | 3 +-
net/netfilter/ipvs/ip_vs_conn.c | 3 +-
net/netfilter/ipvs/ip_vs_mh.c | 3 +-
net/netfilter/nfnetlink_cthelper.c | 3 +-
net/netlink/policy.c | 3 +-
net/openvswitch/conntrack.c | 6 ++--
net/openvswitch/datapath.c | 3 +-
net/openvswitch/vport.c | 3 +-
net/packet/af_packet.c | 3 +-
net/rds/ib.c | 3 +-
net/rds/rdma.c | 3 +-
net/sched/cls_api.c | 3 +-
net/sched/cls_u32.c | 3 +-
net/sched/sch_cake.c | 3 +-
net/sched/sch_fq_codel.c | 3 +-
net/sched/sch_hhf.c | 3 +-
net/sched/sch_mq.c | 3 +-
net/sched/sch_mqprio.c | 3 +-
net/sched/sch_taprio.c | 3 +-
net/smc/smc_wr.c | 15 +++-----
net/sunrpc/auth_gss/auth_gss.c | 3 +-
net/sunrpc/cache.c | 3 +-
net/sunrpc/svcsock.c | 3 +-
net/tipc/netlink_compat.c | 6 ++--
net/unix/af_unix.c | 3 +-
net/wireless/nl80211.c | 9 ++---
net/xdp/xsk_buff_pool.c | 6 ++--
security/apparmor/policy_unpack.c | 3 +-
security/integrity/ima/ima_policy.c | 3 +-
security/selinux/ss/conditional.c | 3 +-
security/selinux/ss/policydb.c | 3 +-
sound/aoa/codecs/onyx.c | 6 ++--
sound/core/oss/pcm_plugin.c | 3 +-
sound/core/seq/seq_memory.c | 3 +-
sound/core/ump.c | 3 +-
sound/drivers/vx/vx_pcm.c | 6 ++--
sound/hda/codecs/ca0132.c | 3 +-
sound/hda/common/proc.c | 3 +-
sound/hda/core/ext/stream.c | 3 +-
sound/hda/core/sysfs.c | 3 +-
sound/pci/cs46xx/dsp_spos.c | 6 ++--
sound/pci/emu10k1/emufx.c | 6 ++--
sound/pci/via82xx.c | 3 +-
sound/pci/via82xx_modem.c | 3 +-
sound/soc/au1x/dma.c | 3 +-
sound/soc/codecs/aw88395/aw88395_lib.c | 3 +-
sound/soc/codecs/da7219.c | 3 +-
sound/soc/codecs/lpass-rx-macro.c | 6 ++--
sound/soc/codecs/lpass-wsa-macro.c | 6 ++--
sound/soc/codecs/tas2781-fmwlib.c | 12 +++----
sound/soc/codecs/wm_adsp.c | 3 +-
sound/soc/soc-dapm.c | 3 +-
sound/soc/sof/ipc3-topology.c | 3 +-
sound/soc/sof/ipc4-topology.c | 3 +-
sound/synth/emux/emux.c | 3 +-
sound/synth/emux/emux_seq.c | 3 +-
sound/usb/6fire/control.c | 3 +-
sound/usb/line6/capture.c | 3 +-
sound/usb/line6/playback.c | 3 +-
sound/usb/mixer.c | 3 +-
sound/usb/mixer_quirks.c | 3 +-
sound/usb/usx2y/usbusx2yaudio.c | 3 +-
sound/xen/xen_snd_front_alsa.c | 3 +-
826 files changed, 1211 insertions(+), 2422 deletions(-)
]
|
| 54/2 |
2026/10/13 22:28 |
llm |
debugger |
0m
Model:
Tokens:
input: 60268
output: 31
thoughts: 1745
Thoughts: **Analyzing the Large Allocation in `drm_mode_create_lease_ioctl`**
Okay, so I'm looking at commit `32a92f8c8932` which changed the allocation of `objects` from `kcalloc` to `kzalloc_objs`. The core issue here is that the `object_count` isn't bounded and the allocation size can exceed the limit for `kmalloc`, causing a warning in `alloc_order_allowed`. `kzalloc_objs`, it turns out, is just a `kmalloc` wrapper, which explains the problem.
My initial thought was to simply bound `object_count` directly, but then I realized that `memdup_array_user` already acts as a de facto limit due to the size limitation of `kmalloc` based allocations, effectively bounding `object_count` to about 1,048,576. So, I can allocate an object array of up to 4MB, but no more.
The next obvious solution is to swap `kzalloc_objs` for `kvcalloc`. This uses `vmalloc`, which doesn't have the size limitation issue that's causing the warning. However, I have to remember that switching to `kvcalloc` requires changing the corresponding `kfree` to `kvfree`.
There doesn't seem to be a good reason *not* to use `kvcalloc` here. It's a clean fix.
I then considered whether I should also switch `object_ids` to `kvmalloc_array`. But, `memdup_array_user` has no `vmemdup_array_user` counterpart. I could use `vmemdup_user`, but I'd need to add overflow checking. Since `memdup_array_user` silently fails with `-ENOMEM` for overly large sizes and the issue is really only in the `objects` allocation, sticking with `memdup_array_user` is fine. It avoids adding new code and potential bugs.
So, the plan is to switch `kzalloc_objs` to `kvcalloc` and change `kfree` to `kvfree` in `fill_object_idr`. That's the most direct fix, and it's consistent with how the kernel handles these kinds of allocations. Let's make sure `kvcalloc` is appropriate in the `drm_lease.c` code. Okay, looks like `kvcalloc` is defined as using `kvmalloc_array` with `__GFP_ZERO`, so it's precisely what I need.
Just to be absolutely certain, let's write down the problem and the explanation:
The crash is a warning in `alloc_order_allowed` because `__alloc_frozen_pages_noprof` is called with an order greater than `MAX_PAGE_ORDER`. This is triggered by `fill_object_idr` when allocating the `objects` array using `kzalloc_objs`. This function internally uses a `kmalloc`-based allocation, similar to `kcalloc`. The problem is that the `object_count` comes directly from userspace without any bounds checking, through `cl->object_count` in `drm_mode_create_lease_ioctl`. `memdup_array_user` allocates `object_ids` before the `objects` array with `kmalloc`, which silently fails for sizes > 4MB. The warning happens when `kzalloc_objs` tries to allocate more than `MAX_PAGE_ORDER`.
The reproducer sets `object_count` to 1,000,000. The `memdup_array_user` allocation is fine, but the subsequent 8MB allocation using `kzalloc_objs` triggers the warning.
So, the fix is to use `kvcalloc` (or `kvmalloc_array` with `__GFP_ZERO`) for the `objects` array in `fill_object_idr` and to change the corresponding `kfree` call to `kvfree`. `kvcalloc` will allocate using `vmalloc` and avoid the size limitations, while still zeroing the memory. Adding a check for the upper bound of `object_count` would also work, but using `kvcalloc` is simpler and more idiomatic.
Now, let's just make sure I'm using `kvcalloc` correctly. Yes, `kvcalloc(n, size, flags)` takes three arguments, and that's precisely what's needed.
|
| 55/2 |
2026/10/13 22:29 |
tool |
grepper |
0m
Args: map[Expression:kvcalloc\( PathPrefixes:[drivers/gpu/drm/]]
Results: map[Output:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c=1028=int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c-1128-
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:1129: vm_entries = kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c-1130- if (!vm_entries) {
--
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c=388=svm_migrate_vma_to_vram(struct kfd_node *node, struct svm_range *prange,
--
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c-410-
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:411: buf = kvcalloc(npages,
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c-412- 2 * sizeof(*migrate.src) + sizeof(u64) + sizeof(dma_addr_t),
--
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c=711=svm_migrate_vma_to_ram(struct kfd_node *node, struct svm_range *prange,
--
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c-736-
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c:737: buf = kvcalloc(npages,
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c-738- 2 * sizeof(*migrate.src) + sizeof(u64) + sizeof(dma_addr_t),
--
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c=526=void dm_dtn_log_append_v(struct dc_context *ctx,
--
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c-559- if (total > log_ctx->size) {
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c:560: char *buf = kvcalloc(total, sizeof(char), GFP_KERNEL);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c-561-
--
drivers/gpu/drm/drm_gpusvm.c=841=enum drm_gpusvm_scan_result drm_gpusvm_scan_mm(struct drm_gpusvm_range *range,
--
drivers/gpu/drm/drm_gpusvm.c-861-
drivers/gpu/drm/drm_gpusvm.c:862: pfns = kvcalloc(npages, sizeof(*pfns), GFP_KERNEL);
drivers/gpu/drm/drm_gpusvm.c-863- if (!pfns)
--
drivers/gpu/drm/drm_pagemap.c=668=int drm_pagemap_migrate_to_devmem(struct drm_pagemap_devmem *devmem_allocation,
--
drivers/gpu/drm/drm_pagemap.c-714-
drivers/gpu/drm/drm_pagemap.c:715: buf = kvcalloc(npages, 2 * sizeof(*migrate.src) + sizeof(*pagemap_addr) +
drivers/gpu/drm/drm_pagemap.c-716- sizeof(*pages), GFP_KERNEL);
--
drivers/gpu/drm/drm_pagemap.c=1312=int drm_pagemap_evict_to_ram(struct drm_pagemap_devmem *devmem_allocation)
--
drivers/gpu/drm/drm_pagemap.c-1330-
drivers/gpu/drm/drm_pagemap.c:1331: buf = kvcalloc(npages, 2 * sizeof(*src) + sizeof(*pagemap_addr) +
drivers/gpu/drm/drm_pagemap.c-1332- sizeof(*pages), GFP_KERNEL);
--
drivers/gpu/drm/drm_pagemap.c=1410=static int __drm_pagemap_migrate_to_ram(struct vm_area_struct *vas,
--
drivers/gpu/drm/drm_pagemap.c-1450-
drivers/gpu/drm/drm_pagemap.c:1451: buf = kvcalloc(npages, 2 * sizeof(*migrate.src) + sizeof(*pagemap_addr) +
drivers/gpu/drm/drm_pagemap.c-1452- sizeof(*pages), GFP_KERNEL);
--
drivers/gpu/drm/lima/lima_drv.c=102=static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_file *file)
--
drivers/gpu/drm/lima/lima_drv.c-124-
drivers/gpu/drm/lima/lima_drv.c:125: bos = kvcalloc(args->nr_bos, sizeof(*submit.bos) + sizeof(*submit.lbos), GFP_KERNEL);
drivers/gpu/drm/lima/lima_drv.c-126- if (!bos)
--
drivers/gpu/drm/nouveau/nouveau_dmem.c=489=nouveau_dmem_evict_chunk(struct nouveau_dmem_chunk *chunk)
--
drivers/gpu/drm/nouveau/nouveau_dmem.c-495-
drivers/gpu/drm/nouveau/nouveau_dmem.c:496: src_pfns = kvcalloc(npages, sizeof(*src_pfns), GFP_KERNEL | __GFP_NOFAIL);
drivers/gpu/drm/nouveau/nouveau_dmem.c:497: dst_pfns = kvcalloc(npages, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL);
drivers/gpu/drm/nouveau/nouveau_dmem.c-498- dma_info = kvzalloc_objs(*dma_info, npages, GFP_KERNEL | __GFP_NOFAIL);
--
drivers/gpu/drm/ttm/ttm_tt.c=118=static int ttm_tt_alloc_page_directory(struct ttm_tt *ttm)
drivers/gpu/drm/ttm/ttm_tt.c-119-{
drivers/gpu/drm/ttm/ttm_tt.c:120: ttm->pages = kvcalloc(ttm->num_pages, sizeof(void*), GFP_KERNEL);
drivers/gpu/drm/ttm/ttm_tt.c-121- if (!ttm->pages)
--
drivers/gpu/drm/ttm/ttm_tt.c=127=static int ttm_dma_tt_alloc_page_directory(struct ttm_tt *ttm)
drivers/gpu/drm/ttm/ttm_tt.c-128-{
drivers/gpu/drm/ttm/ttm_tt.c:129: ttm->pages = kvcalloc(ttm->num_pages, sizeof(*ttm->pages) +
drivers/gpu/drm/ttm/ttm_tt.c-130- sizeof(*ttm->dma_address), GFP_KERNEL);
]
|
| 56/2 |
2026/10/13 22:29 |
llm |
debugger |
0m
Model:
Tokens:
input: 64944
output: 35
thoughts: 97
Thoughts: Here's my thought process, as it unfolded:
**Examining Memory Allocation Routines**
Okay, so I see `kvcalloc` used here β right, I remember it takes three arguments. But hold on, what's this `kvzalloc_objs`? That doesn't immediately ring a bell. And I see itβs in `nouveau_dmem.c`! Hmmm, interesting, because I don't recall seeing that routine explicitly before. Let me just quickly confirm, is this a typo, or does this routine *actually* exist? I'll quickly check for a declaration of `kvzalloc_objs`. I need to ensure there isn't something subtle going on here, something I might have missed. Gotta be thorough.
|
| 57/2 |
2026/10/13 22:30 |
tool |
grepper |
0m
Args: map[Expression:#define kvzalloc_objs PathPrefixes:[include/linux/slab.h]]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1172- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1173:#define kvzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1174- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
]
|
| 58/2 |
2026/10/13 22:30 |
llm |
debugger |
2m
Model:
Tokens:
input: 65400
output: 1188
thoughts: 2026
Thoughts: **My Analysis of the DRM Lease Allocation Issue**
Okay, so I've dug into this crash, and here's what I've got. The smoking gun seems to be this `kvzalloc_objs` function. It looks like it was introduced around the same time this issue started popping up, so that's a good lead. The fix seems straightforward enough: replacing `kzalloc_objs` with `kvzalloc_objs` and the corresponding `kfree` with `kvfree` should do the trick.
Let me verify this quickly. Right, it looks like `kvzalloc_objs` in `include/linux/slab.h` is defined as:
```c
#define kvzalloc_objs(P, COUNT, ...) \
__alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
```
So we can definitely use it with `kvzalloc_objs(struct drm_mode_object *, object_count)`. And then in the `out_free_objects` code:
```c
objects = kvzalloc_objs(struct drm_mode_object *, object_count);
```
Then we simply have to change the `kfree(objects)` to `kvfree(objects)`.
I can see this is a very clean and targeted fix.
Now, let's nail down the root cause. The warning we're seeing in `alloc_order_allowed` is triggered because `__alloc_frozen_pages_noprof` is being called with an order greater than `MAX_PAGE_ORDER`. This is happening during the allocation of the `objects` array within the `fill_object_idr` function:
```c
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
`kzalloc_objs` expands to a `kmalloc`-family allocation, essentially `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`. The kicker is that `object_count` comes straight from userspace via the `drm_mode_create_lease` struct's `cl->object_count` field in `drm_mode_create_lease_ioctl`. The code *doesn't* have an upper bound check on this `object_count` value.
Before this call, `drm_mode_create_lease_ioctl` allocates `object_ids` using `memdup_array_user`:
```c
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user` uses `memdup_user`, which in turn uses `kmalloc` with `GFP_USER | __GFP_NOWARN`. Because of `__GFP_NOWARN`, if `object_count` is large (say, greater than 1,048,576 β requiring >4MB), `memdup_array_user` will silently fail and return `-ENOMEM`. However, if `object_count` is large enough to require more than 4MB for the `objects` array (8-byte elements on 64-bit), *but* small enough for the `object_ids` array (4-byte elements) to fit within that 4MB limit, `memdup_array_user` succeeds. Then, the `kzalloc_objs` call attempts a large allocation exceeding 4MB (order > `MAX_PAGE_ORDER`). Since `kzalloc_objs` uses `GFP_KERNEL` without `__GFP_NOWARN`, this triggers the warning in `alloc_order_allowed`.
In the provided syzkaller reproducer, `object_count` is set to 1,000,000. `memdup_array_user` allocates 4,000,000 bytes (1,000,000 * 4). This is order 10 (assuming 4KB pages), which is within `MAX_PAGE_ORDER`. So, that succeeds. Then `fill_object_idr` attempts to allocate 8,000,000 bytes (1,000,000 * 8), which is order 11 and *exceeds* `MAX_PAGE_ORDER`, leading to the warning.
So, the proposed fix is clear: change the allocation in `fill_object_idr` to use `kvzalloc_objs` (which falls back to `vmalloc` for large allocations and avoids this warning) and the corresponding `kfree` to `kvfree`.
|
| 59/1 |
2026/10/13 22:32 |
agent |
history-explorer |
17m
Model:
Instruction:
You are an experienced Linux kernel developer researching prior art for fixing a kernel bug.
You are given a bug explanation. This explanation details the root cause of the bug resulting
from debugging, but does not provide the final fix strategy. Your goal is to explore how
similar bugs were fixed in the past in the same subsystem or files.
CRITICAL: Do NOT attempt to debug the issue further or write a patch for it yourself.
Your ONLY objective is to research and provide the necessary historical context.
Use the git-log tool with the Since parameter set to "3 years" to focus on recent history.
Search for commits that address issues with similar root causes (e.g. similar missing locks,
incorrect refcounting, or similar error path bugs) in the affected files.
Your final reply must summarize your findings: what idioms, locking rules, or common patterns
should be followed when writing a fix for this bug based on how previous similar bugs were addressed.
If you find no relevant past fixes, clearly state that.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash is:
------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
The explanation of the root cause of the bug is:
An analysis of the crash reveals that it is caused by an unbounded user-controlled allocation size in the DRM lease creation ioctl, which attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` using the `kmalloc` family of functions.
### Root Cause Analysis
The crash is a warning triggered in `alloc_order_allowed()` because `__alloc_frozen_pages_noprof()` is called with an allocation order that exceeds `MAX_PAGE_ORDER` (typically 10, which corresponds to 4MB on systems with 4KB pages).
This happens in `fill_object_idr()` when allocating the `objects` array:
```c
// drivers/gpu/drm/drm_lease.c:389
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
The `kzalloc_objs` macro expands to a `kmalloc`-family allocation (equivalent to `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`).
The `object_count` comes directly from the user-space `drm_mode_create_lease` struct via `cl->object_count` in `drm_mode_create_lease_ioctl()`. There is no upper bound check on this value.
Before calling `fill_object_idr()`, `drm_mode_create_lease_ioctl()` allocates the `object_ids` array using `memdup_array_user()`:
```c
// drivers/gpu/drm/drm_lease.c:512
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user()` uses `memdup_user()`, which allocates memory with `GFP_USER | __GFP_NOWARN`. Because of the `__GFP_NOWARN` flag, if `object_count` is extremely large (e.g., requiring > 4MB), `memdup_array_user()` will silently fail and return `-ENOMEM` without triggering any warnings.
However, there is a specific window where `object_count` is large enough to require more than 4MB for the `objects` array (which has 8-byte pointers on 64-bit systems), but small enough that the `object_ids` array (which has 4-byte `__u32` elements) fits within 4MB.
In the provided syzkaller reproducer:
```c
*(uint32_t*)0x200003c8 = 0xf4240; // object_count = 1,000,000
```
1. `object_count` is set to `1,000,000`.
2. `memdup_array_user()` allocates `1,000,000 * 4 = 4,000,000` bytes. This is order 10, which is `<= MAX_PAGE_ORDER`. The allocation succeeds.
3. `fill_object_idr()` then calls `kzalloc_objs()` to allocate `1,000,000 * 8 = 8,000,000` bytes. This requires order 11, which is `> MAX_PAGE_ORDER`.
4. Since `kzalloc_objs()` uses `GFP_KERNEL` without `__GFP_NOWARN`, the page allocator loudly complains and triggers the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` warning.
### Proposed Fix
To fix this, the allocation of the `objects` array in `fill_object_idr()` should be changed to use `kvzalloc_objs()`, which gracefully falls back to `vmalloc()` for large allocations and does not trigger the page allocator warning. The corresponding `kfree()` must also be updated to `kvfree()`.
```c
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,7 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +462,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
```
*(Note: While adding an arbitrary upper bound check to `object_count` in `drm_mode_create_lease_ioctl()` is another option, using `kvzalloc_objs()` is the standard kernel pattern for handling user-controlled array sizes without imposing artificial limits).*
Reply: Based on a review of recent commits in the DRM subsystem (`drivers/gpu/drm/`) over the last 3 years, there is a clear set of established idioms and patterns for addressing unbounded user-controlled allocation sizes that trigger page allocator warnings.
### 1. Switching to the `kvmalloc` family (Primary Fix)
The proposed fix of switching from `kzalloc_objs()` to `kvzalloc_objs()` (and `kfree()` to `kvfree()`) is the standard kernel pattern for handling large, unbounded arrays without imposing artificial limits.
* **Prior Art:** Commit `bca45af5998a` ("drm/vc4: Use kvmalloc_objs() for the BO cache size list") fixed a nearly identical issue where an unbounded cache size list scaled with the largest BO freed, requiring an order-6 allocation that failed under fragmentation and triggered a `warn_alloc()` splat. The fix was to use `kvmalloc_objs()` so large lists can fall back to `vmalloc()`, avoiding the allocation failure.
### 2. Adding an Upper Bound Check (Crucial Secondary Fix)
While `kvmalloc` avoids the `MAX_PAGE_ORDER` warning, it has its own limitation: it will trigger a `WARN_ON_ONCE(size > INT_MAX)` if the requested allocation size exceeds `INT_MAX` (2GB). Because `object_count` is a `__u32` and `sizeof(struct drm_mode_object *)` is 8 bytes on 64-bit systems, a malicious user can easily pass an `object_count` that results in an allocation size up to ~34GB, which will still trigger a kernel warning even with `kvzalloc_objs()`.
* **Prior Art:** Commit `a1ba4594232c` ("drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO") addressed this exact scenario. A user-supplied `__u32` was used in `kvcalloc()`, which produced an allocation exceeding `INT_MAX` and triggered a warning in `__kvmalloc_node_noprof()`. The fix was to add a bounds check (`if (args->num_entries > INT_MAX / sizeof(*vm_entries)) return -EINVAL;`).
* **Prior Art:** Commit `0829b5bcdd3b` ("drm/i915: 2 GiB of relocations ought to be enough for anybody*") similarly capped the number of relocations to avoid the `kvmalloc` warning for `size > INT_MAX`.
### 3. Consistent Userspace Copying (Optional but Recommended)
Before allocating the `objects` array, the code allocates the `object_ids` array using `memdup_array_user()`. While `memdup_array_user()` fails silently for large sizes (due to `__GFP_NOWARN`), it still limits the maximum size to `MAX_PAGE_ORDER`. To consistently support large arrays across both allocations and separate user/kernel slabs, the DRM subsystem has been moving towards using `vmemdup_array_user()`.
* **Prior Art:** Commit `cb77b79abf5f` ("drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup") and commit `c4ac100e9ae2` ("drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array") both replaced `kvmalloc_array() + copy_from_user()` or `memdup_user()` with `vmemdup_array_user()` when dealing with potentially large, user-controlled arrays.
### Summary of Recommendations for the Fix
Based on how similar bugs were addressed, the final fix should:
1. Apply the proposed switch to `kvzalloc_objs()` and `kvfree()` in `fill_object_idr()`.
2. Add a sanity bounds check in `drm_mode_create_lease_ioctl()` to ensure `object_count` does not exceed `INT_MAX / sizeof(void *)` to prevent `kvmalloc` from warning on sizes > 2GB.
3. (Optional) Change the `object_ids` allocation from `memdup_array_user()` to `vmemdup_array_user()` to allow the first array to also gracefully fall back to `vmalloc()`.
|
| 60/2 |
2026/10/13 22:32 |
llm |
history-explorer |
3m
Model:
Tokens:
input: 7433
output: 34
thoughts: 272
Thoughts: **Investigating Kernel Bug Prior Art**
Okay, so I'm tasked with looking into potential prior solutions for this kernel bug in `drivers/gpu/drm/drm_lease.c`. The core issue seems to be an unbounded allocation size controlled by a user, which then triggers a `kmalloc` warning when allocating the `objects` array within `fill_object_idr()`. The proposed fix is to use `kvzalloc_objs` (or potentially `kvmalloc_array` or `kvcalloc`) instead of `kzalloc_objs`. Makes sense, we're trying to mitigate the unbounded allocation risk.
My immediate thought is to delve into the commit history. I need to find precedents. I need to see how similar issues have been tackled in the past, specifically looking for examples of where `kmalloc`-based allocations were replaced with `kvmalloc`-based counterparts or where unbounded allocations were addressed. I'm thinking, missing locks, incorrect reference counting, general error-path bugsβ¦anything that's in the same ballpark.
Given the scope of the problem I'm going to set up `git-log` search criteria with a `Since` date of "3 years" on the subsystem or the file itself. Specifically, I'll focus on commits that address allocation issues in `drivers/gpu/drm/drm_lease.c` or, for broader context, the entire `drivers/gpu/drm/` directory.
So, first thing's first: let's try searching for commits in `drivers/gpu/drm/drm_lease.c` or `drivers/gpu/drm/` that involve the switch from those memory allocators to the "kv" variants to try and address this bug. I'll start with this more narrow focus, then broaden it to the entire directory.
I'll use `git-log` with the `PathPrefix="drivers/gpu/drm/drm_lease.c"` and `Since="3 years"` to get the specific commits in that file. That should give me a good starting point.
|
| 61/2 |
2026/10/13 22:36 |
tool |
git-log |
0m
Args: map[PathPrefix:drivers/gpu/drm/drm_lease.c Since:3 years]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
]
|
| 62/2 |
2026/10/13 22:36 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 8244
output: 49
thoughts: 109
Thoughts: Okay, here's my analysis of this situation:
**Investigating Potential Memory Allocation Issues in the DRM Subsystem**
Alright, two commits in `drivers/gpu/drm/drm_lease.c` over three years? That's not much activity, and from a quick glance, they appear to be broad refactorings. Probably not where the interesting bugs are. Time to widen the net. Let's cast a broader search across the `drivers/gpu/drm/` directory.
I'm thinking, given the potential for vulnerabilities, I need to focus on memory allocation. Specifically, I'm concerned about the use of `kvmalloc`, `kvcalloc`, or `kvzalloc`, the implications of `MAX_PAGE_ORDER`, any checks around `order > MAX_PAGE_ORDER`, and, of course, anything hinting at "unbounded" or "user-controlled" memory allocation. Those are the red flags I'm looking for. They're all potential entry points for a memory-related vulnerability, or at least where I'd start digging.
|
| 63/2 |
2026/10/13 22:36 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc|kvcalloc|kvzalloc|kvfree] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results:
|
| 64/2 |
2026/10/13 22:36 |
llm |
history-explorer |
1m
Model:
Tokens:
input: 8642
output: 38
thoughts: 64
Thoughts: Here's my thought process, as requested:
**Investigating Memory Allocation in DRM Drivers**
Hmm, that's odd. I was expecting to see some recent commits related to kernel memory allocation functions like `kvmalloc`, `kvcalloc`, `kvzalloc`, and `kvfree` within the `drivers/gpu/drm/` directory over the past three years. The absence of direct hits is surprising. My first instinct is to double-check my search parameters. Perhaps I was too specific. Let's start by broadening the scope. Instead of searching for the exact combination with path prefixes, I should look at just `kvmalloc` without any path restrictions to see if there are any indirect usages in that specific driver. Or, I might narrow my search, but focus on just `kvmalloc` within the `drivers/gpu/drm/` directory. That seems like a good starting point to understand what's really happening here. Maybe I need to look at indirect allocations, or different allocation functions altogether.
|
| 65/2 |
2026/10/13 22:37 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:bca45af5998a drm/vc4: Use kvmalloc_objs() for the BO cache size list
847b371debf3 drm/gpusvm: Fix MM reference leak in drm_gpusvm_range_evict
a8eba56abcad drm/exec: Use kvmalloc_objs for exec->objects
a1ba4594232c drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO
1fe7bf5457f6 drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO
4625fe5bbdac drm: gpu: msm: forbid mem reclaim from reset
e9405ce75e8e drm/amdgpu/userq: Use kvfree instead of kfree in amdgpu_userq_signal_ioctl
087be0cd54f5 drm/amdgpu/userq: Use kvfree instead of kfree in amdgpu_userq_wait_ioctl
189f164e573e Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
c4ac100e9ae2 drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
]
|
| 66/2 |
2026/10/13 22:37 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 9274
output: 22
thoughts: 125
Thoughts: Okay, here's my breakdown of what I'm looking at:
**Investigating Memory Allocation Usage in DRM Subsystems**
Right, so I see `kvmalloc_objs` being employed within `drm/vc4` and `drm/exec`, thatβs interesting. Let's delve a bit deeper and investigate its use. I should really be focusing on avoiding potential memory leaks and ensuring efficient resource management, as you well know.
I'll check out how it's being handled in `drm/amdgpu`, specifically with the recent incorporation of `vmemdup_array_user` in `amdgpu_bo_create_list_entry_array`. I also need to verify that we are validating the `num_entries` field in `GEM_OP GET_MAPPING_INFO` to safeguard against possible vulnerabilities. Also, the `drm/exec` area is using it for `exec->objects`, so I'll see if there's any related nuance.
I'm thinking Iβll use those two commits, `a8eba56abcad` and `c4ac100e9ae2` as a reference point. They'll likely illuminate some of the key changes and decisions made in the code. I'll need to go through those and see if there are other areas to look at.
|
| 67/2 |
2026/10/13 22:38 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a8eba56abcadca67bb4b717d9ea8ebdc703fb111
Author: Jonathan Cavitt <jonathan.cavitt@intel.com>
Date: Thu Jul 2 01:24:58 2026 +0800
drm/exec: Use kvmalloc_objs for exec->objects
Use kvmalloc_objs instead of kvmalloc_array when initializing
exec->objects in drm_exec_init.
Concern caught by static analysis.
Signed-off-by: Jonathan Cavitt <jonathan.cavitt@intel.com>
Cc: Rob Clark <robdclark@chromium.org>
Cc: Christian KΓΆnig <christian.koenig@amd.com>
Reviewed-by: Christian KΓΆnig <christian.koenig@amd.com>
Link: https://patch.msgid.link/20260701172458.1416930-1-jonathan.cavitt@intel.com
diff --git a/drivers/gpu/drm/drm_exec.c b/drivers/gpu/drm/drm_exec.c
index 7988f5e7d56a..fa923852fae4 100644
--- a/drivers/gpu/drm/drm_exec.c
+++ b/drivers/gpu/drm/drm_exec.c
@@ -79,7 +79,7 @@ void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr)
nr = PAGE_SIZE / sizeof(void *);
exec->flags = flags;
- exec->objects = kvmalloc_array(nr, sizeof(void *), GFP_KERNEL);
+ exec->objects = kvmalloc_objs(*exec->objects, nr, GFP_KERNEL);
/* If allocation here fails, just delay that till the first use */
exec->max_objects = exec->objects ? nr : 0;
]
|
| 68/2 |
2026/10/13 22:38 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 10203
output: 25
thoughts: 16
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if it were my own internal monologue:
**Investigating a Specific Commit Hash**
Alright, time to dive in. `c4ac100e9ae2`. That's the commit hash I need to look at. The immediate thought isn't "what is it?" but rather, a mental checklist begins. What's the context? What branches is this likely associated with? Any recent alerts pointing me here? Before I even start, I'm mentally parsing the system logs and thinking about potential areas of impact. Is this a core library change, or something more isolated? I'm anticipating the questions I'll need to answer about this commit. Let's see if this one holds the key.
|
| 69/2 |
2026/10/13 22:38 |
tool |
git-show |
0m
Args:
Results: map[Output:commit c4ac100e9ae252b09986766ad23b1f83ca3a369d
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Thu Jun 12 11:44:26 2025 +0100
drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
Replace kvmalloc_array() + copy_from_user() with vmemdup_array_user() on
the fast path.
This shrinks the source code and improves separation between the kernel
and userspace slabs.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 702f6610d024..66fb37b64388 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -184,43 +184,36 @@ void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
struct drm_amdgpu_bo_list_entry **info_param)
{
- const void __user *uptr = u64_to_user_ptr(in->bo_info_ptr);
const uint32_t info_size = sizeof(struct drm_amdgpu_bo_list_entry);
+ const void __user *uptr = u64_to_user_ptr(in->bo_info_ptr);
+ const uint32_t bo_info_size = in->bo_info_size;
+ const uint32_t bo_number = in->bo_number;
struct drm_amdgpu_bo_list_entry *info;
- int r;
-
- info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
- if (!info)
- return -ENOMEM;
/* copy the handle array from userspace to a kernel buffer */
- r = -EFAULT;
- if (likely(info_size == in->bo_info_size)) {
- unsigned long bytes = in->bo_number *
- in->bo_info_size;
-
- if (copy_from_user(info, uptr, bytes))
- goto error_free;
-
+ if (likely(info_size == bo_info_size)) {
+ info = vmemdup_array_user(uptr, bo_number, info_size);
+ if (IS_ERR(info))
+ return PTR_ERR(info);
} else {
- unsigned long bytes = min(in->bo_info_size, info_size);
+ const uint32_t bytes = min(bo_info_size, info_size);
unsigned i;
- memset(info, 0, in->bo_number * info_size);
- for (i = 0; i < in->bo_number; ++i) {
- if (copy_from_user(&info[i], uptr, bytes))
- goto error_free;
+ info = kvmalloc_array(bo_number, info_size, GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
- uptr += in->bo_info_size;
+ memset(info, 0, bo_number * info_size);
+ for (i = 0; i < bo_number; ++i, uptr += bo_info_size) {
+ if (copy_from_user(&info[i], uptr, bytes)) {
+ kvfree(info);
+ return -EFAULT;
+ }
}
}
*info_param = info;
return 0;
-
-error_free:
- kvfree(info);
- return r;
}
int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
]
|
| 70/2 |
2026/10/13 22:38 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 11574
output: 46
thoughts: 54
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm the expert:
**Investigating Potential Memory Allocation Issues in DRM Drivers**
Alright, time to dig into some potential memory allocation issues within the DRM (Direct Rendering Manager) subsystem drivers. I suspect something might be awry. My gut tells me there could be some subtle memory overruns or misuse happening, and I want to get to the bottom of it. I'm going to start by casting a wide net, looking for clues. Specifically, I'm going to search through the commit history within the `drivers/gpu/drm/` directory. I'll be looking for any commits that touch on certain areas that frequently introduce allocation problems.
First, I'll search for mentions of `MAX_PAGE_ORDER`. This constant often represents a limit on the size of contiguous memory allocations, so any commits that deal with it are immediately interesting. I will also make that search include `order > MAX_PAGE_ORDER`. Then, I'll broaden the search to look for `memdup_user` and `memdup_array_user`. These functions, while convenient, are easy to misuse and can lead to vulnerabilities if not handled carefully. Finally, I'll include `kvmalloc` in the search. It's a kernel virtual memory allocator, and any modifications to its usage, especially in the context of DRM drivers, deserve close scrutiny. This should help me quickly identify any commits that might be relevant to my investigation. I expect this initial search will hopefully give me some leads to start investigating!
|
| 71/2 |
2026/10/13 22:38 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc MAX_PAGE_ORDER] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results:
|
| 72/2 |
2026/10/13 22:38 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 12013
output: 43
thoughts: 14
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Investigating Memory Allocation Boundaries**
Right, let's dive in. I need to get a handle on how memory is being managed in this system, specifically, any potential for unbounded allocation. My initial thought is to zero in on `kvmalloc`. I'm going to search for instances of its usage and pair that search with "unbounded" as a keyword. This could point me towards code that's allocating kernel virtual memory and, crucially, might be doing so without sufficient checks or limits. I'm hoping to identify areas where a rogue driver, or even a subtle bug, could lead to a denial-of-service or, worse, a security vulnerability. The combination of `kvmalloc` with 'unbounded' seems like a good starting point for a focused investigation. I want to see how these two concepts interact within the code.
|
| 73/2 |
2026/10/13 22:38 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc unbounded] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results:
|
| 74/2 |
2026/10/13 22:38 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 12282
output: 42
thoughts: 13
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing Memory Allocation Strategies & User Context**
Alright, my internal processes are now focused. I need to delve into the relationship between `kvmalloc` and the `user` context. My immediate goal is to understand how these two concepts interact, and what specific information I can derive from their association. I am thinking, what I am trying to understand is how the kernel's virtual memory allocator, `kvmalloc`, is utilized within the scope of user-space interactions. This could reveal potential vulnerabilities, performance bottlenecks, or even insights into the overall system architecture. Now, I am thinking, should I look for specific patterns of `kvmalloc` calls triggered by user actions, or maybe trace how memory allocated by `kvmalloc` is eventually mapped into user-space. Perhaps there are data structures involved, and the interaction of those data structures with these calls. I will conduct these searches to uncover crucial system behavior.
|
| 75/2 |
2026/10/13 22:38 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc user] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:a1ba4594232c drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO
1fe7bf5457f6 drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO
e9405ce75e8e drm/amdgpu/userq: Use kvfree instead of kfree in amdgpu_userq_signal_ioctl
087be0cd54f5 drm/amdgpu/userq: Use kvfree instead of kfree in amdgpu_userq_wait_ioctl
189f164e573e Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
c4ac100e9ae2 drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
a292fdecd728 drm/amdgpu: Implement userqueue signal/wait IOCTL
0829b5bcdd3b drm/i915: 2 GiB of relocations ought to be enough for anybody*
]
|
| 76/2 |
2026/10/13 22:38 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 12815
output: 25
thoughts: 16
Thoughts: Okay, let's dive into this. Here's my perspective on this specific task:
**Analyzing `0829b5bcdd3b`**
Alright, the first thing I'm doing is to acknowledge this identifier, `0829b5bcdd3b`. I need to figure out what this represents. Given my expertise, it's likely a hash, some sort of identifier, perhaps a commit ID, a file checksum, or maybe even a database key. The format suggests a hexadecimal representation, which is common in many of the systems I work with. I need to understand the context. Is this a file? A revision? What system is it from? Let's check.
|
| 77/2 |
2026/10/13 22:39 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 0829b5bcdd3ba077c408e71e22ac2bfa85bf2c95
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Tue May 21 11:12:01 2024 +0100
drm/i915: 2 GiB of relocations ought to be enough for anybody*
Kernel test robot reports i915 can hit a warn in kvmalloc_node which has
a purpose of dissalowing crazy size kernel allocations. This was added in
7661809d493b ("mm: don't allow oversized kvmalloc() calls"):
/* Don't even allow crazy sizes */
if (WARN_ON_ONCE(size > INT_MAX))
return NULL;
This would be kind of okay since i915 at one point dropped the need for
making a shadow copy of the relocation list, but then it got re-added in
fd1500fcd442 ("Revert "drm/i915/gem: Drop relocation slowpath".") a year
after Linus added the above warning.
It is plausible that the issue was not seen until now because to trigger
gem_exec_reloc test requires a combination of an relatively older
generation hardware but with at least 8GiB of RAM installed. Probably even
more depending on runtime checks.
Lets cap what we allow userspace to pass in using the matching limit.
There should be no issue for real userspace since we are talking about
"crazy" number of relocations which have no practical purpose.
*) Well IGT tests might get upset but they can be easily adjusted.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202405151008.6ddd1aaf-oliver.sang@intel.com
Cc: Kees Cook <keescook@chromium.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20240521101201.18978-1-tursulin@igalia.com
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
index 090724fa766c..8aff06933f54 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -1533,7 +1533,7 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
u64_to_user_ptr(entry->relocs_ptr);
unsigned long remain = entry->relocation_count;
- if (unlikely(remain > N_RELOC(ULONG_MAX)))
+ if (unlikely(remain > N_RELOC(INT_MAX)))
return -EINVAL;
/*
@@ -1641,7 +1641,7 @@ static int check_relocations(const struct drm_i915_gem_exec_object2 *entry)
if (size == 0)
return 0;
- if (size > N_RELOC(ULONG_MAX))
+ if (size > N_RELOC(INT_MAX))
return -EINVAL;
addr = u64_to_user_ptr(entry->relocs_ptr);
]
|
| 78/2 |
2026/10/13 22:39 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 14126
output: 26
thoughts: 41
Thoughts: Okay, here's my interpretation of this commit's intention:
**Ensuring Memory Allocation Safety**
Alright, so the key here is to prevent a potential problem with `kvmalloc`. The user's providing a count, which is being used to determine the size of a memory allocation, and we need to make sure this count doesn't lead to issues with `kvmalloc` where the requested size exceeds `INT_MAX`. This is a classic integer overflow risk, and we're addressing it directly by capping that count. It's a pragmatic defense against unexpected behavior, memory allocation failures, or even security vulnerabilities related to excessively large memory requests. I'd expect this approach to maintain functionality while upholding system stability. I should double check how this interacts with the wider code base, so I'll probably start by looking at `a1ba4594232c` to see the context of this change and how the user's input is being handled throughout the call stack. Understanding the specifics of that commit would likely clarify the exact nature of the vulnerability being addressed and the rationale for the chosen cap.
|
| 79/2 |
2026/10/13 22:39 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a1ba4594232c87c3b8defd6f89a2e40f8b08395d
Author: Ziyi Guo <n7l8m4@u.northwestern.edu>
Date: Sun Feb 8 00:02:55 2026 +0000
drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO
kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL) at
amdgpu_gem.c:1050 uses the user-supplied num_entries directly without
any upper bounds check. Since num_entries is a __u32 and
sizeof(drm_amdgpu_gem_vm_entry) is 32 bytes, a large num_entries
produces an allocation exceeding INT_MAX, triggering
WARNING in __kvmalloc_node_noprof(), causing a kernel WARNING,
TAINT_WARN, and panic on CONFIG_PANIC_ON_WARN=y systems.
Add a size bounds check before we invoke the kvzalloc() to
reject oversized num_entries early with -EINVAL.
Fixes: 4d82724f7f2b ("drm/amdgpu: Add mapping info option for GEM_OP ioctl")
Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 1fe7bf5457f6efd7be60b17e23163ba54341d73d)
Cc: stable@vger.kernel.org
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 06dd2e8a5b47..fe6d988e7f24 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -1093,6 +1093,11 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
* If that number is larger than the size of the array, the ioctl must
* be retried.
*/
+ if (args->num_entries > INT_MAX / sizeof(*vm_entries)) {
+ r = -EINVAL;
+ goto out_exec;
+ }
+
vm_entries = kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL);
if (!vm_entries) {
r = -ENOMEM;
]
|
| 80/2 |
2026/10/13 22:39 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 15155
output: 43
thoughts: 106
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing Potential Memory Allocation Vulnerabilities in DRM Drivers**
Alright, so this commit's brought up a critical point: a bounds check on `args->num_entries` before calling `kvcalloc`. My immediate thought is, "good catch!" We've got to be vigilant about these integer overflows leading to out-of-bounds memory allocations. It's a textbook example of a vulnerability. The warning from `kvcalloc` is the canary in the coal mine, and addressing it proactively is the right approach.
Now, my mind's already racing ahead. I need to see if this is an isolated incident, or if it highlights a more systemic issue within `drivers/gpu/drm/`. I'm going to leverage my familiarity with the codebase and search for other instances where we've seen this pattern of shifting from the more primitive `kmalloc` to `kvmalloc`, `kvzalloc`, or `kvcalloc`. Iβll target `drivers/gpu/drm/` specifically. My query will be focused: look for the transitions, because that's where we're most likely to find allocations whose size is based on some user-controllable input. That's where we need to be extra cautious. I'm going to search for instances of both `kvmalloc` and `kmalloc` to identify those potential problematic transitions. We're looking for code that's been patched, and we want to know what the rationale was.
|
| 81/2 |
2026/10/13 22:39 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc kmalloc] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:bca45af5998a drm/vc4: Use kvmalloc_objs() for the BO cache size list
189f164e573e Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
4ea512714c42 drm/xe: Fix CFI violation when accessing sysfs files
a292fdecd728 drm/amdgpu: Implement userqueue signal/wait IOCTL
590b9d576cae mm: kvmalloc: align kvrealloc() with krealloc()
]
|
| 82/2 |
2026/10/13 22:39 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 15773
output: 25
thoughts: 16
Thoughts: Okay, here's my interpretation of that.
**Analyzing Commit `bca45af5998a`**
Right, let's dive into this commit, `bca45af5998a`. The identifier is the only starting information I have, so I'll begin by calling the associated object from the database and reading the commit header and diffs. I'm going to look for any obvious red flags: are there any large files introduced or changed? Are we creating, modifying, or deleting crucial configurations? Is the diff clean, or does it hint at some messy rebasing? Any merge commits are easy to spot. I am hoping for a nice, concise code change, but the ID on its own isn't telling me enough. The commit message will be key here - I'm hoping it's descriptive and provides some context. Understanding the intention behind this change will help me evaluate its impact much faster than sifting through code blindly. I need to understand what this commit is supposed to *do*, and whether it does it correctly. I'll need to then quickly evaluate whether it introduces any vulnerabilities, regression potential, or performance bottlenecks.
|
| 83/2 |
2026/10/13 22:39 |
tool |
git-show |
0m
Args:
Results: map[Output:commit bca45af5998a05f34b13a2ef11e639bac9c62643
Author: MaΓra Canal <mcanal@igalia.com>
Date: Wed Sep 30 16:06:51 2026 -0300
drm/vc4: Use kvmalloc_objs() for the BO cache size list
The BO cache size list has one entry per BO page count, so its size
scales with the largest BO ever freed. A 64 MiB BO already needs at
least an order-6 allocation, which fails under fragmentation and
triggers a warn_alloc() splat on BO close:
page allocation failure: order:7, mode:0x40cc0(GFP_KERNEL|__GFP_COMP)
Call trace:
...
warn_alloc+0x118/0x190
__alloc_pages_slowpath+0x4a8/0x520
...
__kmalloc_noprof+0x3ac/0x5d8
vc4_free_object+0x128/0x370 [vc4]
drm_gem_object_handle_put_unlocked+0xb8/0x158 [drm]
drm_gem_object_release_handle+0x74/0xe8 [drm]
drm_gem_handle_delete+0x6c/0xa8 [drm]
drm_gem_close_ioctl+0x34/0x50 [drm]
The list doesn't need physically contiguous memory. Use kvmalloc_objs()
so large lists can fall back to vmalloc(), avoiding the allocation
failure.
Fixes: c826a6e10644 ("drm/vc4: Add a BO cache.")
Reviewed-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://patch.msgid.link/20260930190721.1897264-2-mcanal@igalia.com
Signed-off-by: MaΓra Canal <mcanal@igalia.com>
diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index ea1be891ac78..7b8b3364000f 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -204,7 +204,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
struct list_head *new_list;
uint32_t i;
- new_list = kmalloc_objs(struct list_head, new_size);
+ new_list = kvmalloc_objs(struct list_head, new_size);
if (!new_list)
return NULL;
@@ -224,7 +224,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
for (i = vc4->bo_cache.size_list_size; i < new_size; i++)
INIT_LIST_HEAD(&new_list[i]);
- kfree(vc4->bo_cache.size_list);
+ kvfree(vc4->bo_cache.size_list);
vc4->bo_cache.size_list = new_list;
vc4->bo_cache.size_list_size = new_size;
}
@@ -1052,7 +1052,7 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)
cancel_work_sync(&vc4->bo_cache.time_work);
vc4_bo_cache_purge(dev);
- kfree(vc4->bo_cache.size_list);
+ kvfree(vc4->bo_cache.size_list);
for (i = 0; i < vc4->num_labels; i++) {
if (vc4->bo_labels[i].num_allocated) {
]
|
| 84/2 |
2026/10/13 22:39 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 17159
output: 40
thoughts: 96
Thoughts: Here's my thought process, as if I were analyzing this:
**Identifying a Familiar Pattern and Potential Solutions**
Okay, this scenario screams "memory allocation issue" to me. Specifically, I'm seeing a classic case of a user-supplied size potentially leading to an `kmalloc` failure due to an excessively large `order` value, exceeding `MAX_PAGE_ORDER`. This is a textbook problem. The proposed fix, switching to `kvmalloc_objs` and `kvfree`, is the right path to take given the context - assuming a small number of large memory allocations is preferable to a large number of smaller allocations. Now I need to see if this pattern has been addressed elsewhere in the `drivers/gpu/drm/` directory. Are there any existing solutions I can draw from for an example? I need to know the pattern and existing solutions.
I'm going to quickly search for other commits in that area that utilize the `kvmalloc_array`, `kvcalloc`, or `kvzalloc` functions. This will help me to determine if this is a recurring issue, if there are existing best practices within the DRM subsystem, and if a common solution or pattern has already been established in other similar areas of the kernel. This also helps in debugging the issue as I may be able to glean information on how to test this, since this seems to be an old issue.
|
| 85/2 |
2026/10/13 22:39 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc_array] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:847b371debf3 drm/gpusvm: Fix MM reference leak in drm_gpusvm_range_evict
a8eba56abcad drm/exec: Use kvmalloc_objs for exec->objects
c4ac100e9ae2 drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
a292fdecd728 drm/amdgpu: Implement userqueue signal/wait IOCTL
b57e3ca1fb19 drm/amdgpu: Use kvcalloc instead of kvmalloc_array in amdgpu_cs_parser_bos()
bae9fca96843 drm: i915: Adapt to -Walloc-size
]
|
| 86/2 |
2026/10/13 22:39 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 17774
output: 25
thoughts: 16
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing that Hash**
Alright, let's take a look at that hash, `b57e3ca1fb19`. Right away, my mind starts to race. Depending on the context, this could represent a commit hash, a file hash, a block identifier in a blockchain, or even a unique identifier in some custom data structure. Given the length and hexadecimal format, it screams SHA-1 or MD5 initially, though SHA-256 is increasingly common. If this is from a system I'm working with, I need to immediately recall its conventions. Is it truncated? Does the system use a specific hashing algorithm standard? Where is this hash *from*? What systems does it connect to? That's what I need to establish first. Knowing that, I can work backward from its source to get a better handle on its meaning. Then, I need to start thinking about the context. What metadata surrounds this hash? What system generated it? Is it associated with any logs, change history, or version control system? Are there any tools, scripts, or APIs I can use to quickly resolve it? The goal will be to uncover its origin and content quickly. Once I understand that, I can determine its relevance to the problem.
|
| 87/2 |
2026/10/13 22:40 |
tool |
git-show |
0m
Args:
Results: map[Output:commit b57e3ca1fb192962f5b062c2e13e1bab1936292c
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Date: Wed Dec 20 19:36:20 2023 +0530
drm/amdgpu: Use kvcalloc instead of kvmalloc_array in amdgpu_cs_parser_bos()
kvmalloc_array + __GFP_ZERO is the same with kvcalloc.
Fixes the below:
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:873 amdgpu_cs_parser_bos() warn: Please consider using kvcalloc instead of kvmalloc_array
Cc: Christian KΓΆnig <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Christian KΓΆnig <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index e50be6500030..83c7fc09218c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -870,9 +870,9 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
struct amdgpu_bo *bo = e->bo;
int i;
- e->user_pages = kvmalloc_array(bo->tbo.ttm->num_pages,
- sizeof(struct page *),
- GFP_KERNEL | __GFP_ZERO);
+ e->user_pages = kvcalloc(bo->tbo.ttm->num_pages,
+ sizeof(struct page *),
+ GFP_KERNEL);
if (!e->user_pages) {
DRM_ERROR("kvmalloc_array failure\n");
r = -ENOMEM;
]
|
| 88/2 |
2026/10/13 22:40 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 18719
output: 25
thoughts: 16
Thoughts: Okay, here's my interpretation of that:
**Investigating a Hash Value**
Right, let's take a look at this hash: `a292fdecd728`. This likely represents a unique identifier β could be a commit, a file, a transaction ID, or even a specific state in some system. Now, my immediate thoughts are: what kind of context does this hash exist in? Where did it come from? Knowing the origin is key to knowing how to proceed. Is this a system I recognize, or something new? Is there a known format, algorithm, or associated metadata that I should be aware of? This needs immediate investigation so I can interpret this number.
|
| 89/2 |
2026/10/13 22:40 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a292fdecd72834b3bec380baa5db1e69e7f70679
Author: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Date: Wed Oct 30 10:26:07 2024 +0530
drm/amdgpu: Implement userqueue signal/wait IOCTL
This patch introduces new IOCTL for userqueue secure semaphore.
The signal IOCTL called from userspace application creates a drm
syncobj and array of bo GEM handles and passed in as parameter to
the driver to install the fence into it.
The wait IOCTL gets an array of drm syncobjs, finds the fences
attached to the drm syncobjs and obtain the array of
memory_address/fence_value combintion which are returned to
userspace.
v2: (Christian)
- Install fence into GEM BO object.
- Lock all BO's using the dma resv subsystem
- Reorder the sequence in signal IOCTL function.
- Get write pointer from the shadow wptr
- use userq_fence to fetch the va/value in wait IOCTL.
v3: (Christian)
- Use drm_exec helper for the proper BO drm reserve and avoid BO
lock/unlock issues.
- fence/fence driver reference count logic for signal/wait IOCTLs.
v4: (Christian)
- Fixed the drm_exec calling sequence
- use dma_resv_for_each_fence_unlock if BO's are not locked
- Modified the fence_info array storing logic.
v5: (Christian)
- Keep fence_drv until wait queue execution.
- Add dma_fence_wait for other fences.
- Lock BO's using drm_exec as the number of fences in them could
change.
- Install signaled fences as well into BO/Syncobj.
- Move Syncobj fence installation code after the drm_exec_prepare_array.
- Directly add dma_resv_usage_rw(args->bo_flags....
- remove unnecessary dma_fence_put.
v6: (Christian)
- Add xarray stuff to store the fence_drv
- Implement a function to iterate over the xarray and drop
the fence_drv references.
- Add drm_exec_until_all_locked() wrapper
- Add a check that if we haven't exceeded the user allocated num_fences
before adding dma_fence to the fences array.
v7: (Christian)
- Use memdup_user() for kmalloc_array + copy_from_user
- Move the fence_drv references from the xarray into the newly created fence
and drop the fence_drv references when we signal this fence.
- Move this locking of BOs before the "if (!wait_info->num_fences)",
this way you need this code block only once.
- Merge the error handling code and the cleanup + return 0 code.
- Initializing the xa should probably be done in the userq code.
- Remove the userq back pointer stored in fence_drv.
- Pass xarray as parameter in amdgpu_userq_walk_and_drop_fence_drv()
v8: (Christian)
- Move fence_drv references must come before adding the fence to the list.
- Use xa_lock_irqsave_nested for nested spinlock operations.
- userq_mgr should be per fpriv and not one per device.
- Restructure the interrupt process code for the early exit of the loop.
- The reference acquired in the syncobj fence replace code needs to be
kept around.
- Modify the dma_fence acquire placement in wait IOCTL.
- Move USERQ_BO_WRITE flag to UAPI header file.
- drop the fence drv reference after telling the hw to stop accessing it.
- Add multi sync object support to userq signal IOCTL.
V9: (Christian)
- Store all the fence_drv ref to other drivers and not ourself.
- Remove the userq fence xa implementation and replace with
kvmalloc_array.
v10: (Christian)
- Add a comment for the userq_xa xarray
- drop the if check of userq_fence->fence_drv_array
- use the i variable to initialize userq_fence->fence_drv_array_count
- drop the fence reference before you free the array in the error handling,
otherwise it could be that some references leaked.
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Suggested-by: Christian KΓΆnig <christian.koenig@amd.com>
Reviewed-by: Christian KΓΆnig <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index 02511b6eb6af..be10fbe293e4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -1094,6 +1094,12 @@ struct amdgpu_device {
struct amdgpu_mqd mqds[AMDGPU_HW_IP_NUM];
const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM];
+ /* xarray used to retrieve the user queue fence driver reference
+ * in the EOP interrupt handler to signal the particular user
+ * queue fence.
+ */
+ struct xarray userq_xa;
+
/* df */
struct amdgpu_df df;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
index 0221e7928989..148f859c3b98 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
@@ -2950,6 +2950,8 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {
DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+ DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_SIGNAL, amdgpu_userq_signal_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
+ DRM_IOCTL_DEF_DRV(AMDGPU_USERQ_WAIT, amdgpu_userq_wait_ioctl, DRM_AUTH|DRM_RENDER_ALLOW),
};
static const struct drm_driver amdgpu_kms_driver = {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
index 3693453d8b60..8f9d2427d380 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
@@ -25,6 +25,7 @@
#include <linux/kref.h>
#include <linux/slab.h>
+#include <drm/drm_exec.h>
#include <drm/drm_syncobj.h>
#include "amdgpu.h"
@@ -92,6 +93,7 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
spin_lock_init(&fence_drv->fence_list_lock);
fence_drv->adev = adev;
+ fence_drv->uq_fence_drv_xa_ref = &userq->uq_fence_drv_xa;
fence_drv->context = dma_fence_context_alloc(1);
get_task_comm(fence_drv->timeline_name, current);
@@ -105,6 +107,7 @@ void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_d
struct amdgpu_userq_fence *userq_fence, *tmp;
struct dma_fence *fence;
u64 rptr;
+ int i;
if (!fence_drv)
return;
@@ -115,14 +118,16 @@ void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_d
list_for_each_entry_safe(userq_fence, tmp, &fence_drv->fences, link) {
fence = &userq_fence->base;
- if (rptr >= fence->seqno) {
- dma_fence_signal(fence);
- list_del(&userq_fence->link);
-
- dma_fence_put(fence);
- } else {
+ if (rptr < fence->seqno)
break;
- }
+
+ dma_fence_signal(fence);
+
+ for (i = 0; i < userq_fence->fence_drv_array_count; i++)
+ amdgpu_userq_fence_driver_put(userq_fence->fence_drv_array[i]);
+
+ list_del(&userq_fence->link);
+ dma_fence_put(fence);
}
spin_unlock(&fence_drv->fence_list_lock);
}
@@ -132,8 +137,11 @@ void amdgpu_userq_fence_driver_destroy(struct kref *ref)
struct amdgpu_userq_fence_driver *fence_drv = container_of(ref,
struct amdgpu_userq_fence_driver,
refcount);
+ struct amdgpu_userq_fence_driver *xa_fence_drv;
struct amdgpu_device *adev = fence_drv->adev;
struct amdgpu_userq_fence *fence, *tmp;
+ struct xarray *xa = &adev->userq_xa;
+ unsigned long index;
struct dma_fence *f;
spin_lock(&fence_drv->fence_list_lock);
@@ -150,6 +158,12 @@ void amdgpu_userq_fence_driver_destroy(struct kref *ref)
}
spin_unlock(&fence_drv->fence_list_lock);
+ xa_lock(xa);
+ xa_for_each(xa, index, xa_fence_drv)
+ if (xa_fence_drv == fence_drv)
+ __xa_erase(xa, index);
+ xa_unlock(xa);
+
/* Free seq64 memory */
amdgpu_seq64_free(adev, fence_drv->gpu_addr);
kfree(fence_drv);
@@ -192,6 +206,33 @@ int amdgpu_userq_fence_create(struct amdgpu_usermode_queue *userq,
amdgpu_userq_fence_driver_get(fence_drv);
dma_fence_get(fence);
+ if (!xa_empty(&userq->uq_fence_drv_xa)) {
+ struct amdgpu_userq_fence_driver *stored_fence_drv;
+ unsigned long index, count = 0;
+ int i = 0;
+
+ xa_for_each(&userq->uq_fence_drv_xa, index, stored_fence_drv)
+ count++;
+
+ userq_fence->fence_drv_array =
+ kvmalloc_array(count,
+ sizeof(struct amdgpu_userq_fence_driver *),
+ GFP_KERNEL);
+
+ if (userq_fence->fence_drv_array) {
+ xa_for_each(&userq->uq_fence_drv_xa, index, stored_fence_drv) {
+ userq_fence->fence_drv_array[i] = stored_fence_drv;
+ xa_erase(&userq->uq_fence_drv_xa, index);
+ i++;
+ }
+ }
+
+ userq_fence->fence_drv_array_count = i;
+ } else {
+ userq_fence->fence_drv_array = NULL;
+ userq_fence->fence_drv_array_count = 0;
+ }
+
/* Check if hardware has already processed the job */
spin_lock_irqsave(&fence_drv->fence_list_lock, flags);
if (!dma_fence_is_signaled_locked(fence))
@@ -241,6 +282,8 @@ static void amdgpu_userq_fence_free(struct rcu_head *rcu)
/* Release the fence driver reference */
amdgpu_userq_fence_driver_put(fence_drv);
+
+ kvfree(userq_fence->fence_drv_array);
kmem_cache_free(amdgpu_userq_fence_slab, userq_fence);
}
@@ -256,3 +299,392 @@ static const struct dma_fence_ops amdgpu_userq_fence_ops = {
.signaled = amdgpu_userq_fence_signaled,
.release = amdgpu_userq_fence_release,
};
+
+/**
+ * amdgpu_userq_fence_read_wptr - Read the userq wptr value
+ *
+ * @filp: drm file private data structure
+ * @queue: user mode queue structure pointer
+ * @wptr: write pointer value
+ *
+ * Read the wptr value from userq's MQD. The userq signal IOCTL
+ * creates a dma_fence for the shared buffers that expects the
+ * RPTR value written to seq64 memory >= WPTR.
+ *
+ * Returns wptr value on success, error on failure.
+ */
+static int amdgpu_userq_fence_read_wptr(struct drm_file *filp,
+ struct amdgpu_usermode_queue *queue,
+ u64 *wptr)
+{
+ struct amdgpu_fpriv *fpriv = filp->driver_priv;
+ struct amdgpu_bo_va_mapping *mapping;
+ struct amdgpu_vm *vm = &fpriv->vm;
+ struct amdgpu_bo *bo;
+ u64 addr, *ptr;
+ int r;
+
+ addr = queue->userq_prop->wptr_gpu_addr;
+ addr &= AMDGPU_GMC_HOLE_MASK;
+
+ mapping = amdgpu_vm_bo_lookup_mapping(vm, addr >> PAGE_SHIFT);
+ if (!mapping)
+ return -EINVAL;
+
+ bo = mapping->bo_va->base.bo;
+ r = amdgpu_bo_reserve(bo, true);
+ if (r) {
+ DRM_ERROR("Failed to reserve userqueue wptr bo");
+ return r;
+ }
+
+ r = amdgpu_bo_kmap(bo, (void **)&ptr);
+ if (r) {
+ DRM_ERROR("Failed mapping the userqueue wptr bo");
+ goto map_error;
+ }
+
+ *wptr = le64_to_cpu(*ptr);
+
+ amdgpu_bo_kunmap(bo);
+ amdgpu_bo_unreserve(bo);
+
+ return 0;
+
+map_error:
+ amdgpu_bo_unreserve(bo);
+ return r;
+}
+
+int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp)
+{
+ struct amdgpu_fpriv *fpriv = filp->driver_priv;
+ struct amdgpu_userq_mgr *userq_mgr = &fpriv->userq_mgr;
+ struct drm_amdgpu_userq_signal *args = data;
+ struct amdgpu_usermode_queue *queue;
+ struct drm_gem_object **gobj = NULL;
+ struct drm_syncobj **syncobj = NULL;
+ u32 *syncobj_handles, num_syncobj_handles;
+ u32 *bo_handles, num_bo_handles;
+ int r, i, entry, boentry;
+ struct dma_fence *fence;
+ struct drm_exec exec;
+ u64 wptr;
+
+ /* Array of syncobj handles */
+ num_syncobj_handles = args->num_syncobj_handles;
+ syncobj_handles = memdup_user(u64_to_user_ptr(args->syncobj_handles_array),
+ sizeof(u32) * num_syncobj_handles);
+ if (IS_ERR(syncobj_handles))
+ return PTR_ERR(syncobj_handles);
+
+ /* Array of pointers to the looked up syncobjs */
+ syncobj = kmalloc_array(num_syncobj_handles, sizeof(*syncobj), GFP_KERNEL);
+ if (!syncobj) {
+ r = -ENOMEM;
+ goto free_syncobj_handles;
+ }
+
+ for (entry = 0; entry < num_syncobj_handles; entry++) {
+ syncobj[entry] = drm_syncobj_find(filp, syncobj_handles[entry]);
+ if (!syncobj[entry]) {
+ r = -ENOENT;
+ goto free_syncobj;
+ }
+ }
+
+ /* Array of bo handles */
+ num_bo_handles = args->num_bo_handles;
+ bo_handles = memdup_user(u64_to_user_ptr(args->bo_handles_array),
+ sizeof(u32) * num_bo_handles);
+ if (IS_ERR(bo_handles))
+ goto free_syncobj;
+
+ /* Array of pointers to the GEM objects */
+ gobj = kmalloc_array(num_bo_handles, sizeof(*gobj), GFP_KERNEL);
+ if (!gobj) {
+ r = -ENOMEM;
+ goto free_bo_handles;
+ }
+
+ for (boentry = 0; boentry < num_bo_handles; boentry++) {
+ gobj[boentry] = drm_gem_object_lookup(filp, bo_handles[boentry]);
+ if (!gobj[boentry]) {
+ r = -ENOENT;
+ goto put_gobj;
+ }
+ }
+
+ drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
+ drm_exec_until_all_locked(&exec) {
+ r = drm_exec_prepare_array(&exec, gobj, num_bo_handles, 1);
+ drm_exec_retry_on_contention(&exec);
+ if (r)
+ goto exec_fini;
+ }
+
+ /*Retrieve the user queue */
+ queue = idr_find(&userq_mgr->userq_idr, args->queue_id);
+ if (!queue) {
+ r = -ENOENT;
+ goto exec_fini;
+ }
+
+ r = amdgpu_userq_fence_read_wptr(filp, queue, &wptr);
+ if (r)
+ goto exec_fini;
+
+ /* Create a new fence */
+ r = amdgpu_userq_fence_create(queue, wptr, &fence);
+ if (r)
+ goto exec_fini;
+
+ for (i = 0; i < num_bo_handles; i++)
+ dma_resv_add_fence(gobj[i]->resv, fence,
+ dma_resv_usage_rw(args->bo_flags &
+ AMDGPU_USERQ_BO_WRITE));
+
+ /* Add the created fence to syncobj/BO's */
+ for (i = 0; i < num_syncobj_handles; i++)
+ drm_syncobj_replace_fence(syncobj[i], fence);
+
+ /* drop the reference acquired in fence creation function */
+ dma_fence_put(fence);
+
+exec_fini:
+ drm_exec_fini(&exec);
+put_gobj:
+ while (boentry-- > 0)
+ drm_gem_object_put(gobj[boentry]);
+ kfree(gobj);
+free_bo_handles:
+ kfree(bo_handles);
+free_syncobj:
+ while (entry-- > 0)
+ if (syncobj[entry])
+ drm_syncobj_put(syncobj[entry]);
+ kfree(syncobj);
+free_syncobj_handles:
+ kfree(syncobj_handles);
+
+ return r;
+}
+
+int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp)
+{
+ struct drm_amdgpu_userq_fence_info *fence_info = NULL;
+ struct drm_amdgpu_userq_wait *wait_info = data;
+ u32 *syncobj_handles, *bo_handles;
+ struct dma_fence **fences = NULL;
+ u32 num_syncobj, num_bo_handles;
+ struct drm_gem_object **gobj;
+ struct drm_exec exec;
+ int r, i, entry, cnt;
+ u64 num_fences = 0;
+
+ num_bo_handles = wait_info->num_bo_handles;
+ bo_handles = memdup_user(u64_to_user_ptr(wait_info->bo_handles_array),
+ sizeof(u32) * num_bo_handles);
+ if (IS_ERR(bo_handles))
+ return PTR_ERR(bo_handles);
+
+ num_syncobj = wait_info->num_syncobj_handles;
+ syncobj_handles = memdup_user(u64_to_user_ptr(wait_info->syncobj_handles_array),
+ sizeof(u32) * num_syncobj);
+ if (IS_ERR(syncobj_handles)) {
+ r = PTR_ERR(syncobj_handles);
+ goto free_bo_handles;
+ }
+
+ /* Array of GEM object handles */
+ gobj = kmalloc_array(num_bo_handles, sizeof(*gobj), GFP_KERNEL);
+ if (!gobj) {
+ r = -ENOMEM;
+ goto free_syncobj_handles;
+ }
+
+ for (entry = 0; entry < num_bo_handles; entry++) {
+ gobj[entry] = drm_gem_object_lookup(filp, bo_handles[entry]);
+ if (!gobj[entry]) {
+ r = -ENOENT;
+ goto put_gobj;
+ }
+ }
+
+ drm_exec_init(&exec, DRM_EXEC_INTERRUPTIBLE_WAIT, 0);
+ drm_exec_until_all_locked(&exec) {
+ r = drm_exec_prepare_array(&exec, gobj, num_bo_handles, 0);
+ drm_exec_retry_on_contention(&exec);
+ if (r) {
+ drm_exec_fini(&exec);
+ goto put_gobj;
+ }
+ }
+
+ if (!wait_info->num_fences) {
+ /* Count syncobj's fence */
+ for (i = 0; i < num_syncobj; i++) {
+ struct dma_fence *fence;
+
+ r = drm_syncobj_find_fence(filp, syncobj_handles[i],
+ 0, 0, &fence);
+ if (r)
+ goto exec_fini;
+
+ num_fences++;
+ dma_fence_put(fence);
+ }
+
+ /* Count GEM objects fence */
+ for (i = 0; i < num_bo_handles; i++) {
+ struct dma_resv_iter resv_cursor;
+ struct dma_fence *fence;
+
+ dma_resv_for_each_fence(&resv_cursor, gobj[i]->resv,
+ dma_resv_usage_rw(wait_info->bo_wait_flags &
+ AMDGPU_USERQ_BO_WRITE), fence)
+ num_fences++;
+ }
+
+ /*
+ * Passing num_fences = 0 means that userspace doesn't want to
+ * retrieve userq_fence_info. If num_fences = 0 we skip filling
+ * userq_fence_info and return the actual number of fences on
+ * args->num_fences.
+ */
+ wait_info->num_fences = num_fences;
+ } else {
+ /* Array of fence info */
+ fence_info = kmalloc_array(wait_info->num_fences, sizeof(*fence_info), GFP_KERNEL);
+ if (!fence_info) {
+ r = -ENOMEM;
+ goto exec_fini;
+ }
+
+ /* Array of fences */
+ fences = kmalloc_array(wait_info->num_fences, sizeof(*fences), GFP_KERNEL);
+ if (!fences) {
+ r = -ENOMEM;
+ goto free_fence_info;
+ }
+
+ /* Retrieve GEM objects fence */
+ for (i = 0; i < num_bo_handles; i++) {
+ struct dma_resv_iter resv_cursor;
+ struct dma_fence *fence;
+
+ dma_resv_for_each_fence(&resv_cursor, gobj[i]->resv,
+ dma_resv_usage_rw(wait_info->bo_wait_flags &
+ AMDGPU_USERQ_BO_WRITE), fence) {
+ if (WARN_ON_ONCE(num_fences >= wait_info->num_fences)) {
+ r = -EINVAL;
+ goto free_fences;
+ }
+
+ fences[num_fences++] = fence;
+ dma_fence_get(fence);
+ }
+ }
+
+ /* Retrieve syncobj's fence */
+ for (i = 0; i < num_syncobj; i++) {
+ struct dma_fence *fence;
+
+ r = drm_syncobj_find_fence(filp, syncobj_handles[i],
+ 0, 0, &fence);
+ if (r)
+ goto free_fences;
+
+ if (WARN_ON_ONCE(num_fences >= wait_info->num_fences)) {
+ r = -EINVAL;
+ goto free_fences;
+ }
+
+ fences[num_fences++] = fence;
+ }
+
+ for (i = 0, cnt = 0; i < wait_info->num_fences; i++) {
+ struct amdgpu_userq_fence_driver *fence_drv;
+ struct amdgpu_userq_fence *userq_fence;
+ u32 index;
+
+ userq_fence = to_amdgpu_userq_fence(fences[i]);
+ if (!userq_fence) {
+ /*
+ * Just waiting on other driver fences should
+ * be good for now
+ */
+ dma_fence_wait(fences[i], false);
+ dma_fence_put(fences[i]);
+
+ continue;
+ }
+
+ fence_drv = userq_fence->fence_drv;
+ /*
+ * We need to make sure the user queue release their reference
+ * to the fence drivers at some point before queue destruction.
+ * Otherwise, we would gather those references until we don't
+ * have any more space left and crash.
+ */
+ if (fence_drv->uq_fence_drv_xa_ref) {
+ r = xa_alloc(fence_drv->uq_fence_drv_xa_ref, &index, fence_drv,
+ xa_limit_32b, GFP_KERNEL);
+ if (r)
+ goto free_fences;
+
+ amdgpu_userq_fence_driver_get(fence_drv);
+ }
+
+ /* Store drm syncobj's gpu va address and value */
+ fence_info[cnt].va = fence_drv->gpu_addr;
+ fence_info[cnt].value = fences[i]->seqno;
+
+ dma_fence_put(fences[i]);
+ /* Increment the actual userq fence count */
+ cnt++;
+ }
+
+ wait_info->num_fences = cnt;
+ /* Copy userq fence info to user space */
+ if (copy_to_user(u64_to_user_ptr(wait_info->userq_fence_info),
+ fence_info, wait_info->num_fences * sizeof(*fence_info))) {
+ r = -EFAULT;
+ goto free_fences;
+ }
+
+ kfree(fences);
+ kfree(fence_info);
+ }
+
+ drm_exec_fini(&exec);
+ for (i = 0; i < num_bo_handles; i++)
+ drm_gem_object_put(gobj[i]);
+ kfree(gobj);
+
+ kfree(syncobj_handles);
+ kfree(bo_handles);
+
+ return 0;
+
+free_fences:
+ while (num_fences-- > 0)
+ dma_fence_put(fences[num_fences]);
+ kfree(fences);
+free_fence_info:
+ kfree(fence_info);
+exec_fini:
+ drm_exec_fini(&exec);
+put_gobj:
+ while (entry-- > 0)
+ drm_gem_object_put(gobj[entry]);
+ kfree(gobj);
+free_syncobj_handles:
+ kfree(syncobj_handles);
+free_bo_handles:
+ kfree(bo_handles);
+
+ return r;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h
index c3e04cdbb9e7..f72424248cc5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.h
@@ -37,7 +37,9 @@ struct amdgpu_userq_fence {
*/
spinlock_t lock;
struct list_head link;
+ unsigned long fence_drv_array_count;
struct amdgpu_userq_fence_driver *fence_drv;
+ struct amdgpu_userq_fence_driver **fence_drv_array;
};
struct amdgpu_userq_fence_driver {
@@ -52,6 +54,7 @@ struct amdgpu_userq_fence_driver {
spinlock_t fence_list_lock;
struct list_head fences;
struct amdgpu_device *adev;
+ struct xarray *uq_fence_drv_xa_ref;
char timeline_name[TASK_COMM_LEN];
};
@@ -65,5 +68,9 @@ int amdgpu_userq_fence_driver_alloc(struct amdgpu_device *adev,
struct amdgpu_usermode_queue *userq);
void amdgpu_userq_fence_driver_process(struct amdgpu_userq_fence_driver *fence_drv);
void amdgpu_userq_fence_driver_destroy(struct kref *ref);
+int amdgpu_userq_signal_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp);
+int amdgpu_userq_wait_ioctl(struct drm_device *dev, void *data,
+ struct drm_file *filp);
#endif
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
index bcd86c1b3a75..34c1297d7970 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
@@ -27,6 +27,32 @@
#include "amdgpu_userqueue.h"
#include "amdgpu_userq_fence.h"
+static void amdgpu_userq_walk_and_drop_fence_drv(struct xarray *xa)
+{
+ struct amdgpu_userq_fence_driver *fence_drv;
+ unsigned long index;
+
+ if (xa_empty(xa))
+ return;
+
+ xa_lock(xa);
+ xa_for_each(xa, index, fence_drv) {
+ __xa_erase(xa, index);
+ amdgpu_userq_fence_driver_put(fence_drv);
+ }
+
+ xa_unlock(xa);
+}
+
+static void
+amdgpu_userq_fence_driver_free(struct amdgpu_usermode_queue *userq)
+{
+ amdgpu_userq_walk_and_drop_fence_drv(&userq->uq_fence_drv_xa);
+ xa_destroy(&userq->uq_fence_drv_xa);
+ /* Drop the fence_drv reference held by user queue */
+ amdgpu_userq_fence_driver_put(userq->fence_drv);
+}
+
static void
amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
struct amdgpu_usermode_queue *queue,
@@ -36,7 +62,7 @@ amdgpu_userqueue_cleanup(struct amdgpu_userq_mgr *uq_mgr,
const struct amdgpu_userq_funcs *uq_funcs = adev->userq_funcs[queue->queue_type];
uq_funcs->mqd_destroy(uq_mgr, queue);
- amdgpu_userq_fence_driver_put(queue->fence_drv);
+ amdgpu_userq_fence_driver_free(queue);
idr_remove(&uq_mgr->userq_idr, queue_id);
kfree(queue);
}
@@ -234,6 +260,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
}
queue->doorbell_index = index;
+ xa_init_flags(&queue->uq_fence_drv_xa, XA_FLAGS_ALLOC);
r = amdgpu_userq_fence_driver_alloc(adev, queue);
if (r) {
DRM_ERROR("Failed to alloc fence driver\n");
diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
index 76a59c350c2a..7df837fedce0 100644
--- a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
+++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
@@ -47,6 +47,7 @@ struct amdgpu_usermode_queue {
struct amdgpu_userq_obj db_obj;
struct amdgpu_userq_obj fw_obj;
struct amdgpu_userq_obj wptr_obj;
+ struct xarray uq_fence_drv_xa;
struct amdgpu_userq_fence_driver *fence_drv;
};
]
|
| 90/2 |
2026/10/13 22:40 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 28390
output: 25
thoughts: 175
Thoughts: **Analyzing Memory Allocation in a Recent Commit**
Okay, so I'm looking at this commit and immediately something feels a little off with the memory allocation strategy here. I see they're using `memdup_user` for both `syncobj_handles` and `bo_handles`, which are arrays of `u32` as the code indicates. But then, for the `syncobj` and `gobj` structures, they're using `kmalloc_array`. I'm trying to wrap my head around the rationale for this divergence. Itβs not immediately apparent why we'd choose different methods for what appear, at face value, to be similar allocation needs. This doesnβt seem related to the more nuanced situation of using `kvmalloc` for user-controlled unbounded arrays.
To get a clearer picture, let's go back and check out the rationale behind commit `847b371debf3` "drm/gpusvm: Fix MM reference leak in drm_gpusvm_range_evict." Understanding the context there might illuminate the current approach.
|
| 91/2 |
2026/10/13 22:40 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 847b371debf3c8c72384ab7b9a0c4123a74cc925
Author: Matthew Brost <matthew.brost@intel.com>
Date: Tue Jul 14 10:00:25 2026 -0700
drm/gpusvm: Fix MM reference leak in drm_gpusvm_range_evict
If kvmalloc_array() fails in drm_gpusvm_range_evict(), the MM
reference acquired earlier is not released, resulting in a reference
leak.
Fix this by dropping the MM reference on the kvmalloc_array()
failure path.
Fixes: 99624bdff867 ("drm/gpusvm: Add support for GPU Shared Virtual Memory")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Link: https://patch.msgid.link/20260714170025.3487974-1-matthew.brost@intel.com
diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
index 9a06ff7d2608..9aeaca02e928 100644
--- a/drivers/gpu/drm/drm_gpusvm.c
+++ b/drivers/gpu/drm/drm_gpusvm.c
@@ -1753,8 +1753,10 @@ int drm_gpusvm_range_evict(struct drm_gpusvm *gpusvm,
return -EFAULT;
pfns = kvmalloc_array(npages, sizeof(*pfns), GFP_KERNEL);
- if (!pfns)
+ if (!pfns) {
+ mmput(mm);
return -ENOMEM;
+ }
hmm_range.hmm_pfns = pfns;
while (!time_after(jiffies, timeout)) {
]
|
| 92/2 |
2026/10/13 22:40 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 29390
output: 40
thoughts: 728
Thoughts: **Memory Leak Fix: A Familiar Pattern**
Alright, this looks like a straightforward memory leak fix. Let's break down what's happening. The core issue revolves around an unbounded, user-controlled allocation size within `drm_mode_create_lease_ioctl`. Specifically, the code uses `kzalloc_objs` (which, as we know, is a wrapper for `kcalloc`) to allocate an array of pointers. The size of this array, controlled by `object_count`, can get dangerously large. When `object_count` gets past `MAX_PAGE_ORDER`, the page allocator throws a warning.
The fix, as proposed, is to switch to `kvzalloc_objs` (which wraps `kvcalloc`) and, consequently, `kvfree`. Simple enough on the surface. But, let's see if we can understand this better. It seems like the common issue is allocating a list with a possibly large size.
I started digging into similar issues within `drivers/gpu/drm/` to see if there was precedent. Here's what I found, and it's quite revealing:
1. `bca45af5998a` (drm/vc4): The BO cache size list was scaling with the largest BO ever freed. A large BO, like 64 MiB, could trigger an order-6 allocation, which could fail due to fragmentation and trigger `warn_alloc()`. The fix was `kvmalloc_objs()`, so the large lists could fall back to `vmalloc()`, which avoids the allocation failure.
2. `a1ba4594232c` (drm/amdgpu): Here, `kvcalloc` directly used the user-supplied `num_entries`. This could lead to a really large `num_entries`, which produces an allocation exceeding `INT_MAX`, and triggers a warning in `__kvmalloc_node_noprof()`. The fix added a bounds check before invoking `kvzalloc()`. Good to know!
3. `0829b5bcdd3b` (drm/i915): Capped the number of relocations to avoid `kvmalloc` warning for `size > INT_MAX`.
4. `a8eba56abcad` (drm/exec): A straight switch to `kvmalloc_objs` from `kvmalloc_array`.
5. `c4ac100e9ae2` (drm/amdgpu): Replaced `kvmalloc_array() + copy_from_user()` with `vmemdup_array_user()` on the fast path. Okay, interesting. Wait, `vmemdup_array_user()`? Let's check this against `memdup_array_user`.
So, in our bug, `memdup_array_user` is used for `object_ids`. `memdup_array_user` calls `memdup_user`, which uses `kmalloc` with `__GFP_NOWARN`. This means it silently fails for really large sizes. However, our `objects` array is allocated with `kzalloc_objs`, which uses `GFP_KERNEL` without `__GFP_NOWARN`, and that's why we get the warning. This seems like it is a pattern!
The proposed fix of `kvzalloc_objs` for `objects` makes sense here.
Finally, I'll search for `kvmalloc_objs` in `drivers/gpu/drm/` to double-check that this fix is indeed the right approach and see how frequently we've applied this pattern.
|
| 93/2 |
2026/10/13 22:40 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc_objs] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:bca45af5998a drm/vc4: Use kvmalloc_objs() for the BO cache size list
a8eba56abcad drm/exec: Use kvmalloc_objs for exec->objects
189f164e573e Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
]
|
| 94/2 |
2026/10/13 22:40 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 31023
output: 27
thoughts: 18
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:
**Investigating a Specific Identifier**
Alright, let's take a look at this one: `189f164e573e`. Just the identifier itself doesn't tell us much, but it immediately flags the need for deeper analysis. Based on its structure, I'm already mentally forming some hypotheses. Is this a hash value? A unique transaction ID? A process identifier? The format hints at something hexadecimal, so my initial focus will be on the potential systems or data stores where this kind of representation is prevalent within our infrastructure. I'll need to correlate this identifier to its context. My first step will be to search the relevant logs and data sources, using this identifier as the primary query term. I'm expecting some hits there. I'll also want to look at system metadata to look for connections. Depending on the results of the initial searches, I might need to move to a more granular analysis to dig further.
|
| 95/2 |
2026/10/13 22:40 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 189f164e573e18d9f8876dbd3ad8fcbe11f93037
Author: Kees Cook <kees@kernel.org>
Date: Sat Feb 21 23:46:04 2026 -0800
Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses
Conversion performed via this Coccinelle script:
// SPDX-License-Identifier: GPL-2.0-only
// Options: --include-headers-for-types --all-includes --include-headers --keep-comments
virtual patch
@gfp depends on patch && !(file in "tools") && !(file in "samples")@
identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex,
kzalloc_obj,kzalloc_objs,kzalloc_flex,
kvmalloc_obj,kvmalloc_objs,kvmalloc_flex,
kvzalloc_obj,kvzalloc_objs,kvzalloc_flex};
@@
ALLOC(...
- , GFP_KERNEL
)
$ make coccicheck MODE=patch COCCI=gfp.cocci
Build and boot tested x86_64 with Fedora 42's GCC and Clang:
Linux version 6.19.0+ (user@host) (gcc (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7), GNU ld version 2.44-12.fc42) #1 SMP PREEMPT_DYNAMIC 1970-01-01
Linux version 6.19.0+ (user@host) (clang version 20.1.8 (Fedora 20.1.8-4.fc42), LLD 20.1.8) #1 SMP PREEMPT_DYNAMIC 1970-01-01
Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/arch/arm/probes/kprobes/test-core.c b/arch/arm/probes/kprobes/test-core.c
index ef93f2f1db62..7a2baa135f0f 100644
--- a/arch/arm/probes/kprobes/test-core.c
+++ b/arch/arm/probes/kprobes/test-core.c
@@ -764,7 +764,7 @@ static int coverage_start_fn(const struct decode_header *h, void *args)
static int coverage_start(const union decode_item *table)
{
coverage.base = kmalloc_objs(struct coverage_entry,
- MAX_COVERAGE_ENTRIES, GFP_KERNEL);
+ MAX_COVERAGE_ENTRIES);
coverage.num_entries = 0;
coverage.nesting = 0;
return table_iter(table, coverage_start_fn, &coverage);
diff --git a/arch/mips/kernel/smp-cps.c b/arch/mips/kernel/smp-cps.c
index 70a846c5ddba..b01ebaace48e 100644
--- a/arch/mips/kernel/smp-cps.c
+++ b/arch/mips/kernel/smp-cps.c
@@ -342,7 +342,7 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
/* Allocate cluster boot configuration structs */
nclusters = mips_cps_numclusters();
mips_cps_cluster_bootcfg = kzalloc_objs(*mips_cps_cluster_bootcfg,
- nclusters, GFP_KERNEL);
+ nclusters);
if (!mips_cps_cluster_bootcfg)
goto err_out;
@@ -368,8 +368,7 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
int v;
core_vpes = core_vpe_count(cl, c);
core_bootcfg[c].vpe_config = kzalloc_objs(*core_bootcfg[c].vpe_config,
- core_vpes,
- GFP_KERNEL);
+ core_vpes);
for (v = 0; v < core_vpes; v++)
cpumask_set_cpu(nvpe++, &mips_cps_cluster_bootcfg[cl].cpumask);
if (!core_bootcfg[c].vpe_config)
diff --git a/arch/powerpc/kvm/e500_mmu.c b/arch/powerpc/kvm/e500_mmu.c
index 13bcadccb2b7..48580c85f23b 100644
--- a/arch/powerpc/kvm/e500_mmu.c
+++ b/arch/powerpc/kvm/e500_mmu.c
@@ -913,8 +913,7 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
vcpu_e500->gtlb_params[1].sets = 1;
vcpu_e500->gtlb_arch = kmalloc_objs(*vcpu_e500->gtlb_arch,
- KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE,
- GFP_KERNEL);
+ KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE);
if (!vcpu_e500->gtlb_arch)
return -ENOMEM;
@@ -922,14 +921,12 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE;
vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref,
- vcpu_e500->gtlb_params[0].entries,
- GFP_KERNEL);
+ vcpu_e500->gtlb_params[0].entries);
if (!vcpu_e500->gtlb_priv[0])
goto free_vcpu;
vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_ref,
- vcpu_e500->gtlb_params[1].entries,
- GFP_KERNEL);
+ vcpu_e500->gtlb_params[1].entries);
if (!vcpu_e500->gtlb_priv[1])
goto free_vcpu;
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index db98e9af8812..c1563b4eaa94 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -1699,8 +1699,7 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
/* Needed for hotplug/migration */
if (!per_nest_pmu_arr) {
per_nest_pmu_arr = kzalloc_objs(struct imc_pmu *,
- get_max_nest_dev() + 1,
- GFP_KERNEL);
+ get_max_nest_dev() + 1);
if (!per_nest_pmu_arr)
goto err;
}
diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
index d4665daa34c2..10fa9b844fcc 100644
--- a/arch/powerpc/platforms/cell/spufs/file.c
+++ b/arch/powerpc/platforms/cell/spufs/file.c
@@ -2282,7 +2282,7 @@ static int spufs_switch_log_open(struct inode *inode, struct file *file)
}
ctx->switch_log = kmalloc_flex(*ctx->switch_log, log,
- SWITCH_LOG_BUFSIZE, GFP_KERNEL);
+ SWITCH_LOG_BUFSIZE);
if (!ctx->switch_log) {
rc = -ENOMEM;
diff --git a/arch/powerpc/platforms/powernv/opal-async.c b/arch/powerpc/platforms/powernv/opal-async.c
index 2cacfe5407c9..6560c024bfd2 100644
--- a/arch/powerpc/platforms/powernv/opal-async.c
+++ b/arch/powerpc/platforms/powernv/opal-async.c
@@ -266,7 +266,7 @@ int __init opal_async_comp_init(void)
opal_max_async_tokens = be32_to_cpup(async);
opal_async_tokens = kzalloc_objs(*opal_async_tokens,
- opal_max_async_tokens, GFP_KERNEL);
+ opal_max_async_tokens);
if (!opal_async_tokens) {
err = -ENOMEM;
goto out_opal_node;
diff --git a/arch/powerpc/platforms/pseries/papr_platform_attributes.c b/arch/powerpc/platforms/pseries/papr_platform_attributes.c
index 38b417c158ba..c6159870de0e 100644
--- a/arch/powerpc/platforms/pseries/papr_platform_attributes.c
+++ b/arch/powerpc/platforms/pseries/papr_platform_attributes.c
@@ -314,8 +314,7 @@ static int __init papr_init(void)
/* Allocate the groups before registering */
for (idx = 0; idx < num_attrs; idx++) {
papr_groups[idx].pg.attrs = kzalloc_objs(*papr_groups[idx].pg.attrs,
- KOBJ_MAX_ATTRS + 1,
- GFP_KERNEL);
+ KOBJ_MAX_ATTRS + 1);
if (!papr_groups[idx].pg.attrs)
goto out_pgattrs;
diff --git a/arch/riscv/kernel/module.c b/arch/riscv/kernel/module.c
index cc2f980700f3..1961135689db 100644
--- a/arch/riscv/kernel/module.c
+++ b/arch/riscv/kernel/module.c
@@ -754,7 +754,7 @@ initialize_relocation_hashtable(unsigned int num_relocations,
/* Number of relocations may be large, so kvmalloc it */
*relocation_hashtable = kvmalloc_objs(**relocation_hashtable,
- hashtable_size, GFP_KERNEL);
+ hashtable_size);
if (!*relocation_hashtable)
return 0;
diff --git a/arch/riscv/kvm/vcpu_sbi_fwft.c b/arch/riscv/kvm/vcpu_sbi_fwft.c
index 14cea431b863..2eab15339694 100644
--- a/arch/riscv/kvm/vcpu_sbi_fwft.c
+++ b/arch/riscv/kvm/vcpu_sbi_fwft.c
@@ -353,7 +353,7 @@ static int kvm_sbi_ext_fwft_init(struct kvm_vcpu *vcpu)
int i;
fwft->configs = kzalloc_objs(struct kvm_sbi_fwft_config,
- ARRAY_SIZE(features), GFP_KERNEL);
+ ARRAY_SIZE(features));
if (!fwft->configs)
return -ENOMEM;
diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c
index 8fd3e47307a3..86f71a3d1ef2 100644
--- a/arch/s390/kernel/perf_pai.c
+++ b/arch/s390/kernel/perf_pai.c
@@ -282,8 +282,7 @@ static int pai_alloc_cpu(struct perf_event *event, int cpu)
need_paiext_cb = true;
}
cpump->save = kvmalloc_objs(struct pai_userdata,
- pai_pmu[idx].num_avail + 1,
- GFP_KERNEL);
+ pai_pmu[idx].num_avail + 1);
if (!cpump->area || !cpump->save ||
(need_paiext_cb && !cpump->paiext_cb)) {
pai_free(mp);
diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
index 42f392e6add3..012b2bcaa8a0 100644
--- a/arch/um/drivers/ubd_kern.c
+++ b/arch/um/drivers/ubd_kern.c
@@ -1070,7 +1070,7 @@ static int __init ubd_init(void)
return -1;
irq_req_buffer = kmalloc_objs(struct io_thread_req *,
- UBD_REQ_BUFFER_SIZE, GFP_KERNEL);
+ UBD_REQ_BUFFER_SIZE);
irq_remainder = 0;
if (irq_req_buffer == NULL) {
@@ -1078,7 +1078,7 @@ static int __init ubd_init(void)
return -ENOMEM;
}
io_req_buffer = kmalloc_objs(struct io_thread_req *,
- UBD_REQ_BUFFER_SIZE, GFP_KERNEL);
+ UBD_REQ_BUFFER_SIZE);
io_remainder = 0;
diff --git a/arch/um/drivers/vfio_kern.c b/arch/um/drivers/vfio_kern.c
index 7b6492174da0..e6dab473cde4 100644
--- a/arch/um/drivers/vfio_kern.c
+++ b/arch/um/drivers/vfio_kern.c
@@ -515,7 +515,7 @@ static void uml_vfio_open_device(struct uml_vfio_device *dev)
}
dev->intr_ctx = kmalloc_objs(struct uml_vfio_intr_ctx,
- dev->udev.irq_count, GFP_KERNEL);
+ dev->udev.irq_count);
if (!dev->intr_ctx) {
pr_err("Failed to allocate interrupt context (%s)\n",
dev->name);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 41f571040145..cf3a4fe06ff2 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -7379,7 +7379,7 @@ static __always_inline int intel_pmu_init_hybrid(enum hybrid_pmu_type pmus)
x86_pmu.num_hybrid_pmus = hweight_long(pmus_mask);
x86_pmu.hybrid_pmu = kzalloc_objs(struct x86_hybrid_pmu,
- x86_pmu.num_hybrid_pmus, GFP_KERNEL);
+ x86_pmu.num_hybrid_pmus);
if (!x86_pmu.hybrid_pmu)
return -ENOMEM;
diff --git a/arch/x86/events/intel/uncore_discovery.c b/arch/x86/events/intel/uncore_discovery.c
index c8bf3983accf..12e259a988dd 100644
--- a/arch/x86/events/intel/uncore_discovery.c
+++ b/arch/x86/events/intel/uncore_discovery.c
@@ -745,8 +745,7 @@ intel_uncore_generic_init_uncores(enum uncore_access_type type_id, int num_extra
int i = 0;
uncores = kzalloc_objs(struct intel_uncore_type *,
- num_discovered_types[type_id] + num_extra + 1,
- GFP_KERNEL);
+ num_discovered_types[type_id] + num_extra + 1);
if (!uncores)
return empty_uncore;
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index d22cabe119b1..c5065f84b78b 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -2407,7 +2407,7 @@ static int __tdx_td_init(struct kvm *kvm, struct td_params *td_params,
/* TDVPS = TDVPR(4K page) + TDCX(multiple 4K pages), -1 for TDVPR. */
kvm_tdx->td.tdcx_nr_pages = tdx_sysinfo->td_ctrl.tdvps_base_size / PAGE_SIZE - 1;
tdcs_pages = kzalloc_objs(*kvm_tdx->td.tdcs_pages,
- kvm_tdx->td.tdcs_nr_pages, GFP_KERNEL);
+ kvm_tdx->td.tdcs_nr_pages);
if (!tdcs_pages)
goto free_tdr;
diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c
index 24b8b1c40e25..61f595410832 100644
--- a/block/blk-crypto-fallback.c
+++ b/block/blk-crypto-fallback.c
@@ -574,7 +574,7 @@ static int blk_crypto_fallback_init(void)
goto fail_destroy_profile;
blk_crypto_keyslots = kzalloc_objs(blk_crypto_keyslots[0],
- blk_crypto_num_keyslots, GFP_KERNEL);
+ blk_crypto_num_keyslots);
if (!blk_crypto_keyslots)
goto fail_free_wq;
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 54ee346ddb5a..9d1dd6ccfad7 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -1805,7 +1805,7 @@ static int disk_alloc_zone_resources(struct gendisk *disk,
disk->zone_wplugs_hash =
kzalloc_objs(struct hlist_head,
- disk_zone_wplugs_hash_size(disk), GFP_KERNEL);
+ disk_zone_wplugs_hash_size(disk));
if (!disk->zone_wplugs_hash)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/common/context.c b/drivers/accel/habanalabs/common/context.c
index 276c97aba992..69c68b187bb7 100644
--- a/drivers/accel/habanalabs/common/context.c
+++ b/drivers/accel/habanalabs/common/context.c
@@ -210,8 +210,7 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
atomic_set(&ctx->thread_ctx_switch_token, 1);
ctx->thread_ctx_switch_wait_token = 0;
ctx->cs_pending = kzalloc_objs(struct hl_fence *,
- hdev->asic_prop.max_pending_cs,
- GFP_KERNEL);
+ hdev->asic_prop.max_pending_cs);
if (!ctx->cs_pending)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/common/device.c b/drivers/accel/habanalabs/common/device.c
index d4c3473fb64f..09b27bac3a31 100644
--- a/drivers/accel/habanalabs/common/device.c
+++ b/drivers/accel/habanalabs/common/device.c
@@ -893,8 +893,7 @@ static int device_early_init(struct hl_device *hdev)
if (hdev->asic_prop.completion_queues_count) {
hdev->cq_wq = kzalloc_objs(struct workqueue_struct *,
- hdev->asic_prop.completion_queues_count,
- GFP_KERNEL);
+ hdev->asic_prop.completion_queues_count);
if (!hdev->cq_wq) {
rc = -ENOMEM;
goto asid_fini;
@@ -2159,8 +2158,7 @@ int hl_device_init(struct hl_device *hdev)
if (user_interrupt_cnt) {
hdev->user_interrupt = kzalloc_objs(*hdev->user_interrupt,
- user_interrupt_cnt,
- GFP_KERNEL);
+ user_interrupt_cnt);
if (!hdev->user_interrupt) {
rc = -ENOMEM;
goto early_fini;
@@ -2227,7 +2225,7 @@ int hl_device_init(struct hl_device *hdev)
*/
if (cq_cnt) {
hdev->completion_queue = kzalloc_objs(*hdev->completion_queue,
- cq_cnt, GFP_KERNEL);
+ cq_cnt);
if (!hdev->completion_queue) {
dev_err(hdev->dev,
@@ -2249,8 +2247,7 @@ int hl_device_init(struct hl_device *hdev)
}
hdev->shadow_cs_queue = kzalloc_objs(struct hl_cs *,
- hdev->asic_prop.max_pending_cs,
- GFP_KERNEL);
+ hdev->asic_prop.max_pending_cs);
if (!hdev->shadow_cs_queue) {
rc = -ENOMEM;
goto cq_fini;
diff --git a/drivers/accel/habanalabs/common/hw_queue.c b/drivers/accel/habanalabs/common/hw_queue.c
index f0ab99dd74d6..4232f374dfc3 100644
--- a/drivers/accel/habanalabs/common/hw_queue.c
+++ b/drivers/accel/habanalabs/common/hw_queue.c
@@ -1083,7 +1083,7 @@ int hl_hw_queues_create(struct hl_device *hdev)
int i, rc, q_ready_cnt;
hdev->kernel_queues = kzalloc_objs(*hdev->kernel_queues,
- asic->max_queues, GFP_KERNEL);
+ asic->max_queues);
if (!hdev->kernel_queues) {
dev_err(hdev->dev, "Not enough memory for H/W queues\n");
diff --git a/drivers/accel/habanalabs/common/hwmon.c b/drivers/accel/habanalabs/common/hwmon.c
index 3c0f405a5148..768604d2392d 100644
--- a/drivers/accel/habanalabs/common/hwmon.c
+++ b/drivers/accel/habanalabs/common/hwmon.c
@@ -196,7 +196,7 @@ int hl_build_hwmon_channel_info(struct hl_device *hdev, struct cpucp_sensor *sen
}
channels_info = kzalloc_objs(struct hwmon_channel_info *,
- num_active_sensor_types + 1, GFP_KERNEL);
+ num_active_sensor_types + 1);
if (!channels_info) {
rc = -ENOMEM;
goto channels_info_array_err;
diff --git a/drivers/accel/habanalabs/gaudi/gaudi.c b/drivers/accel/habanalabs/gaudi/gaudi.c
index 76fdf3b77b87..5ddb38aaff7a 100644
--- a/drivers/accel/habanalabs/gaudi/gaudi.c
+++ b/drivers/accel/habanalabs/gaudi/gaudi.c
@@ -540,7 +540,7 @@ static int gaudi_set_fixed_properties(struct hl_device *hdev)
prop->max_queues = GAUDI_QUEUE_ID_SIZE;
prop->hw_queues_props = kzalloc_objs(struct hw_queue_properties,
- prop->max_queues, GFP_KERNEL);
+ prop->max_queues);
if (!prop->hw_queues_props)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2.c b/drivers/accel/habanalabs/gaudi2/gaudi2.c
index 91f46719931c..5d9c6f0698b7 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2.c
@@ -2763,7 +2763,7 @@ static int gaudi2_set_fixed_properties(struct hl_device *hdev)
prop->max_queues = GAUDI2_QUEUE_ID_SIZE;
prop->hw_queues_props = kzalloc_objs(struct hw_queue_properties,
- prop->max_queues, GFP_KERNEL);
+ prop->max_queues);
if (!prop->hw_queues_props)
return -ENOMEM;
@@ -3944,8 +3944,7 @@ static int gaudi2_special_blocks_config(struct hl_device *hdev)
prop->glbl_err_max_cause_num = GAUDI2_GLBL_ERR_MAX_CAUSE_NUM;
prop->num_of_special_blocks = ARRAY_SIZE(gaudi2_special_blocks);
prop->special_blocks = kmalloc_objs(*prop->special_blocks,
- prop->num_of_special_blocks,
- GFP_KERNEL);
+ prop->num_of_special_blocks);
if (!prop->special_blocks)
return -ENOMEM;
@@ -3960,8 +3959,7 @@ static int gaudi2_special_blocks_config(struct hl_device *hdev)
if (ARRAY_SIZE(gaudi2_iterator_skip_block_types)) {
prop->skip_special_blocks_cfg.block_types =
kmalloc_objs(gaudi2_iterator_skip_block_types[0],
- ARRAY_SIZE(gaudi2_iterator_skip_block_types),
- GFP_KERNEL);
+ ARRAY_SIZE(gaudi2_iterator_skip_block_types));
if (!prop->skip_special_blocks_cfg.block_types) {
rc = -ENOMEM;
goto free_special_blocks;
@@ -3977,8 +3975,7 @@ static int gaudi2_special_blocks_config(struct hl_device *hdev)
if (ARRAY_SIZE(gaudi2_iterator_skip_block_ranges)) {
prop->skip_special_blocks_cfg.block_ranges =
kmalloc_objs(gaudi2_iterator_skip_block_ranges[0],
- ARRAY_SIZE(gaudi2_iterator_skip_block_ranges),
- GFP_KERNEL);
+ ARRAY_SIZE(gaudi2_iterator_skip_block_ranges));
if (!prop->skip_special_blocks_cfg.block_ranges) {
rc = -ENOMEM;
goto free_skip_special_blocks_types;
diff --git a/drivers/accel/habanalabs/goya/goya.c b/drivers/accel/habanalabs/goya/goya.c
index f94a331f4c32..bf12702e0a69 100644
--- a/drivers/accel/habanalabs/goya/goya.c
+++ b/drivers/accel/habanalabs/goya/goya.c
@@ -364,7 +364,7 @@ int goya_set_fixed_properties(struct hl_device *hdev)
prop->max_queues = GOYA_QUEUE_ID_SIZE;
prop->hw_queues_props = kzalloc_objs(struct hw_queue_properties,
- prop->max_queues, GFP_KERNEL);
+ prop->max_queues);
if (!prop->hw_queues_props)
return -ENOMEM;
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 755971c13caf..ac51bff39833 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -497,8 +497,7 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
{
struct rocket_device *rdev = rocket_priv->rdev;
struct drm_gpu_scheduler **scheds = kmalloc_objs(*scheds,
- rdev->num_cores,
- GFP_KERNEL);
+ rdev->num_cores);
unsigned int core;
int ret;
diff --git a/drivers/acpi/acpi_video.c b/drivers/acpi/acpi_video.c
index 5f4751478752..3fa28f1abca3 100644
--- a/drivers/acpi/acpi_video.c
+++ b/drivers/acpi/acpi_video.c
@@ -837,8 +837,7 @@ int acpi_video_get_levels(struct acpi_device *device,
* special levels (see below)
*/
br->levels = kmalloc_objs(*br->levels,
- obj->package.count + ACPI_VIDEO_FIRST_LEVEL,
- GFP_KERNEL);
+ obj->package.count + ACPI_VIDEO_FIRST_LEVEL);
if (!br->levels) {
result = -ENOMEM;
goto out_free;
@@ -1331,7 +1330,7 @@ static int acpi_video_device_enumerate(struct acpi_video_bus *video)
dod->package.count);
active_list = kzalloc_objs(struct acpi_video_enumerated_device,
- 1 + dod->package.count, GFP_KERNEL);
+ 1 + dod->package.count);
if (!active_list) {
status = -ENOMEM;
goto out;
diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c
index afffde4cfe7a..9b88d0993e88 100644
--- a/drivers/acpi/riscv/irq.c
+++ b/drivers/acpi/riscv/irq.c
@@ -343,7 +343,7 @@ static u32 riscv_acpi_add_prt_dep(acpi_handle handle)
acpi_get_handle(handle, entry->source, &link_handle);
dep_devices.count = 1;
dep_devices.handles = kzalloc_objs(*dep_devices.handles,
- 1, GFP_KERNEL);
+ 1);
if (!dep_devices.handles) {
acpi_handle_err(handle, "failed to allocate memory\n");
continue;
@@ -355,7 +355,7 @@ static u32 riscv_acpi_add_prt_dep(acpi_handle handle)
gsi_handle = riscv_acpi_get_gsi_handle(entry->source_index);
dep_devices.count = 1;
dep_devices.handles = kzalloc_objs(*dep_devices.handles,
- 1, GFP_KERNEL);
+ 1);
if (!dep_devices.handles) {
acpi_handle_err(handle, "failed to allocate memory\n");
continue;
diff --git a/drivers/acpi/x86/s2idle.c b/drivers/acpi/x86/s2idle.c
index 82075543a1ed..b6b1dd76a06b 100644
--- a/drivers/acpi/x86/s2idle.c
+++ b/drivers/acpi/x86/s2idle.c
@@ -130,8 +130,7 @@ static void lpi_device_get_constraints_amd(void)
}
lpi_constraints_table = kzalloc_objs(*lpi_constraints_table,
- package->package.count,
- GFP_KERNEL);
+ package->package.count);
if (!lpi_constraints_table)
goto free_acpi_buffer;
@@ -210,7 +209,7 @@ static void lpi_device_get_constraints(void)
return;
lpi_constraints_table = kzalloc_objs(*lpi_constraints_table,
- out_obj->package.count, GFP_KERNEL);
+ out_obj->package.count);
if (!lpi_constraints_table)
goto free_acpi_buffer;
diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 0dccb4526a7c..21f91d9f2fbc 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -5903,7 +5903,7 @@ static long binder_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
}
target_procs = kzalloc_objs(struct binder_proc *,
- target_procs_count, GFP_KERNEL);
+ target_procs_count);
if (!target_procs) {
mutex_unlock(&binder_procs_lock);
diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 4dd3415d8fdb..241f16a9b63d 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -917,7 +917,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
alloc->vm_start = vma->vm_start;
alloc->pages = kvzalloc_objs(alloc->pages[0],
- alloc->buffer_size / PAGE_SIZE, GFP_KERNEL);
+ alloc->buffer_size / PAGE_SIZE);
if (!alloc->pages) {
ret = -ENOMEM;
failure_string = "alloc page array";
diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
index d155f9dab44c..12cb3aa588bc 100644
--- a/drivers/atm/eni.c
+++ b/drivers/atm/eni.c
@@ -1846,8 +1846,7 @@ static int eni_start(struct atm_dev *dev)
buffer_mem = eni_dev->mem - (buf - eni_dev->ram);
eni_dev->free_list_size = buffer_mem/MID_MIN_BUF_SIZE/2;
eni_dev->free_list = kmalloc_objs(*eni_dev->free_list,
- eni_dev->free_list_size + 1,
- GFP_KERNEL);
+ eni_dev->free_list_size + 1);
if (!eni_dev->free_list) {
printk(KERN_ERR DEV_LABEL "(itf %d): couldn't get free page\n",
dev->number);
diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c
index eb16451ba0a3..391ac5e3d2f5 100644
--- a/drivers/base/cacheinfo.c
+++ b/drivers/base/cacheinfo.c
@@ -884,7 +884,7 @@ static int cpu_cache_sysfs_init(unsigned int cpu)
/* Allocate all required memory */
per_cpu_index_dev(cpu) = kzalloc_objs(struct device *,
- cache_leaves(cpu), GFP_KERNEL);
+ cache_leaves(cpu));
if (unlikely(per_cpu_index_dev(cpu) == NULL))
goto err_out;
diff --git a/drivers/block/rnbd/rnbd-clt.c b/drivers/block/rnbd/rnbd-clt.c
index c60dafbe79e8..4d6725a0035e 100644
--- a/drivers/block/rnbd/rnbd-clt.c
+++ b/drivers/block/rnbd/rnbd-clt.c
@@ -1418,7 +1418,7 @@ static struct rnbd_clt_dev *init_dev(struct rnbd_clt_session *sess,
* nr_poll_queues: the number of polling queues
*/
dev->hw_queues = kzalloc_objs(*dev->hw_queues,
- nr_cpu_ids + nr_poll_queues, GFP_KERNEL);
+ nr_cpu_ids + nr_poll_queues);
if (!dev->hw_queues) {
ret = -ENOMEM;
goto out_alloc;
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 8fc7fc3bf867..f765970578f9 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -2209,12 +2209,11 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
rinfo->shadow[i].grants_used =
kvzalloc_objs(rinfo->shadow[i].grants_used[0], grants);
rinfo->shadow[i].sg = kvzalloc_objs(rinfo->shadow[i].sg[0],
- psegs, GFP_KERNEL);
+ psegs);
if (info->max_indirect_segments)
rinfo->shadow[i].indirect_grants =
kvzalloc_objs(rinfo->shadow[i].indirect_grants[0],
- INDIRECT_GREFS(grants),
- GFP_KERNEL);
+ INDIRECT_GREFS(grants));
if ((rinfo->shadow[i].grants_used == NULL) ||
(rinfo->shadow[i].sg == NULL) ||
(info->max_indirect_segments &&
diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
index 879b8b706428..e3d0a3cbaf94 100644
--- a/drivers/bus/mhi/ep/main.c
+++ b/drivers/bus/mhi/ep/main.c
@@ -1137,7 +1137,7 @@ int mhi_ep_power_up(struct mhi_ep_cntrl *mhi_cntrl)
mhi_ep_mmio_init(mhi_cntrl);
mhi_cntrl->mhi_event = kzalloc_objs(*mhi_cntrl->mhi_event,
- mhi_cntrl->event_rings, GFP_KERNEL);
+ mhi_cntrl->event_rings);
if (!mhi_cntrl->mhi_event)
return -ENOMEM;
@@ -1400,7 +1400,7 @@ static int mhi_ep_chan_init(struct mhi_ep_cntrl *mhi_cntrl,
* only the defined channels
*/
mhi_cntrl->mhi_chan = kzalloc_objs(*mhi_cntrl->mhi_chan,
- mhi_cntrl->max_chan, GFP_KERNEL);
+ mhi_cntrl->max_chan);
if (!mhi_cntrl->mhi_chan)
return -ENOMEM;
diff --git a/drivers/bus/mhi/ep/ring.c b/drivers/bus/mhi/ep/ring.c
index ee5b7f4755c5..9375b16ff2a5 100644
--- a/drivers/bus/mhi/ep/ring.c
+++ b/drivers/bus/mhi/ep/ring.c
@@ -206,7 +206,7 @@ int mhi_ep_ring_start(struct mhi_ep_cntrl *mhi_cntrl, struct mhi_ep_ring *ring,
/* Allocate ring cache memory for holding the copy of host ring */
ring->ring_cache = kzalloc_objs(struct mhi_ring_element,
- ring->ring_size, GFP_KERNEL);
+ ring->ring_size);
if (!ring->ring_cache)
return -ENOMEM;
diff --git a/drivers/clk/aspeed/clk-ast2600.c b/drivers/clk/aspeed/clk-ast2600.c
index bc9a5b81009d..873879e5ad9b 100644
--- a/drivers/clk/aspeed/clk-ast2600.c
+++ b/drivers/clk/aspeed/clk-ast2600.c
@@ -839,7 +839,7 @@ static void __init aspeed_g6_cc_init(struct device_node *np)
soc_rev = (readl(scu_g6_base + ASPEED_G6_SILICON_REV) & CHIP_REVISION_ID) >> 16;
aspeed_g6_clk_data = kzalloc_flex(*aspeed_g6_clk_data, hws,
- ASPEED_G6_NUM_CLKS, GFP_KERNEL);
+ ASPEED_G6_NUM_CLKS);
if (!aspeed_g6_clk_data)
return;
aspeed_g6_clk_data->num = ASPEED_G6_NUM_CLKS;
diff --git a/drivers/clk/clk-clps711x.c b/drivers/clk/clk-clps711x.c
index babe42e59533..27a57a9b3cb3 100644
--- a/drivers/clk/clk-clps711x.c
+++ b/drivers/clk/clk-clps711x.c
@@ -54,7 +54,7 @@ static void __init clps711x_clk_init_dt(struct device_node *np)
BUG_ON(!base);
clps711x_clk = kzalloc_flex(*clps711x_clk, clk_data.hws,
- CLPS711X_CLK_MAX, GFP_KERNEL);
+ CLPS711X_CLK_MAX);
BUG_ON(!clps711x_clk);
spin_lock_init(&clps711x_clk->lock);
diff --git a/drivers/clk/clk-npcm7xx.c b/drivers/clk/clk-npcm7xx.c
index 2cd1ae4f152d..79eca6ee3120 100644
--- a/drivers/clk/clk-npcm7xx.c
+++ b/drivers/clk/clk-npcm7xx.c
@@ -422,7 +422,7 @@ static void __init npcm7xx_clk_init(struct device_node *clk_np)
goto npcm7xx_init_error;
npcm7xx_clk_data = kzalloc_flex(*npcm7xx_clk_data, hws,
- NPCM7XX_NUM_CLOCKS, GFP_KERNEL);
+ NPCM7XX_NUM_CLOCKS);
if (!npcm7xx_clk_data)
goto npcm7xx_init_np_err;
diff --git a/drivers/clocksource/ingenic-sysost.c b/drivers/clocksource/ingenic-sysost.c
index d967972c1fdc..026615bbe921 100644
--- a/drivers/clocksource/ingenic-sysost.c
+++ b/drivers/clocksource/ingenic-sysost.c
@@ -459,7 +459,7 @@ static int __init ingenic_ost_probe(struct device_node *np)
ost->soc_info = id->data;
ost->clocks = kzalloc_flex(*ost->clocks, hws,
- ost->soc_info->num_channels, GFP_KERNEL);
+ ost->soc_info->num_channels);
if (!ost->clocks) {
ret = -ENOMEM;
goto err_clk_disable;
diff --git a/drivers/comedi/drivers/ni_tio.c b/drivers/comedi/drivers/ni_tio.c
index d6e7e2006981..519359a870a7 100644
--- a/drivers/comedi/drivers/ni_tio.c
+++ b/drivers/comedi/drivers/ni_tio.c
@@ -1795,7 +1795,7 @@ ni_gpct_device_construct(struct comedi_device *dev,
counter_dev->counters = kzalloc_objs(*counter, num_counters);
counter_dev->regs = kzalloc_objs(*counter_dev->regs,
- counter_dev->num_chips, GFP_KERNEL);
+ counter_dev->num_chips);
if (!counter_dev->regs || !counter_dev->counters) {
kfree(counter_dev->regs);
kfree(counter_dev->counters);
diff --git a/drivers/crypto/intel/qat/qat_common/adf_telemetry.c b/drivers/crypto/intel/qat/qat_common/adf_telemetry.c
index a745c1ca4048..8c575113cbcd 100644
--- a/drivers/crypto/intel/qat/qat_common/adf_telemetry.c
+++ b/drivers/crypto/intel/qat/qat_common/adf_telemetry.c
@@ -76,7 +76,7 @@ static int adf_tl_alloc_mem(struct adf_accel_dev *accel_dev)
goto err_free_tl;
telemetry->regs_hist_buff = kmalloc_objs(*telemetry->regs_hist_buff,
- tl_data->num_hbuff, GFP_KERNEL);
+ tl_data->num_hbuff);
if (!telemetry->regs_hist_buff)
goto err_free_rp_indexes;
diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c
index 30f83f06d185..e61a367b0d17 100644
--- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c
+++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c
@@ -1200,8 +1200,7 @@ static int qat_uclo_map_suof(struct icp_qat_fw_loader_handle *handle,
if (suof_handle->img_table.num_simgs != 0) {
suof_img_hdr = kzalloc_objs(img_header,
- suof_handle->img_table.num_simgs,
- GFP_KERNEL);
+ suof_handle->img_table.num_simgs);
if (!suof_img_hdr)
return -ENOMEM;
suof_handle->img_table.simg_hdr = suof_img_hdr;
@@ -1892,8 +1891,7 @@ static int qat_uclo_map_objs_from_mof(struct icp_qat_mof_handle *mobj_handle)
sobj_chunk_num = sobj_hdr->num_chunks;
mobj_hdr = kzalloc_objs(*mobj_hdr,
- size_add(uobj_chunk_num, sobj_chunk_num),
- GFP_KERNEL);
+ size_add(uobj_chunk_num, sobj_chunk_num));
if (!mobj_hdr)
return -ENOMEM;
diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
index 0c5ad5a55453..cf0d3c2dfc04 100644
--- a/drivers/edac/edac_device.c
+++ b/drivers/edac/edac_device.c
@@ -78,7 +78,7 @@ edac_device_alloc_ctl_info(unsigned pvt_sz, char *dev_name, unsigned nr_instance
dev_ctl->instances = dev_inst;
dev_blk = kzalloc_objs(struct edac_device_block,
- nr_instances * nr_blocks, GFP_KERNEL);
+ nr_instances * nr_blocks);
if (!dev_blk)
goto free;
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
index fc434739b3c3..09d4e816404b 100644
--- a/drivers/edac/sb_edac.c
+++ b/drivers/edac/sb_edac.c
@@ -776,7 +776,7 @@ static struct sbridge_dev *alloc_sbridge_dev(int seg, u8 bus, enum domain dom,
return NULL;
sbridge_dev->pdev = kzalloc_objs(*sbridge_dev->pdev,
- table->n_devs_per_imc, GFP_KERNEL);
+ table->n_devs_per_imc);
if (!sbridge_dev->pdev) {
kfree(sbridge_dev);
return NULL;
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index b2c6a1660c51..d9e9815a5f96 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -1208,8 +1208,7 @@ static int extcon_alloc_groups(struct extcon_dev *edev)
return 0;
edev->extcon_dev_type.groups = kzalloc_objs(*edev->extcon_dev_type.groups,
- edev->max_supported + 2,
- GFP_KERNEL);
+ edev->max_supported + 2);
if (!edev->extcon_dev_type.groups)
return -ENOMEM;
diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
index 21c61405f794..d2b40a1a565e 100644
--- a/drivers/firewire/core-iso.c
+++ b/drivers/firewire/core-iso.c
@@ -31,8 +31,7 @@
int fw_iso_buffer_alloc(struct fw_iso_buffer *buffer, int page_count)
{
struct page **page_array __free(kfree) = kzalloc_objs(page_array[0],
- page_count,
- GFP_KERNEL);
+ page_count);
if (!page_array)
return -ENOMEM;
@@ -58,8 +57,7 @@ int fw_iso_buffer_map_dma(struct fw_iso_buffer *buffer, struct fw_card *card,
enum dma_data_direction direction)
{
dma_addr_t *dma_addrs __free(kfree) = kzalloc_objs(dma_addrs[0],
- buffer->page_count,
- GFP_KERNEL);
+ buffer->page_count);
int i;
if (!dma_addrs)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
index 04b45242dc76..af3d2fd61cf3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c
@@ -1179,8 +1179,7 @@ static int amdgpu_discovery_sysfs_ips(struct amdgpu_device *adev,
*/
ip_hw_instance = kzalloc_flex(*ip_hw_instance,
base_addr,
- ip->num_base_address,
- GFP_KERNEL);
+ ip->num_base_address);
if (!ip_hw_instance) {
DRM_ERROR("no memory for ip_hw_instance");
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
index d9b2252db00e..5179fa008626 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -1728,8 +1728,7 @@ int amdgpu_gmc_init_mem_ranges(struct amdgpu_device *adev)
bool valid;
adev->gmc.mem_partitions = kzalloc_objs(struct amdgpu_mem_partition_info,
- AMDGPU_MAX_MEM_RANGES,
- GFP_KERNEL);
+ AMDGPU_MAX_MEM_RANGES);
if (!adev->gmc.mem_partitions)
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
index 49eedfbfb5e8..254a4e983f40 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
@@ -437,7 +437,7 @@ int amdgpu_irq_add_id(struct amdgpu_device *adev,
if (!adev->irq.client[client_id].sources) {
adev->irq.client[client_id].sources =
kzalloc_objs(struct amdgpu_irq_src *,
- AMDGPU_MAX_IRQ_SRC_ID, GFP_KERNEL);
+ AMDGPU_MAX_IRQ_SRC_ID);
if (!adev->irq.client[client_id].sources)
return -ENOMEM;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
index ad5d2fcd03d7..60bbe00e8024 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
@@ -452,8 +452,7 @@ static int amdgpu_pmu_alloc_pmu_attrs(
return -ENOMEM;
fmt_attr_group->attrs = kzalloc_objs(*fmt_attr_group->attrs,
- config->num_formats + 1,
- GFP_KERNEL);
+ config->num_formats + 1);
if (!fmt_attr_group->attrs)
goto err_fmt_attr_grp;
@@ -464,7 +463,7 @@ static int amdgpu_pmu_alloc_pmu_attrs(
goto err_evt_attr;
evt_attr_group->attrs = kzalloc_objs(*evt_attr_group->attrs,
- config->num_events + 1, GFP_KERNEL);
+ config->num_events + 1);
if (!evt_attr_group->attrs)
goto err_evt_attr_grp;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
index eb3e62eb7b20..c0336ca9bf6a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
@@ -3239,7 +3239,7 @@ int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
if (from_rom) {
err_data.err_addr =
kzalloc_objs(struct eeprom_table_record,
- adev->umc.retire_unit, GFP_KERNEL);
+ adev->umc.retire_unit);
if (!err_data.err_addr) {
dev_warn(adev->dev, "Failed to alloc UMC error address record in mca2pa conversion!\n");
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d319c37e0d4e..eeaa56c8d129 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1881,8 +1881,7 @@ static int amdgpu_ttm_pools_init(struct amdgpu_device *adev)
return 0;
adev->mman.ttm_pools = kzalloc_objs(*adev->mman.ttm_pools,
- adev->gmc.num_mem_partitions,
- GFP_KERNEL);
+ adev->gmc.num_mem_partitions);
if (!adev->mman.ttm_pools)
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c
index 8da772ec4b40..4df0f9d5ad11 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_umc.c
@@ -59,7 +59,7 @@ int amdgpu_umc_page_retirement_mca(struct amdgpu_device *adev,
err_data.err_addr =
kzalloc_objs(struct eeprom_table_record,
- adev->umc.max_ras_err_cnt_per_query, GFP_KERNEL);
+ adev->umc.max_ras_err_cnt_per_query);
if (!err_data.err_addr) {
dev_warn(adev->dev,
"Failed to alloc memory for umc error record in MCA notifier!\n");
@@ -106,7 +106,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev,
err_data->err_addr =
kzalloc_objs(struct eeprom_table_record,
- adev->umc.max_ras_err_cnt_per_query, GFP_KERNEL);
+ adev->umc.max_ras_err_cnt_per_query);
/* still call query_ras_error_address to clear error status
* even NOMEM error is encountered
@@ -132,8 +132,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev,
adev->umc.max_ras_err_cnt_per_query) {
err_data->err_addr =
kzalloc_objs(struct eeprom_table_record,
- adev->umc.max_ras_err_cnt_per_query,
- GFP_KERNEL);
+ adev->umc.max_ras_err_cnt_per_query);
/* still call query_ras_error_address to clear error status
* even NOMEM error is encountered
@@ -163,8 +162,7 @@ void amdgpu_umc_handle_bad_pages(struct amdgpu_device *adev,
adev->umc.max_ras_err_cnt_per_query) {
err_data->err_addr =
kzalloc_objs(struct eeprom_table_record,
- adev->umc.max_ras_err_cnt_per_query,
- GFP_KERNEL);
+ adev->umc.max_ras_err_cnt_per_query);
/* still call query_ras_error_address to clear error status
* even NOMEM error is encountered
@@ -554,7 +552,7 @@ int amdgpu_umc_lookup_bad_pages_in_a_row(struct amdgpu_device *adev,
struct ras_err_data err_data;
err_data.err_addr = kzalloc_objs(struct eeprom_table_record,
- adev->umc.retire_unit, GFP_KERNEL);
+ adev->umc.retire_unit);
if (!err_data.err_addr) {
dev_warn(adev->dev, "Failed to alloc memory in bad page lookup!\n");
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
index 2c19b65de840..5cef8cd14148 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vkms.c
@@ -500,8 +500,7 @@ static int amdgpu_vkms_sw_init(struct amdgpu_ip_block *ip_block)
struct amdgpu_device *adev = ip_block->adev;
adev->amdgpu_vkms_output = kzalloc_objs(struct amdgpu_vkms_output,
- adev->mode_info.num_crtc,
- GFP_KERNEL);
+ adev->mode_info.num_crtc);
if (!adev->amdgpu_vkms_output)
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index d0f7bd2a3481..09dabb3b3297 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -781,7 +781,7 @@ static int kfd_ioctl_get_process_apertures_new(struct file *filp,
* the amount of memory allocated by user
*/
pa = kzalloc_objs(struct kfd_process_device_apertures,
- args->num_of_nodes, GFP_KERNEL);
+ args->num_of_nodes);
if (!pa)
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c
index 212f613fad1e..b96fbc03c371 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crc.c
@@ -959,7 +959,7 @@ void amdgpu_dm_crtc_secure_display_create_contexts(struct amdgpu_device *adev)
int i;
crtc_ctx = kzalloc_objs(struct secure_display_crtc_context,
- adev->mode_info.num_crtc, GFP_KERNEL);
+ adev->mode_info.num_crtc);
if (!crtc_ctx) {
adev->dm.secure_display_ctx.crtc_ctx = NULL;
diff --git a/drivers/gpu/drm/amd/display/dc/resource/dcn20/dcn20_resource.c b/drivers/gpu/drm/amd/display/dc/resource/dcn20/dcn20_resource.c
index 13ac1980a376..8b555187ac75 100644
--- a/drivers/gpu/drm/amd/display/dc/resource/dcn20/dcn20_resource.c
[Output truncated: showing 1000 of 7327 lines]]
|
| 96/2 |
2026/10/13 22:40 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 49257
output: 41
thoughts: 957
Thoughts: **Analyzing Kernel Memory Allocation Strategies in DRM Subsystem**
Okay, so `189f164e573e` is a refactoring where `kmalloc_objs(..., GFP_KERNEL)` is being simplified to `kmalloc_objs(...)` by Kees Cook, which removes the `GFP_KERNEL` argument. The bug report suggests a fix using `kvzalloc_objs()` which gracefully falls back to `vmalloc()` for large allocations, avoiding page allocator warnings, and requires a corresponding `kvfree()`.
Therefore, I need to hunt for commits addressing comparable unbounded allocation problems and subsequent shifts to `kvmalloc` or equivalent strategies within the relevant files or subsystem.
I've already identified some potentially relevant commits within the `drivers/gpu/drm/` subsystem: `bca45af5998a`, `a1ba4594232c`, `0829b5bcdd3b`, `a8eba56abcad`, and `c4ac100e9ae2`. Let's focus our attention on the files within the subsystem since the initial affected file is `drivers/gpu/drm/drm_lease.c`.
Let's revisit `bca45af5998a`. The issue here is a BO cache size list that scales with the largest BO ever freed. Large allocations (e.g., 64 MiB BOs) can trigger allocation failures and `warn_alloc()` due to fragmentation. `kvmalloc_objs()` provides a fallback to `vmalloc()`, which is crucial here to avoid such failures.
Then there is `a1ba4594232c`. This one deals with a missing bounds check on user-supplied `num_entries`, leading to allocations exceeding `INT_MAX`. This is an instance of a security concern. It proposes a size bounds check to reject oversized `num_entries` early, before even calling `kvzalloc()`. This is another interesting point.
Next is `0829b5bcdd3b`. Here the "kernel test robot" reported an issue in `kvmalloc_node` due to large sizes. This commit introduces a cap on user-space-passed sizes, preventing oversized kernel allocations.
Finally, `c4ac100e9ae2` involves replacing `kvmalloc_array() + copy_from_user()` with `vmemdup_array_user()` for efficiency. This suggests a preferred strategy for handling user-space data copying in the DRM subsystem.
I need to confirm if using `vmemdup_user` or something equivalent could be relevant. Now I will search for `vmemdup_user` within the `drivers/gpu/drm/` directory.
|
| 97/2 |
2026/10/13 22:41 |
tool |
git-log |
0m
Args: map[MessageRegexps:[vmemdup_user] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:c5f500161709 drm/xe: Fix memory leak in exec_queue_set_hang_replay_state()
1026c1a73a96 drm/xe: Implement DRM_XE_EXEC_QUEUE_SET_HANG_REPLAY_STATE
]
|
| 98/2 |
2026/10/13 22:41 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 50922
output: 43
thoughts: 23
Thoughts: Okay, here's my summary, tailored for an expert audience, as if I'm thinking these thoughts:
**Analyzing GPU Driver Memory Operations**
Alright, let's dive in. I need to understand how user-space memory is being handled in the DRM subsystem, specifically focusing on potential vulnerabilities. My initial target is `vmemdup_array_user`. I'm heading straight to the `drivers/gpu/drm/` directory because that's where the heart of the GPU driver code resides, and user-space interaction is a key area for exploitation. I'm focusing on that specific function because it suggests a potentially unsafe copy from user space. I need to see how it's used, how the size arguments are handled, and if there are any subtle integer overflows or off-by-one errors that could be leveraged. I'll be looking at the surrounding code for any missing bounds checks, race conditions with memory allocation or deallocation, and whether the destination buffer is properly validated. I'm expecting this to be a fruitful line of inquiry.
|
| 99/2 |
2026/10/13 22:41 |
tool |
git-log |
0m
Args: map[MessageRegexps:[vmemdup_array_user] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:84c4c36acd5c drm/amdgpu: validate CP_GFX_SHADOW chunk size in CS pass1
7f61b2eef741 drm/amdgpu: validate CP_GFX_SHADOW chunk size in CS pass1
922682d48d62 drm/gem: Correct error condition in drm_gem_objects_lookup
cb77b79abf5f drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
c4ac100e9ae2 drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
]
|
| 100/2 |
2026/10/13 22:41 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 51382
output: 25
thoughts: 16
Thoughts: Okay, here's my interpretation of that request, formatted as requested:
**Deconstructing cb77b79abf5f**
Alright, let's take a look at this `cb77b79abf5f` identifier. Based on its structure, my initial thought is that it's likely a commit hash, a transaction ID, or perhaps some sort of unique key. Given the length and hexadecimal format, it's screaming SHA-1 or a similar cryptographic hash. I'll need more context to be certain, of course. But assuming it is one of those, the next step is to figure out *where* this hash originated. Is it a Git commit? A database transaction? A message queue identifier? That's the crucial piece of information I'm missing. Understanding the system it pertains to will guide my next steps. I'll need to use my usual tools and techniques. From there I can determine its role, how to debug any issues related to it, or if it is even relevant at all.
|
| 101/2 |
2026/10/13 22:41 |
tool |
git-show |
0m
Args:
Results: map[Output:commit cb77b79abf5ff8f4af07f7ebef196a003c826b7a
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Wed Nov 12 09:27:32 2025 +0000
drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
Use a helper to shrink the code and separate the user and kernel slabs for
better security.
While at it lets remove the useless debug message.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: AndrΓ© Almeida <andrealmeid@igalia.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://lore.kernel.org/r/20251112092732.23584-1-tvrtko.ursulin@igalia.com
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index a1a9c828938b..68168d58a7c8 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)
{
- struct drm_device *dev = filp->minor->dev;
struct drm_gem_object **objs;
u32 *handles;
int ret;
@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
*objs_out = objs;
- handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL);
- if (!handles) {
- ret = -ENOMEM;
- goto out;
- }
-
- if (copy_from_user(handles, bo_handles, count * sizeof(u32))) {
- ret = -EFAULT;
- drm_dbg_core(dev, "Failed to copy in GEM handles\n");
+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
+ if (IS_ERR(handles)) {
+ ret = PTR_ERR(handles);
goto out;
}
]
|
| 102/2 |
2026/10/13 22:41 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 52359
output: 42
thoughts: 505
Thoughts: **Analyzing a Potential Memory Allocation Vulnerability in DRM Lease Code**
Okay, so I'm looking at this `vmemdup_array_user` function β seems like it's a helpful wrapper around `kvmalloc_array` and `copy_from_user`, nothing immediately concerning there. But hang on, the bug description is key here. Apparently, `drm_mode_create_lease_ioctl()` calls `memdup_array_user()` to allocate this `object_ids` array *before* calling `fill_object_idr()`. And this `memdup_array_user()` uses `memdup_user()`, allocating with `GFP_USER | __GFP_NOWARN`. The problem? If `object_count` is huge β potentially over 4MB, it silently fails because of the `__GFP_NOWARN` flag.
My immediate thought is, if the `memdup_array_user` fails silently, that's not the critical issue. The problem arises when it *succeeds* allocating a smaller chunk (like order 10), and then later `kzalloc_objs` is called which requires order 11 allocation and *loudly* fails because of a `kmalloc` usage without the `__GFP_NOWARN` flag.
So the proposed fix, smart, is to replace that `kzalloc_objs` call with `kvzalloc_objs`. This would allow the code to fallback to vmalloc if a large allocation is needed.
I need to see if this pattern has occurred elsewhere in `drivers/gpu/drm/`. I'm going to search for commits that have switched from `kmalloc` to `kvmalloc` to avoid these page allocation failures when dealing with user-controlled sizes.
Aha! There's `bca45af5998a`. It's exactly the same situation. That commit mentions: "The BO cache size list has one entry per BO page count, so its size scales with the largest BO ever freed. A 64 MiB BO already needs at least an order-6 allocation, which fails under fragmentation and triggers a warn_alloc() splat on BO close ... The list doesn't need physically contiguous memory. Use kvmalloc_objs() so large lists can fall back to vmalloc(), avoiding the allocation failure."
Okay, let's keep digging. I'll search for `kvmalloc` and `order` in `drivers/gpu/drm/` to see what else I can find and ensure this isn't a systemic issue.
|
| 103/2 |
2026/10/13 22:41 |
tool |
git-log |
0m
Args: map[MessageRegexps:[kvmalloc order] PathPrefix:drivers/gpu/drm/ Since:3 years]
Results: map[Output:bca45af5998a drm/vc4: Use kvmalloc_objs() for the BO cache size list
a292fdecd728 drm/amdgpu: Implement userqueue signal/wait IOCTL
]
|
| 104/2 |
2026/10/13 22:42 |
llm |
history-explorer |
1m
Model:
Tokens:
input: 53513
output: 47
thoughts: 711
Thoughts: **Analyzing Allocation Patterns for User-Controlled Sizes**
Okay, so I've been digging into how we're handling potentially unbounded user-controlled allocation sizes, and I've identified a few key patterns that are being used to avoid problems. Looking at `bca45af5998a`, it's clear that the primary strategy is to leverage `kvmalloc` (or its related functions) instead of the standard `kmalloc` approach. This allows the system to fall back to `vmalloc` when dealing with larger allocations, thus avoiding those nasty `warn_alloc()` messages. It's essentially the preferred method in the kernel for this sort of thing, and it looks like `drm/vc4` is a prime example of its application.
Then there are scenarios where even `kvmalloc` throws a warningβthat happens when the size exceeds `INT_MAX`. In those instances, we see the implementation of an explicit upper bound check, as demonstrated in `a1ba4594232c` (drm/amdgpu) and `0829b5bcdd3b` (drm/i915). This is a pretty straightforward approach to prevent the warnings.
Finally, when copying large arrays from userspace, it's smarter to use helpers like `vmemdup_array_user()` instead of relying on the combination of `memdup_array_user()` and a `copy_from_user()` operation. The commits `cb77b79abf5f` and `c4ac100e9ae2` highlight the use of the `vmemdup_array_user` approach.
Now, looking at our own codebase, specifically at how we're allocating `object_ids`, I have to wonder if we're doing the right thing. We're currently using `memdup_array_user`. If `object_count` is large, it may fail silently due to the presence of `__GFP_NOWARN` flag. Should we be using `vmemdup_array_user` instead? If so, this would give us the potential to succeed with large arrays by leveraging `vmalloc`'s capabilities. Yes, that makes sense. `vmemdup_array_user` is the `vmalloc` equivalent of `memdup_array_user`. I'll need to check the `memdup_array_user` implementation in `drm_lease.c` to be sure.
|
| 105/2 |
2026/10/13 22:43 |
tool |
git-log |
0m
Args: map[MessageRegexps:[memdup_array_user] PathPrefix:drivers/gpu/drm/drm_lease.c Since:3 years]
Results:
|
| 106/2 |
2026/10/13 22:43 |
llm |
history-explorer |
5m
Model:
Tokens:
input: 54808
output: 38
thoughts: 41
Thoughts: Okay, let's see. My first thought is: **Connecting the Dots: memdup_array_user and drm_lease.c**.
Right, so `memdup_array_user` is mentioned in that bug report, and it's used in `drm_lease.c`. Okay, that's the key starting point. I need to understand the relationship between those two and how this specific function is being used.
Therefore, I need to check the definition of `vmemdup_array_user`. I'm going to look at that definition next. Let's see what's going on in there.
|
| 107/2 |
2026/10/13 22:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:vmemdup_array_user]
Results: map[SourceCode: 42: /**
43: * vmemdup_array_user - duplicate array from user space
44: * @src: source address in user space
45: * @n: number of array members to copy
46: * @size: size of one array member
47: *
48: * Return: an ERR_PTR() on failure. Result may be not
49: * physically contiguous. Use kvfree() to free.
50: */
51: static inline __realloc_size(2, 3)
52: void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
53: {
54: size_t nbytes;
55:
56: if (check_mul_overflow(n, size, &nbytes))
57: return ERR_PTR(-EOVERFLOW);
58:
59: return vmemdup_user(src, nbytes);
60: }
SourceFile:include/linux/string.h]
|
| 108/2 |
2026/10/13 22:49 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 55320
output: 37
thoughts: 33
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating `vmemdup_array_user`'s Underlying Mechanism**
Right, so `vmemdup_array_user` is built on top of `vmemdup_user`. That's the first connection to grasp. The naming suggests array-specific handling, but let's dive deeper and confirm my assumption. I need to understand how this relationship works in detail. Time to dissect the `memdup_array_user` definition and figure out the exact nuance this abstraction provides.
|
| 109/2 |
2026/10/13 22:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:memdup_array_user]
Results: map[SourceCode: 22: /**
23: * memdup_array_user - duplicate array from user space
24: * @src: source address in user space
25: * @n: number of array members to copy
26: * @size: size of one array member
27: *
28: * Return: an ERR_PTR() on failure. Result is physically
29: * contiguous, to be freed by kfree().
30: */
31: static inline __realloc_size(2, 3)
32: void *memdup_array_user(const void __user *src, size_t n, size_t size)
33: {
34: size_t nbytes;
35:
36: if (check_mul_overflow(n, size, &nbytes))
37: return ERR_PTR(-EOVERFLOW);
38:
39: return memdup_user(src, nbytes);
40: }
SourceFile:include/linux/string.h]
|
| 110/2 |
2026/10/13 22:49 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 55811
output: 44
thoughts: 1058
Thoughts: **Analysis of the Allocation Issue and Proposed Fix**
Alright, let's break this down. It seems we have a situation where `memdup_array_user` is used internally by `memdup_user`, while `kzalloc_objs` is causing the warning. The proposed fix of using `kvzalloc_objs` and `kvfree` for the `objects` array addresses the loud warning from `kzalloc_objs`. While `memdup_array_user` *does* limit large leases, it fails silently, so it is not a bug.
Looking at recent commits within `drivers/gpu/drm/` it's becoming clear how to proceed. There are several recurring patterns to consider:
1. **Embracing `kvmalloc` for Unbounded Sizes:** Commits like `bca45af5998a` and `a8eba56abcad` highlight the strategy of migrating to the `kvmalloc` family, specifically `kvmalloc_objs`, to handle potentially large allocations by falling back to `vmalloc` when the page allocator struggles. This is the core of the proposed solution and is the direct analog to the issue we are seeing here.
2. **Implementing Bounds Checks:** There's a parallel need to address the possibility of sizes that are larger than `INT_MAX`, as even `kvmalloc` will issue a warning in such a situation. Commits like `a1ba4594232c` and `0829b5bcdd3b` show how to explicitly check the user-provided size against `INT_MAX` and reject the request with `-EINVAL` if it's too large.
3. **Using `vmemdup_array_user` for User-Space Data:** The `object_ids` array, allocated using `memdup_array_user()`, while not triggering a warning, is also constrained by `MAX_PAGE_ORDER`. Recent commits, like `cb77b79abf5f` and `c4ac100e9ae2`, suggest we should consider replacing `memdup_array_user()` with `vmemdup_array_user()` for consistency. This would ensure we can handle the same range of sizes for both allocations, even if the primary fix makes the potential sizes much larger.
In summary:
* The *primary fix* is to follow the established pattern and use `kvzalloc_objs()` (or, equivalently, `kvcalloc()`) and `kvfree()` for the `objects` array, allowing fallback to `vmalloc()` and preventing the page allocator warning.
* We should also consider a *secondary, important check* of verifying the allocation size doesn't exceed `INT_MAX`. This is similar to the approach shown in commit `a1ba4594232c`.
* Finally, we should also look at the `object_ids` allocation, and consider updating it from `memdup_array_user()` to `vmemdup_array_user()`, to match the pattern from commits like `cb77b79abf5f`.
We should double check to see if `drm_mode_create_lease_ioctl` has any of the necessary bounds checks.
|
| 111/2 |
2026/10/13 22:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_create_lease_ioctl]
Results: map[SourceCode: 469: /*
470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
475: int drm_mode_create_lease_ioctl(struct drm_device *dev,
476: void *data, struct drm_file *lessor_priv)
477: {
478: struct drm_mode_create_lease *cl = data;
479: size_t object_count;
480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
540: /* lessee will take the ownership of leases */
541: lessee = drm_lease_create(lessor, &leases);
542:
543: if (IS_ERR(lessee)) {
544: ret = PTR_ERR(lessee);
545: idr_destroy(&leases);
546: goto out_leases;
547: }
548:
549: /* Clone the lessor file to create a new file for us */
550: drm_dbg_lease(dev, "Allocating lease file\n");
551: lessee_file = file_clone_open(lessor_file);
552: if (IS_ERR(lessee_file)) {
553: ret = PTR_ERR(lessee_file);
554: goto out_lessee;
555: }
556:
557: lessee_priv = lessee_file->private_data;
558: /* Change the file to a master one */
559: drm_master_put(&lessee_priv->master);
560: lessee_priv->master = lessee;
561: lessee_priv->is_master = 1;
562: lessee_priv->authenticated = 1;
563:
564: /* Pass fd back to userspace */
565: drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
566: cl->fd = fd;
567: cl->lessee_id = lessee->lessee_id;
568:
569: /* Hook up the fd */
570: fd_install(fd, lessee_file);
571:
572: drm_master_put(&lessor);
573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
574: return 0;
575:
576: out_lessee:
577: drm_master_put(&lessee);
578:
579: out_leases:
580: put_unused_fd(fd);
581:
582: out_lessor:
583: drm_master_put(&lessor);
584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
585: return ret;
586: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 112/2 |
2026/10/13 22:49 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 59432
output: 41
thoughts: 98
Thoughts: Okay, here's my understanding, tailored for an expert audience, as if it were my own thought process:
**Potential Memory Allocation Issue with Object Counting and `memdup_array_user`**
Alright, let's see... the `object_count` variable, that's derived from `cl->object_count`, right? And that `cl->object_count` is a `__u32`. Okay, standard unsigned 32-bit integer. Now, `memdup_array_user`, the function that's crucial here, takes two `size_t` arguments: `n` and `size`. The real gotcha is, if `object_count` is particularly large β let's say it's nearing the maximum value for a `__u32` β there's a serious risk. I see the potential for a silent `-ENOMEM` failure within `memdup_array_user`. The use of `__GFP_NOWARN` is what really worries me here, because any memory allocation failure doesn't give a warning. If it *does* somehow manage to succeed, we then move on to call `fill_object_idr`. So, the main thing to consider is the size of `object_count` because there's clearly a potential for a really nasty, difficult-to-debug memory allocation failure that can happen silently. We need to analyze this closely, as large values would cause issues and possible `memdup_array_user` failure.
|
| 113/2 |
2026/10/13 22:49 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:fill_object_idr]
Results: map[SourceCode: 378: static int fill_object_idr(struct drm_device *dev,
379: struct drm_file *lessor_priv,
380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 114/2 |
2026/10/13 22:49 |
llm |
history-explorer |
0m
Model:
Tokens:
input: 61384
output: 963
thoughts: 1155
Thoughts: **My Analysis of the Proposed Fix**
Okay, so the initial plan is to swap `kzalloc_objs` with `kvzalloc_objs` and correspondingly replace `kfree` with `kvfree`. That seems reasonable on the surface. It matches the pattern seen in commit `bca45af5998a`. Let's dig deeper.
The core issue is that we have an unbounded user-controlled allocation size, leading to the page allocator throwing a warning because the requested size can exceed `MAX_PAGE_ORDER`. Switching to the `kvmalloc` family looks like the right approach, allowing the allocation to fall back to `vmalloc()` for potentially large requests, thus circumventing the page allocator's limitations.
I've been looking at similar cases in `drivers/gpu/drm/`. Commit `bca45af5998a` confirms this as the common solution. They encountered the exact same issue: an unbounded cache size list, that was causing allocation failures. The fix was, as we are proposing, to switch to `kvmalloc_objs()`. That gives us confidence in the approach.
However, there's a critical detail we need to address that's hinted at by `a1ba4594232c` and `0829b5bcdd3b`. If the user-controlled size is massive, even `kvmalloc` can generate a warning if the allocation size exceeds `INT_MAX`. Because `object_count` is a `__u32`, the total allocation size could easily exceed this, even with a pointer size of 8 bytes on a 64-bit system. We *must* include an upper bound check to prevent this.
I've just confirmed it in `mm/util.c` - `kvmalloc` does indeed warn when the allocation size exceeds `INT_MAX`. This makes the bounds check not just a good idea, but essential. `a1ba4594232c` shows precisely how to add that check. In our case, something like `if (object_count > INT_MAX / sizeof(struct drm_mode_object *))` will work. And looking at `cb77b79abf5f` and `c4ac100e9ae2`, we should also consider using `vmemdup_array_user()` for the `object_ids` allocation, to be consistent with the other DRM drivers dealing with large arrays.
Alright, time to formulate the final summary for the fix. The primary fix is to use `kvzalloc_objs` (or `kvcalloc()`) and `kvfree()` for the `objects` array. Crucially, we need to add the bounds check. We will want to check, `if (object_count > INT_MAX / sizeof(struct drm_mode_object *))`. Finally, let's consider switching `memdup_array_user()` to `vmemdup_array_user()` to ensure consistency. This combination of changes should provide a robust solution.
|
| 115/1 |
2026/10/13 22:50 |
action |
kernel-scratch-checkouter |
1m
Results: map[KernelScratchSrc:/app/workdir/cache/tmp/tmp770938699]
|
| 116/1 |
2026/10/13 22:51 |
loop |
|
1h26m
|
| 117/2 |
2026/10/13 22:51 |
iteration |
0 |
1h26m
|
| 118/3 |
2026/10/13 22:51 |
agent |
patch-generator |
24m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with creating a fix for a kernel bug.
You will be given a crash report, an initial explanation of the root cause done by another
kernel expert, and a summary of how similar bugs were fixed in the past.
Use the codeeditor tool to do code edits.
Note: you will not see your changes when looking at the code using codesearch tools.
Use the patch-diff tool to review the modifications you applied.
Your final reply should contain explanation of what you did in the patch and why
(details not present in the initial explanation of the bug).
Your fix must not just prevent the given crash, but also be the best fix for the underlying
root cause from the software engineering point of view. There can be several ways to fix the
same bug. Consider alternatives, and pick the best one. For example, additional checks may be
added at different locations/functions, it's usually better to place them earlier in the
execution to avoid multiple checks at various locations later.
Frequently the same coding mistake is done in several locations in the source code.
Check if your fix should be extended/applied to similar cases around to fix other similar bugs.
But don't go too wide, don't try to fix problems kernel-wide, fix similar issues
in the same file only.
If you are changing post-conditions of a function, consider all callers of the functions,
and if they need to be updated to handle new post-conditions. For example, if you make
a function that previously never returned a NULL, return NULL, consider if callers
need to be updated to handle NULL return value.
If you will end up removing the WARN_ON macro because the condition can legitimately happen,
add a pr_err/dev_err/... (whatever is the macro for printing runtime errors used in the file)
call that logs that the unlikely condition has happened. The pr_err/dev_err/... message
must not include "WARNING" nor "BUG" strings.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
The explanation of the root cause of the bug is:
An analysis of the crash reveals that it is caused by an unbounded user-controlled allocation size in the DRM lease creation ioctl, which attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` using the `kmalloc` family of functions.
### Root Cause Analysis
The crash is a warning triggered in `alloc_order_allowed()` because `__alloc_frozen_pages_noprof()` is called with an allocation order that exceeds `MAX_PAGE_ORDER` (typically 10, which corresponds to 4MB on systems with 4KB pages).
This happens in `fill_object_idr()` when allocating the `objects` array:
```c
// drivers/gpu/drm/drm_lease.c:389
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
The `kzalloc_objs` macro expands to a `kmalloc`-family allocation (equivalent to `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`).
The `object_count` comes directly from the user-space `drm_mode_create_lease` struct via `cl->object_count` in `drm_mode_create_lease_ioctl()`. There is no upper bound check on this value.
Before calling `fill_object_idr()`, `drm_mode_create_lease_ioctl()` allocates the `object_ids` array using `memdup_array_user()`:
```c
// drivers/gpu/drm/drm_lease.c:512
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user()` uses `memdup_user()`, which allocates memory with `GFP_USER | __GFP_NOWARN`. Because of the `__GFP_NOWARN` flag, if `object_count` is extremely large (e.g., requiring > 4MB), `memdup_array_user()` will silently fail and return `-ENOMEM` without triggering any warnings.
However, there is a specific window where `object_count` is large enough to require more than 4MB for the `objects` array (which has 8-byte pointers on 64-bit systems), but small enough that the `object_ids` array (which has 4-byte `__u32` elements) fits within 4MB.
In the provided syzkaller reproducer:
```c
*(uint32_t*)0x200003c8 = 0xf4240; // object_count = 1,000,000
```
1. `object_count` is set to `1,000,000`.
2. `memdup_array_user()` allocates `1,000,000 * 4 = 4,000,000` bytes. This is order 10, which is `<= MAX_PAGE_ORDER`. The allocation succeeds.
3. `fill_object_idr()` then calls `kzalloc_objs()` to allocate `1,000,000 * 8 = 8,000,000` bytes. This requires order 11, which is `> MAX_PAGE_ORDER`.
4. Since `kzalloc_objs()` uses `GFP_KERNEL` without `__GFP_NOWARN`, the page allocator loudly complains and triggers the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` warning.
### Proposed Fix
To fix this, the allocation of the `objects` array in `fill_object_idr()` should be changed to use `kvzalloc_objs()`, which gracefully falls back to `vmalloc()` for large allocations and does not trigger the page allocator warning. The corresponding `kfree()` must also be updated to `kvfree()`.
```c
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,7 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +462,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
```
*(Note: While adding an arbitrary upper bound check to `object_count` in `drm_mode_create_lease_ioctl()` is another option, using `kvzalloc_objs()` is the standard kernel pattern for handling user-controlled array sizes without imposing artificial limits).*
Historical context on how similar bugs were fixed in the past:
Based on a review of recent commits in the DRM subsystem (`drivers/gpu/drm/`) over the last 3 years, there is a clear set of established idioms and patterns for addressing unbounded user-controlled allocation sizes that trigger page allocator warnings.
### 1. Switching to the `kvmalloc` family (Primary Fix)
The proposed fix of switching from `kzalloc_objs()` to `kvzalloc_objs()` (and `kfree()` to `kvfree()`) is the standard kernel pattern for handling large, unbounded arrays without imposing artificial limits.
* **Prior Art:** Commit `bca45af5998a` ("drm/vc4: Use kvmalloc_objs() for the BO cache size list") fixed a nearly identical issue where an unbounded cache size list scaled with the largest BO freed, requiring an order-6 allocation that failed under fragmentation and triggered a `warn_alloc()` splat. The fix was to use `kvmalloc_objs()` so large lists can fall back to `vmalloc()`, avoiding the allocation failure.
### 2. Adding an Upper Bound Check (Crucial Secondary Fix)
While `kvmalloc` avoids the `MAX_PAGE_ORDER` warning, it has its own limitation: it will trigger a `WARN_ON_ONCE(size > INT_MAX)` if the requested allocation size exceeds `INT_MAX` (2GB). Because `object_count` is a `__u32` and `sizeof(struct drm_mode_object *)` is 8 bytes on 64-bit systems, a malicious user can easily pass an `object_count` that results in an allocation size up to ~34GB, which will still trigger a kernel warning even with `kvzalloc_objs()`.
* **Prior Art:** Commit `a1ba4594232c` ("drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO") addressed this exact scenario. A user-supplied `__u32` was used in `kvcalloc()`, which produced an allocation exceeding `INT_MAX` and triggered a warning in `__kvmalloc_node_noprof()`. The fix was to add a bounds check (`if (args->num_entries > INT_MAX / sizeof(*vm_entries)) return -EINVAL;`).
* **Prior Art:** Commit `0829b5bcdd3b` ("drm/i915: 2 GiB of relocations ought to be enough for anybody*") similarly capped the number of relocations to avoid the `kvmalloc` warning for `size > INT_MAX`.
### 3. Consistent Userspace Copying (Optional but Recommended)
Before allocating the `objects` array, the code allocates the `object_ids` array using `memdup_array_user()`. While `memdup_array_user()` fails silently for large sizes (due to `__GFP_NOWARN`), it still limits the maximum size to `MAX_PAGE_ORDER`. To consistently support large arrays across both allocations and separate user/kernel slabs, the DRM subsystem has been moving towards using `vmemdup_array_user()`.
* **Prior Art:** Commit `cb77b79abf5f` ("drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup") and commit `c4ac100e9ae2` ("drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array") both replaced `kvmalloc_array() + copy_from_user()` or `memdup_user()` with `vmemdup_array_user()` when dealing with potentially large, user-controlled arrays.
### Summary of Recommendations for the Fix
Based on how similar bugs were addressed, the final fix should:
1. Apply the proposed switch to `kvzalloc_objs()` and `kvfree()` in `fill_object_idr()`.
2. Add a sanity bounds check in `drm_mode_create_lease_ioctl()` to ensure `object_count` does not exceed `INT_MAX / sizeof(void *)` to prevent `kvmalloc` from warning on sizes > 2GB.
3. (Optional) Change the `object_ids` allocation from `memdup_array_user()` to `vmemdup_array_user()` to allow the first array to also gracefully fall back to `vmalloc()`.
Reply: I have created a patch to address the page allocator warning triggered in `drm_mode_create_lease_ioctl()`.
### Root Cause & Engineering Analysis
1. In `fill_object_idr()`, the temporary `objects` pointer array was allocated using `kzalloc_objs(struct drm_mode_object *, object_count)`. Because `kzalloc_objs` expands to `kmalloc` with `GFP_KERNEL` (which lacks `__GFP_NOWARN`), when a userspace caller provides a sufficiently large `cl->object_count` (e.g., 1,000,000 mode objects), the requested size exceeds `MAX_PAGE_ORDER` (order 11 > 10), triggering the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, ...)` in `alloc_order_allowed()`.
2. Although `cl->object_ids` was duplicated from user space using `memdup_array_user()`, that allocation also relied on `kmalloc` and could fail under memory fragmentation or for larger order allocations.
3. While switching to the `kvmalloc` family (`kvzalloc_objs()`) enables falling back to `vmalloc()` to prevent the `MAX_PAGE_ORDER` splat, `__kvmalloc_node_noprof()` still triggers a `WARN_ON_ONCE(size > INT_MAX)` if user space passes a crazy allocation size (> 2GB). Since `cl->object_count` is an unbounded `__u32`, `object_count * sizeof(struct drm_mode_object *)` could otherwise easily exceed `INT_MAX`.
4. Furthermore, `cl->object_count` is a `__u32` in `struct drm_mode_create_lease`, but `fill_object_idr()` and `validate_lease()` accept `int object_count`. Without an upper bound, a value $\ge 2^{31}$ would suffer signed integer overflow.
### Changes Made
1. **Switch to `kvzalloc_objs()` / `kvfree()`**:
In `fill_object_idr()`, switched the `objects` array allocation from `kzalloc_objs()` to `kvzalloc_objs()` so large allocations can gracefully fall back to `vmalloc()`, and updated `kfree(objects)` to `kvfree(objects)`.
2. **Switch to `vmemdup_array_user()` / `kvfree()`**:
In `drm_mode_create_lease_ioctl()`, switched copying `cl->object_ids` from `memdup_array_user()` to `vmemdup_array_user()`, and updated `kfree(object_ids)` to `kvfree(object_ids)`.
3. **Early Upper Bounds Check**:
Added an early check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))` at the start of `drm_mode_create_lease_ioctl()`, alongside the `cl->flags` validation. Placing this check before `drm_file_get_master(lessor_priv)` ensures that invalid requests are rejected early with `-EINVAL` without leaking the lessor's `drm_master` reference, prevents `__kvmalloc_node_noprof()` from triggering `WARN_ON_ONCE(size > INT_MAX)` on both allocations, and guarantees that `object_count` safely fits within a positive `int`.
4. **Header Cleanups**:
Included `<linux/limits.h>`, `<linux/slab.h>`, and `<linux/string.h>` in `drivers/gpu/drm/drm_lease.c` for `INT_MAX`, `kvzalloc_objs`/`kvfree`, and `vmemdup_array_user`.
|
| 119/4 |
2026/10/13 22:51 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 8929
output: 40
thoughts: 112
Thoughts: **Analyzing the DRM Lease Implementation**
Okay, let's break this down. My initial instinct is to dive into the kernel code and see exactly what's going on. The problem likely relates to the DRM lease mechanism, so I'll start by focusing on `drivers/gpu/drm/drm_lease.c`. Specifically, I need to understand how the lease creation is handled, so I'll be investigating `drm_mode_create_lease_ioctl()` and the `fill_object_idr()` function. I'll need to understand their functionality to comprehend how they interrelate. I'll need to look around these functions as well.
To get a clearer picture, I'll need to read the source code directly. I'll use `read-file` and zero in on the relevant section, approximately lines 380 to 550, which should contain the key logic for these functions. Hopefully, this will give me the information I need.
|
| 120/4 |
2026/10/13 22:51 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:370 LineCount:100]
Results: map[Contents: 370: }
371: if (has_crtc == -1 || has_connector == -1)
372: return -EINVAL;
373: if (universal_planes && has_plane == -1)
374: return -EINVAL;
375: return 0;
376: }
377:
378: static int fill_object_idr(struct drm_device *dev,
379: struct drm_file *lessor_priv,
380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
468:
469: /*
]
|
| 121/4 |
2026/10/13 22:51 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 10877
output: 40
thoughts: 29
Thoughts: Okay, here's my interpretation of what I would be thinking, formatted as requested:
**Diving into the Lease Implementation**
Right, let's get down to brass tacks. I've been working with DRM lease mechanisms for a while now, and to really understand how they are functioning in this specific context, I need to get my hands dirty. I'm going to start by pulling up the `drivers/gpu/drm/drm_lease.c` file. Given my expertise, I'm already familiar with the general structure, but I need to see exactly how this driver is handling the lease logic. Let's zero in on lines 470 through 570. That should give me a good slice of the critical code, right in the middle of the most important logic. That range will likely contain crucial sections related to either lease granting, renewal, revocation, or maybe even the interplay between userspace and the kernel. I'm hoping to quickly identify the key functions or data structures being used to manage these leases within this specific driver. From there I'll be able to tell what's happening at any point in time.
|
| 122/4 |
2026/10/13 22:52 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:470 LineCount:100]
Results: map[Contents: 470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
475: int drm_mode_create_lease_ioctl(struct drm_device *dev,
476: void *data, struct drm_file *lessor_priv)
477: {
478: struct drm_mode_create_lease *cl = data;
479: size_t object_count;
480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
540: /* lessee will take the ownership of leases */
541: lessee = drm_lease_create(lessor, &leases);
542:
543: if (IS_ERR(lessee)) {
544: ret = PTR_ERR(lessee);
545: idr_destroy(&leases);
546: goto out_leases;
547: }
548:
549: /* Clone the lessor file to create a new file for us */
550: drm_dbg_lease(dev, "Allocating lease file\n");
551: lessee_file = file_clone_open(lessor_file);
552: if (IS_ERR(lessee_file)) {
553: ret = PTR_ERR(lessee_file);
554: goto out_lessee;
555: }
556:
557: lessee_priv = lessee_file->private_data;
558: /* Change the file to a master one */
559: drm_master_put(&lessee_priv->master);
560: lessee_priv->master = lessee;
561: lessee_priv->is_master = 1;
562: lessee_priv->authenticated = 1;
563:
564: /* Pass fd back to userspace */
565: drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
566: cl->fd = fd;
567: cl->lessee_id = lessee->lessee_id;
568:
569: /* Hook up the fd */
]
|
| 123/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 12743
output: 39
thoughts: 36
Thoughts: Here's my take on the thought process, summarized as you requested:
**Digging Deeper into the DRM Lease Implementation**
Okay, so I've looked at the surface, and I'm pretty sure I know what's going on here, but let's not make any assumptions. Before I lock anything down, I need to thoroughly vet `drm_mode_create_lease_ioctl` and all of `drm_lease.c`. I have a feeling there might be some related functions or potentially even subtle references to other components that could be relevant to the issue I'm investigating. I need to be absolutely certain I understand the full scope of this lease mechanism, and the possible interactions, before I go any further. Itβs the only way to avoid missing something crucial. Let's see what else the code reveals.
|
| 124/4 |
2026/10/13 22:52 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:565 LineCount:40]
Results: map[Contents: 565: drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
566: cl->fd = fd;
567: cl->lessee_id = lessee->lessee_id;
568:
569: /* Hook up the fd */
570: fd_install(fd, lessee_file);
571:
572: drm_master_put(&lessor);
573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
574: return 0;
575:
576: out_lessee:
577: drm_master_put(&lessee);
578:
579: out_leases:
580: put_unused_fd(fd);
581:
582: out_lessor:
583: drm_master_put(&lessor);
584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
585: return ret;
586: }
587:
588: int drm_mode_list_lessees_ioctl(struct drm_device *dev,
589: void *data, struct drm_file *lessor_priv)
590: {
591: struct drm_mode_list_lessees *arg = data;
592: __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr);
593: __u32 count_lessees = arg->count_lessees;
594: struct drm_master *lessor, *lessee;
595: int count;
596: int ret = 0;
597:
598: if (arg->pad)
599: return -EINVAL;
600:
601: /* Can't lease without MODESET */
602: if (!drm_core_check_feature(dev, DRIVER_MODESET))
603: return -EOPNOTSUPP;
604:
]
|
| 125/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 13623
output: 40
thoughts: 51
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Diving into the Lease Implementation**
Right, so we're focused on DRM leases, and my initial thought is to comprehensively audit the related ioctls within `drivers/gpu/drm/drm_lease.c`. We're likely dealing with the core logic there, and a thorough review of the various control interfaces is essential for understanding the full picture.
I'm specifically targeting the latter part of the file; I'll start by examining lines 605 and beyond. This usually means we're in the thick of the more complex lease management functions, perhaps error handling, cleanup routines, or interaction with other subsystems. I need to get a handle on what happens at the end of the line, and go from there.
|
| 126/4 |
2026/10/13 22:52 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:605 LineCount:100]
Results: map[Contents: 605: lessor = drm_file_get_master(lessor_priv);
606: drm_dbg_lease(dev, "List lessees for %d\n", lessor->lessee_id);
607:
608: mutex_lock(&dev->mode_config.idr_mutex);
609:
610: count = 0;
611: drm_for_each_lessee(lessee, lessor) {
612: /* Only list un-revoked leases */
613: if (!idr_is_empty(&lessee->leases)) {
614: if (count_lessees > count) {
615: drm_dbg_lease(dev, "Add lessee %d\n",
616: lessee->lessee_id);
617: ret = put_user(lessee->lessee_id, lessee_ids + count);
618: if (ret)
619: break;
620: }
621: count++;
622: }
623: }
624:
625: drm_dbg_lease(dev, "Lessor leases to %d\n", count);
626: if (ret == 0)
627: arg->count_lessees = count;
628:
629: mutex_unlock(&dev->mode_config.idr_mutex);
630: drm_master_put(&lessor);
631:
632: return ret;
633: }
634:
635: /* Return the list of leased objects for the specified lessee */
636: int drm_mode_get_lease_ioctl(struct drm_device *dev,
637: void *data, struct drm_file *lessee_priv)
638: {
639: struct drm_mode_get_lease *arg = data;
640: __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr);
641: __u32 count_objects = arg->count_objects;
642: struct drm_master *lessee;
643: struct idr *object_idr;
644: int count;
645: void *entry;
646: int object;
647: int ret = 0;
648:
649: if (arg->pad)
650: return -EINVAL;
651:
652: /* Can't lease without MODESET */
653: if (!drm_core_check_feature(dev, DRIVER_MODESET))
654: return -EOPNOTSUPP;
655:
656: lessee = drm_file_get_master(lessee_priv);
657: drm_dbg_lease(dev, "get lease for %d\n", lessee->lessee_id);
658:
659: mutex_lock(&dev->mode_config.idr_mutex);
660:
661: if (lessee->lessor == NULL)
662: /* owner can use all objects */
663: object_idr = &lessee->dev->mode_config.object_idr;
664: else
665: /* lessee can only use allowed object */
666: object_idr = &lessee->leases;
667:
668: count = 0;
669: idr_for_each_entry(object_idr, entry, object) {
670: if (count_objects > count) {
671: drm_dbg_lease(dev, "adding object %d\n", object);
672: ret = put_user(object, object_ids + count);
673: if (ret)
674: break;
675: }
676: count++;
677: }
678:
679: DRM_DEBUG("lease holds %d objects\n", count);
680: if (ret == 0)
681: arg->count_objects = count;
682:
683: mutex_unlock(&dev->mode_config.idr_mutex);
684: drm_master_put(&lessee);
685:
686: return ret;
687: }
688:
689: /*
690: * This removes all of the objects from the lease without
691: * actually getting rid of the lease itself; that way all
692: * references to it still work correctly
693: */
694: int drm_mode_revoke_lease_ioctl(struct drm_device *dev,
695: void *data, struct drm_file *lessor_priv)
696: {
697: struct drm_mode_revoke_lease *arg = data;
698: struct drm_master *lessor;
699: struct drm_master *lessee;
700: int ret = 0;
701:
702: drm_dbg_lease(dev, "revoke lease for %d\n", arg->lessee_id);
703:
704: /* Can't lease without MODESET */
]
|
| 127/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 15393
output: 39
thoughts: 18
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as a first-person summary:
**Diving into `drm_mode_revoke_lease_ioctl`**
Alright, let's get down to brass tacks. I need to take a closer look at the rest of `drm_mode_revoke_lease_ioctl`. I've already scoped out the basics, and the general flow, but now it's time to dig deeper and ensure this function is behaving correctly under every possible scenario. I need to verify that it handles all the edge cases, and, critically, doesn't introduce any new security vulnerabilities. I'm focusing on the interaction with the DRM core, the resource management aspects, and of course, how it interacts with different drivers and configurations. I'm looking for potential race conditions, incorrect error handling, and anything that could lead to unexpected behavior. The goal is a rock-solid, secure implementation. Let's see what gems we can find in there!
|
| 128/4 |
2026/10/13 22:52 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:700 LineCount:40]
Results: map[Contents: 700: int ret = 0;
701:
702: drm_dbg_lease(dev, "revoke lease for %d\n", arg->lessee_id);
703:
704: /* Can't lease without MODESET */
705: if (!drm_core_check_feature(dev, DRIVER_MODESET))
706: return -EOPNOTSUPP;
707:
708: lessor = drm_file_get_master(lessor_priv);
709: mutex_lock(&dev->mode_config.idr_mutex);
710:
711: lessee = _drm_find_lessee(lessor, arg->lessee_id);
712:
713: /* No such lessee */
714: if (!lessee) {
715: ret = -ENOENT;
716: goto fail;
717: }
718:
719: /* Lease is not held by lessor */
720: if (lessee->lessor != lessor) {
721: ret = -EACCES;
722: goto fail;
723: }
724:
725: _drm_lease_revoke(lessee);
726:
727: fail:
728: mutex_unlock(&dev->mode_config.idr_mutex);
729: drm_master_put(&lessor);
730:
731: return ret;
732: }
]
|
| 129/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 16118
output: 37
thoughts: 44
Thoughts: Here's my take on the thought process:
**Reviewing the `drm_lease.c` Module**
Okay, that's the end of the `drm_lease.c` file β time to get a more comprehensive picture. To truly understand its place within the kernel, I need to zoom out. Let's start at the beginning of `drm_lease.c` to establish context, looking at those crucial initial header inclusions and the declared functions. Understanding the dependencies and the exposed API is key to dissecting how this leasing mechanism integrates with the broader Direct Rendering Manager (DRM) infrastructure. With a clear overview, I can make connections between the lease implementation and the kernel's overall functionality.
|
| 130/4 |
2026/10/13 22:52 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:1 LineCount:80]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0-or-later
2: /*
3: * Copyright Β© 2017 Keith Packard <keithp@keithp.com>
4: */
5: #include <linux/file.h>
6: #include <linux/uaccess.h>
7:
8: #include <drm/drm_auth.h>
9: #include <drm/drm_crtc.h>
10: #include <drm/drm_drv.h>
11: #include <drm/drm_file.h>
12: #include <drm/drm_lease.h>
13: #include <drm/drm_print.h>
14:
15: #include "drm_crtc_internal.h"
16: #include "drm_internal.h"
17:
18: /**
19: * DOC: drm leasing
20: *
21: * DRM leases provide information about whether a DRM master may control a DRM
22: * mode setting object. This enables the creation of multiple DRM masters that
23: * manage subsets of display resources.
24: *
25: * The original DRM master of a device 'owns' the available drm resources. It
26: * may create additional DRM masters and 'lease' resources which it controls
27: * to the new DRM master. This gives the new DRM master control over the
28: * leased resources until the owner revokes the lease, or the new DRM master
29: * is closed. Some helpful terminology:
30: *
31: * - An 'owner' is a &struct drm_master that is not leasing objects from
32: * another &struct drm_master, and hence 'owns' the objects. The owner can be
33: * identified as the &struct drm_master for which &drm_master.lessor is NULL.
34: *
35: * - A 'lessor' is a &struct drm_master which is leasing objects to one or more
36: * other &struct drm_master. Currently, lessees are not allowed to
37: * create sub-leases, hence the lessor is the same as the owner.
38: *
39: * - A 'lessee' is a &struct drm_master which is leasing objects from some
40: * other &struct drm_master. Each lessee only leases resources from a single
41: * lessor recorded in &drm_master.lessor, and holds the set of objects that
42: * it is leasing in &drm_master.leases.
43: *
44: * - A 'lease' is a contract between the lessor and lessee that identifies
45: * which resources may be controlled by the lessee. All of the resources
46: * that are leased must be owned by or leased to the lessor, and lessors are
47: * not permitted to lease the same object to multiple lessees.
48: *
49: * The set of objects any &struct drm_master 'controls' is limited to the set
50: * of objects it leases (for lessees) or all objects (for owners).
51: *
52: * Objects not controlled by a &struct drm_master cannot be modified through
53: * the various state manipulating ioctls, and any state reported back to user
54: * space will be edited to make them appear idle and/or unusable. For
55: * instance, connectors always report 'disconnected', while encoders
56: * report no possible crtcs or clones.
57: *
58: * Since each lessee may lease objects from a single lessor, display resource
59: * leases form a tree of &struct drm_master. As lessees are currently not
60: * allowed to create sub-leases, the tree depth is limited to 1. All of
61: * these get activated simultaneously when the top level device owner changes
62: * through the SETMASTER or DROPMASTER IOCTL, so &drm_device.master points to
63: * the owner at the top of the lease tree (i.e. the &struct drm_master for which
64: * &drm_master.lessor is NULL). The full list of lessees that are leasing
65: * objects from the owner can be searched via the owner's
66: * &drm_master.lessee_idr.
67: */
68:
69: #define drm_for_each_lessee(lessee, lessor) \
70: list_for_each_entry((lessee), &(lessor)->lessees, lessee_list)
71:
72: static uint64_t drm_lease_idr_object;
73:
74: struct drm_master *drm_lease_owner(struct drm_master *master)
75: {
76: while (master->lessor != NULL)
77: master = master->lessor;
78: return master;
79: }
80:
]
|
| 131/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 17700
output: 20
thoughts: 34
Thoughts: Okay, let's break this down.
**Investigating Memory Allocation Objects**
Right, so I need to understand what `kzalloc_objs` and `kvzalloc_objs` actually *are*. First instinct is to confirm their definitions β no point in making assumptions. Where are these things defined in the codebase? Okay, time to fire up `grep`. Let's see if we can locate them quickly and efficiently. Time to get to the core of these objects.
|
| 132/4 |
2026/10/13 22:52 |
tool |
grepper |
0m
Args: map[Expression:define kvzalloc_objs]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1172- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1173:#define kvzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1174- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
]
|
| 133/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 18015
output: 36
thoughts: 40
Thoughts: Okay, let's dive into this. Here's my thought process on this:
**Investigating `kzalloc_objs` and `kvzalloc_objs` in `slab.h`**
Right, so I need to refresh my memory on how `kzalloc_objs` and `kvzalloc_objs` are actually defined. Given that these are slab allocator functions, and I'm interested in their implementation details, I'm heading straight to the source. Specifically, I know that the core definitions for slab allocation are usually in `include/linux/slab.h`. The line number is a general guideline; I'm expecting to find them around line 1170. This gives me a decent starting point. From there, I'll examine the function signatures, any inline comments, and possibly associated macros to get a complete picture of these functions' behavior. Ultimately, I'm aiming to understand the specifics of their zero-initialization behavior with respect to object allocation within the kernel.
|
| 134/4 |
2026/10/13 22:52 |
tool |
read-file |
0m
Args: map[File:include/linux/slab.h FirstLine:1160 LineCount:25]
Results: map[Contents:1160: __alloc_flex(kzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
1161:
1162: /* All kvmalloc aliases for kmalloc_(obj|objs|flex). */
1163: #define kvmalloc_obj(P, ...) \
1164: __alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
1165: #define kvmalloc_objs(P, COUNT, ...) \
1166: __alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
1167: #define kvmalloc_flex(P, FAM, COUNT, ...) \
1168: __alloc_flex(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
1169:
1170: /* All kvzalloc aliases for kmalloc_(obj|objs|flex). */
1171: #define kvzalloc_obj(P, ...) \
1172: __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
1173: #define kvzalloc_objs(P, COUNT, ...) \
1174: __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
1175: #define kvzalloc_flex(P, FAM, COUNT, ...) \
1176: __alloc_flex(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
1177:
1178: #define kmem_buckets_alloc(_b, _size, _flags) \
1179: alloc_hooks(__kmalloc_node_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, NUMA_NO_NODE))
1180:
1181: #define kmem_buckets_alloc_node_track_caller(_b, _size, _flags, _node) \
1182: alloc_hooks(__kmalloc_node_track_caller_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, _node, _RET_IP_))
1183:
1184: #define kmem_buckets_alloc_track_caller(_b, _size, _flags) \
]
|
| 135/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 18944
output: 21
thoughts: 71
Thoughts: Here's my summary, as I'd be thinking it:
**Analyzing Memory Allocation in the DRM Mode Object Context**
Okay, so I'm looking at `kvzalloc_objs` here, and it's using `kvzalloc` with `sizeof(...) * count` and `GFP_KERNEL`. Standard kernel allocation using the vmalloc subsystem, that's fine. Now, let's see how that memory is handled. The next thing on the list is `vmemdup_array_user`. I need to figure out how this function fits into the picture. It's obviously related to memory duplication, potentially from userspace. Right, where is `vmemdup_array_user` actually defined? I'll just grep for that. Gotta trace that definition to see how it's dealing with copying from userspace, and what checks it's putting in place.
|
| 136/4 |
2026/10/13 22:52 |
tool |
grepper |
0m
Args: map[Expression:vmemdup_array_user]
Results: map[Output:arch/x86/kvm/cpuid.c=590=int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
--
arch/x86/kvm/cpuid.c-601- if (cpuid->nent) {
arch/x86/kvm/cpuid.c:602: e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e));
arch/x86/kvm/cpuid.c-603- if (IS_ERR(e))
--
arch/x86/kvm/cpuid.c=635=int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
--
arch/x86/kvm/cpuid.c-645- if (cpuid->nent) {
arch/x86/kvm/cpuid.c:646: e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2));
arch/x86/kvm/cpuid.c-647- if (IS_ERR(e2))
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c=164=amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-174-
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:175: return vmemdup_array_user(uptr, bo_number,
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-176- sizeof(struct drm_amdgpu_bo_list_entry));
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c=179=static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-219-
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:220: p->chunks[i].kdata = vmemdup_array_user(u64_to_user_ptr(user_chunk.chunk_data),
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-221- size,
--
drivers/gpu/drm/drm_gem.c=832=int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
--
drivers/gpu/drm/drm_gem.c-847-
drivers/gpu/drm/drm_gem.c:848: handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
drivers/gpu/drm/drm_gem.c-849- if (IS_ERR(handles)) {
--
drivers/tty/vt/consolemap.c=632=int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
--
drivers/tty/vt/consolemap.c-640-
drivers/tty/vt/consolemap.c:641: struct unipair *unilist __free(kvfree) = vmemdup_array_user(list, ct, sizeof(*unilist));
drivers/tty/vt/consolemap.c-642- if (IS_ERR(unilist))
--
include/linux/string.h=32=void *memdup_array_user(const void __user *src, size_t n, size_t size)
--
include/linux/string.h-42-/**
include/linux/string.h:43: * vmemdup_array_user - duplicate array from user space
include/linux/string.h-44- * @src: source address in user space
--
include/linux/string.h=51=static inline __realloc_size(2, 3)
include/linux/string.h:52:void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
include/linux/string.h-53-{
--
virt/kvm/kvm_main.c=5177=static long kvm_vm_ioctl(struct file *filp,
--
virt/kvm/kvm_main.c-5344- urouting = argp;
virt/kvm/kvm_main.c:5345: entries = vmemdup_array_user(urouting->entries,
virt/kvm/kvm_main.c-5346- routing.nr, sizeof(*entries));
]
|
| 137/4 |
2026/10/13 22:52 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 20437
output: 34
thoughts: 33
Thoughts: Here's my analysis of the provided thought process, tailored for an expert audience:
**Diving into `vmemdup_array_user` Implementation**
Okay, so we're looking to understand the mechanics behind `vmemdup_array_user`. My first instinct is to go directly to the source. Specifically, I'll be heading over to `include/linux/string.h`, around line 40, to get a clear picture of its implementation details. I want to see precisely how it handles the virtual memory duplication within a user context. I'm assuming there's something non-trivial there, perhaps related to memory access permissions or security considerations for user-space data. The goal is to identify any potential gotchas or optimizations in its design. Let's see what's actually under the hood.
|
| 138/4 |
2026/10/13 22:53 |
tool |
read-file |
0m
Args: map[File:include/linux/string.h FirstLine:30 LineCount:40]
Results: map[Contents: 30: */
31: static inline __realloc_size(2, 3)
32: void *memdup_array_user(const void __user *src, size_t n, size_t size)
33: {
34: size_t nbytes;
35:
36: if (check_mul_overflow(n, size, &nbytes))
37: return ERR_PTR(-EOVERFLOW);
38:
39: return memdup_user(src, nbytes);
40: }
41:
42: /**
43: * vmemdup_array_user - duplicate array from user space
44: * @src: source address in user space
45: * @n: number of array members to copy
46: * @size: size of one array member
47: *
48: * Return: an ERR_PTR() on failure. Result may be not
49: * physically contiguous. Use kvfree() to free.
50: */
51: static inline __realloc_size(2, 3)
52: void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
53: {
54: size_t nbytes;
55:
56: if (check_mul_overflow(n, size, &nbytes))
57: return ERR_PTR(-EOVERFLOW);
58:
59: return vmemdup_user(src, nbytes);
60: }
61:
62: /*
63: * Include machine specific inline routines
64: */
65: #include <asm/string.h>
66:
67: #ifndef __HAVE_ARCH_STRCPY
68: extern char * strcpy(char *,const char *);
69: #endif
]
|
| 139/4 |
2026/10/13 22:53 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 21210
output: 36
thoughts: 71
Thoughts: Here's my thought process, as requested:
**Understanding the Memory Allocation and Deallocation in `vmemdup_array_user`**
Okay, so `vmemdup_array_user` is returning memory allocated with `kvmalloc`, and crucially, this means I need to use `kvfree()` to release it. That's straightforward, but I need to be absolutely certain I'm not missing any subtleties here. Let's delve deeper into the implementation. What precisely is `vmemdup_user` doing behind the scenes? I need to understand its behaviour to be completely confident in how I'm handling the memory. I should be able to get a clear picture with a quick search using `grep`, or by jumping to the source code definition itself. I need to be sure that `vmemdup_user` doesn't do anything unexpected, or allocate additional memory that I need to be concerned with.
|
| 140/4 |
2026/10/13 22:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:vmemdup_user]
Results: map[SourceCode: 234: /**
235: * vmemdup_user - duplicate memory region from user space
236: *
237: * @src: source address in user space
238: * @len: number of bytes to copy
239: *
240: * Return: an ERR_PTR() on failure. Result may be not
241: * physically contiguous. Use kvfree() to free.
242: */
243: void *vmemdup_user(const void __user *src, size_t len)
244: {
245: void *p;
246:
247: p = kmem_buckets_valloc(user_buckets, len, GFP_USER);
248: if (!p)
249: return ERR_PTR(-ENOMEM);
250:
251: if (copy_from_user(p, src, len)) {
252: kvfree(p);
253: return ERR_PTR(-EFAULT);
254: }
255:
256: return p;
257: }
SourceFile:mm/util.c]
|
| 141/4 |
2026/10/13 22:53 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 21862
output: 38
thoughts: 50
Thoughts: Okay, let's dive into this `kvmalloc` business. I'm wondering what happens when we throw a size larger than `INT_MAX` at it. My initial thought is to trace the execution path and see where it goes. I'll need to check the relevant function calls within the kernel code. Specifically, I'm thinking of looking at either `__kvmalloc_node_noprof` or `kvmalloc_node` in `mm/util.c`. That should give me the entry point or, at the very least, where the size parameter gets validated or processed. I'm keen to see if there's any overflow handling or if it just crashes spectacularly. Knowing the kernel, I'm guessing there's *something* in place, but I want to be certain.
|
| 142/4 |
2026/10/13 22:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/util.c Name:__kvmalloc_node_noprof]
Results: map[SourceCode:7000: void *__kvmalloc_node_noprof(DECL_KMALLOC_PARAMS(size, b, token), unsigned long align,
7001: gfp_t flags, int node)
7002: {
7003: bool allow_block;
7004: void *ret;
7005: const struct slab_alloc_context ac = {
7006: .caller_addr = _RET_IP_,
7007: .orig_size = size,
7008: .alloc_flags = SLAB_ALLOC_DEFAULT,
7009: };
7010:
7011: /*
7012: * It doesn't really make sense to fallback to vmalloc for sub page
7013: * requests
7014: */
7015: ret = __do_kmalloc_node(PASS_BUCKET_PARAM(b),
7016: kmalloc_gfp_adjust(flags, size),
7017: node, PASS_TOKEN_PARAM(token), &ac);
7018: if (ret || size <= PAGE_SIZE)
7019: return ret;
7020:
7021: /* Don't even allow crazy sizes */
7022: if (unlikely(size > INT_MAX)) {
7023: WARN_ON_ONCE(!(flags & __GFP_NOWARN));
7024: return NULL;
7025: }
7026:
7027: /*
7028: * For non-blocking the VM_ALLOW_HUGE_VMAP is not used
7029: * because the huge-mapping path in vmalloc contains at
7030: * least one might_sleep() call.
7031: *
7032: * TODO: Revise huge-mapping path to support non-blocking
7033: * flags.
7034: */
7035: allow_block = gfpflags_allow_blocking(flags);
7036:
7037: /*
7038: * kvmalloc() can always use VM_ALLOW_HUGE_VMAP,
7039: * since the callers already cannot assume anything
7040: * about the resulting pointer, and cannot play
7041: * protection games.
7042: */
7043: return __vmalloc_node_range_noprof(size, align, VMALLOC_START, VMALLOC_END,
7044: flags, PAGE_KERNEL, allow_block ? VM_ALLOW_HUGE_VMAP:0,
7045: node, __builtin_return_address(0));
7046: }
SourceFile:mm/slub.c]
|
| 143/4 |
2026/10/13 22:53 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 22857
output: 42
thoughts: 233
Thoughts: **Analyzing Potential Integer Overflow in `kvzalloc_objs`**
Okay, let's break this down. I'm looking at lines 7022-7025 in `mm/slub.c`. It's pretty clear that they're guarding against excessively large allocation sizes, specifically checking if `size > INT_MAX`. The key is what happens if that condition *is* true.
Now, I'm thinking about `kvzalloc_objs(struct drm_mode_object *, object_count)`. I know that this function is involved, and I remember that the `flags` parameter passed to it is `GFP_KERNEL`. And, critically, `GFP_KERNEL` *does not* include the `__GFP_NOWARN` flag. So, if `size` does exceed `INT_MAX`, that `WARN_ON_ONCE` will trigger because the bitwise AND operation `(flags & __GFP_NOWARN)` will always be false. The function will then return `NULL`.
The next important question is: what actually *is* `object_count`? Where does this come from? It's time to check the definition of `struct drm_mode_create_lease`. I need to figure out how `object_count` is calculated or passed in. This looks like a potential area for integer overflow if the input from `struct drm_mode_create_lease` is large. Let's see how they handle it there.
|
| 144/4 |
2026/10/13 22:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_create_lease]
Results: map[SourceCode:1425: /**
1426: * struct drm_mode_create_lease - Create lease
1427: *
1428: * Lease mode resources, creating another drm_master.
1429: *
1430: * The @object_ids array must reference at least one CRTC, one connector and
1431: * one plane if &DRM_CLIENT_CAP_UNIVERSAL_PLANES is enabled. Alternatively,
1432: * the lease can be completely empty.
1433: */
1434: struct drm_mode_create_lease {
1435: /** @object_ids: Pointer to array of object ids (__u32) */
1436: __u64 object_ids;
1437: /** @object_count: Number of object ids */
1438: __u32 object_count;
1439: /** @flags: flags for new FD (O_CLOEXEC, etc) */
1440: __u32 flags;
1441:
1442: /** @lessee_id: Return: unique identifier for lessee. */
1443: __u32 lessee_id;
1444: /** @fd: Return: file descriptor to new drm_master file */
1445: __u32 fd;
1446: };
SourceFile:include/uapi/drm/drm_mode.h]
|
| 145/4 |
2026/10/13 22:53 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 23837
output: 39
thoughts: 555
Thoughts: **A Potential Integer Overflow Vulnerability in DRM Lease Creation**
Okay, let's break this down. I'm looking at the `drm_mode_create_lease` structure and the corresponding ioctl handler. I see that the `object_count` member in the structure is an `__u32`. In the `drm_mode_create_lease_ioctl` function, the `object_count` variable is defined as `size_t` and gets assigned the value from the user-provided `cl->object_count`. So far, so good. Then, the code allocates memory for `object_ids` based on this `object_count`.
However, here's where things get interesting. This `object_count` is then passed to the `fill_object_idr` function. And that's where the problem is because `fill_object_idr` takes `object_count` as an `int`. Now, if `cl->object_count` has a large value, say 0x80000000, which is perfectly valid for an unsigned 32-bit integer, and then that value is assigned to the `int object_count` inside `fill_object_idr`, then `object_count` would become negative due to the signed integer conversion. This is a classic integer overflow situation.
The next thing is that within `fill_object_idr`, there's a loop that iterates up to `object_count`. If `object_count` is negative due to overflow, the loop wouldn't run at all. Later, `validate_lease` might be used with `int object_count` depending on what `validate_lease` is, and that will be problematic. This is something that needs further investigation. It seems that there's a potential vulnerability here that an attacker could exploit to bypass checks or cause other unexpected behavior, or even potentially cause a crash. I need to understand what `validate_lease` does, so that I can figure out the impact of this overflow.
|
| 146/4 |
2026/10/13 22:53 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:330 LineCount:50]
Results: map[Contents: 330: if (master == top)
331: break;
332:
333: /* Over */
334: master = list_next_entry(master, lessee_list);
335: }
336: }
337: }
338:
339: void drm_lease_revoke(struct drm_master *top)
340: {
341: mutex_lock(&top->dev->mode_config.idr_mutex);
342: _drm_lease_revoke(top);
343: mutex_unlock(&top->dev->mode_config.idr_mutex);
344: }
345:
346: static int validate_lease(struct drm_device *dev,
347: int object_count,
348: struct drm_mode_object **objects,
349: bool universal_planes)
350: {
351: int o;
352: int has_crtc = -1;
353: int has_connector = -1;
354: int has_plane = -1;
355:
356: /* we want to confirm that there is at least one crtc, plane
357: connector object. */
358:
359: for (o = 0; o < object_count; o++) {
360: if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
361: has_crtc = o;
362: }
363: if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
364: has_connector = o;
365:
366: if (universal_planes) {
367: if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
368: has_plane = o;
369: }
370: }
371: if (has_crtc == -1 || has_connector == -1)
372: return -EINVAL;
373: if (universal_planes && has_plane == -1)
374: return -EINVAL;
375: return 0;
376: }
377:
378: static int fill_object_idr(struct drm_device *dev,
379: struct drm_file *lessor_priv,
]
|
| 147/4 |
2026/10/13 22:53 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 25590
output: 25
thoughts: 958
Thoughts: **Analyzing `drm_mode_create_lease_ioctl` and Unbounded Allocations**
Okay, let's dive into this `drm_mode_create_lease_ioctl` function. The code takes an `object_count` from userspace, which is concerning because it could lead to unbounded allocations. I need to figure out what the reasonable limit for the number of mode objects is for a DRM device.
The historical context provided is helpful. It points to established patterns within the DRM subsystem for dealing with these situations. There are three key recommendations:
1. **Switch to `kvmalloc`:** The primary fix is switching from `kzalloc_objs` to `kvzalloc_objs` and `kfree` to `kvfree`. This family is designed for large, user-controlled allocations without artificial limits.
2. **Add an Upper Bound Check:** While `kvmalloc` avoids the `MAX_PAGE_ORDER` warning, it still has its limits. If the allocation size exceeds `INT_MAX`, it will trigger a `WARN_ON_ONCE`. Considering `object_count` is a `__u32` and `sizeof(struct drm_mode_object *)` is 8 bytes on 64-bit systems, a malicious user could pass a large `object_count` and cause an allocation size of up to 34GB, still triggering a kernel warning. The fix should involve a bounds check to prevent allocations larger than INT\_MAX / sizeof(void \*). The provided prior art, like commit `a1ba4594232c`, clearly demonstrates this pattern of checking user-supplied values before calling `kvmalloc`.
3. **(Optional) Consistent Userspace Copying:** The code currently uses `memdup_array_user` for the `object_ids` array, which fails silently for large sizes due to `__GFP_NOWARN` but it still limits the maximum size to `MAX_PAGE_ORDER`. To support large arrays consistently, the suggested approach is to use `vmemdup_array_user` instead. This is consistent with what the DRM subsystem has been doing. The commits `cb77b79abf5f` and `c4ac100e9ae2` demonstrate how the `drm` subsystem replaced `kvmalloc_array + copy_from_user` or `memdup_user` with `vmemdup_array_user`.
So, the proposed solution involves:
* Replacing the current allocation with `kvzalloc_objs` and `kvfree` in `fill_object_idr`.
* Adding a bounds check in `drm_mode_create_lease_ioctl` to verify `object_count` doesn't exceed `INT_MAX / sizeof(void *)`.
* And, as an optional improvement, switching to `vmemdup_array_user` to handle the `object_ids` allocation.
Now I need to inspect those example commits the text mentions!
I'll use `git-show` to review `cb77b79abf5f`, `c4ac100e9ae2`, `a1ba4594232c`, and `bca45af5998a`.
|
| 148/4 |
2026/10/13 22:53 |
tool |
git-show |
0m
Args:
Results: map[Output:commit cb77b79abf5ff8f4af07f7ebef196a003c826b7a
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Wed Nov 12 09:27:32 2025 +0000
drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
Use a helper to shrink the code and separate the user and kernel slabs for
better security.
While at it lets remove the useless debug message.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: AndrΓ© Almeida <andrealmeid@igalia.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://lore.kernel.org/r/20251112092732.23584-1-tvrtko.ursulin@igalia.com
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index a1a9c828938b..68168d58a7c8 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)
{
- struct drm_device *dev = filp->minor->dev;
struct drm_gem_object **objs;
u32 *handles;
int ret;
@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
*objs_out = objs;
- handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL);
- if (!handles) {
- ret = -ENOMEM;
- goto out;
- }
-
- if (copy_from_user(handles, bo_handles, count * sizeof(u32))) {
- ret = -EFAULT;
- drm_dbg_core(dev, "Failed to copy in GEM handles\n");
+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
+ if (IS_ERR(handles)) {
+ ret = PTR_ERR(handles);
goto out;
}
]
|
| 149/4 |
2026/10/13 22:53 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 27990
output: 26
thoughts: 18
Thoughts: Okay, let's dive into this. I need to take a look at `a1ba4594232c`. Let me assess this thingβ¦
|
| 150/4 |
2026/10/13 22:54 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a1ba4594232c87c3b8defd6f89a2e40f8b08395d
Author: Ziyi Guo <n7l8m4@u.northwestern.edu>
Date: Sun Feb 8 00:02:55 2026 +0000
drm/amdgpu: check num_entries in GEM_OP GET_MAPPING_INFO
kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL) at
amdgpu_gem.c:1050 uses the user-supplied num_entries directly without
any upper bounds check. Since num_entries is a __u32 and
sizeof(drm_amdgpu_gem_vm_entry) is 32 bytes, a large num_entries
produces an allocation exceeding INT_MAX, triggering
WARNING in __kvmalloc_node_noprof(), causing a kernel WARNING,
TAINT_WARN, and panic on CONFIG_PANIC_ON_WARN=y systems.
Add a size bounds check before we invoke the kvzalloc() to
reject oversized num_entries early with -EINVAL.
Fixes: 4d82724f7f2b ("drm/amdgpu: Add mapping info option for GEM_OP ioctl")
Signed-off-by: Ziyi Guo <n7l8m4@u.northwestern.edu>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 1fe7bf5457f6efd7be60b17e23163ba54341d73d)
Cc: stable@vger.kernel.org
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
index 06dd2e8a5b47..fe6d988e7f24 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -1093,6 +1093,11 @@ int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
* If that number is larger than the size of the array, the ioctl must
* be retried.
*/
+ if (args->num_entries > INT_MAX / sizeof(*vm_entries)) {
+ r = -EINVAL;
+ goto out_exec;
+ }
+
vm_entries = kvcalloc(args->num_entries, sizeof(*vm_entries), GFP_KERNEL);
if (!vm_entries) {
r = -ENOMEM;
]
|
| 151/4 |
2026/10/13 22:54 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 28800
output: 25
thoughts: 97
Thoughts: Okay, let's break this down.
**Examining a Kernel Commit and Potential Vulnerabilities**
Alright, so I'm looking at this snippet from `amdgpu`, specifically this check for `args->num_entries` in relation to the size of `vm_entries`. The code is doing a sanity check: `if (args->num_entries > INT_MAX / sizeof(*vm_entries))`. Essentially, it's preventing an integer overflow when calculating the memory allocation size. It's a pretty standard defensive programming technique, protecting against a scenario where `args->num_entries` is a large value that, when multiplied by `sizeof(*vm_entries)`, could wrap around, resulting in a smaller allocation than expected. That could then lead to a buffer overflow.
The `kvcalloc` call confirms this is a kernel-mode allocation. The check is good, but it makes me wonder: can we exploit this? Are there any weaknesses in how `args->num_entries` is populated? Are there other integer-related vulnerabilities in this area? How does `bca45af5998a` interact with this? Perhaps it introduces another way to manipulate this value. It's a common pattern to look for dependencies and interaction points. It's important to understand the context and how the `args` structure is populated and how the value of `num_entries` is derived.
|
| 152/4 |
2026/10/13 22:54 |
tool |
git-show |
0m
Args:
Results: map[Output:commit bca45af5998a05f34b13a2ef11e639bac9c62643
Author: MaΓra Canal <mcanal@igalia.com>
Date: Wed Sep 30 16:06:51 2026 -0300
drm/vc4: Use kvmalloc_objs() for the BO cache size list
The BO cache size list has one entry per BO page count, so its size
scales with the largest BO ever freed. A 64 MiB BO already needs at
least an order-6 allocation, which fails under fragmentation and
triggers a warn_alloc() splat on BO close:
page allocation failure: order:7, mode:0x40cc0(GFP_KERNEL|__GFP_COMP)
Call trace:
...
warn_alloc+0x118/0x190
__alloc_pages_slowpath+0x4a8/0x520
...
__kmalloc_noprof+0x3ac/0x5d8
vc4_free_object+0x128/0x370 [vc4]
drm_gem_object_handle_put_unlocked+0xb8/0x158 [drm]
drm_gem_object_release_handle+0x74/0xe8 [drm]
drm_gem_handle_delete+0x6c/0xa8 [drm]
drm_gem_close_ioctl+0x34/0x50 [drm]
The list doesn't need physically contiguous memory. Use kvmalloc_objs()
so large lists can fall back to vmalloc(), avoiding the allocation
failure.
Fixes: c826a6e10644 ("drm/vc4: Add a BO cache.")
Reviewed-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
Link: https://patch.msgid.link/20260930190721.1897264-2-mcanal@igalia.com
Signed-off-by: MaΓra Canal <mcanal@igalia.com>
diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
index ea1be891ac78..7b8b3364000f 100644
--- a/drivers/gpu/drm/vc4/vc4_bo.c
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
@@ -204,7 +204,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
struct list_head *new_list;
uint32_t i;
- new_list = kmalloc_objs(struct list_head, new_size);
+ new_list = kvmalloc_objs(struct list_head, new_size);
if (!new_list)
return NULL;
@@ -224,7 +224,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
for (i = vc4->bo_cache.size_list_size; i < new_size; i++)
INIT_LIST_HEAD(&new_list[i]);
- kfree(vc4->bo_cache.size_list);
+ kvfree(vc4->bo_cache.size_list);
vc4->bo_cache.size_list = new_list;
vc4->bo_cache.size_list_size = new_size;
}
@@ -1052,7 +1052,7 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)
cancel_work_sync(&vc4->bo_cache.time_work);
vc4_bo_cache_purge(dev);
- kfree(vc4->bo_cache.size_list);
+ kvfree(vc4->bo_cache.size_list);
for (i = 0; i < vc4->num_labels; i++) {
if (vc4->bo_labels[i].num_allocated) {
]
|
| 153/4 |
2026/10/13 22:54 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 30320
output: 25
thoughts: 18
Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person:
**Analyzing the New Data Point: 0829b5bcdd3b**
Alright, let's dissect this new element: `0829b5bcdd3b`. I need to assess its place in the broader picture. What's its potential significance? My immediate questions are: What system is it from? What metadata is associated with it? What are the immediate and direct connections from this to anything else?
My first instinct is to run it through my standard battery of initial analysis tools: entropy checks, character distribution, known hash databases, any readily available online resources. Does this look like code? Is this an identifier, a timestamp, a key, or something entirely new?
I'll be looking for any inherent patterns and correlations that emerge immediately. Is there an obvious relationship to other data points I'm already aware of? Does the hexadecimal format suggest anything about its origin or purpose? Are there any clear markers indicating its use as a unique identifier?
Once I get these initial results, I'll examine the immediate network. What links exist? Is this piece of data referenced in any logs? Is there any record of this information being accessed? I need to build a connection map to gain a full understanding of its function and importance.
|
| 154/4 |
2026/10/13 22:54 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 0829b5bcdd3ba077c408e71e22ac2bfa85bf2c95
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Tue May 21 11:12:01 2024 +0100
drm/i915: 2 GiB of relocations ought to be enough for anybody*
Kernel test robot reports i915 can hit a warn in kvmalloc_node which has
a purpose of dissalowing crazy size kernel allocations. This was added in
7661809d493b ("mm: don't allow oversized kvmalloc() calls"):
/* Don't even allow crazy sizes */
if (WARN_ON_ONCE(size > INT_MAX))
return NULL;
This would be kind of okay since i915 at one point dropped the need for
making a shadow copy of the relocation list, but then it got re-added in
fd1500fcd442 ("Revert "drm/i915/gem: Drop relocation slowpath".") a year
after Linus added the above warning.
It is plausible that the issue was not seen until now because to trigger
gem_exec_reloc test requires a combination of an relatively older
generation hardware but with at least 8GiB of RAM installed. Probably even
more depending on runtime checks.
Lets cap what we allow userspace to pass in using the matching limit.
There should be no issue for real userspace since we are talking about
"crazy" number of relocations which have no practical purpose.
*) Well IGT tests might get upset but they can be easily adjusted.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202405151008.6ddd1aaf-oliver.sang@intel.com
Cc: Kees Cook <keescook@chromium.org>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20240521101201.18978-1-tursulin@igalia.com
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
index 090724fa766c..8aff06933f54 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -1533,7 +1533,7 @@ static int eb_relocate_vma(struct i915_execbuffer *eb, struct eb_vma *ev)
u64_to_user_ptr(entry->relocs_ptr);
unsigned long remain = entry->relocation_count;
- if (unlikely(remain > N_RELOC(ULONG_MAX)))
+ if (unlikely(remain > N_RELOC(INT_MAX)))
return -EINVAL;
/*
@@ -1641,7 +1641,7 @@ static int check_relocations(const struct drm_i915_gem_exec_object2 *entry)
if (size == 0)
return 0;
- if (size > N_RELOC(ULONG_MAX))
+ if (size > N_RELOC(INT_MAX))
return -EINVAL;
addr = u64_to_user_ptr(entry->relocs_ptr);
]
|
| 155/4 |
2026/10/13 22:54 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 31772
output: 44
thoughts: 1473
Thoughts: **Deep Dive into drm_lease.c: A Type Mismatch Conundrum**
Alright, this is quite clear, and it's time to dig into `drm_lease.c` with a fine-tooth comb. I'm focusing on the `drm_mode_create_lease_ioctl` function and its interactions, specifically, `fill_object_idr`.
I'm immediately looking at how `object_count` is handled. It starts as a `size_t` variable within `drm_mode_create_lease_ioctl`, but then it's assigned the value of `cl->object_count`, which is a `__u32`. This raises a red flag. The crucial part is how `object_count` is then passed to `fill_object_idr`.
Initially, `fill_object_idr` takes an `int object_count`. This is where it gets interesting. I'm questioning the rationale behind this type change. If `object_count` is `__u32` which might be passed in `int object_count`, there might be an overflow, so let's check.
I'm thinking, if `object_count` is a `__u32`, the code could handle values up to the maximum value of a 32-bit unsigned integer. I'm calculating the potential maximum: the maximum size would be roughly 2GB divided by the size of a pointer (`sizeof(struct drm_mode_object *)`). However, a 32-bit `int` (`INT_MAX`) can handle at most `2,147,483,647`.
I'm getting curious: Why isn't there a check to ensure that `object_count` doesn't exceed `INT_MAX / sizeof(struct drm_mode_object *)` or maybe `INT_MAX / sizeof(void *)`? This seems like a potential vulnerability if `object_count` is large enough. If `object_count` is too large, the function might return `-EINVAL`. This also makes me think about how `object_ids` might be allocated using `vmemdup_array_user`.
I need to confirm the sizes for `object_ids`: `sizeof(__u32)` which is 4 and `sizeof(struct drm_mode_object *)`, is 8 on 64-bit systems and 4 on 32-bit systems. We are safe because we check for this.
I'm further analyzing the code and its use in `validate_lease`. The same `object_count` is passed to `validate_lease`, which takes `int object_count`. However, `object_count` will always fit within a positive `int` if it's bounded by `INT_MAX / sizeof(struct drm_mode_object *)`.
This raises a broader question: Why use `int` when the `object_count` can clearly be `size_t` throughout? Let's check `fill_object_idr`:
```c
static int fill_object_idr(struct drm_device *dev,
struct drm_file *lessor_priv,
struct idr *leases,
size_t object_count,
u32 *object_ids)
```
Interestingly, I find the usage of `size_t` in `fill_object_idr`. But I'm going to look deeper. There should not be a change to the function signature without a good reason. I'll need to check the git blame to understand the history of this part of the code and the reasoning behind these design choices.
|
| 156/4 |
2026/10/13 22:54 |
tool |
git-blame |
0m
Args: map[End:525 File:drivers/gpu/drm/drm_lease.c LineCount:<nil> Start:505]
Results: map[Output:56f0729a510f9 505) }
56f0729a510f9 506)
62884cd386b87 507) object_count = cl->object_count;
62884cd386b87 508)
4bb2d367a5a28 509) /* Handle leased objects, if any */
62884cd386b87 510) idr_init(&leases);
4bb2d367a5a28 511) if (object_count != 0) {
f37d63e219c39 512) object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
f37d63e219c39 513) object_count, sizeof(__u32));
4bb2d367a5a28 514) if (IS_ERR(object_ids)) {
4bb2d367a5a28 515) ret = PTR_ERR(object_ids);
4bb2d367a5a28 516) idr_destroy(&leases);
4bb2d367a5a28 517) goto out_lessor;
4bb2d367a5a28 518) }
62884cd386b87 519)
4bb2d367a5a28 520) /* fill and validate the object idr */
4bb2d367a5a28 521) ret = fill_object_idr(dev, lessor_priv, &leases,
4bb2d367a5a28 522) object_count, object_ids);
4bb2d367a5a28 523) kfree(object_ids);
4bb2d367a5a28 524) if (ret) {
7bd224b6625ab 525) drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
]
|
| 157/4 |
2026/10/13 22:54 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 34689
output: 28
thoughts: 35
Thoughts: Okay, here's my interpretation of those commits, presented as a personal thought process, as requested:
**Analyzing Commits f37d63e219c39 and 62884cd386b87**
Alright, let's dive into these commits. First, I want to take a look at `f37d63e219c39`. Based on the context and the commit message (which I'd obviously need to see to be *truly* insightful!), I'm expecting something in the realm of [**Insert relevant technical area related to their expertise, e.g., "algorithm optimization," "database schema migration," "frontend UI refactoring" etc. Here**]. I'll need to pay close attention to the code diffs, specifically the lines added and deleted, the specific files modified, and any associated unit tests that were affected. I'll be looking for potential side effects, performance implications, and adherence to established coding standards. Depending on the size of the diff, I might need to run a quick local build and test cycle just to get a feel for the changes and the committers' motivations for them.
Now, let's pivot to `62884cd386b87`. Given its position in the commit history or if it's referenced after the first commit (again, I'd need more context), this one probably builds on or relates to the first. Perhaps it's a follow-up fix, a refactoring based on feedback from a review of the prior commit, or maybe it addresses a previously identified edge case or performance bottleneck. I'll be examining the changes with an eye towards understanding their relationship with the first. Are they complementary? Do they introduce any conflicts? Do they address the same problem in an alternative way? I would assess the quality of the changes and see whether or not they follow best practices and contribute to the overall project's stability. I would look at its associated commit message and, if necessary, compare and contrast it with commit `f37d63e219c39`. Ultimately, I will determine if these commits represent a cohesive, well-reasoned set of changes or if further investigation is warranted.
|
| 158/4 |
2026/10/13 22:54 |
tool |
git-show |
0m
Args: map[Commit:f37d63e219c39]
Results: map[Output:commit f37d63e219c39199a59b8b8a211412ff27192830
Author: Philipp Stanner <pstanner@redhat.com>
Date: Wed Sep 20 14:36:12 2023 +0200
drm_lease.c: copy user-array safely
Currently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for
duplicating the user-space array safely.
Suggested-by: David Airlie <airlied@redhat.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230920123612.16914-6-pstanner@redhat.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 150fe1555068..94375c6a5425 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -510,8 +510,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
- array_size(object_count, sizeof(__u32)));
+ object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
]
|
| 159/4 |
2026/10/13 22:54 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 35822
output: 27
thoughts: 89
Thoughts: Okay, here's my analysis of these commits, presented as a personal thought process:
**Diving into Memory Duplication Safety**
Alright, let's see... commit `f37d63e219c39` on `drm_lease.c` caught my eye. They've opted for `memdup_array_user` instead of just plain `memdup_user()`. Interesting. That immediately suggests a focus on more robust user-space memory handling, likely to avoid potential buffer overflows or other vulnerabilities when copying data from user space. The use of `_array` implies that they're dealing with an array-like structure from user space, which adds a layer of complexity that needs careful management to prevent security issues. The `_array` suffix signals that the size of the memory being duplicated is derived from user space, and must be validated.
Now, let's shift gears and look at commit `62884cd386b87`. I need to understand if this commit follows similar principles, or perhaps addresses a different aspect of memory safety. A quick peek at the commit message won't be enough. Let's fire up `git show 62884cd386b87` and see what it's all about. I'm especially interested to see if it deals with user-space data copying or handling, and if it references any similar memory duplication techniques. I'm anticipating that I will be looking for similarities and differences between the two, or perhaps checking if there are relationships between them. This will allow me to create a mental picture about the project's overall approach to memory security.
|
| 160/4 |
2026/10/13 22:54 |
tool |
git-show |
0m
Args: map[Commit:62884cd386b87]
Results: map[Output:commit 62884cd386b876638720ef88374b31a84ca7ee5f
Author: Keith Packard <keithp@keithp.com>
Date: Thu Mar 16 17:56:28 2017 -0700
drm: Add four ioctls for managing drm mode object leases [v7]
drm_mode_create_lease
Creates a lease for a list of drm mode objects, returning an
fd for the new drm_master and a 64-bit identifier for the lessee
drm_mode_list_lesees
List the identifiers of the lessees for a master file
drm_mode_get_lease
List the leased objects for a master file
drm_mode_revoke_lease
Erase the set of objects managed by a lease.
This should suffice to at least create and query leases.
Changes for v2 as suggested by Daniel Vetter <daniel.vetter@ffwll.ch>:
* query ioctls only query the master associated with
the provided file.
* 'mask_lease' value has been removed
* change ioctl has been removed.
Changes for v3 suggested in part by Dave Airlie <airlied@gmail.com>
* Add revoke ioctl.
Changes for v4 suggested by Dave Airlie <airlied@gmail.com>
* Expand on the comment about the magic use of &drm_lease_idr_object
* Pad lease ioctl structures to align on 64-bit boundaries
Changes for v5 suggested by Dave Airlie <airlied@gmail.com>
* Check for non-negative object_id in create_lease to avoid debug
output from the kernel.
Changes for v6 provided by Dave Airlie <airlied@gmail.com>
* For non-universal planes add primary/cursor planes to lease
If we aren't exposing universal planes to this userspace client,
and it requests a lease on a crtc, we should implicitly export the
primary and cursor planes for the crtc.
If the lessee doesn't request universal planes, it will just see
the crtc, but if it does request them it will then see the plane
objects as well.
This also moves the object look ups earlier as a side effect, so
we'd exit the ioctl quicker for non-existant objects.
* Restrict leases to crtc/connector/planes.
This only allows leasing for objects we wish to allow.
Changes for v7 provided by Dave Airlie <airlied@gmail.com>
* Check pad args are 0
* Check create flags and object count are valid.
* Check return from fd allocation
* Refactor lease idr setup and add some simple validation
* Use idr_mutex uniformly (Keith)
Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
index 9c435a4c0c82..4aafe4802099 100644
--- a/drivers/gpu/drm/drm_ioctl.c
+++ b/drivers/gpu/drm/drm_ioctl.c
@@ -665,6 +665,10 @@ static const struct drm_ioctl_desc drm_ioctls[] = {
DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, DRM_UNLOCKED),
DRM_IOCTL_DEF(DRM_IOCTL_CRTC_QUEUE_SEQUENCE, drm_crtc_queue_sequence_ioctl, DRM_UNLOCKED),
+ DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+ DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
+ DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED),
};
#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 030db1170570..d1eb56a1eff4 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -23,6 +23,8 @@
#define drm_for_each_lessee(lessee, lessor) \
list_for_each_entry((lessee), &(lessor)->lessees, lessee_list)
+static uint64_t drm_lease_idr_object;
+
/**
* drm_lease_owner - return ancestor owner drm_master
* @master: drm_master somewhere within tree of lessees and lessors
@@ -353,3 +355,413 @@ void drm_lease_revoke(struct drm_master *top)
_drm_lease_revoke(top);
mutex_unlock(&top->dev->mode_config.idr_mutex);
}
+
+static int validate_lease(struct drm_device *dev,
+ struct drm_file *lessor_priv,
+ int object_count,
+ struct drm_mode_object **objects)
+{
+ int o;
+ int has_crtc = -1;
+ int has_connector = -1;
+ int has_plane = -1;
+
+ /* we want to confirm that there is at least one crtc, plane
+ connector object. */
+
+ for (o = 0; o < object_count; o++) {
+ if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
+ has_crtc = o;
+ }
+ if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
+ has_connector = o;
+
+ if (lessor_priv->universal_planes) {
+ if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
+ has_plane = o;
+ }
+ }
+ if (has_crtc == -1 || has_connector == -1)
+ return -EINVAL;
+ if (lessor_priv->universal_planes && has_plane == -1)
+ return -EINVAL;
+ return 0;
+}
+
+static int fill_object_idr(struct drm_device *dev,
+ struct drm_file *lessor_priv,
+ struct idr *leases,
+ int object_count,
+ u32 *object_ids)
+{
+ struct drm_mode_object **objects;
+ u32 o;
+ int ret;
+ objects = kcalloc(object_count, sizeof(struct drm_mode_object *),
+ GFP_KERNEL);
+ if (!objects)
+ return -ENOMEM;
+
+ /* step one - get references to all the mode objects
+ and check for validity. */
+ for (o = 0; o < object_count; o++) {
+ if ((int) object_ids[o] < 0) {
+ ret = -EINVAL;
+ goto out_free_objects;
+ }
+
+ objects[o] = drm_mode_object_find(dev, lessor_priv,
+ object_ids[o],
+ DRM_MODE_OBJECT_ANY);
+ if (!objects[o]) {
+ ret = -ENOENT;
+ goto out_free_objects;
+ }
+
+ if (!drm_mode_object_lease_required(objects[o]->type)) {
+ ret = -EINVAL;
+ goto out_free_objects;
+ }
+ }
+
+ ret = validate_lease(dev, lessor_priv, object_count, objects);
+ if (ret)
+ goto out_free_objects;
+
+ /* add their IDs to the lease request - taking into account
+ universal planes */
+ for (o = 0; o < object_count; o++) {
+ struct drm_mode_object *obj = objects[o];
+ u32 object_id = objects[o]->id;
+ DRM_DEBUG_LEASE("Adding object %d to lease\n", object_id);
+
+ /*
+ * We're using an IDR to hold the set of leased
+ * objects, but we don't need to point at the object's
+ * data structure from the lease as the main crtc_idr
+ * will be used to actually find that. Instead, all we
+ * really want is a 'leased/not-leased' result, for
+ * which any non-NULL pointer will work fine.
+ */
+ ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
+ if (ret < 0) {
+ DRM_DEBUG_LEASE("Object %d cannot be inserted into leases (%d)\n",
+ object_id, ret);
+ goto out_free_objects;
+ }
+ if (obj->type == DRM_MODE_OBJECT_CRTC && !lessor_priv->universal_planes) {
+ struct drm_crtc *crtc = obj_to_crtc(obj);
+ ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
+ if (ret < 0) {
+ DRM_DEBUG_LEASE("Object primary plane %d cannot be inserted into leases (%d)\n",
+ object_id, ret);
+ goto out_free_objects;
+ }
+ if (crtc->cursor) {
+ ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
+ if (ret < 0) {
+ DRM_DEBUG_LEASE("Object cursor plane %d cannot be inserted into leases (%d)\n",
+ object_id, ret);
+ goto out_free_objects;
+ }
+ }
+ }
+ }
+
+ ret = 0;
+out_free_objects:
+ for (o = 0; o < object_count; o++) {
+ if (objects[o])
+ drm_mode_object_put(objects[o]);
+ }
+ kfree(objects);
+ return ret;
+}
+
+/**
+ * drm_mode_create_lease_ioctl - create a new lease
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_create_lease
+ * @file_priv: the file being manipulated
+ *
+ * The master associated with the specified file will have a lease
+ * created containing the objects specified in the ioctl structure.
+ * A file descriptor will be allocated for that and returned to the
+ * application.
+ */
+int drm_mode_create_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessor_priv)
+{
+ struct drm_mode_create_lease *cl = data;
+ size_t object_count;
+ int ret = 0;
+ struct idr leases;
+ struct drm_master *lessor = lessor_priv->master;
+ struct drm_master *lessee = NULL;
+ struct file *lessee_file = NULL;
+ struct file *lessor_file = lessor_priv->filp;
+ struct drm_file *lessee_priv;
+ int fd = -1;
+ uint32_t *object_ids;
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ /* Do not allow sub-leases */
+ if (lessor->lessor)
+ return -EINVAL;
+
+ /* need some objects */
+ if (cl->object_count == 0)
+ return -EINVAL;
+
+ if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK)))
+ return -EINVAL;
+
+ object_count = cl->object_count;
+
+ object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), object_count * sizeof(__u32));
+ if (IS_ERR(object_ids))
+ return PTR_ERR(object_ids);
+
+ idr_init(&leases);
+
+ /* fill and validate the object idr */
+ ret = fill_object_idr(dev, lessor_priv, &leases,
+ object_count, object_ids);
+ kfree(object_ids);
+ if (ret) {
+ idr_destroy(&leases);
+ return ret;
+ }
+
+ /* Allocate a file descriptor for the lease */
+ fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
+ if (fd < 0) {
+ idr_destroy(&leases);
+ return fd;
+ }
+
+ DRM_DEBUG_LEASE("Creating lease\n");
+ lessee = drm_lease_create(lessor, &leases);
+
+ if (IS_ERR(lessee)) {
+ ret = PTR_ERR(lessee);
+ goto out_leases;
+ }
+
+ /* Clone the lessor file to create a new file for us */
+ DRM_DEBUG_LEASE("Allocating lease file\n");
+ path_get(&lessor_file->f_path);
+ lessee_file = alloc_file(&lessor_file->f_path,
+ lessor_file->f_mode,
+ fops_get(lessor_file->f_inode->i_fop));
+
+ if (IS_ERR(lessee_file)) {
+ ret = PTR_ERR(lessee_file);
+ goto out_lessee;
+ }
+
+ /* Initialize the new file for DRM */
+ DRM_DEBUG_LEASE("Initializing the file with %p\n", lessee_file->f_op->open);
+ ret = lessee_file->f_op->open(lessee_file->f_inode, lessee_file);
+ if (ret)
+ goto out_lessee_file;
+
+ lessee_priv = lessee_file->private_data;
+
+ /* Change the file to a master one */
+ drm_master_put(&lessee_priv->master);
+ lessee_priv->master = lessee;
+ lessee_priv->is_master = 1;
+ lessee_priv->authenticated = 1;
+
+ /* Hook up the fd */
+ fd_install(fd, lessee_file);
+
+ /* Pass fd back to userspace */
+ DRM_DEBUG_LEASE("Returning fd %d id %d\n", fd, lessee->lessee_id);
+ cl->fd = fd;
+ cl->lessee_id = lessee->lessee_id;
+
+ DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl succeeded\n");
+ return 0;
+
+out_lessee_file:
+ fput(lessee_file);
+
+out_lessee:
+ drm_master_put(&lessee);
+
+out_leases:
+ put_unused_fd(fd);
+ idr_destroy(&leases);
+
+ DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl failed: %d\n", ret);
+ return ret;
+}
+
+/**
+ * drm_mode_list_lessees_ioctl - list lessee ids
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_list_lessees
+ * @lessor_priv: the file being manipulated
+ *
+ * Starting from the master associated with the specified file,
+ * the master with the provided lessee_id is found, and then
+ * an array of lessee ids associated with leases from that master
+ * are returned.
+ */
+
+int drm_mode_list_lessees_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessor_priv)
+{
+ struct drm_mode_list_lessees *arg = data;
+ __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr);
+ __u32 count_lessees = arg->count_lessees;
+ struct drm_master *lessor = lessor_priv->master, *lessee;
+ int count;
+ int ret = 0;
+
+ if (arg->pad)
+ return -EINVAL;
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ DRM_DEBUG_LEASE("List lessees for %d\n", lessor->lessee_id);
+
+ mutex_lock(&dev->mode_config.idr_mutex);
+
+ count = 0;
+ drm_for_each_lessee(lessee, lessor) {
+ /* Only list un-revoked leases */
+ if (!idr_is_empty(&lessee->leases)) {
+ if (count_lessees > count) {
+ DRM_DEBUG_LEASE("Add lessee %d\n", lessee->lessee_id);
+ ret = put_user(lessee->lessee_id, lessee_ids + count);
+ if (ret)
+ break;
+ }
+ count++;
+ }
+ }
+
+ DRM_DEBUG_LEASE("Lessor leases to %d\n", count);
+ if (ret == 0)
+ arg->count_lessees = count;
+
+ mutex_unlock(&dev->mode_config.idr_mutex);
+
+ return ret;
+}
+
+/**
+ * drm_mode_get_lease_ioctl - list leased objects
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_get_lease
+ * @file_priv: the file being manipulated
+ *
+ * Return the list of leased objects for the specified lessee
+ */
+
+int drm_mode_get_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessee_priv)
+{
+ struct drm_mode_get_lease *arg = data;
+ __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr);
+ __u32 count_objects = arg->count_objects;
+ struct drm_master *lessee = lessee_priv->master;
+ struct idr *object_idr;
+ int count;
+ void *entry;
+ int object;
+ int ret = 0;
+
+ if (arg->pad)
+ return -EINVAL;
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ DRM_DEBUG_LEASE("get lease for %d\n", lessee->lessee_id);
+
+ mutex_lock(&dev->mode_config.idr_mutex);
+
+ if (lessee->lessor == NULL)
+ /* owner can use all objects */
+ object_idr = &lessee->dev->mode_config.crtc_idr;
+ else
+ /* lessee can only use allowed object */
+ object_idr = &lessee->leases;
+
+ count = 0;
+ idr_for_each_entry(object_idr, entry, object) {
+ if (count_objects > count) {
+ DRM_DEBUG_LEASE("adding object %d\n", object);
+ ret = put_user(object, object_ids + count);
+ if (ret)
+ break;
+ }
+ count++;
+ }
+
+ DRM_DEBUG("lease holds %d objects\n", count);
+ if (ret == 0)
+ arg->count_objects = count;
+
+ mutex_unlock(&dev->mode_config.idr_mutex);
+
+ return ret;
+}
+
+/**
+ * drm_mode_revoke_lease_ioctl - revoke lease
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_revoke_lease
+ * @file_priv: the file being manipulated
+ *
+ * This removes all of the objects from the lease without
+ * actually getting rid of the lease itself; that way all
+ * references to it still work correctly
+ */
+int drm_mode_revoke_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessor_priv)
+{
+ struct drm_mode_revoke_lease *arg = data;
+ struct drm_master *lessor = lessor_priv->master;
+ struct drm_master *lessee;
+ int ret = 0;
+
+ DRM_DEBUG_LEASE("revoke lease for %d\n", arg->lessee_id);
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ mutex_lock(&dev->mode_config.idr_mutex);
+
+ lessee = _drm_find_lessee(lessor, arg->lessee_id);
+
+ /* No such lessee */
+ if (!lessee) {
+ ret = -ENOENT;
+ goto fail;
+ }
+
+ /* Lease is not held by lessor */
+ if (lessee->lessor != lessor) {
+ ret = -EACCES;
+ goto fail;
+ }
+
+ _drm_lease_revoke(lessee);
+
+fail:
+ mutex_unlock(&dev->mode_config.idr_mutex);
+
+ return ret;
+}
diff --git a/drivers/gpu/drm/drm_mode_object.c b/drivers/gpu/drm/drm_mode_object.c
index d1599f36b605..7c8b2698c6a7 100644
--- a/drivers/gpu/drm/drm_mode_object.c
+++ b/drivers/gpu/drm/drm_mode_object.c
@@ -111,7 +111,7 @@ void drm_mode_object_unregister(struct drm_device *dev,
* Returns whether the provided type of drm_mode_object must
* be owned or leased to be used by a process.
*/
-static bool drm_lease_required(uint32_t type)
+bool drm_mode_object_lease_required(uint32_t type)
{
switch(type) {
case DRM_MODE_OBJECT_CRTC:
@@ -136,7 +136,8 @@ struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,
if (obj && obj->id != id)
obj = NULL;
- if (obj && drm_lease_required(obj->type) && !_drm_lease_held(file_priv, obj->id))
+ if (obj && drm_mode_object_lease_required(obj->type) &&
+ !_drm_lease_held(file_priv, obj->id))
obj = NULL;
if (obj && obj->free_cb) {
diff --git a/include/drm/drm_lease.h b/include/drm/drm_lease.h
index 6149e56ddbf3..fbc0ab54855b 100644
--- a/include/drm/drm_lease.h
+++ b/include/drm/drm_lease.h
@@ -31,4 +31,16 @@ void drm_lease_revoke(struct drm_master *master);
uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs);
+int drm_mode_create_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *file_priv);
+
+int drm_mode_list_lessees_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *file_priv);
+
+int drm_mode_get_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *file_priv);
+
+int drm_mode_revoke_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *file_priv);
+
#endif /* _DRM_LEASE_H_ */
diff --git a/include/drm/drm_mode_object.h b/include/drm/drm_mode_object.h
index c8155cb5a932..7ba3913f30b5 100644
--- a/include/drm/drm_mode_object.h
+++ b/include/drm/drm_mode_object.h
@@ -154,4 +154,6 @@ int drm_object_property_get_value(struct drm_mode_object *obj,
void drm_object_attach_property(struct drm_mode_object *obj,
struct drm_property *property,
uint64_t init_val);
+
+bool drm_mode_object_lease_required(uint32_t type);
#endif
diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h
index 91d83c1747c0..6fdff5945c8a 100644
--- a/include/uapi/drm/drm.h
+++ b/include/uapi/drm/drm.h
@@ -888,6 +888,11 @@ extern "C" {
#define DRM_IOCTL_SYNCOBJ_RESET DRM_IOWR(0xC4, struct drm_syncobj_array)
#define DRM_IOCTL_SYNCOBJ_SIGNAL DRM_IOWR(0xC5, struct drm_syncobj_array)
+#define DRM_IOCTL_MODE_CREATE_LEASE DRM_IOWR(0xC6, struct drm_mode_create_lease)
+#define DRM_IOCTL_MODE_LIST_LESSEES DRM_IOWR(0xC7, struct drm_mode_list_lessees)
+#define DRM_IOCTL_MODE_GET_LEASE DRM_IOWR(0xC8, struct drm_mode_get_lease)
+#define DRM_IOCTL_MODE_REVOKE_LEASE DRM_IOWR(0xC9, struct drm_mode_revoke_lease)
+
/**
* Device specific ioctls should only be in their respective headers
* The device specific ioctl range is from 0x40 to 0x9f.
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index 34b6bb34b002..5597a87154e5 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -782,6 +782,72 @@ struct drm_mode_destroy_blob {
__u32 blob_id;
};
+/**
+ * Lease mode resources, creating another drm_master.
+ */
+struct drm_mode_create_lease {
+ /** Pointer to array of object ids (__u32) */
+ __u64 object_ids;
+ /** Number of object ids */
+ __u32 object_count;
+ /** flags for new FD (O_CLOEXEC, etc) */
+ __u32 flags;
+
+ /** Return: unique identifier for lessee. */
+ __u32 lessee_id;
+ /** Return: file descriptor to new drm_master file */
+ __u32 fd;
+};
+
+/**
+ * List lesses from a drm_master
+ */
+struct drm_mode_list_lessees {
+ /** Number of lessees.
+ * On input, provides length of the array.
+ * On output, provides total number. No
+ * more than the input number will be written
+ * back, so two calls can be used to get
+ * the size and then the data.
+ */
+ __u32 count_lessees;
+ __u32 pad;
+
+ /** Pointer to lessees.
+ * pointer to __u64 array of lessee ids
+ */
+ __u64 lessees_ptr;
+};
+
+/**
+ * Get leased objects
+ */
+struct drm_mode_get_lease {
+ /** Number of leased objects.
+ * On input, provides length of the array.
+ * On output, provides total number. No
+ * more than the input number will be written
+ * back, so two calls can be used to get
+ * the size and then the data.
+ */
+ __u32 count_objects;
+ __u32 pad;
+
+ /** Pointer to objects.
+ * pointer to __u32 array of object ids
+ */
+ __u64 objects_ptr;
+};
+
+/**
+ * Revoke lease
+ */
+struct drm_mode_revoke_lease {
+ /** Unique ID of lessee
+ */
+ __u32 lessee_id;
+};
+
#if defined(__cplusplus)
}
#endif
]
|
| 161/4 |
2026/10/13 22:54 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 44130
output: 39
thoughts: 227
Thoughts: **Analyzing the Evolution of `object_count` Usage**
Okay, let's trace the history of how `object_count` has been used. My initial thought process is to understand the context and evolution of a specific line of code. I'm seeing changes related to memory allocation, specifically the `object_count` variable. Initially, I observe that commit `62884cd386b87` used `kcalloc` and `memdup_user` in relation to `object_count`. After that commit, commit `f37d63e219c39` altered `memdup_user` to the `memdup_array_user` variant. Now, I see a newer modification where `kcalloc` has been swapped out for `kzalloc_objs`, which piques my interest. It is important to know why this modification was made. To delve further, my next step is to use `git blame` on line 389 of `drivers/gpu/drm/drm_lease.c`. This will give me information about who modified the code, when, and with what commit. With this information, I can understand the context and rationale for the change and its potential impact on the overall code.
|
| 162/4 |
2026/10/13 22:55 |
tool |
git-blame |
0m
Args: map[End:392 File:drivers/gpu/drm/drm_lease.c Start:388]
Results: map[Output:968029057192e 388)
32a92f8c89326 389) objects = kzalloc_objs(struct drm_mode_object *, object_count);
62884cd386b87 390) if (!objects)
62884cd386b87 391) return -ENOMEM;
62884cd386b87 392)
]
|
| 163/4 |
2026/10/13 22:55 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 44804
output: 28
thoughts: 20
Thoughts: Okay, here's my interpretation of what's going through my mind when I encounter that prompt, rendered in the first person:
**Analyzing the Commit Context**
Alright, show me commit `32a92f8c89326`. That commit hash is a good starting point. I need to understand what changed there. My initial thought process is geared towards efficient context switching. What was the context of the work? What was the problem being solved or the feature being implemented? Is this something I'm already familiar with, or is it a completely new area for me? My immediate goal is to establish a mental model of the changes and their potential implications within the existing codebase. I will quickly scan the commit diff, focusing on file paths, function signatures, and any comments that might offer quick insights. I'm looking for clues about the scope and purpose of the changes. I'll need to assess the magnitude of the modification. Was it an isolated fix, a refactor, or a substantial feature implementation? The answers to those questions will dictate how deep I need to dive into the associated codebase for an effective analysis.
|
| 164/4 |
2026/10/13 22:55 |
tool |
git-show |
0m
Args: map[Commit:32a92f8c89326]
Results: map[Output:commit 32a92f8c89326985e05dce8b22d3f0aa07a3e1bd
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat Feb 21 20:03:00 2026 -0800
Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
This converts some of the visually simpler cases that have been split
over multiple lines. I only did the ones that are easy to verify the
resulting diff by having just that final GFP_KERNEL argument on the next
line.
Somebody should probably do a proper coccinelle script for this, but for
me the trivial script actually resulted in an assertion failure in the
middle of the script. I probably had made it a bit _too_ trivial.
So after fighting that far a while I decided to just do some of the
syntactically simpler cases with variations of the previous 'sed'
scripts.
The more syntactically complex multi-line cases would mostly really want
whitespace cleanup anyway.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/arch/arm/mach-omap1/mcbsp.c b/arch/arm/mach-omap1/mcbsp.c
index a4dae1baae99..b6cce510c343 100644
--- a/arch/arm/mach-omap1/mcbsp.c
+++ b/arch/arm/mach-omap1/mcbsp.c
@@ -294,8 +294,7 @@ static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
{
int i;
- omap_mcbsp_devices = kzalloc_objs(struct platform_device *, size,
- GFP_KERNEL);
+ omap_mcbsp_devices = kzalloc_objs(struct platform_device *, size);
if (!omap_mcbsp_devices) {
printk(KERN_ERR "Could not register McBSP devices\n");
return;
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 34d761ef08b0..592dd8668de4 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -81,8 +81,7 @@ static int __init __vdso_init(enum vdso_abi abi)
vdso_info[abi].vdso_code_start) >>
PAGE_SHIFT;
- vdso_pagelist = kzalloc_objs(struct page *, vdso_info[abi].vdso_pages,
- GFP_KERNEL);
+ vdso_pagelist = kzalloc_objs(struct page *, vdso_info[abi].vdso_pages);
if (vdso_pagelist == NULL)
return -ENOMEM;
diff --git a/arch/loongarch/kernel/vdso.c b/arch/loongarch/kernel/vdso.c
index 222be8fc4aec..0aa10cadb959 100644
--- a/arch/loongarch/kernel/vdso.c
+++ b/arch/loongarch/kernel/vdso.c
@@ -52,8 +52,7 @@ static int __init init_vdso(void)
vdso_info.size = PAGE_ALIGN(vdso_end - vdso_start);
vdso_info.code_mapping.pages =
- kzalloc_objs(struct page *, vdso_info.size / PAGE_SIZE,
- GFP_KERNEL);
+ kzalloc_objs(struct page *, vdso_info.size / PAGE_SIZE);
if (!vdso_info.code_mapping.pages)
return -ENOMEM;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index b7fdb089f2af..2ba2dd26a7ea 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1738,8 +1738,7 @@ static int kvmppc_core_vcpu_create_pr(struct kvm_vcpu *vcpu)
vcpu->arch.book3s = vcpu_book3s;
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
- vcpu->arch.shadow_vcpu = kzalloc_obj(*vcpu->arch.shadow_vcpu,
- GFP_KERNEL);
+ vcpu->arch.shadow_vcpu = kzalloc_obj(*vcpu->arch.shadow_vcpu);
if (!vcpu->arch.shadow_vcpu)
goto free_vcpu3s;
#endif
diff --git a/arch/powerpc/mm/book3s64/mmu_context.c b/arch/powerpc/mm/book3s64/mmu_context.c
index c7302dd2ef25..2fe787e6c2dc 100644
--- a/arch/powerpc/mm/book3s64/mmu_context.c
+++ b/arch/powerpc/mm/book3s64/mmu_context.c
@@ -96,8 +96,7 @@ static int hash__init_new_context(struct mm_struct *mm)
{
int index;
- mm->context.hash_context = kmalloc_obj(struct hash_mm_context,
- GFP_KERNEL);
+ mm->context.hash_context = kmalloc_obj(struct hash_mm_context);
if (!mm->context.hash_context)
return -ENOMEM;
@@ -124,8 +123,7 @@ static int hash__init_new_context(struct mm_struct *mm)
#ifdef CONFIG_PPC_SUBPAGE_PROT
/* inherit subpage prot details if we have one. */
if (current->mm->context.hash_context->spt) {
- mm->context.hash_context->spt = kmalloc_obj(struct subpage_prot_table,
- GFP_KERNEL);
+ mm->context.hash_context->spt = kmalloc_obj(struct subpage_prot_table);
if (!mm->context.hash_context->spt) {
kfree(mm->context.hash_context);
return -ENOMEM;
diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index 8a8d8c2b8930..243c0a1c8cda 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -917,8 +917,7 @@ static int create_events_from_catalog(struct attribute ***events_,
goto e_event_attrs;
}
- event_long_descs = kmalloc_objs(*event_long_descs, event_idx + 1,
- GFP_KERNEL);
+ event_long_descs = kmalloc_objs(*event_long_descs, event_idx + 1);
if (!event_long_descs) {
ret = -ENOMEM;
goto e_event_descs;
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index e3cb23906fcd..db98e9af8812 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -1527,8 +1527,7 @@ static int init_nest_pmu_ref(void)
{
int nid, i, cpu;
- nest_imc_refc = kzalloc_objs(*nest_imc_refc, num_possible_nodes(),
- GFP_KERNEL);
+ nest_imc_refc = kzalloc_objs(*nest_imc_refc, num_possible_nodes());
if (!nest_imc_refc)
return -ENOMEM;
@@ -1714,14 +1713,12 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
goto err;
nr_cores = DIV_ROUND_UP(num_possible_cpus(), threads_per_core);
- pmu_ptr->mem_info = kzalloc_objs(struct imc_mem_info, nr_cores,
- GFP_KERNEL);
+ pmu_ptr->mem_info = kzalloc_objs(struct imc_mem_info, nr_cores);
if (!pmu_ptr->mem_info)
goto err;
- core_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores,
- GFP_KERNEL);
+ core_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores);
if (!core_imc_refc) {
kfree(pmu_ptr->mem_info);
@@ -1754,8 +1751,7 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
return -ENOMEM;
nr_cores = DIV_ROUND_UP(num_possible_cpus(), threads_per_core);
- trace_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores,
- GFP_KERNEL);
+ trace_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores);
if (!trace_imc_refc)
return -ENOMEM;
diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
index 1389a3131993..6cd461f82968 100644
--- a/arch/powerpc/platforms/powernv/idle.c
+++ b/arch/powerpc/platforms/powernv/idle.c
@@ -1336,8 +1336,7 @@ static int __init pnv_parse_cpuidle_dt(void)
nr_idle_states = of_property_count_u32_elems(np,
"ibm,cpu-idle-state-flags");
- pnv_idle_states = kzalloc_objs(*pnv_idle_states, nr_idle_states,
- GFP_KERNEL);
+ pnv_idle_states = kzalloc_objs(*pnv_idle_states, nr_idle_states);
temp_u32 = kcalloc(nr_idle_states, sizeof(u32), GFP_KERNEL);
temp_u64 = kcalloc(nr_idle_states, sizeof(u64), GFP_KERNEL);
temp_string = kcalloc(nr_idle_states, sizeof(char *), GFP_KERNEL);
diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c
index 5214e2d43e78..6aa578e6348d 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -133,8 +133,7 @@ static int memtrace_init_regions_runtime(u64 size)
u32 nid;
u64 m;
- memtrace_array = kzalloc_objs(struct memtrace_entry, num_online_nodes(),
- GFP_KERNEL);
+ memtrace_array = kzalloc_objs(struct memtrace_entry, num_online_nodes());
if (!memtrace_array) {
pr_err("Failed to allocate memtrace_array\n");
return -EINVAL;
diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index ed2842bea1cb..b3fd5c648dea 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -108,8 +108,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,
nr_chips))
goto error;
- pmu_ptr->mem_info = kzalloc_objs(*pmu_ptr->mem_info, nr_chips + 1,
- GFP_KERNEL);
+ pmu_ptr->mem_info = kzalloc_objs(*pmu_ptr->mem_info, nr_chips + 1);
if (!pmu_ptr->mem_info)
goto error;
diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
index 0e297d70647f..9bb73cb42a65 100644
--- a/arch/powerpc/platforms/powernv/opal-powercap.c
+++ b/arch/powerpc/platforms/powernv/opal-powercap.c
@@ -181,13 +181,11 @@ void __init opal_powercap_init(void)
has_cur = true;
}
- pcaps[i].pattrs = kzalloc_objs(struct powercap_attr, j,
- GFP_KERNEL);
+ pcaps[i].pattrs = kzalloc_objs(struct powercap_attr, j);
if (!pcaps[i].pattrs)
goto out_pcaps_pattrs;
- pcaps[i].pg.attrs = kzalloc_objs(struct attribute *, j + 1,
- GFP_KERNEL);
+ pcaps[i].pg.attrs = kzalloc_objs(struct attribute *, j + 1);
if (!pcaps[i].pg.attrs) {
kfree(pcaps[i].pattrs);
goto out_pcaps_pattrs;
diff --git a/arch/powerpc/platforms/powernv/opal-psr.c b/arch/powerpc/platforms/powernv/opal-psr.c
index 731d8b355343..24d0a894d965 100644
--- a/arch/powerpc/platforms/powernv/opal-psr.c
+++ b/arch/powerpc/platforms/powernv/opal-psr.c
@@ -132,8 +132,7 @@ void __init opal_psr_init(void)
return;
}
- psr_attrs = kzalloc_objs(*psr_attrs, of_get_child_count(psr),
- GFP_KERNEL);
+ psr_attrs = kzalloc_objs(*psr_attrs, of_get_child_count(psr));
if (!psr_attrs)
goto out_put_psr;
diff --git a/arch/powerpc/platforms/powernv/opal-sensor-groups.c b/arch/powerpc/platforms/powernv/opal-sensor-groups.c
index 2a3474246908..87fd6d7769e9 100644
--- a/arch/powerpc/platforms/powernv/opal-sensor-groups.c
+++ b/arch/powerpc/platforms/powernv/opal-sensor-groups.c
@@ -190,13 +190,11 @@ void __init opal_sensor_groups_init(void)
if (!nr_attrs)
continue;
- sgs[i].sgattrs = kzalloc_objs(*sgs[i].sgattrs, nr_attrs,
- GFP_KERNEL);
+ sgs[i].sgattrs = kzalloc_objs(*sgs[i].sgattrs, nr_attrs);
if (!sgs[i].sgattrs)
goto out_sgs_sgattrs;
- sgs[i].sg.attrs = kzalloc_objs(*sgs[i].sg.attrs, nr_attrs + 1,
- GFP_KERNEL);
+ sgs[i].sg.attrs = kzalloc_objs(*sgs[i].sg.attrs, nr_attrs + 1);
if (!sgs[i].sg.attrs) {
kfree(sgs[i].sgattrs);
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index eba277134224..257886ec3f70 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1639,8 +1639,7 @@ void __init mpic_init(struct mpic *mpic)
#ifdef CONFIG_PM
/* allocate memory to save mpic state */
- mpic->save_data = kmalloc_objs(*mpic->save_data, mpic->num_sources,
- GFP_KERNEL);
+ mpic->save_data = kmalloc_objs(*mpic->save_data, mpic->num_sources);
BUG_ON(mpic->save_data == NULL);
#endif
diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c
index e9af4fa940b1..26f62ae5f671 100644
--- a/arch/powerpc/sysdev/mpic_msgr.c
+++ b/arch/powerpc/sysdev/mpic_msgr.c
@@ -188,8 +188,7 @@ static int mpic_msgr_probe(struct platform_device *dev)
dev_info(&dev->dev, "Found %d message registers\n",
mpic_msgr_count);
- mpic_msgrs = kzalloc_objs(*mpic_msgrs, mpic_msgr_count,
- GFP_KERNEL);
+ mpic_msgrs = kzalloc_objs(*mpic_msgrs, mpic_msgr_count);
if (!mpic_msgrs) {
dev_err(&dev->dev,
"No memory for message register blocks\n");
diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c
index 7e3749131c59..9c2f5e442338 100644
--- a/arch/riscv/kernel/vdso.c
+++ b/arch/riscv/kernel/vdso.c
@@ -55,8 +55,7 @@ static void __init __vdso_init(struct __vdso_info *vdso_info)
vdso_info->vdso_code_start) >>
PAGE_SHIFT;
- vdso_pagelist = kzalloc_objs(struct page *, vdso_info->vdso_pages,
- GFP_KERNEL);
+ vdso_pagelist = kzalloc_objs(struct page *, vdso_info->vdso_pages);
if (vdso_pagelist == NULL)
panic("vDSO kcalloc failed!\n");
diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index fc80495027ba..86d93e8dddae 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -126,8 +126,7 @@ int kvm_s390_pci_aen_init(u8 nisc)
return -EPERM;
mutex_lock(&aift->aift_lock);
- aift->kzdev = kzalloc_objs(struct kvm_zdev *, ZPCI_NR_DEVICES,
- GFP_KERNEL);
+ aift->kzdev = kzalloc_objs(struct kvm_zdev *, ZPCI_NR_DEVICES);
if (!aift->kzdev) {
rc = -ENOMEM;
goto unlock;
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 0ae82e529c21..2a430722cbe4 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -1073,8 +1073,7 @@ static int zpci_mem_init(void)
if (!zdev_fmb_cache)
goto error_fmb;
- zpci_iomap_start = kzalloc_objs(*zpci_iomap_start, ZPCI_IOMAP_ENTRIES,
- GFP_KERNEL);
+ zpci_iomap_start = kzalloc_objs(*zpci_iomap_start, ZPCI_IOMAP_ENTRIES);
if (!zpci_iomap_start)
goto error_iomap;
diff --git a/arch/sh/drivers/pci/pcie-sh7786.c b/arch/sh/drivers/pci/pcie-sh7786.c
index 1e67082eb3b4..cbbb94d41fd0 100644
--- a/arch/sh/drivers/pci/pcie-sh7786.c
+++ b/arch/sh/drivers/pci/pcie-sh7786.c
@@ -558,8 +558,7 @@ static int __init sh7786_pcie_init(void)
if (unlikely(nr_ports == 0))
return -ENODEV;
- sh7786_pcie_ports = kzalloc_objs(struct sh7786_pcie_port, nr_ports,
- GFP_KERNEL);
+ sh7786_pcie_ports = kzalloc_objs(struct sh7786_pcie_port, nr_ports);
if (unlikely(!sh7786_pcie_ports))
return -ENOMEM;
diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index 81f0be76f48a..371460e34484 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -297,8 +297,7 @@ static void ldom_startcpu_cpuid(unsigned int cpu, unsigned long thread_reg,
unsigned long hv_err;
int i;
- hdesc = kzalloc_flex(*hdesc, maps, num_kernel_image_mappings,
- GFP_KERNEL);
+ hdesc = kzalloc_flex(*hdesc, maps, num_kernel_image_mappings);
if (!hdesc) {
printk(KERN_ERR "ldom_startcpu_cpuid: Cannot allocate "
"hvtramp_descr.\n");
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 8d5e2d5c0bc5..ecefcffcf7b1 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -647,8 +647,7 @@ SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
}
if (!current_thread_info()->utraps) {
current_thread_info()->utraps =
- kzalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1,
- GFP_KERNEL);
+ kzalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1);
if (!current_thread_info()->utraps)
return -ENOMEM;
current_thread_info()->utraps[0] = 1;
@@ -658,8 +657,7 @@ SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
unsigned long *p = current_thread_info()->utraps;
current_thread_info()->utraps =
- kmalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1,
- GFP_KERNEL);
+ kmalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1);
if (!current_thread_info()->utraps) {
current_thread_info()->utraps = p;
return -ENOMEM;
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 5434c87542e5..2cc90055499a 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -544,11 +544,9 @@ static struct vector_queue *create_queue(
result->max_iov_frags = num_extra_frags;
for (i = 0; i < max_size; i++) {
if (vp->header_size > 0)
- iov = kmalloc_objs(struct iovec, 3 + num_extra_frags,
- GFP_KERNEL);
+ iov = kmalloc_objs(struct iovec, 3 + num_extra_frags);
else
- iov = kmalloc_objs(struct iovec, 2 + num_extra_frags,
- GFP_KERNEL);
+ iov = kmalloc_objs(struct iovec, 2 + num_extra_frags);
if (iov == NULL)
goto out_fail;
mmsg_vector->msg_hdr.msg_iov = iov;
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 069e6b788280..5ed6e0b7e715 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3753,8 +3753,7 @@ static int pmu_alloc_topology(struct intel_uncore_type *type, int topology_type)
goto err;
for (die = 0; die < uncore_max_dies(); die++) {
- topology[die] = kzalloc_objs(**topology, type->num_boxes,
- GFP_KERNEL);
+ topology[die] = kzalloc_objs(**topology, type->num_boxes);
if (!topology[die])
goto clear;
for (idx = 0; idx < type->num_boxes; idx++) {
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index e945ed623027..323adc93f2dc 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -467,8 +467,7 @@ void __init hyperv_init(void)
if (hv_isolation_type_tdx())
hv_vp_assist_page = NULL;
else
- hv_vp_assist_page = kzalloc_objs(*hv_vp_assist_page, nr_cpu_ids,
- GFP_KERNEL);
+ hv_vp_assist_page = kzalloc_objs(*hv_vp_assist_page, nr_cpu_ids);
if (!hv_vp_assist_page) {
ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED;
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 852e8ff5ebd9..5d364540673d 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -68,8 +68,7 @@ static int amd_cache_northbridges(void)
amd_northbridges.num = amd_num_nodes();
- nb = kzalloc_objs(struct amd_northbridge, amd_northbridges.num,
- GFP_KERNEL);
+ nb = kzalloc_objs(struct amd_northbridge, amd_northbridges.num);
if (!nb)
return -ENOMEM;
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 1021a4e33ac6..38b7fd2f63be 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -798,8 +798,7 @@ static bool __init sgx_page_cache_init(void)
int nid;
int i;
- sgx_numa_nodes = kmalloc_objs(*sgx_numa_nodes, num_possible_nodes(),
- GFP_KERNEL);
+ sgx_numa_nodes = kmalloc_objs(*sgx_numa_nodes, num_possible_nodes());
if (!sgx_numa_nodes)
return false;
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index c196aa0c1bd1..d2486506a808 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1991,8 +1991,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (sanity_check_entries(entries, cpuid->nent, type))
return -EINVAL;
- array.entries = kvzalloc_objs(struct kvm_cpuid_entry2, cpuid->nent,
- GFP_KERNEL);
+ array.entries = kvzalloc_objs(struct kvm_cpuid_entry2, cpuid->nent);
if (!array.entries)
return -ENOMEM;
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 8517d5fbf79c..d22cabe119b1 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -2218,8 +2218,7 @@ static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd)
if (nr_user_entries < td_conf->num_cpuid_config)
return -E2BIG;
- caps = kzalloc_flex(*caps, cpuid.entries, td_conf->num_cpuid_config,
- GFP_KERNEL);
+ caps = kzalloc_flex(*caps, cpuid.entries, td_conf->num_cpuid_config);
if (!caps)
return -ENOMEM;
diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c
index 9a05abe8d43f..24b8b1c40e25 100644
--- a/block/blk-crypto-fallback.c
+++ b/block/blk-crypto-fallback.c
@@ -546,8 +546,7 @@ static int blk_crypto_fallback_init(void)
goto out;
/* Dynamic allocation is needed because of lockdep_register_key(). */
- blk_crypto_fallback_profile = kzalloc_obj(*blk_crypto_fallback_profile,
- GFP_KERNEL);
+ blk_crypto_fallback_profile = kzalloc_obj(*blk_crypto_fallback_profile);
if (!blk_crypto_fallback_profile) {
err = -ENOMEM;
goto fail_free_bioset;
diff --git a/block/blk-crypto-profile.c b/block/blk-crypto-profile.c
index 970880d9adf4..4ac74443687a 100644
--- a/block/blk-crypto-profile.c
+++ b/block/blk-crypto-profile.c
@@ -120,8 +120,7 @@ int blk_crypto_profile_init(struct blk_crypto_profile *profile,
profile->log_slot_ht_size = ilog2(slot_hashtable_size);
profile->slot_hashtable =
- kvmalloc_objs(profile->slot_hashtable[0], slot_hashtable_size,
- GFP_KERNEL);
+ kvmalloc_objs(profile->slot_hashtable[0], slot_hashtable_size);
if (!profile->slot_hashtable)
goto err_destroy;
for (i = 0; i < slot_hashtable_size; i++)
diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index a561674bac97..8c290ddd3251 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -210,8 +210,7 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
return -ENOMEM;
nr_pages = (PAGE_ALIGN(addr + len) - (addr & PAGE_MASK)) >> PAGE_SHIFT;
- mapp->range.hmm_pfns = kvzalloc_objs(*mapp->range.hmm_pfns, nr_pages,
- GFP_KERNEL);
+ mapp->range.hmm_pfns = kvzalloc_objs(*mapp->range.hmm_pfns, nr_pages);
if (!mapp->range.hmm_pfns) {
ret = -ENOMEM;
goto free_map;
diff --git a/drivers/accel/ethosu/ethosu_drv.c b/drivers/accel/ethosu/ethosu_drv.c
index ae5e6b15e7de..9992193d7338 100644
--- a/drivers/accel/ethosu/ethosu_drv.c
+++ b/drivers/accel/ethosu/ethosu_drv.c
@@ -144,8 +144,7 @@ static int ethosu_open(struct drm_device *ddev, struct drm_file *file)
if (!try_module_get(THIS_MODULE))
return -EINVAL;
- struct ethosu_file_priv __free(kfree) *priv = kzalloc_obj(*priv,
- GFP_KERNEL);
+ struct ethosu_file_priv __free(kfree) *priv = kzalloc_obj(*priv);
if (!priv) {
ret = -ENOMEM;
goto err_put_mod;
diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c
index cbd74e3adb9f..4fbd4bbf2909 100644
--- a/drivers/accel/ethosu/ethosu_gem.c
+++ b/drivers/accel/ethosu/ethosu_gem.c
@@ -352,8 +352,7 @@ static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
struct ethosu_gem_object *bo,
u32 size)
{
- struct ethosu_validated_cmdstream_info __free(kfree) *info = kzalloc_obj(*info,
- GFP_KERNEL);
+ struct ethosu_validated_cmdstream_info __free(kfree) *info = kzalloc_obj(*info);
struct ethosu_device *edev = to_ethosu_device(ddev);
u32 *bocmds = bo->base.vaddr;
struct cmd_state st;
diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c
index 6c896eb816de..ba4257bda77b 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -1422,8 +1422,7 @@ static int hl_cs_copy_chunk_array(struct hl_device *hdev,
*cs_chunk_array = kmalloc_objs(**cs_chunk_array, num_chunks, GFP_ATOMIC);
if (!*cs_chunk_array)
- *cs_chunk_array = kmalloc_objs(**cs_chunk_array, num_chunks,
- GFP_KERNEL);
+ *cs_chunk_array = kmalloc_objs(**cs_chunk_array, num_chunks);
if (!*cs_chunk_array) {
atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
atomic64_inc(&hdev->aggregated_cs_counters.out_of_mem_drop_cnt);
diff --git a/drivers/accel/habanalabs/common/debugfs.c b/drivers/accel/habanalabs/common/debugfs.c
index 05b1cc7918c5..1d5e29fc6463 100644
--- a/drivers/accel/habanalabs/common/debugfs.c
+++ b/drivers/accel/habanalabs/common/debugfs.c
@@ -2052,8 +2052,7 @@ int hl_debugfs_device_init(struct hl_device *hdev)
int count = ARRAY_SIZE(hl_debugfs_list);
dev_entry->hdev = hdev;
- dev_entry->entry_arr = kmalloc_objs(struct hl_debugfs_entry, count,
- GFP_KERNEL);
+ dev_entry->entry_arr = kmalloc_objs(struct hl_debugfs_entry, count);
if (!dev_entry->entry_arr)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/common/hw_queue.c b/drivers/accel/habanalabs/common/hw_queue.c
index d499063a79ec..f0ab99dd74d6 100644
--- a/drivers/accel/habanalabs/common/hw_queue.c
+++ b/drivers/accel/habanalabs/common/hw_queue.c
@@ -837,8 +837,7 @@ static int ext_and_cpu_queue_init(struct hl_device *hdev, struct hl_hw_queue *q,
q->kernel_address = p;
- q->shadow_queue = kmalloc_objs(struct hl_cs_job *, HL_QUEUE_LENGTH,
- GFP_KERNEL);
+ q->shadow_queue = kmalloc_objs(struct hl_cs_job *, HL_QUEUE_LENGTH);
if (!q->shadow_queue) {
dev_err(hdev->dev,
"Failed to allocate shadow queue for H/W queue %d\n",
diff --git a/drivers/accel/habanalabs/common/mmu/mmu.c b/drivers/accel/habanalabs/common/mmu/mmu.c
index 1f8f7cf2d3fb..6c7c4ff8a8a9 100644
--- a/drivers/accel/habanalabs/common/mmu/mmu.c
+++ b/drivers/accel/habanalabs/common/mmu/mmu.c
@@ -843,8 +843,7 @@ int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 h
return -ENOMEM;
}
- hr_priv->mmu_asid_hop0 = kvzalloc_objs(struct pgt_info, prop->max_asid,
- GFP_KERNEL);
+ hr_priv->mmu_asid_hop0 = kvzalloc_objs(struct pgt_info, prop->max_asid);
if (ZERO_OR_NULL_PTR(hr_priv->mmu_asid_hop0)) {
dev_err(hdev->dev, "Failed to allocate hr-mmu hop0 table\n");
rc = -ENOMEM;
diff --git a/drivers/accel/habanalabs/common/security.c b/drivers/accel/habanalabs/common/security.c
index 8a0da0194cab..abe5ed0d405a 100644
--- a/drivers/accel/habanalabs/common/security.c
+++ b/drivers/accel/habanalabs/common/security.c
@@ -312,8 +312,7 @@ int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
int i, j;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
@@ -392,8 +391,7 @@ int hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,
int i, j, rc = 0;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
@@ -474,8 +472,7 @@ int hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
int i, rc = 0;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
@@ -521,8 +518,7 @@ int hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,
int i;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c
index f4f8f9122f5c..ea3a0e57c836 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c
@@ -2620,8 +2620,7 @@ static int gaudi2_init_pb_tpc(struct hl_device *hdev)
block_array_size = ARRAY_SIZE(gaudi2_pb_dcr0_tpc0);
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, block_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, block_array_size);
if (!glbl_sec)
return -ENOMEM;
diff --git a/drivers/accel/qaic/qaic_ssr.c b/drivers/accel/qaic/qaic_ssr.c
index e3daeaad057d..a5bb6078824b 100644
--- a/drivers/accel/qaic/qaic_ssr.c
+++ b/drivers/accel/qaic/qaic_ssr.c
@@ -457,8 +457,7 @@ static struct ssr_dump_info *alloc_dump_info(struct qaic_device *qdev,
}
/* Buffer used to send MEMORY READ request to device via MHI */
- dump_info->read_buf_req = kzalloc_obj(*dump_info->read_buf_req,
- GFP_KERNEL);
+ dump_info->read_buf_req = kzalloc_obj(*dump_info->read_buf_req);
if (!dump_info->read_buf_req) {
ret = -ENOMEM;
goto free_dump_info;
diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
index 751697899a98..a9248af078f6 100644
--- a/drivers/acpi/apei/einj-core.c
+++ b/drivers/acpi/apei/einj-core.c
@@ -1021,8 +1021,7 @@ static bool setup_einjv2_component_files(void)
{
char name[32];
- syndrome_data = kzalloc_objs(syndrome_data[0], max_nr_components,
- GFP_KERNEL);
+ syndrome_data = kzalloc_objs(syndrome_data[0], max_nr_components);
if (!syndrome_data)
return false;
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 5c2116171789..f0e513e9ed5d 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -636,8 +636,7 @@ static int pcc_data_alloc(int pcc_ss_id)
if (pcc_data[pcc_ss_id]) {
pcc_data[pcc_ss_id]->refcount++;
} else {
- pcc_data[pcc_ss_id] = kzalloc_obj(struct cppc_pcc_data,
- GFP_KERNEL);
+ pcc_data[pcc_ss_id] = kzalloc_obj(struct cppc_pcc_data);
if (!pcc_data[pcc_ss_id])
return -ENOMEM;
pcc_data[pcc_ss_id]->refcount++;
diff --git a/drivers/acpi/mipi-disco-img.c b/drivers/acpi/mipi-disco-img.c
index 328093ed7136..ea4bffe3c02d 100644
--- a/drivers/acpi/mipi-disco-img.c
+++ b/drivers/acpi/mipi-disco-img.c
@@ -91,8 +91,7 @@ static acpi_status parse_csi2_resource(struct acpi_resource *res, void *context)
return AE_OK;
}
- conn = kmalloc_flex(*conn, remote_name, csi2_res_src_length + 1,
- GFP_KERNEL);
+ conn = kmalloc_flex(*conn, remote_name, csi2_res_src_length + 1);
if (!conn)
return AE_OK;
diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index bd4d332520bb..79d2e92e5c28 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -560,8 +560,7 @@ struct device *platform_profile_register(struct device *dev, const char *name,
!ops->profile_set || !ops->probe))
return ERR_PTR(-EINVAL);
- struct platform_profile_handler *pprof __free(kfree) = kzalloc_obj(*pprof,
- GFP_KERNEL);
+ struct platform_profile_handler *pprof __free(kfree) = kzalloc_obj(*pprof);
if (!pprof)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index f1c7c2ad5094..fdf55c285c9a 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -341,8 +341,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
pr->performance->state_count = pss->package.count;
pr->performance->states =
- kmalloc_objs(struct acpi_processor_px, pss->package.count,
- GFP_KERNEL);
+ kmalloc_objs(struct acpi_processor_px, pss->package.count);
if (!pr->performance->states) {
result = -ENOMEM;
goto end;
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 2d398ae5c662..c0f92b93747d 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -512,8 +512,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
pr->throttling.state_count = tss->package.count;
pr->throttling.states_tss =
- kmalloc_objs(struct acpi_processor_tx_tss, tss->package.count,
- GFP_KERNEL);
+ kmalloc_objs(struct acpi_processor_tx_tss, tss->package.count);
if (!pr->throttling.states_tss) {
result = -ENOMEM;
goto end;
diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c
index c1f759fb5758..afffde4cfe7a 100644
--- a/drivers/acpi/riscv/irq.c
+++ b/drivers/acpi/riscv/irq.c
@@ -384,8 +384,7 @@ static u32 riscv_acpi_add_irq_dep(acpi_handle handle)
riscv_acpi_irq_get_dep(handle, i, &gsi_handle);
i++) {
dep_devices.count = 1;
- dep_devices.handles = kzalloc_objs(*dep_devices.handles, 1,
- GFP_KERNEL);
+ dep_devices.handles = kzalloc_objs(*dep_devices.handles, 1);
if (!dep_devices.handles) {
acpi_handle_err(handle, "failed to allocate memory\n");
continue;
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index a6f453d4785b..dfdd004fb1a9 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -757,8 +757,7 @@ int acpi_device_add(struct acpi_device *device)
if (result)
goto err_unlock;
} else {
- acpi_device_bus_id = kzalloc_obj(*acpi_device_bus_id,
- GFP_KERNEL);
+ acpi_device_bus_id = kzalloc_obj(*acpi_device_bus_id);
if (!acpi_device_bus_id) {
result = -ENOMEM;
goto err_unlock;
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index 12c3a0330f67..f37247e7a5cb 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -594,8 +594,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
* We cannot use devm_ here, since ahci_platform_put_resources() uses
* target_pwrs after devm_ have freed memory
*/
- hpriv->target_pwrs = kzalloc_objs(*hpriv->target_pwrs, hpriv->nports,
- GFP_KERNEL);
+ hpriv->target_pwrs = kzalloc_objs(*hpriv->target_pwrs, hpriv->nports);
if (!hpriv->target_pwrs) {
rc = -ENOMEM;
goto err_out;
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index 8108ef0c089a..bb9cb00f9585 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -786,8 +786,7 @@ static int he_init_group(struct he_dev *he_dev, int group)
}
/* rbpl_virt 64-bit pointers */
- he_dev->rbpl_virt = kmalloc_objs(*he_dev->rbpl_virt, RBPL_TABLE_SIZE,
- GFP_KERNEL);
+ he_dev->rbpl_virt = kmalloc_objs(*he_dev->rbpl_virt, RBPL_TABLE_SIZE);
if (!he_dev->rbpl_virt) {
hprintk("unable to allocate rbpl virt table\n");
goto out_free_rbpl_table;
diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
index b90761dcd87f..0d38e93772c2 100644
--- a/drivers/atm/iphase.c
+++ b/drivers/atm/iphase.c
@@ -1978,8 +1978,7 @@ static int tx_init(struct atm_dev *dev)
buf_desc_ptr++;
tx_pkt_start += iadev->tx_buf_sz;
}
- iadev->tx_buf = kmalloc_objs(*iadev->tx_buf, iadev->num_tx_desc,
- GFP_KERNEL);
+ iadev->tx_buf = kmalloc_objs(*iadev->tx_buf, iadev->num_tx_desc);
if (!iadev->tx_buf) {
printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
goto err_free_dle;
@@ -1999,8 +1998,7 @@ static int tx_init(struct atm_dev *dev)
sizeof(*cpcs),
DMA_TO_DEVICE);
}
- iadev->desc_tbl = kmalloc_objs(*iadev->desc_tbl, iadev->num_tx_desc,
- GFP_KERNEL);
+ iadev->desc_tbl = kmalloc_objs(*iadev->desc_tbl, iadev->num_tx_desc);
if (!iadev->desc_tbl) {
printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
goto err_free_all_tx_bufs;
@@ -2128,8 +2126,7 @@ static int tx_init(struct atm_dev *dev)
memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4);
vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
- iadev->testTable = kmalloc_objs(*iadev->testTable, iadev->num_vc,
- GFP_KERNEL);
+ iadev->testTable = kmalloc_objs(*iadev->testTable, iadev->num_vc);
if (!iadev->testTable) {
printk("Get freepage failed\n");
goto err_free_desc_tbl;
@@ -2138,8 +2135,7 @@ static int tx_init(struct atm_dev *dev)
{
memset((caddr_t)vc, 0, sizeof(*vc));
memset((caddr_t)evc, 0, sizeof(*evc));
- iadev->testTable[i] = kmalloc_obj(struct testTable_t,
- GFP_KERNEL);
+ iadev->testTable[i] = kmalloc_obj(struct testTable_t);
if (!iadev->testTable[i])
goto err_free_test_tables;
iadev->testTable[i]->lastTime = 0;
diff --git a/drivers/base/physical_location.c b/drivers/base/physical_location.c
index 06a2797e0213..2e723fff6e8a 100644
--- a/drivers/base/physical_location.c
+++ b/drivers/base/physical_location.c
@@ -21,8 +21,7 @@ bool dev_add_physical_location(struct device *dev)
if (!acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld))
return false;
- dev->physical_location = kzalloc_obj(*dev->physical_location,
- GFP_KERNEL);
+ dev->physical_location = kzalloc_obj(*dev->physical_location);
if (!dev->physical_location) {
ACPI_FREE(pld);
return false;
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index c2dd784bc14b..3cfef456a1f3 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3932,8 +3932,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
if (my_usize != p_usize) {
struct disk_conf *old_disk_conf, *new_disk_conf = NULL;
- new_disk_conf = kzalloc_obj(struct disk_conf,
- GFP_KERNEL);
+ new_disk_conf = kzalloc_obj(struct disk_conf);
if (!new_disk_conf) {
put_ldev(device);
return -ENOMEM;
diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 7844424f7b17..41cc8cefea01 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -401,8 +401,7 @@ static int ps3vram_cache_init(struct ps3_system_bus_device *dev)
priv->cache.page_count = CACHE_PAGE_COUNT;
priv->cache.page_size = CACHE_PAGE_SIZE;
- priv->cache.tags = kzalloc_objs(struct ps3vram_tag, CACHE_PAGE_COUNT,
- GFP_KERNEL);
+ priv->cache.tags = kzalloc_objs(struct ps3vram_tag, CACHE_PAGE_COUNT);
if (!priv->cache.tags)
return -ENOMEM;
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index bc665b8abd7b..7871099bc0d4 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -846,8 +846,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,
* We are using persistent grants, the grant is
* not mapped but we might have room for it.
*/
- persistent_gnt = kmalloc_obj(struct persistent_gnt,
- GFP_KERNEL);
+ persistent_gnt = kmalloc_obj(struct persistent_gnt);
if (!persistent_gnt) {
/*
* If we don't have enough memory to
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index adfd61af86ee..4b865ef800b1 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -131,8 +131,7 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
{
unsigned int r;
- blkif->rings = kzalloc_objs(struct xen_blkif_ring, blkif->nr_rings,
- GFP_KERNEL);
+ blkif->rings = kzalloc_objs(struct xen_blkif_ring, blkif->nr_rings);
if (!blkif->rings)
return -ENOMEM;
@@ -1014,14 +1013,12 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
goto fail;
list_add_tail(&req->free_list, &ring->pending_free);
for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++) {
- req->segments[j] = kzalloc_obj(*req->segments[0],
- GFP_KERNEL);
+ req->segments[j] = kzalloc_obj(*req->segments[0]);
if (!req->segments[j])
goto fail;
}
for (j = 0; j < MAX_INDIRECT_PAGES; j++) {
- req->indirect_pages[j] = kzalloc_obj(*req->indirect_pages[0],
- GFP_KERNEL);
+ req->indirect_pages[j] = kzalloc_obj(*req->indirect_pages[0]);
if (!req->indirect_pages[j])
goto fail;
}
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 777a5ae0cd33..8fc7fc3bf867 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -2207,8 +2207,7 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
for (i = 0; i < BLK_RING_SIZE(info); i++) {
rinfo->shadow[i].grants_used =
- kvzalloc_objs(rinfo->shadow[i].grants_used[0], grants,
- GFP_KERNEL);
+ kvzalloc_objs(rinfo->shadow[i].grants_used[0], grants);
rinfo->shadow[i].sg = kvzalloc_objs(rinfo->shadow[i].sg[0],
psegs, GFP_KERNEL);
if (info->max_indirect_segments)
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index e12abdec2647..b216cba1c3bf 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -187,8 +187,7 @@ static int z2_open(struct gendisk *disk, blk_mode_t mode)
(unsigned long)z_remap_nocache_nonser(paddr, size);
#endif
z2ram_map =
- kmalloc_objs(z2ram_map[0], size / Z2RAM_CHUNKSIZE,
- GFP_KERNEL);
+ kmalloc_objs(z2ram_map[0], size / Z2RAM_CHUNKSIZE);
if (z2ram_map == NULL) {
printk(KERN_ERR DEVICE_NAME
": cannot get mem for z2ram_map\n");
diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
index a27261914bd1..879b8b706428 100644
--- a/drivers/bus/mhi/ep/main.c
+++ b/drivers/bus/mhi/ep/main.c
@@ -1459,8 +1459,7 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
if (ret)
return ret;
- mhi_cntrl->mhi_cmd = kzalloc_objs(*mhi_cntrl->mhi_cmd, NR_OF_CMD_RINGS,
- GFP_KERNEL);
+ mhi_cntrl->mhi_cmd = kzalloc_objs(*mhi_cntrl->mhi_cmd, NR_OF_CMD_RINGS);
if (!mhi_cntrl->mhi_cmd) {
ret = -ENOMEM;
goto err_free_ch;
diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
index 7845fc7fe6c2..f16a1e67a667 100644
--- a/drivers/bus/mhi/host/boot.c
+++ b/drivers/bus/mhi/host/boot.c
@@ -380,8 +380,7 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
return -ENOMEM;
/* Allocate memory for entries */
- img_info->mhi_buf = kzalloc_objs(*img_info->mhi_buf, segments,
- GFP_KERNEL);
[Output truncated: showing 1000 of 15164 lines]]
|
| 165/4 |
2026/10/13 22:55 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 63160
output: 36
thoughts: 1309
Thoughts: **Analyzing Potential Memory Allocation Issues in DRM Lease Handling**
Okay, Linus just mass-converted `kcalloc` to `kzalloc_objs`. Interesting. I need to dive into this change to understand any potential implications. Before this commit, it was using the older `kzalloc_objs` function with a `struct drm_mode_object *` pointer and `object_count` as an argument. I see it's now used in `fill_object_idr`.
My initial thought is to examine situations with a large `object_count`. Let's look at `drm_mode_create_lease_ioctl`. I see `object_count` is passed. A critical piece to examine is how `object_ids` is allocated using `memdup_array_user`. This uses `kmalloc`, and when `object_count` becomes large, say 1,000,000, and we are allocating `__u32` elements, this could trigger issues if the allocated size grows. It looks like `memdup_array_user` allocates this data with `kmalloc`. So a large `object_count` might result in a substantial allocation, in the example of 1,000,000 elements * 4 bytes each equals 4MB, which is fine.
However, in `fill_object_idr`, `objects` is allocated using `kzalloc_objs`, which allocates an array of `struct drm_mode_object *` pointers. And a `struct drm_mode_object *` is 8 bytes. With `object_count` being 1,000,000, that is 8,000,000 bytes or 8MB. Because it uses `GFP_KERNEL` without the `__GFP_NOWARN` flag, this could trigger a warning from the kernel's memory allocation subsystem.
Wait, what if `vmemdup_array_user` was used instead? That's interesting! If `object_ids` were allocated using that instead, then it will use `vmalloc()`. And that will also change how we free the data. I'll need to confirm that `kvfree` can correctly free memory allocated by `vmemdup_array_user`. The documentation confirms this: use `kvfree()` to free this memory. Then, `objects` should use `kvzalloc_objs` instead, which is followed by `kvfree(objects)`. This seems to be a significant optimization here, avoiding the order 11 allocation limit in the kernel.
Now, let's consider extremely large `object_count` values. What if `object_count` is, say, 500,000,000? That would translate to 4,000,000,000 bytes (4GB) for the `objects` array alone! This exceeds the maximum size allowed in `__kvmalloc_node_noprof` and will trigger a warning. With a large `size > INT_MAX` the `WARN_ON_ONCE` in `__kvmalloc_node_noprof()` will trigger because the call passes `GFP_KERNEL`. What about the `vmemdup_array_user` case? What about `kmem_buckets_valloc`? I will need to look into this more closely.
|
| 166/4 |
2026/10/13 22:55 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:mm/util.c Name:kmem_buckets_valloc]
Results: map[SourceCode: SourceFile:]
|
| 167/4 |
2026/10/13 22:55 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 65249
output: 21
thoughts: 14
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing Memory Allocation**
Alright, time to get to the root of this memory issue. My immediate instinct is to dive into the kernel memory allocation details. Since I'm thinking about memory buckets, I'm going to reach for `grep` and search for the `kmem_buckets_valloc` function. This function's name suggests it's involved in virtual allocation related to those buckets, making it a likely candidate for pinpointing memory leaks or inefficiencies within that specific subsystem. This is my starting point to understand the allocation behavior and pinpoint anything unusual.
|
| 168/4 |
2026/10/13 22:55 |
tool |
grepper |
0m
Args: map[Expression:kmem_buckets_valloc]
Results: map[Output:include/linux/slab.h=1352=void *kvmalloc_node(size_t size, gfp_t flags, int node);
--
include/linux/slab.h-1362-
include/linux/slab.h:1363:#define kmem_buckets_valloc(_b, _size, _flags) \
include/linux/slab.h-1364- alloc_hooks(__kvmalloc_node_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), 1, _flags, NUMA_NO_NODE))
--
mm/util.c=243=void *vmemdup_user(const void __user *src, size_t len)
--
mm/util.c-246-
mm/util.c:247: p = kmem_buckets_valloc(user_buckets, len, GFP_USER);
mm/util.c-248- if (!p)
]
|
| 169/4 |
2026/10/13 22:55 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 65678
output: 30
thoughts: 2154
Thoughts: **Analysis of Potential Integer Overflow Vulnerability in DRM Lease Handling**
Okay, so I've been digging into this potential integer overflow issue related to the DRM lease functionality. My initial thought was: Hmm, that `kmem_buckets_valloc` call with `GFP_USER` is concerning. Since `GFP_USER` doesn't include `__GFP_NOWARN`, a large `len` exceeding `INT_MAX` could trigger a warning in `__kvmalloc_node_noprof`, potentially in `vmemdup_user` or `vmemdup_array_user` if used later. Similarly, allocations with `kvzalloc_objs` (using `GFP_KERNEL`) could also warn on oversized `size`.
My immediate question was why would such a large `object_count` even be permitted? I went back to the summary, and the proposed fix highlights three key points: switching `kvzalloc_objs` and `kvfree` in `fill_object_idr`, adding a sanity check to `drm_mode_create_lease_ioctl` and optionally using `vmemdup_array_user` for graceful fallback.
So, I started examining the relevant functions to see what's actually happening. In `fill_object_idr` and `validate_lease`, `object_count` is an `int` right now! This means the code *should* be safe. But then, I looked at `drm_mode_create_lease_ioctl`, where `object_count` comes from `cl->object_count`, which is a `__u32`. This implies a potential size mismatch.
If `object_count > INT_MAX / sizeof(struct drm_mode_object *)`, we could run into issues. On a 64-bit system, that limit is roughly 268 million, which is still within `INT_MAX`, and on 32-bit systems, the limit is 536 million, also within `INT_MAX`. Since `INT_MAX / sizeof(...)` is always < `INT_MAX`, and `object_count` will then fit within an `int`, we can proceed with a sanity check.
My train of thought then turned to where the best place is to add this check. I observed that `object_count` is first inspected in the `drm_mode_create_lease_ioctl` function. And while `object_count` *can* be zero (for an empty lease as the documentation states), I need to be sure that the check is implemented correctly.
So, after considering the need to call `drm_master_put` on error and checking other DRM ioctls for integer check idioms, I'm confident that adding the bounds check *before* the `drm_file_get_master` call is the best approach. This prevents any unnecessary resource allocation if the `object_count` is out of bounds and results in an earlier return. So, something like:
```c
object_count = cl->object_count;
if (object_count > INT_MAX / sizeof(struct drm_mode_object *))
return -EINVAL;
```
It is worth noting that we can check `cl->object_count` before `drm_file_get_master`.
This is a good, safe approach. Now, I'll review other DRM ioctls for this integer check idiom.
|
| 170/4 |
2026/10/13 22:56 |
tool |
grepper |
0m
Args: map[Expression:INT_MAX / PathPrefixes:[drivers/gpu/drm]]
Results: map[Output:drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c=1028=int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c-1123-
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:1124: if (args->num_entries > INT_MAX / sizeof(*vm_entries)) {
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c-1125- r = -EINVAL;
--
drivers/gpu/drm/tests/drm_format_test.c=225=static void drm_test_format_min_pitch_two_plane(struct kunit *test)
--
drivers/gpu/drm/tests/drm_format_test.c-251- (uint64_t)UINT_MAX);
drivers/gpu/drm/tests/drm_format_test.c:252: KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1),
drivers/gpu/drm/tests/drm_format_test.c-253- (uint64_t)UINT_MAX + 1);
--
drivers/gpu/drm/tests/drm_format_test.c=260=static void drm_test_format_min_pitch_three_plane_8bpp(struct kunit *test)
--
drivers/gpu/drm/tests/drm_format_test.c-294- (uint64_t)UINT_MAX);
drivers/gpu/drm/tests/drm_format_test.c:295: KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1),
drivers/gpu/drm/tests/drm_format_test.c:296: (uint64_t)UINT_MAX / 2 + 1);
drivers/gpu/drm/tests/drm_format_test.c:297: KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 2, UINT_MAX / 2 + 1),
drivers/gpu/drm/tests/drm_format_test.c:298: (uint64_t)UINT_MAX / 2 + 1);
drivers/gpu/drm/tests/drm_format_test.c-299- KUNIT_EXPECT_EQ(test, drm_format_info_min_pitch(info, 0, (UINT_MAX - 1) / 2),
--
drivers/gpu/drm/tests/drm_framebuffer_test.c=34=static const struct drm_framebuffer_test drm_framebuffer_create_cases[] = {
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-87- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:88: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-89- .pitches = { 4 * MAX_WIDTH, 0, 0 },
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-98- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:99: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, UINT_MAX / 2, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-100- .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-105- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:106: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-107- .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_INVALID,
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-111- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:112: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-113- .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-117- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:118: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-119- .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-125- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:126: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-127- .pitches = { 4 * MAX_WIDTH, 0, 0 }, .flags = DRM_MODE_FB_MODIFIERS,
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-132- .cmd = { .width = MAX_WIDTH, .height = MAX_HEIGHT, .pixel_format = DRM_FORMAT_ABGR8888,
drivers/gpu/drm/tests/drm_framebuffer_test.c:133: .handles = { 1, 0, 0 }, .offsets = { UINT_MAX / 2, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-134- .pitches = { 4 * MAX_WIDTH, 4 * MAX_WIDTH, 0 },
--
drivers/gpu/drm/tests/drm_framebuffer_test.c=423=static void drm_test_framebuffer_modifiers_not_supported(struct kunit *test)
--
drivers/gpu/drm/tests/drm_framebuffer_test.c-432- .pixel_format = DRM_FORMAT_ABGR8888, .handles = { 1, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c:433: .offsets = { UINT_MAX / 2, 0, 0 }, .pitches = { 4 * MAX_WIDTH, 0, 0 },
drivers/gpu/drm/tests/drm_framebuffer_test.c-434- .flags = DRM_MODE_FB_MODIFIERS,
--
drivers/gpu/drm/vc4/vc4_gem.c=735=vc4_get_bcl(struct drm_device *dev, struct vc4_exec_info *exec)
--
drivers/gpu/drm/vc4/vc4_gem.c-753- exec_size < uniforms_offset ||
drivers/gpu/drm/vc4/vc4_gem.c:754: args->shader_rec_count >= (UINT_MAX /
drivers/gpu/drm/vc4/vc4_gem.c-755- sizeof(struct vc4_shader_state)) ||
]
|
| 171/4 |
2026/10/13 22:56 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 70786
output: 33
thoughts: 50
Thoughts: Okay, let's dive into this. I need to get a handle on how array counts are validated and how data is copied from user space within the DRM subsystem. My initial thought is to see how other parts of the code base handle this safely, to avoid introducing any vulnerabilities, so let's start with a code-based exploration.
**DRM Array Count Validation and User Space Data Copy**
My immediate plan is to understand existing practices within `drivers/gpu/drm/`. I'm going to leverage my existing knowledge to see if I can find examples. Specifically, I'm going to search for instances of `vmemdup_array_user` within that directory, as that function is likely to be a key element for secure user space data transfer. Finding existing usages of `vmemdup_array_user` is the first place to start.
|
| 172/4 |
2026/10/13 22:56 |
tool |
grepper |
0m
Args: map[Expression:vmemdup_array_user PathPrefixes:[drivers/gpu/drm]]
Results: map[Output:drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c=164=amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-174-
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:175: return vmemdup_array_user(uptr, bo_number,
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-176- sizeof(struct drm_amdgpu_bo_list_entry));
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c=179=static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-219-
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:220: p->chunks[i].kdata = vmemdup_array_user(u64_to_user_ptr(user_chunk.chunk_data),
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-221- size,
--
drivers/gpu/drm/drm_gem.c=832=int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
--
drivers/gpu/drm/drm_gem.c-847-
drivers/gpu/drm/drm_gem.c:848: handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
drivers/gpu/drm/drm_gem.c-849- if (IS_ERR(handles)) {
]
|
| 173/4 |
2026/10/13 22:56 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 71526
output: 47
thoughts: 3830
Thoughts: **Analysis of a Potential Integer Overflow Vulnerability in DRM Lease Handling**
Okay, so I've been digging into this potential integer overflow vulnerability in the DRM lease code, specifically within `drm_mode_create_lease_ioctl`. The core issue stems from how the code handles a user-provided `object_count` when allocating memory for a list of DRM mode objects. It seems if the `object_count` is large enough, and particularly when multiplied by the size of a mode object, we can hit an integer overflow. This can then lead to a `WARN_ON_ONCE` within the kernel or out-of-bounds memory accesses when `vmemdup_array_user` or `kvzalloc_objs` are called.
I started by looking at `drm_gem_objects_lookup`, which gives a good example of how memory is freed after allocation using `kvfree`. This quickly led me to investigate the code in `drm_lease.c`, especially the use of `memdup_array_user`. I realized it's replaced with `vmemdup_array_user` which calls `__kvmalloc_node_noprof` which has the size check. If the allocated memory size is larger than `INT_MAX`, there's a kernel warning. This also holds true for `kvzalloc_objs`.
Then the thought occurred that we needed to add a check for the size *before* the allocations. My first instinct was to check if `object_count > INT_MAX / sizeof(struct drm_mode_object *)`. I figured, if we check for an overflow *before* the multiplication, we're guaranteed to avoid exceeding INT_MAX during the multiplication. Then the question became whether `sizeof(struct drm_mode_object *)` or `sizeof(__u32)` is the right check. Since the object size is guaranteed to be larger than `__u32`, `sizeof(struct drm_mode_object *)` is the right choice.
The next question was where to put the check. It's best to place the check early. Reading the code, I realized this check could and *should* be done *before* calling `drm_file_get_master`, which is the first function after the arguments have been set. This avoids acquiring unnecessary references if the arguments are invalid. We want to catch the potentially invalid `object_count` *before* getting any master references.
So, the optimal fix involves: 1) adding a check for `object_count > INT_MAX / sizeof(struct drm_mode_object *)` right at the start of `drm_mode_create_lease_ioctl`, immediately after the flag checks. This check ensures that a large `object_count` doesn't lead to a memory allocation that overflows INT_MAX and triggers a kernel warning. It's cleaner, more efficient, and prevents resource acquisition if the argument is out-of-bounds.
|
| 174/4 |
2026/10/13 22:56 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c IncludeSnippetLines:1 Name:fill_object_idr]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:drm_mode_create_lease_ioctl SourceFile:drivers/gpu/drm/drm_lease.c SourceLine:521 SourceSnippet: 520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
]] TruncatedOutput:false]
|
| 175/4 |
2026/10/13 22:56 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 76168
output: 35
thoughts: 3719
Thoughts: **Analysis of `drm_mode_create_lease_ioctl` and Related Functions**
Okay, so I'm digging into `drm_mode_create_lease_ioctl` and its supporting functions, specifically `fill_object_idr` and `validate_lease`. It seems there's a type mismatch issue. The primary entry point, `drm_mode_create_lease_ioctl`, uses `size_t object_count` which is derived from `cl->object_count`, where `cl->object_count` is a `__u32`. This `object_count` is then passed to `fill_object_idr`. Inside `fill_object_idr`, however, `object_count` is declared as an `int`. This discrepancy causes some serious concern.
My initial thought was that a `size_t` would be more appropriate for `fill_object_idr` given that's what's passed down from the ioctl. However, I need to ensure there are no unintended consequences. The current code has the loop variable `o` declared as `u32 o;` inside `fill_object_idr`, and `int o;` inside `validate_lease`. So, if I change it to `size_t object_count`, I'd also have to change `o` to `size_t o;` to avoid potential sign comparison warnings. I also need to make sure I don't introduce any overflow issues if `object_count` is large.
Then, I remember there's a historical patch related to `kvzalloc_objs` and `kvfree` in `fill_object_idr`. I re-read the context, and it suggests a bounds check and potentially `vmemdup_array_user` as a replacement for `memdup_array_user`. I'm concerned that `memdup_array_user` allocates with `kmalloc`, but `kvzalloc_objs` uses `vmalloc` if the requested size exceeds a limit. This could cause `kvfree` and `kfree` mismatches. Since `vmemdup_array_user` can also fall back to vmalloc, I should be using `kvfree`.
Thinking about this, I need to consider the current constraints. `cl->object_count` is `__u32`. This is used to calculate the size of an array with `object_count` elements of type `struct drm_mode_object *`. Now, even if `cl->object_count` is `0xFFFFFFFF` (the maximum value of a 32-bit unsigned integer), the resulting size will fit in `INT_MAX`, provided the size of `struct drm_mode_object *` is a reasonable value. Therefore, I can actually keep the code as is. I can simply add a check that `cl->object_count` does not exceed `INT_MAX / sizeof(void*)`. Because `memdup_array_user` can return `ERR_PTR`, it does not actually *need* to be changed to `vmemdup_array_user`. If it *is* changed, then `kvfree` must be used.
Also, I checked `drm_gem_objects_lookup`, which has `int count`. If `drm_mode_create_lease_ioctl` calls `drm_gem_objects_lookup`, then a `size_t object_count` needs to be `int count` anyway.
So, adding a bounds check in `drm_mode_create_lease_ioctl` to ensure `object_count` doesn't exceed `INT_MAX / sizeof(void *)` is sufficient. This fixes the original issue and any potential integer overflow issues. And it keeps existing type constraints in `fill_object_idr` and related functions. There is no need to switch `memdup_array_user` to `vmemdup_array_user` at this time, though the option does remain open.
|
| 176/4 |
2026/10/13 22:57 |
tool |
grepper |
0m
Args: map[Expression:alloc|dup PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results: map[Output:drivers/gpu/drm/drm_lease.c=154=uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in)
--
drivers/gpu/drm/drm_lease.c-196-/*
drivers/gpu/drm/drm_lease.c:197: * Uses drm_master_create to allocate a new drm_master, then checks to
drivers/gpu/drm/drm_lease.c-198- * make sure all of the desired objects can be leased, atomically
--
drivers/gpu/drm/drm_lease.c-204- * ERR_PTR(-EEXIST) same object specified more than once in the provided list
drivers/gpu/drm/drm_lease.c:205: * ERR_PTR(-ENOMEM) allocation failed
drivers/gpu/drm/drm_lease.c-206- */
drivers/gpu/drm/drm_lease.c=207=static struct drm_master *drm_lease_create(struct drm_master *lessor, struct idr *leases)
--
drivers/gpu/drm/drm_lease.c-239- /* Insert the new lessee into the tree */
drivers/gpu/drm/drm_lease.c:240: id = idr_alloc(&(drm_lease_owner(lessor)->lessee_idr), lessee, 1, 0, GFP_KERNEL);
drivers/gpu/drm/drm_lease.c-241- if (id < 0) {
--
drivers/gpu/drm/drm_lease.c=378=static int fill_object_idr(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-388-
drivers/gpu/drm/drm_lease.c:389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
drivers/gpu/drm/drm_lease.c-390- if (!objects)
--
drivers/gpu/drm/drm_lease.c-432- */
drivers/gpu/drm/drm_lease.c:433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
drivers/gpu/drm/drm_lease.c-434- if (ret < 0) {
--
drivers/gpu/drm/drm_lease.c-441-
drivers/gpu/drm/drm_lease.c:442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
drivers/gpu/drm/drm_lease.c-443- if (ret < 0) {
--
drivers/gpu/drm/drm_lease.c-448- if (crtc->cursor) {
drivers/gpu/drm/drm_lease.c:449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
drivers/gpu/drm/drm_lease.c-450- if (ret < 0) {
--
drivers/gpu/drm/drm_lease.c-471- * created containing the objects specified in the ioctl structure.
drivers/gpu/drm/drm_lease.c:472: * A file descriptor will be allocated for that and returned to the
drivers/gpu/drm/drm_lease.c-473- * application.
--
drivers/gpu/drm/drm_lease.c=475=int drm_mode_create_lease_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-511- if (object_count != 0) {
drivers/gpu/drm/drm_lease.c:512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
drivers/gpu/drm/drm_lease.c-513- object_count, sizeof(__u32));
]
|
| 177/4 |
2026/10/13 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 81812
output: 43
thoughts: 1073
Thoughts: **Analyzing DRM Lease Allocations**
Okay, let's break down the memory allocation situation within `drm_lease.c`. First, I need to confirm my understanding of the landscape. I've examined `drm_mode_list_lessees_ioctl`, `drm_mode_get_lease_ioctl`, and `drm_mode_revoke_lease_ioctl`, and it appears that none of these directly allocate any memory. They involve `put_user` calls within loops, but no dynamic allocation is happening there. This means `fill_object_idr` and `drm_mode_create_lease_ioctl` are the prime suspects, as they are the ONLY places with allocations in `drm_lease.c`.
Now, I'm trying to nail down the precise headers needed for the allocation functions used in those two problematic ioctls. I checked the included headers in `drivers/gpu/drm/drm_lease.c` and saw the usual suspects: file, uaccess, drm auth, crtc, driver, file, lease, and print headers. But that doesn't immediately tell me where the allocation functions are declared.
I'm thinking, do I need to explicitly include `<linux/slab.h>` or `<linux/string.h>`? My brain is racing. Was this already included indirectly? It's often the case that these are brought in through dependencies. I quickly check whether the code compiled and ran previously with `kzalloc_objs` and `kfree`, and the answer is yes, so perhaps it's already included. But I need to be *sure*.
So the logical next step is to find where `kvzalloc_objs` and `kvfree` are declared. Okay, it's definitely `<linux/slab.h>`. And `vmemdup_array_user` is declared in `<linux/string.h>`. Alright. Now, are either of these headers already included? Let me check by grepping through the included headers in `drm_crtc.h` and the others. Or, even better, I can just add `#include <linux/slab.h>` and see if it breaks the build. If it's already there, it shouldn't, but if it's missing and needed, this will confirm the need.
Wait, it's pretty standard for kernel code that allocates memory to include `<linux/slab.h>`. Why isn't it already explicitly included? I need to figure out the dependencies to understand why the code might have compiled previously without it. So, I need to check if one of the included headers already brings in `<linux/slab.h>`. That's the next task.
|
| 178/4 |
2026/10/13 22:57 |
tool |
grepper |
0m
Args: map[Expression:#include <linux/slab\.h> PathPrefixes:[include/drm/ drivers/gpu/drm/]]
Results: map[Output:
Full output is too long, showing 200 out of 1063 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (266 files in total):
drivers/gpu/drm/amd/acp/acp_hw.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c:1
drivers/gpu/drm/amd/amdgpu/atom.c:1
drivers/gpu/drm/amd/amdgpu/cik.c:1
drivers/gpu/drm/amd/amdgpu/nv.c:1
drivers/gpu/drm/amd/amdgpu/si.c:1
drivers/gpu/drm/amd/amdgpu/soc15.c:1
drivers/gpu/drm/amd/amdgpu/soc21.c:1
drivers/gpu/drm/amd/amdgpu/soc24.c:1
drivers/gpu/drm/amd/amdgpu/vi.c:1
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:1
drivers/gpu/drm/amd/amdkfd/kfd_device.c:1
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:1
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c:1
drivers/gpu/drm/amd/amdkfd/kfd_events.c:1
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c:1
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c:1
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c:1
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c:1
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c:1
drivers/gpu/drm/amd/amdkfd/kfd_process.c:1
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c:1
drivers/gpu/drm/amd/amdkfd/kfd_queue.c:1
drivers/gpu/drm/amd/amdxcp/amdgpu_xcp_drv.c:1
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c:1
drivers/gpu/drm/amd/display/dc/bios/bios_parser.c:1
drivers/gpu/drm/amd/display/dc/dccg/dcn20/dcn20_dccg.c:1
drivers/gpu/drm/amd/display/dc/dce/dce_abm.c:1
drivers/gpu/drm/amd/display/dc/gpio/hw_generic.c:1
drivers/gpu/drm/amd/display/dc/irq/dce60/irq_service_dce60.c:1
... and 216 more files
drivers/gpu/drm/amd/acp/acp_hw.c-24-#include <linux/mm.h>
drivers/gpu/drm/amd/acp/acp_hw.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/acp/acp_hw.c-26-#include <linux/device.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c-27-#include <linux/backlight.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c:28:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c-29-#include <linux/xarray.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c-27-#include <linux/sched.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c:28:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c-29-#include <linux/sched/mm.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c-8-#include <linux/vga_switcheroo.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c:9:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_atpx_handler.c-10-#include <linux/acpi.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c-33-#include <linux/pci.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c:34:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_bios.c-35-#include <linux/acpi.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c-25-#include <linux/pci.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_cgs.c-27-
--
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c-33-#include <linux/console.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c:34:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c-35-#include <linux/iommu.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c-34-#include <linux/kref.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c:35:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c-36-#include <linux/firmware.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c-29-#include <linux/seq_file.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c:30:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c-31-
--
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c-38-#include <linux/vga_switcheroo.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c:39:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c-40-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c-32-#include <linux/list.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:33:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c-34-#include <linux/dma-buf.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-29-#include <linux/seq_file.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:30:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-31-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c-22- */
drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c:23:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ring_mux.c-24-#include <drm/drm_print.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-38-#include <linux/seq_file.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:39:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c-40-#include <linux/swap.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c-24-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_ucode.c-26-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c-25-#include <linux/kref.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c-27-#include <linux/dma-fence-unwrap.h>
--
drivers/gpu/drm/amd/amdgpu/atom.c-26-#include <linux/sched.h>
drivers/gpu/drm/amd/amdgpu/atom.c:27:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/atom.c-28-#include <linux/string_helpers.h>
--
drivers/gpu/drm/amd/amdgpu/cik.c-24-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/cik.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/cik.c-26-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/nv.c-23-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/nv.c:24:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/nv.c-25-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/si.c-24-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/si.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/si.c-26-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/soc15.c-23-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/soc15.c:24:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/soc15.c-25-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/soc21.c-23-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/soc21.c:24:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/soc21.c-25-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/soc24.c-23-#include <linux/firmware.h>
drivers/gpu/drm/amd/amdgpu/soc24.c:24:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/soc24.c-25-#include <linux/module.h>
--
drivers/gpu/drm/amd/amdgpu/vi.c-24-#include <linux/pci.h>
drivers/gpu/drm/amd/amdgpu/vi.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdgpu/vi.c-26-
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-30-#include <linux/sched.h>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:31:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-32-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_device.c-25-#include <linux/pci.h>
drivers/gpu/drm/amd/amdkfd/kfd_device.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_device.c-27-#include "kfd_priv.h"
--
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c-26-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c:27:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c-28-#include <linux/list.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c-25-#include <linux/mman.h>
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c-27-#include <linux/io.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_events.c-24-#include <linux/mm_types.h>
drivers/gpu/drm/amd/amdkfd/kfd_events.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_events.c-26-#include <linux/types.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c-28-#include <linux/sched.h>
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c:29:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_flat_memory.c-30-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c-43-
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c:44:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_interrupt.c-45-#include <linux/device.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c-26-#include <linux/mutex.h>
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c:27:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_kernel_queue.c-28-#include <linux/printk.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c-25-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c-27-#include <linux/mm_types.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c-25-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c-27-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c-24-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c-26-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c-25-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c-27-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c-25-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c-27-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c-25-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c-27-#include <linux/uaccess.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c-25-#include <linux/printk.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c-27-#include <linux/mm_types.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c-24-
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager.c-26-#include <linux/mutex.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_process.c-29-#include <linux/mmu_context.h>
drivers/gpu/drm/amd/amdkfd/kfd_process.c:30:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_process.c-31-#include <linux/notifier.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c-24-
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c-26-#include <linux/list.h>
--
drivers/gpu/drm/amd/amdkfd/kfd_queue.c-24-
drivers/gpu/drm/amd/amdkfd/kfd_queue.c:25:#include <linux/slab.h>
drivers/gpu/drm/amd/amdkfd/kfd_queue.c-26-#include <linux/overflow.h>
--
drivers/gpu/drm/amd/amdxcp/amdgpu_xcp_drv.c-27-#include <linux/platform_device.h>
drivers/gpu/drm/amd/amdxcp/amdgpu_xcp_drv.c:28:#include <linux/slab.h>
drivers/gpu/drm/amd/amdxcp/amdgpu_xcp_drv.c-29-
--
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c-10-#include <linux/kobject.h>
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c:11:#include <linux/slab.h>
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_hdcp_test.c-12-#include <linux/sysfs.h>
--
drivers/gpu/drm/amd/display/dc/bios/bios_parser.c-25-
drivers/gpu/drm/amd/display/dc/bios/bios_parser.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/display/dc/bios/bios_parser.c-27-
--
drivers/gpu/drm/amd/display/dc/dccg/dcn20/dcn20_dccg.c-25-
drivers/gpu/drm/amd/display/dc/dccg/dcn20/dcn20_dccg.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/display/dc/dccg/dcn20/dcn20_dccg.c-27-
--
drivers/gpu/drm/amd/display/dc/dce/dce_abm.c-25-
drivers/gpu/drm/amd/display/dc/dce/dce_abm.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/display/dc/dce/dce_abm.c-27-
--
drivers/gpu/drm/amd/display/dc/gpio/hw_generic.c-25-
drivers/gpu/drm/amd/display/dc/gpio/hw_generic.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/display/dc/gpio/hw_generic.c-27-
--
drivers/gpu/drm/amd/display/dc/irq/dce60/irq_service_dce60.c-25-
drivers/gpu/drm/amd/display/dc/irq/dce60/irq_service_dce60.c:26:#include <linux/slab.h>
drivers/gpu/drm/amd/display/dc/irq/dce60/irq_service_dce60.c-27-
--
]
|
| 179/4 |
2026/10/13 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 89778
output: 64
thoughts: 35
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Investigating Potential Header Dependencies**
Alright, I need to quickly determine the header inclusion landscape. My gut tells me there might be a subtle dependency on `linux/slab.h` creeping in via either `include/drm/drm_file.h` or, less likely but still possible, `drm_crtc.h`. I've encountered similar scenarios before, and it's always prudent to double-check these things, especially in a kernel context where hidden dependencies can lead to surprising issues down the line β particularly around memory management or locking. I want to rule out any unexpected uses of slab allocators that might impact the overall system's memory footprint or lead to subtle locking issues down the line. Let's see if those headers are bringing it in directly or indirectly.
|
| 180/4 |
2026/10/13 22:57 |
tool |
grepper |
0m
Error:
Args: map[Expression:#include <linux/slab\.h> PathPrefixes:[include/drm/drm_file.h include/drm/drm_crtc.h include/drm/drm_drv.h]]
Results:
|
| 181/4 |
2026/10/13 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 90071
output: 30
thoughts: 23
Thoughts: Okay, here's my summary, tailored for an expert audience, presented as if it were my own thought process:
**Diving into DRM Lease Dependencies**
Alright, time to get my hands dirty. I need to understand the dependencies within `drm_lease.c`, specifically concerning the slab allocator. The immediate question is which header file, if any, is responsible for pulling in `linux/slab.h` for this module. I need to trace this back. This is crucial for understanding how memory is managed within the lease subsystem and any potential conflicts or design choices around slab allocation. I suspect it's implicitly included, but I need to confirm and identify the mechanism. Let's start digging.
|
| 182/4 |
2026/10/13 22:57 |
tool |
grepper |
0m
Error:
Args: map[Expression:linux/slab\.h PathPrefixes:[include/drm/]]
Results:
|
| 183/4 |
2026/10/13 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 90284
output: 38
thoughts: 239
Thoughts: **My Analysis of Potential Header Inclusion in `drm_lease.c`**
Okay, first things first, I need to verify whether `drm_lease.c` explicitly includes `<linux/slab.h>`. Let's take a look at the file itself⦠hmm, nope. It's not there. Although it's not strictly *required* because of dependency trees, I've always held the belief that explicitly including `<linux/slab.h>` whenever using functions like `kvfree` or `kvzalloc_objs` is just good, clean Linux kernel coding practice. It adds a layer of clarity and self-documentation to the code.
Now, wait a minute, I should also check if `<linux/overflow.h>` is needed. I see an integer division involving `INT_MAX` and the `sizeof(struct drm_mode_object *)`. Hold on... no, that won't require `<linux/overflow.h>`. Integer division, even with `INT_MAX`, won't overflow the result. The overflow protection isn't needed here.
Okay, let's take a step back. Is `INT_MAX` properly defined? It should be in `<linux/limits.h>` or `<linux/kernel.h>`, which are common headers in the kernel. I should make a note to check that.
To get a better perspective, I'm going to quickly glance at some other DRM core files. Specifically, I'll check `drivers/gpu/drm/drm_gem.c` to see how those files handle similar limit checks and header inclusions. Looking at their practices may influence my own decision here.
|
| 184/4 |
2026/10/13 22:57 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_gem.c FirstLine:20 LineCount:40]
Results: map[Contents: 20: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21: * IN THE SOFTWARE.
22: *
23: * Authors:
24: * Eric Anholt <eric@anholt.net>
25: *
26: */
27:
28: #include <linux/dma-buf.h>
29: #include <linux/export.h>
30: #include <linux/file.h>
31: #include <linux/fs.h>
32: #ifdef CONFIG_TRANSPARENT_HUGEPAGE
33: #include <linux/fs_context.h>
34: #endif
35: #include <linux/iosys-map.h>
36: #include <linux/mem_encrypt.h>
37: #include <linux/mm.h>
38: #include <linux/mman.h>
39: #include <linux/module.h>
40: #include <linux/pagemap.h>
41: #include <linux/folio_batch.h>
42: #include <linux/sched/mm.h>
43: #include <linux/shmem_fs.h>
44: #include <linux/slab.h>
45: #include <linux/string_helpers.h>
46: #include <linux/types.h>
47: #include <linux/uaccess.h>
48:
49: #include <drm/drm.h>
50: #include <drm/drm_device.h>
51: #include <drm/drm_drv.h>
52: #include <drm/drm_file.h>
53: #include <drm/drm_gem.h>
54: #include <drm/drm_managed.h>
55: #include <drm/drm_print.h>
56: #include <drm/drm_vma_manager.h>
57:
58: #include "drm_internal.h"
59:
]
|
| 185/4 |
2026/10/13 22:57 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 91500
output: 37
thoughts: 6706
Thoughts: **Analysis of drm_lease.c Changes**
Okay, so I've carefully reviewed the proposed changes to `drm_lease.c`, focusing on potential issues related to memory allocation, integer overflows, and code correctness, and it's quite straightforward. My initial instinct to include `<linux/slab.h>` is confirmed, it's clean and standard practice.
First, concerning the `fill_object_idr()` function: the `kvzalloc_objs` and `kvfree` calls are correctly paired, and the error handling for allocation failure (`!objects`) is properly handled by returning `-ENOMEM` and avoiding the subsequent cleanup. The existing `out_free_objects` label ensures that any partially allocated `objects` are freed in all execution paths, so that's all good.
The second change within `drm_mode_create_lease_ioctl()` replacing `memdup_array_user` with `vmemdup_array_user` and `kfree` with `kvfree` is also completely sound. I double-checked the logic around `vmemdup_array_user`, `fill_object_idr`, and the subsequent `kvfree(object_ids)` call. If `fill_object_idr` returns an error, the `object_ids` are freed before the function exits. And the `leases` are destroyed if errors are encountered. This ensures memory is freed properly and avoids leaks.
The most critical aspect is the third change, the bounds check on `object_count`. This is where I have to be the most rigorous. The addition of the check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))` within `drm_mode_create_lease_ioctl` is correct and necessary. It should be placed early in the function, before any allocations or references to user-provided data take place. This ensures that the code isn't vulnerable to integer overflows that could lead to memory corruption. I decided that `"invalid object count"` or `"too many objects"` is a reasonable debug message. Also, ensuring that `sizeof(struct drm_mode_object *)` is used in the check is the most explicit and clearest way to do this.
I've also checked whether this would impact any of the other ioctls, `drm_mode_list_lessees_ioctl` and `drm_mode_get_lease_ioctl`, and found that neither of these perform any allocation and simply read/write to user space. Therefore, the change doesn't need to be applied to either function.
After double-checking, I conclude that there is NO reason to change `int object_count` to `size_t object_count` in `fill_object_idr`, `validate_lease`, or `drm_mode_create_lease_ioctl`. Since the `cl->object_count` comes from a `__u32` which is the user-supplied value.
Since the added bound check ensures the size is less than `INT_MAX`, and that value fits into `int object_count` - therefore, there is NO reason to change these types.
Finally, the existing checks around `object_count == 0` are consistent with the documentation. An empty lease is a valid option. If the user calls with `object_count == 0`, no allocations happen, which is fine. The existing code is correct here.
I believe this is a robust and safe change.
|
| 186/4 |
2026/10/13 22:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/slub.c Name:kmalloc_gfp_adjust]
Results: map[SourceCode:6976: static gfp_t kmalloc_gfp_adjust(gfp_t flags, size_t size)
6977: {
6978: /*
6979: * We want to attempt a large physically contiguous block first because
6980: * it is less likely to fragment multiple larger blocks and therefore
6981: * contribute to a long term fragmentation less than vmalloc fallback.
6982: * However make sure that larger requests are not too disruptive - i.e.
6983: * do not direct reclaim unless physically continuous memory is preferred
6984: * (__GFP_RETRY_MAYFAIL mode). We still kick in kswapd/kcompactd to
6985: * start working in the background
6986: */
6987: if (size > PAGE_SIZE) {
6988: flags |= __GFP_NOWARN;
6989:
6990: if (!(flags & __GFP_RETRY_MAYFAIL))
6991: flags &= ~__GFP_DIRECT_RECLAIM;
6992:
6993: /* nofail semantic is implemented by the vmalloc fallback */
6994: flags &= ~__GFP_NOFAIL;
6995: }
6996:
6997: return flags;
6998: }
SourceFile:mm/slub.c]
|
| 187/4 |
2026/10/13 22:58 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 99356
output: 35
thoughts: 3681
Thoughts: **Analysis and Refinement of DRM Lease Object Allocation**
Alright, let's break this down. My focus here is ensuring robustness and safety in the DRM lease object handling, specifically addressing potential integer overflows and memory allocation issues, as per the user's instructions.
First off, I need to understand that the system's allocation strategy is to use `kmalloc` with a fallback to `__vmalloc` in `kvmalloc`. I've determined that integer overflow is prevented by the check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;`. This check ensures that the requested `size` for allocation never exceeds `INT_MAX`, preventing the warning from `if (unlikely(size > INT_MAX))`.
Now, the core issue seems to revolve around potentially large user-controlled arrays, specifically the `object_ids` and `objects` arrays in `drm_mode_create_lease_ioctl`. The use of `vmemdup_array_user` is a good thing as it addresses the potential `-ENOMEM` errors that `memdup_array_user` could suffer when dealing with large arrays. This is because `vmemdup_array_user` gracefully falls back to `vmalloc`, which is better for this situation.
My next step is to examine the placement of the bounds check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))`. I'm going to put it after the `cl->flags` check, as that's early validation that doesn't involve unnecessary references or allocations. This allows for early error detection, reporting via `drm_dbg_lease()`, and prevents any further processing if the object count is excessive.
The existing code used `kfree` for `object_ids` and `objects` after `vmemdup_array_user` and `kvzalloc_objs` respectively. This is a potential bug because `vmalloc` returns memory that is *not* allocated with `kmalloc`. It is crucial to switch to `kvfree` when freeing the arrays. I've updated the code in both `drm_mode_create_lease_ioctl` and `fill_object_idr` from `kfree` to `kvfree`.
I've also confirmed that the necessary `#include <linux/slab.h>` is missing in `drm_lease.c`, which is required for `kvzalloc` and `kvfree`. I'll add this include to ensure proper function declaration.
Finally, I've checked the rest of the file `drivers/gpu/drm/drm_lease.c` and made sure there are no other allocations or similar coding patterns that I need to be concerned about. I made a thorough, line-by-line inspection of the file.
I also considered other error messages, and determined that the error message `drm_dbg_lease(dev, "invalid object count\n");` is more appropriate than others for the failed bounds check.
I did this carefully, given that I can't directly compile and test the changes. I'm very confident that these changes address the core vulnerability, provide the best overall solution for this memory management issue, and adhere to the guidelines.
|
| 188/4 |
2026/10/13 22:59 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:include/linux/slab.h Name:__alloc_objs]
Results: map[SourceCode: SourceFile:]
|
| 189/4 |
2026/10/13 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 103790
output: 34
thoughts: 22
Thoughts: Here's my thought process, as if I were thinking it:
**Digging into Kernel Memory Allocation**
Alright, I need to understand the memory allocation strategy, specifically how these object allocations are handled. My first move is to dive straight into the code. Let's start with a focused search. I'm going to use `grep` to hunt down the definition of `__alloc_objs` in `include/linux/slab.h`. That macro or function likely holds the key to the core logic I'm after. This should give me a good entry point to trace the allocation path.
|
| 190/4 |
2026/10/13 22:59 |
tool |
grepper |
0m
Args: map[Expression:#define __alloc_objs PathPrefixes:[include/linux/slab.h]]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1086- */
include/linux/slab.h:1087:#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
include/linux/slab.h-1088-({ \
]
|
| 191/4 |
2026/10/13 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 104088
output: 36
thoughts: 26
Thoughts: Okay, let's dive into this. Here's my thought process:
**Diving into Slab Allocation in `linux/slab.h`**
Alright, I need to understand this part of the kernel's memory management, and `include/linux/slab.h` seems like the right place to start. I'm going to use `read-file` to get a look at the file. Now, based on my understanding of this system, I'm going to jump to around line 1087. I'm expecting to find some interesting details there, hopefully related to slab cache structures, object allocation/deallocation, or perhaps some key function definitions. This line number is a general estimate, of course. My experience tells me that significant structures related to object management are often defined or declared around this point, so it's a good initial probe to assess the overall code. I'll read and analyze that section carefully. I'll be looking for things like the declaration of `kmem_cache` structures, slab allocation functions like `kmem_cache_alloc`, and potentially functions like `kmem_cache_free`. I know the kernel, and I know this is a hot spot, and it's time to dig in.
|
| 192/4 |
2026/10/13 22:59 |
tool |
read-file |
0m
Args: map[File:include/linux/slab.h FirstLine:1085 LineCount:40]
Results: map[Contents:1085: * allocated @TYPE objects, or NULL on failure.
1086: */
1087: #define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
1088: ({ \
1089: const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \
1090: (TYPE *)KMALLOC(__obj_size, GFP); \
1091: })
1092:
1093: /**
1094: * __alloc_flex - Allocate an object that has a trailing flexible array
1095: * @KMALLOC: kmalloc wrapper function to use for allocation.
1096: * @GFP: GFP flags for the allocation.
1097: * @TYPE: type of structure to allocate space for.
1098: * @FAM: The name of the flexible array member of @TYPE structure.
1099: * @COUNT: how many @FAM elements to allocate space for.
1100: *
1101: * Returns: Newly allocated pointer to @TYPE with @COUNT-many trailing
1102: * @FAM elements, or NULL on failure or if @COUNT cannot be represented
1103: * by the member of @TYPE that counts the @FAM elements (annotated via
1104: * __counted_by()).
1105: */
1106: #define __alloc_flex(KMALLOC, GFP, TYPE, FAM, COUNT) \
1107: ({ \
1108: const size_t __count = (COUNT); \
1109: const size_t __obj_size = struct_size_t(TYPE, FAM, __count); \
1110: TYPE *__obj_ptr = KMALLOC(__obj_size, GFP); \
1111: if (__obj_ptr) \
1112: __set_flex_counter(__obj_ptr->FAM, __count); \
1113: __obj_ptr; \
1114: })
1115:
1116: /**
1117: * kmalloc_obj - Allocate a single instance of the given type
1118: * @VAR_OR_TYPE: Variable or type to allocate.
1119: * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified).
1120: *
1121: * Returns: newly allocated pointer to a @VAR_OR_TYPE on success, or NULL
1122: * on failure.
1123: */
1124: #define kmalloc_obj(VAR_OR_TYPE, ...) \
]
|
| 193/4 |
2026/10/13 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 105112
output: 35
thoughts: 781
Thoughts: **Analyzing Memory Allocation and Type Handling in DRM Lease Code**
Okay, let's break this down piece by piece. First, that macro, `__alloc_objs`: I see how it's used with `kvzalloc_objs`. The `TYPE` gets substituted with `struct drm_mode_object *`, `sizeof(TYPE)` becomes `sizeof(struct drm_mode_object *)`, and `KMALLOC` is `kvzalloc`. So, the return type becomes a `struct drm_mode_object **`, and the resulting pointer gets assigned directly to `objects`, which is also a `struct drm_mode_object **`. The compiler's happy, type-checking is fine, everything's working as expected here, a double pointer correctly allocated using `kvzalloc`.
Next, `vmemdup_array_user`: It looks like the core purpose is to safely duplicate an array of user-space data into kernel space, handling potential overflows. In `drm_mode_create_lease_ioctl`, the call uses `vmemdup_array_user` to copy `cl->object_ids`, which is of type `__u64`, using `u64_to_user_ptr` to get a `void __user *`. The critical type here is `sizeof(__u32)` as the size of each element in the array we're copying. The return `void *` from `vmemdup_array_user` works fine because of C's implicit pointer conversion to `uint32_t *` for assignment to `object_ids`. The subsequent use of `IS_ERR` and `PTR_ERR` is the standard way to check for errors returned as a pointer and retrieve the error code respectively, and finally `kvfree` is used to free the memory. This is exactly how `memdup_array_user` and `kfree` would have worked. I'm seeing this code handling the vmalloc fallback in a clean way for user space data.
Alright, now the critical part. What if `cl->object_count` gets too large? The code already includes a check:
```c
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
return -EINVAL;
}
```
The division `INT_MAX / sizeof(struct drm_mode_object *)` is intended to prevent an integer overflow in the size calculation. The check is present, but I must know if `INT_MAX` is visible and what it's type is in this context. Is it defined directly or being pulled in via an included header? I need to verify that `INT_MAX` is correctly defined and accessible within this particular `.c` file. I need to make sure that the definition of `INT_MAX` is correct for the architecture and that the integer division behaves correctly with respect to the desired bounds check. I will `grep` for `INT_MAX` in this file or look at included headers to be sure.
|
| 194/4 |
2026/10/13 22:59 |
tool |
grepper |
0m
Error:
Args: map[Expression:INT_MAX PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results:
|
| 195/4 |
2026/10/13 22:59 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 106613
output: 30
thoughts: 16
Thoughts: Okay, here's my summary, tailored for an expert audience, as if I'm thinking these things myself:
**Investigating the Definition of INT_MAX Across Kernel Headers**
Alright, I need to pinpoint the definition of `INT_MAX`. It's crucial, and I want to be *absolutely* sure where the canonical definition resides within the kernel header landscape. This isn't just about finding *a* definition; I need to know *the* definition the kernel relies on. I'm thinking cross-referencing and header file exploration. I need to be diligent about this, given the potential for subtle differences or overrides. I'm going to carefully track the various locations and any potential source of the definition, to make certain that the definition in question aligns with the rest of my work.
|
| 196/4 |
2026/10/13 22:59 |
tool |
grepper |
0m
Error:
Args: map[Expression:#define INT_MAX PathPrefixes:[include/linux/]]
Results:
|
| 197/4 |
2026/10/13 23:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 106841
output: 28
thoughts: 17
Thoughts: Here's a summary of my thought process:
**Where's That Maximum Integer Defined?**
Okay, so I need to find the definition of `INT_MAX`. It's a standard macro, so it's most likely in a standard header file. Given that this is likely a C or C++ codebase, my first instinct is to check the `include/` directory. That's the logical place where the project's developers, or the system itself, would house the standard headers. I'll navigate there and start looking. `limits.h` is the most obvious candidate, since it's the standard header for integer limits. I'll check that one first. If it's not there, I'll need to broaden my search. But, `limits.h` is the safe bet, and likely where I'll find my answer.
|
| 198/4 |
2026/10/13 23:00 |
tool |
grepper |
0m
Args: map[Expression:#define INT_MAX PathPrefixes:[include/]]
Results: map[Output:include/vdso/limits.h-7-#define SHRT_MIN ((short)(-SHRT_MAX - 1))
include/vdso/limits.h:8:#define INT_MAX ((int)(~0U >> 1))
include/vdso/limits.h-9-#define INT_MIN (-INT_MAX - 1)
]
|
| 199/4 |
2026/10/13 23:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 107162
output: 50
thoughts: 142
Thoughts: Here's my thought process, as it stands:
**Digging into Header Dependencies**
Okay, so I see that `include/linux/limits.h` pulls in `<vdso/limits.h>`. And that's interesting because `<linux/kernel.h>` also includes `<linux/limits.h>`. The real kicker is that pretty much *every* kernel file eventually includes `<linux/kernel.h>`. I need to figure out if `drm_lease.c` (or any file in this project) is *redundantly* including `<linux/limits.h>` through one of these header chains. That's the first thing I need to confirm.
To do that, I'll leverage my resources. Either I'll query `codeexpert` β if it's got up-to-date kernel knowledge β or I'll just dive into a direct code search. I'll need to know where `INT_MAX` is being used to tell.
I'll check if `INT_MAX` is used in any of the other `drivers/gpu/drm/*.c` files. That's a reasonable starting point, given the context. Then I'll expand that search to include any files in the `drivers/gpu/drm/` directory. Gotta make sure I'm not missing anything.
|
| 200/4 |
2026/10/13 23:00 |
tool |
grepper |
0m
Error:
Args: map[Expression:INT_MAX PathPrefixes:[drivers/gpu/drm/drm_ioctl.c drivers/gpu/drm/drm_crtc.c]]
Results:
|
| 201/4 |
2026/10/13 23:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 107654
output: 63
thoughts: 20
Thoughts: Okay, here's my summary, taking the perspective of someone familiar with kernel development and the DRM subsystem:
**Hunting for `INT_MAX` in the DRM Landscape**
Alright, I'm thinking I need to find all instances of `INT_MAX` within the DRM driver code. That's a classic code review target, right? Potential integer overflows, subtle bugs... you name it. It's time to use grep. Specifically, I'll restrict the search to the core DRM driver files. The intention is to identify any uses within the `drivers/gpu/drm/*.c` directory. This should zero in on the relevant code. Let's see what pops up. I'm expecting to find a few, and then I'll need to evaluate each case contextually to determine if it's correct usage, a potential bug, or perhaps some optimization opportunity. It's going to be interesting to see what the initial results are.
|
| 202/4 |
2026/10/13 23:00 |
tool |
grepper |
0m
Args: map[Expression:INT_MAX PathPrefixes:[drivers/gpu/drm/drm_atomic.c drivers/gpu/drm/drm_connector.c drivers/gpu/drm/drm_modes.c]]
Results: map[Output:drivers/gpu/drm/drm_atomic.c=784=static int drm_atomic_plane_check(const struct drm_plane_state *old_plane_state,
--
drivers/gpu/drm/drm_atomic.c-827- /* Give drivers some help against integer overflows */
drivers/gpu/drm/drm_atomic.c:828: if (new_plane_state->crtc_w > INT_MAX ||
drivers/gpu/drm/drm_atomic.c:829: new_plane_state->crtc_x > INT_MAX - (int32_t) new_plane_state->crtc_w ||
drivers/gpu/drm/drm_atomic.c:830: new_plane_state->crtc_h > INT_MAX ||
drivers/gpu/drm/drm_atomic.c:831: new_plane_state->crtc_y > INT_MAX - (int32_t) new_plane_state->crtc_h) {
drivers/gpu/drm/drm_atomic.c-832- drm_dbg_atomic(plane->dev,
--
drivers/gpu/drm/drm_modes.c=2660=int drm_mode_convert_umode(struct drm_device *dev,
--
drivers/gpu/drm/drm_modes.c-2663-{
drivers/gpu/drm/drm_modes.c:2664: if (in->clock > INT_MAX || in->vrefresh > INT_MAX)
drivers/gpu/drm/drm_modes.c-2665- return -ERANGE;
]
|
| 203/4 |
2026/10/13 23:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 108339
output: 40
thoughts: 835
Thoughts: **Analyzing Object Count Limits in DRM Lease Creation**
Okay, so I'm digging into the DRM code, specifically `drm_lease.c`, around line 490. I need to understand the object count checks in the lease creation process. First, I noticed that `INT_MAX` is available within the DRM file without needing a `limits.h` include, which is something I always keep in mind when parsing code.
Now, looking at the code, there's a check for `cl->object_count` to prevent an integer overflow when calculating the number of objects. The current code checks `cl->object_count` directly. My immediate thought was, "Could we move the assignment of `object_count = cl->object_count;` *before* the overflow check?" However, after a quick scan, it looks like that assignment actually happens later, and for good reason!
Then I thought again! I realized that `cl->object_count` is being checked directly against a limit based on `INT_MAX`. This is similar to the check on `cl->flags` immediately above. The checks on both `cl->flags` and `cl->object_count` are made early in the function, before any resource allocation or object referencing happens which is a good coding pattern for safety. It's consistent and efficient.
It hits me, the `cl` struct is being validated up front which is a good practice. They are both fields of the client's structure, `cl`, and are checked in sequence. This seems like a reasonable and robust approach.
Finally, just to be absolutely certain, I wanted to double-check the format specifier used in `drm_dbg_lease`. Specifically, I was curious if `%u` was appropriate for `__u32` which is the type of `cl->object_count`. I need to ensure it's not a print vulnerability. After a quick look, yep, `%u` is correct for an unsigned 32-bit integer. All checks out. I have to confirm the usage of `drm_dbg_lease` to make sure it is correct!
|
| 204/4 |
2026/10/13 23:00 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_dbg_lease]
Results: map[SourceCode: SourceFile:]
|
| 205/4 |
2026/10/13 23:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 109684
output: 20
thoughts: 12
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person:
**Investigating the `drm_dbg_lease` Code**
Alright, let's dive in. My first thought is to leverage the power of `grep`. Given the context, I'm likely dealing with debugging or investigating the Direct Rendering Manager (DRM) subsystem, and specifically, lease management. The presence of `drm_dbg_lease` strongly suggests a debug-related variable, function, or macro dedicated to lease functionality within the DRM. My goal is to quickly pinpoint its occurrences and context within the codebase. This initial `grep` operation is the fastest way to get a bird's-eye view, to understand where this thing is used. This will inform my next steps, whether I go digging through the surrounding code, check documentation, or trace call paths. This initial search should quickly uncover the declaration, initialization, and any usages of `drm_dbg_lease`. From there, I can start to understand its function and purpose within the broader DRM lease system.
|
| 206/4 |
2026/10/13 23:00 |
tool |
grepper |
0m
Args: map[Expression:define drm_dbg_lease]
Results: map[Output:include/drm/drm_print.h=608=static inline struct device *__drm_to_dev(const struct drm_device *drm)
--
include/drm/drm_print.h-661- drm_dev_dbg(__drm_to_dev(drm), DRM_UT_STATE, fmt, ##__VA_ARGS__)
include/drm/drm_print.h:662:#define drm_dbg_lease(drm, fmt, ...) \
include/drm/drm_print.h-663- drm_dev_dbg(__drm_to_dev(drm), DRM_UT_LEASE, fmt, ##__VA_ARGS__)
]
|
| 207/4 |
2026/10/13 23:00 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 110107
output: 36
thoughts: 2871
Thoughts: **Analysis of Lease Object Creation in DRM**
Okay, let's break this down. My initial thought was that adding `drm_dbg_lease` calls for cases of "too many objects" or "invalid object count" was a good practice, even if not directly removing a `WARN_ON`. I'm already seeing some good uses, let me examine...
I then focused on what would happen if `object_count` was zero, and confirmed it's correctly handled due to the conditional check with `object_count != 0`. Then, I moved on to larger values of `object_count` to stress the allocation routines and found the following: The integer division (`INT_MAX / sizeof(...)`) prevents large values, the memory allocation sizes are reasonable, the `vmemdup_array_user` copies safely into memory. The use of `kvzalloc` within the `fill_object_idr` function, with its fallback to `vmalloc`, seems robust, plus there is no call to `WARN_ON_ONCE_GFP`. All memory is deallocated using `kvfree`, regardless of successes or failures along the execution path.
Next, I considered error scenarios with `vmemdup_array_user` and `fill_object_idr` and ensured that the subsequent error handling, including the usage of `kvfree` for both `object_ids` and `objects`, is all correct and consistent, handling the case of `ERR_PTR` return values. Also, the check for `check_mul_overflow` in `vmemdup_array_user` seems appropriate and that the size of the objects would not overflow.
Next, I had to consider if the signed integer overflow in `object_count` was possible, as it is passed around. I investigated the function parameter types in `fill_object_idr`, specifically its `int object_count` to ensure it always correctly handles the maximum size. I quickly see that in all cases, `object_count` is less than `INT_MAX`, and that the `size_t` value passed into `int` in `fill_object_idr` is safe. I considered if it should be changed, but after further thought, keeping it the same and bounded makes sense.
After that, I made sure that the loop and object puts within `fill_object_idr` and the allocation size within `kvzalloc_objs` are properly handled, and the loop is clean, initializing each object pointer to NULL so they will be properly freed. I confirmed that the memory management functions are consistently being updated to `kvfree` from `kfree`. Also, the `memdup_array_user` has properly updated to `vmemdup_array_user`.
I verified the bounds check is correct, the inclusion of `<linux/slab.h>` is handled. I also confirmed through cross-referencing and git searches that `drm_mode_create_lease_ioctl` is called from the DRM ioctl table and that its signature and return types are consistent with other parts of the DRM code. I have verified that no new return error codes are necessary, as `-EINVAL` is already returned on invalid flags or parameters. I have searched the git history for the commit.
|
| 208/4 |
2026/10/13 23:01 |
tool |
git-log |
5m
Args: map[CodeRegexp:vmemdup_array_user PathPrefixes:drivers/gpu/drm]
Results: map[Output:0131a305886f drm/amdgpu: Remove output parameter in bo list handling
2a8e1e297cfc drm/amdgpu: Drop support for variable struct drm_amdgpu_bo_list_entry size
cb77b79abf5f drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
d4b6274cbf0b drm/amdgpu: Use (v)memdup_array_user in amdgpu_cs_pass1
c4ac100e9ae2 drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
2fe16088c3c7 tty/vt: use guard()s in con_font_set/get() and con_{set,get}_unimap()
7d78a7773355 string: Add additional __realloc_size() annotations for "dup" helpers
1f829359c8c3 KVM: Harden copying of userspace-array against overflow
573cc0e5cf14 KVM: x86: Harden copying of userspace-array against overflow
e651faa2fba4 drivers/tty/vt: use standard array-copy-functions
]
|
| 209/4 |
2026/10/13 23:06 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 114023
output: 25
thoughts: 23
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing Commit c4ac100e9ae2**
Alright, let's dive into commit `c4ac100e9ae2`. I need to understand the implications of this change. My initial focus will be on the direct code modifications. I'll probably start by checking the diff to identify the files touched and the key functions or data structures that were altered.
I'll be looking for potential regressions first and foremost. Does this commit introduce any subtle bugs, performance bottlenecks, or unintended side effects? I'll probably look for any test changes to start, since the tests should tell me about the intention of the commit. Was the existing test coverage modified, or were new tests written? If so, does the new testing cover the changes?
I will also be on the lookout for architectural implications. Did this commit introduce any dependencies, break existing abstractions, or necessitate changes in other parts of the system? I'll be thinking about the long-term maintainability of the codebase.
Finally, I'll consider the context. What was the purpose of this commit? Was it a bug fix, a feature addition, a refactoring, or something else entirely? Understanding the "why" will help me assess the quality of the solution and whether it aligns with the overall project goals. Time to get to work.
|
| 210/4 |
2026/10/13 23:06 |
tool |
git-show |
0m
Args:
Results: map[Output:commit c4ac100e9ae252b09986766ad23b1f83ca3a369d
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Thu Jun 12 11:44:26 2025 +0100
drm/amdgpu: Use vmemdup_array_user in amdgpu_bo_create_list_entry_array
Replace kvmalloc_array() + copy_from_user() with vmemdup_array_user() on
the fast path.
This shrinks the source code and improves separation between the kernel
and userspace slabs.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
index 702f6610d024..66fb37b64388 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c
@@ -184,43 +184,36 @@ void amdgpu_bo_list_put(struct amdgpu_bo_list *list)
int amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in,
struct drm_amdgpu_bo_list_entry **info_param)
{
- const void __user *uptr = u64_to_user_ptr(in->bo_info_ptr);
const uint32_t info_size = sizeof(struct drm_amdgpu_bo_list_entry);
+ const void __user *uptr = u64_to_user_ptr(in->bo_info_ptr);
+ const uint32_t bo_info_size = in->bo_info_size;
+ const uint32_t bo_number = in->bo_number;
struct drm_amdgpu_bo_list_entry *info;
- int r;
-
- info = kvmalloc_array(in->bo_number, info_size, GFP_KERNEL);
- if (!info)
- return -ENOMEM;
/* copy the handle array from userspace to a kernel buffer */
- r = -EFAULT;
- if (likely(info_size == in->bo_info_size)) {
- unsigned long bytes = in->bo_number *
- in->bo_info_size;
-
- if (copy_from_user(info, uptr, bytes))
- goto error_free;
-
+ if (likely(info_size == bo_info_size)) {
+ info = vmemdup_array_user(uptr, bo_number, info_size);
+ if (IS_ERR(info))
+ return PTR_ERR(info);
} else {
- unsigned long bytes = min(in->bo_info_size, info_size);
+ const uint32_t bytes = min(bo_info_size, info_size);
unsigned i;
- memset(info, 0, in->bo_number * info_size);
- for (i = 0; i < in->bo_number; ++i) {
- if (copy_from_user(&info[i], uptr, bytes))
- goto error_free;
+ info = kvmalloc_array(bo_number, info_size, GFP_KERNEL);
+ if (!info)
+ return -ENOMEM;
- uptr += in->bo_info_size;
+ memset(info, 0, bo_number * info_size);
+ for (i = 0; i < bo_number; ++i, uptr += bo_info_size) {
+ if (copy_from_user(&info[i], uptr, bytes)) {
+ kvfree(info);
+ return -EFAULT;
+ }
}
}
*info_param = info;
return 0;
-
-error_free:
- kvfree(info);
- return r;
}
int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
]
|
| 211/4 |
2026/10/13 23:06 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 115524
output: 26
thoughts: 45
Thoughts: Here's my summary, as if I were thinking these thoughts:
**Examining Commit d4b6274cbf0b**
Okay, let's take a quick look at commit `d4b6274cbf0b`. I remember that one; it was a while back. I'm specifically interested in its contribution to `drm/amdgpu`. From the commit message, the focus appears to be on replacing something with `(v)memdup_array_user` within the `amdgpu_cs_pass1` function. Right, so this is likely a security hardening or performance optimization concerning how user-space memory is handled within the command submission process. I need to refresh my memory on the context of `amdgpu_cs_pass1` itself. I'll need to think about how these functions fit into the command stream processing. And I should keep in mind potential race conditions.
|
| 212/4 |
2026/10/13 23:07 |
tool |
git-show |
0m
Args:
Results: map[Output:commit d4b6274cbf0b0ee92294d699f138b63aa4796ad0
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Thu Jun 12 11:44:28 2025 +0100
drm/amdgpu: Use (v)memdup_array_user in amdgpu_cs_pass1
Replace k(v)malloc_array() + copy_from_user() with (v)memdup_array_user().
This shrinks the source code and improves separation between the kernel
and userspace slabs.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index 0e41589a7f18..2e93d570153c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -178,25 +178,17 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
struct amdgpu_fpriv *fpriv = p->filp->driver_priv;
unsigned int num_ibs[AMDGPU_CS_GANG_SIZE] = { };
struct amdgpu_vm *vm = &fpriv->vm;
- uint64_t *chunk_array_user;
uint64_t *chunk_array;
uint32_t uf_offset = 0;
size_t size;
int ret;
int i;
- chunk_array = kvmalloc_array(cs->in.num_chunks, sizeof(uint64_t),
- GFP_KERNEL);
- if (!chunk_array)
- return -ENOMEM;
-
- /* get chunks */
- chunk_array_user = u64_to_user_ptr(cs->in.chunks);
- if (copy_from_user(chunk_array, chunk_array_user,
- sizeof(uint64_t)*cs->in.num_chunks)) {
- ret = -EFAULT;
- goto free_chunk;
- }
+ chunk_array = memdup_array_user(u64_to_user_ptr(cs->in.chunks),
+ cs->in.num_chunks,
+ sizeof(uint64_t));
+ if (IS_ERR(chunk_array))
+ return PTR_ERR(chunk_array);
p->nchunks = cs->in.num_chunks;
p->chunks = kvmalloc_array(p->nchunks, sizeof(struct amdgpu_cs_chunk),
@@ -209,7 +201,6 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
for (i = 0; i < p->nchunks; i++) {
struct drm_amdgpu_cs_chunk __user *chunk_ptr = NULL;
struct drm_amdgpu_cs_chunk user_chunk;
- uint32_t __user *cdata;
chunk_ptr = u64_to_user_ptr(chunk_array[i]);
if (copy_from_user(&user_chunk, chunk_ptr,
@@ -222,20 +213,16 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
p->chunks[i].length_dw = user_chunk.length_dw;
size = p->chunks[i].length_dw;
- cdata = u64_to_user_ptr(user_chunk.chunk_data);
- p->chunks[i].kdata = kvmalloc_array(size, sizeof(uint32_t),
- GFP_KERNEL);
- if (p->chunks[i].kdata == NULL) {
- ret = -ENOMEM;
+ p->chunks[i].kdata = vmemdup_array_user(u64_to_user_ptr(user_chunk.chunk_data),
+ size,
+ sizeof(uint32_t));
+ if (IS_ERR(p->chunks[i].kdata)) {
+ ret = PTR_ERR(p->chunks[i].kdata);
i--;
goto free_partial_kdata;
}
size *= sizeof(uint32_t);
- if (copy_from_user(p->chunks[i].kdata, cdata, size)) {
- ret = -EFAULT;
- goto free_partial_kdata;
- }
/* Assume the worst on the following checks */
ret = -EINVAL;
]
|
| 213/4 |
2026/10/13 23:07 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 117096
output: 199
thoughts: 339
Thoughts: **Analyzing `vmemdup_array_user` Usage and Safety**
Okay, so I've been reviewing this patch, and I've spotted a pattern with `vmemdup_array_user`. I see that in commit `d4b6274cbf0b`, it's used alongside `kvfree(p->chunks[i].kdata)`. Then, in commit `cb77b79abf5f`, the same function is used with `kvfree(handles)`. Now, I'm looking at this `drm_lease.c` file, and I'm noticing a similar pairing: `vmemdup_array_user` is being used with `kvfree(object_ids)`. That's the key thing.
My concern is to ensure these calls are truly balanced and don't introduce any subtle memory leaks or use-after-free scenarios. I need to make sure I haven't missed anything obvious. I'm going to run this by `codeexpert`. To that end, I'll formulate a precise question, covering all the bases.
Here's my question for `codeexpert`:
"In drivers/gpu/drm/drm_lease.c:
1. I'm changing `kzalloc_objs(struct drm_mode_object *, object_count)` to `kvzalloc_objs` and `kfree(objects)` to `kvfree(objects)` within the `fill_object_idr()` function.
2. In `drm_mode_create_lease_ioctl()`, I'm switching from `memdup_array_user(...)` to `vmemdup_array_user(...)` and replacing `kfree(object_ids)` with `kvfree(object_ids)`.
3. I'm adding an early check in `drm_mode_create_lease_ioctl()`: `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;`.
Are there any corner cases, lifetime issues, or missing includes/prerequisites that I need to be aware of with these proposed changes? I need to be completely sure that the memory management is sound and that I haven't inadvertently introduced a vulnerability or instability."
|
| 214/4 |
2026/10/13 23:07 |
tool |
codeexpert |
6m
Args: map[Question:In drivers/gpu/drm/drm_lease.c:
1. In fill_object_idr(), changing kzalloc_objs(struct drm_mode_object *, object_count) to kvzalloc_objs(struct drm_mode_object *, object_count) and kfree(objects) to kvfree(objects).
2. In drm_mode_create_lease_ioctl(), changing memdup_array_user() to vmemdup_array_user() and kfree(object_ids) to kvfree(object_ids).
3. In drm_mode_create_lease_ioctl(), adding an early check:
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;
Are there any corner cases, lifetime issues, or missing includes/prerequisites with these changes?]
Results: map[Answer:Analysis of the proposed changes in `drivers/gpu/drm/drm_lease.c`:
### 1. Lifetime Issues
* **Lessor Master Reference Leak (Corner Case / Placement Issue in Change 3)**:
* In `drm_mode_create_lease_ioctl()`, `lessor = drm_file_get_master(lessor_priv)` increments the reference count of the lessor (`drm_master`).
* If the early check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;` is placed **after** `drm_file_get_master()`, an immediate `return -EINVAL;` will **leak the lessor reference**.
* To avoid leaking `lessor`, the check must either be placed **before** `drm_file_get_master()` (e.g., right alongside the `cl->flags` check), or jump to `goto out_lessor;`.
* **Allocation Lifetimes (Changes 1 & 2)**:
* No lifetime issues with the allocated buffers.
* `objects` in `fill_object_idr()` is strictly local to the function: all acquired `drm_mode_object` references are released via `drm_mode_object_put()` before `kvfree(objects)` is called.
* `object_ids` in `drm_mode_create_lease_ioctl()` is strictly local to the ioctl and is freed with `kvfree(object_ids)` immediately after `fill_object_idr()` returns. Replacing `kfree()` with `kvfree()` correctly matches `vmemdup_array_user()`.
### 2. Corner Cases and Type Interactions
* **Signed vs Unsigned / Integer Overflow in `fill_object_idr()` and `validate_lease()`**:
* In `struct drm_mode_create_lease`, `cl->object_count` is `__u32`.
* However, `fill_object_idr()` and `validate_lease()` declare `object_count` as signed `int`, and `validate_lease()` uses `int o` as its loop counter.
* Without a bound on `cl->object_count`, passing a count $> \text{INT\_MAX}$ would result in sign overflow when converted to `int`. Checking `cl->object_count > INT_MAX / sizeof(...)` ensures that `object_count` fits safely in `int` without signed integer overflow.
* **Empty Leases (`object_count == 0`)**:
* An `object_count` of 0 is valid in DRM leasing (commit `4bb2d367a5a2 drm/lease: allow empty leases`). Because `0 <= INT_MAX / sizeof(...)`, the check correctly handles empty leases without triggering early rejection.
* **Error Return Code Difference**:
* Previously, allocating an excessively huge array via `memdup_array_user()` would return `-ENOMEM` (or `-EOVERFLOW` from `check_mul_overflow()`). Returning `-EINVAL` early changes the user-visible errno on oversized requests from `-ENOMEM`/`-EOVERFLOW` to `-EINVAL`.
### 3. Missing Includes / Prerequisites
* **`INT_MAX`**:
* Defined in `<linux/limits.h>`. `drivers/gpu/drm/drm_lease.c` does not explicitly include `<linux/limits.h>` or `<linux/kernel.h>`. While it may be pulled in transitively via other headers on some configs, `<linux/limits.h>` should be explicitly included.
* **`vmemdup_array_user`**:
* Defined in `<linux/string.h>`.
* **`kvzalloc_objs` and `kvfree`**:
* Defined in `<linux/slab.h>`. Explicit inclusion of `<linux/slab.h>` is recommended if not relying on transitive includes.]
|
| 215/5 |
2026/10/13 23:07 |
agent |
codeexpert |
6m
Model:
Results: map[Answer:Analysis of the proposed changes in `drivers/gpu/drm/drm_lease.c`:
### 1. Lifetime Issues
* **Lessor Master Reference Leak (Corner Case / Placement Issue in Change 3)**:
* In `drm_mode_create_lease_ioctl()`, `lessor = drm_file_get_master(lessor_priv)` increments the reference count of the lessor (`drm_master`).
* If the early check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;` is placed **after** `drm_file_get_master()`, an immediate `return -EINVAL;` will **leak the lessor reference**.
* To avoid leaking `lessor`, the check must either be placed **before** `drm_file_get_master()` (e.g., right alongside the `cl->flags` check), or jump to `goto out_lessor;`.
* **Allocation Lifetimes (Changes 1 & 2)**:
* No lifetime issues with the allocated buffers.
* `objects` in `fill_object_idr()` is strictly local to the function: all acquired `drm_mode_object` references are released via `drm_mode_object_put()` before `kvfree(objects)` is called.
* `object_ids` in `drm_mode_create_lease_ioctl()` is strictly local to the ioctl and is freed with `kvfree(object_ids)` immediately after `fill_object_idr()` returns. Replacing `kfree()` with `kvfree()` correctly matches `vmemdup_array_user()`.
### 2. Corner Cases and Type Interactions
* **Signed vs Unsigned / Integer Overflow in `fill_object_idr()` and `validate_lease()`**:
* In `struct drm_mode_create_lease`, `cl->object_count` is `__u32`.
* However, `fill_object_idr()` and `validate_lease()` declare `object_count` as signed `int`, and `validate_lease()` uses `int o` as its loop counter.
* Without a bound on `cl->object_count`, passing a count $> \text{INT\_MAX}$ would result in sign overflow when converted to `int`. Checking `cl->object_count > INT_MAX / sizeof(...)` ensures that `object_count` fits safely in `int` without signed integer overflow.
* **Empty Leases (`object_count == 0`)**:
* An `object_count` of 0 is valid in DRM leasing (commit `4bb2d367a5a2 drm/lease: allow empty leases`). Because `0 <= INT_MAX / sizeof(...)`, the check correctly handles empty leases without triggering early rejection.
* **Error Return Code Difference**:
* Previously, allocating an excessively huge array via `memdup_array_user()` would return `-ENOMEM` (or `-EOVERFLOW` from `check_mul_overflow()`). Returning `-EINVAL` early changes the user-visible errno on oversized requests from `-ENOMEM`/`-EOVERFLOW` to `-EINVAL`.
### 3. Missing Includes / Prerequisites
* **`INT_MAX`**:
* Defined in `<linux/limits.h>`. `drivers/gpu/drm/drm_lease.c` does not explicitly include `<linux/limits.h>` or `<linux/kernel.h>`. While it may be pulled in transitively via other headers on some configs, `<linux/limits.h>` should be explicitly included.
* **`vmemdup_array_user`**:
* Defined in `<linux/string.h>`.
* **`kvzalloc_objs` and `kvfree`**:
* Defined in `<linux/slab.h>`. Explicit inclusion of `<linux/slab.h>` is recommended if not relying on transitive includes.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: In drivers/gpu/drm/drm_lease.c:
1. In fill_object_idr(), changing kzalloc_objs(struct drm_mode_object *, object_count) to kvzalloc_objs(struct drm_mode_object *, object_count) and kfree(objects) to kvfree(objects).
2. In drm_mode_create_lease_ioctl(), changing memdup_array_user() to vmemdup_array_user() and kfree(object_ids) to kvfree(object_ids).
3. In drm_mode_create_lease_ioctl(), adding an early check:
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;
Are there any corner cases, lifetime issues, or missing includes/prerequisites with these changes?
|
| 216/6 |
2026/10/13 23:07 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4470
output: 38
thoughts: 318
Thoughts: **Analyzing Potential Issues in DRM Lease Code Changes**
Okay, let's break this down. The user is asking about potential problems with a few code modifications in `drivers/gpu/drm/drm_lease.c`, specifically related to memory allocation and size limits. My immediate thought is to meticulously assess each change in the context of the surrounding code.
First, the `fill_object_idr()` function: the suggestion involves switching from `kzalloc_objs` to `kvzalloc_objs` and from `kfree` to `kvfree`. Right off the bat, I need to confirm whether `kzalloc_objs` and `kvzalloc_objs` are even valid function calls. It's likely they are meant to be a variation of `kcalloc`, `kmalloc_array`, or similar memory allocation routines. I need to verify their actual definitions and usage within the kernel to understand the change's impact, especially regarding memory alignment and zero initialization. I'll need to scrutinize the allocation/deallocation patterns in that function, and whether any assumptions are made about the initial state of the memory.
Second, in `drm_mode_create_lease_ioctl()`, there's a proposed change from `memdup_array_user` to `vmemdup_array_user` and `kfree` to `kvfree`. This warrants closer examination. `memdup_array_user` is copying data from user space. The change suggests a `vmemdup` variant. The key here is to confirm that any differences in the functions aren't subtle, and correctly handle potential user-space input vulnerabilities. The change to `kvfree` needs to be considered along with the allocation function being used. The deallocation *must* match the allocation.
Finally, the addition of an early check for `cl->object_count` exceeding `INT_MAX / sizeof(struct drm_mode_object *)` is a good practice. It's designed to prevent integer overflows and potentially out-of-memory errors due to overly large object counts. However, I have to ensure that the check is placed correctly, that the logic is sound and correctly handles all reasonable input. There might be some edge cases to consider when dealing with large numbers, and how they interact with existing code.
Before I jump to conclusions, I need to thoroughly read and understand the sections of `drivers/gpu/drm/drm_lease.c` around `fill_object_idr` and `drm_mode_create_lease_ioctl` in order to determine any corner cases, lifetimes, or missing includes or prerequisites related to these changes.
|
| 217/6 |
2026/10/13 23:07 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:1 LineCount:100]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0-or-later
2: /*
3: * Copyright Β© 2017 Keith Packard <keithp@keithp.com>
4: */
5: #include <linux/file.h>
6: #include <linux/uaccess.h>
7:
8: #include <drm/drm_auth.h>
9: #include <drm/drm_crtc.h>
10: #include <drm/drm_drv.h>
11: #include <drm/drm_file.h>
12: #include <drm/drm_lease.h>
13: #include <drm/drm_print.h>
14:
15: #include "drm_crtc_internal.h"
16: #include "drm_internal.h"
17:
18: /**
19: * DOC: drm leasing
20: *
21: * DRM leases provide information about whether a DRM master may control a DRM
22: * mode setting object. This enables the creation of multiple DRM masters that
23: * manage subsets of display resources.
24: *
25: * The original DRM master of a device 'owns' the available drm resources. It
26: * may create additional DRM masters and 'lease' resources which it controls
27: * to the new DRM master. This gives the new DRM master control over the
28: * leased resources until the owner revokes the lease, or the new DRM master
29: * is closed. Some helpful terminology:
30: *
31: * - An 'owner' is a &struct drm_master that is not leasing objects from
32: * another &struct drm_master, and hence 'owns' the objects. The owner can be
33: * identified as the &struct drm_master for which &drm_master.lessor is NULL.
34: *
35: * - A 'lessor' is a &struct drm_master which is leasing objects to one or more
36: * other &struct drm_master. Currently, lessees are not allowed to
37: * create sub-leases, hence the lessor is the same as the owner.
38: *
39: * - A 'lessee' is a &struct drm_master which is leasing objects from some
40: * other &struct drm_master. Each lessee only leases resources from a single
41: * lessor recorded in &drm_master.lessor, and holds the set of objects that
42: * it is leasing in &drm_master.leases.
43: *
44: * - A 'lease' is a contract between the lessor and lessee that identifies
45: * which resources may be controlled by the lessee. All of the resources
46: * that are leased must be owned by or leased to the lessor, and lessors are
47: * not permitted to lease the same object to multiple lessees.
48: *
49: * The set of objects any &struct drm_master 'controls' is limited to the set
50: * of objects it leases (for lessees) or all objects (for owners).
51: *
52: * Objects not controlled by a &struct drm_master cannot be modified through
53: * the various state manipulating ioctls, and any state reported back to user
54: * space will be edited to make them appear idle and/or unusable. For
55: * instance, connectors always report 'disconnected', while encoders
56: * report no possible crtcs or clones.
57: *
58: * Since each lessee may lease objects from a single lessor, display resource
59: * leases form a tree of &struct drm_master. As lessees are currently not
60: * allowed to create sub-leases, the tree depth is limited to 1. All of
61: * these get activated simultaneously when the top level device owner changes
62: * through the SETMASTER or DROPMASTER IOCTL, so &drm_device.master points to
63: * the owner at the top of the lease tree (i.e. the &struct drm_master for which
64: * &drm_master.lessor is NULL). The full list of lessees that are leasing
65: * objects from the owner can be searched via the owner's
66: * &drm_master.lessee_idr.
67: */
68:
69: #define drm_for_each_lessee(lessee, lessor) \
70: list_for_each_entry((lessee), &(lessor)->lessees, lessee_list)
71:
72: static uint64_t drm_lease_idr_object;
73:
74: struct drm_master *drm_lease_owner(struct drm_master *master)
75: {
76: while (master->lessor != NULL)
77: master = master->lessor;
78: return master;
79: }
80:
81: static struct drm_master*
82: _drm_find_lessee(struct drm_master *master, int lessee_id)
83: {
84: lockdep_assert_held(&master->dev->mode_config.idr_mutex);
85: return idr_find(&drm_lease_owner(master)->lessee_idr, lessee_id);
86: }
87:
88: static int _drm_lease_held_master(struct drm_master *master, int id)
89: {
90: lockdep_assert_held(&master->dev->mode_config.idr_mutex);
91: if (master->lessor)
92: return idr_find(&master->leases, id) != NULL;
93: return true;
94: }
95:
96: /* Checks if the given object has been leased to some lessee of drm_master */
97: static bool _drm_has_leased(struct drm_master *master, int id)
98: {
99: struct drm_master *lessee;
100:
]
|
| 218/6 |
2026/10/13 23:07 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7037
output: 48
thoughts: 42
Thoughts: Okay, let's dive into this. Here's how I'd approach summarizing the code, thinking like a seasoned developer in this domain:
**Analyzing `drivers/gpu/drm/drm_lease.c`**
Alright, I'm heading into `drivers/gpu/drm/drm_lease.c` to see what's going on. Specifically, I need to get a handle on how these leases are implemented in the DRM subsystem, so I'll be homing in on the `fill_object_idr` and `drm_mode_create_lease_ioctl` functions. The former likely deals with populating an IDR (Integer ID Registry) with lease-related objects, and the latter is probably the ioctl that handles the creation of a lease. I need to understand how the IDR is used to track the leased objects. I'll be looking for things like how objects are allocated and deallocated within the IDR, any locking mechanisms used to protect the IDR, and how the information is being passed to the user space through the `ioctl` call. I expect `fill_object_idr` to handle the IDR population in a thread safe manner, considering that multiple processes could be creating and using leases simultaneously. I'll keep an eye out for potential race conditions and how the code mitigates them. Specifically, I'm interested in the security aspect of this design - how are these leases created and managed? What permissions are being checked? I'll also look for error handling; I'm curious what happens if something goes wrong during lease creation or object registration.
|
| 219/6 |
2026/10/13 23:07 |
tool |
grepper |
0m
Args: map[Expression:fill_object_idr|drm_mode_create_lease_ioctl PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results: map[Output:drivers/gpu/drm/drm_lease.c=346=static int validate_lease(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-377-
drivers/gpu/drm/drm_lease.c:378:static int fill_object_idr(struct drm_device *dev,
drivers/gpu/drm/drm_lease.c-379- struct drm_file *lessor_priv,
--
drivers/gpu/drm/drm_lease.c-474- */
drivers/gpu/drm/drm_lease.c:475:int drm_mode_create_lease_ioctl(struct drm_device *dev,
drivers/gpu/drm/drm_lease.c-476- void *data, struct drm_file *lessor_priv)
--
drivers/gpu/drm/drm_lease.c-520- /* fill and validate the object idr */
drivers/gpu/drm/drm_lease.c:521: ret = fill_object_idr(dev, lessor_priv, &leases,
drivers/gpu/drm/drm_lease.c-522- object_count, object_ids);
--
drivers/gpu/drm/drm_lease.c-572- drm_master_put(&lessor);
drivers/gpu/drm/drm_lease.c:573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
drivers/gpu/drm/drm_lease.c-574- return 0;
--
drivers/gpu/drm/drm_lease.c-583- drm_master_put(&lessor);
drivers/gpu/drm/drm_lease.c:584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
drivers/gpu/drm/drm_lease.c-585- return ret;
]
|
| 220/6 |
2026/10/13 23:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 7951
output: 40
thoughts: 48
Thoughts: Okay, let's dive into `drivers/gpu/drm/drm_lease.c`. Specifically, I want to refresh my memory on the lease creation process, so I'll zero in on `fill_object_idr` and `drm_mode_create_lease_ioctl`, covering lines 375 to 600. I need to understand how the DRM subsystem manages and tracks leased objects. Specifically, I'm thinking about the object ID assignment within the IDR and the actual IOCTL implementation for lease creation. I'm going to pay close attention to the data structures involved, the locking mechanisms used, and the error handling flow. This should refresh my knowledge of the interaction between the driver and the kernel within the context of hardware leasing.
|
| 221/6 |
2026/10/13 23:08 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:375 LineCount:100]
Results: map[Contents: 375: return 0;
376: }
377:
378: static int fill_object_idr(struct drm_device *dev,
379: struct drm_file *lessor_priv,
380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
468:
469: /*
470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
]
|
| 222/6 |
2026/10/13 23:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 9788
output: 40
thoughts: 30
Thoughts: Okay, let's dive into this `drm_mode_create_lease_ioctl` function, specifically focusing on lines 470 to 590. My immediate thought is, what are we trying to achieve here? This ioctl likely deals with the allocation or establishment of some kind of lease related to DRM modes β very interesting. I need to understand the control flow, the data structures involved, and the potential error conditions handled within this section. Given the length, it's probably handling several steps of the lease creation process. I expect to see allocations, permission checks, perhaps some synchronization primitives, and definitely some error handling. Let's see how they've chosen to implement this in the kernel. This is probably a critical part for security and resource management within the display system. Iβm keen to see if they're employing any innovative strategies or whether itβs a standard approach. Let's get reading and dissect this.
|
| 223/6 |
2026/10/13 23:08 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:470 LineCount:100]
Results: map[Contents: 470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
475: int drm_mode_create_lease_ioctl(struct drm_device *dev,
476: void *data, struct drm_file *lessor_priv)
477: {
478: struct drm_mode_create_lease *cl = data;
479: size_t object_count;
480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
540: /* lessee will take the ownership of leases */
541: lessee = drm_lease_create(lessor, &leases);
542:
543: if (IS_ERR(lessee)) {
544: ret = PTR_ERR(lessee);
545: idr_destroy(&leases);
546: goto out_leases;
547: }
548:
549: /* Clone the lessor file to create a new file for us */
550: drm_dbg_lease(dev, "Allocating lease file\n");
551: lessee_file = file_clone_open(lessor_file);
552: if (IS_ERR(lessee_file)) {
553: ret = PTR_ERR(lessee_file);
554: goto out_lessee;
555: }
556:
557: lessee_priv = lessee_file->private_data;
558: /* Change the file to a master one */
559: drm_master_put(&lessee_priv->master);
560: lessee_priv->master = lessee;
561: lessee_priv->is_master = 1;
562: lessee_priv->authenticated = 1;
563:
564: /* Pass fd back to userspace */
565: drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
566: cl->fd = fd;
567: cl->lessee_id = lessee->lessee_id;
568:
569: /* Hook up the fd */
]
|
| 224/6 |
2026/10/13 23:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 11610
output: 39
thoughts: 21
Thoughts: Okay, here's the summary, rendered as a first-person account, focusing on the specified task, assuming the user is an expert.
**Analyzing the Concluding Section**
Alright, I'm diving back in. I've been working my way through this document, but I want to make sure I grasp the final arguments in their entirety. Let me just skip ahead to lines 570-600. It's often the concluding section that really crystallizes the core claims and ties everything together. I want to see how this wraps up, what nuances are added, and if there are any subtle shifts in the author's position from earlier points. Often, the conclusion will bring in a summarization of all that has come before, and I am especially curious as to what points will be emphasized as well as what will be left out. I'll need to pay close attention to the rhetoric, too β see if the tone solidifies or softens the argument. I want to get the final flavor of the piece. I'm looking for a clean, strong finish here, not a rushed or ambiguous one, especially in the conclusion.
|
| 225/6 |
2026/10/13 23:08 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:569 LineCount:35]
Results: map[Contents: 569: /* Hook up the fd */
570: fd_install(fd, lessee_file);
571:
572: drm_master_put(&lessor);
573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
574: return 0;
575:
576: out_lessee:
577: drm_master_put(&lessee);
578:
579: out_leases:
580: put_unused_fd(fd);
581:
582: out_lessor:
583: drm_master_put(&lessor);
584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
585: return ret;
586: }
587:
588: int drm_mode_list_lessees_ioctl(struct drm_device *dev,
589: void *data, struct drm_file *lessor_priv)
590: {
591: struct drm_mode_list_lessees *arg = data;
592: __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr);
593: __u32 count_lessees = arg->count_lessees;
594: struct drm_master *lessor, *lessee;
595: int count;
596: int ret = 0;
597:
598: if (arg->pad)
599: return -EINVAL;
600:
601: /* Can't lease without MODESET */
602: if (!drm_core_check_feature(dev, DRIVER_MODESET))
603: return -EOPNOTSUPP;
]
|
| 226/6 |
2026/10/13 23:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 12455
output: 23
thoughts: 298
Thoughts: **Analyzing Proposed Lease Code Changes**
Okay, let's break this down. The question presents three specific changes in `drivers/gpu/drm/drm_lease.c` and asks for potential issues. First, I need to methodically dissect each alteration. I'm seeing changes in memory allocation and deallocation functions, and an integer overflow check being introduced. This raises a few immediate questions.
The first change is switching `kzalloc_objs` to `kvzalloc_objs` and `kfree` to `kvfree`. Right away, my alarm bells are going off. Are these functions even valid replacements? I know the kernel memory allocation ecosystem, but I need to be *sure*. This calls for immediate verification. Is `kvzalloc_objs` defined anywhere? And more critically, does `kzalloc_objs` exist in the kernel? I need to check both before proceeding. Let's go ahead and grep across the codebase to confirm their existence and usage. I'll search for *both* to ensure the proposed change makes sense and to understand where these functions are defined.
This initial analysis is crucial before jumping to broader concerns about lifetimes, corner cases, or missing dependencies. Need to establish that the basic building blocks are what they're supposed to be.
|
| 227/6 |
2026/10/13 23:08 |
tool |
grepper |
0m
Args: map[Expression:k(zalloc|vzalloc)_objs]
Results: map[Output:
Full output is too long, showing 200 out of 15737 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (1652 files in total):
Documentation/process/coding-style.rst:2
Documentation/process/deprecated.rst:1
Documentation/translations/it_IT/process/coding-style.rst:2
Documentation/translations/it_IT/process/deprecated.rst:1
Documentation/translations/pt_BR/process/deprecated.rst:1
arch/alpha/kernel/module.c:1
arch/arm/kernel/vdso.c:1
arch/arm/mach-footbridge/dc21285.c:1
arch/arm/mach-omap1/mcbsp.c:1
arch/arm/mach-omap2/omap_device.c:1
arch/arm/mach-omap2/pm33xx-core.c:1
arch/arm/mach-omap2/sr_device.c:1
arch/arm/mach-versatile/spc.c:1
arch/arm/xen/enlighten.c:1
arch/arm64/kernel/vdso.c:1
arch/arm64/kvm/nested.c:1
arch/arm64/kvm/vgic/vgic-init.c:2
arch/arm64/kvm/vgic/vgic-irqfd.c:1
arch/arm64/kvm/vgic/vgic-v4.c:1
arch/arm64/net/bpf_jit_comp.c:1
arch/csky/kernel/vdso.c:1
arch/loongarch/kernel/vdso.c:1
arch/loongarch/kvm/intc/pch_pic.c:1
arch/mips/alchemy/common/clock.c:2
arch/mips/alchemy/common/dbdma.c:1
arch/mips/alchemy/common/platform.c:1
arch/mips/alchemy/devboards/platform.c:2
arch/mips/bcm47xx/buttons.c:4
arch/mips/kernel/smp-cps.c:3
arch/parisc/kernel/vdso.c:1
arch/parisc/net/bpf_jit_core.c:1
arch/powerpc/kernel/smp.c:1
arch/powerpc/kernel/vdso.c:1
arch/powerpc/kvm/e500_mmu.c:4
arch/powerpc/mm/drmem.c:2
arch/powerpc/perf/imc-pmu.c:7
arch/powerpc/perf/vpa-dtl.c:1
arch/powerpc/platforms/44x/pci.c:1
arch/powerpc/platforms/powernv/idle.c:1
arch/powerpc/platforms/powernv/memtrace.c:1
arch/powerpc/platforms/powernv/opal-async.c:1
arch/powerpc/platforms/powernv/opal-imc.c:1
arch/powerpc/platforms/powernv/opal-irqchip.c:1
arch/powerpc/platforms/powernv/opal-powercap.c:3
arch/powerpc/platforms/powernv/opal-psr.c:1
arch/powerpc/platforms/powernv/opal-sensor-groups.c:3
arch/powerpc/platforms/powernv/opal-sysparam.c:1
arch/powerpc/platforms/pseries/papr_platform_attributes.c:2
arch/powerpc/sysdev/mpic.c:1
arch/powerpc/sysdev/mpic_msgr.c:1
... and 1602 more files
Documentation/process/coding-style.rst=938=The kernel provides the following general purpose memory allocators:
Documentation/process/coding-style.rst:939:kmalloc(), kzalloc(), kmalloc_objs(), kzalloc_objs(), vmalloc(), and
Documentation/process/coding-style.rst-940-vzalloc(). Please refer to the API documentation for further information
--
Documentation/process/coding-style.rst=964=The preferred form for allocating a zeroed array is the following:
--
Documentation/process/coding-style.rst-967-
Documentation/process/coding-style.rst:968: p = kzalloc_objs(*p, n, ...);
Documentation/process/coding-style.rst-969-
--
Documentation/process/deprecated.rst=398=become, respectively::
--
Documentation/process/deprecated.rst-402- ptr = kmalloc_objs(*ptr, count [, gfp] );
Documentation/process/deprecated.rst:403: ptr = kzalloc_objs(*ptr, count [, gfp] );
Documentation/process/deprecated.rst-404- ptr = kmalloc_flex(*ptr, flex_member, count [, gfp] );
--
Documentation/translations/it_IT/process/coding-style.rst=940=Il kernel fornisce i seguenti assegnatori ad uso generico:
Documentation/translations/it_IT/process/coding-style.rst:941:kmalloc(), kzalloc(), kmalloc_objs(), kzalloc_objs(), vmalloc(), e vzalloc().
Documentation/translations/it_IT/process/coding-style.rst-942-Per maggiori informazioni, consultate la documentazione dell'API:
--
Documentation/translations/it_IT/process/coding-style.rst=965=Il modo preferito per assegnare un vettore a zero Γ¨ il seguente:
--
Documentation/translations/it_IT/process/coding-style.rst-968-
Documentation/translations/it_IT/process/coding-style.rst:969: p = kzalloc_objs(*p, n, ...);
Documentation/translations/it_IT/process/coding-style.rst-970-
--
Documentation/translations/it_IT/process/deprecated.rst=441=diventano, rispettivamente::
--
Documentation/translations/it_IT/process/deprecated.rst-445- ptr = kmalloc_objs(*ptr, count [, gfp] );
Documentation/translations/it_IT/process/deprecated.rst:446: ptr = kzalloc_objs(*ptr, count [, gfp] );
Documentation/translations/it_IT/process/deprecated.rst-447- ptr = kmalloc_flex(*ptr, flex_member, count [, gfp] );
--
Documentation/translations/pt_BR/process/deprecated.rst=410=tornam-se, respectivamente::
--
Documentation/translations/pt_BR/process/deprecated.rst-414- ptr = kmalloc_objs(*ptr, count [, gfp] );
Documentation/translations/pt_BR/process/deprecated.rst:415: ptr = kzalloc_objs(*ptr, count [, gfp] );
Documentation/translations/pt_BR/process/deprecated.rst-416- ptr = kmalloc_flex(*ptr, flex_member, count [, gfp] );
--
arch/alpha/kernel/module.c=64=module_frob_arch_sections(Elf64_Ehdr *hdr, Elf64_Shdr *sechdrs,
--
arch/alpha/kernel/module.c-95- nsyms = symtab->sh_size / sizeof(Elf64_Sym);
arch/alpha/kernel/module.c:96: chains = kzalloc_objs(struct got_entry, nsyms);
arch/alpha/kernel/module.c-97- if (!chains) {
--
arch/arm/kernel/vdso.c=169=static int __init vdso_init(void)
--
arch/arm/kernel/vdso.c-181- /* Allocate the VDSO text pagelist */
arch/arm/kernel/vdso.c:182: vdso_text_pagelist = kzalloc_objs(struct page *, text_pages);
arch/arm/kernel/vdso.c-183- if (vdso_text_pagelist == NULL)
--
arch/arm/mach-footbridge/dc21285.c=261=int __init dc21285_setup(int nr, struct pci_sys_data *sys)
--
arch/arm/mach-footbridge/dc21285.c-264-
arch/arm/mach-footbridge/dc21285.c:265: res = kzalloc_objs(struct resource, 2);
arch/arm/mach-footbridge/dc21285.c-266- if (!res) {
--
arch/arm/mach-omap1/mcbsp.c=292=static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
--
arch/arm/mach-omap1/mcbsp.c-296-
arch/arm/mach-omap1/mcbsp.c:297: omap_mcbsp_devices = kzalloc_objs(struct platform_device *, size);
arch/arm/mach-omap1/mcbsp.c-298- if (!omap_mcbsp_devices) {
--
arch/arm/mach-omap2/omap_device.c=131=static int omap_device_build_from_dt(struct platform_device *pdev)
--
arch/arm/mach-omap2/omap_device.c-158-
arch/arm/mach-omap2/omap_device.c:159: hwmods = kzalloc_objs(struct omap_hwmod *, oh_cnt);
arch/arm/mach-omap2/omap_device.c-160- if (!hwmods) {
--
arch/arm/mach-omap2/pm33xx-core.c=379=static int __init amx3_idle_init(struct device_node *cpu_node, int cpu)
--
arch/arm/mach-omap2/pm33xx-core.c-412-
arch/arm/mach-omap2/pm33xx-core.c:413: idle_states = kzalloc_objs(*idle_states, state_count);
arch/arm/mach-omap2/pm33xx-core.c-414- if (!idle_states)
--
arch/arm/mach-omap2/sr_device.c=30=static void __init sr_set_nvalues(struct omap_volt_data *volt_data,
--
arch/arm/mach-omap2/sr_device.c-41-
arch/arm/mach-omap2/sr_device.c:42: nvalue_table = kzalloc_objs(*nvalue_table, count);
arch/arm/mach-omap2/sr_device.c-43- if (!nvalue_table)
--
arch/arm/mach-versatile/spc.c=393=static int ve_spc_populate_opps(uint32_t cluster)
--
arch/arm/mach-versatile/spc.c-397-
arch/arm/mach-versatile/spc.c:398: opps = kzalloc_objs(*opps, MAX_OPPS);
arch/arm/mach-versatile/spc.c-399- if (!opps)
--
arch/arm/xen/enlighten.c=316=int __init arch_xen_unpopulated_init(struct resource **res)
--
arch/arm/xen/enlighten.c-343-
arch/arm/xen/enlighten.c:344: regs = kzalloc_objs(*regs, nr_reg);
arch/arm/xen/enlighten.c-345- if (!regs) {
--
arch/arm64/kernel/vdso.c=68=static int __init __vdso_init(enum vdso_abi abi)
--
arch/arm64/kernel/vdso.c-83-
arch/arm64/kernel/vdso.c:84: vdso_pagelist = kzalloc_objs(struct page *, vdso_info[abi].vdso_pages);
arch/arm64/kernel/vdso.c-85- if (vdso_pagelist == NULL)
--
arch/arm64/kvm/nested.c=83=int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
--
arch/arm64/kvm/nested.c-106-
arch/arm64/kvm/nested.c:107: tmp = kvzalloc_objs(*tmp, S2_MMU_PER_VCPU, GFP_KERNEL_ACCOUNT);
arch/arm64/kvm/nested.c-108- if (!tmp)
--
arch/arm64/kvm/vgic/vgic-init.c=204=static int kvm_vgic_dist_init(struct kvm *kvm, unsigned int nr_spis)
--
arch/arm64/kvm/vgic/vgic-init.c-213- dist->active_spis = (atomic_t)ATOMIC_INIT(0);
arch/arm64/kvm/vgic/vgic-init.c:214: dist->spis = kzalloc_objs(struct vgic_irq, nr_spis, GFP_KERNEL_ACCOUNT);
arch/arm64/kvm/vgic/vgic-init.c-215- if (!dist->spis)
--
arch/arm64/kvm/vgic/vgic-init.c=316=static int vgic_allocate_private_irqs_locked(struct kvm_vcpu *vcpu, u32 type)
--
arch/arm64/kvm/vgic/vgic-init.c-331-
arch/arm64/kvm/vgic/vgic-init.c:332: vgic_cpu->private_irqs = kzalloc_objs(struct vgic_irq,
arch/arm64/kvm/vgic/vgic-init.c-333- num_private_irqs,
--
arch/arm64/kvm/vgic/vgic-irqfd.c=142=int kvm_vgic_setup_default_irq_routing(struct kvm *kvm)
--
arch/arm64/kvm/vgic/vgic-irqfd.c-148-
arch/arm64/kvm/vgic/vgic-irqfd.c:149: entries = kzalloc_objs(*entries, nr, GFP_KERNEL_ACCOUNT);
arch/arm64/kvm/vgic/vgic-irqfd.c-150- if (!entries)
--
arch/arm64/kvm/vgic/vgic-v4.c=242=int vgic_v4_init(struct kvm *kvm)
--
arch/arm64/kvm/vgic/vgic-v4.c-258-
arch/arm64/kvm/vgic/vgic-v4.c:259: dist->its_vm.vpes = kzalloc_objs(*dist->its_vm.vpes, nr_vcpus,
arch/arm64/kvm/vgic/vgic-v4.c-260- GFP_KERNEL_ACCOUNT);
--
arch/arm64/net/bpf_jit_comp.c=2158=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
--
arch/arm64/net/bpf_jit_comp.c-2213-
arch/arm64/net/bpf_jit_comp.c:2214: ctx.offset = kvzalloc_objs(int, prog->len + 1);
arch/arm64/net/bpf_jit_comp.c-2215- if (ctx.offset == NULL)
--
arch/csky/kernel/vdso.c=17=static int __init vdso_init(void)
--
arch/csky/kernel/vdso.c-22- vdso_pagelist =
arch/csky/kernel/vdso.c:23: kzalloc_objs(struct page *, vdso_pages);
arch/csky/kernel/vdso.c-24- if (unlikely(vdso_pagelist == NULL)) {
--
arch/loongarch/kernel/vdso.c=45=static int __init init_vdso(void)
--
arch/loongarch/kernel/vdso.c-55- vdso_info.code_mapping.pages =
arch/loongarch/kernel/vdso.c:56: kzalloc_objs(struct page *, vdso_info.size / PAGE_SIZE);
arch/loongarch/kernel/vdso.c-57-
--
arch/loongarch/kvm/intc/pch_pic.c=413=static int kvm_setup_default_irq_routing(struct kvm *kvm)
--
arch/loongarch/kvm/intc/pch_pic.c-418-
arch/loongarch/kvm/intc/pch_pic.c:419: entries = kzalloc_objs(*entries, nr);
arch/loongarch/kvm/intc/pch_pic.c-420- if (!entries)
--
arch/mips/alchemy/common/clock.c=754=static int __init alchemy_clk_init_fgens(int ctype)
--
arch/mips/alchemy/common/clock.c-777-
arch/mips/alchemy/common/clock.c:778: a = kzalloc_objs(*a, 6);
arch/mips/alchemy/common/clock.c-779- if (!a)
--
arch/mips/alchemy/common/clock.c=960=static int __init alchemy_clk_setup_imux(int ctype)
--
arch/mips/alchemy/common/clock.c-998-
arch/mips/alchemy/common/clock.c:999: a = kzalloc_objs(*a, 6);
arch/mips/alchemy/common/clock.c-1000- if (!a)
--
arch/mips/alchemy/common/dbdma.c=1056=static int __init dbdma_setup(unsigned int irq, dbdev_tab_t *idtable)
--
arch/mips/alchemy/common/dbdma.c-1059-
arch/mips/alchemy/common/dbdma.c:1060: dbdev_tab = kzalloc_objs(dbdev_tab_t, DBDEV_TAB_SIZE);
arch/mips/alchemy/common/dbdma.c-1061- if (!dbdev_tab)
--
arch/mips/alchemy/common/platform.c=203=static int __init _new_usbres(struct resource **r, struct platform_device **d)
arch/mips/alchemy/common/platform.c-204-{
arch/mips/alchemy/common/platform.c:205: *r = kzalloc_objs(struct resource, 2);
arch/mips/alchemy/common/platform.c-206- if (!*r)
--
arch/mips/alchemy/devboards/platform.c=70=int __init db1x_register_pcmcia_socket(phys_addr_t pcmcia_attr_start,
--
arch/mips/alchemy/devboards/platform.c-91-
arch/mips/alchemy/devboards/platform.c:92: sr = kzalloc_objs(struct resource, cnt);
arch/mips/alchemy/devboards/platform.c-93- if (!sr)
--
arch/mips/alchemy/devboards/platform.c=154=int __init db1x_register_norflash(unsigned long size, int width,
--
arch/mips/alchemy/devboards/platform.c-166- ret = -ENOMEM;
arch/mips/alchemy/devboards/platform.c:167: parts = kzalloc_objs(struct mtd_partition, 5);
arch/mips/alchemy/devboards/platform.c-168- if (!parts)
--
arch/mips/bcm47xx/buttons.c=501=bcm47xx_buttons_add(const struct bcm47xx_gpio_key *buttons, int nbuttons)
--
arch/mips/bcm47xx/buttons.c-525- const struct software_node **node_group __free(kfree) =
arch/mips/bcm47xx/buttons.c:526: kzalloc_objs(*node_group, 1 + nbuttons + 1);
arch/mips/bcm47xx/buttons.c-527- if (!node_group)
--
arch/mips/bcm47xx/buttons.c-531- struct property_entry *props __free(kfree) =
arch/mips/bcm47xx/buttons.c:532: kzalloc_objs(*props, nbuttons * 3);
arch/mips/bcm47xx/buttons.c-533- if (!props)
--
arch/mips/bcm47xx/buttons.c-537- struct software_node *nodes __free(kfree) =
arch/mips/bcm47xx/buttons.c:538: kzalloc_objs(*nodes, 1 + nbuttons);
arch/mips/bcm47xx/buttons.c-539- if (!nodes)
]
|
| 228/6 |
2026/10/13 23:08 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 18474
output: 33
thoughts: 46
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Finding the Source: `kzalloc_objs` and `kvzalloc_objs`**
Right, let's track down the definitions for `kzalloc_objs` and `kvzalloc_objs`. These are obviously macros, likely related to kernel memory allocation, but I need to know precisely *where* they're defined. That's crucial for understanding their context and how they're used. Time to leverage `grep` β the workhorse! I'll target the preprocessor definitions directly. A simple search for `#define` followed by either of the target macros β `#define.*kzalloc_objs` and `#define.*kvzalloc_objs` β should get me the exact lines I'm after, making it quick to locate where these macros are declared. This approach is efficient and directly targets the desired information within the codebase.
|
| 229/6 |
2026/10/13 23:08 |
tool |
grepper |
0m
Args: map[Expression:#define (kzalloc_objs|kvzalloc_objs|kmalloc_objs)]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1135- */
include/linux/slab.h:1136:#define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \
include/linux/slab.h-1137- __alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), COUNT)
--
include/linux/slab.h-1156- __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1157:#define kzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1158- __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
--
include/linux/slab.h-1172- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1173:#define kvzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1174- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
--
tools/virtio/linux/kernel.h=63=static inline void *kmalloc_array(unsigned n, size_t s, gfp_t gfp)
--
tools/virtio/linux/kernel.h-70-
tools/virtio/linux/kernel.h:71:#define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \
tools/virtio/linux/kernel.h-72- ((typeof(VAR_OR_TYPE) *)kmalloc(sizeof(typeof(VAR_OR_TYPE)) * (COUNT), 0))
]
|
| 230/6 |
2026/10/13 23:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 19244
output: 36
thoughts: 51
Thoughts: Here's my take on the thought process:
**Diving into Slab Allocation Details**
Okay, I need to refresh my memory on the specifics of those kernel allocation functions, `kzalloc_objs`, `kvzalloc_objs`, and their kin. I seem to recall they're defined within the `slab.h` header, but I should double-check. I'll navigate to `include/linux/slab.h` and target around lines 1130 to 1180. That should give me the source for the `*zalloc_objs` definitions.
I'm particularly interested in the header files this code includes as a refresher on their dependencies. It's important to understand the layering and the interaction with other kernel subsystems when looking at allocation routines. I need to make sure I grasp the relevant structures and macros. Time to get down to specifics.
|
| 231/6 |
2026/10/13 23:09 |
tool |
read-file |
0m
Args: map[File:include/linux/slab.h FirstLine:1130 LineCount:55]
Results: map[Contents:1130: * @COUNT: How many elements in the array.
1131: * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified).
1132: *
1133: * Returns: newly allocated pointer to array of @VAR_OR_TYPE on success,
1134: * or NULL on failure.
1135: */
1136: #define kmalloc_objs(VAR_OR_TYPE, COUNT, ...) \
1137: __alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), COUNT)
1138:
1139: /**
1140: * kmalloc_flex - Allocate a single instance of the given flexible structure
1141: * @VAR_OR_TYPE: Variable or type to allocate (with its flex array).
1142: * @FAM: The name of the flexible array member of the structure.
1143: * @COUNT: How many flexible array member elements are desired.
1144: * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified).
1145: *
1146: * Returns: newly allocated pointer to @VAR_OR_TYPE on success, NULL on
1147: * failure. If @FAM has been annotated with __counted_by(), the allocation
1148: * will immediately fail if @COUNT is larger than what the type of the
1149: * struct's counter variable can represent.
1150: */
1151: #define kmalloc_flex(VAR_OR_TYPE, FAM, COUNT, ...) \
1152: __alloc_flex(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), FAM, COUNT)
1153:
1154: /* All kzalloc aliases for kmalloc_(obj|objs|flex). */
1155: #define kzalloc_obj(P, ...) \
1156: __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
1157: #define kzalloc_objs(P, COUNT, ...) \
1158: __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
1159: #define kzalloc_flex(P, FAM, COUNT, ...) \
1160: __alloc_flex(kzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
1161:
1162: /* All kvmalloc aliases for kmalloc_(obj|objs|flex). */
1163: #define kvmalloc_obj(P, ...) \
1164: __alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
1165: #define kvmalloc_objs(P, COUNT, ...) \
1166: __alloc_objs(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
1167: #define kvmalloc_flex(P, FAM, COUNT, ...) \
1168: __alloc_flex(kvmalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
1169:
1170: /* All kvzalloc aliases for kmalloc_(obj|objs|flex). */
1171: #define kvzalloc_obj(P, ...) \
1172: __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
1173: #define kvzalloc_objs(P, COUNT, ...) \
1174: __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
1175: #define kvzalloc_flex(P, FAM, COUNT, ...) \
1176: __alloc_flex(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), FAM, COUNT)
1177:
1178: #define kmem_buckets_alloc(_b, _size, _flags) \
1179: alloc_hooks(__kmalloc_node_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, NUMA_NO_NODE))
1180:
1181: #define kmem_buckets_alloc_node_track_caller(_b, _size, _flags, _node) \
1182: alloc_hooks(__kmalloc_node_track_caller_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), _flags, _node, _RET_IP_))
1183:
1184: #define kmem_buckets_alloc_track_caller(_b, _size, _flags) \
]
|
| 232/6 |
2026/10/13 23:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 20766
output: 36
thoughts: 39
Thoughts: Okay, let's dive into this. I need to understand the inner workings of `__alloc_objs`. Since I'm very familiar with kernel internals, I'll go straight to the source, looking at the header file. Specifically, I need to understand what's happening from line 1100 to 1135 in `include/linux/slab.h`. That should give me the relevant definitions and perhaps some inline comments to get a handle on the function's intended purpose and likely implementation details. From there, I'll be able to extrapolate to how it works within the broader memory allocation subsystem.
|
| 233/6 |
2026/10/13 23:09 |
tool |
read-file |
0m
Args: map[File:include/linux/slab.h FirstLine:1100 LineCount:35]
Results: map[Contents:1100: *
1101: * Returns: Newly allocated pointer to @TYPE with @COUNT-many trailing
1102: * @FAM elements, or NULL on failure or if @COUNT cannot be represented
1103: * by the member of @TYPE that counts the @FAM elements (annotated via
1104: * __counted_by()).
1105: */
1106: #define __alloc_flex(KMALLOC, GFP, TYPE, FAM, COUNT) \
1107: ({ \
1108: const size_t __count = (COUNT); \
1109: const size_t __obj_size = struct_size_t(TYPE, FAM, __count); \
1110: TYPE *__obj_ptr = KMALLOC(__obj_size, GFP); \
1111: if (__obj_ptr) \
1112: __set_flex_counter(__obj_ptr->FAM, __count); \
1113: __obj_ptr; \
1114: })
1115:
1116: /**
1117: * kmalloc_obj - Allocate a single instance of the given type
1118: * @VAR_OR_TYPE: Variable or type to allocate.
1119: * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified).
1120: *
1121: * Returns: newly allocated pointer to a @VAR_OR_TYPE on success, or NULL
1122: * on failure.
1123: */
1124: #define kmalloc_obj(VAR_OR_TYPE, ...) \
1125: __alloc_objs(kmalloc, default_gfp(__VA_ARGS__), typeof(VAR_OR_TYPE), 1)
1126:
1127: /**
1128: * kmalloc_objs - Allocate an array of the given type
1129: * @VAR_OR_TYPE: Variable or type to allocate an array of.
1130: * @COUNT: How many elements in the array.
1131: * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified).
1132: *
1133: * Returns: newly allocated pointer to array of @VAR_OR_TYPE on success,
1134: * or NULL on failure.
]
|
| 234/6 |
2026/10/13 23:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 21598
output: 34
thoughts: 26
Thoughts: Here's a summary of my thought process:
**Hunting Down the Definition of `__alloc_objs`**
Okay, so I see `__alloc_objs` and my first thought is, "Where the heck is that defined?" It's not a standard function I immediately recognize. Given that it's likely a memory allocation function, my next move is to check the header files for common memory allocation routines, specifically `include/linux/slab.h`. That's the most logical place to start digging for its declaration and likely its implementation details. Let's see if it's hiding in there.
|
| 235/6 |
2026/10/13 23:09 |
tool |
grepper |
0m
Args: map[Expression:#define __alloc_objs PathPrefixes:[include/linux/slab.h]]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1086- */
include/linux/slab.h:1087:#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
include/linux/slab.h-1088-({ \
]
|
| 236/6 |
2026/10/13 23:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 21903
output: 36
thoughts: 26
Thoughts: Okay, let's dive into this. Here's my take on those lines:
**Analyzing `include/linux/slab.h` - Lines 1080-1105**
Alright, I'm heading over to `include/linux/slab.h`, specifically lines 1080 to 1105. My brain immediately starts running through the implications. I'm expecting to see something pretty critical about the slab allocator's internals, probably related to object allocation, free lists, or maybe even some of the more advanced features like per-CPU caches or NUMA awareness. Given the range, it's likely a relatively concise block of code, probably defining a structure, a macro, or a key function used in the allocation path. I'm hoping I can glean information about data structures or algorithms employed in the slab allocator to improve the performance of object allocation and deallocation. Or perhaps an important piece of information on memory utilization. Let's get to it and see what's actually there. I'm ready to interpret the details as they unfold.
|
| 237/6 |
2026/10/13 23:09 |
tool |
read-file |
0m
Args: map[File:include/linux/slab.h FirstLine:1080 LineCount:26]
Results: map[Contents:1080: * @GFP: GFP flags for the allocation.
1081: * @TYPE: type to allocate space for.
1082: * @COUNT: how many @TYPE objects to allocate.
1083: *
1084: * Returns: Newly allocated pointer to (first) @TYPE of @COUNT-many
1085: * allocated @TYPE objects, or NULL on failure.
1086: */
1087: #define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
1088: ({ \
1089: const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \
1090: (TYPE *)KMALLOC(__obj_size, GFP); \
1091: })
1092:
1093: /**
1094: * __alloc_flex - Allocate an object that has a trailing flexible array
1095: * @KMALLOC: kmalloc wrapper function to use for allocation.
1096: * @GFP: GFP flags for the allocation.
1097: * @TYPE: type of structure to allocate space for.
1098: * @FAM: The name of the flexible array member of @TYPE structure.
1099: * @COUNT: how many @FAM elements to allocate space for.
1100: *
1101: * Returns: Newly allocated pointer to @TYPE with @COUNT-many trailing
1102: * @FAM elements, or NULL on failure or if @COUNT cannot be represented
1103: * by the member of @TYPE that counts the @FAM elements (annotated via
1104: * __counted_by()).
1105: */
]
|
| 238/6 |
2026/10/13 23:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 22647
output: 40
thoughts: 150
Thoughts: **Dissecting the Memory Allocation Macros**
Okay, so I'm looking at `__alloc_objs` and it's calling `KMALLOC` with some arguments: `GFP`, `TYPE`, and `COUNT`. Standard stuff, but hold on a minute, line 1173 has something interesting:
```c
#define kvzalloc_objs(P, COUNT, ...) \
__alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
```
Huh, `kvzalloc`... what's that? I need to check if `kvzalloc` is defined in `slab.h`, or somewhere else in the kernel memory management subsystem. That's unusual, I should know this.
And, if we're looking at allocation, where's the corresponding free function? Where is `kvfree` declared? And while I'm at it, I should also find where `vmemdup_array_user` is declared. Gotta get the full picture, so let's get searching.
|
| 239/6 |
2026/10/13 23:10 |
tool |
grepper |
0m
Args: map[Expression:(kvfree|vmemdup_array_user|kvzalloc)\( PathPrefixes:[include/]]
Results: map[Output:include/linux/bpfptr.h=68=static inline void *kvmemdup_bpfptr_noprof(bpfptr_t src, size_t len)
--
include/linux/bpfptr.h-74- if (copy_from_bpfptr(p, src, len)) {
include/linux/bpfptr.h:75: kvfree(p);
include/linux/bpfptr.h-76- return ERR_PTR(-EFAULT);
--
include/linux/fwctl.h=22=struct fwctl_ops {
--
include/linux/fwctl.h-53- * response pointer. Otherwise the returned pointer is freed with
include/linux/fwctl.h:54: * kvfree().
include/linux/fwctl.h-55- */
--
include/linux/kvm_host.h=1709=static inline void __kvm_arch_free_vm(struct kvm *kvm)
include/linux/kvm_host.h-1710-{
include/linux/kvm_host.h:1711: kvfree(kvm);
include/linux/kvm_host.h-1712-}
--
include/linux/ptr_ring.h=619=static inline int ptr_ring_resize_noprof(struct ptr_ring *r, int size, gfp_t gfp,
--
include/linux/ptr_ring.h-636-
include/linux/ptr_ring.h:637: kvfree(old);
include/linux/ptr_ring.h-638-
--
include/linux/ptr_ring.h=649=static inline int ptr_ring_resize_multiple_bh_noprof(struct ptr_ring **rings,
--
include/linux/ptr_ring.h-676- for (i = 0; i < nrings; ++i)
include/linux/ptr_ring.h:677: kvfree(queues[i]);
include/linux/ptr_ring.h-678-
--
include/linux/ptr_ring.h-684- while (--i >= 0)
include/linux/ptr_ring.h:685: kvfree(queues[i]);
include/linux/ptr_ring.h-686-
--
include/linux/ptr_ring.h=695=static inline void ptr_ring_cleanup(struct ptr_ring *r, void (*destroy)(void *))
--
include/linux/ptr_ring.h-701- destroy(ptr);
include/linux/ptr_ring.h:702: kvfree(r->queue);
include/linux/ptr_ring.h-703-}
--
include/linux/rcupdate.h=994=static inline void rcu_read_unlock_migrate(void)
--
include/linux/rcupdate.h-1096- *
include/linux/rcupdate.h:1097: * where @ptr is the pointer to be freed by kvfree().
include/linux/rcupdate.h-1098- *
--
include/linux/sbitmap.h=185=static inline void sbitmap_free(struct sbitmap *sb)
--
include/linux/sbitmap.h-187- free_percpu(sb->alloc_hint);
include/linux/sbitmap.h:188: kvfree(sb->map);
include/linux/sbitmap.h-189- sb->map = NULL;
--
include/linux/slab.h=1352=void *kvmalloc_node(size_t size, gfp_t flags, int node);
--
include/linux/slab.h-1358-#define kvmalloc_noprof(_size, _flags) kvmalloc_node_noprof(_size, _flags, NUMA_NO_NODE)
include/linux/slab.h:1359:#define kvzalloc(_size, _flags) kvmalloc(_size, (_flags)|__GFP_ZERO)
include/linux/slab.h-1360-
--
include/linux/slab.h=1385=void *kvrealloc_node_align_noprof(const void *p, DECL_TOKEN_PARAMS(size, token), unsigned long align,
--
include/linux/slab.h-1409- *
include/linux/slab.h:1410: * This function must not be called concurrently with itself or kvfree() for the
include/linux/slab.h-1411- * same memory allocation.
--
include/linux/slab.h=1415=void *kvrealloc_node_align(const void *p, size_t size, unsigned long align, gfp_t flags, int nid);
--
include/linux/slab.h-1421-
include/linux/slab.h:1422:extern void kvfree(const void *addr);
include/linux/slab.h:1423:DEFINE_FREE(kvfree, void *, if (!IS_ERR_OR_NULL(_T)) kvfree(_T))
include/linux/slab.h-1424-
--
include/linux/string.h=32=void *memdup_array_user(const void __user *src, size_t n, size_t size)
--
include/linux/string.h-48- * Return: an ERR_PTR() on failure. Result may be not
include/linux/string.h:49: * physically contiguous. Use kvfree() to free.
include/linux/string.h-50- */
include/linux/string.h=51=static inline __realloc_size(2, 3)
include/linux/string.h:52:void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
include/linux/string.h-53-{
--
include/net/fq_impl.h=349=static int fq_init(struct fq *fq, int flows_cnt)
--
include/net/fq_impl.h-366- if (!fq->flows_bitmap) {
include/net/fq_impl.h:367: kvfree(fq->flows);
include/net/fq_impl.h-368- fq->flows = NULL;
--
include/net/fq_impl.h=378=static void fq_reset(struct fq *fq,
--
include/net/fq_impl.h-385-
include/net/fq_impl.h:386: kvfree(fq->flows);
include/net/fq_impl.h-387- fq->flows = NULL;
--
include/net/inet_hashtables.h=207=static inline void inet_ehash_locks_free(struct inet_hashinfo *hashinfo)
include/net/inet_hashtables.h-208-{
include/net/inet_hashtables.h:209: kvfree(hashinfo->ehash_locks);
include/net/inet_hashtables.h-210- hashinfo->ehash_locks = NULL;
--
include/rdma/rdmavt_qp.h=955=static inline void rvt_free_rq(struct rvt_rq *rq)
include/rdma/rdmavt_qp.h-956-{
include/rdma/rdmavt_qp.h:957: kvfree(rq->kwq);
include/rdma/rdmavt_qp.h-958- rq->kwq = NULL;
--
include/trace/events/rcu.h=598=TRACE_EVENT_RCU(rcu_invoke_callback,
--
include/trace/events/rcu.h-621- * Tracepoint for the invocation of a single RCU callback of the special
include/trace/events/rcu.h:622: * kvfree() form. The first argument is the RCU flavor, the second
include/trace/events/rcu.h-623- * argument is a pointer to the RCU callback, and the third argument
]
|
| 240/6 |
2026/10/13 23:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 25075
output: 32
thoughts: 725
Thoughts: **Analyzing Potential Issues in DRM Lease Code**
Okay, so I'm looking at these proposed changes to `drivers/gpu/drm/drm_lease.c`, and my initial thought is, "Hey, `kvzalloc_objs`, `kvfree`, and `vmemdup_array_user` are already defined and used. They're part of standard headers!" It's a bit surprising the question even highlights these functions specifically as needing changes.
Let me take a look at the included headers within the file. I want to be certain that all prerequisites are met. Okay, the includes are: `<linux/file.h>`, `<linux/uaccess.h>`, and the DRM-specific headers: `<drm/drm_auth.h>`, `<drm/drm_crtc.h>`, `<drm/drm_drv.h>`, `<drm/drm_file.h>`, `<drm/drm_lease.h>`, `<drm/drm_print.h>`, along with some internal DRM headers.
The first thing I did was make sure I wasn't missing a header or importing some other function from slab.h or string.h.
I double-checked line 389 and 512 of `drm_lease.c` just to be sure... I see that `kzalloc_objs` is already being used at line 389 and `memdup_array_user` is at line 512. So, changing to the `kv` variants should be straightforward if the kernel configuration permits this.
The question also mentions an integer overflow check. That makes sense, a sanity check is always a good idea, particularly when dealing with user-supplied counts. And it is being added in the same function as `vmemdup_array_user`. That looks fine to me, a good addition.
My next step is to carefully re-read the question's focus. The question's intent is to assess whether there are any corner cases, lifetime issues, or missing includes/prerequisites with *these* specific changes. I see that the question is asking about these *specific* changes.
Therefore, my main concern becomes whether I'm missing something contextually, perhaps a subtlety within the DRM lease code or its interaction with other parts of the graphics stack. So, I will look at the `git log` for this file. It may reveal relevant recent patches, discussions, or bug reports that I need to be aware of.
|
| 241/6 |
2026/10/13 23:10 |
tool |
git-log |
0m
Args: map[Count:20 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
f37d63e219c3 drm_lease.c: copy user-array safely
cde3d37b19df drm: Remove unnecessary include statements for drm_crtc_helper.h
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
4bb2d367a5a2 drm/lease: allow empty leases
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
d793b8f732d6 drm: clarify usage of drm leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
7988fdf5f0a3 drm: Don't include drm_legacy.h in drm_lease.c
948de84233d3 drm : Insert blank lines after declarations.
b216a8e7908c drm/lease: fix WARNING in idr_destroy
c942fddf8793 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
0500c04ea14a drm: drop use of drmP.h in drm/*
46b757780dfe drm/lease: Check for lessor outside of locks
ae9d6c076c0d drm/lease: Drop recursive leads checks
e40b76428842 drm/leases: Drop object_id validation for negative ids
69ef943dbc14 drm: Use array_size() when creating lease
b5f06893c499 drm: Rename crtc_idr as object_idr to KMS cleanups
ce85882860f0 drm/lease: Send a distinct uevent
]
|
| 242/6 |
2026/10/13 23:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 26853
output: 27
thoughts: 36
Thoughts: Okay, here's my interpretation of that request, formatted for a user who's an expert in the field:
**Analyzing Commit f37d63e219c3: "drm_lease.c: copy user-array safely"**
Alright, let's dive into commit `f37d63e219c3`. I need to see this one; the description *specifically* mentions "copy user-array safely" within `drm_lease.c`. Given my experience, that phrase practically screams potential vulnerability and likely a very specific class of security concern related to user-space interactions in Direct Rendering Manager (DRM). I'm immediately thinking about race conditions, buffer overflows, or format string bugs β anything that could be exploited by malicious user-space code leveraging `drm_lease.c` to manipulate kernel memory or data structures. The emphasis on safety indicates someone was likely concerned about potential security flaws stemming from improper handling of data received from user space. I'm keen to see the specific mechanism used for the copy and how it's now safeguarded. My immediate concern is if it relates to a memory leak.
|
| 243/6 |
2026/10/13 23:10 |
tool |
git-show |
0m
Args:
Results: map[Output:commit f37d63e219c39199a59b8b8a211412ff27192830
Author: Philipp Stanner <pstanner@redhat.com>
Date: Wed Sep 20 14:36:12 2023 +0200
drm_lease.c: copy user-array safely
Currently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for
duplicating the user-space array safely.
Suggested-by: David Airlie <airlied@redhat.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230920123612.16914-6-pstanner@redhat.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 150fe1555068..94375c6a5425 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -510,8 +510,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
- array_size(object_count, sizeof(__u32)));
+ object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
]
|
| 244/6 |
2026/10/13 23:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 27757
output: 43
thoughts: 32
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in my code and referencing those specific commits:
**Diving Deep into Specific Commits**
Alright, I need to get laser-focused on these specific commits: `32a92f8c8932` and `69050f8d6d07`. It's pretty clear something's happening or changing, so I need to understand the relationship between them. I'm going to start by pulling up the diffs, examining the code changes, and tracing any dependencies that might have been impacted. I need to understand the intent of each commit individually, and *then* how they interact. Are these sequential changes addressing a single issue, or are they related in some other way? I need to look closely for any breaking changes, performance implications, or even subtle functional differences. I'm looking for the "why" behind these changes, not just the "what." This analysis is vital for understanding the flow, and any possible issues that may have occurred with the new versions of my work.
|
| 245/6 |
2026/10/13 23:10 |
tool |
git-show |
0m
Args: map[Commit:32a92f8c8932 File:drivers/gpu/drm/drm_lease.c]
Results: map[Output:commit 32a92f8c89326985e05dce8b22d3f0aa07a3e1bd
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat Feb 21 20:03:00 2026 -0800
Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
This converts some of the visually simpler cases that have been split
over multiple lines. I only did the ones that are easy to verify the
resulting diff by having just that final GFP_KERNEL argument on the next
line.
Somebody should probably do a proper coccinelle script for this, but for
me the trivial script actually resulted in an assertion failure in the
middle of the script. I probably had made it a bit _too_ trivial.
So after fighting that far a while I decided to just do some of the
syntactically simpler cases with variations of the previous 'sed'
scripts.
The more syntactically complex multi-line cases would mostly really want
whitespace cleanup anyway.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index f0a5cef17164..5d2cf724cbd7 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,8 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count,
- GFP_KERNEL);
+ objects = kzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
]
|
| 246/6 |
2026/10/13 23:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28592
output: 24
thoughts: 56
Thoughts: Here's a summary of my thought process, as requested:
**Diving into DRM Lease Fixes**
Alright, let's get down to brass tacks. I need to take a look at these two commits: `69ef943dbc14` ("drm: Use array_size() when creating lease") and `b216a8e7908c` ("drm/lease: fix WARNING in idr_destroy"). My initial thought is that these are likely related to recent issues I've been tracking concerning the Direct Rendering Manager (DRM) lease handling. The title of the first commit is pretty self-explanatory β I'm expecting to see a proper usage of `array_size()` to improve the clarity and maintainability of some memory allocation. It should be a straightforward change, aiming to prevent buffer overflows or size mismatches. I want to quickly evaluate the before-and-after and make sure it doesn't introduce any regressions, but the intent seems sound.
The second commit, `b216a8e7908c`, has a more concerning title; that "WARNING" flag is always something to pay attention to! An `idr_destroy` warning suggests potential memory corruption or a resource leak related to IDR (ID Radix Tree) management within the DRM lease framework. I need to check the patch and the context of the fix very carefully. I'll need to understand *why* the warning was triggered and confirm that the fix genuinely addresses the root cause and doesn't just silence it. I'll look for potential race conditions, incorrect cleanup routines, or improper usage of the IDR APIs. It's likely related to lease revocation or device detachment, but I'll need to go deeper to be sure. I'm especially interested in the exact warning message and the circumstances that trigger it. I need to ensure this fix doesn't introduce any new flaws in this already complex part of the kernel.
|
| 247/6 |
2026/10/13 23:10 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 69ef943dbc14b21987c79f8399ffea08f9a1b446
Author: Matthew Wilcox <willy@infradead.org>
Date: Thu Feb 14 11:03:48 2019 -0800
drm: Use array_size() when creating lease
Passing an object_count of sufficient size will make
object_count * 4 wrap around to be very small, then a later function
will happily iterate off the end of the object_ids array. Using
array_size() will saturate at SIZE_MAX, the kmalloc() will fail and
we'll return an -ENOMEM to the norty userspace.
Fixes: 62884cd386b8 ("drm: Add four ioctls for managing drm mode object leases [v7]")
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: <stable@vger.kernel.org> # v4.15+
Signed-off-by: Dave Airlie <airlied@redhat.com>
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 99cba8ea5d82..5df1256618cc 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -528,7 +528,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
object_count = cl->object_count;
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), object_count * sizeof(__u32));
+ object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
+ array_size(object_count, sizeof(__u32)));
if (IS_ERR(object_ids))
return PTR_ERR(object_ids);
]
|
| 248/6 |
2026/10/13 23:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 29670
output: 27
thoughts: 32
Thoughts: Okay, let's dive into this commit, `b216a8e7908c`, which is tagged as "drm/lease: fix WARNING in idr_destroy". I need to understand the context of the `idr_destroy` call within the DRM (Direct Rendering Manager) lease mechanism. This likely deals with resource management, specifically the releasing of IDs associated with leases. A "WARNING" suggests a potential issue, maybe a memory leak, use-after-free, or some kind of race condition during the destruction process. I'll need to scrutinize the code diff to understand where `idr_destroy` is being called and how the relevant structures are being managed, specifically focusing on the lease handling. I need to figure out the conditions that trigger the warning and, crucially, confirm the fix actually addresses the root cause correctly without introducing any regressions or new vulnerabilities. My immediate thought is to check if all necessary cleanup steps are being performed. I need to make sure this fix doesn't simply mask a more fundamental flaw by suppressing the warning, if I can, I can also review the testing done to see how well it covers this fix.
|
| 249/6 |
2026/10/13 23:10 |
tool |
git-show |
0m
Args:
Results: map[Output:commit b216a8e7908cd750550c0480cf7d2b3a37f06954
Author: Qiujun Huang <hqjagain@gmail.com>
Date: Wed Mar 18 15:53:50 2020 +0800
drm/lease: fix WARNING in idr_destroy
drm_lease_create takes ownership of leases. And leases will be released
by drm_master_put.
drm_master_put
->drm_master_destroy
->idr_destroy
So we needn't call idr_destroy again.
Reported-and-tested-by: syzbot+05835159fe322770fe3d@syzkaller.appspotmail.com
Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/1584518030-4173-1-git-send-email-hqjagain@gmail.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index b481cafdde28..825abe38201a 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -542,10 +542,12 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
}
DRM_DEBUG_LEASE("Creating lease\n");
+ /* lessee will take the ownership of leases */
lessee = drm_lease_create(lessor, &leases);
if (IS_ERR(lessee)) {
ret = PTR_ERR(lessee);
+ idr_destroy(&leases);
goto out_leases;
}
@@ -580,7 +582,6 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
out_leases:
put_unused_fd(fd);
- idr_destroy(&leases);
DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl failed: %d\n", ret);
return ret;
]
|
| 250/6 |
2026/10/13 23:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 30621
output: 42
thoughts: 1128
Thoughts: **Analyzing `drm_mode_create_lease_ioctl` and Proposed Changes**
Okay, let's break this down. I'm looking at the `drm_mode_create_lease_ioctl` function, and my initial thoughts are around the lease creation process. First, the function checks if modesetting is supported. Then, it validates the input flags and ensures we don't have recursive leases, which is good. It then handles the object count and processes the object IDs, using an IDR to manage the leased objects.
Now, those changes. Let's start with Change 1. Switching from `kzalloc_objs` and `kfree` to `kvzalloc_objs` and `kvfree` in `fill_object_idr`? That's about using vmalloc memory instead of the regular kernel allocator, which could be important for very large object counts or if dealing with fragmented memory. I need to remember why the original choice was made.
Change 2, in `drm_mode_create_lease_ioctl`, is similar: `memdup_array_user` to `vmemdup_array_user` and `kfree` to `kvfree`. Again, vmalloc usage. Makes sense, potentially for handling large user-provided arrays. The goal here is to deal with large `object_count` efficiently.
However, Change 3 is the one that's making me pause. Adding that early check: `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;`. This is an *integer overflow* protection, presumably to prevent a massive allocation request. But, *where* is it being added?
The crucial question is, *where* does this early check go in the function's execution flow? If it's *before* the call to `drm_file_get_master(lessor_priv)`, that's straightforward: we're doing a sanity check on the input *before* acquiring a reference to the master. But if it's *after* `drm_file_get_master(lessor_priv)`, that changes things.
Look at lines 499-505.
```c
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
drm_dbg_lease(dev, "recursive leasing not allowed\n");
ret = -EINVAL;
goto out_lessor;
}
```
If the new check is *after* this call, and the check fails, returning `-EINVAL`, we *have* already incremented the reference count on `lessor`. *That's a leak*. We need to be very careful to decrement the reference somehow. This check cannot be inserted after the master reference acquisition.
I need to quickly verify that `drm_file_get_master` does, in fact, increment a reference. I'll check the source of that function. I am thinking this check has to be before `drm_file_get_master`.
|
| 251/6 |
2026/10/13 23:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_file_get_master]
Results: map[SourceCode: 378: /**
379: * drm_file_get_master - reference &drm_file.master of @file_priv
380: * @file_priv: DRM file private
381: *
382: * Increments the reference count of @file_priv's &drm_file.master and returns
383: * the &drm_file.master. If @file_priv has no &drm_file.master, returns NULL.
384: *
385: * Master pointers returned from this function should be unreferenced using
386: * drm_master_put().
387: */
388: struct drm_master *drm_file_get_master(struct drm_file *file_priv)
389: {
390: struct drm_master *master = NULL;
391:
392: spin_lock(&file_priv->master_lookup_lock);
393: if (!file_priv->master)
394: goto unlock;
395: master = drm_master_get(file_priv->master);
396:
397: unlock:
398: spin_unlock(&file_priv->master_lookup_lock);
399: return master;
400: }
SourceFile:drivers/gpu/drm/drm_auth.c]
|
| 252/6 |
2026/10/13 23:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 32865
output: 42
thoughts: 290
Thoughts: **Vulnerability Assessment: Lease Object Count Overflow**
Okay, here's what's running through my mind. I'm looking at this code and immediately see a potential issue. If we place the return after `drm_file_get_master`, returning directly *before* a call to `drm_master_put(&lessor)` β or a `goto out_lessor` β we have a pretty clear resource leak of the `lessor` object. That's the obvious one.
But what if we shift things around? My immediate thought is, "What if it's placed before?" β and that makes me think there's some kind of integer overflow possibility.
My next step is to examine the types and parameter to check what `INT_MAX / sizeof(...)` is.
Hold on, let me look at `fill_object_idr`! I see it!
```c
static int fill_object_idr(struct drm_device *dev,
struct drm_file *lessor_priv,
struct idr *leases,
int object_count,
u32 *object_ids)
```
Wait! It's the parameter `int object_count`! I notice that `object_count` is of type `int`!
Okay, so I'm connecting the dots now. Let's see what happens within `drm_mode_create_lease_ioctl`:
```c
struct drm_mode_create_lease *cl = data;
size_t object_count;
...
object_count = cl->object_count;
```
Hold on, what is the type of `cl->object_count` in `struct drm_mode_create_lease`? I need to check the definition! This could be a classic integer overflow vulnerability. I think I have a good idea of what's going on now.
|
| 253/6 |
2026/10/13 23:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_create_lease]
Results: map[SourceCode:1425: /**
1426: * struct drm_mode_create_lease - Create lease
1427: *
1428: * Lease mode resources, creating another drm_master.
1429: *
1430: * The @object_ids array must reference at least one CRTC, one connector and
1431: * one plane if &DRM_CLIENT_CAP_UNIVERSAL_PLANES is enabled. Alternatively,
1432: * the lease can be completely empty.
1433: */
1434: struct drm_mode_create_lease {
1435: /** @object_ids: Pointer to array of object ids (__u32) */
1436: __u64 object_ids;
1437: /** @object_count: Number of object ids */
1438: __u32 object_count;
1439: /** @flags: flags for new FD (O_CLOEXEC, etc) */
1440: __u32 flags;
1441:
1442: /** @lessee_id: Return: unique identifier for lessee. */
1443: __u32 lessee_id;
1444: /** @fd: Return: file descriptor to new drm_master file */
1445: __u32 fd;
1446: };
SourceFile:include/uapi/drm/drm_mode.h]
|
| 254/6 |
2026/10/13 23:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 33998
output: 38
thoughts: 377
Thoughts: **Vulnerability Detection: Integer Overflow in DRM Lease Creation**
Okay, here's what's running through my head. I'm looking at this `drm_mode_create_lease_ioctl` function, specifically how it handles object counts. I see `cl->object_count` is defined as a `__u32`. Great. But then, inside this `ioctl`, they're assigning `cl->object_count` to a `size_t` variable called `object_count`. And, looking further, this `object_count` gets passed into `fill_object_idr`.
Now I need to check something... Right, `fill_object_idr` takes an *`int`* for the `object_count` parameter. Hmm... If `cl->object_count`, which is a `__u32` (so potentially a larger value) becomes larger than `INT_MAX`, what's going to happen when that value gets truncated down to an `int`? This is starting to look like an integer overflow vulnerability.
Let me think this through... the comparison looks like this `cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)`. Okay, that makes sense. We are concerned about the number of objects we can pass to the IDR. This means we're limiting the size of the objects. What's the size of the pointer? I know on a 64-bit system, a pointer is 8 bytes. On a 32-bit system, it's 4. So if we're on a 64-bit system, `INT_MAX / 8` would be around 2^28, or roughly 268 million objects. This is a bit high, but I'm thinking... why this exact calculation of integer division? I'll probably look into this later.
But wait, why am I only looking at this one place? There's `validate_lease`! Let me just quickly go over there and double check to see if something similar occurs there as well.
|
| 255/6 |
2026/10/13 23:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:validate_lease]
Results: map[SourceCode: 346: static int validate_lease(struct drm_device *dev,
347: int object_count,
348: struct drm_mode_object **objects,
349: bool universal_planes)
350: {
351: int o;
352: int has_crtc = -1;
353: int has_connector = -1;
354: int has_plane = -1;
355:
356: /* we want to confirm that there is at least one crtc, plane
357: connector object. */
358:
359: for (o = 0; o < object_count; o++) {
360: if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
361: has_crtc = o;
362: }
363: if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
364: has_connector = o;
365:
366: if (universal_planes) {
367: if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
368: has_plane = o;
369: }
370: }
371: if (has_crtc == -1 || has_connector == -1)
372: return -EINVAL;
373: if (universal_planes && has_plane == -1)
374: return -EINVAL;
375: return 0;
376: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 256/6 |
2026/10/13 23:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 35360
output: 38
thoughts: 144
Thoughts: **Analyzing Potential Integer Overflow Vulnerability**
Okay, let's dive into this code. My initial focus is on the `fill_object_idr` function and these loops:
```c
for (o = 0; o < object_count; o++) {
```
I see that `o` is declared as an `u32` here. However, I'm already noticing a potential discrepancy when I compare it to `validate_lease`, where `o` is an `int`. Furthermore, `object_count` itself is also an `int`. This has immediately raised a red flag. What happens if the `object_count`, and therefore the number of loops, is sufficiently large? The integer `o` could potentially overflow!
This smells like a possible vulnerability. I need to keep this in mind and dig deeper. The next thing I'll do is check out `vmemdup_array_user` to see if it's related. I'll examine its definition to understand its role in this system.
|
| 257/6 |
2026/10/13 23:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:vmemdup_array_user]
Results: map[SourceCode: 42: /**
43: * vmemdup_array_user - duplicate array from user space
44: * @src: source address in user space
45: * @n: number of array members to copy
46: * @size: size of one array member
47: *
48: * Return: an ERR_PTR() on failure. Result may be not
49: * physically contiguous. Use kvfree() to free.
50: */
51: static inline __realloc_size(2, 3)
52: void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
53: {
54: size_t nbytes;
55:
56: if (check_mul_overflow(n, size, &nbytes))
57: return ERR_PTR(-EOVERFLOW);
58:
59: return vmemdup_user(src, nbytes);
60: }
SourceFile:include/linux/string.h]
|
| 258/6 |
2026/10/13 23:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 36063
output: 36
thoughts: 23
Thoughts: Here's my thought process, as if I were considering this code:
**Diving into `vmemdup_user`**
Wait a minute, hold on! My focus just snapped to `vmemdup_user`. Okay, that function name immediately piques my interest. It strongly suggests a user-space memory duplication, meaning we're dealing with transferring data *from* user space *to* the kernel. That's a critical point for security and reliability. Now, the next logical question β where is `vmemdup_user` actually *defined*? I need to track down the implementation. Is it a core kernel function, or part of some module? What header files are included around it? I need the exact source to understand its behavior thoroughly. Understanding how it handles errors, permissions, and potential race conditions is paramount to determining its implications in the broader context of whatever I'm examining. I need that definition!
|
| 259/6 |
2026/10/13 23:11 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/string.h Name:vmemdup_user]
Results: map[SourceCode: 234: /**
235: * vmemdup_user - duplicate memory region from user space
236: *
237: * @src: source address in user space
238: * @len: number of bytes to copy
239: *
240: * Return: an ERR_PTR() on failure. Result may be not
241: * physically contiguous. Use kvfree() to free.
242: */
243: void *vmemdup_user(const void __user *src, size_t len)
244: {
245: void *p;
246:
247: p = kmem_buckets_valloc(user_buckets, len, GFP_USER);
248: if (!p)
249: return ERR_PTR(-ENOMEM);
250:
251: if (copy_from_user(p, src, len)) {
252: kvfree(p);
253: return ERR_PTR(-EFAULT);
254: }
255:
256: return p;
257: }
SourceFile:mm/util.c]
|
| 260/6 |
2026/10/13 23:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 36667
output: 34
thoughts: 382
Thoughts: **Investigating the Mystery of `kzalloc_objs` in `drm_lease.c`**
Okay, here's what's going through my mind as I dig into this. I'm starting by trying to get a lay of the land, specifically regarding what headers are included directly in `drivers/gpu/drm/drm_lease.c`. Let's confirm the included headers: `linux/file.h`, `linux/uaccess.h`, and then the DRM-specific ones like `drm/drm_auth.h`, `drm/drm_crtc.h`, `drm/drm_drv.h`, etc., down to `drm/drm_lease.h` and some internal DRM headers.
Now, my radar is up because I'm looking for indirect dependencies, or unexpected ones. I'm wondering if `<linux/slab.h>` is sneakily included through one of the DRM headers. I'm also curious about other potential suspects that might introduce memory allocation functions like `<linux/overflow.h>`, `<linux/string.h>`, or `<linux/limits.h>`.
The immediate goal is to understand how `kzalloc_objs` is getting pulled into the compilation. I need to figure out the include chain leading to `kzalloc_objs`. I know that `linux/slab.h` defines the functions like `kzalloc_objs`, `kvzalloc_objs`, and `kvfree`, so let's start there.
But wait a minute, how did `drm_lease.c` even *compile* with `kzalloc_objs`? Is this even a valid concern? It's essential to confirm that the code actually compiles. Where does `kzalloc_objs` come from within the context of `drm_lease.c`? What is the include hierarchy?
So, I'm going to systematically examine the include files within the DRM space, like `drm_crtc.h`, `drm_file.h`, and others. Then, I could grep the `include/drm/` directory for `slab.h` directly, or check which headers have it included. That should help me figure out the include path!
|
| 261/6 |
2026/10/13 23:11 |
tool |
grepper |
0m
Error:
Args: map[Expression:#include <linux/slab.h> PathPrefixes:[include/drm/]]
Results:
|
| 262/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 37561
output: 58
thoughts: 67
Thoughts: Here's my thought process, as if I were considering this issue:
**Investigating the Missing `<linux/slab.h>` Inclusion**
Okay, so I'm seeing something odd here. I was under the impression that the DRM headers might have a direct dependency on `<linux/slab.h>`, but it seems that's not the case based on what I'm seeing. I need to get a better handle on how memory allocation is handled within the DRM subsystem. Let me double-check a few key headers in `include/drm/` to be sure. I'll start with `drm_print.h`, `drm_crtc.h`, and a few others that seem like they might touch memory management. I really need to understand the inclusion paths and dependencies. If it's not a direct inclusion, where *is* it happening? I can't just assume anything here.
Alright, let's cut to the chase, I'm going to run a quick `grep` for `slab.h` directly within the `drivers/gpu/drm/` directory. That'll show me all the files that explicitly include it, allowing me to understand how slab allocation is incorporated at a lower level. Hopefully, I'll find the culprit and understand how it's being used.
|
| 263/6 |
2026/10/13 23:12 |
tool |
grepper |
0m
Error:
Args: map[Expression:#include <linux/slab.h> PathPrefixes:[drivers/gpu/drm/drm_crtc_internal.h drivers/gpu/drm/drm_internal.h]]
Results:
|
| 264/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 37974
output: 28
thoughts: 185
Thoughts: Okay, let's see. My objective is to pinpoint where `slab.h` is being included within the context of `drivers/gpu/drm/drm_lease.c`. That's a reasonable starting point for debugging some memory allocation issues, or understanding dependencies.
My first thought is to employ a good old `grep`. I'll scan through the include tree of `drm_lease.c` for `slab.h`. Before I launch the `grep`, I'd better confirm the includes to avoid wasting time.
Aha, looks like `drm_lease.c` includes:
* `<linux/file.h>`
* `<linux/uaccess.h>`
* `<drm/drm_auth.h>`
* `<drm/drm_crtc.h>`
* `<drm/drm_drv.h>`
* `<drm/drm_file.h>`
* `<drm/drm_lease.h>`
* `<drm/drm_print.h>`
* `"drm_crtc_internal.h"`
* `"drm_internal.h"`
Now I'll focus my `grep` on these headers. Based on my experience, it's quite likely that `slab.h` is included transitively. I'll start with the more generic headers, specifically `drm_print.h` and the other drm headers, as those are my best bets. Now it's time for the investigation!
|
| 265/6 |
2026/10/13 23:12 |
tool |
grepper |
0m
Error:
Args: map[Expression:slab.h PathPrefixes:[include/drm/]]
Results:
|
| 266/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 38521
output: 35
thoughts: 16
Thoughts: Okay, let's dive into this. Here's my summary, taking the first-person perspective as requested:
**Peeking Inside `drm/drm_drv.h`**
Alright, time to crack open `drm/drm_drv.h`. I need to get a clear picture of what this core header file pulls in. It's the foundation, the starting point for a lot of the Direct Rendering Manager driver work, so understanding its dependencies is crucial for any deeper analysis or debugging. I'm especially interested in the core structures and function prototypes it defines, and which other headers it relies on to build those definitions. This should quickly give me a sense of the conceptual architecture and what fundamental elements this header exposes. I'm expecting this to be a fast, informative glance rather than an exhaustive line-by-line inspection β but it is the first step!
|
| 267/6 |
2026/10/13 23:12 |
tool |
read-file |
0m
Args: map[File:include/drm/drm_drv.h FirstLine:1 LineCount:45]
Results: map[Contents: 1: /*
2: * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
3: * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
4: * Copyright (c) 2009-2010, Code Aurora Forum.
5: * Copyright 2016 Intel Corp.
6: *
7: * Permission is hereby granted, free of charge, to any person obtaining a
8: * copy of this software and associated documentation files (the "Software"),
9: * to deal in the Software without restriction, including without limitation
10: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11: * and/or sell copies of the Software, and to permit persons to whom the
12: * Software is furnished to do so, subject to the following conditions:
13: *
14: * The above copyright notice and this permission notice (including the next
15: * paragraph) shall be included in all copies or substantial portions of the
16: * Software.
17: *
18: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21: * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22: * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23: * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24: * OTHER DEALINGS IN THE SOFTWARE.
25: */
26:
27: #ifndef _DRM_DRV_H_
28: #define _DRM_DRV_H_
29:
30: #include <linux/list.h>
31: #include <linux/irqreturn.h>
32:
33: #include <video/nomodeset.h>
34:
35: #include <drm/drm_device.h>
36:
37: struct dmem_cgroup_init;
38: struct dmem_cgroup_region;
39: struct drm_fb_helper;
40: struct drm_fb_helper_surface_size;
41: struct drm_file;
42: struct drm_gem_object;
43: struct drm_master;
44: struct drm_minor;
45: struct dma_buf;
]
|
| 268/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 39447
output: 35
thoughts: 13
Thoughts: Okay, here's my take on summarizing those thoughts, speaking as an expert:
**Delving into drm/drm_device.h**
Alright, let's see... My brain's buzzing with the standard thought process when I encounter a header like `drm/drm_device.h`. First, my mind jumps to a core question: **"What's in this thing? What key elements define a DRM device in the kernel's eyes?"** I immediately begin to anticipate its contents. I'm thinking, of course, about the fundamental data structures, macros, and function prototypes. Things like the `drm_device` structure itself β that's gotta be central, obviously. What fields are included? How is it laid out? What are the implications of the layout? Are there any significant bitfields to remember? I'm picturing it, trying to remember the major components.
Then the thought process continues: I'm also expecting to find definitions related to device management: How are these devices represented? How are they initialized, registered, and unregistered within the DRM framework? There might be function prototypes for things like resource allocation, memory management related to the device. Any hooks for probe/remove operations would be there.
Are there macros defining some of the device flags, capabilities, or modes? What standard error codes are defined related to the DRM device operations? Any critical inline functions for accessing members of the `drm_device` structure safely? Any important internal helper structs that the kernel uses to deal with DRM device details? I'll probably be able to anticipate most of them, but I need to ensure my assumptions are correct. I need a clear mental model of how the DRM core interacts with these hardware devices.
So, in essence, I'm trying to mentally unpack the contents of `drm/drm_device.h` to solidify my understanding of the DRM device abstraction layer, its role within the graphics stack, and its relationship to the underlying hardware. Knowing it backwards and forwards is crucial!
|
| 269/6 |
2026/10/13 23:12 |
tool |
read-file |
0m
Args: map[File:include/drm/drm_device.h FirstLine:1 LineCount:40]
Results: map[Contents: 1: #ifndef _DRM_DEVICE_H_
2: #define _DRM_DEVICE_H_
3:
4: #include <linux/list.h>
5: #include <linux/kref.h>
6: #ifdef CONFIG_TRANSPARENT_HUGEPAGE
7: #include <linux/mount.h>
8: #endif
9: #include <linux/mutex.h>
10: #include <linux/idr.h>
11: #include <linux/sched.h>
12:
13: #include <drm/drm_mode_config.h>
14:
15: struct drm_driver;
16: struct drm_minor;
17: struct drm_master;
18: struct drm_vblank_crtc;
19: struct drm_vma_offset_manager;
20: struct drm_vram_mm;
21: struct drm_fb_helper;
22:
23: struct inode;
24:
25: struct pci_dev;
26: struct pci_controller;
27:
28: /*
29: * Recovery methods for wedged device in order of less to more side-effects.
30: * To be used with drm_dev_wedged_event() as recovery @method. Callers can
31: * use any one, multiple (or'd) or none depending on their needs.
32: *
33: * Refer to "Device Wedging" chapter in Documentation/gpu/drm-uapi.rst for more
34: * details.
35: */
36: #define DRM_WEDGE_RECOVERY_NONE BIT(0) /* optional telemetry collection */
37: #define DRM_WEDGE_RECOVERY_REBIND BIT(1) /* unbind + bind driver */
38: #define DRM_WEDGE_RECOVERY_BUS_RESET BIT(2) /* unbind + reset bus device + bind */
39: #define DRM_WEDGE_RECOVERY_VENDOR BIT(3) /* vendor specific recovery method */
40:
]
|
| 270/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 40507
output: 84
thoughts: 105
Thoughts: Okay, here's my thought process on this, as if I were working through it:
**Tracing the Origins of Memory Management Functions**
Alright, hang on a second... I was looking at `drm_lease.c` and I'm seeing `kzalloc` and `kfree`, but I'm not sure where these are defined. I thought I knew my memory management, but it's always good to refresh. So, let's step back and figure out where these functions actually originate. I'm seeing that `kfree(objects)` is already used in `drm_lease.c`, which is interesting.
Right, so a quick check. I'm going to bet it's something fundamental, almost certainly `linux/slab.h`. Let's confirm that. Yes, `linux/slab.h` is the likely candidate.
Okay, so the next step is: how is `linux/slab.h` being pulled into `drm_lease.c`? We're going to need to trace the includes. I need to understand the dependencies. Let's see... I'll check the typical suspects in the DRM subsystem, like `drm/drm_file.h`, `drm/drm_auth.h`, etc. Let's see if we can find the include chain that leads to `linux/slab.h`. Then I'll have a complete picture.
|
| 271/6 |
2026/10/13 23:12 |
tool |
grepper |
0m
Error:
Args: map[Expression:slab\.h PathPrefixes:[include/drm/drm_file.h include/drm/drm_auth.h include/drm/drm_crtc.h include/drm/drm_lease.h include/drm/drm_mode_config.h]]
Results:
|
| 272/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 41047
output: 37
thoughts: 25
Thoughts: Here's my take on those files.
**Analyzing Header File Dependencies in the DRM Subsystem**
Alright, let's dive into this. My initial thought is to figure out the architectural landscape of these internal DRM headers. Specifically, I need to know what `drm_crtc_internal.h` and `drm_internal.h` pull in. I'm looking for the scope of their dependencies. Are they tightly coupled with core DRM data structures, or do they reach out into other areas? Are they relying on other internal headers, other kernel subsystems, or userland interfaces? Understanding these inclusions is the first step.
|
| 273/6 |
2026/10/13 23:12 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_internal.h FirstLine:1 LineCount:40]
Results: map[Contents: 1: /*
2: * Copyright Β© 2014 Intel Corporation
3: * Daniel Vetter <daniel.vetter@ffwll.ch>
4: *
5: * Permission is hereby granted, free of charge, to any person obtaining a
6: * copy of this software and associated documentation files (the "Software"),
7: * to deal in the Software without restriction, including without limitation
8: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9: * and/or sell copies of the Software, and to permit persons to whom the
10: * Software is furnished to do so, subject to the following conditions:
11: *
12: * The above copyright notice and this permission notice shall be included in
13: * all copies or substantial portions of the Software.
14: *
15: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18: * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19: * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20: * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21: * OTHER DEALINGS IN THE SOFTWARE.
22: */
23:
24: #ifndef __DRM_INTERNAL_H__
25: #define __DRM_INTERNAL_H__
26:
27: #include <linux/kthread.h>
28: #include <linux/types.h>
29:
30: #include <drm/drm_ioctl.h>
31: #include <drm/drm_vblank.h>
32:
33: #define DRM_IF_MAJOR 1
34: #define DRM_IF_MINOR 4
35:
36: #define DRM_IF_VERSION(maj, min) (maj << 16 | min)
37:
38: struct dentry;
39: struct dma_buf;
40: struct iosys_map;
]
|
| 274/6 |
2026/10/13 23:12 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 41848
output: 40
thoughts: 17
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into `drm_crtc_internal.h`**
Alright, let's take a look at what's being included in `drm_crtc_internal.h`. I'm specifically interested in understanding the dependencies and the overall architecture this header file contributes to within the Direct Rendering Manager (DRM) driver framework. My initial hypothesis is that it's going to pull in definitions and structures specifically pertinent to CRTC managementβthe core of display output. We'll likely see dependencies on other DRM core components like modesetting structures, framebuffer management, and possibly some hardware-specific definitions depending on the level of abstraction it intends. I expect a good chunk of it will be related to managing the CRTC's state, enabling, disabling, and handling the various aspects of the display pipeline from the driver perspective. I need to get a better handle on the internal representation and the key data structures used for the CRTC.
|
| 275/6 |
2026/10/13 23:12 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_crtc_internal.h FirstLine:1 LineCount:40]
Results: map[Contents: 1: /*
2: * Copyright Β© 2006 Keith Packard
3: * Copyright Β© 2007-2008 Dave Airlie
4: * Copyright Β© 2007-2008 Intel Corporation
5: * Jesse Barnes <jesse.barnes@intel.com>
6: * Copyright Β© 2014 Intel Corporation
7: * Daniel Vetter <daniel.vetter@ffwll.ch>
8: * Copyright (c) 2020, The Linux Foundation. All rights reserved.
9: *
10: * Permission is hereby granted, free of charge, to any person obtaining a
11: * copy of this software and associated documentation files (the "Software"),
12: * to deal in the Software without restriction, including without limitation
13: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14: * and/or sell copies of the Software, and to permit persons to whom the
15: * Software is furnished to do so, subject to the following conditions:
16: *
17: * The above copyright notice and this permission notice shall be included in
18: * all copies or substantial portions of the Software.
19: *
20: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23: * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
24: * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
25: * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26: * OTHER DEALINGS IN THE SOFTWARE.
27: */
28:
29: /*
30: * This header file contains mode setting related functions and definitions
31: * which are only used within the drm module as internal implementation details
32: * and are not exported to drivers.
33: */
34:
35: #ifndef __DRM_CRTC_INTERNAL_H__
36: #define __DRM_CRTC_INTERNAL_H__
37:
38: #include <linux/err.h>
39: #include <linux/types.h>
40:
]
|
| 276/6 |
2026/10/13 23:13 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 42874
output: 881
thoughts: 2071
Thoughts: **Analysis of DRM Lease Code Changes**
Okay, let's break this down systematically. My primary concern here is correctness and potential regressions, so I'm focusing on lifetimes, potential integer overflows, and missing dependencies. Given the context, these changes in the DRM lease code look relatively straightforward, but as always, the devil is in the details.
First, regarding the memory allocation changes in `fill_object_idr()` β swapping `kzalloc_objs` and `kfree` for `kvzalloc_objs` and `kvfree`, respectively, seem okay. The function allocates, populates, validates, and *then* frees the memory within its scope. The use of `kvzalloc` means we potentially use vmalloc for large allocations, but `kvfree` correctly handles both kmalloc and vmalloc allocations, thus ensuring no leaks or dangling pointers are introduced. The references to `drm_mode_object` are managed via `drm_mode_object_put()`, which is crucial for reference counting, and all allocations are cleaned up before function exit. I don't see any apparent issues here. Header prerequisites are likely met, as `<linux/slab.h>` is probably included either directly or indirectly, but it's worth double-checking.
Next, the change in `drm_mode_create_lease_ioctl()` β replacing `memdup_array_user()` with `vmemdup_array_user()` and correspondingly using `kvfree` β is also sound, *provided* that `vmemdup_array_user`'s return value is correctly handled. And it is β the code checks for `IS_ERR()` before proceeding. The lifetimes are well-defined: memory is allocated, used, and freed within the scope of the function. No leaks here, provided `kvfree` is called after allocation, which it is. Again, the inclusion of `<linux/string.h>` for `vmemdup_array_user()` might need explicit checking, but it is typically included by other headers.
Finally, the addition of the `object_count` limit check is a good practice. It's designed to prevent excessively large leases. However, placement is critical. If the check is *after* the `drm_file_get_master` call, returning immediately with `-EINVAL` will cause a reference leak of the `lessor` master object. The fix would be to either move the check *before* the `drm_file_get_master` call or add a jump to the `out_lessor` label on error to ensure the reference is released. This is a very common mistake and needs to be addressed during code review. Now, let's consider the type safety/integer overflow aspects: the original code uses signed `int object_count` in `fill_object_idr()` and `validate_lease()` and the iteration variable `o` in `validate_lease` is signed int, while `cl->object_count` is an unsigned `__u32`. The check `cl->object_count > INT_MAX / sizeof(...)` is key here. It protects against integer overflow and ensures `object_count` fits into the `int` for these internal calls. It also correctly allows empty leases (`object_count == 0`), which are explicitly supported. The inclusion of `<linux/limits.h>` for `INT_MAX` is now required and must be checked, or the build will fail.
In summary, the memory allocation changes are safe. The new check is a valuable addition, but its *placement* is critical to prevent reference leaks. Integer overflow issues are effectively addressed by the limit check, which must be combined with the inclusion of required headers. I'll need to double-check the placement of that check and explicitly add the `#include` directives to make the code robust.
|
| 277/6 |
2026/10/13 23:13 |
tool |
set-results |
0m
Args: map[Answer:Analysis of the proposed changes in `drivers/gpu/drm/drm_lease.c`:
### 1. Lifetime Issues
* **Lessor Master Reference Leak (Corner Case / Placement Issue in Change 3)**:
* In `drm_mode_create_lease_ioctl()`, `lessor = drm_file_get_master(lessor_priv)` increments the reference count of the lessor (`drm_master`).
* If the early check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;` is placed **after** `drm_file_get_master()`, an immediate `return -EINVAL;` will **leak the lessor reference**.
* To avoid leaking `lessor`, the check must either be placed **before** `drm_file_get_master()` (e.g., right alongside the `cl->flags` check), or jump to `goto out_lessor;`.
* **Allocation Lifetimes (Changes 1 & 2)**:
* No lifetime issues with the allocated buffers.
* `objects` in `fill_object_idr()` is strictly local to the function: all acquired `drm_mode_object` references are released via `drm_mode_object_put()` before `kvfree(objects)` is called.
* `object_ids` in `drm_mode_create_lease_ioctl()` is strictly local to the ioctl and is freed with `kvfree(object_ids)` immediately after `fill_object_idr()` returns. Replacing `kfree()` with `kvfree()` correctly matches `vmemdup_array_user()`.
### 2. Corner Cases and Type Interactions
* **Signed vs Unsigned / Integer Overflow in `fill_object_idr()` and `validate_lease()`**:
* In `struct drm_mode_create_lease`, `cl->object_count` is `__u32`.
* However, `fill_object_idr()` and `validate_lease()` declare `object_count` as signed `int`, and `validate_lease()` uses `int o` as its loop counter.
* Without a bound on `cl->object_count`, passing a count $> \text{INT\_MAX}$ would result in sign overflow when converted to `int`. Checking `cl->object_count > INT_MAX / sizeof(...)` ensures that `object_count` fits safely in `int` without signed integer overflow.
* **Empty Leases (`object_count == 0`)**:
* An `object_count` of 0 is valid in DRM leasing (commit `4bb2d367a5a2 drm/lease: allow empty leases`). Because `0 <= INT_MAX / sizeof(...)`, the check correctly handles empty leases without triggering early rejection.
* **Error Return Code Difference**:
* Previously, allocating an excessively huge array via `memdup_array_user()` would return `-ENOMEM` (or `-EOVERFLOW` from `check_mul_overflow()`). Returning `-EINVAL` early changes the user-visible errno on oversized requests from `-ENOMEM`/`-EOVERFLOW` to `-EINVAL`.
### 3. Missing Includes / Prerequisites
* **`INT_MAX`**:
* Defined in `<linux/limits.h>`. `drivers/gpu/drm/drm_lease.c` does not explicitly include `<linux/limits.h>` or `<linux/kernel.h>`. While it may be pulled in transitively via other headers on some configs, `<linux/limits.h>` should be explicitly included.
* **`vmemdup_array_user`**:
* Defined in `<linux/string.h>`.
* **`kvzalloc_objs` and `kvfree`**:
* Defined in `<linux/slab.h>`. Explicit inclusion of `<linux/slab.h>` is recommended if not relying on transitive includes.]
Results: map[Answer:Analysis of the proposed changes in `drivers/gpu/drm/drm_lease.c`:
### 1. Lifetime Issues
* **Lessor Master Reference Leak (Corner Case / Placement Issue in Change 3)**:
* In `drm_mode_create_lease_ioctl()`, `lessor = drm_file_get_master(lessor_priv)` increments the reference count of the lessor (`drm_master`).
* If the early check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) return -EINVAL;` is placed **after** `drm_file_get_master()`, an immediate `return -EINVAL;` will **leak the lessor reference**.
* To avoid leaking `lessor`, the check must either be placed **before** `drm_file_get_master()` (e.g., right alongside the `cl->flags` check), or jump to `goto out_lessor;`.
* **Allocation Lifetimes (Changes 1 & 2)**:
* No lifetime issues with the allocated buffers.
* `objects` in `fill_object_idr()` is strictly local to the function: all acquired `drm_mode_object` references are released via `drm_mode_object_put()` before `kvfree(objects)` is called.
* `object_ids` in `drm_mode_create_lease_ioctl()` is strictly local to the ioctl and is freed with `kvfree(object_ids)` immediately after `fill_object_idr()` returns. Replacing `kfree()` with `kvfree()` correctly matches `vmemdup_array_user()`.
### 2. Corner Cases and Type Interactions
* **Signed vs Unsigned / Integer Overflow in `fill_object_idr()` and `validate_lease()`**:
* In `struct drm_mode_create_lease`, `cl->object_count` is `__u32`.
* However, `fill_object_idr()` and `validate_lease()` declare `object_count` as signed `int`, and `validate_lease()` uses `int o` as its loop counter.
* Without a bound on `cl->object_count`, passing a count $> \text{INT\_MAX}$ would result in sign overflow when converted to `int`. Checking `cl->object_count > INT_MAX / sizeof(...)` ensures that `object_count` fits safely in `int` without signed integer overflow.
* **Empty Leases (`object_count == 0`)**:
* An `object_count` of 0 is valid in DRM leasing (commit `4bb2d367a5a2 drm/lease: allow empty leases`). Because `0 <= INT_MAX / sizeof(...)`, the check correctly handles empty leases without triggering early rejection.
* **Error Return Code Difference**:
* Previously, allocating an excessively huge array via `memdup_array_user()` would return `-ENOMEM` (or `-EOVERFLOW` from `check_mul_overflow()`). Returning `-EINVAL` early changes the user-visible errno on oversized requests from `-ENOMEM`/`-EOVERFLOW` to `-EINVAL`.
### 3. Missing Includes / Prerequisites
* **`INT_MAX`**:
* Defined in `<linux/limits.h>`. `drivers/gpu/drm/drm_lease.c` does not explicitly include `<linux/limits.h>` or `<linux/kernel.h>`. While it may be pulled in transitively via other headers on some configs, `<linux/limits.h>` should be explicitly included.
* **`vmemdup_array_user`**:
* Defined in `<linux/string.h>`.
* **`kvzalloc_objs` and `kvfree`**:
* Defined in `<linux/slab.h>`. Explicit inclusion of `<linux/slab.h>` is recommended if not relying on transitive includes.]
|
| 278/4 |
2026/10/13 23:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 119001
output: 37
thoughts: 857
Thoughts: **Code Review: DRM Lease Fix Verification**
Okay, so the code expert's confirmation is spot-on. They've really drilled down into the details, which is exactly what's needed. The key is placing the check *before* the call to `drm_file_get_master()`. This prevents any potential resource leaks, ensuring that we catch the error condition before any critical data structures are allocated.
They've also highlighted the necessity of including the `<linux/limits.h>` and `<linux/slab.h>` headers, along with the existing `<linux/string.h>` (which, of course, might already be included implicitly, but explicitly including it is good practice). Let me double-check the current headers in `drivers/gpu/drm/drm_lease.c`:
```c
#include <linux/file.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
#include <drm/drm_crtc.h>
#include <drm/drm_drv.h>
#include <drm/drm_file.h>
#include <drm/drm_lease.h>
#include <drm/drm_print.h>
#include "drm_crtc_internal.h"
#include "drm_internal.h"
```
Yup, adding the other `<linux/...>` headers ( `<linux/limits.h>`, `<linux/slab.h>`, and potentially including `<linux/string.h>`) fits perfectly, and they should be alphabetized for consistency. Excellent, following the standard Linux kernel style.
Now, let's confirm the exact location of the `cl->object_count` check within the existing code. Examining lines 494-498:
```c
if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
drm_dbg_lease(dev, "invalid flags\n");
return -EINVAL;
}
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
return -EINVAL;
}
lessor = drm_file_get_master(lessor_priv);
```
Exactly, right *after* the `cl->flags` check, just as intended. The code checks `cl->object_count` against `INT_MAX / sizeof(struct drm_mode_object *)`, logs using `drm_dbg_lease`, and returns `-EINVAL`. The important thing is that *no* references are taken before this check, so there's nothing to clean up if the check fails. Very clean.
Let's check lines 384-392 and 465 from `drivers/gpu/drm/drm_lease.c`:
```c
objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
```
```c
kvfree(objects);
return ret;
```
Okay, so the memory allocation and deallocation of `objects` is handled correctly using `kvzalloc_objs` and `kvfree` respectively.
And lines 512-524:
```c
object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
goto out_lessor;
}
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
kvfree(object_ids);
```
Here it's copying object IDs from userspace, which is handled and cleaned correctly.
Everything checks out. The proposed change is logically sound, safe, and follows established kernel coding conventions. We can proceed with the integration. Now, let's copy the code from the editor and integrate.
|
| 279/4 |
2026/10/13 23:13 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:1 LineCount:20]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0-or-later
2: /*
3: * Copyright Β© 2017 Keith Packard <keithp@keithp.com>
4: */
5: #include <linux/file.h>
6: #include <linux/uaccess.h>
7:
8: #include <drm/drm_auth.h>
9: #include <drm/drm_crtc.h>
10: #include <drm/drm_drv.h>
11: #include <drm/drm_file.h>
12: #include <drm/drm_lease.h>
13: #include <drm/drm_print.h>
14:
15: #include "drm_crtc_internal.h"
16: #include "drm_internal.h"
17:
18: /**
19: * DOC: drm leasing
20: *
]
|
| 280/4 |
2026/10/13 23:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 121121
output: 39
thoughts: 28
Thoughts: Okay, here's my interpretation of what's going on in that section of `drm_lease.c`, presented as if it were my thought process:
**Diving into the Lease Handling**
Alright, time to focus on lines 380 to 470 of `drivers/gpu/drm/drm_lease.c`. Let's get down to the core logic of these DRM lease operations. I know this code pretty well, but it always pays to refresh the context. I need to fully grasp how the lease management is working. I need to remind myself of the conditions that define valid lease granting and revocation. I'm guessing this section probably deals with the core functions for requesting, granting, and potentially revoking those leases.
I'm expecting to see calls related to the lease request structure, likely involving data structures associated with the client requesting the lease and the device granting it. This should contain logic around device access checks and if those checks fail, the code must implement the fallback behaviors, such as rejecting the request or queuing it. Furthermore, there might be concurrency issues, considering we have multiple clients trying to access the device. The developers must be using mutexes or semaphores to avoid race conditions. I bet there are some important considerations for handling lease revocation too, whether due to a client closing or the device driver itself needing to reclaim resources. There might be error handling here, too, like what to do if the lease request fails for whatever reason and how it reports it to the caller. Okay, let's see how they've implemented it in this section. I'm keen to see if they're addressing the potential corner cases I'm thinking about.
|
| 281/4 |
2026/10/13 23:13 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:380 LineCount:90]
Results: map[Contents: 380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
468:
469: /*
]
|
| 282/4 |
2026/10/13 23:13 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 122986
output: 39
thoughts: 29
Thoughts: Okay, here's my interpretation of what's going through my mind as I analyze that code, keeping in mind that the user is an expert in the field:
**Diving into `drm_lease.c`: Lines 490-535**
Alright, let's get down to brass tacks. I need to understand how this lease mechanism is functioning within the DRM framework, specifically looking at the implementation details within `drivers/gpu/drm/drm_lease.c`. I'm going to focus my attention on lines 490 to 535. This is likely where the core of some interaction or state transition is happening related to these leases. I have a feeling I'll find some intricate dance involving file descriptors, permissions, and some kind of signaling.
Okay, scanning quickly... I'm looking for the key functions or structures involved here. Is this an acquisition phase, release, or maybe some kind of renewal logic? Based on the surrounding code I know, it's likely part of the device setup. Let's see... looking for loops, conditional statements, and anything related to userspace interaction β that's often where the magic, or the bugs, happen.
I'm expecting to see calls to `drm_ioctl`, `fput`, or possibly interactions with `inode` or `file` structures. I'm also anticipating some kind of locking mechanism to ensure concurrency is handled gracefully, hopefully leveraging spinlocks or mutexes appropriately. The context here is critical; I'm assuming we're dealing with either a master device, a client, or perhaps some kind of intermediary device that's being leased out.
This is going to involve understanding the intended data flows and where the specific actions or permissions are checked. I'll need to figure out what happens if something goes wrong, too. Error handling is important. Hopefully, it is robustly handled.
|
| 283/4 |
2026/10/13 23:14 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:490 LineCount:45]
Results: map[Contents: 490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
]
|
| 284/4 |
2026/10/13 23:14 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 124165
output: 34
thoughts: 60
Thoughts: Okay, here's my thought process as I'd articulate it:
**Digging into Potential Memory Corruption in `drm_lease.c`**
Alright, I need to be absolutely certain we've covered our bases in `drm_lease.c` regarding memory management. The potential for misuse of `kfree` where `kvfree` or a related function might be more appropriate is a common class of memory bug, and frankly, I need to rule it out entirely here. My next step, and it's a critical one, is to systematically examine the code to ensure we are using the correct free calls for the allocators. It's time to grep for `kfree` within the specific file: `drivers/gpu/drm/drm_lease.c`. That will give me a manageable list of candidates to review closely, looking for opportunities to tighten up the memory safety.
|
| 285/4 |
2026/10/13 23:14 |
tool |
grepper |
0m
Args: map[Expression:kfree PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results: map[Output:drivers/gpu/drm/drm_lease.c=378=static int fill_object_idr(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-464- }
drivers/gpu/drm/drm_lease.c:465: kfree(objects);
drivers/gpu/drm/drm_lease.c-466- return ret;
--
drivers/gpu/drm/drm_lease.c=475=int drm_mode_create_lease_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-522- object_count, object_ids);
drivers/gpu/drm/drm_lease.c:523: kfree(object_ids);
drivers/gpu/drm/drm_lease.c-524- if (ret) {
]
|
| 286/4 |
2026/10/13 23:14 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 124669
output: 108
thoughts: 594
Thoughts: **My Analysis and Proposed Changes**
Okay, so I've been poring over this code, specifically focusing on memory allocation and deallocation within `drivers/gpu/drm/drm_lease.c` and associated calls. The critical part is to optimize how memory is handled.
First things first, I've tracked down the `kfree` calls within the file β just two of them, actually, at lines 465 and 523. Both are associated with the `objects` and `object_ids` variables, respectively. Now, to make sure everything is consistent, let's look at the associated allocation calls. `memdup` call at line 512, and `kzalloc` at line 389.
Alright, so to improve this, I'm going to make the following changes, all using the `codeeditor` tool, of course:
1. **Header Inclusion:** I'll begin by adding necessary headers to `drivers/gpu/drm/drm_lease.c`. Specifically, I need `<linux/file.h>`, `<linux/limits.h>`, `<linux/slab.h>`, `<linux/string.h>`, and `<linux/uaccess.h>`.
2. **`fill_object_idr()` Modification:** Within this function, I'll replace `kzalloc_objs(...)` with `kvzalloc_objs(...)` to leverage the kernel's virtual addressing capabilities for the `objects` allocation, and replace `kfree(objects)` with `kvfree(objects)` for the appropriate deallocation.
3. **`drm_mode_create_lease_ioctl()` Enhancements:** Here's where it gets a little more involved. First, I'm going to add an early bounds check on `cl->flags` and `cl->object_count` for invalid and too large values, respectively, as an early error condition. Next, I'll switch the allocation of `object_ids` from `memdup_array_user` to `vmemdup_array_user` for the same virtual addressing reason, and of course change the corresponding `kfree(object_ids)` call to `kvfree(object_ids)`.
Let's call the `codeeditor` function for the first change (adding the headers). This should make our code more robust and efficient.
|
| 287/4 |
2026/10/13 23:14 |
tool |
codeeditor |
0m
Args: map[CurrentCode:#include <linux/file.h>
#include <linux/uaccess.h> NewCode:#include <linux/file.h>
#include <linux/limits.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/uaccess.h> SourceFile:drivers/gpu/drm/drm_lease.c]
Results:
|
| 288/4 |
2026/10/13 23:14 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 125882
output: 105
thoughts: 17
Thoughts: Okay, let's get this done. Here's how I'd approach summarizing the prompt:
**Focusing on the `fill_object_idr` Function**
Alright, so the task at hand is crystal clear. I'm focusing in on the next step, specifically the second change needed within the `fill_object_idr` function. This signals a continuation of a previously initiated process. The request is specific; my expertise tells me that this function plays a crucial role in object identification and retrieval. Knowing this context, I now understand that I need to be precise and efficient. It's time to dive in and get this implemented.
|
| 289/4 |
2026/10/13 23:14 |
tool |
codeeditor |
0m
Args: map[CurrentCode: objects = kzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM; NewCode: objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM; SourceFile:drivers/gpu/drm/drm_lease.c]
Results:
|
| 290/4 |
2026/10/13 23:14 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 126148
output: 110
thoughts: 17
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing the Memory Allocation Change**
Alright, so the shift from `kfree(objects)` to `kvfree(objects)` has landed. I immediately start mentally parsing the implications. This isn't just a trivial find-and-replace; it signifies a deliberate choice in kernel memory management. We're moving from a generic `kmalloc`-based allocation to something leveraging the "v" variant. My first instinct is to understand the context: what specific allocation strategy triggered this? Was it a global change or confined to a particular subsystem or driver? What are the underlying performance or security justifications? The devil is always in the details, so I need to dig deeper.
I'm guessing they are trying to fix a security issue or improve the memory management strategy. Is this allocation coming from contiguous or virtual allocations?
|
| 291/4 |
2026/10/13 23:14 |
tool |
codeeditor |
0m
Args: map[CurrentCode: if (objects[o])
drm_mode_object_put(objects[o]);
}
kfree(objects);
return ret; NewCode: if (objects[o])
drm_mode_object_put(objects[o]);
}
kvfree(objects);
return ret; SourceFile:drivers/gpu/drm/drm_lease.c]
Results:
|
| 292/4 |
2026/10/13 23:14 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 126468
output: 237
thoughts: 30
Thoughts: Okay, here's my take on those thoughts, framed as a first-person expert summary:
**Analyzing the DRM Lease Creation IOCTL Modification**
Alright, let's break down this `drm_mode_create_lease_ioctl` change. My initial focus, as always, hones in on potential vulnerabilities and resource management. The very first thing that jumps out is that early bounds check on `cl->object_count`. This is precisely where I'd start too. We need to be absolutely certain that any object count passed into this function is reasonable before we even begin to allocate resources. A flawed check here is a potential attack vector for denial-of-service or even something more sinister, so I would certainly focus on the robustness of that check and its coverage. I'm keen to understand the implications of this particular check with respect to our overall memory safety guarantees and the maximum lease object limit.
|
| 293/4 |
2026/10/13 23:14 |
tool |
codeeditor |
0m
Args: map[CurrentCode: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
drm_dbg_lease(dev, "invalid flags\n");
return -EINVAL;
}
lessor = drm_file_get_master(lessor_priv); NewCode: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
drm_dbg_lease(dev, "invalid flags\n");
return -EINVAL;
}
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
return -EINVAL;
}
lessor = drm_file_get_master(lessor_priv); SourceFile:drivers/gpu/drm/drm_lease.c]
Results:
|
| 294/4 |
2026/10/13 23:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 126930
output: 312
thoughts: 22
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Re-evaluating Memory Allocation Strategy**
Alright, so the focus is shifting. I'm looking at `vmemdup_array_user` and the `kvfree(object_ids)` call. This change, or *these* changes, are the key to the next phase of optimization. I immediately start wondering about the implications of the memory duplication strategy in the user context, specifically `vmemdup_array_user`. I need to remember the architectural implications of how this function is implemented in the target architecture. Are there any particular nuances related to the user memory access that could result in bottlenecks or performance degradation, especially with regard to the `object_ids` array, since the intention is to free them with a `kvfree`.
My immediate question is: am I overlooking anything? Are there alignment considerations? Potential for fragmentation? Are there any hidden performance implications when there are a large number of object IDs? The current implementation using `vmemdup_array_user` is a well-established and tested memory allocation and copy methodology, which is one of the important reasons I keep coming back to these areas of code.
It is clear I'll need to double check the allocation and free calls to see if they are symmetrical with the object IDs, and also ensure the security boundaries for user memory access are maintained. Is the allocation large enough? Are there any unaddressed race conditions lurking? I'll need to thoroughly review the surrounding code to understand the context and potential side effects this change, or these changes, might bring.
Essentially, I am thinking through the specifics of the memory copy, and free calls and their implications on system performance. Time to dig in!
|
| 295/4 |
2026/10/13 23:15 |
tool |
codeeditor |
0m
Args: map[CurrentCode: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
goto out_lessor;
}
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
kfree(object_ids); NewCode: object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
goto out_lessor;
}
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
kvfree(object_ids); SourceFile:drivers/gpu/drm/drm_lease.c]
Results:
|
| 296/4 |
2026/10/13 23:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 127640
output: 10
thoughts: 10
Thoughts: Okay, here's my interpretation of that:
**Analyzing the Proposed Changes**
Right, let's get down to brass tacks. I need to take a look at these proposed changes, so I'm going to run the `patch-diff` command. This is the standard procedure to understand exactly what's being added, removed, or modified. I'm hoping it's well-formatted and easy to parse, because the clarity of the diff is critical for a smooth review and integration. I need to assess the scope of the change and if the change has a potential impact on any dependencies.
|
| 297/4 |
2026/10/13 23:15 |
tool |
patch-diff |
0m
Results: map[Output:diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -1,70 +1,73 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
#include <drm/drm_crtc.h>
#include <drm/drm_drv.h>
#include <drm/drm_file.h>
#include <drm/drm_lease.h>
#include <drm/drm_print.h>
#include "drm_crtc_internal.h"
#include "drm_internal.h"
/**
* DOC: drm leasing
*
* DRM leases provide information about whether a DRM master may control a DRM
* mode setting object. This enables the creation of multiple DRM masters that
* manage subsets of display resources.
*
* The original DRM master of a device 'owns' the available drm resources. It
* may create additional DRM masters and 'lease' resources which it controls
* to the new DRM master. This gives the new DRM master control over the
* leased resources until the owner revokes the lease, or the new DRM master
* is closed. Some helpful terminology:
*
* - An 'owner' is a &struct drm_master that is not leasing objects from
* another &struct drm_master, and hence 'owns' the objects. The owner can be
* identified as the &struct drm_master for which &drm_master.lessor is NULL.
*
* - A 'lessor' is a &struct drm_master which is leasing objects to one or more
* other &struct drm_master. Currently, lessees are not allowed to
* create sub-leases, hence the lessor is the same as the owner.
*
* - A 'lessee' is a &struct drm_master which is leasing objects from some
* other &struct drm_master. Each lessee only leases resources from a single
* lessor recorded in &drm_master.lessor, and holds the set of objects that
* it is leasing in &drm_master.leases.
*
* - A 'lease' is a contract between the lessor and lessee that identifies
* which resources may be controlled by the lessee. All of the resources
* that are leased must be owned by or leased to the lessor, and lessors are
* not permitted to lease the same object to multiple lessees.
*
* The set of objects any &struct drm_master 'controls' is limited to the set
* of objects it leases (for lessees) or all objects (for owners).
*
* Objects not controlled by a &struct drm_master cannot be modified through
* the various state manipulating ioctls, and any state reported back to user
* space will be edited to make them appear idle and/or unusable. For
* instance, connectors always report 'disconnected', while encoders
* report no possible crtcs or clones.
*
* Since each lessee may lease objects from a single lessor, display resource
* leases form a tree of &struct drm_master. As lessees are currently not
* allowed to create sub-leases, the tree depth is limited to 1. All of
* these get activated simultaneously when the top level device owner changes
* through the SETMASTER or DROPMASTER IOCTL, so &drm_device.master points to
* the owner at the top of the lease tree (i.e. the &struct drm_master for which
* &drm_master.lessor is NULL). The full list of lessees that are leasing
* objects from the owner can be searched via the owner's
* &drm_master.lessee_idr.
*/
#define drm_for_each_lessee(lessee, lessor) \
list_for_each_entry((lessee), &(lessor)->lessees, lessee_list)
@@ -378,209 +381,214 @@ static int validate_lease(struct drm_device *dev,
static int fill_object_idr(struct drm_device *dev,
struct drm_file *lessor_priv,
struct idr *leases,
int object_count,
u32 *object_ids)
{
struct drm_mode_object **objects;
u32 o;
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
/* step one - get references to all the mode objects
and check for validity. */
for (o = 0; o < object_count; o++) {
objects[o] = drm_mode_object_find(dev, lessor_priv,
object_ids[o],
DRM_MODE_OBJECT_ANY);
if (!objects[o]) {
ret = -ENOENT;
goto out_free_objects;
}
if (!drm_mode_object_lease_required(objects[o]->type)) {
DRM_DEBUG_KMS("invalid object for lease\n");
ret = -EINVAL;
goto out_free_objects;
}
}
ret = validate_lease(dev, object_count, objects, universal_planes);
if (ret) {
drm_dbg_lease(dev, "lease validation failed\n");
goto out_free_objects;
}
/* add their IDs to the lease request - taking into account
universal planes */
for (o = 0; o < object_count; o++) {
struct drm_mode_object *obj = objects[o];
u32 object_id = objects[o]->id;
drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
/*
* We're using an IDR to hold the set of leased
* objects, but we don't need to point at the object's
* data structure from the lease as the main object_idr
* will be used to actually find that. Instead, all we
* really want is a 'leased/not-leased' result, for
* which any non-NULL pointer will work fine.
*/
ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
if (ret < 0) {
drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
object_id, ret);
goto out_free_objects;
}
if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
struct drm_crtc *crtc = obj_to_crtc(obj);
ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
if (ret < 0) {
drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
object_id, ret);
goto out_free_objects;
}
if (crtc->cursor) {
ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
if (ret < 0) {
drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
object_id, ret);
goto out_free_objects;
}
}
}
}
ret = 0;
out_free_objects:
for (o = 0; o < object_count; o++) {
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
/*
* The master associated with the specified file will have a lease
* created containing the objects specified in the ioctl structure.
* A file descriptor will be allocated for that and returned to the
* application.
*/
int drm_mode_create_lease_ioctl(struct drm_device *dev,
void *data, struct drm_file *lessor_priv)
{
struct drm_mode_create_lease *cl = data;
size_t object_count;
int ret = 0;
struct idr leases;
struct drm_master *lessor;
struct drm_master *lessee = NULL;
struct file *lessee_file = NULL;
struct file *lessor_file = lessor_priv->filp;
struct drm_file *lessee_priv;
int fd = -1;
uint32_t *object_ids;
/* Can't lease without MODESET */
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EOPNOTSUPP;
if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
drm_dbg_lease(dev, "invalid flags\n");
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
drm_dbg_lease(dev, "recursive leasing not allowed\n");
ret = -EINVAL;
goto out_lessor;
}
object_count = cl->object_count;
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
goto out_lessor;
}
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
goto out_lessor;
}
}
/* Allocate a file descriptor for the lease */
fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
if (fd < 0) {
idr_destroy(&leases);
ret = fd;
goto out_lessor;
}
drm_dbg_lease(dev, "Creating lease\n");
/* lessee will take the ownership of leases */
lessee = drm_lease_create(lessor, &leases);
if (IS_ERR(lessee)) {
ret = PTR_ERR(lessee);
idr_destroy(&leases);
goto out_leases;
}
/* Clone the lessor file to create a new file for us */
drm_dbg_lease(dev, "Allocating lease file\n");
lessee_file = file_clone_open(lessor_file);
if (IS_ERR(lessee_file)) {
ret = PTR_ERR(lessee_file);
goto out_lessee;
}
lessee_priv = lessee_file->private_data;
/* Change the file to a master one */
drm_master_put(&lessee_priv->master);
lessee_priv->master = lessee;
lessee_priv->is_master = 1;
lessee_priv->authenticated = 1;
/* Pass fd back to userspace */
drm_dbg_lease(dev, "Returning fd %d id %d\n", fd, lessee->lessee_id);
cl->fd = fd;
cl->lessee_id = lessee->lessee_id;
/* Hook up the fd */
fd_install(fd, lessee_file);
drm_master_put(&lessor);
drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
return 0;
out_lessee:
drm_master_put(&lessee);
out_leases:
put_unused_fd(fd);
out_lessor:
drm_master_put(&lessor);
drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
return ret;
}
]
|
| 298/4 |
2026/10/13 23:15 |
llm |
patch-generator |
0m
Model:
Tokens:
input: 131418
output: 831
thoughts: 688
Thoughts: **Reviewing the Patch: A Deep Dive**
Okay, let's break this down. First, I see the header includes are updated. We've brought in `<linux/limits.h>`, `<linux/slab.h>`, and `<linux/string.h>`. These additions provide us with critical tools: `INT_MAX`, the `kvzalloc_objs` and `kvfree` allocators, and `vmemdup_array_user`. This is a good sign; we're preparing to handle potentially large allocations and address the previous concerns.
Next, I see changes in `fill_object_idr()`. The switch from `kzalloc_objs` to `kvzalloc_objs` and from `kfree` to `kvfree` is significant. The goal here is clearly to leverage `vmalloc()` as a fallback when the required memory exceeds the constraints of regular kernel allocation (specifically `PAGE_SIZE` or `MAX_PAGE_ORDER`). This avoids the warning in `alloc_order_allowed()` and, crucially, ensures proper deallocation. The use of `kvzalloc_objs` and `kvfree` is consistent and clean, exactly what's needed.
Moving on to `drm_mode_create_lease_ioctl()`, a critical check has been added early on: `cl->object_count` is now validated against `INT_MAX / sizeof(struct drm_mode_object *)`. This is *excellent* defensive programming. It prevents the allocation size of both `objects` and `object_ids` from overflowing and passing `INT_MAX`, and more importantly, it avoids a resource leak by ensuring this check happens before grabbing a reference to `lessor_priv`. This completely addresses the potential integer overflow issue that was flagged earlier. This also addresses the possible integer overflow when `cl->object_count` is passed as `int object_count` to `fill_object_idr()` and `validate_lease()`.
Finally, the `drm_mode_create_lease_ioctl()` function has updated the user array duplication from `memdup_array_user` to `vmemdup_array_user`, and, of course, updated the corresponding free to `kvfree`. This follows the same strategy as the other allocation: a safe fallback to `vmalloc()` for potentially large user arrays and matching deallocation.
This diff is clean, minimal, directly addresses the root cause of the issue, and adheres precisely to all the requirements. It's a complete and robust solution. Time to write the explanation and move on.
|
| 299/3 |
2026/10/13 23:15 |
action |
test-patch |
39m
Results: map[PatchDiff:diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -3,6 +3,9 @@
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
@@ -386,7 +389,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +465,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
@@ -496,6 +499,11 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
@@ -509,8 +517,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
@@ -520,7 +528,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
TestError:]
|
| 300/3 |
2026/10/13 23:55 |
action |
If |
23m
Args:
|
| 301/4 |
2026/10/13 23:55 |
agent |
patch-reviewer |
22m
Model:
Results: map[ReviewApproved:true ReviewComments:[]]
Instruction: You are an experienced Linux kernel maintainer reviewing a proposed patch that compiles and passes reproducer tests.
Evaluate the patch diff against the crash report, root cause, and the architectural design guidelines below.
Scope Constraint (Single-Patch Submissions):
We only generate single, standalone patches (not patch series). If a comprehensive architectural redesign would require a multi-patch series touching many files, accept a localized single-patch fix as long as it correctly fixes the bug, does not introduce new issues, and avoids sentinel band-aids within its local scope.
Evaluation:
- Set ReviewApproved=true (and leave ReviewComments empty) if the patch is acceptable for upstream submission as a single-patch fix.
- Set ReviewApproved=false and list concise, actionable feedback in ReviewComments if the patch contains fixable "Kernel Architectural Design & Maintainer Taste" violations.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
---
# Kernel Architectural Design & Maintainer Taste
Evaluate kernel patches and fix proposals beyond binary bug presence. Enforce **maintainer taste**, **lifecycle symmetry**, **typestate soundness**, and **topological graph simplicity**.
---
## 1. Core Philosophy: Band-Aid vs. Architectural Design
Naive patches often introduce **defensive sentinel guards** (e.g., ad-hoc `if (!ptr) return;` checks, status flags, or suppressed warnings) directly at the point of failure. While locally avoiding crashes, they degrade subsystem architecture by leaving uninitialized states reachable.
Maintainer "good taste" solves the root cause by **shifting invariants** (making invalid states unrepresentable) and moving dynamic runtime checks into static typestate guarantees.
```
HACKY BAND-AID FIX (Monolithic Cleanup) ARCHITECTURAL DESIGN (Scoped RAII / Invariant Shift)
βββββββββββββββββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββββββββββββββββββββββ
[ Init / Entry ] [ Init / Entry ]
β β
(Register Global Cleanup) (Allocate Resource A)
β β
[ Init Sub-B ] ββfailβββ [ Init Sub-B ] ββfailβββ
β (success) β β (success) β
βΌ β βΌ βΌ
[ Setup Complete ] β (Arm B Cleanup / RAII) (Unwind A Only:
β β β B never armed)
(Deferred Teardown) β βΌ β
β β [ Setup Complete ] βΌ
βΌ βΌ β [ Error Exit ]
[ release_all ] βββββββββ (LIFO Scope Teardown)
β β
(if (!ctx->b) return;) <-- Defensive guard! βΌ
β [ Clean Destruction ]
[ Unsafe State ] (Zero sentinel checks needed)
```
```c
// ANTI-PATTERN (Defensive Sentinel Guard): Teardown called on partial init -> callee needs guard
void driver_cleanup(struct ctx *ctx) {
if (!ctx->buf) return; // <-- Sentinel band-aid
free_buffer(ctx->buf);
}
// CANONICAL SHIFT (Granular Scoped Action): Registered only upon complete initialization
ctx->buf = alloc_buffer();
if (!ctx->buf) return -ENOMEM;
devm_add_action_or_reset(dev, free_buffer_action, ctx->buf);
```
---
## 2. Maintainer Taste as Graph Topology & Structural Simplicity
Software design quality maps directly to graph-theoretic properties across the Control-Flow Graph (CFG), Data-Flow Graph (DFG), and Object Lifecycle DAG:
### A. Control-Flow Graph (CFG) Simplification
* **Branch Minimization & Path Explosion (McCabe 1976):** Every defensive check added to a compound destructor or callback (`if (!ctx->buffer) return;`) adds a predicate node ($\pi$), increases cyclomatic complexity $v(G) = |E| - |V| + 2$, causes exponential path explosion ($O(2^k)$ paths), and enlarges explicit state spaces ($|S| = \prod |D_i|$). Good taste eliminates the branch by guaranteeing destructors are invoked only on initialized typestates. *(Note: Standard idempotent leaf deallocators like `kfree(NULL)` and public API input sanitizers are exempt).*
* **Single-Entry Single-Exit (SESE) Symmetry (Ferrante 1987, Johnson 1994, Dijkstra 1972):** Resource acquisition and release must form strict **nested dominator trees**. If resource $R_i$ is acquired at node $A$, the set of release actions $\{B_1, \dots, B_m\}$ must form a strict **post-dominating cut** relative to $A$ across all maximal exit paths.
* **Pointer Uniformity (Linus's "Good Taste" Rule):** Eliminate special-case conditional branches by operating on address indirection (e.g., indirect pointers `**curr` in linked list unlinking) to unify edge and interior cases into a branchless invariant.
* **Lexical Scope Invariants & Affine Lifecycles (Wadler 1990, RAII):** Enforce SESE symmetry and "consumed exactly once" affine invariants using compiler-backed scoped cleanup (`<linux/cleanup.h>` `guard()`, `scoped_guard()`, `__free()`).
### B. Ownership & Lifetime DAGs
* **Acyclic Lifecycles & Topological Teardown (Tarjan 1972, Kahn 1962):** Resource ownership must form a strict Directed Acyclic Graph (DAG) $G = (R, E)$. Teardown order must strictly follow reverse topological sort $\text{toposort}(G)^R$. Mixing conflicting lifetime paradigms (e.g., embedding a dynamic refcounted `kref`/socket struct inside a device-managed `devres` buffer or parent container) violates DAG acyclicity, creating synchronous blocking hacks (`wait_for_completion`), circular pins, and Use-After-Free hazards.
* **Three-Phase Concurrent Quiescence:** Multi-threaded and asynchronous teardown (networking, block layer, RCU) must strictly sequence: (1) **Deactivation/Delisting** (make unreachable) -> (2) **Quiescence & Draining** (`synchronize_rcu()`, `cancel_work_sync()`, `napi_disable()`) -> (3) **Physical Reclamation** (`kfree()`, `kmem_cache_destroy()`).
* **Typestate Validity (Strom & Yemini 1986, Aldrich et al. 2009):** A struct with $N$ fields should not use runtime boolean flags (`ctx->is_initialized`) to model incomplete typestates. Sub-resources must transition as a deterministic typestate automaton ($S_{uninit} \xrightarrow{\text{alloc}} S_{init} \xrightarrow{\text{publish}} S_{registered}$), and registration functions must accept only fully initialized typestates.
---
## 3. Deterministic Decision Trigger Matrix
| Code Symptom / Trigger (When you see X) | Anti-Pattern Band-Aid (DO NOT DO Z) | Canonical Invariant Shift (DO Y) |
| :--- | :--- | :--- |
| **Null deref in compound destructor / cleanup callback** | Add `if (!priv->buf) return;` in composite cleanup handler | Register granular cleanup immediately upon allocation via `devm_add_action_or_reset()`, `<linux/cleanup.h>` `__free()`, or discrete reverse LIFO labels |
| **UAF on dynamic object after container unbind** | Allocate with `devm_kzalloc()` and block on `wait_for_completion()` | Allocate with `kzalloc()`, manage lifetime via `kref_get()`/`kref_put()`, call unbind/delist on unbind, free in `kref` release callback |
| **Goto ladder lock leaks on early error exit** | Sprinkle manual `mutex_unlock()` across error returns | Use `guard(mutex)(&lock)` or `scoped_guard(spinlock, &lock)` from `<linux/cleanup.h>` |
| **Callback / IRQ / timer fires before full init** | Add `if (!priv->ready)` check inside IRQ/timer handler | Move `request_irq()`, `timer_setup()`, or `napi_enable()` strictly to the end of setup after all state structures are fully initialized |
| **Multi-step setup failure leaks resources** | Route all errors to a single `err:` label calling a monolithic `cleanup(priv)` with NULL checks | Use `cleanup.h` RAII, granular `devm` actions, or a strict reverse LIFO goto ladder (`err_free_b:` -> `err_free_a:`) |
| **Mixed ownership / asymmetric refcount drops** | Conditionally call `kref_put()` in caller based on error code | Enforce unconditional callee-cleans or caller-cleans ownership convention across all paths |
| **Ad-hoc state flag polling during teardown** | Add `priv->stopping = true` and spin/poll in callbacks | Use atomic typestate transitions and synchronous flush/drain APIs (`cancel_work_sync()`, `drain_workqueue()`) |
---
## 4. The Architectural Review Checklist
Before finalizing any kernel fix or review, audit against the following four criteria:
1. **The Sentinel Test (Caller vs. Callee Responsibility):**
* *Smell:* Adding a defensive guard (`if (!ptr)` or `if (flags & INITIALIZED)`) inside a compound teardown callback or destructor to mask partial initialization.
* *Invariant:* If a destructor executes on uninitialized data, the defect is at the **caller's registration/invocation point**, not the callee.
* *Note:* Standard C allocator no-ops (`kfree(NULL)`) and public API parameter validators (`if (WARN_ON(!ptr)) return -EINVAL;`) are exempt; this rule targets *internal subsystem lifecycle pipelines and teardown paths*.
* *Action:* Move registration to the point of complete initialization (`devm_add_action_or_reset()`, RAII/`__free()`, or discrete caller unwinding).
2. **LIFO Stack Unwinding Symmetry:**
* *Smell:* Releasing resources in arbitrary order or invoking destructors for partially initialized subsystems.
* *Invariant:* Resource release must strictly mirror acquisition order in reverse (LIFO) without monolithic cleanup guards.
* *Action:* Verify that partial setup/initialization failures (e.g., `probe()`, `mount()`, `open()`, `alloc_pool()`) unwind only already-allocated resources in reverse order via strict LIFO labels or `cleanup.h` scope exit.
3. **Ownership Decoupling:**
* *Smell:* Embedding dynamically refcounted objects (`kref`, `struct sock`, `struct inode`, `struct file`) directly inside hardware device-bound allocations (`devres`) or parent containers (`super_block`, `net_device`).
* *Invariant:* Dynamic consumer references must outlive parent unregistration without use-after-free, circular pins, or blocking hacks.
* *Action:* Decouple the refcounted core object from the container binding; container teardown must unbind/delist the object, but memory is freed exclusively by the final `kref_put()`.
4. **Codebase Idiom Alignment:**
* *Smell:* Using legacy custom rollback ladders, ad-hoc state flags, or manual lock unlocking on error paths.
* *Invariant:* Prefer standard, modern kernel abstractions with compiler-enforced safety guarantees.
* *Action (Modern >= 6.6):* Replace manual boilerplate with `cleanup.h` (`guard()`, `scoped_guard()`, `__free()`), `devm_add_action_or_reset()`, `refcount_t`, and standard `kref` helpers.
* *Action (Legacy / LTS / No-RAII Subsystems):* Enforce clean, branchless reverse LIFO goto ladders (`err_free_b:` -> `err_free_a:`).
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
Bug title:
WARNING in alloc_frozen_pages_noprof
The crash report:
------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
The root cause explanation:
An analysis of the crash reveals that it is caused by an unbounded user-controlled allocation size in the DRM lease creation ioctl, which attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` using the `kmalloc` family of functions.
### Root Cause Analysis
The crash is a warning triggered in `alloc_order_allowed()` because `__alloc_frozen_pages_noprof()` is called with an allocation order that exceeds `MAX_PAGE_ORDER` (typically 10, which corresponds to 4MB on systems with 4KB pages).
This happens in `fill_object_idr()` when allocating the `objects` array:
```c
// drivers/gpu/drm/drm_lease.c:389
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
The `kzalloc_objs` macro expands to a `kmalloc`-family allocation (equivalent to `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`).
The `object_count` comes directly from the user-space `drm_mode_create_lease` struct via `cl->object_count` in `drm_mode_create_lease_ioctl()`. There is no upper bound check on this value.
Before calling `fill_object_idr()`, `drm_mode_create_lease_ioctl()` allocates the `object_ids` array using `memdup_array_user()`:
```c
// drivers/gpu/drm/drm_lease.c:512
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user()` uses `memdup_user()`, which allocates memory with `GFP_USER | __GFP_NOWARN`. Because of the `__GFP_NOWARN` flag, if `object_count` is extremely large (e.g., requiring > 4MB), `memdup_array_user()` will silently fail and return `-ENOMEM` without triggering any warnings.
However, there is a specific window where `object_count` is large enough to require more than 4MB for the `objects` array (which has 8-byte pointers on 64-bit systems), but small enough that the `object_ids` array (which has 4-byte `__u32` elements) fits within 4MB.
In the provided syzkaller reproducer:
```c
*(uint32_t*)0x200003c8 = 0xf4240; // object_count = 1,000,000
```
1. `object_count` is set to `1,000,000`.
2. `memdup_array_user()` allocates `1,000,000 * 4 = 4,000,000` bytes. This is order 10, which is `<= MAX_PAGE_ORDER`. The allocation succeeds.
3. `fill_object_idr()` then calls `kzalloc_objs()` to allocate `1,000,000 * 8 = 8,000,000` bytes. This requires order 11, which is `> MAX_PAGE_ORDER`.
4. Since `kzalloc_objs()` uses `GFP_KERNEL` without `__GFP_NOWARN`, the page allocator loudly complains and triggers the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` warning.
### Proposed Fix
To fix this, the allocation of the `objects` array in `fill_object_idr()` should be changed to use `kvzalloc_objs()`, which gracefully falls back to `vmalloc()` for large allocations and does not trigger the page allocator warning. The corresponding `kfree()` must also be updated to `kvfree()`.
```c
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,7 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +462,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
```
*(Note: While adding an arbitrary upper bound check to `object_count` in `drm_mode_create_lease_ioctl()` is another option, using `kvzalloc_objs()` is the standard kernel pattern for handling user-controlled array sizes without imposing artificial limits).*
The proposed patch diff:
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -3,6 +3,9 @@
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
@@ -386,7 +389,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +465,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
@@ -496,6 +499,11 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
@@ -509,8 +517,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
@@ -520,7 +528,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
Review this patch diff against the crash report, root cause explanation, and kernel architectural design guidelines.
|
| 302/5 |
2026/10/13 23:55 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 11067
output: 39
thoughts: 58
Thoughts: Okay, let's dive into this. Someone wants me to review a kernel patch, specifically one addressing a bug. My immediate thought is, "Right, let's break this down systematically."
**Patch Review Protocol Activated**
First, I need to fully understand the nature of the crash. What's the context? What are the symptoms? Then, and *only* then, can I make heads or tails of the proposed patch. Next, I need to get my hands on the actual code, the patch itself, and preferably a local copy of the repository for easy inspection. We are dealing with low-level kernel code so the tooling is everything. It will also make it much easier to explore related areas and ensure the fix is complete and doesn't introduce regressions.
Let's start by digging into the core issue. I've been directed to examine `drivers/gpu/drm/drm_lease.c`. Alright, fire up the IDE, load the repository, and let's start dissecting that file. We'll start with a straightforward reading and then move to a more thorough analysis.
|
| 303/5 |
2026/10/13 23:55 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:380 LineCount:80]
Results: map[Contents: 380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
]
|
| 304/5 |
2026/10/13 23:55 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 12720
output: 39
thoughts: 30
Thoughts: Okay, here's my take on those lines of code, presented as a personal thought process, assuming I'm already pretty familiar with the DRM and lease concepts:
**Deep Dive into DRM Lease Management**
Alright, let's get into the nitty-gritty of how the lease mechanism works, specifically within `drivers/gpu/drm/drm_lease.c`, focusing on the area around line 460 through 560. I need to refresh my memory on the critical sections here.
Okay, I'm expecting this section to likely handle things like lease creation, revocation, or maybe even the granting/revocation of file descriptors associated with the lease, based on prior exposure to other DRM code. I'll need to see how the code deals with the specific lease's permissions, ownership, and client connections. I wonder if it includes the logic for validating client requests or handling conflict resolution when multiple clients are requesting the same resources. It could also detail the interactions with the underlying kernel memory and DRM resources.
I'll be looking carefully to see how the kernel handles the potential race conditions that can happen when juggling access rights. I'll be expecting to see a lot of locking, maybe mutexes or spinlocks, to protect shared data structures related to the lease. I'm especially interested in how the driver ensures atomicity of the operation, given that DRM is such a low-level and latency-sensitive part of the system. I'll be keeping an eye out for any subtle bugs or optimizations that stand out to me as I read. I'll be looking for things like reference counting and memory management.
|
| 305/5 |
2026/10/13 23:55 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:460 LineCount:90]
Results: map[Contents: 460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
465: kfree(objects);
466: return ret;
467: }
468:
469: /*
470: * The master associated with the specified file will have a lease
471: * created containing the objects specified in the ioctl structure.
472: * A file descriptor will be allocated for that and returned to the
473: * application.
474: */
475: int drm_mode_create_lease_ioctl(struct drm_device *dev,
476: void *data, struct drm_file *lessor_priv)
477: {
478: struct drm_mode_create_lease *cl = data;
479: size_t object_count;
480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
540: /* lessee will take the ownership of leases */
541: lessee = drm_lease_create(lessor, &leases);
542:
543: if (IS_ERR(lessee)) {
544: ret = PTR_ERR(lessee);
545: idr_destroy(&leases);
546: goto out_leases;
547: }
548:
549: /* Clone the lessor file to create a new file for us */
]
|
| 306/5 |
2026/10/13 23:55 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 14476
output: 32
thoughts: 49
Thoughts: Okay, let's dive into this. Here's how I'm approaching this problem:
**Analyzing Potential Issues in DRM Lease Handling**
Alright, my initial thought is to get a handle on what's been happening with `drm_lease.c` and potentially related issues within the DRM subsystem, especially where memory management β specifically `page_alloc` β is concerned. The goal is to identify a pattern or trace a history.
So, I'm going to start by getting a clean view of the git history for the `drm_lease.c` file itself. I'll execute a `git log` command directly on that file. This should give me a chronological record of all modifications, additions, and removals specific to this source file. From there, I'll review relevant changes and try to identify commits with related warnings, error messages, or suspicious behavior. I'll be looking for changes concerning leases that might have unintentionally interacted with memory allocation in ways that cause problems. If I can understand the history of this code then, potentially, I can better understand its current issues.
|
| 307/5 |
2026/10/13 23:56 |
tool |
git-log |
0m
Args: map[Count:10 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
f37d63e219c3 drm_lease.c: copy user-array safely
cde3d37b19df drm: Remove unnecessary include statements for drm_crtc_helper.h
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
4bb2d367a5a2 drm/lease: allow empty leases
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
d793b8f732d6 drm: clarify usage of drm leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
7988fdf5f0a3 drm: Don't include drm_legacy.h in drm_lease.c
]
|
| 308/5 |
2026/10/13 23:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 15052
output: 27
thoughts: 19
Thoughts: Okay, I'm ready. Let's dig into this commit:
**Analyzing Commit f37d63e219c3**
Alright, let's pull up that commit, `f37d63e219c3`. Hmm, let me quickly review the diff. Okay, so it looks like we've got some changes in [briefly describe the area or files affected, e.g., the core API, the data processing module, or the UI component]. I need to assess the implications here. First, I'm scanning for potential regressions. Given my understanding of the system, are there any obvious areas that might be impacted negatively by these modifications? I see a change to [specific function/class/variable]. My immediate thought is to consider the downstream dependencies of this particular component - how are others calling it? Does this modification follow the expected pattern? I have to consider side effects. Are there any potential performance bottlenecks introduced? I'll need to do some more in-depth static analysis to be certain. Next, I need to focus on any new functionality. It's crucial for me to understand the purpose of these changes at a high level. Is this intended to address a specific bug? Does it enhance the performance, or is this related to a new feature? Are the comments and commit message clear enough to explain the motivation behind this modification? Does this commit follow our architectural principles and coding guidelines? If this commit modifies any external dependencies, I'll review these too. Finally, let me see if these changes are accompanied by test coverage. Any unit tests or integration tests to validate the intended behavior? Good test coverage is critical to avoid any issues in the future.
|
| 309/5 |
2026/10/13 23:56 |
tool |
git-show |
0m
Args:
Results: map[Output:commit f37d63e219c39199a59b8b8a211412ff27192830
Author: Philipp Stanner <pstanner@redhat.com>
Date: Wed Sep 20 14:36:12 2023 +0200
drm_lease.c: copy user-array safely
Currently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for
duplicating the user-space array safely.
Suggested-by: David Airlie <airlied@redhat.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230920123612.16914-6-pstanner@redhat.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 150fe1555068..94375c6a5425 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -510,8 +510,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
- array_size(object_count, sizeof(__u32)));
+ object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
]
|
| 310/5 |
2026/10/13 23:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 16048
output: 19
thoughts: 944
Thoughts: **Analyzing the DRM Lease Patch**
Okay, first things first, let me thoroughly examine this proposed patch. I need to understand the nuances of these changes to the DRM lease code. My initial thought is to make sure nothing fishy is going on, and to assess whether the suggested modifications improve the driver's robustness and efficiency.
Alright, I see a few key areas of interest right away. First, there's a replacement of `kzalloc_objs` with `kvzalloc_objs`. I need to understand why this change was made. What is the distinction? Does the new function align with the existing kernel memory management strategies? Does it have any implications for memory alignment or other low-level considerations within this DRM context?
Then, I'm noting that `kfree` is being swapped to `kvfree`. Again, I have to determine why this change has been made. I need to cross-check this to see if it's the correct change.
I also see a new check added in `drm_mode_create_lease_ioctl`, specifically regarding `object_count`. This is good, ensuring that we're handling potentially large object counts gracefully. Preventing an integer overflow or an allocation of excessive memory is key. I'll need to confirm that the `INT_MAX` limit is appropriate here, and that the check is implemented correctly.
Finally, there is a swap out of `memdup_array_user` to `vmemdup_array_user`. I wonder what the performance implications, if any, there are between these two functions?
Alright, before I proceed further, I should verify the existence of `kvzalloc_objs` and the other new memory functions! A quick search within the kernel source is in order, just to confirm that these functions are actually defined and part of the kernel's memory management system. It's always wise to verify before trusting anything.
|
| 311/5 |
2026/10/13 23:56 |
tool |
grepper |
0m
Args: map[Expression:kvzalloc_objs]
Results: map[Output:
Full output is too long, showing 200 out of 1188 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (137 files in total):
arch/arm64/kvm/nested.c:1
arch/arm64/net/bpf_jit_comp.c:1
arch/riscv/kvm/vcpu_pmu.c:1
arch/riscv/net/bpf_jit_comp64.c:1
arch/riscv/net/bpf_jit_core.c:1
arch/x86/kvm/cpuid.c:1
arch/x86/kvm/mmu/mmu.c:1
arch/x86/kvm/svm/sev.c:1
block/blk-crypto-profile.c:1
drivers/accel/amdxdna/amdxdna_gem.c:1
drivers/accel/amdxdna/amdxdna_ubuf.c:1
drivers/accel/habanalabs/common/mmu/mmu.c:1
drivers/accel/qaic/qaic_data.c:1
drivers/android/binder_alloc.c:1
drivers/block/xen-blkfront.c:3
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:1
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c:1
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:6
drivers/gpu/drm/amd/amdkfd/kfd_svm.c:1
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:8
drivers/gpu/drm/drm_gpusvm.c:1
drivers/gpu/drm/nouveau/nouveau_dmem.c:1
drivers/gpu/drm/nouveau/nouveau_svm.c:1
drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmm.c:1
drivers/gpu/drm/radeon/radeon_cs.c:2
drivers/gpu/drm/ttm/ttm_tt.c:1
drivers/gpu/drm/virtio/virtgpu_submit.c:2
drivers/gpu/drm/xe/xe_vm.c:2
drivers/infiniband/hw/hns/hns_roce_debugfs.c:1
drivers/infiniband/hw/hns/hns_roce_main.c:1
drivers/infiniband/hw/hns/hns_roce_mr.c:2
drivers/infiniband/ulp/ipoib/ipoib_main.c:1
drivers/iommu/amd/init.c:2
drivers/iommu/dma-iommu.c:1
drivers/iommu/iommufd/selftest.c:1
drivers/iommu/iommufd/viommu.c:1
drivers/md/dm-pcache/cache.c:1
drivers/md/dm-pcache/cache_key.c:1
drivers/md/dm-snap-persistent.c:1
drivers/md/raid0.c:1
drivers/media/common/videobuf2/videobuf2-dma-sg.c:1
drivers/media/v4l2-core/v4l2-ctrls-core.c:1
drivers/media/v4l2-core/v4l2-subdev.c:2
drivers/net/ethernet/alibaba/eea/eea_net.c:3
drivers/net/ethernet/alibaba/eea/eea_rx.c:1
drivers/net/ethernet/alibaba/eea/eea_tx.c:1
drivers/net/ethernet/broadcom/cnic.c:1
drivers/net/ethernet/chelsio/cxgb4/clip_tbl.c:1
... and 87 more files
arch/arm64/kvm/nested.c=83=int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
--
arch/arm64/kvm/nested.c-106-
arch/arm64/kvm/nested.c:107: tmp = kvzalloc_objs(*tmp, S2_MMU_PER_VCPU, GFP_KERNEL_ACCOUNT);
arch/arm64/kvm/nested.c-108- if (!tmp)
--
arch/arm64/net/bpf_jit_comp.c=2158=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
--
arch/arm64/net/bpf_jit_comp.c-2213-
arch/arm64/net/bpf_jit_comp.c:2214: ctx.offset = kvzalloc_objs(int, prog->len + 1);
arch/arm64/net/bpf_jit_comp.c-2215- if (ctx.offset == NULL)
--
arch/riscv/kvm/vcpu_pmu.c=488=int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low,
--
arch/riscv/kvm/vcpu_pmu.c-514-
arch/riscv/kvm/vcpu_pmu.c:515: einfo = kvzalloc_objs(*einfo, num_events,
arch/riscv/kvm/vcpu_pmu.c-516- GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
--
arch/riscv/net/bpf_jit_comp64.c=1019=static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
--
arch/riscv/net/bpf_jit_comp64.c-1206- if (fmod_ret->nr_nodes) {
arch/riscv/net/bpf_jit_comp64.c:1207: branches_off = kvzalloc_objs(int, fmod_ret->nr_nodes);
arch/riscv/net/bpf_jit_comp64.c-1208- if (!branches_off)
--
arch/riscv/net/bpf_jit_core.c=44=struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_prog *prog)
--
arch/riscv/net/bpf_jit_core.c-74- ctx->prog = prog;
arch/riscv/net/bpf_jit_core.c:75: ctx->offset = kvzalloc_objs(int, prog->len);
arch/riscv/net/bpf_jit_core.c-76- if (!ctx->offset)
--
arch/x86/kvm/cpuid.c=1992=int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
--
arch/x86/kvm/cpuid.c-2012-
arch/x86/kvm/cpuid.c:2013: array.entries = kvzalloc_objs(struct kvm_cpuid_entry2, cpuid->nent);
arch/x86/kvm/cpuid.c-2014- if (!array.entries)
--
arch/x86/kvm/mmu/mmu.c=4044=static int kvm_mmu_alloc_page_hash(struct kvm *kvm)
--
arch/x86/kvm/mmu/mmu.c-4050-
arch/x86/kvm/mmu/mmu.c:4051: h = kvzalloc_objs(*h, KVM_NUM_MMU_PAGES, GFP_KERNEL_ACCOUNT);
arch/x86/kvm/mmu/mmu.c-4052- if (!h)
--
arch/x86/kvm/svm/sev.c=776=static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
--
arch/x86/kvm/svm/sev.c-807- */
arch/x86/kvm/svm/sev.c:808: pages = kvzalloc_objs(*pages, npages, GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
arch/x86/kvm/svm/sev.c-809- if (!pages)
--
block/blk-crypto-profile.c=76=int blk_crypto_profile_init(struct blk_crypto_profile *profile,
--
block/blk-crypto-profile.c-97-
block/blk-crypto-profile.c:98: profile->slots = kvzalloc_objs(profile->slots[0], num_slots);
block/blk-crypto-profile.c-99- if (!profile->slots)
--
drivers/accel/amdxdna/amdxdna_gem.c=348=static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
--
drivers/accel/amdxdna/amdxdna_gem.c-383- nr_pages = (PAGE_ALIGN(addr + len) - (addr & PAGE_MASK)) >> PAGE_SHIFT;
drivers/accel/amdxdna/amdxdna_gem.c:384: mapp->range.hmm_pfns = kvzalloc_objs(*mapp->range.hmm_pfns, nr_pages);
drivers/accel/amdxdna/amdxdna_gem.c-385- if (!mapp->range.hmm_pfns) {
--
drivers/accel/amdxdna/amdxdna_ubuf.c=78=struct dma_buf *amdxdna_get_ubuf(struct drm_device *dev,
--
drivers/accel/amdxdna/amdxdna_ubuf.c-99-
drivers/accel/amdxdna/amdxdna_ubuf.c:100: va_ent = kvzalloc_objs(*va_ent, num_entries);
drivers/accel/amdxdna/amdxdna_ubuf.c-101- if (!va_ent) {
--
drivers/accel/habanalabs/common/mmu/mmu.c=824=int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 hop_table_size,
--
drivers/accel/habanalabs/common/mmu/mmu.c-845-
drivers/accel/habanalabs/common/mmu/mmu.c:846: hr_priv->mmu_asid_hop0 = kvzalloc_objs(struct pgt_info, prop->max_asid);
drivers/accel/habanalabs/common/mmu/mmu.c-847- if (ZERO_OR_NULL_PTR(hr_priv->mmu_asid_hop0)) {
--
drivers/accel/qaic/qaic_data.c=391=static int qaic_map_one_slice(struct qaic_device *qdev, struct qaic_bo *bo,
--
drivers/accel/qaic/qaic_data.c-407-
drivers/accel/qaic/qaic_data.c:408: slice->reqs = kvzalloc_objs(*slice->reqs, sgt->nents);
drivers/accel/qaic/qaic_data.c-409- if (!slice->reqs) {
--
drivers/android/binder_alloc.c=894=int binder_alloc_mmap_handler(struct binder_alloc *alloc,
--
drivers/android/binder_alloc.c-918-
drivers/android/binder_alloc.c:919: alloc->pages = kvzalloc_objs(alloc->pages[0],
drivers/android/binder_alloc.c-920- alloc->buffer_size / PAGE_SIZE);
--
drivers/block/xen-blkfront.c=2170=static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
--
drivers/block/xen-blkfront.c-2218- rinfo->shadow[i].grants_used =
drivers/block/xen-blkfront.c:2219: kvzalloc_objs(rinfo->shadow[i].grants_used[0], grants);
drivers/block/xen-blkfront.c:2220: rinfo->shadow[i].sg = kvzalloc_objs(rinfo->shadow[i].sg[0],
drivers/block/xen-blkfront.c-2221- psegs);
--
drivers/block/xen-blkfront.c-2223- rinfo->shadow[i].indirect_grants =
drivers/block/xen-blkfront.c:2224: kvzalloc_objs(rinfo->shadow[i].indirect_grants[0],
drivers/block/xen-blkfront.c-2225- INDIRECT_GREFS(grants));
--
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c=40=static void *qat_zstd_alloc_scratch(void)
--
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c-61-
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c:62: scratch->out_seqs = kvzalloc_objs(ZSTD_Sequence, QAT_MAX_SEQUENCES);
drivers/crypto/intel/qat/qat_common/qat_comp_algs.c-63- if (!scratch->out_seqs)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c=546=void amdgpu_coredump(struct amdgpu_device *adev, bool skip_vram_check,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c-605- if (ring_count)
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c:606: coredump->rings = kvzalloc_objs(struct amdgpu_coredump_ring,
drivers/gpu/drm/amd/amdgpu/amdgpu_dev_coredump.c-607- ring_count, GFP_NOWAIT);
--
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c=1194=int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c-1218-
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:1219: bo_entries = kvzalloc_objs(*bo_entries, num_bos);
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c-1220- if (!bo_entries)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c=1264=amdgpu_ras_debugfs_table_read_uniras(struct amdgpu_device *adev,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c-1295- if (num_recs) {
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c:1296: records = kvzalloc_objs(*records, num_recs);
drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c-1297- if (!records) {
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c=1957=static int criu_checkpoint_devices(struct kfd_process *p,
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-1966-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:1967: device_buckets = kvzalloc_objs(*device_buckets, num_devices);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-1968- if (!device_buckets) {
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-1972-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:1973: device_priv = kvzalloc_objs(*device_priv, num_devices);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-1974- if (!device_priv) {
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c=2081=static int criu_checkpoint_bos(struct kfd_process *p,
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2092-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:2093: bo_buckets = kvzalloc_objs(*bo_buckets, num_bos);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2094- if (!bo_buckets)
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2096-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:2097: bo_privs = kvzalloc_objs(*bo_privs, num_bos);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2098- if (!bo_privs) {
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2102-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:2103: files = kvzalloc_objs(struct file *, num_bos);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2104- if (!files) {
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c=2613=static int criu_restore_bos(struct kfd_process *p,
--
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2633-
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c:2634: files = kvzalloc_objs(struct file *, args->num_bos);
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c-2635- if (!files) {
--
drivers/gpu/drm/amd/amdkfd/kfd_svm.c=159=svm_range_dma_map_dev(struct amdgpu_device *adev, struct svm_range *prange,
--
drivers/gpu/drm/amd/amdkfd/kfd_svm.c-169- if (!addr) {
drivers/gpu/drm/amd/amdkfd/kfd_svm.c:170: addr = kvzalloc_objs(*addr, prange->npages);
drivers/gpu/drm/amd/amdkfd/kfd_svm.c-171- if (!addr)
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c=1672=bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1718- if (map_user_ramp && ramp && ramp->type == GAMMA_RGB_256) {
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1719: rgb_user = kvzalloc_objs(*rgb_user,
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1720- ramp->num_entries + _EXTRA_POINTS);
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1723-
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1724: axis_x = kvzalloc_objs(*axis_x,
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1725- ramp->num_entries + _EXTRA_POINTS);
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1740-
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1741: curve = kvzalloc_objs(*curve, MAX_HW_POINTS + _EXTRA_POINTS);
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1742- if (!curve)
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1744-
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1745: coeff = kvzalloc_objs(*coeff, MAX_HW_POINTS + _EXTRA_POINTS);
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1746- if (!coeff)
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c=1907=bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf,
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1941- (map_user_ramp || ramp->type != GAMMA_RGB_256)) {
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1942: rgb_user = kvzalloc_objs(*rgb_user,
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1943- ramp->num_entries + _EXTRA_POINTS);
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1946-
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1947: axis_x = kvzalloc_objs(*axis_x, ramp->num_entries + 3);
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1948- if (!axis_x)
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1965-
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1966: rgb_regamma = kvzalloc_objs(*rgb_regamma, MAX_HW_POINTS + _EXTRA_POINTS);
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1967- if (!rgb_regamma)
--
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1969-
drivers/gpu/drm/amd/display/modules/color/color_gamma.c:1970: coeff = kvzalloc_objs(*coeff, MAX_HW_POINTS + _EXTRA_POINTS);
drivers/gpu/drm/amd/display/modules/color/color_gamma.c-1971- if (!coeff)
--
drivers/gpu/drm/drm_gpusvm.c=1459=int drm_gpusvm_get_pages(struct drm_gpusvm *gpusvm,
--
drivers/gpu/drm/drm_gpusvm.c-1546- svm_pages->dma_addr =
drivers/gpu/drm/drm_gpusvm.c:1547: kvzalloc_objs(*svm_pages->dma_addr, npages);
drivers/gpu/drm/drm_gpusvm.c-1548- if (!svm_pages->dma_addr) {
--
drivers/gpu/drm/nouveau/nouveau_dmem.c=489=nouveau_dmem_evict_chunk(struct nouveau_dmem_chunk *chunk)
--
drivers/gpu/drm/nouveau/nouveau_dmem.c-497- dst_pfns = kvcalloc(npages, sizeof(*dst_pfns), GFP_KERNEL | __GFP_NOFAIL);
]
|
| 312/5 |
2026/10/13 23:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 23629
output: 21
thoughts: 43
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Examining the kvzalloc_objs Definition**
Alright, so `kvzalloc_objs` is declared in `include/linux/slab.h`. That's where it *should* be, but let's not make assumptions. I need to be absolutely sure about the actual definition, and what other factors come into play. I'll need to go directly to `include/linux/slab.h` and check the actual declaration, look for dependencies, and any potentially important macro expansions or inline behaviors. I want to thoroughly understand its structure and purpose before proceeding. Let's make sure it is exactly what I expect.
|
| 313/5 |
2026/10/13 23:56 |
tool |
grepper |
0m
Args: map[Expression:#define kvzalloc_objs]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1172- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1173:#define kvzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1174- __alloc_objs(kvzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
]
|
| 314/5 |
2026/10/13 23:56 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 24005
output: 20
thoughts: 23
Thoughts: Here's my thought process, as if I were considering this myself:
**Investigating `kzalloc_objs` Definition**
Okay, so I'm deep into this memory allocation issue, and I need to understand the fundamental building blocks. My first thought is: I need to refresh my memory on exactly how `kzalloc_objs` is defined. Knowing the specifics of this structure, especially in `include/linux/slab.h`, will give me a vital view on how the kernel is handling zeroed memory allocations, which is relevant to the issue I am debugging. I need to see the data structures involved, and any associated context or macros. Let me go check that header file and take a look.
|
| 315/5 |
2026/10/13 23:56 |
tool |
grepper |
0m
Args: map[Expression:#define kzalloc_objs]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1156- __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), 1)
include/linux/slab.h:1157:#define kzalloc_objs(P, COUNT, ...) \
include/linux/slab.h-1158- __alloc_objs(kzalloc, default_gfp(__VA_ARGS__), typeof(P), COUNT)
]
|
| 316/5 |
2026/10/13 23:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 24354
output: 21
thoughts: 47
Thoughts: Okay, let's dive into this.
**Examining the `vmemdup_array_user` Function**
Right, my focus is now on `vmemdup_array_user`. I need to confirm its existence first. It's time to run a quick grep search across the kernel source. I'm going to quickly look for any instances of `vmemdup_array_user` to get a sense of where it's used and, crucially, to make sure it's actually defined within the codebase. This initial check is fundamental. Knowing the function exists is the foundation for any deeper investigation into its behavior and potential interactions. I'll be looking for both the declaration and any calls to it.
|
| 317/5 |
2026/10/13 23:57 |
tool |
grepper |
0m
Args: map[Expression:vmemdup_array_user]
Results: map[Output:arch/x86/kvm/cpuid.c=590=int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
--
arch/x86/kvm/cpuid.c-601- if (cpuid->nent) {
arch/x86/kvm/cpuid.c:602: e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e));
arch/x86/kvm/cpuid.c-603- if (IS_ERR(e))
--
arch/x86/kvm/cpuid.c=635=int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
--
arch/x86/kvm/cpuid.c-645- if (cpuid->nent) {
arch/x86/kvm/cpuid.c:646: e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2));
arch/x86/kvm/cpuid.c-647- if (IS_ERR(e2))
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c=164=amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-174-
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:175: return vmemdup_array_user(uptr, bo_number,
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-176- sizeof(struct drm_amdgpu_bo_list_entry));
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c=179=static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-219-
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:220: p->chunks[i].kdata = vmemdup_array_user(u64_to_user_ptr(user_chunk.chunk_data),
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-221- size,
--
drivers/gpu/drm/drm_gem.c=832=int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
--
drivers/gpu/drm/drm_gem.c-847-
drivers/gpu/drm/drm_gem.c:848: handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
drivers/gpu/drm/drm_gem.c-849- if (IS_ERR(handles)) {
--
drivers/tty/vt/consolemap.c=632=int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
--
drivers/tty/vt/consolemap.c-640-
drivers/tty/vt/consolemap.c:641: struct unipair *unilist __free(kvfree) = vmemdup_array_user(list, ct, sizeof(*unilist));
drivers/tty/vt/consolemap.c-642- if (IS_ERR(unilist))
--
include/linux/string.h=32=void *memdup_array_user(const void __user *src, size_t n, size_t size)
--
include/linux/string.h-42-/**
include/linux/string.h:43: * vmemdup_array_user - duplicate array from user space
include/linux/string.h-44- * @src: source address in user space
--
include/linux/string.h=51=static inline __realloc_size(2, 3)
include/linux/string.h:52:void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
include/linux/string.h-53-{
--
virt/kvm/kvm_main.c=5177=static long kvm_vm_ioctl(struct file *filp,
--
virt/kvm/kvm_main.c-5344- urouting = argp;
virt/kvm/kvm_main.c:5345: entries = vmemdup_array_user(urouting->entries,
virt/kvm/kvm_main.c-5346- routing.nr, sizeof(*entries));
]
|
| 318/5 |
2026/10/13 23:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 25786
output: 34
thoughts: 43
Thoughts: Here's my take on the thought process:
**Diving into String Manipulation in the Kernel**
Okay, so `vmemdup_array_user`... right, I seem to recall that's defined somewhere in the kernel's string header. Let me just confirm that. I'm pretty sure it's `include/linux/string.h`. Alright, let's navigate straight to that file and, given the common function structure I'm expecting it to be around the more basic `memcpy` kind of functions, I'll focus on lines 40-70. Let's start there and see if it's got what I'm looking for. That should give me the function's definition, any relevant comments, and probably its arguments.
|
| 319/5 |
2026/10/13 23:57 |
tool |
read-file |
0m
Args: map[File:include/linux/string.h FirstLine:40 LineCount:35]
Results: map[Contents: 40: }
41:
42: /**
43: * vmemdup_array_user - duplicate array from user space
44: * @src: source address in user space
45: * @n: number of array members to copy
46: * @size: size of one array member
47: *
48: * Return: an ERR_PTR() on failure. Result may be not
49: * physically contiguous. Use kvfree() to free.
50: */
51: static inline __realloc_size(2, 3)
52: void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
53: {
54: size_t nbytes;
55:
56: if (check_mul_overflow(n, size, &nbytes))
57: return ERR_PTR(-EOVERFLOW);
58:
59: return vmemdup_user(src, nbytes);
60: }
61:
62: /*
63: * Include machine specific inline routines
64: */
65: #include <asm/string.h>
66:
67: #ifndef __HAVE_ARCH_STRCPY
68: extern char * strcpy(char *,const char *);
69: #endif
70: ssize_t sized_strscpy(char *, const char *, size_t);
71:
72: /*
73: * The 2 argument style can only be used when dst is an array with a
74: * known size.
]
|
| 320/5 |
2026/10/13 23:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 26490
output: 39
thoughts: 81
Thoughts: Here's my take on those lines of code, seeing as I'm familiar with this area:
**Analyzing `drm_gem_objects_lookup` and Its Handle Processing**
Okay, so I'm digging into `drm_gem_objects_lookup` now, specifically around line 848. I see that `handles = vmemdup_array_user(bo_handles, count, sizeof(u32));` is the key line in question. Essentially, it appears we're using `vmemdup_array_user` to create a kernel-space copy of a user-provided array of buffer object handles. The goal here, as I understand it, is to securely copy a list of handle values from user space into a kernel-allocated buffer for internal use.
To fully grasp the context and potential pitfalls here, I'll need to refresh my memory on how this `drm_gem_objects_lookup` function interacts with the overall GEM object management scheme. I'll need to go back to `drivers/gpu/drm/drm_gem.c`, probably around lines 830-860, to see how these handles are validated, used, and subsequently released. I'm keen to check for potential security issues like integer overflows, or any possible information leak from how the handles are being sanitized, mapped, or handled in this section.
|
| 321/5 |
2026/10/13 23:57 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_gem.c FirstLine:830 LineCount:40]
Results: map[Contents: 830: * Zero on success or a negative error code.
831: */
832: int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
833: int count, struct drm_gem_object ***objs_out)
834: {
835: struct drm_gem_object **objs;
836: u32 *handles;
837: int ret;
838:
839: *objs_out = NULL;
840:
841: if (!count)
842: return 0;
843:
844: objs = kvmalloc_objs(*objs, count);
845: if (!objs)
846: return -ENOMEM;
847:
848: handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
849: if (IS_ERR(handles)) {
850: ret = PTR_ERR(handles);
851: goto err_free_objs;
852: }
853:
854: ret = objects_lookup(filp, handles, count, objs);
855: if (ret)
856: goto err_free_handles;
857:
858: kvfree(handles);
859: *objs_out = objs;
860: return 0;
861:
862: err_free_handles:
863: kvfree(handles);
864: err_free_objs:
865: kvfree(objs);
866: return ret;
867: }
868: EXPORT_SYMBOL(drm_gem_objects_lookup);
869:
]
|
| 322/5 |
2026/10/13 23:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 27426
output: 42
thoughts: 292
Thoughts: **Analyzing Lease Creation in the DRM Subsystem**
Alright, let's see, I'm taking a look at how leases are handled, specifically focusing on the object handling and creation flow. I'm noticing this `drm_gem_objects_lookup` function first; it looks like it's responsible for retrieving the GEM objects. I see memory allocation with `kvmalloc_objs` and handle duplication with `vmemdup_array_user`. I'm also seeing the subsequent freeing with `kvfree`, which is good to see for resource management.
Now, let's dig into `drm_lease.c`, and specifically the `drm_mode_create_lease_ioctl` function. Okay, so we have this structure, `drm_mode_create_lease`, and it looks like it's receiving a data pointer. There's an `idr leases`, a `lessor` master, and a potential `lessee` master. We've got file pointers for both the lessor and lessee, and an FD that is initialized to -1.
Wait a second... I need to double-check something. What *exactly* is the type of `cl->object_count`? That's critical information here. Time to go find the definition of `struct drm_mode_create_lease` and make sure I know what I'm dealing with.
|
| 323/5 |
2026/10/13 23:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_create_lease]
Results: map[SourceCode:1425: /**
1426: * struct drm_mode_create_lease - Create lease
1427: *
1428: * Lease mode resources, creating another drm_master.
1429: *
1430: * The @object_ids array must reference at least one CRTC, one connector and
1431: * one plane if &DRM_CLIENT_CAP_UNIVERSAL_PLANES is enabled. Alternatively,
1432: * the lease can be completely empty.
1433: */
1434: struct drm_mode_create_lease {
1435: /** @object_ids: Pointer to array of object ids (__u32) */
1436: __u64 object_ids;
1437: /** @object_count: Number of object ids */
1438: __u32 object_count;
1439: /** @flags: flags for new FD (O_CLOEXEC, etc) */
1440: __u32 flags;
1441:
1442: /** @lessee_id: Return: unique identifier for lessee. */
1443: __u32 lessee_id;
1444: /** @fd: Return: file descriptor to new drm_master file */
1445: __u32 fd;
1446: };
SourceFile:include/uapi/drm/drm_mode.h]
|
| 324/5 |
2026/10/13 23:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 28437
output: 38
thoughts: 1361
Thoughts: **Analyzing a Potential Integer Overflow Vulnerability in DRM Lease Code**
Okay, so I'm looking at this DRM lease code and immediately something jumps out at me. We've got `cl->object_count`, which is a `__u32`, and it's being assigned to a `size_t` variable called `object_count`. Fine, that's normal. Then, that `object_count` (which, as a `size_t`, is unsigned) is being passed to the `fill_object_idr` function.
But, hang on... the *signature* of `fill_object_idr` takes an *`int`* for the `object_count` argument! This is a classic potential integer overflow vulnerability. If `cl->object_count` has a value greater than `INT_MAX`, the conversion to `int` will cause it to become a *negative* number.
The original code didn't handle the case where `cl->object_count` could be greater than `INT_MAX`, which means that it can result in a negative number, which results in very bad outcomes down the line.
The fix I'm seeing adds a check:
```c
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
```
This prevents the integer overflow by checking if `cl->object_count` exceeds a safe upper bound when converted to `int` based on the size of the objects. That's a good start, but I need to make sure I understand the scope of the fix. The patch also has other changes: It uses `kvzalloc_objs` and `kvfree` instead of `kzalloc_objs` and `kfree`, which is just a change from `GFP_KERNEL` to `GFP_KERNEL | __GFP_ZERO`. It also uses `vmemdup_array_user` instead of `memdup_array_user`. I need to ensure these changes are correct and don't introduce other issues.
Specifically, I need to ensure that the change of `object_count` being passed to `validate_lease` is still safe after this fix is added and that all of these changes are applied correctly.
|
| 325/5 |
2026/10/13 23:57 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:validate_lease]
Results: map[SourceCode: 346: static int validate_lease(struct drm_device *dev,
347: int object_count,
348: struct drm_mode_object **objects,
349: bool universal_planes)
350: {
351: int o;
352: int has_crtc = -1;
353: int has_connector = -1;
354: int has_plane = -1;
355:
356: /* we want to confirm that there is at least one crtc, plane
357: connector object. */
358:
359: for (o = 0; o < object_count; o++) {
360: if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
361: has_crtc = o;
362: }
363: if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
364: has_connector = o;
365:
366: if (universal_planes) {
367: if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
368: has_plane = o;
369: }
370: }
371: if (has_crtc == -1 || has_connector == -1)
372: return -EINVAL;
373: if (universal_planes && has_plane == -1)
374: return -EINVAL;
375: return 0;
376: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 326/5 |
2026/10/13 23:57 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 30854
output: 39
thoughts: 1749
Thoughts: **Analyzing the DRM Lease Implementation**
Okay, let's break this down. First, `validate_lease`β¦ what's the core concept here? What kinds of objects are we even leasing? Specifically in the context of DRM, if `DRM_CLIENT_CAP_UNIVERSAL_PLANES` is enabled, the `@object_ids` array *must* reference at least one CRTC, one connector, and one plane. The number of mode objects on a device is limited, typically in the hundreds or low thousands β certainly not a million. I need to keep that in mind.
Now, that `if` statement⦠`if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))`. Where did that come from? It's there to prevent a huge value, but that check *does* appear in the diff, but *not* the root cause explanation, even though it *is* in the presented function: `drm_mode_create_lease_ioctl()`.
The provided fix suggests using `kvzalloc_objs()` instead of `kzalloc_objs` in `fill_object_idr()` to handle potentially large user-controlled array sizes gracefully. This aligns with the "standard kernel pattern" to avoid artificial limits, and it's accompanied by the appropriate `kvfree()` to go with it. So, that part makes sense as a standard and reasonable approach to this class of issue.
Let's look more closely at the patch placement of the `if (cl->object_count > ...)` check within `drm_mode_create_lease_ioctl()` code block. It appears *after* the `object_count` is read from the user space structure, *before* the master lessor is retrieved, and *before* the sub-lease check.
Looking at the context, this suggests the author is trying to prevent an integer overflow (although an issue with the allocation is mentioned in the prompt). The `object_count` could be an excessively large value, leading to a huge allocation request. The integer overflow check should also be in place for `kvzalloc_objs`! I should consider if there is another potential issue: `memdup_array_user` and `vmemdup_array_user` in the code, too! The use of `vmemdup_array_user` *could* be because this has similar issues to the page allocator warning.
|
| 327/5 |
2026/10/13 23:58 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:490 LineCount:25]
Results: map[Contents: 490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
]
|
| 328/5 |
2026/10/13 23:58 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 33570
output: 42
thoughts: 52
Thoughts: Okay, let's break this down.
**Diving into the DRM Master Retrieval**
Hold on a second, that line caught my eye: `lessor = drm_file_get_master(lessor_priv);` I need to understand what's happening here. The critical function is `drm_file_get_master()`. Itβs not immediately obvious what this function does from the surrounding context, so my next thought is, βWhat exactly *does* `drm_file_get_master()` *do*?". Time to investigate its implementation to determine its purpose! Let's go look at `drm_file_get_master`!
|
| 329/5 |
2026/10/13 23:58 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_file_get_master]
Results: map[SourceCode: 378: /**
379: * drm_file_get_master - reference &drm_file.master of @file_priv
380: * @file_priv: DRM file private
381: *
382: * Increments the reference count of @file_priv's &drm_file.master and returns
383: * the &drm_file.master. If @file_priv has no &drm_file.master, returns NULL.
384: *
385: * Master pointers returned from this function should be unreferenced using
386: * drm_master_put().
387: */
388: struct drm_master *drm_file_get_master(struct drm_file *file_priv)
389: {
390: struct drm_master *master = NULL;
391:
392: spin_lock(&file_priv->master_lookup_lock);
393: if (!file_priv->master)
394: goto unlock;
395: master = drm_master_get(file_priv->master);
396:
397: unlock:
398: spin_unlock(&file_priv->master_lookup_lock);
399: return master;
400: }
SourceFile:drivers/gpu/drm/drm_auth.c]
|
| 330/5 |
2026/10/13 23:58 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 34190
output: 20
thoughts: 688
Thoughts: **Analyzing the Lease Creation Patch**
Okay, let's break this down. First, the patch includes a check for invalid flags, and now a check for an `object_count` that is too large. My initial thought was that there might be a potential `lessor` leak if `drm_file_get_master` failed, but the `lessor` variable is only assigned *before* the invalid flag check, so the code is structured correctly and there's no leak. However, I need to confirm what is done if `drm_file_get_master` returns NULL. The following lines of code seem to indicate that the return is checked. I have confirmed that the DRM master flag is checked before `drm_mode_create_lease_ioctl` is called. So, the kernel code seems safe there.
My real question is why the added `object_count` check is there. I see the addition, and it looks like a size check to me, but I need to understand the implications of the value of this field. It's used in `vmemdup_array_user` and `fill_object_idr`. That's where it's used. The interesting thing is that `fill_object_idr` takes `int object_count` as an argument, and `validate_lease` also uses this integer. I should see if `object_count` itself is being converted. It also looks like a size check, as I suspect. In `fill_object_idr`, it is used to allocate `objects = kvzalloc_objs(struct drm_mode_object *, object_count);`. I should inspect this function to be sure. I'm going to follow the expansion of `kvzalloc_objs` to see where the memory allocation actually happens.
|
| 331/5 |
2026/10/13 23:58 |
tool |
grepper |
0m
Args: map[Expression:#define __alloc_objs]
Results: map[Output:include/linux/slab.h=1073=void *kmalloc_nolock(size_t size, gfp_t gfp_flags, int node);
--
include/linux/slab.h-1086- */
include/linux/slab.h:1087:#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
include/linux/slab.h-1088-({ \
--
tools/include/linux/slab.h=200=static inline unsigned int kmem_cache_sheaf_size(struct slab_sheaf *sheaf)
--
tools/include/linux/slab.h-204-
tools/include/linux/slab.h:205:#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
tools/include/linux/slab.h-206-({ \
]
|
| 332/5 |
2026/10/13 23:58 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 35502
output: 36
thoughts: 21
Thoughts: Okay, let's dive into this. Here's my take on those lines in `include/linux/slab.h`:
**Analyzing Slab Allocation - A Deep Dive**
Alright, I'm heading into `include/linux/slab.h` and pinpointing around line 1087. I'm immediately looking for how the kernel handles slab allocation, specifically how it's optimized. My focus is going to be on the interplay between memory zones, cachelines, and how this impacts overall performance. I need to understand the specifics of the data structures and how they're used to efficiently manage kernel memory. The goal is to see any recent changes and consider their impact on system stability and throughput. I'm anticipating some complex logic; I'll need to pay close attention to the lock management and how it interacts with the slab allocator to prevent contention. This is where the kernel gets interesting; I'll be looking to quickly pinpoint bottlenecks and potential areas for tuning. I'm ready to get my hands dirty and start digging into the intricacies.
|
| 333/5 |
2026/10/13 23:58 |
tool |
read-file |
0m
Args: map[File:include/linux/slab.h FirstLine:1085 LineCount:40]
Results: map[Contents:1085: * allocated @TYPE objects, or NULL on failure.
1086: */
1087: #define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
1088: ({ \
1089: const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \
1090: (TYPE *)KMALLOC(__obj_size, GFP); \
1091: })
1092:
1093: /**
1094: * __alloc_flex - Allocate an object that has a trailing flexible array
1095: * @KMALLOC: kmalloc wrapper function to use for allocation.
1096: * @GFP: GFP flags for the allocation.
1097: * @TYPE: type of structure to allocate space for.
1098: * @FAM: The name of the flexible array member of @TYPE structure.
1099: * @COUNT: how many @FAM elements to allocate space for.
1100: *
1101: * Returns: Newly allocated pointer to @TYPE with @COUNT-many trailing
1102: * @FAM elements, or NULL on failure or if @COUNT cannot be represented
1103: * by the member of @TYPE that counts the @FAM elements (annotated via
1104: * __counted_by()).
1105: */
1106: #define __alloc_flex(KMALLOC, GFP, TYPE, FAM, COUNT) \
1107: ({ \
1108: const size_t __count = (COUNT); \
1109: const size_t __obj_size = struct_size_t(TYPE, FAM, __count); \
1110: TYPE *__obj_ptr = KMALLOC(__obj_size, GFP); \
1111: if (__obj_ptr) \
1112: __set_flex_counter(__obj_ptr->FAM, __count); \
1113: __obj_ptr; \
1114: })
1115:
1116: /**
1117: * kmalloc_obj - Allocate a single instance of the given type
1118: * @VAR_OR_TYPE: Variable or type to allocate.
1119: * @...: optional GFP flags for the allocation (GFP_KERNEL when not specified).
1120: *
1121: * Returns: newly allocated pointer to a @VAR_OR_TYPE on success, or NULL
1122: * on failure.
1123: */
1124: #define kmalloc_obj(VAR_OR_TYPE, ...) \
]
|
| 334/5 |
2026/10/13 23:58 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 36477
output: 37
thoughts: 168
Thoughts: **Analyzing Memory Allocation in the Kernel**
Okay, let's dive into this `__alloc_objs` macro, specifically lines 1088-1090. I'm seeing this construct:
```c
#define __alloc_objs(KMALLOC, GFP, TYPE, COUNT) \
({ \
const size_t __obj_size = size_mul(sizeof(TYPE), COUNT); \
(TYPE *)KMALLOC(__obj_size, GFP); \
})
```
My immediate concern is the `size_mul` function. How does the kernel's memory allocation handle the potential for huge sizes or, more critically, *overflow* within `size_mul`? My experience tells me this is where vulnerabilities often lurk. I know from my work that `size_mul` will return `SIZE_MAX` on overflow, that's not what's interesting.
So, the next logical step is to understand what happens when `kvmalloc` receives `SIZE_MAX` as a size argument. Let's see what happens if we pass that value to the underlying `kvmalloc_node` call. I need to understand the behaviour.
Let's check the implementation of `kvmalloc_node` in `mm/util.c`. That's where I need to be. I'll need to go there to understand how the system reacts to these values.
|
| 335/5 |
2026/10/13 23:58 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:mm/util.c Name:kvmalloc_node_noprof]
Results: map[SourceCode: SourceFile:]
|
| 336/5 |
2026/10/13 23:58 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 37007
output: 27
thoughts: 11
Thoughts: Okay, here's my summary, framed as my internal thought process, assuming I'm a seasoned kernel developer:
**Locating the `kvmalloc` Implementation**
Alright, time to get to work. First things first, I need to track down the implementation of `kvmalloc`. Given its name, it's pretty clear that it's likely involved in kernel virtual memory allocation, so the logical place to start digging is the `mm/` directory within the kernel source tree. Let's head over there and see what we can find. I suspect it won't be too hard to spot, but it's always good to be methodical about these things, especially in such a vast codebase. Searching for it now.
|
| 337/5 |
2026/10/13 23:59 |
tool |
grepper |
0m
Args: map[Expression:kvmalloc_node PathPrefixes:[mm/]]
Results: map[Output:mm/slub.c=6976=static gfp_t kmalloc_gfp_adjust(gfp_t flags, size_t size)
--
mm/slub.c-6999-
mm/slub.c:7000:void *__kvmalloc_node_noprof(DECL_KMALLOC_PARAMS(size, b, token), unsigned long align,
mm/slub.c-7001- gfp_t flags, int node)
--
mm/slub.c-7046-}
mm/slub.c:7047:EXPORT_SYMBOL(__kvmalloc_node_noprof);
mm/slub.c-7048-
--
mm/slub.c=7102=void *kvrealloc_node_align_noprof(const void *p, DECL_TOKEN_PARAMS(size, token), unsigned long align,
--
mm/slub.c-7112- /* We failed to krealloc(), fall back to kvmalloc(). */
mm/slub.c:7113: n = __kvmalloc_node_noprof(PASS_KMALLOC_PARAMS(size, NULL, token), align, flags, nid);
mm/slub.c-7114- if (!n)
]
|
| 338/5 |
2026/10/13 23:59 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 37522
output: 35
thoughts: 19
Thoughts: Okay, let's dive into this. Here's my take on those lines around 7000 in `mm/slub.c`:
**Deep Dive into `mm/slub.c` Around Line 7000**
Alright, so I'm focusing on around line 7000 in `mm/slub.c`. My initial assumption is that we're dealing with either cache management, object allocation, or possibly deallocation within the SLUB allocator at that point. Given the position in the file, it's likely a relatively low-level function related to the mechanics of the allocator itself, rather than user-facing high-level calls. Iβm expecting to see things like object initialization, bookkeeping on free lists, or maybe even atomic operations related to concurrent access. We could also be looking at functions that handle page allocation or page freeing, since SLUB is built on the slab infrastructure which relies on page-based memory management. It is important to know which exact function we are discussing, as this will help guide the interpretation. I'm keen to see if we're looking at operations on the `slab` struct or the `kmem_cache` structure. More specifically, I wonder if the code is dealing with the creation or destruction of slabs, the addition or removal of objects from a slab, or perhaps interactions with the per-cpu data structures used by SLUB to optimize for locality. My gut feeling is that it's going to be something critical to the overall performance and correctness of SLUB. Let's see whatβs actually there and see if my assumptions hold true.
|
| 339/5 |
2026/10/13 23:59 |
tool |
read-file |
0m
Args: map[File:mm/slub.c FirstLine:7000 LineCount:45]
Results: map[Contents:7000: void *__kvmalloc_node_noprof(DECL_KMALLOC_PARAMS(size, b, token), unsigned long align,
7001: gfp_t flags, int node)
7002: {
7003: bool allow_block;
7004: void *ret;
7005: const struct slab_alloc_context ac = {
7006: .caller_addr = _RET_IP_,
7007: .orig_size = size,
7008: .alloc_flags = SLAB_ALLOC_DEFAULT,
7009: };
7010:
7011: /*
7012: * It doesn't really make sense to fallback to vmalloc for sub page
7013: * requests
7014: */
7015: ret = __do_kmalloc_node(PASS_BUCKET_PARAM(b),
7016: kmalloc_gfp_adjust(flags, size),
7017: node, PASS_TOKEN_PARAM(token), &ac);
7018: if (ret || size <= PAGE_SIZE)
7019: return ret;
7020:
7021: /* Don't even allow crazy sizes */
7022: if (unlikely(size > INT_MAX)) {
7023: WARN_ON_ONCE(!(flags & __GFP_NOWARN));
7024: return NULL;
7025: }
7026:
7027: /*
7028: * For non-blocking the VM_ALLOW_HUGE_VMAP is not used
7029: * because the huge-mapping path in vmalloc contains at
7030: * least one might_sleep() call.
7031: *
7032: * TODO: Revise huge-mapping path to support non-blocking
7033: * flags.
7034: */
7035: allow_block = gfpflags_allow_blocking(flags);
7036:
7037: /*
7038: * kvmalloc() can always use VM_ALLOW_HUGE_VMAP,
7039: * since the callers already cannot assume anything
7040: * about the resulting pointer, and cannot play
7041: * protection games.
7042: */
7043: return __vmalloc_node_range_noprof(size, align, VMALLOC_START, VMALLOC_END,
7044: flags, PAGE_KERNEL, allow_block ? VM_ALLOW_HUGE_VMAP:0,
]
|
| 340/5 |
2026/10/13 23:59 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 38612
output: 34
thoughts: 694
Thoughts: **Analyzing Potential Integer Overflow in DRM Lease Object Allocation**
Okay, so I'm looking at this code and immediately my attention is drawn to line 7022, that `WARN_ON_ONCE` within the `__kvmalloc_node_noprof` function. Right, so if `size` is greater than `INT_MAX`, it will WARN.
Now, I'm thinking about how this relates to `kvzalloc_objs`. If you call `kvzalloc_objs` with a `size > INT_MAX`, you're going to trigger that `WARN_ON_ONCE`. Specifically, the size is calculated as `object_count * sizeof(struct drm_mode_object *)`. So, the critical point is if `object_count` becomes greater than `INT_MAX / sizeof(struct drm_mode_object *)`, the allocation size will exceed `INT_MAX`.
This is where it gets interesting. I see that `fill_object_idr` takes `int object_count`. If `cl->object_count` is larger than INT_MAX, it overflows to a negative integer! That's when I recognize the purpose of this check:
```c
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
return -EINVAL;
}
```
This check is specifically here to prevent the integer overflow _and_ to avoid the potential `WARN_ON_ONCE` in `__kvmalloc_node_noprof`.
But here's where I start to question the assumptions. Is `INT_MAX / sizeof(...)` a reasonable limit for leases? Let's take a step back and consider what DRM leases are *for*. Ah, right, these are used by VR compositors, Wayland compositors, and similar applications to give non-privileged clients access to DRM resources like connectors, CRTCs, and planes. Thinking about typical hardware, GPUs don't have *that* many of these. Four CRTCs, maybe ten planes, a few connectors... so maybe a few dozen DRM mode objects at most.
Now the question is, does DRM enforce this limit anywhere else? Are there other checks? Let's quickly search the code for other examples of `drm_mode_create_lease` or other related functions. Let's see if there are other places where the number of objects is constrained. I need to get a better sense of any existing DRM limits.
|
| 341/5 |
2026/10/13 23:59 |
tool |
grepper |
0m
Args: map[Expression:drm_mode_create_lease PathPrefixes:[drivers/gpu/drm/]]
Results: map[Output:drivers/gpu/drm/drm_ioctl.c=644=static const struct drm_ioctl_desc drm_ioctls[] = {
--
drivers/gpu/drm/drm_ioctl.c-743- DRM_IOCTL_DEF(DRM_IOCTL_CRTC_QUEUE_SEQUENCE, drm_crtc_queue_sequence_ioctl, 0),
drivers/gpu/drm/drm_ioctl.c:744: DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),
drivers/gpu/drm/drm_ioctl.c-745- DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER),
--
drivers/gpu/drm/drm_lease.c=378=static int fill_object_idr(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-474- */
drivers/gpu/drm/drm_lease.c:475:int drm_mode_create_lease_ioctl(struct drm_device *dev,
drivers/gpu/drm/drm_lease.c-476- void *data, struct drm_file *lessor_priv)
drivers/gpu/drm/drm_lease.c-477-{
drivers/gpu/drm/drm_lease.c:478: struct drm_mode_create_lease *cl = data;
drivers/gpu/drm/drm_lease.c-479- size_t object_count;
--
drivers/gpu/drm/drm_lease.c-572- drm_master_put(&lessor);
drivers/gpu/drm/drm_lease.c:573: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl succeeded\n");
drivers/gpu/drm/drm_lease.c-574- return 0;
--
drivers/gpu/drm/drm_lease.c-583- drm_master_put(&lessor);
drivers/gpu/drm/drm_lease.c:584: drm_dbg_lease(dev, "drm_mode_create_lease_ioctl failed: %d\n", ret);
drivers/gpu/drm/drm_lease.c-585- return ret;
]
|
| 342/5 |
2026/10/13 23:59 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 40489
output: 44
thoughts: 301
Thoughts: **Analyzing DRM GEM Object Lookup**
Okay, let's dive into this `drm_gem_objects_lookup` function and see how it handles user-provided arrays. First, I need to check how it deals with potential security vulnerabilities when taking user data. My initial thought is to examine how it handles the array passed in and how it allocates memory for that array.
Alright, I see it clearly: `drm_gem_objects_lookup` uses `kvmalloc_objs` to allocate memory for an array of `drm_gem_object` pointers, specifically `objs`. Then, it uses `vmemdup_array_user` to safely copy the user-provided handle array (`bo_handles`) into a kernel-allocated buffer named `handles`. Perfect, `vmemdup_array_user` is the key for verifying the user's data! Then, both memory allocations, the object array `objs`, and the user handle array `handles` are freed via `kvfree()`. This looks like a reasonable implementation to me. Next, I should probably check the commit history and maybe the associated documentation to understand the rationale behind this approach and see if it has been audited or reviewed recently.
|
| 343/5 |
2026/10/13 23:59 |
tool |
git-log |
0m
Error:
Args: map[Count:5 PathPrefix:drivers/gpu/drm/drm_gem.c SymbolName:drm_gem_objects_lookup]
Results:
|
| 344/5 |
2026/10/13 23:59 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 41106
output: 44
thoughts: 10
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing Git Log Output with a Specific Source Path**
Alright, time to get down to brass tacks. I'm thinking, let's fire up `git log` now, but with a crucial detail β we need to specify a particular `SourcePath`. This isn't just a generic `git log` call; we're targeting a specific area of the repository for analysis. It's about efficiently sifting through the commit history to extract the information most relevant to our current task. We know full well the potential breadth of git log, and while we can configure it to be very specific, or very generic, using `SourcePath` as a filter here allows us to streamline that process. We are very aware that running a generic git log, especially on large repositories with extensive history, can be computationally expensive and time-consuming. We don't have time for that! We are thinking, we are smart, and we know this approach will give us the desired insights with surgical precision. Let's see what the log reveals once we've narrowed the scope.
|
| 345/5 |
2026/10/13 23:59 |
tool |
git-log |
0m
Args: map[Count:5 SourcePath:drivers/gpu/drm/drm_gem.c SymbolName:drm_gem_objects_lookup]
Results: map[Output:8b85987d3cf5 Merge drm/drm-next into drm-misc-next
dbce431756f8 drm/gem: Make drm_gem_objects_lookup() self-cleaning on failure v6
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
922682d48d62 drm/gem: Correct error condition in drm_gem_objects_lookup
cb77b79abf5f drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
]
|
| 346/5 |
2026/10/13 23:59 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 41565
output: 25
thoughts: 23
Thoughts: Okay, here's my interpretation of that prompt, and my response:
**Initial Assessment of Commit cb77b79abf5f**
Alright, let's dive into this commit, `cb77b79abf5f`. Immediately, my mental process jumps to "inspection mode." This commit's identifier is the key, and Iβm already formulating the ideal approach. Given the nature of my field, I'll likely begin by considering the repository context, the timing, and any prior knowledge I have of this particular codebase or project. From there, the exploration will follow the classic principles. Is this a functional change or a structural refactor? What files are touched, and what's the delta? I'll probably start with a `git show` to get a quick overview, then consider diffs to the code's changes in order to form an understanding. From there I'll dive into the specifics of the changed files to perform an informed critique. I'll be looking for potential side effects, edge cases, and areas that might warrant further investigation.
|
| 347/5 |
2026/10/14 00:00 |
tool |
git-show |
0m
Args:
Results: map[Output:commit cb77b79abf5ff8f4af07f7ebef196a003c826b7a
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Wed Nov 12 09:27:32 2025 +0000
drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
Use a helper to shrink the code and separate the user and kernel slabs for
better security.
While at it lets remove the useless debug message.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: AndrΓ© Almeida <andrealmeid@igalia.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://lore.kernel.org/r/20251112092732.23584-1-tvrtko.ursulin@igalia.com
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index a1a9c828938b..68168d58a7c8 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)
{
- struct drm_device *dev = filp->minor->dev;
struct drm_gem_object **objs;
u32 *handles;
int ret;
@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
*objs_out = objs;
- handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL);
- if (!handles) {
- ret = -ENOMEM;
- goto out;
- }
-
- if (copy_from_user(handles, bo_handles, count * sizeof(u32))) {
- ret = -EFAULT;
- drm_dbg_core(dev, "Failed to copy in GEM handles\n");
+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
+ if (IS_ERR(handles)) {
+ ret = PTR_ERR(handles);
goto out;
}
]
|
| 348/5 |
2026/10/14 00:00 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 42558
output: 25
thoughts: 108
Thoughts: Okay, let's break this down.
**Analyzing `drm_gem_objects_lookup` and Its Related Commit**
Alright, I see a section in `drm_gem_objects_lookup`. The core of the issue, from my perspective, revolves around memory allocation and error handling within this function. I'm focusing on these lines: `objs = kvmalloc_objs(*objs, count);` and `handles = vmemdup_array_user(bo_handles, count, sizeof(u32));`. Specifically, `kvmalloc_objs` and `vmemdup_array_user` are allocating memory for the objects and the handles respectively. My immediate thought is, are these allocations robust? Are we accounting for all possible failure scenarios? That leads me to the commit message: `dbce431756f8 drm/gem: Make drm_gem_objects_lookup() self-cleaning on failure v6`. It immediately flags something important. This commit is likely addressing how the function handles those failure cases, particularly related to the allocated memory I was just looking at. It's almost certain it includes important error-checking logic. Given the context of the function and the keywords in the commit message, the implementation is likely aiming to prevent memory leaks and ensure the system remains stable even when the object lookup fails for any reason. I'll need to dig into the details of commit `dbce431756f8` to understand the specific self-cleaning mechanisms. I'll be looking for `kfree` calls and the like!
|
| 349/5 |
2026/10/14 00:00 |
tool |
git-show |
0m
Args:
Results: map[Output:commit dbce431756f85ec76a189312afdae2dee14fb0de
Author: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Date: Fri Feb 6 18:51:41 2026 +0530
drm/gem: Make drm_gem_objects_lookup() self-cleaning on failure v6
drm_gem_objects_lookup() can allocate the output array and take
references on GEM objects before it fails.
If an error happens part-way through, callers previously had to clean up
partially created results themselves. This relied on subtle and
undocumented behavior and was easy to get wrong.
Make drm_gem_objects_lookup() clean up on failure. The function now
drops any references it already took, frees the array, and sets
*objs_out to NULL before returning an error.
On success, behavior is unchanged. Existing callers remain correct and
their error cleanup paths simply do nothing when *objs_out is NULL.
v2/v3: Move partial-lookup cleanup into objects_lookup(), perform
reference dropping outside the lock, and remove reliance on __GFP_ZERO
or implicit NULL handling. (Christian)
v4: Use goto-style error handling in objects_lookup(), drop partial
references outside the lock, and simplify drm_gem_objects_lookup()
cleanup by routing failures through err_free_handles as suggested.
(Christian)
v5: Rebase on drm-misc-next, drop the ret local variable. (Christian)
v6: Drop superfluous initialization of handles. (Christian/Tvrtko)
Cc: Alex Deucher <alexander.deucher@amd.com>
Suggested-by: Christian KΓΆnig <christian.koenig@amd.com>
Suggested-by: Tvrtko Ursulin <tursulin@ursulin.net>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Christian KΓΆnig <christian.koenig@amd.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patch.msgid.link/20260206132141.1474191-1-srinivasan.shanmugam@amd.com
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 7ff6b7bbeb73..c4a3de3b920e 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -783,7 +783,7 @@ EXPORT_SYMBOL(drm_gem_put_pages);
static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
struct drm_gem_object **objs)
{
- int i, ret = 0;
+ int i;
struct drm_gem_object *obj;
spin_lock(&filp->table_lock);
@@ -791,16 +791,23 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
for (i = 0; i < count; i++) {
/* Check if we currently have a reference on the object */
obj = idr_find(&filp->object_idr, handle[i]);
- if (!obj) {
- ret = -ENOENT;
- break;
- }
+ if (!obj)
+ goto err;
+
drm_gem_object_get(obj);
objs[i] = obj;
}
+
spin_unlock(&filp->table_lock);
+ return 0;
- return ret;
+err:
+ spin_unlock(&filp->table_lock);
+
+ while (i--)
+ drm_gem_object_put(objs[i]);
+
+ return -ENOENT;
}
/**
@@ -828,24 +835,34 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
u32 *handles;
int ret;
+ *objs_out = NULL;
+
if (!count)
return 0;
- objs = kvmalloc_array(count, sizeof(struct drm_gem_object *),
- GFP_KERNEL | __GFP_ZERO);
+ objs = kvmalloc_array(count, sizeof(*objs), GFP_KERNEL);
if (!objs)
return -ENOMEM;
- *objs_out = objs;
-
handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
- if (IS_ERR(handles))
- return PTR_ERR(handles);
+ if (IS_ERR(handles)) {
+ ret = PTR_ERR(handles);
+ goto err_free_objs;
+ }
ret = objects_lookup(filp, handles, count, objs);
+ if (ret)
+ goto err_free_handles;
+
kvfree(handles);
- return ret;
+ *objs_out = objs;
+ return 0;
+err_free_handles:
+ kvfree(handles);
+err_free_objs:
+ kvfree(objs);
+ return ret;
}
EXPORT_SYMBOL(drm_gem_objects_lookup);
]
|
| 350/5 |
2026/10/14 00:00 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 44485
output: 34
thoughts: 2026
Thoughts: **Analyzing Memory Allocation and Overflow in drm_mode_create_lease_ioctl**
Okay, so I'm looking at this code and immediately I see some interesting patterns. In `drm_gem_objects_lookup`, `vmemdup_array_user` is paired with `kvfree`, and `objs` uses `kvmalloc_objs` with `kvfree`, which is a good sign. However, I'm trying to understand why commit `f37d63e219c3` originally used `memdup_array_user` instead of `vmemdup_array_user` in `drm_lease.c`, when the intention was to safely duplicate a user-space array. The commit message indicates that `memdup_array_user` provides overflow safety, and it was used with `kfree(object_ids)` at the time.
Now, let's dive deeper into `drm_mode_create_lease_ioctl`. I notice in `drm_lease.c`, a block of code related to leased objects uses `memdup_array_user` to copy `object_ids`. Then, the patch changes `memdup_array_user` to `vmemdup_array_user` and `kfree` to `kvfree`.
But hold on! The patch also adds this check: `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))`. I need to figure out if this is correct. I am going to carefully evaluate what the patch is doing and check every detail against our guidelines! Is this check correct, or is it arbitrary? I need to analyze why we're dividing `INT_MAX` by `sizeof(struct drm_mode_object *)`.
Let's look at the type of `object_count`. It's a `size_t` in the `drm_mode_create_lease_ioctl` function, but it is passed as an `int` to `fill_object_idr`. That is potentially problematic. Inside `fill_object_idr`, `objects = kvzalloc_objs(struct drm_mode_object *, object_count);` is called, and `kvzalloc_objs` is using `object_count` to determine the number of objects to allocate. It takes the argument `COUNT` which can cause an integer overflow! Further inside `fill_object_idr` there is a loop that iterates up to `object_count`.
If `cl->object_count` (which is `u32`) is greater than `INT_MAX`, the `object_count` passed to `fill_object_idr` becomes negative due to integer truncation!
This is where the check comes in: `cl->object_count * sizeof(struct drm_mode_object *) > INT_MAX`. This is an overflow check! The code is preventing the multiplication of the number of objects by the size of each object from exceeding `INT_MAX`. Because if `cl->object_count * sizeof(struct drm_mode_object *)` is larger than `INT_MAX`, `kvmalloc` will warn via `WARN_ON_ONCE`!
Now, the question is, does `vmemdup_array_user` emit a warning in case of overflow? I need to look at `vmemdup_array_user`. It calls `vmemdup_user` which calls `check_mul_overflow`, and if overflow happens, returns `ERR_PTR(-EOVERFLOW)`.
So, the new code is a bit more robust; `vmemdup_array_user` and `kvfree` are the correct tools for the job, and the added `INT_MAX` check is critical for preventing integer overflow during memory allocation.
|
| 351/5 |
2026/10/14 00:00 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:mm/util.c Name:vmemdup_user]
Results: map[SourceCode: 234: /**
235: * vmemdup_user - duplicate memory region from user space
236: *
237: * @src: source address in user space
238: * @len: number of bytes to copy
239: *
240: * Return: an ERR_PTR() on failure. Result may be not
241: * physically contiguous. Use kvfree() to free.
242: */
243: void *vmemdup_user(const void __user *src, size_t len)
244: {
245: void *p;
246:
247: p = kmem_buckets_valloc(user_buckets, len, GFP_USER);
248: if (!p)
249: return ERR_PTR(-ENOMEM);
250:
251: if (copy_from_user(p, src, len)) {
252: kvfree(p);
253: return ERR_PTR(-EFAULT);
254: }
255:
256: return p;
257: }
SourceFile:mm/util.c]
|
| 352/5 |
2026/10/14 00:00 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 47700
output: 36
thoughts: 14
Thoughts: Okay, let's dive into this. Here's how I'd approach summarizing the prompt, given my assumed expertise:
**Checking `kmem_buckets_valloc`**
Right, so the prompt is directing me to focus on `kmem_buckets_valloc`. My initial thought is, "Ah, `kmem_buckets_valloc`, that's a key function within the kernel's memory management." I'm immediately running through its purpose in my head β it's likely responsible for allocating virtual memory from the `kmem_buckets` subsystem, usually for kernel-internal structures and buffers. I know the `buckets` part indicates it's likely using a slab allocator or something similar, optimizing allocation and deallocation of smaller, frequently used memory regions. I'm wondering if this is a recent performance issue.
What's the context? What are we trying to understand about `kmem_buckets_valloc`? Is this about debugging a memory leak? Or perhaps performance tuning? Are we trying to understand how it interacts with other kernel subsystems? I need more information to fully assess the significance of this focus. I'm assuming that it is to understand the performance and functionality of this function.
I'd want to check the following things immediately: its usage, how memory is actually allocated, if there are any locks being utilized, if there are any potential race conditions, and how much fragmentation it creates. I'm also thinking about what kernel version this relates to, as implementations can vary significantly. I need to understand the specifics of how this function operates in this particular kernel version. I'm already formulating questions in my mind: What are the typical call sites? How does it interact with the underlying virtual memory management? What's the impact on overall system performance when it's heavily utilized?
|
| 353/5 |
2026/10/14 00:00 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:mm/util.c Name:kmem_buckets_valloc]
Results: map[SourceCode: SourceFile:]
|
| 354/5 |
2026/10/14 00:00 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 48152
output: 21
thoughts: 13
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Hunting Down `kmem_buckets_valloc`**
Right, let's get down to it. My initial thought is to zero in on finding the function `kmem_buckets_valloc`. Why? Well, depending on the context, and without more info, it could be the key to understanding a specific memory allocation scheme within the kernel. Itβs got that βbucketsβ in the name, which immediately suggests some kind of categorized allocation, perhaps slab or slub-based. Knowing its location is critical for any deeper dive. Is it in the core kernel, a module, or something more obscure? I'll probably need to start by tracing calls, using tools like `kprobe` or even looking at the symbol table. Knowing the location will inform the best next steps, whether that's static analysis, dynamic tracing, or simply examining the source. Time to get digging!
|
| 355/5 |
2026/10/14 00:00 |
tool |
grepper |
0m
Args: map[Expression:kmem_buckets_valloc]
Results: map[Output:include/linux/slab.h=1352=void *kvmalloc_node(size_t size, gfp_t flags, int node);
--
include/linux/slab.h-1362-
include/linux/slab.h:1363:#define kmem_buckets_valloc(_b, _size, _flags) \
include/linux/slab.h-1364- alloc_hooks(__kvmalloc_node_noprof(PASS_KMALLOC_PARAMS(_size, _b, __kmalloc_token(_size)), 1, _flags, NUMA_NO_NODE))
--
mm/util.c=243=void *vmemdup_user(const void __user *src, size_t len)
--
mm/util.c-246-
mm/util.c:247: p = kmem_buckets_valloc(user_buckets, len, GFP_USER);
mm/util.c-248- if (!p)
]
|
| 356/5 |
2026/10/14 00:00 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 48641
output: 32
thoughts: 565
Thoughts: Here's my analysis of this code, as I understand it:
**Digging into Potential Integer Overflow Vulnerabilities**
Okay, so I'm looking at this code and immediately I see `kmem_buckets_valloc` calling `__kvmalloc_node_noprof` with `GFP_USER`. The important thing here is that `GFP_USER` *doesn't* include `__GFP_NOWARN`. This immediately raises a red flag. If the requested length (`len`) in `vmemdup_user` is larger than `INT_MAX`, then `__kvmalloc_node_noprof` gets called with a `size > INT_MAX`. That's where the problem shows itself: the kernel will `WARN_ON_ONCE` because it should never see sizes that are that large. Exactly the same issue exists in `kvzalloc_objs`! It also uses `GFP_KERNEL` without `__GFP_NOWARN`, so a size greater than `INT_MAX` would also trigger a `WARN_ON_ONCE`.
However, the check `cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)` seems to address this issue. Looking at this, it ensures a few things:
1. `cl->object_count * sizeof(struct drm_mode_object *)` will never exceed `INT_MAX`.
2. `cl->object_count * sizeof(__u32)` also doesn't.
3. `cl->object_count` itself doesn't exceed `INT_MAX`, ensuring there are no integer overflows when passed to `fill_object_idr`.
Now I'm questioning myself. Is this check truly safe? I'm missing something, so I look at the include statements that were added to understand the context.
I see that the includes are there because `<linux/limits.h>` defines `INT_MAX`, `<linux/slab.h>` contains `kvzalloc_objs` and `kvfree`, and `<linux/string.h>` is needed for `vmemdup_array_user`. Okay, that makes sense now!
But wait, I need to ask a bigger question: Does a DRM lease *ever* actually need `vmemdup_array_user` or `kvzalloc_objs`? Are these functions even appropriate for what DRM is doing? This feels a bit suspicious. I need to understand the scale of potential DRM objects. How many objects can a DRM device *possibly* have? Can we have millions of these? My instinct is no. I need to investigate the DRM code itself. I'm going to search through it, starting with how DRM objects are created and how their IDs are assigned, in order to get a better sense of the limits here. This smells like potential for a misunderstanding of scale.
|
| 357/5 |
2026/10/14 00:00 |
tool |
grepper |
0m
Args: map[Expression:drm_mode_object PathPrefixes:[drivers/gpu/drm/]]
Results: map[Output:
Full output is too long, showing 200 out of 615 lines.
Use more precise expression or PathPrefixes if possible.
Number of matching lines per file (23 files in total):
drivers/gpu/drm/Makefile:1
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c:1
drivers/gpu/drm/armada/armada_overlay.c:1
drivers/gpu/drm/display/drm_hdcp_helper.c:1
drivers/gpu/drm/drm_atomic_uapi.c:12
drivers/gpu/drm/drm_bridge.c:1
drivers/gpu/drm/drm_colorop.c:1
drivers/gpu/drm/drm_connector.c:8
drivers/gpu/drm/drm_crtc.c:5
drivers/gpu/drm/drm_crtc_internal.h:17
drivers/gpu/drm/drm_drv.c:1
drivers/gpu/drm/drm_encoder.c:3
drivers/gpu/drm/drm_framebuffer.c:6
drivers/gpu/drm/drm_lease.c:7
drivers/gpu/drm/drm_mode_object.c:51
drivers/gpu/drm/drm_plane.c:6
drivers/gpu/drm/drm_property.c:14
drivers/gpu/drm/msm/disp/mdp4/mdp4_plane.c:1
drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c:1
drivers/gpu/drm/omapdrm/omap_overlay.h:1
drivers/gpu/drm/omapdrm/omap_plane.c:1
drivers/gpu/drm/omapdrm/omap_plane.h:2
drivers/gpu/drm/tests/drm_framebuffer_test.c:3
drivers/gpu/drm/Makefile=35=drm-y := \
--
drivers/gpu/drm/Makefile-60- drm_mode_config.o \
drivers/gpu/drm/Makefile:61: drm_mode_object.o \
drivers/gpu/drm/Makefile-62- drm_modes.o \
--
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c-16-#include <drm/drm_managed.h>
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c:17:#include <drm/drm_mode_object.h>
drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c-18-#include <drm/drm_modes.h>
--
drivers/gpu/drm/armada/armada_overlay.c=542=int armada_overlay_plane_create(struct drm_device *dev, unsigned long crtcs)
--
drivers/gpu/drm/armada/armada_overlay.c-544- struct armada_private *priv = drm_to_armada_dev(dev);
drivers/gpu/drm/armada/armada_overlay.c:545: struct drm_mode_object *mobj;
drivers/gpu/drm/armada/armada_overlay.c-546- struct drm_plane *overlay;
--
drivers/gpu/drm/display/drm_hdcp_helper.c-20-#include <drm/drm_property.h>
drivers/gpu/drm/display/drm_hdcp_helper.c:21:#include <drm/drm_mode_object.h>
drivers/gpu/drm/display/drm_hdcp_helper.c-22-#include <drm/drm_connector.h>
--
drivers/gpu/drm/drm_atomic_uapi.c=980=drm_atomic_connector_get_property(struct drm_connector *connector,
--
drivers/gpu/drm/drm_atomic_uapi.c-1065-
drivers/gpu/drm/drm_atomic_uapi.c:1066:int drm_atomic_get_property(struct drm_mode_object *obj,
drivers/gpu/drm/drm_atomic_uapi.c-1067- struct drm_property *property, uint64_t *val)
--
drivers/gpu/drm/drm_atomic_uapi.c=1203=int drm_atomic_set_property(struct drm_atomic_commit *state,
drivers/gpu/drm/drm_atomic_uapi.c-1204- struct drm_file *file_priv,
drivers/gpu/drm/drm_atomic_uapi.c:1205: struct drm_mode_object *obj,
drivers/gpu/drm/drm_atomic_uapi.c-1206- struct drm_property *prop,
--
drivers/gpu/drm/drm_atomic_uapi.c-1209-{
drivers/gpu/drm/drm_atomic_uapi.c:1210: struct drm_mode_object *ref;
drivers/gpu/drm/drm_atomic_uapi.c-1211- u64 old_val;
--
drivers/gpu/drm/drm_atomic_uapi.c=1611=int drm_mode_atomic_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_atomic_uapi.c-1685- uint32_t obj_id, count_props;
drivers/gpu/drm/drm_atomic_uapi.c:1686: struct drm_mode_object *obj;
drivers/gpu/drm/drm_atomic_uapi.c-1687-
--
drivers/gpu/drm/drm_atomic_uapi.c-1692-
drivers/gpu/drm/drm_atomic_uapi.c:1693: obj = drm_mode_object_find(dev, file_priv, obj_id, DRM_MODE_OBJECT_ANY);
drivers/gpu/drm/drm_atomic_uapi.c-1694- if (!obj) {
--
drivers/gpu/drm/drm_atomic_uapi.c-1701- drm_dbg_atomic(dev, "[OBJECT:%d] has no properties", obj_id);
drivers/gpu/drm/drm_atomic_uapi.c:1702: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1703- ret = -ENOENT;
--
drivers/gpu/drm/drm_atomic_uapi.c-1707- if (get_user(count_props, count_props_ptr + copied_objs)) {
drivers/gpu/drm/drm_atomic_uapi.c:1708: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1709- ret = -EFAULT;
--
drivers/gpu/drm/drm_atomic_uapi.c-1720- if (get_user(prop_id, props_ptr + copied_props)) {
drivers/gpu/drm/drm_atomic_uapi.c:1721: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1722- ret = -EFAULT;
--
drivers/gpu/drm/drm_atomic_uapi.c-1730- obj_id, prop_id);
drivers/gpu/drm/drm_atomic_uapi.c:1731: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1732- ret = -ENOENT;
--
drivers/gpu/drm/drm_atomic_uapi.c-1738- sizeof(prop_value))) {
drivers/gpu/drm/drm_atomic_uapi.c:1739: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1740- ret = -EFAULT;
--
drivers/gpu/drm/drm_atomic_uapi.c-1746- if (ret) {
drivers/gpu/drm/drm_atomic_uapi.c:1747: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1748- goto out;
--
drivers/gpu/drm/drm_atomic_uapi.c-1753-
drivers/gpu/drm/drm_atomic_uapi.c:1754: drm_mode_object_put(obj);
drivers/gpu/drm/drm_atomic_uapi.c-1755- }
--
drivers/gpu/drm/drm_bridge.c-59- *
drivers/gpu/drm/drm_bridge.c:60: * &drm_bridge, like &drm_panel, aren't &drm_mode_object entities like planes,
drivers/gpu/drm/drm_bridge.c-61- * CRTCs, encoders or connectors and hence are not visible to userspace. They
--
drivers/gpu/drm/drm_colorop.c=95=static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *colorop,
--
drivers/gpu/drm/drm_colorop.c-103-
drivers/gpu/drm/drm_colorop.c:104: ret = drm_mode_object_add(dev, &colorop->base, DRM_MODE_OBJECT_COLOROP);
drivers/gpu/drm/drm_colorop.c-105- if (ret)
--
drivers/gpu/drm/drm_connector.c=194=static void drm_connector_free(struct kref *kref)
--
drivers/gpu/drm/drm_connector.c-199-
drivers/gpu/drm/drm_connector.c:200: drm_mode_object_unregister(dev, &connector->base);
drivers/gpu/drm/drm_connector.c-201- connector->funcs->destroy(connector);
--
drivers/gpu/drm/drm_connector.c=204=void drm_connector_free_work_fn(struct work_struct *work)
--
drivers/gpu/drm/drm_connector.c-217- llist_for_each_entry_safe(connector, n, freed, free_node) {
drivers/gpu/drm/drm_connector.c:218: drm_mode_object_unregister(dev, &connector->base);
drivers/gpu/drm/drm_connector.c-219- connector->funcs->destroy(connector);
--
drivers/gpu/drm/drm_connector.c=223=static int drm_connector_init_only(struct drm_device *dev,
--
drivers/gpu/drm/drm_connector.c-237-
drivers/gpu/drm/drm_connector.c:238: ret = __drm_mode_object_add(dev, &connector->base,
drivers/gpu/drm/drm_connector.c-239- DRM_MODE_OBJECT_CONNECTOR,
--
drivers/gpu/drm/drm_connector.c-327- if (ret)
drivers/gpu/drm/drm_connector.c:328: drm_mode_object_unregister(dev, &connector->base);
drivers/gpu/drm/drm_connector.c-329-
--
drivers/gpu/drm/drm_connector.c=771=void drm_connector_cleanup(struct drm_connector *connector)
--
drivers/gpu/drm/drm_connector.c-807- kfree(connector->display_info.vics);
drivers/gpu/drm/drm_connector.c:808: drm_mode_object_unregister(dev, &connector->base);
drivers/gpu/drm/drm_connector.c-809- kfree(connector->name);
--
drivers/gpu/drm/drm_connector.c=850=int drm_connector_register(struct drm_connector *connector)
--
drivers/gpu/drm/drm_connector.c-876-
drivers/gpu/drm/drm_connector.c:877: drm_mode_object_register(connector->dev, &connector->base);
drivers/gpu/drm/drm_connector.c-878-
--
drivers/gpu/drm/drm_connector.c=3417=EXPORT_SYMBOL(drm_connector_update_privacy_screen);
drivers/gpu/drm/drm_connector.c-3418-
drivers/gpu/drm/drm_connector.c:3419:int drm_connector_set_obj_prop(struct drm_mode_object *obj,
drivers/gpu/drm/drm_connector.c-3420- struct drm_property *property,
--
drivers/gpu/drm/drm_connector.c=3496=int drm_mode_getconnector(struct drm_device *dev, void *data,
--
drivers/gpu/drm/drm_connector.c-3626- */
drivers/gpu/drm/drm_connector.c:3627: ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
drivers/gpu/drm/drm_connector.c-3628- file_priv->plane_color_pipeline,
--
drivers/gpu/drm/drm_crtc.c=254=static int __drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc,
--
drivers/gpu/drm/drm_crtc.c-280- drm_modeset_lock_init(&crtc->mutex);
drivers/gpu/drm/drm_crtc.c:281: ret = drm_mode_object_add(dev, &crtc->base, DRM_MODE_OBJECT_CRTC);
drivers/gpu/drm/drm_crtc.c-282- if (ret)
--
drivers/gpu/drm/drm_crtc.c-290- if (!crtc->name) {
drivers/gpu/drm/drm_crtc.c:291: drm_mode_object_unregister(dev, &crtc->base);
drivers/gpu/drm/drm_crtc.c-292- return -ENOMEM;
--
drivers/gpu/drm/drm_crtc.c-313- if (ret) {
drivers/gpu/drm/drm_crtc.c:314: drm_mode_object_unregister(dev, &crtc->base);
drivers/gpu/drm/drm_crtc.c-315- return ret;
--
drivers/gpu/drm/drm_crtc.c=500=void drm_crtc_cleanup(struct drm_crtc *crtc)
--
drivers/gpu/drm/drm_crtc.c-515-
drivers/gpu/drm/drm_crtc.c:516: drm_mode_object_unregister(dev, &crtc->base);
drivers/gpu/drm/drm_crtc.c-517- list_del(&crtc->head);
--
drivers/gpu/drm/drm_crtc.c=709=int drm_mode_setcrtc(struct drm_device *dev, void *data,
--
drivers/gpu/drm/drm_crtc.c-912-
drivers/gpu/drm/drm_crtc.c:913:int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
drivers/gpu/drm/drm_crtc.c-914- struct drm_property *property,
--
drivers/gpu/drm/drm_crtc_internal.h=58=struct drm_mode_fb_cmd;
drivers/gpu/drm/drm_crtc_internal.h:59:struct drm_mode_object;
drivers/gpu/drm/drm_crtc_internal.h-60-struct drm_mode_set;
--
drivers/gpu/drm/drm_crtc_internal.h=69=struct work_struct;
--
drivers/gpu/drm/drm_crtc_internal.h-71-/* drm_crtc.c */
drivers/gpu/drm/drm_crtc_internal.h:72:int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj,
drivers/gpu/drm/drm_crtc_internal.h-73- struct drm_property *property,
--
drivers/gpu/drm/drm_crtc_internal.h=136=bool drm_property_change_valid_get(struct drm_property *property,
drivers/gpu/drm/drm_crtc_internal.h-137- uint64_t value,
drivers/gpu/drm/drm_crtc_internal.h:138: struct drm_mode_object **ref);
drivers/gpu/drm/drm_crtc_internal.h-139-void drm_property_change_valid_put(struct drm_property *property,
drivers/gpu/drm/drm_crtc_internal.h:140: struct drm_mode_object *ref);
drivers/gpu/drm/drm_crtc_internal.h-141-
--
drivers/gpu/drm/drm_crtc_internal.h=149=int drm_mode_destroyblob_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_crtc_internal.h-151-
drivers/gpu/drm/drm_crtc_internal.h:152:/* drm_mode_object.c */
drivers/gpu/drm/drm_crtc_internal.h:153:int __drm_mode_object_add(struct drm_device *dev, struct drm_mode_object *obj,
drivers/gpu/drm/drm_crtc_internal.h-154- uint32_t obj_type, bool register_obj,
drivers/gpu/drm/drm_crtc_internal.h-155- void (*obj_free_cb)(struct kref *kref));
drivers/gpu/drm/drm_crtc_internal.h:156:int drm_mode_object_add(struct drm_device *dev, struct drm_mode_object *obj,
drivers/gpu/drm/drm_crtc_internal.h-157- uint32_t obj_type);
drivers/gpu/drm/drm_crtc_internal.h:158:void drm_mode_object_register(struct drm_device *dev,
drivers/gpu/drm/drm_crtc_internal.h:159: struct drm_mode_object *obj);
drivers/gpu/drm/drm_crtc_internal.h:160:struct drm_mode_object *__drm_mode_object_find(struct drm_device *dev,
drivers/gpu/drm/drm_crtc_internal.h-161- struct drm_file *file_priv,
drivers/gpu/drm/drm_crtc_internal.h-162- uint32_t id, uint32_t type);
drivers/gpu/drm/drm_crtc_internal.h:163:void drm_mode_object_unregister(struct drm_device *dev,
drivers/gpu/drm/drm_crtc_internal.h:164: struct drm_mode_object *object);
drivers/gpu/drm/drm_crtc_internal.h:165:int drm_mode_object_get_properties(struct drm_mode_object *obj, bool atomic,
drivers/gpu/drm/drm_crtc_internal.h-166- bool plane_color_pipeline,
--
drivers/gpu/drm/drm_crtc_internal.h-169- uint32_t *arg_count_props);
drivers/gpu/drm/drm_crtc_internal.h:170:struct drm_property *drm_mode_obj_find_prop_id(struct drm_mode_object *obj,
drivers/gpu/drm/drm_crtc_internal.h-171- uint32_t prop_id);
--
drivers/gpu/drm/drm_crtc_internal.h=192=int drm_connector_register_all(struct drm_device *dev);
drivers/gpu/drm/drm_crtc_internal.h:193:int drm_connector_set_obj_prop(struct drm_mode_object *obj,
drivers/gpu/drm/drm_crtc_internal.h-194- struct drm_property *property,
--
drivers/gpu/drm/drm_crtc_internal.h=260=int drm_atomic_set_property(struct drm_atomic_commit *state,
drivers/gpu/drm/drm_crtc_internal.h-261- struct drm_file *file_priv,
]
|
| 358/5 |
2026/10/14 00:00 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 55019
output: 44
thoughts: 15
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing the Lease Requirement**
Alright, let's dive into this `drm_mode_object_lease_required` situation. My initial thought is to examine exactly what this variable signifies and where it's utilized within the DRM (Direct Rendering Manager) framework. I need to quickly recall its implications regarding resource management and access control within the graphics stack. Does it impact lease acquisition strategies for modeset objects? Is it related to the negotiation and enforcement of leases between different processes or drivers? I'm immediately running through the potential implications for synchronization, particularly around the handover of resources during modesetting operations. Ultimately, I'm thinking about the implications for stability, security, and the overall performance of the rendering pipeline. I need to understand its role in the context of the larger DRM architecture.
|
| 359/5 |
2026/10/14 00:01 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_mode_object_lease_required]
Results: map[SourceCode: 119: /**
120: * drm_mode_object_lease_required - check types which must be leased to be used
121: * @type: type of object
122: *
123: * Returns whether the provided type of drm_mode_object must
124: * be owned or leased to be used by a process.
125: */
126: bool drm_mode_object_lease_required(uint32_t type)
127: {
128: switch(type) {
129: case DRM_MODE_OBJECT_CRTC:
130: case DRM_MODE_OBJECT_CONNECTOR:
131: case DRM_MODE_OBJECT_PLANE:
132: return true;
133: default:
134: return false;
135: }
136: }
SourceFile:drivers/gpu/drm/drm_mode_object.c]
|
| 360/5 |
2026/10/14 00:01 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 55546
output: 23
thoughts: 1313
Thoughts: **Analyzing the `drm_mode_create_lease_ioctl` Vulnerability**
Okay, so I'm looking at this code and immediately I see a potential issue. The `drm_mode_create_lease_ioctl` function is only supposed to deal with a limited number of CRTCs, Connectors, and Planesβa few dozen at most, realistically. But the `drm_mode_create_lease_ioctl` takes an array of object IDs, `object_ids`, from user space via `cl->object_count`, and the user can essentially pass *any* value for `object_count`. This is the first red flag.
The reproducer and crash report highlight exactly this. A user sent a count of 1,000,000. That means the code tries to allocate a 4MB array for the IDs (`memdup_array_user`). Then, within `fill_object_idr`, it attempts to allocate another array, `objects`, of a structure for each ID, resulting in an 8MB allocation using `kzalloc_objs`. This second `kmalloc` with `GFP_KERNEL` fails because it's an order larger than `MAX_PAGE_ORDER`. Boom, a warning from the page allocator!
Now, the patch diff is interesting. It replaces `kzalloc_objs` with `kvzalloc_objs` and `kfree` with `kvfree`. That's a good step toward fixing the immediate allocation issue (using vmalloc, which can handle larger orders). Also, the patch adds a check: if `cl->object_count` is larger than `INT_MAX / sizeof(struct drm_mode_object *)`, it returns an error. That's a basic sanity check, but I'm thinking... does it go far enough?
But wait! Replacing `memdup_array_user` with `vmemdup_array_user` is crucial. Why? If you had 2,000,000 objects, the memory would jump to 8MB in the object_ids array, which can still be problematic and lead to `kmalloc` failures. `vmemdup_array_user` seems to be used to allocate user arrays, so this is a crucial point of concern.
The real question is... can a user space application really allocate *unlimited* memory through `vmemdup_array_user` or `kvzalloc_objs`?
I just calculated it: `INT_MAX / sizeof(struct drm_mode_object *)` is roughly 268 million. So, if user space sets the count to 200,000,000: `vmemdup_array_user` attempts to allocate 800 MB (200M * 4 bytes) and `kvzalloc_objs` would then go for 1.6GB (200M * 8 bytes)! This *looks* like a potential denial of service or, at the very least, a memory hog issue.
Now, who can call `drm_mode_create_lease_ioctl`? It's restricted to `DRM_MASTER`, which is usually root, or logind/a display server. Still, why would this function *allow* allocation sizes so enormous when no real device will ever approach those numbers? Is this just a maintainer taste issue, or is this architecture accepted?
I need to investigate further. What do upstream kernel and DRM maintainers think about this? Is this something they've addressed elsewhere? I'm going to search the git log in `drivers/gpu/drm` and commit history for this function (`drm_mode_create_lease_ioctl` or `fill_object_idr`). I need more context to understand the rationale and implications fully, before deciding whether this truly is a vulnerability.
|
| 361/5 |
2026/10/14 00:01 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:fill_object_idr]
Results:
|
| 362/5 |
2026/10/14 00:11 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 57742
output: 35
thoughts: 7
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of a technical problem and aiming for a clean, efficient solution.
**Implementing PathPrefix: A Strategic Addition**
Alright, I'm thinking about the current architecture, and a thought just popped into my head: "Let's add `PathPrefix`." It's likely I'm considering a routing strategy, potentially dealing with multiple services or applications under a single domain. I'm probably looking at how to effectively direct traffic based on URL paths. The implications are probably that the routing logic needs to be flexible and that adding `PathPrefix` is the cleanest way. Perhaps I'm trying to avoid overly complex regular expressions in the configuration or in the code, or trying to centralize the management of routes. In short, the addition will hopefully make the system better.
|
| 363/5 |
2026/10/14 00:11 |
tool |
git-log |
3m
Args: map[CodeRegexp:fill_object_idr PathPrefix:drivers/gpu/drm/]
Results: map[Output:4bb2d367a5a2 drm/lease: allow empty leases
62884cd386b8 drm: Add four ioctls for managing drm mode object leases [v7]
]
|
| 364/5 |
2026/10/14 00:15 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 58025
output: 26
thoughts: 26
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Investigating Memory Allocation Constraints**
Alright, I need to dig deeper into how the kernel handles allocation order restrictions and the freezing of pages. My immediate thought is to leverage `git log` to trace relevant code modifications. I'll search for commit messages specifically referencing `alloc_order_allowed` and `alloc_frozen_pages`. These keywords are likely to point me to changes impacting the behavior, constraints, and potentially, the use cases or problem spaces where these allocation flags come into play.
By focusing on commit messages, I can quickly identify patches that directly touch these areas. I expect this approach will give me a timeline of changes, provide context on why modifications were made, and possibly reveal any related bugs or optimizations. This is more efficient than simply grepping the source code, as the commit message often explains the *intent* behind the change, which is crucial for my understanding. Itβs also a good way to determine who to reach out to if I need more context. I'm hoping this will provide a clear picture of how these flags have evolved and are currently utilized.
|
| 365/5 |
2026/10/14 00:15 |
tool |
git-log |
0m
Args: map[Count:5 MessageRegexps:[alloc_order_allowed]]
Results: map[Output:2fc4c1d51d87 mm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof()
]
|
| 366/5 |
2026/10/14 00:16 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 58364
output: 25
thoughts: 27
Thoughts: Here's my thinking process:
**Hunting Down Those DRM Lease Issues**
Okay, so I've got a specific issue I need to address related to DRM leases, probably some warnings or allocation problems. The most efficient way to get a handle on this is to dig through commit messages. Let's focus on messages that mention either `drm_mode_create_lease` or just the broader term `drm_lease`. Those should be the most relevant and likely contain the fixes or discussions I need. That search should help me zero in on the relevant code changes quickly, which saves me a ton of time and allows me to see the context of these potentially problematic leases. Gotta find those fixes!
|
| 367/5 |
2026/10/14 00:16 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[drm_lease]]
Results: map[Output:dbae67ed6ac6 drm/lease: make drm_lease.h self-contained
f37d63e219c3 drm_lease.c: copy user-array safely
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
d793b8f732d6 drm: clarify usage of drm leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
1f7ef07cfa14 drm: add a locked version of drm_is_current_master
1815d9c86e30 drm: add a locked version of drm_is_current_master
c336a5ee9847 drm: Lock pointer access in drm_master_release()
7988fdf5f0a3 drm: Don't include drm_legacy.h in drm_lease.c
]
|
| 368/5 |
2026/10/14 00:16 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 58824
output: 28
thoughts: 20
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Kernel-Wide Hunt for `memdup_array_user` Usage**
Alright, let's dive into this. My initial thought is to comprehensively examine the entire kernel source base. The goal here is specific: I want to identify every instance where `memdup_array_user` is employed. This function likely carries security implications, particularly around memory allocation and user-space data handling, so a complete understanding of its scope is essential. This search will be the foundation for either confirming a well-established pattern, or looking for something unexpected. This isn't just a casual grep; I anticipate needing a nuanced search strategy given the kernel's complexities. I'll need to consider how commit messages might offer context on the evolution and rationale behind each of these calls to `memdup_array_user`, as these are often well written and give an insight to intention. This information will inform any further analysis, vulnerability assessment, or code auditing I might need to perform. Time to get to work.
|
| 369/5 |
2026/10/14 00:16 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[memdup_array_user]]
Results: map[Output:7d5c576cb1c8 Input: cs40l50-vibra - validate custom data from user space
2321831d7e95 drm/amdkfd: Use memdup_array_user to copy data from/to user space at kfd ioctls
84c4c36acd5c drm/amdgpu: validate CP_GFX_SHADOW chunk size in CS pass1
4eca4742eb21 drm/amdkfd: Use memdup_array_user to copy data from/to user space at kfd ioctls
7f61b2eef741 drm/amdgpu: validate CP_GFX_SHADOW chunk size in CS pass1
a1371d9f0e61 drm/amdgpu: rework amdgpu_userq_wait_ioctl v4
5eb2a72bac35 drm/amdgpu/userq: Use memdup_array_user in amdgpu_userq_signal_ioctl
fb1bf29acdd5 drm/amdgpu/userq: Use memdup_array_user in amdgpu_userq_wait_ioctl
922682d48d62 drm/gem: Correct error condition in drm_gem_objects_lookup
cb77b79abf5f drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
]
|
| 370/5 |
2026/10/14 00:16 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 59440
output: 27
thoughts: 19
Thoughts: Okay, I'm ready. Here's a summary as if I'm processing the prompt:
**Analyzing Commit `922682d48d62`**
Alright, let's take a look at commit `922682d48d62`. Immediately, I need to understand the context. Without any additional information, this is just a cryptographic hash β a fingerprint. I can't derive much from it directly. I need to know the repository, the branch, and ideally, some surrounding information like the associated commit message or tickets.
From my perspective, as a domain expert, this tells me nothing definitive on its own. It's a key; perhaps it is the key to further understanding the code and changes. It's the starting point for my investigation. My mind is already racing through the questions I need to answer. What was the change? Why was it made? What does it impact? Based on the lack of data, I would need more information about the commit's content or context before I could provide any kind of helpful analysis or insight.
|
| 371/5 |
2026/10/14 00:16 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 922682d48d628c6c5540da2eb5481f7f7694ce48
Author: Steven Price <steven.price@arm.com>
Date: Mon Nov 24 11:20:38 2025 +0000
drm/gem: Correct error condition in drm_gem_objects_lookup
When vmemdup_array_user() fails, 'handles' is set to a negative error
code and no memory is allocated. So the call to kvfree() should not
happen. Instead just return early with the error code.
Fixes: cb77b79abf5f ("drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup")
Signed-off-by: Steven Price <steven.price@arm.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Link: https://patch.msgid.link/20251124112039.117748-1-steven.price@arm.com
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index 68168d58a7c8..efc79bbf3c73 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -798,13 +798,10 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
*objs_out = objs;
handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
- if (IS_ERR(handles)) {
- ret = PTR_ERR(handles);
- goto out;
- }
+ if (IS_ERR(handles))
+ return PTR_ERR(handles);
ret = objects_lookup(filp, handles, count, objs);
-out:
kvfree(handles);
return ret;
]
|
| 372/5 |
2026/10/14 00:16 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 60281
output: 37
thoughts: 4791
Thoughts: **Analysis of the drm_lease.c Patch for Potential Vulnerabilities and Design Issues**
Okay, let's break this down. This patch is focused on hardening the `drm_mode_create_lease_ioctl` function, specifically related to the handling of `object_count` passed from userspace. The critical section seems to be around the allocation and handling of `object_ids` and `objects`.
First, I see the core fix: replacing `kfree` with `kvfree` and `kzalloc` with `kvzalloc` when working with user-provided data, and that's good. It ensures we're using the correct kernel memory allocators. Also, I see `vmemdup_array_user` is being used, which is a good thing to use when coping data from user space.
Next, I'm zeroing in on this added check:
```c
if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
return -EINVAL;
}
```
This is the heart of the matter. It's crucial because `object_count` is used to determine the size of the arrays that are allocated:
* `object_ids`: Allocated using `vmemdup_array_user`, effectively `size * sizeof(u32)`.
* `objects`: Allocated using `kvzalloc_objs`, effectively `size * sizeof(struct drm_mode_object *)`.
Without this check, a malicious user could pass a huge `object_count` to cause an integer overflow when allocating `objects`, which may lead to several issues. Here's why:
1. **Integer Overflow:** Without the check, if `cl->object_count` is large enough, multiplying by `sizeof(struct drm_mode_object *)` *could* result in an integer overflow, leading to a small or even negative allocation size.
2. **Size Overflow:** If the multiplication *doesn't* overflow, the result could still exceed `INT_MAX`, the maximum size that the kernel allocators can reliably handle, potentially leading to allocation failures or other unexpected behavior.
3. **Potential for Out-of-Bounds Access:** Even if the allocation *succeeds*, a very large value for `object_count` combined with the unsigned nature of the loop counter `o` (`for (o = 0; o < object_count; o++)`) could lead to out-of-bounds access within the `fill_object_idr` function. Specifically, because `object_count` is passed as an `int` to `fill_object_idr`, a very large value would likely be interpreted as a negative integer within the function's scope, causing the loop condition to behave unexpectedly, and possibly leading to out-of-bounds reads or writes.
Therefore, the check `cl->object_count > INT_MAX / sizeof(...)` prevents the integer overflow and out-of-bounds access.
Also, it is crucial that there are not any issues with how the memory is freed in the error paths.
Finally, the added includes were likely not in the source file to begin with, so the patch is correct in adding them.
So, in summary, this patch is an important safety measure, and it's well-scoped:
* It addresses a potential integer overflow vulnerability.
* It protects against excessively large memory allocations requested from user space.
* The check specifically prevents `kvmalloc` from being called with an illegal size, which protects against a `WARN_ON_ONCE` in `kvmalloc`.
* It protects against a kernel crash or security vulnerability.
* The patch's modifications are localized to this single file, and it is a complete fix to the reported issue.
Therefore, this patch is acceptable as a single-patch fix.
|
| 373/5 |
2026/10/14 00:17 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:1 LineCount:35]
Results: map[Contents: 1: // SPDX-License-Identifier: GPL-2.0-or-later
2: /*
3: * Copyright Β© 2017 Keith Packard <keithp@keithp.com>
4: */
5: #include <linux/file.h>
6: #include <linux/uaccess.h>
7:
8: #include <drm/drm_auth.h>
9: #include <drm/drm_crtc.h>
10: #include <drm/drm_drv.h>
11: #include <drm/drm_file.h>
12: #include <drm/drm_lease.h>
13: #include <drm/drm_print.h>
14:
15: #include "drm_crtc_internal.h"
16: #include "drm_internal.h"
17:
18: /**
19: * DOC: drm leasing
20: *
21: * DRM leases provide information about whether a DRM master may control a DRM
22: * mode setting object. This enables the creation of multiple DRM masters that
23: * manage subsets of display resources.
24: *
25: * The original DRM master of a device 'owns' the available drm resources. It
26: * may create additional DRM masters and 'lease' resources which it controls
27: * to the new DRM master. This gives the new DRM master control over the
28: * leased resources until the owner revokes the lease, or the new DRM master
29: * is closed. Some helpful terminology:
30: *
31: * - An 'owner' is a &struct drm_master that is not leasing objects from
32: * another &struct drm_master, and hence 'owns' the objects. The owner can be
33: * identified as the &struct drm_master for which &drm_master.lessor is NULL.
34: *
35: * - A 'lessor' is a &struct drm_master which is leasing objects to one or more
]
|
| 374/5 |
2026/10/14 00:17 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 66523
output: 40
thoughts: 713
Thoughts: **My Thoughts on the `drm_lease.c` Patch**
Okay, so I'm looking at this patch for `drm_lease.c`. Adding those includes, `<linux/limits.h>`, `<linux/slab.h>`, and `<linux/string.h>`, is sensible. Alphabetical order, clean kernel style - good. However, wait a minute, let's not just rubber stamp this. I need to make sure I understand the consequences.
My immediate focus is on `drm_mode_create_lease_ioctl`. Let's step through the error paths there. Specifically, this section:
```c
object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
goto out_lessor;
}
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
goto out_lessor;
}
```
Okay, the memory allocation and copying from userspace look standard. If that fails, it cleans up and bails. The `fill_object_idr` call looks interesting. Then I see `idr_destroy(&leases)`. *That* warrants attention. I need to be *sure* what `idr_destroy` does. Does it free any objects *within* the IDR? It's a critical point if `fill_object_idr` might only partially succeed.
Let's dive into `fill_object_idr`. Lines 433-455:
```c
ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
if (ret < 0) {
drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
object_id, ret);
goto out_free_objects;
}
...
out_free_objects:
for (o = 0; o < object_count; o++) {
if (objects[o])
drm_mode_object_put(objects[o]);
}
kvfree(objects);
return ret;
```
Ah, here's the answer! If `idr_alloc` fails, it *does* clean up. It iterates through the partially populated `objects` array and calls `drm_mode_object_put` on the allocated objects, then frees the `objects` array itself. So the cleanup is *explicitly* handled if `fill_object_idr` fails. This makes me feel more confident in that code path.
Coming back to `drm_mode_create_lease_ioctl`, the call to `idr_destroy(&leases)` is in the `ret` path after `fill_object_idr`.
Now I need to understand what happens if `fill_object_idr` *succeeds*. What is `drm_lease_create` doing with this populated IDR? I need to check how the IDR is used later on.
|
| 375/5 |
2026/10/14 00:17 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/gpu/drm/drm_lease.c Name:drm_lease_create]
Results: map[SourceCode: 196: /*
197: * Uses drm_master_create to allocate a new drm_master, then checks to
198: * make sure all of the desired objects can be leased, atomically
199: * leasing them to the new drmmaster.
200: *
201: * ERR_PTR(-EACCES) some other master holds the title to any object
202: * ERR_PTR(-ENOENT) some object is not a valid DRM object for this device
203: * ERR_PTR(-EBUSY) some other lessee holds title to this object
204: * ERR_PTR(-EEXIST) same object specified more than once in the provided list
205: * ERR_PTR(-ENOMEM) allocation failed
206: */
207: static struct drm_master *drm_lease_create(struct drm_master *lessor, struct idr *leases)
208: {
209: struct drm_device *dev = lessor->dev;
210: int error;
211: struct drm_master *lessee;
212: int object;
213: int id;
214: void *entry;
215:
216: drm_dbg_lease(dev, "lessor %d\n", lessor->lessee_id);
217:
218: lessee = drm_master_create(lessor->dev);
219: if (!lessee) {
220: drm_dbg_lease(dev, "drm_master_create failed\n");
221: return ERR_PTR(-ENOMEM);
222: }
223:
224: mutex_lock(&dev->mode_config.idr_mutex);
225:
226: idr_for_each_entry(leases, entry, object) {
227: error = 0;
228: if (!idr_find(&dev->mode_config.object_idr, object))
229: error = -ENOENT;
230: else if (_drm_has_leased(lessor, object))
231: error = -EBUSY;
232:
233: if (error != 0) {
234: drm_dbg_lease(dev, "object %d failed %d\n", object, error);
235: goto out_lessee;
236: }
237: }
238:
239: /* Insert the new lessee into the tree */
240: id = idr_alloc(&(drm_lease_owner(lessor)->lessee_idr), lessee, 1, 0, GFP_KERNEL);
241: if (id < 0) {
242: error = id;
243: goto out_lessee;
244: }
245:
246: lessee->lessee_id = id;
247: lessee->lessor = drm_master_get(lessor);
248: list_add_tail(&lessee->lessee_list, &lessor->lessees);
249:
250: /* Move the leases over */
251: lessee->leases = *leases;
252: drm_dbg_lease(dev, "new lessee %d %p, lessor %d %p\n",
253: lessee->lessee_id, lessee, lessor->lessee_id, lessor);
254:
255: mutex_unlock(&dev->mode_config.idr_mutex);
256: return lessee;
257:
258: out_lessee:
259: mutex_unlock(&dev->mode_config.idr_mutex);
260:
261: drm_master_put(&lessee);
262:
263: return ERR_PTR(error);
264: }
SourceFile:drivers/gpu/drm/drm_lease.c]
|
| 376/5 |
2026/10/14 00:17 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 69200
output: 42
thoughts: 2434
Thoughts: **Lease Object Validation and Resource Management Analysis**
Okay, so I'm diving into this lease object code, and my initial focus is on the `drm_mode_create_lease_ioctl` function. I see how the IDR is handled β it's moved to the `lessee` on success, and destroyed on failure, which is standard practice. Now, I'm checking what happens in the case of failure, and how `vmemdup_array_user` or `fill_object_idr` failures are managed, which is my main concern.
I noticed the careful handling of the IDR destruction (`idr_destroy(&leases)`) in the error paths of `drm_mode_create_lease_ioctl`, specifically after a failure in `fill_object_idr`. That call is critical as it populates the IDR with the objects to be leased and it needs to be cleaned up on failure. Good, it looks like `fill_object_idr` drops the references to the mode objects, and it also handles freeing `object_ids` and `objects`, which are allocated within the function. Then, I see `drm_lease_create` which can also destroy the IDR in the case of failure.
I'm now focusing on the object count validation. There is a new check: `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))`. This immediately flags a potential integer overflow issue. It's excellent to see that this validation happens *before* acquiring the lessor master, demonstrating a "fail fast" approach, ensuring the input is validated before any resources are acquired. This is very good.
Now, I'm verifying the bounds: `cl->object_count` is a `__u32` which is unsigned, and thus its conversion to `int` within `fill_object_idr` is safe because it's validated to be within `int` range, and therefore it guarantees it is never negative. Both `validate_lease` and `fill_object_idr` take `int object_count`, which is consistent, so this bounds check is very important!
Next, I'm checking the memory allocation. The code now uses `vmemdup_array_user` instead of `memdup_array_user` to handle potentially large object lists, so `kvfree` needs to be used to free them, which is a key improvement I see. That makes sense, since `vmemdup_array_user` (and `vmemdup_user`) allocates memory which must be freed by `kvfree`. And, it is correct that the allocations in `fill_object_idr` now use `kvzalloc_objs` and thus must be freed with `kvfree`.
I'm making sure that there is no other place where the objects are freed, and that the resources are managed correctly. Good, I checked the whole file to make sure that there are no leaks. It looks like the lease code does a good job of validating inputs before acquiring resources, handles errors correctly and cleans up after itself. Thatβs solid!
|
| 377/5 |
2026/10/14 00:17 |
tool |
grepper |
0m
Args: map[Expression:\b(object_ids|objects)\b PathPrefixes:[drivers/gpu/drm/drm_lease.c]]
Results: map[Output:drivers/gpu/drm/drm_lease.c-30- *
drivers/gpu/drm/drm_lease.c:31: * - An 'owner' is a &struct drm_master that is not leasing objects from
drivers/gpu/drm/drm_lease.c:32: * another &struct drm_master, and hence 'owns' the objects. The owner can be
drivers/gpu/drm/drm_lease.c-33- * identified as the &struct drm_master for which &drm_master.lessor is NULL.
drivers/gpu/drm/drm_lease.c-34- *
drivers/gpu/drm/drm_lease.c:35: * - A 'lessor' is a &struct drm_master which is leasing objects to one or more
drivers/gpu/drm/drm_lease.c-36- * other &struct drm_master. Currently, lessees are not allowed to
--
drivers/gpu/drm/drm_lease.c-38- *
drivers/gpu/drm/drm_lease.c:39: * - A 'lessee' is a &struct drm_master which is leasing objects from some
drivers/gpu/drm/drm_lease.c-40- * other &struct drm_master. Each lessee only leases resources from a single
drivers/gpu/drm/drm_lease.c:41: * lessor recorded in &drm_master.lessor, and holds the set of objects that
drivers/gpu/drm/drm_lease.c-42- * it is leasing in &drm_master.leases.
--
drivers/gpu/drm/drm_lease.c-48- *
drivers/gpu/drm/drm_lease.c:49: * The set of objects any &struct drm_master 'controls' is limited to the set
drivers/gpu/drm/drm_lease.c:50: * of objects it leases (for lessees) or all objects (for owners).
drivers/gpu/drm/drm_lease.c-51- *
--
drivers/gpu/drm/drm_lease.c-57- *
drivers/gpu/drm/drm_lease.c:58: * Since each lessee may lease objects from a single lessor, display resource
drivers/gpu/drm/drm_lease.c-59- * leases form a tree of &struct drm_master. As lessees are currently not
--
drivers/gpu/drm/drm_lease.c-64- * &drm_master.lessor is NULL). The full list of lessees that are leasing
drivers/gpu/drm/drm_lease.c:65: * objects from the owner can be searched via the owner's
drivers/gpu/drm/drm_lease.c-66- * &drm_master.lessee_idr.
--
drivers/gpu/drm/drm_lease.c=154=uint32_t drm_lease_filter_crtcs(struct drm_file *file_priv, uint32_t crtcs_in)
--
drivers/gpu/drm/drm_lease.c-197- * Uses drm_master_create to allocate a new drm_master, then checks to
drivers/gpu/drm/drm_lease.c:198: * make sure all of the desired objects can be leased, atomically
drivers/gpu/drm/drm_lease.c-199- * leasing them to the new drmmaster.
--
drivers/gpu/drm/drm_lease.c=346=static int validate_lease(struct drm_device *dev,
drivers/gpu/drm/drm_lease.c-347- int object_count,
drivers/gpu/drm/drm_lease.c:348: struct drm_mode_object **objects,
drivers/gpu/drm/drm_lease.c-349- bool universal_planes)
--
drivers/gpu/drm/drm_lease.c-359- for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c:360: if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
drivers/gpu/drm/drm_lease.c-361- has_crtc = o;
drivers/gpu/drm/drm_lease.c-362- }
drivers/gpu/drm/drm_lease.c:363: if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
drivers/gpu/drm/drm_lease.c-364- has_connector = o;
--
drivers/gpu/drm/drm_lease.c-366- if (universal_planes) {
drivers/gpu/drm/drm_lease.c:367: if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
drivers/gpu/drm/drm_lease.c-368- has_plane = o;
--
drivers/gpu/drm/drm_lease.c=378=static int fill_object_idr(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-381- int object_count,
drivers/gpu/drm/drm_lease.c:382: u32 *object_ids)
drivers/gpu/drm/drm_lease.c-383-{
drivers/gpu/drm/drm_lease.c:384: struct drm_mode_object **objects;
drivers/gpu/drm/drm_lease.c-385- u32 o;
--
drivers/gpu/drm/drm_lease.c-388-
drivers/gpu/drm/drm_lease.c:389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
drivers/gpu/drm/drm_lease.c:390: if (!objects)
drivers/gpu/drm/drm_lease.c-391- return -ENOMEM;
drivers/gpu/drm/drm_lease.c-392-
drivers/gpu/drm/drm_lease.c:393: /* step one - get references to all the mode objects
drivers/gpu/drm/drm_lease.c-394- and check for validity. */
drivers/gpu/drm/drm_lease.c-395- for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c:396: objects[o] = drm_mode_object_find(dev, lessor_priv,
drivers/gpu/drm/drm_lease.c:397: object_ids[o],
drivers/gpu/drm/drm_lease.c-398- DRM_MODE_OBJECT_ANY);
drivers/gpu/drm/drm_lease.c:399: if (!objects[o]) {
drivers/gpu/drm/drm_lease.c-400- ret = -ENOENT;
--
drivers/gpu/drm/drm_lease.c-403-
drivers/gpu/drm/drm_lease.c:404: if (!drm_mode_object_lease_required(objects[o]->type)) {
drivers/gpu/drm/drm_lease.c-405- DRM_DEBUG_KMS("invalid object for lease\n");
--
drivers/gpu/drm/drm_lease.c-410-
drivers/gpu/drm/drm_lease.c:411: ret = validate_lease(dev, object_count, objects, universal_planes);
drivers/gpu/drm/drm_lease.c-412- if (ret) {
--
drivers/gpu/drm/drm_lease.c-419- for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c:420: struct drm_mode_object *obj = objects[o];
drivers/gpu/drm/drm_lease.c:421: u32 object_id = objects[o]->id;
drivers/gpu/drm/drm_lease.c-422-
--
drivers/gpu/drm/drm_lease.c-426- * We're using an IDR to hold the set of leased
drivers/gpu/drm/drm_lease.c:427: * objects, but we don't need to point at the object's
drivers/gpu/drm/drm_lease.c-428- * data structure from the lease as the main object_idr
--
drivers/gpu/drm/drm_lease.c-461- for (o = 0; o < object_count; o++) {
drivers/gpu/drm/drm_lease.c:462: if (objects[o])
drivers/gpu/drm/drm_lease.c:463: drm_mode_object_put(objects[o]);
drivers/gpu/drm/drm_lease.c-464- }
drivers/gpu/drm/drm_lease.c:465: kfree(objects);
drivers/gpu/drm/drm_lease.c-466- return ret;
--
drivers/gpu/drm/drm_lease.c-470- * The master associated with the specified file will have a lease
drivers/gpu/drm/drm_lease.c:471: * created containing the objects specified in the ioctl structure.
drivers/gpu/drm/drm_lease.c-472- * A file descriptor will be allocated for that and returned to the
--
drivers/gpu/drm/drm_lease.c=475=int drm_mode_create_lease_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-487- int fd = -1;
drivers/gpu/drm/drm_lease.c:488: uint32_t *object_ids;
drivers/gpu/drm/drm_lease.c-489-
--
drivers/gpu/drm/drm_lease.c-508-
drivers/gpu/drm/drm_lease.c:509: /* Handle leased objects, if any */
drivers/gpu/drm/drm_lease.c-510- idr_init(&leases);
drivers/gpu/drm/drm_lease.c-511- if (object_count != 0) {
drivers/gpu/drm/drm_lease.c:512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
drivers/gpu/drm/drm_lease.c-513- object_count, sizeof(__u32));
drivers/gpu/drm/drm_lease.c:514: if (IS_ERR(object_ids)) {
drivers/gpu/drm/drm_lease.c:515: ret = PTR_ERR(object_ids);
drivers/gpu/drm/drm_lease.c-516- idr_destroy(&leases);
--
drivers/gpu/drm/drm_lease.c-521- ret = fill_object_idr(dev, lessor_priv, &leases,
drivers/gpu/drm/drm_lease.c:522: object_count, object_ids);
drivers/gpu/drm/drm_lease.c:523: kfree(object_ids);
drivers/gpu/drm/drm_lease.c-524- if (ret) {
--
drivers/gpu/drm/drm_lease.c=588=int drm_mode_list_lessees_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-634-
drivers/gpu/drm/drm_lease.c:635:/* Return the list of leased objects for the specified lessee */
drivers/gpu/drm/drm_lease.c-636-int drm_mode_get_lease_ioctl(struct drm_device *dev,
--
drivers/gpu/drm/drm_lease.c-639- struct drm_mode_get_lease *arg = data;
drivers/gpu/drm/drm_lease.c:640: __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr);
drivers/gpu/drm/drm_lease.c-641- __u32 count_objects = arg->count_objects;
--
drivers/gpu/drm/drm_lease.c-661- if (lessee->lessor == NULL)
drivers/gpu/drm/drm_lease.c:662: /* owner can use all objects */
drivers/gpu/drm/drm_lease.c-663- object_idr = &lessee->dev->mode_config.object_idr;
--
drivers/gpu/drm/drm_lease.c-671- drm_dbg_lease(dev, "adding object %d\n", object);
drivers/gpu/drm/drm_lease.c:672: ret = put_user(object, object_ids + count);
drivers/gpu/drm/drm_lease.c-673- if (ret)
--
drivers/gpu/drm/drm_lease.c-678-
drivers/gpu/drm/drm_lease.c:679: DRM_DEBUG("lease holds %d objects\n", count);
drivers/gpu/drm/drm_lease.c-680- if (ret == 0)
--
drivers/gpu/drm/drm_lease.c-689-/*
drivers/gpu/drm/drm_lease.c:690: * This removes all of the objects from the lease without
drivers/gpu/drm/drm_lease.c-691- * actually getting rid of the lease itself; that way all
]
|
| 378/5 |
2026/10/14 00:17 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 75713
output: 33
thoughts: 1010
Thoughts: **Analyzing the get_lease ioctl and Patch Against Kernel Guidelines**
Okay, let's break this down. First, it's clear that `drm_mode_get_lease_ioctl` is a distinct function, which I already knew, but it's good to confirm. It's completely separate from the other function we are evaluating.
Now, let's run through the guidelines.
1. **Sentinel Test:** The patch doesn't introduce any defensive guards *inside* a compound teardown. The `if` statement checking `cl->object_count` is a validation at the *ioctl entry point*. That's public API, which is explicitly exempt. Good, that's not a concern.
2. **LIFO Stack Unwinding:** The order here is very clean. The check for `object_count` comes *before* any resource acquisition. If that fails, it returns immediately. `vmemdup_array_user` allocates `object_ids`. If it fails, we unwind to `idr_destroy` and `goto out_lessor`. `fill_object_idr` uses `object_ids` and creates `objects`. Immediately after `object_ids` is used, `kvfree(object_ids)` is called. Then, `kvfree(objects)` is paired with `kvzalloc_objs` in the `fill_object_idr`. This is a textbook LIFO unwind. Everything is properly handled and cleaned up as it should be.
3. **Ownership Decoupling:** Not applicable here, this isn't relevant to dynamically refcounted objects and device-bound allocations.
4. **Codebase Idiom Alignment:** Hmm, this is where it gets interesting. Can we leverage `__free(kvfree)` or `cleanup.h`? It's worth double-checking. Time to check the codebase. Gotta see if DRM uses this, in the `drivers/gpu/drm/` directory. If it doesn't, we can add it and create a patch. Otherwise, this check is good.
|
| 379/5 |
2026/10/14 00:17 |
tool |
grepper |
0m
Error:
Args: map[Expression:__free\(kvfree\) PathPrefixes:[drivers/gpu/drm/]]
Results:
|
| 380/5 |
2026/10/14 00:17 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 77211
output: 33
thoughts: 37
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating Memory Management in the DRM Subsystem**
Alright, the initial hunch is that `__free(kvfree)` isn't being used in the `drivers/gpu/drm` directory. That's a reasonable starting point for an investigation. It's often the case that certain subsystems or kernel areas evolve with their own memory management conventions. So, let's confirm that by digging into the usage of its close relative, `__free(kfree)` within the same `drivers/gpu/drm` space. Understanding *how* they're freeing memory, or more importantly *if* they're using this type of memory freeing, will illuminate whether the system is fully compliant, or if there's possibly some area of code that's worth a more in-depth look.
|
| 381/5 |
2026/10/14 00:18 |
tool |
grepper |
0m
Args: map[Expression:__free\(kfree\) PathPrefixes:[drivers/gpu/drm/]]
Results: map[Output:drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c=79=static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c-131- */
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c:132: u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL);
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c-133- if (!data)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c=241=static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 offset, size_t size, int write_en)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c-258- */
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c:259: u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL);
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c-260- if (!data)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c=484=static ssize_t amdgpu_ras_cper_debugfs_read(struct file *f, char __user *buf,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-488- struct amdgpu_ring *ring = file_inode(f)->i_private;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:489: struct ras_cmd_cper_snapshot_req *snapshot_req __free(kfree) =
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-490- kzalloc_obj(struct ras_cmd_cper_snapshot_req);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:491: struct ras_cmd_cper_snapshot_rsp *snapshot_rsp __free(kfree) =
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-492- kzalloc_obj(struct ras_cmd_cper_snapshot_rsp);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:493: struct ras_cmd_cper_record_req *record_req __free(kfree) =
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-494- kzalloc_obj(struct ras_cmd_cper_record_req);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:495: struct ras_cmd_cper_record_rsp *record_rsp __free(kfree) =
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-496- kzalloc_obj(struct ras_cmd_cper_record_rsp);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:497: u32 *ring_header __free(kfree) =
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c-498- kzalloc(ring_header_size, GFP_KERNEL);
--
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c=1728=static void dm_gpureset_commit_state(struct dc_state *dc_state,
--
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c-1736- struct dc_stream_update stream_update;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c:1737: } *bundle __free(kfree);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c-1738- int k, m;
--
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c=541=static int smu_v13_0_6_tables_init(struct smu_context *smu)
--
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c-545- struct smu_v13_0_6_gpu_metrics *gpu_metrics;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c:546: void *driver_pptable __free(kfree) = NULL;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c:547: void *metrics_table __free(kfree) = NULL;
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c-548- struct amdgpu_device *adev = smu->adev;
--
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c=197=static int smu_v15_0_8_tables_init(struct smu_context *smu)
--
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c-204- struct smu_v15_0_8_gpu_metrics *gpu_metrics;
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c:205: void *driver_pptable __free(kfree) = NULL;
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c:206: void *metrics_table __free(kfree) = NULL;
drivers/gpu/drm/amd/pm/swsmu/smu15/smu_v15_0_8_ppt.c-207-
--
drivers/gpu/drm/msm/msm_gpu.h=352=struct msm_perfcntr_state {
--
drivers/gpu/drm/msm/msm_gpu.h-363- * statically pre-allocated when the gpu is initialized to simplify
drivers/gpu/drm/msm/msm_gpu.h:364: * error path cleanup in PERFCNTR_CONFIG ioctl. (__free(kfree)
drivers/gpu/drm/msm/msm_gpu.h-365- * doesn't really help with variable length arrays of allocated
--
drivers/gpu/drm/msm/msm_perfcntr.c=370=msm_ioctl_perfcntr_config(struct drm_device *dev, void *data, struct drm_file *file)
--
drivers/gpu/drm/msm/msm_perfcntr.c-420-
drivers/gpu/drm/msm/msm_perfcntr.c:421: struct msm_perfcntr_context_state *perfctx __free(kfree) = kzalloc(
drivers/gpu/drm/msm/msm_perfcntr.c-422- struct_size(perfctx, reserved_counters, gpu->num_perfcntr_groups),
--
drivers/gpu/drm/msm/msm_perfcntr.c-426-
drivers/gpu/drm/msm/msm_perfcntr.c:427: struct msm_perfcntr_stream *stream __free(kfree) = kzalloc_obj(*stream);
drivers/gpu/drm/msm/msm_perfcntr.c-428- if (!stream)
--
drivers/gpu/drm/msm/msm_perfcntr.c-430-
drivers/gpu/drm/msm/msm_perfcntr.c:431: uint8_t *nr_counters __free(kfree) = kzalloc_objs(uint8_t, gpu->num_perfcntr_groups);
drivers/gpu/drm/msm/msm_perfcntr.c-432- if (!nr_counters)
--
drivers/gpu/drm/msm/msm_perfcntr.c-434-
drivers/gpu/drm/msm/msm_perfcntr.c:435: uint32_t *group_idx __free(kfree) = kzalloc_objs(uint32_t, args->nr_groups);
drivers/gpu/drm/msm/msm_perfcntr.c-436- if (!group_idx)
--
drivers/gpu/drm/msm/msm_perfcntr.c-539-
drivers/gpu/drm/msm/msm_perfcntr.c:540: void *buf __free(kfree) = kmalloc(stream->fifo_size, GFP_KERNEL);
drivers/gpu/drm/msm/msm_perfcntr.c-541- if (!buf)
--
drivers/gpu/drm/xe/xe_configfs.c=412=static ssize_t gt_types_allowed_store(struct config_item *item, const char *page,
--
drivers/gpu/drm/xe/xe_configfs.c-415- struct xe_config_group_device *dev = to_xe_config_group_device(item);
drivers/gpu/drm/xe/xe_configfs.c:416: char *buf __free(kfree) = kstrdup(page, GFP_KERNEL);
drivers/gpu/drm/xe/xe_configfs.c-417- char *p = buf;
--
drivers/gpu/drm/xe/xe_gt_sriov_pf_debugfs.c=294=static ssize_t sched_groups_config_write(struct file *file, const char __user *ubuf,
--
drivers/gpu/drm/xe/xe_gt_sriov_pf_debugfs.c-301- u32 values[GUC_MAX_SCHED_GROUPS];
drivers/gpu/drm/xe/xe_gt_sriov_pf_debugfs.c:302: int *input __free(kfree) = NULL;
drivers/gpu/drm/xe/xe_gt_sriov_pf_debugfs.c-303- u32 count;
--
drivers/gpu/drm/xe/xe_pci.c=610=static int read_gmdid(struct xe_device *xe, enum xe_gmdid_type type, u32 *ver, u32 *revid)
--
drivers/gpu/drm/xe/xe_pci.c-626- */
drivers/gpu/drm/xe/xe_pci.c:627: struct xe_gt *gt __free(kfree) = NULL;
drivers/gpu/drm/xe/xe_pci.c-628- int err;
--
drivers/gpu/drm/xe/xe_sysctrl_mailbox.c=217=static int sysctrl_receive_frames(struct xe_sysctrl *sc,
--
drivers/gpu/drm/xe/xe_sysctrl_mailbox.c-224- size_t remain = sizeof(*hdr) + data_out_len;
drivers/gpu/drm/xe/xe_sysctrl_mailbox.c:225: u8 *buffer __free(kfree) = kzalloc(remain, GFP_KERNEL);
drivers/gpu/drm/xe/xe_sysctrl_mailbox.c-226- size_t frame_size;
]
|
| 382/5 |
2026/10/14 00:18 |
llm |
patch-reviewer |
0m
Model:
Tokens:
input: 80504
output: 19
thoughts: 2020
Thoughts: **Patch Review: drm/lease - Analysis and Approval**
Okay, let's break this down. This patch is aiming to fix a potential vulnerability within the DRM lease functionality, specifically addressing the allocation of large object ID arrays. The standard use of `goto` ladders and `kfree/kvfree` in `drm_lease.c` and `drm_gem.c` is fine, but we need to ensure this particular patch doesn't introduce any new problems.
First, I need to confirm this patch adheres to our single-patch policy, which it seems to be doing. We're looking for a localized fix, no architectural overhauls, and no band-aids. This appears to be precisely what we have.
The core of the patch involves replacing `kzalloc_objs` and `memdup_array_user` with `kvzalloc_objs` and `vmemdup_array_user`, respectively. This is a good sign, as `kvmalloc` and its related functions are intended for handling potentially large and user-controlled allocations. We're also seeing the introduction of checks for `cl->object_count` against `INT_MAX / sizeof(...)` to prevent overflows.
Alright, let's go over the allocation and deallocation process, starting with the integers.
I'm verifying that the allocation and deallocation pairs are correct: `kvzalloc_objs` with `kvfree`, and `vmemdup_array_user` with `kvfree`. All seems in order.
Next, I need to scrutinize the integer checks. The critical aspect is to ensure the checks for `cl->object_count` are sufficient. The initial thought is to make sure it is not 0 (allowed by commit `4bb2d367a5a2`). Then, the primary focus is on ensuring that `cl->object_count` *does* not result in integer overflows during calculations (that is, no allocation that exceeds `INT_MAX`). We are good on this front. The size checks before allocating with `kvzalloc_objs` and `vmemdup_array_user` are solid, thus they will never exceed `INT_MAX`.
Next, I'm verifying that the patch is robust against various failure scenarios for `vmemdup_array_user` and `fill_object_idr`. The code explicitly handles error returns like `-EFAULT` and `-ENOMEM` with appropriate checks using `IS_ERR` and jumps to `out_lessor` to handle cleanup gracefully. Also, I am checking the cleanup order, which appears to be LIFO.
Let's check for any compiler issues.
Now, I'll confirm that all necessary includes are present and properly placed in the source file. `<linux/limits.h>` for `INT_MAX`, `<linux/slab.h>` for `kvzalloc_objs` and `kvfree`, and `<linux/string.h>` for `vmemdup_array_user`. All seem to be present, and they're in the right place.
The underlying root cause here, as I understand it, is Syzkaller triggering an allocation that exceeds the `MAX_PAGE_ORDER` due to the use of `kmalloc` with `GFP_KERNEL` (and this is correctly addressed by this patch). The patch changes this to `vmemdup_array_user`, which can handle non-contiguous allocations and virtual memory and `kvmalloc`. The explicit `INT_MAX` check effectively prevents excessive allocation sizes from being passed to these functions in the first place, thus preventing any warnings from `__kvmalloc_node_noprof`.
Does this violate any architectural principles? Let's check:
- It's not a sentinel guard.
- No memory leaks or use-after-free conditions.
- LIFO lifecycle is maintained.
- Localized change, as it is only in `drivers/gpu/drm/drm_lease.c`.
Let's double-check again for any subtle flaws:
- `cl->object_ids` can't be NULL (handled by `vmemdup_array_user`).
- Zero `cl->object_count` (already verified and permitted).
- `cl->object_count` exceeding `INT_MAX / sizeof(...)` is blocked.
- Potential `kvzalloc_objs` failures are handled.
- `vmemdup_array_user` failures are handled.
- `kvfree` handles NULL.
Everything is very solid. This patch is a clean fix, follows the kernel's coding standards, handles potential errors correctly, and addresses the root cause directly. **ReviewApproved = true**. No comments are needed. Time to call the `set-results` tool.
|
| 383/5 |
2026/10/14 00:18 |
tool |
set-results |
0m
Args: map[ReviewApproved:true ReviewComments:[]]
Results: map[ReviewApproved:true ReviewComments:[]]
|
| 384/4 |
2026/10/14 00:18 |
action |
evaluate-patch-review |
0m
Results: map[NeedsIteration:false ReviewFeedback:]
|
| 385/1 |
2026/10/14 00:18 |
action |
apply-patch |
0m
Results:
|
| 386/1 |
2026/10/14 00:18 |
action |
init-style-items |
0m
Results:
|
| 387/1 |
2026/10/14 00:18 |
action |
run-checkpatch |
0m
Results: map[CheckpatchOutput:total: 0 errors, 0 warnings, 54 lines checked
Your patch has no obvious style problems and is ready for submission.
]
|
| 388/1 |
2026/10/14 00:18 |
loop |
|
0m
|
| 389/2 |
2026/10/14 00:18 |
iteration |
0 |
0m
|
| 390/3 |
2026/10/14 00:18 |
agent |
checkpatch-arbiter |
0m
Model:
Results:
Instruction:
You are an expert Linux kernel maintainer acting as a code style arbiter.
Your task is to review scripts/checkpatch.pl output and reviewer style requests for a proposed patch.
Determine which reported issues are genuine, actionable formatting/style defects (e.g. indentation, whitespace,
naming, syntax style) and should be fixed. List them in ActionableIssues.
Ignore issues that are false positives, intentional constructs (e.g. BUG_ON/XA_BUG_ON in test files, macros,
subsystem conventions), or unfixable without breaking code logic or tests. If no issues should be changed,
leave ActionableIssues empty.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The patch diff is:
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -3,6 +3,9 @@
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
@@ -386,7 +389,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +465,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
@@ -496,6 +499,11 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
@@ -509,8 +517,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
@@ -520,7 +528,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
The checkpatch.pl output is:
total: 0 errors, 0 warnings, 54 lines checked
Your patch has no obvious style problems and is ready for submission.
Carefully evaluate each issue and populate ActionableIssues.
|
| 391/4 |
2026/10/14 00:18 |
llm |
checkpatch-arbiter |
0m
Model:
Tokens:
input: 1252
output: 15
thoughts: 319
Thoughts: **Reviewing the Patch for Style and Formatting**
Okay, so I need to go through this patch, looking at the output from `scripts/checkpatch.pl` and any reviewer comments to assess if there are any style or formatting issues. The goal is to determine if there are actionable defects that need fixing.
Right, the checkpatch output is clean: "total: 0 errors, 0 warnings, 54 lines checked. Your patch has no obvious style problems and is ready for submission." Fantastic! And there are no reviewer comments to sift through either.
So, the situation is straightforward. There are no reported issues from either checkpatch or the reviewers. Therefore, following the instructions, the `ActionableIssues` list should be empty. We have to consider things like false positives and those constructs that we can't alter without breaking the code, but there is no need to make those considerations here.
Now, let's make sure we're adhering to the tool call requirements. I need to call `set-results` exactly once before the final reply, with `ActionableIssues: []`. So, I will be setting `ActionableIssues` to an empty list `[]`. Let's get that done.
|
| 392/4 |
2026/10/14 00:18 |
tool |
set-results |
0m
Args:
Results:
|
| 393/3 |
2026/10/14 00:18 |
action |
evaluate-checkpatch-arbiter |
0m
Results: map[NeedRefinement:false]
|
| 394/3 |
2026/10/14 00:18 |
action |
If |
0m
Args: map[NeedRefinement:false]
|
| 395/1 |
2026/10/14 00:18 |
agent |
fixes-finder |
18m
Model:
Results: map[FixesHash:62884cd386b876638720ef88374b31a84ca7ee5f]
Instruction:
You are an experienced Linux kernel developer tasked with identifying the commit
that introduced the bug being fixed. Identifying the correct buggy commit is crucial
for proper kernel maintenance (backporting to stable trees, etc.).
Your investigation strategy:
1. Examine the patch that fixes the bug. Use git tools (like git-log or git-blame)
to trace the history of the lines or functions modified by the patch.
2. Analyze the stack trace in the crash report. Identify the key files and functions
involved in the crash and investigate their history to see when the problematic
logic was introduced.
3. Compare the bug explanation with the commit history to find the point where
the described logic error first appeared.
A bug is typically introduced when a piece of code is first written, or when
a refactoring changed its logic in a way that introduced the bug.
Trace the history of relevant symbols or find when specific code patterns were introduced/removed.
You must provide exactly one bug-introducing commit hash.
If you are unable to confidently determine the bug-introducing commit after investigation,
return an empty string rather than guessing.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The crash is:
------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
The explanation of the root cause is:
An analysis of the crash reveals that it is caused by an unbounded user-controlled allocation size in the DRM lease creation ioctl, which attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` using the `kmalloc` family of functions.
### Root Cause Analysis
The crash is a warning triggered in `alloc_order_allowed()` because `__alloc_frozen_pages_noprof()` is called with an allocation order that exceeds `MAX_PAGE_ORDER` (typically 10, which corresponds to 4MB on systems with 4KB pages).
This happens in `fill_object_idr()` when allocating the `objects` array:
```c
// drivers/gpu/drm/drm_lease.c:389
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
The `kzalloc_objs` macro expands to a `kmalloc`-family allocation (equivalent to `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`).
The `object_count` comes directly from the user-space `drm_mode_create_lease` struct via `cl->object_count` in `drm_mode_create_lease_ioctl()`. There is no upper bound check on this value.
Before calling `fill_object_idr()`, `drm_mode_create_lease_ioctl()` allocates the `object_ids` array using `memdup_array_user()`:
```c
// drivers/gpu/drm/drm_lease.c:512
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user()` uses `memdup_user()`, which allocates memory with `GFP_USER | __GFP_NOWARN`. Because of the `__GFP_NOWARN` flag, if `object_count` is extremely large (e.g., requiring > 4MB), `memdup_array_user()` will silently fail and return `-ENOMEM` without triggering any warnings.
However, there is a specific window where `object_count` is large enough to require more than 4MB for the `objects` array (which has 8-byte pointers on 64-bit systems), but small enough that the `object_ids` array (which has 4-byte `__u32` elements) fits within 4MB.
In the provided syzkaller reproducer:
```c
*(uint32_t*)0x200003c8 = 0xf4240; // object_count = 1,000,000
```
1. `object_count` is set to `1,000,000`.
2. `memdup_array_user()` allocates `1,000,000 * 4 = 4,000,000` bytes. This is order 10, which is `<= MAX_PAGE_ORDER`. The allocation succeeds.
3. `fill_object_idr()` then calls `kzalloc_objs()` to allocate `1,000,000 * 8 = 8,000,000` bytes. This requires order 11, which is `> MAX_PAGE_ORDER`.
4. Since `kzalloc_objs()` uses `GFP_KERNEL` without `__GFP_NOWARN`, the page allocator loudly complains and triggers the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` warning.
### Proposed Fix
To fix this, the allocation of the `objects` array in `fill_object_idr()` should be changed to use `kvzalloc_objs()`, which gracefully falls back to `vmalloc()` for large allocations and does not trigger the page allocator warning. The corresponding `kfree()` must also be updated to `kvfree()`.
```c
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,7 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +462,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
```
*(Note: While adding an arbitrary upper bound check to `object_count` in `drm_mode_create_lease_ioctl()` is another option, using `kvzalloc_objs()` is the standard kernel pattern for handling user-controlled array sizes without imposing artificial limits).*
The patch that fixes the bug is:
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -3,6 +3,9 @@
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
@@ -386,7 +389,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +465,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
@@ -496,6 +499,11 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
@@ -509,8 +517,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
@@ -520,7 +528,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
Search for the commit(s) that introduced this bug.
|
| 396/2 |
2026/10/14 00:18 |
llm |
fixes-finder |
1m
Model:
Tokens:
input: 8443
output: 78
thoughts: 976
Thoughts: **Pinpointing the Bug-Fixing Commit**
Okay, so I need to track down the commit that introduced the bug this patch fixes. My first instinct is always to carefully dissect the patch itself. Looking at the `diff`, it's clear we're dealing with memory allocation and object handling within the DRM lease functionality. Specifically, changes are focused around `fill_object_idr` and `drm_mode_create_lease_ioctl`.
The patch makes several changes. It replaces `kzalloc_objs` with `kvzalloc_objs` and `kfree` with `kvfree`, indicating a shift towards using kernel virtual memory for allocations. Additionally, there are changes from `memdup_array_user` to `vmemdup_array_user`. This hints at potential issues with how user-provided data for object IDs is handled, possibly related to memory copying and validation. And finally, an integer overflow check has been added to `cl->object_count`.
Given these changes, my working hypothesis is that the bug likely involves memory allocation or integer overflow when dealing with the number or size of leased objects. The fact that the code is dealing with user provided data reinforces this. It makes sense to assume the vulnerability might be in memory handling that is exposed to userspace.
To get the necessary context to determine the root cause, I'll leverage my knowledge of the codebase and the `git` tools. I'll use `git blame` or `git log` on `drivers/gpu/drm/drm_lease.c` and focus on the lines related to the changes I just analyzed, namely `fill_object_idr`, `drm_mode_create_lease_ioctl` and the lines immediately surrounding them, to see when these allocation functions were introduced or modified, and if there are any associated commit messages that might shed light on the initial design or subsequent modifications. With that information, I should be able to narrow down the range of commits and identify the culprit.
|
| 397/2 |
2026/10/14 00:20 |
tool |
git-blame |
0m
Args: map[End:400 File:drivers/gpu/drm/drm_lease.c Start:380]
Results: map[Output:62884cd386b87 380) struct idr *leases,
62884cd386b87 381) int object_count,
62884cd386b87 382) u32 *object_ids)
62884cd386b87 383) {
62884cd386b87 384) struct drm_mode_object **objects;
62884cd386b87 385) u32 o;
62884cd386b87 386) int ret;
968029057192e 387) bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
968029057192e 388)
32a92f8c89326 389) objects = kzalloc_objs(struct drm_mode_object *, object_count);
62884cd386b87 390) if (!objects)
62884cd386b87 391) return -ENOMEM;
62884cd386b87 392)
62884cd386b87 393) /* step one - get references to all the mode objects
62884cd386b87 394) and check for validity. */
62884cd386b87 395) for (o = 0; o < object_count; o++) {
62884cd386b87 396) objects[o] = drm_mode_object_find(dev, lessor_priv,
62884cd386b87 397) object_ids[o],
62884cd386b87 398) DRM_MODE_OBJECT_ANY);
62884cd386b87 399) if (!objects[o]) {
62884cd386b87 400) ret = -ENOENT;
]
|
| 398/2 |
2026/10/14 00:20 |
tool |
git-blame |
0m
Args: map[End:530 File:drivers/gpu/drm/drm_lease.c Start:505]
Results: map[Output:56f0729a510f9 505) }
56f0729a510f9 506)
62884cd386b87 507) object_count = cl->object_count;
62884cd386b87 508)
4bb2d367a5a28 509) /* Handle leased objects, if any */
62884cd386b87 510) idr_init(&leases);
4bb2d367a5a28 511) if (object_count != 0) {
f37d63e219c39 512) object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
f37d63e219c39 513) object_count, sizeof(__u32));
4bb2d367a5a28 514) if (IS_ERR(object_ids)) {
4bb2d367a5a28 515) ret = PTR_ERR(object_ids);
4bb2d367a5a28 516) idr_destroy(&leases);
4bb2d367a5a28 517) goto out_lessor;
4bb2d367a5a28 518) }
62884cd386b87 519)
4bb2d367a5a28 520) /* fill and validate the object idr */
4bb2d367a5a28 521) ret = fill_object_idr(dev, lessor_priv, &leases,
4bb2d367a5a28 522) object_count, object_ids);
4bb2d367a5a28 523) kfree(object_ids);
4bb2d367a5a28 524) if (ret) {
7bd224b6625ab 525) drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
4bb2d367a5a28 526) idr_destroy(&leases);
4bb2d367a5a28 527) goto out_lessor;
4bb2d367a5a28 528) }
62884cd386b87 529) }
62884cd386b87 530)
]
|
| 399/2 |
2026/10/14 00:20 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 11238
output: 56
thoughts: 85
Thoughts: **Examining the Recent Commit History**
Alright, let's dive right in. The context suggests there's been some recent activity that warrants a closer look. My immediate thought is to examine the specific commits listed: `62884cd386b87`, `4bb2d367a5a28`, `f37d63e219c39`, and `32a92f8c89326`. To get a clear picture of the changes introduced by each, the most direct approach is to leverage `git-show`. This will allow me to quickly dissect the diffs and understand the what, why, and how behind these commits. Time to get my hands dirty and investigate.
|
| 400/2 |
2026/10/14 00:20 |
tool |
git-show |
0m
Args: map[Commit:32a92f8c89326]
Results: map[Output:commit 32a92f8c89326985e05dce8b22d3f0aa07a3e1bd
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date: Sat Feb 21 20:03:00 2026 -0800
Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
This converts some of the visually simpler cases that have been split
over multiple lines. I only did the ones that are easy to verify the
resulting diff by having just that final GFP_KERNEL argument on the next
line.
Somebody should probably do a proper coccinelle script for this, but for
me the trivial script actually resulted in an assertion failure in the
middle of the script. I probably had made it a bit _too_ trivial.
So after fighting that far a while I decided to just do some of the
syntactically simpler cases with variations of the previous 'sed'
scripts.
The more syntactically complex multi-line cases would mostly really want
whitespace cleanup anyway.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/arch/arm/mach-omap1/mcbsp.c b/arch/arm/mach-omap1/mcbsp.c
index a4dae1baae99..b6cce510c343 100644
--- a/arch/arm/mach-omap1/mcbsp.c
+++ b/arch/arm/mach-omap1/mcbsp.c
@@ -294,8 +294,7 @@ static void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
{
int i;
- omap_mcbsp_devices = kzalloc_objs(struct platform_device *, size,
- GFP_KERNEL);
+ omap_mcbsp_devices = kzalloc_objs(struct platform_device *, size);
if (!omap_mcbsp_devices) {
printk(KERN_ERR "Could not register McBSP devices\n");
return;
diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c
index 34d761ef08b0..592dd8668de4 100644
--- a/arch/arm64/kernel/vdso.c
+++ b/arch/arm64/kernel/vdso.c
@@ -81,8 +81,7 @@ static int __init __vdso_init(enum vdso_abi abi)
vdso_info[abi].vdso_code_start) >>
PAGE_SHIFT;
- vdso_pagelist = kzalloc_objs(struct page *, vdso_info[abi].vdso_pages,
- GFP_KERNEL);
+ vdso_pagelist = kzalloc_objs(struct page *, vdso_info[abi].vdso_pages);
if (vdso_pagelist == NULL)
return -ENOMEM;
diff --git a/arch/loongarch/kernel/vdso.c b/arch/loongarch/kernel/vdso.c
index 222be8fc4aec..0aa10cadb959 100644
--- a/arch/loongarch/kernel/vdso.c
+++ b/arch/loongarch/kernel/vdso.c
@@ -52,8 +52,7 @@ static int __init init_vdso(void)
vdso_info.size = PAGE_ALIGN(vdso_end - vdso_start);
vdso_info.code_mapping.pages =
- kzalloc_objs(struct page *, vdso_info.size / PAGE_SIZE,
- GFP_KERNEL);
+ kzalloc_objs(struct page *, vdso_info.size / PAGE_SIZE);
if (!vdso_info.code_mapping.pages)
return -ENOMEM;
diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
index b7fdb089f2af..2ba2dd26a7ea 100644
--- a/arch/powerpc/kvm/book3s_pr.c
+++ b/arch/powerpc/kvm/book3s_pr.c
@@ -1738,8 +1738,7 @@ static int kvmppc_core_vcpu_create_pr(struct kvm_vcpu *vcpu)
vcpu->arch.book3s = vcpu_book3s;
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
- vcpu->arch.shadow_vcpu = kzalloc_obj(*vcpu->arch.shadow_vcpu,
- GFP_KERNEL);
+ vcpu->arch.shadow_vcpu = kzalloc_obj(*vcpu->arch.shadow_vcpu);
if (!vcpu->arch.shadow_vcpu)
goto free_vcpu3s;
#endif
diff --git a/arch/powerpc/mm/book3s64/mmu_context.c b/arch/powerpc/mm/book3s64/mmu_context.c
index c7302dd2ef25..2fe787e6c2dc 100644
--- a/arch/powerpc/mm/book3s64/mmu_context.c
+++ b/arch/powerpc/mm/book3s64/mmu_context.c
@@ -96,8 +96,7 @@ static int hash__init_new_context(struct mm_struct *mm)
{
int index;
- mm->context.hash_context = kmalloc_obj(struct hash_mm_context,
- GFP_KERNEL);
+ mm->context.hash_context = kmalloc_obj(struct hash_mm_context);
if (!mm->context.hash_context)
return -ENOMEM;
@@ -124,8 +123,7 @@ static int hash__init_new_context(struct mm_struct *mm)
#ifdef CONFIG_PPC_SUBPAGE_PROT
/* inherit subpage prot details if we have one. */
if (current->mm->context.hash_context->spt) {
- mm->context.hash_context->spt = kmalloc_obj(struct subpage_prot_table,
- GFP_KERNEL);
+ mm->context.hash_context->spt = kmalloc_obj(struct subpage_prot_table);
if (!mm->context.hash_context->spt) {
kfree(mm->context.hash_context);
return -ENOMEM;
diff --git a/arch/powerpc/perf/hv-24x7.c b/arch/powerpc/perf/hv-24x7.c
index 8a8d8c2b8930..243c0a1c8cda 100644
--- a/arch/powerpc/perf/hv-24x7.c
+++ b/arch/powerpc/perf/hv-24x7.c
@@ -917,8 +917,7 @@ static int create_events_from_catalog(struct attribute ***events_,
goto e_event_attrs;
}
- event_long_descs = kmalloc_objs(*event_long_descs, event_idx + 1,
- GFP_KERNEL);
+ event_long_descs = kmalloc_objs(*event_long_descs, event_idx + 1);
if (!event_long_descs) {
ret = -ENOMEM;
goto e_event_descs;
diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c
index e3cb23906fcd..db98e9af8812 100644
--- a/arch/powerpc/perf/imc-pmu.c
+++ b/arch/powerpc/perf/imc-pmu.c
@@ -1527,8 +1527,7 @@ static int init_nest_pmu_ref(void)
{
int nid, i, cpu;
- nest_imc_refc = kzalloc_objs(*nest_imc_refc, num_possible_nodes(),
- GFP_KERNEL);
+ nest_imc_refc = kzalloc_objs(*nest_imc_refc, num_possible_nodes());
if (!nest_imc_refc)
return -ENOMEM;
@@ -1714,14 +1713,12 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
goto err;
nr_cores = DIV_ROUND_UP(num_possible_cpus(), threads_per_core);
- pmu_ptr->mem_info = kzalloc_objs(struct imc_mem_info, nr_cores,
- GFP_KERNEL);
+ pmu_ptr->mem_info = kzalloc_objs(struct imc_mem_info, nr_cores);
if (!pmu_ptr->mem_info)
goto err;
- core_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores,
- GFP_KERNEL);
+ core_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores);
if (!core_imc_refc) {
kfree(pmu_ptr->mem_info);
@@ -1754,8 +1751,7 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
return -ENOMEM;
nr_cores = DIV_ROUND_UP(num_possible_cpus(), threads_per_core);
- trace_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores,
- GFP_KERNEL);
+ trace_imc_refc = kzalloc_objs(struct imc_pmu_ref, nr_cores);
if (!trace_imc_refc)
return -ENOMEM;
diff --git a/arch/powerpc/platforms/powernv/idle.c b/arch/powerpc/platforms/powernv/idle.c
index 1389a3131993..6cd461f82968 100644
--- a/arch/powerpc/platforms/powernv/idle.c
+++ b/arch/powerpc/platforms/powernv/idle.c
@@ -1336,8 +1336,7 @@ static int __init pnv_parse_cpuidle_dt(void)
nr_idle_states = of_property_count_u32_elems(np,
"ibm,cpu-idle-state-flags");
- pnv_idle_states = kzalloc_objs(*pnv_idle_states, nr_idle_states,
- GFP_KERNEL);
+ pnv_idle_states = kzalloc_objs(*pnv_idle_states, nr_idle_states);
temp_u32 = kcalloc(nr_idle_states, sizeof(u32), GFP_KERNEL);
temp_u64 = kcalloc(nr_idle_states, sizeof(u64), GFP_KERNEL);
temp_string = kcalloc(nr_idle_states, sizeof(char *), GFP_KERNEL);
diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c
index 5214e2d43e78..6aa578e6348d 100644
--- a/arch/powerpc/platforms/powernv/memtrace.c
+++ b/arch/powerpc/platforms/powernv/memtrace.c
@@ -133,8 +133,7 @@ static int memtrace_init_regions_runtime(u64 size)
u32 nid;
u64 m;
- memtrace_array = kzalloc_objs(struct memtrace_entry, num_online_nodes(),
- GFP_KERNEL);
+ memtrace_array = kzalloc_objs(struct memtrace_entry, num_online_nodes());
if (!memtrace_array) {
pr_err("Failed to allocate memtrace_array\n");
return -EINVAL;
diff --git a/arch/powerpc/platforms/powernv/opal-imc.c b/arch/powerpc/platforms/powernv/opal-imc.c
index ed2842bea1cb..b3fd5c648dea 100644
--- a/arch/powerpc/platforms/powernv/opal-imc.c
+++ b/arch/powerpc/platforms/powernv/opal-imc.c
@@ -108,8 +108,7 @@ static int imc_get_mem_addr_nest(struct device_node *node,
nr_chips))
goto error;
- pmu_ptr->mem_info = kzalloc_objs(*pmu_ptr->mem_info, nr_chips + 1,
- GFP_KERNEL);
+ pmu_ptr->mem_info = kzalloc_objs(*pmu_ptr->mem_info, nr_chips + 1);
if (!pmu_ptr->mem_info)
goto error;
diff --git a/arch/powerpc/platforms/powernv/opal-powercap.c b/arch/powerpc/platforms/powernv/opal-powercap.c
index 0e297d70647f..9bb73cb42a65 100644
--- a/arch/powerpc/platforms/powernv/opal-powercap.c
+++ b/arch/powerpc/platforms/powernv/opal-powercap.c
@@ -181,13 +181,11 @@ void __init opal_powercap_init(void)
has_cur = true;
}
- pcaps[i].pattrs = kzalloc_objs(struct powercap_attr, j,
- GFP_KERNEL);
+ pcaps[i].pattrs = kzalloc_objs(struct powercap_attr, j);
if (!pcaps[i].pattrs)
goto out_pcaps_pattrs;
- pcaps[i].pg.attrs = kzalloc_objs(struct attribute *, j + 1,
- GFP_KERNEL);
+ pcaps[i].pg.attrs = kzalloc_objs(struct attribute *, j + 1);
if (!pcaps[i].pg.attrs) {
kfree(pcaps[i].pattrs);
goto out_pcaps_pattrs;
diff --git a/arch/powerpc/platforms/powernv/opal-psr.c b/arch/powerpc/platforms/powernv/opal-psr.c
index 731d8b355343..24d0a894d965 100644
--- a/arch/powerpc/platforms/powernv/opal-psr.c
+++ b/arch/powerpc/platforms/powernv/opal-psr.c
@@ -132,8 +132,7 @@ void __init opal_psr_init(void)
return;
}
- psr_attrs = kzalloc_objs(*psr_attrs, of_get_child_count(psr),
- GFP_KERNEL);
+ psr_attrs = kzalloc_objs(*psr_attrs, of_get_child_count(psr));
if (!psr_attrs)
goto out_put_psr;
diff --git a/arch/powerpc/platforms/powernv/opal-sensor-groups.c b/arch/powerpc/platforms/powernv/opal-sensor-groups.c
index 2a3474246908..87fd6d7769e9 100644
--- a/arch/powerpc/platforms/powernv/opal-sensor-groups.c
+++ b/arch/powerpc/platforms/powernv/opal-sensor-groups.c
@@ -190,13 +190,11 @@ void __init opal_sensor_groups_init(void)
if (!nr_attrs)
continue;
- sgs[i].sgattrs = kzalloc_objs(*sgs[i].sgattrs, nr_attrs,
- GFP_KERNEL);
+ sgs[i].sgattrs = kzalloc_objs(*sgs[i].sgattrs, nr_attrs);
if (!sgs[i].sgattrs)
goto out_sgs_sgattrs;
- sgs[i].sg.attrs = kzalloc_objs(*sgs[i].sg.attrs, nr_attrs + 1,
- GFP_KERNEL);
+ sgs[i].sg.attrs = kzalloc_objs(*sgs[i].sg.attrs, nr_attrs + 1);
if (!sgs[i].sg.attrs) {
kfree(sgs[i].sgattrs);
diff --git a/arch/powerpc/sysdev/mpic.c b/arch/powerpc/sysdev/mpic.c
index eba277134224..257886ec3f70 100644
--- a/arch/powerpc/sysdev/mpic.c
+++ b/arch/powerpc/sysdev/mpic.c
@@ -1639,8 +1639,7 @@ void __init mpic_init(struct mpic *mpic)
#ifdef CONFIG_PM
/* allocate memory to save mpic state */
- mpic->save_data = kmalloc_objs(*mpic->save_data, mpic->num_sources,
- GFP_KERNEL);
+ mpic->save_data = kmalloc_objs(*mpic->save_data, mpic->num_sources);
BUG_ON(mpic->save_data == NULL);
#endif
diff --git a/arch/powerpc/sysdev/mpic_msgr.c b/arch/powerpc/sysdev/mpic_msgr.c
index e9af4fa940b1..26f62ae5f671 100644
--- a/arch/powerpc/sysdev/mpic_msgr.c
+++ b/arch/powerpc/sysdev/mpic_msgr.c
@@ -188,8 +188,7 @@ static int mpic_msgr_probe(struct platform_device *dev)
dev_info(&dev->dev, "Found %d message registers\n",
mpic_msgr_count);
- mpic_msgrs = kzalloc_objs(*mpic_msgrs, mpic_msgr_count,
- GFP_KERNEL);
+ mpic_msgrs = kzalloc_objs(*mpic_msgrs, mpic_msgr_count);
if (!mpic_msgrs) {
dev_err(&dev->dev,
"No memory for message register blocks\n");
diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c
index 7e3749131c59..9c2f5e442338 100644
--- a/arch/riscv/kernel/vdso.c
+++ b/arch/riscv/kernel/vdso.c
@@ -55,8 +55,7 @@ static void __init __vdso_init(struct __vdso_info *vdso_info)
vdso_info->vdso_code_start) >>
PAGE_SHIFT;
- vdso_pagelist = kzalloc_objs(struct page *, vdso_info->vdso_pages,
- GFP_KERNEL);
+ vdso_pagelist = kzalloc_objs(struct page *, vdso_info->vdso_pages);
if (vdso_pagelist == NULL)
panic("vDSO kcalloc failed!\n");
diff --git a/arch/s390/kvm/pci.c b/arch/s390/kvm/pci.c
index fc80495027ba..86d93e8dddae 100644
--- a/arch/s390/kvm/pci.c
+++ b/arch/s390/kvm/pci.c
@@ -126,8 +126,7 @@ int kvm_s390_pci_aen_init(u8 nisc)
return -EPERM;
mutex_lock(&aift->aift_lock);
- aift->kzdev = kzalloc_objs(struct kvm_zdev *, ZPCI_NR_DEVICES,
- GFP_KERNEL);
+ aift->kzdev = kzalloc_objs(struct kvm_zdev *, ZPCI_NR_DEVICES);
if (!aift->kzdev) {
rc = -ENOMEM;
goto unlock;
diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c
index 0ae82e529c21..2a430722cbe4 100644
--- a/arch/s390/pci/pci.c
+++ b/arch/s390/pci/pci.c
@@ -1073,8 +1073,7 @@ static int zpci_mem_init(void)
if (!zdev_fmb_cache)
goto error_fmb;
- zpci_iomap_start = kzalloc_objs(*zpci_iomap_start, ZPCI_IOMAP_ENTRIES,
- GFP_KERNEL);
+ zpci_iomap_start = kzalloc_objs(*zpci_iomap_start, ZPCI_IOMAP_ENTRIES);
if (!zpci_iomap_start)
goto error_iomap;
diff --git a/arch/sh/drivers/pci/pcie-sh7786.c b/arch/sh/drivers/pci/pcie-sh7786.c
index 1e67082eb3b4..cbbb94d41fd0 100644
--- a/arch/sh/drivers/pci/pcie-sh7786.c
+++ b/arch/sh/drivers/pci/pcie-sh7786.c
@@ -558,8 +558,7 @@ static int __init sh7786_pcie_init(void)
if (unlikely(nr_ports == 0))
return -ENODEV;
- sh7786_pcie_ports = kzalloc_objs(struct sh7786_pcie_port, nr_ports,
- GFP_KERNEL);
+ sh7786_pcie_ports = kzalloc_objs(struct sh7786_pcie_port, nr_ports);
if (unlikely(!sh7786_pcie_ports))
return -ENOMEM;
diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
index 81f0be76f48a..371460e34484 100644
--- a/arch/sparc/kernel/smp_64.c
+++ b/arch/sparc/kernel/smp_64.c
@@ -297,8 +297,7 @@ static void ldom_startcpu_cpuid(unsigned int cpu, unsigned long thread_reg,
unsigned long hv_err;
int i;
- hdesc = kzalloc_flex(*hdesc, maps, num_kernel_image_mappings,
- GFP_KERNEL);
+ hdesc = kzalloc_flex(*hdesc, maps, num_kernel_image_mappings);
if (!hdesc) {
printk(KERN_ERR "ldom_startcpu_cpuid: Cannot allocate "
"hvtramp_descr.\n");
diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
index 8d5e2d5c0bc5..ecefcffcf7b1 100644
--- a/arch/sparc/kernel/sys_sparc_64.c
+++ b/arch/sparc/kernel/sys_sparc_64.c
@@ -647,8 +647,7 @@ SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
}
if (!current_thread_info()->utraps) {
current_thread_info()->utraps =
- kzalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1,
- GFP_KERNEL);
+ kzalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1);
if (!current_thread_info()->utraps)
return -ENOMEM;
current_thread_info()->utraps[0] = 1;
@@ -658,8 +657,7 @@ SYSCALL_DEFINE5(utrap_install, utrap_entry_t, type,
unsigned long *p = current_thread_info()->utraps;
current_thread_info()->utraps =
- kmalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1,
- GFP_KERNEL);
+ kmalloc_objs(long, UT_TRAP_INSTRUCTION_31 + 1);
if (!current_thread_info()->utraps) {
current_thread_info()->utraps = p;
return -ENOMEM;
diff --git a/arch/um/drivers/vector_kern.c b/arch/um/drivers/vector_kern.c
index 5434c87542e5..2cc90055499a 100644
--- a/arch/um/drivers/vector_kern.c
+++ b/arch/um/drivers/vector_kern.c
@@ -544,11 +544,9 @@ static struct vector_queue *create_queue(
result->max_iov_frags = num_extra_frags;
for (i = 0; i < max_size; i++) {
if (vp->header_size > 0)
- iov = kmalloc_objs(struct iovec, 3 + num_extra_frags,
- GFP_KERNEL);
+ iov = kmalloc_objs(struct iovec, 3 + num_extra_frags);
else
- iov = kmalloc_objs(struct iovec, 2 + num_extra_frags,
- GFP_KERNEL);
+ iov = kmalloc_objs(struct iovec, 2 + num_extra_frags);
if (iov == NULL)
goto out_fail;
mmsg_vector->msg_hdr.msg_iov = iov;
diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c
index 069e6b788280..5ed6e0b7e715 100644
--- a/arch/x86/events/intel/uncore_snbep.c
+++ b/arch/x86/events/intel/uncore_snbep.c
@@ -3753,8 +3753,7 @@ static int pmu_alloc_topology(struct intel_uncore_type *type, int topology_type)
goto err;
for (die = 0; die < uncore_max_dies(); die++) {
- topology[die] = kzalloc_objs(**topology, type->num_boxes,
- GFP_KERNEL);
+ topology[die] = kzalloc_objs(**topology, type->num_boxes);
if (!topology[die])
goto clear;
for (idx = 0; idx < type->num_boxes; idx++) {
diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index e945ed623027..323adc93f2dc 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -467,8 +467,7 @@ void __init hyperv_init(void)
if (hv_isolation_type_tdx())
hv_vp_assist_page = NULL;
else
- hv_vp_assist_page = kzalloc_objs(*hv_vp_assist_page, nr_cpu_ids,
- GFP_KERNEL);
+ hv_vp_assist_page = kzalloc_objs(*hv_vp_assist_page, nr_cpu_ids);
if (!hv_vp_assist_page) {
ms_hyperv.hints &= ~HV_X64_ENLIGHTENED_VMCS_RECOMMENDED;
diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index 852e8ff5ebd9..5d364540673d 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -68,8 +68,7 @@ static int amd_cache_northbridges(void)
amd_northbridges.num = amd_num_nodes();
- nb = kzalloc_objs(struct amd_northbridge, amd_northbridges.num,
- GFP_KERNEL);
+ nb = kzalloc_objs(struct amd_northbridge, amd_northbridges.num);
if (!nb)
return -ENOMEM;
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 1021a4e33ac6..38b7fd2f63be 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -798,8 +798,7 @@ static bool __init sgx_page_cache_init(void)
int nid;
int i;
- sgx_numa_nodes = kmalloc_objs(*sgx_numa_nodes, num_possible_nodes(),
- GFP_KERNEL);
+ sgx_numa_nodes = kmalloc_objs(*sgx_numa_nodes, num_possible_nodes());
if (!sgx_numa_nodes)
return false;
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index c196aa0c1bd1..d2486506a808 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1991,8 +1991,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (sanity_check_entries(entries, cpuid->nent, type))
return -EINVAL;
- array.entries = kvzalloc_objs(struct kvm_cpuid_entry2, cpuid->nent,
- GFP_KERNEL);
+ array.entries = kvzalloc_objs(struct kvm_cpuid_entry2, cpuid->nent);
if (!array.entries)
return -ENOMEM;
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 8517d5fbf79c..d22cabe119b1 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -2218,8 +2218,7 @@ static int tdx_get_capabilities(struct kvm_tdx_cmd *cmd)
if (nr_user_entries < td_conf->num_cpuid_config)
return -E2BIG;
- caps = kzalloc_flex(*caps, cpuid.entries, td_conf->num_cpuid_config,
- GFP_KERNEL);
+ caps = kzalloc_flex(*caps, cpuid.entries, td_conf->num_cpuid_config);
if (!caps)
return -ENOMEM;
diff --git a/block/blk-crypto-fallback.c b/block/blk-crypto-fallback.c
index 9a05abe8d43f..24b8b1c40e25 100644
--- a/block/blk-crypto-fallback.c
+++ b/block/blk-crypto-fallback.c
@@ -546,8 +546,7 @@ static int blk_crypto_fallback_init(void)
goto out;
/* Dynamic allocation is needed because of lockdep_register_key(). */
- blk_crypto_fallback_profile = kzalloc_obj(*blk_crypto_fallback_profile,
- GFP_KERNEL);
+ blk_crypto_fallback_profile = kzalloc_obj(*blk_crypto_fallback_profile);
if (!blk_crypto_fallback_profile) {
err = -ENOMEM;
goto fail_free_bioset;
diff --git a/block/blk-crypto-profile.c b/block/blk-crypto-profile.c
index 970880d9adf4..4ac74443687a 100644
--- a/block/blk-crypto-profile.c
+++ b/block/blk-crypto-profile.c
@@ -120,8 +120,7 @@ int blk_crypto_profile_init(struct blk_crypto_profile *profile,
profile->log_slot_ht_size = ilog2(slot_hashtable_size);
profile->slot_hashtable =
- kvmalloc_objs(profile->slot_hashtable[0], slot_hashtable_size,
- GFP_KERNEL);
+ kvmalloc_objs(profile->slot_hashtable[0], slot_hashtable_size);
if (!profile->slot_hashtable)
goto err_destroy;
for (i = 0; i < slot_hashtable_size; i++)
diff --git a/drivers/accel/amdxdna/amdxdna_gem.c b/drivers/accel/amdxdna/amdxdna_gem.c
index a561674bac97..8c290ddd3251 100644
--- a/drivers/accel/amdxdna/amdxdna_gem.c
+++ b/drivers/accel/amdxdna/amdxdna_gem.c
@@ -210,8 +210,7 @@ static int amdxdna_hmm_register(struct amdxdna_gem_obj *abo,
return -ENOMEM;
nr_pages = (PAGE_ALIGN(addr + len) - (addr & PAGE_MASK)) >> PAGE_SHIFT;
- mapp->range.hmm_pfns = kvzalloc_objs(*mapp->range.hmm_pfns, nr_pages,
- GFP_KERNEL);
+ mapp->range.hmm_pfns = kvzalloc_objs(*mapp->range.hmm_pfns, nr_pages);
if (!mapp->range.hmm_pfns) {
ret = -ENOMEM;
goto free_map;
diff --git a/drivers/accel/ethosu/ethosu_drv.c b/drivers/accel/ethosu/ethosu_drv.c
index ae5e6b15e7de..9992193d7338 100644
--- a/drivers/accel/ethosu/ethosu_drv.c
+++ b/drivers/accel/ethosu/ethosu_drv.c
@@ -144,8 +144,7 @@ static int ethosu_open(struct drm_device *ddev, struct drm_file *file)
if (!try_module_get(THIS_MODULE))
return -EINVAL;
- struct ethosu_file_priv __free(kfree) *priv = kzalloc_obj(*priv,
- GFP_KERNEL);
+ struct ethosu_file_priv __free(kfree) *priv = kzalloc_obj(*priv);
if (!priv) {
ret = -ENOMEM;
goto err_put_mod;
diff --git a/drivers/accel/ethosu/ethosu_gem.c b/drivers/accel/ethosu/ethosu_gem.c
index cbd74e3adb9f..4fbd4bbf2909 100644
--- a/drivers/accel/ethosu/ethosu_gem.c
+++ b/drivers/accel/ethosu/ethosu_gem.c
@@ -352,8 +352,7 @@ static int ethosu_gem_cmdstream_copy_and_validate(struct drm_device *ddev,
struct ethosu_gem_object *bo,
u32 size)
{
- struct ethosu_validated_cmdstream_info __free(kfree) *info = kzalloc_obj(*info,
- GFP_KERNEL);
+ struct ethosu_validated_cmdstream_info __free(kfree) *info = kzalloc_obj(*info);
struct ethosu_device *edev = to_ethosu_device(ddev);
u32 *bocmds = bo->base.vaddr;
struct cmd_state st;
diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c
index 6c896eb816de..ba4257bda77b 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -1422,8 +1422,7 @@ static int hl_cs_copy_chunk_array(struct hl_device *hdev,
*cs_chunk_array = kmalloc_objs(**cs_chunk_array, num_chunks, GFP_ATOMIC);
if (!*cs_chunk_array)
- *cs_chunk_array = kmalloc_objs(**cs_chunk_array, num_chunks,
- GFP_KERNEL);
+ *cs_chunk_array = kmalloc_objs(**cs_chunk_array, num_chunks);
if (!*cs_chunk_array) {
atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
atomic64_inc(&hdev->aggregated_cs_counters.out_of_mem_drop_cnt);
diff --git a/drivers/accel/habanalabs/common/debugfs.c b/drivers/accel/habanalabs/common/debugfs.c
index 05b1cc7918c5..1d5e29fc6463 100644
--- a/drivers/accel/habanalabs/common/debugfs.c
+++ b/drivers/accel/habanalabs/common/debugfs.c
@@ -2052,8 +2052,7 @@ int hl_debugfs_device_init(struct hl_device *hdev)
int count = ARRAY_SIZE(hl_debugfs_list);
dev_entry->hdev = hdev;
- dev_entry->entry_arr = kmalloc_objs(struct hl_debugfs_entry, count,
- GFP_KERNEL);
+ dev_entry->entry_arr = kmalloc_objs(struct hl_debugfs_entry, count);
if (!dev_entry->entry_arr)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/common/hw_queue.c b/drivers/accel/habanalabs/common/hw_queue.c
index d499063a79ec..f0ab99dd74d6 100644
--- a/drivers/accel/habanalabs/common/hw_queue.c
+++ b/drivers/accel/habanalabs/common/hw_queue.c
@@ -837,8 +837,7 @@ static int ext_and_cpu_queue_init(struct hl_device *hdev, struct hl_hw_queue *q,
q->kernel_address = p;
- q->shadow_queue = kmalloc_objs(struct hl_cs_job *, HL_QUEUE_LENGTH,
- GFP_KERNEL);
+ q->shadow_queue = kmalloc_objs(struct hl_cs_job *, HL_QUEUE_LENGTH);
if (!q->shadow_queue) {
dev_err(hdev->dev,
"Failed to allocate shadow queue for H/W queue %d\n",
diff --git a/drivers/accel/habanalabs/common/mmu/mmu.c b/drivers/accel/habanalabs/common/mmu/mmu.c
index 1f8f7cf2d3fb..6c7c4ff8a8a9 100644
--- a/drivers/accel/habanalabs/common/mmu/mmu.c
+++ b/drivers/accel/habanalabs/common/mmu/mmu.c
@@ -843,8 +843,7 @@ int hl_mmu_hr_init(struct hl_device *hdev, struct hl_mmu_hr_priv *hr_priv, u32 h
return -ENOMEM;
}
- hr_priv->mmu_asid_hop0 = kvzalloc_objs(struct pgt_info, prop->max_asid,
- GFP_KERNEL);
+ hr_priv->mmu_asid_hop0 = kvzalloc_objs(struct pgt_info, prop->max_asid);
if (ZERO_OR_NULL_PTR(hr_priv->mmu_asid_hop0)) {
dev_err(hdev->dev, "Failed to allocate hr-mmu hop0 table\n");
rc = -ENOMEM;
diff --git a/drivers/accel/habanalabs/common/security.c b/drivers/accel/habanalabs/common/security.c
index 8a0da0194cab..abe5ed0d405a 100644
--- a/drivers/accel/habanalabs/common/security.c
+++ b/drivers/accel/habanalabs/common/security.c
@@ -312,8 +312,7 @@ int hl_init_pb_with_mask(struct hl_device *hdev, u32 num_dcores,
int i, j;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
@@ -392,8 +391,7 @@ int hl_init_pb_ranges_with_mask(struct hl_device *hdev, u32 num_dcores,
int i, j, rc = 0;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
@@ -474,8 +472,7 @@ int hl_init_pb_single_dcore(struct hl_device *hdev, u32 dcore_offset,
int i, rc = 0;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
@@ -521,8 +518,7 @@ int hl_init_pb_ranges_single_dcore(struct hl_device *hdev, u32 dcore_offset,
int i;
struct hl_block_glbl_sec *glbl_sec;
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, blocks_array_size);
if (!glbl_sec)
return -ENOMEM;
diff --git a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c
index f4f8f9122f5c..ea3a0e57c836 100644
--- a/drivers/accel/habanalabs/gaudi2/gaudi2_security.c
+++ b/drivers/accel/habanalabs/gaudi2/gaudi2_security.c
@@ -2620,8 +2620,7 @@ static int gaudi2_init_pb_tpc(struct hl_device *hdev)
block_array_size = ARRAY_SIZE(gaudi2_pb_dcr0_tpc0);
- glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, block_array_size,
- GFP_KERNEL);
+ glbl_sec = kzalloc_objs(struct hl_block_glbl_sec, block_array_size);
if (!glbl_sec)
return -ENOMEM;
diff --git a/drivers/accel/qaic/qaic_ssr.c b/drivers/accel/qaic/qaic_ssr.c
index e3daeaad057d..a5bb6078824b 100644
--- a/drivers/accel/qaic/qaic_ssr.c
+++ b/drivers/accel/qaic/qaic_ssr.c
@@ -457,8 +457,7 @@ static struct ssr_dump_info *alloc_dump_info(struct qaic_device *qdev,
}
/* Buffer used to send MEMORY READ request to device via MHI */
- dump_info->read_buf_req = kzalloc_obj(*dump_info->read_buf_req,
- GFP_KERNEL);
+ dump_info->read_buf_req = kzalloc_obj(*dump_info->read_buf_req);
if (!dump_info->read_buf_req) {
ret = -ENOMEM;
goto free_dump_info;
diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
index 751697899a98..a9248af078f6 100644
--- a/drivers/acpi/apei/einj-core.c
+++ b/drivers/acpi/apei/einj-core.c
@@ -1021,8 +1021,7 @@ static bool setup_einjv2_component_files(void)
{
char name[32];
- syndrome_data = kzalloc_objs(syndrome_data[0], max_nr_components,
- GFP_KERNEL);
+ syndrome_data = kzalloc_objs(syndrome_data[0], max_nr_components);
if (!syndrome_data)
return false;
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 5c2116171789..f0e513e9ed5d 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -636,8 +636,7 @@ static int pcc_data_alloc(int pcc_ss_id)
if (pcc_data[pcc_ss_id]) {
pcc_data[pcc_ss_id]->refcount++;
} else {
- pcc_data[pcc_ss_id] = kzalloc_obj(struct cppc_pcc_data,
- GFP_KERNEL);
+ pcc_data[pcc_ss_id] = kzalloc_obj(struct cppc_pcc_data);
if (!pcc_data[pcc_ss_id])
return -ENOMEM;
pcc_data[pcc_ss_id]->refcount++;
diff --git a/drivers/acpi/mipi-disco-img.c b/drivers/acpi/mipi-disco-img.c
index 328093ed7136..ea4bffe3c02d 100644
--- a/drivers/acpi/mipi-disco-img.c
+++ b/drivers/acpi/mipi-disco-img.c
@@ -91,8 +91,7 @@ static acpi_status parse_csi2_resource(struct acpi_resource *res, void *context)
return AE_OK;
}
- conn = kmalloc_flex(*conn, remote_name, csi2_res_src_length + 1,
- GFP_KERNEL);
+ conn = kmalloc_flex(*conn, remote_name, csi2_res_src_length + 1);
if (!conn)
return AE_OK;
diff --git a/drivers/acpi/platform_profile.c b/drivers/acpi/platform_profile.c
index bd4d332520bb..79d2e92e5c28 100644
--- a/drivers/acpi/platform_profile.c
+++ b/drivers/acpi/platform_profile.c
@@ -560,8 +560,7 @@ struct device *platform_profile_register(struct device *dev, const char *name,
!ops->profile_set || !ops->probe))
return ERR_PTR(-EINVAL);
- struct platform_profile_handler *pprof __free(kfree) = kzalloc_obj(*pprof,
- GFP_KERNEL);
+ struct platform_profile_handler *pprof __free(kfree) = kzalloc_obj(*pprof);
if (!pprof)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c
index f1c7c2ad5094..fdf55c285c9a 100644
--- a/drivers/acpi/processor_perflib.c
+++ b/drivers/acpi/processor_perflib.c
@@ -341,8 +341,7 @@ static int acpi_processor_get_performance_states(struct acpi_processor *pr)
pr->performance->state_count = pss->package.count;
pr->performance->states =
- kmalloc_objs(struct acpi_processor_px, pss->package.count,
- GFP_KERNEL);
+ kmalloc_objs(struct acpi_processor_px, pss->package.count);
if (!pr->performance->states) {
result = -ENOMEM;
goto end;
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c
index 2d398ae5c662..c0f92b93747d 100644
--- a/drivers/acpi/processor_throttling.c
+++ b/drivers/acpi/processor_throttling.c
@@ -512,8 +512,7 @@ static int acpi_processor_get_throttling_states(struct acpi_processor *pr)
pr->throttling.state_count = tss->package.count;
pr->throttling.states_tss =
- kmalloc_objs(struct acpi_processor_tx_tss, tss->package.count,
- GFP_KERNEL);
+ kmalloc_objs(struct acpi_processor_tx_tss, tss->package.count);
if (!pr->throttling.states_tss) {
result = -ENOMEM;
goto end;
diff --git a/drivers/acpi/riscv/irq.c b/drivers/acpi/riscv/irq.c
index c1f759fb5758..afffde4cfe7a 100644
--- a/drivers/acpi/riscv/irq.c
+++ b/drivers/acpi/riscv/irq.c
@@ -384,8 +384,7 @@ static u32 riscv_acpi_add_irq_dep(acpi_handle handle)
riscv_acpi_irq_get_dep(handle, i, &gsi_handle);
i++) {
dep_devices.count = 1;
- dep_devices.handles = kzalloc_objs(*dep_devices.handles, 1,
- GFP_KERNEL);
+ dep_devices.handles = kzalloc_objs(*dep_devices.handles, 1);
if (!dep_devices.handles) {
acpi_handle_err(handle, "failed to allocate memory\n");
continue;
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index a6f453d4785b..dfdd004fb1a9 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -757,8 +757,7 @@ int acpi_device_add(struct acpi_device *device)
if (result)
goto err_unlock;
} else {
- acpi_device_bus_id = kzalloc_obj(*acpi_device_bus_id,
- GFP_KERNEL);
+ acpi_device_bus_id = kzalloc_obj(*acpi_device_bus_id);
if (!acpi_device_bus_id) {
result = -ENOMEM;
goto err_unlock;
diff --git a/drivers/ata/libahci_platform.c b/drivers/ata/libahci_platform.c
index 12c3a0330f67..f37247e7a5cb 100644
--- a/drivers/ata/libahci_platform.c
+++ b/drivers/ata/libahci_platform.c
@@ -594,8 +594,7 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev,
* We cannot use devm_ here, since ahci_platform_put_resources() uses
* target_pwrs after devm_ have freed memory
*/
- hpriv->target_pwrs = kzalloc_objs(*hpriv->target_pwrs, hpriv->nports,
- GFP_KERNEL);
+ hpriv->target_pwrs = kzalloc_objs(*hpriv->target_pwrs, hpriv->nports);
if (!hpriv->target_pwrs) {
rc = -ENOMEM;
goto err_out;
diff --git a/drivers/atm/he.c b/drivers/atm/he.c
index 8108ef0c089a..bb9cb00f9585 100644
--- a/drivers/atm/he.c
+++ b/drivers/atm/he.c
@@ -786,8 +786,7 @@ static int he_init_group(struct he_dev *he_dev, int group)
}
/* rbpl_virt 64-bit pointers */
- he_dev->rbpl_virt = kmalloc_objs(*he_dev->rbpl_virt, RBPL_TABLE_SIZE,
- GFP_KERNEL);
+ he_dev->rbpl_virt = kmalloc_objs(*he_dev->rbpl_virt, RBPL_TABLE_SIZE);
if (!he_dev->rbpl_virt) {
hprintk("unable to allocate rbpl virt table\n");
goto out_free_rbpl_table;
diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
index b90761dcd87f..0d38e93772c2 100644
--- a/drivers/atm/iphase.c
+++ b/drivers/atm/iphase.c
@@ -1978,8 +1978,7 @@ static int tx_init(struct atm_dev *dev)
buf_desc_ptr++;
tx_pkt_start += iadev->tx_buf_sz;
}
- iadev->tx_buf = kmalloc_objs(*iadev->tx_buf, iadev->num_tx_desc,
- GFP_KERNEL);
+ iadev->tx_buf = kmalloc_objs(*iadev->tx_buf, iadev->num_tx_desc);
if (!iadev->tx_buf) {
printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
goto err_free_dle;
@@ -1999,8 +1998,7 @@ static int tx_init(struct atm_dev *dev)
sizeof(*cpcs),
DMA_TO_DEVICE);
}
- iadev->desc_tbl = kmalloc_objs(*iadev->desc_tbl, iadev->num_tx_desc,
- GFP_KERNEL);
+ iadev->desc_tbl = kmalloc_objs(*iadev->desc_tbl, iadev->num_tx_desc);
if (!iadev->desc_tbl) {
printk(KERN_ERR DEV_LABEL " couldn't get mem\n");
goto err_free_all_tx_bufs;
@@ -2128,8 +2126,7 @@ static int tx_init(struct atm_dev *dev)
memset((caddr_t)(iadev->seg_ram+i), 0, iadev->num_vc*4);
vc = (struct main_vc *)iadev->MAIN_VC_TABLE_ADDR;
evc = (struct ext_vc *)iadev->EXT_VC_TABLE_ADDR;
- iadev->testTable = kmalloc_objs(*iadev->testTable, iadev->num_vc,
- GFP_KERNEL);
+ iadev->testTable = kmalloc_objs(*iadev->testTable, iadev->num_vc);
if (!iadev->testTable) {
printk("Get freepage failed\n");
goto err_free_desc_tbl;
@@ -2138,8 +2135,7 @@ static int tx_init(struct atm_dev *dev)
{
memset((caddr_t)vc, 0, sizeof(*vc));
memset((caddr_t)evc, 0, sizeof(*evc));
- iadev->testTable[i] = kmalloc_obj(struct testTable_t,
- GFP_KERNEL);
+ iadev->testTable[i] = kmalloc_obj(struct testTable_t);
if (!iadev->testTable[i])
goto err_free_test_tables;
iadev->testTable[i]->lastTime = 0;
diff --git a/drivers/base/physical_location.c b/drivers/base/physical_location.c
index 06a2797e0213..2e723fff6e8a 100644
--- a/drivers/base/physical_location.c
+++ b/drivers/base/physical_location.c
@@ -21,8 +21,7 @@ bool dev_add_physical_location(struct device *dev)
if (!acpi_get_physical_device_location(ACPI_HANDLE(dev), &pld))
return false;
- dev->physical_location = kzalloc_obj(*dev->physical_location,
- GFP_KERNEL);
+ dev->physical_location = kzalloc_obj(*dev->physical_location);
if (!dev->physical_location) {
ACPI_FREE(pld);
return false;
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index c2dd784bc14b..3cfef456a1f3 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -3932,8 +3932,7 @@ static int receive_sizes(struct drbd_connection *connection, struct packet_info
if (my_usize != p_usize) {
struct disk_conf *old_disk_conf, *new_disk_conf = NULL;
- new_disk_conf = kzalloc_obj(struct disk_conf,
- GFP_KERNEL);
+ new_disk_conf = kzalloc_obj(struct disk_conf);
if (!new_disk_conf) {
put_ldev(device);
return -ENOMEM;
diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index 7844424f7b17..41cc8cefea01 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -401,8 +401,7 @@ static int ps3vram_cache_init(struct ps3_system_bus_device *dev)
priv->cache.page_count = CACHE_PAGE_COUNT;
priv->cache.page_size = CACHE_PAGE_SIZE;
- priv->cache.tags = kzalloc_objs(struct ps3vram_tag, CACHE_PAGE_COUNT,
- GFP_KERNEL);
+ priv->cache.tags = kzalloc_objs(struct ps3vram_tag, CACHE_PAGE_COUNT);
if (!priv->cache.tags)
return -ENOMEM;
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index bc665b8abd7b..7871099bc0d4 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -846,8 +846,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,
* We are using persistent grants, the grant is
* not mapped but we might have room for it.
*/
- persistent_gnt = kmalloc_obj(struct persistent_gnt,
- GFP_KERNEL);
+ persistent_gnt = kmalloc_obj(struct persistent_gnt);
if (!persistent_gnt) {
/*
* If we don't have enough memory to
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index adfd61af86ee..4b865ef800b1 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -131,8 +131,7 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)
{
unsigned int r;
- blkif->rings = kzalloc_objs(struct xen_blkif_ring, blkif->nr_rings,
- GFP_KERNEL);
+ blkif->rings = kzalloc_objs(struct xen_blkif_ring, blkif->nr_rings);
if (!blkif->rings)
return -ENOMEM;
@@ -1014,14 +1013,12 @@ static int read_per_ring_refs(struct xen_blkif_ring *ring, const char *dir)
goto fail;
list_add_tail(&req->free_list, &ring->pending_free);
for (j = 0; j < MAX_INDIRECT_SEGMENTS; j++) {
- req->segments[j] = kzalloc_obj(*req->segments[0],
- GFP_KERNEL);
+ req->segments[j] = kzalloc_obj(*req->segments[0]);
if (!req->segments[j])
goto fail;
}
for (j = 0; j < MAX_INDIRECT_PAGES; j++) {
- req->indirect_pages[j] = kzalloc_obj(*req->indirect_pages[0],
- GFP_KERNEL);
+ req->indirect_pages[j] = kzalloc_obj(*req->indirect_pages[0]);
if (!req->indirect_pages[j])
goto fail;
}
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 777a5ae0cd33..8fc7fc3bf867 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -2207,8 +2207,7 @@ static int blkfront_setup_indirect(struct blkfront_ring_info *rinfo)
for (i = 0; i < BLK_RING_SIZE(info); i++) {
rinfo->shadow[i].grants_used =
- kvzalloc_objs(rinfo->shadow[i].grants_used[0], grants,
- GFP_KERNEL);
+ kvzalloc_objs(rinfo->shadow[i].grants_used[0], grants);
rinfo->shadow[i].sg = kvzalloc_objs(rinfo->shadow[i].sg[0],
psegs, GFP_KERNEL);
if (info->max_indirect_segments)
diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c
index e12abdec2647..b216cba1c3bf 100644
--- a/drivers/block/z2ram.c
+++ b/drivers/block/z2ram.c
@@ -187,8 +187,7 @@ static int z2_open(struct gendisk *disk, blk_mode_t mode)
(unsigned long)z_remap_nocache_nonser(paddr, size);
#endif
z2ram_map =
- kmalloc_objs(z2ram_map[0], size / Z2RAM_CHUNKSIZE,
- GFP_KERNEL);
+ kmalloc_objs(z2ram_map[0], size / Z2RAM_CHUNKSIZE);
if (z2ram_map == NULL) {
printk(KERN_ERR DEVICE_NAME
": cannot get mem for z2ram_map\n");
diff --git a/drivers/bus/mhi/ep/main.c b/drivers/bus/mhi/ep/main.c
index a27261914bd1..879b8b706428 100644
--- a/drivers/bus/mhi/ep/main.c
+++ b/drivers/bus/mhi/ep/main.c
@@ -1459,8 +1459,7 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
if (ret)
return ret;
- mhi_cntrl->mhi_cmd = kzalloc_objs(*mhi_cntrl->mhi_cmd, NR_OF_CMD_RINGS,
- GFP_KERNEL);
+ mhi_cntrl->mhi_cmd = kzalloc_objs(*mhi_cntrl->mhi_cmd, NR_OF_CMD_RINGS);
if (!mhi_cntrl->mhi_cmd) {
ret = -ENOMEM;
goto err_free_ch;
diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
index 7845fc7fe6c2..f16a1e67a667 100644
--- a/drivers/bus/mhi/host/boot.c
+++ b/drivers/bus/mhi/host/boot.c
@@ -380,8 +380,7 @@ int mhi_alloc_bhie_table(struct mhi_controller *mhi_cntrl,
return -ENOMEM;
/* Allocate memory for entries */
- img_info->mhi_buf = kzalloc_objs(*img_info->mhi_buf, segments,
- GFP_KERNEL);
[Output truncated: showing 1000 of 15164 lines]]
|
| 401/2 |
2026/10/14 00:20 |
tool |
git-show |
0m
Args: map[Commit:f37d63e219c39]
Results: map[Output:commit f37d63e219c39199a59b8b8a211412ff27192830
Author: Philipp Stanner <pstanner@redhat.com>
Date: Wed Sep 20 14:36:12 2023 +0200
drm_lease.c: copy user-array safely
Currently, there is no overflow-check with memdup_user().
Use the new function memdup_array_user() instead of memdup_user() for
duplicating the user-space array safely.
Suggested-by: David Airlie <airlied@redhat.com>
Signed-off-by: Philipp Stanner <pstanner@redhat.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Zack Rusin <zackr@vmware.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230920123612.16914-6-pstanner@redhat.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 150fe1555068..94375c6a5425 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -510,8 +510,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
- array_size(object_count, sizeof(__u32)));
+ object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
]
|
| 402/2 |
2026/10/14 00:20 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 30207
output: 27
thoughts: 83
Thoughts: Okay, let's dive into this. Here's my thought process on this task:
**Analyzing Recent Commits: A Focused Review**
Alright, my immediate thought is to zero in on the relevant commits. I've got to investigate the changes associated with those IDs. Specifically, I'm going to start with the commit labeled "drm: Add lease support [v8]" β that's 62884cd386b87. Lease support in DRM is a significant feature, so it warrants a close look to understand the implementation details. I also need to understand commit 4bb2d367a5a28 and how it relates to this. I'm going to review the changes introduced in each of those commits, paying close attention to any dependencies, potential conflicts, and, of course, the overall architectural impact.
|
| 403/2 |
2026/10/14 00:20 |
tool |
git-show |
0m
Args: map[Commit:4bb2d367a5a28]
Results: map[Output:commit 4bb2d367a5a2807185a04949ae922d247f650576
Author: Simon Ser <contact@emersion.fr>
Date: Fri Sep 3 13:00:32 2021 +0000
drm/lease: allow empty leases
This can be used to create a separate DRM file description, thus
creating a new GEM handle namespace.
My use-case is wlroots. The library splits responsibilities between
separate components: the GBM allocator creates buffers, the GLES2
renderer uses EGL to import them and render to them, the DRM
backend imports the buffers and displays them. wlroots has a
modular architecture, and any of these components can be swapped
and replaced with something else. For instance, the pipeline can
be set up so that the DRM dumb buffer allocator is used instead of
GBM and the Pixman renderer is used instead of GLES2. Library users
can also replace any of these components with their own custom one.
DMA-BUFs are used to pass buffer references across components. We
could use GEM handles instead, but this would result in pain if
multiple GPUs are in use: wlroots copies buffers across GPUs as
needed. Importing a GEM handle created on one GPU into a completely
different GPU will blow up (fail at best, mix unrelated buffers
otherwise).
Everything is fine if all components use Mesa. However, this isn't
always desirable. For instance when running with DRM dumb buffers
and the Pixman software renderer it's unfortunate to depend on GBM
in the DRM backend just to turn DMA-BUFs into FB IDs. GBM loads
Mesa drivers to perform an action which has nothing driver-specific.
Additionally, drivers will fail the import if the 3D engine can't
use the imported buffer, for instance amdgpu will refuse to import
DRM dumb buffers [1]. We might also want to be running with a Vulkan
renderer and a Vulkan allocator in the future, and GBM wouldn't be
welcome in this setup.
To address this, GBM can be side-stepped in the DRM backend, and
can be replaced with drmPrimeFDToHandle calls. However because of
GEM handle reference counting issues, care must be taken to avoid
double-closing the same GEM handle. In particular, it's not
possible to share a DRM FD with GBM or EGL and perform some
drmPrimeFDToHandle calls manually.
So wlroots needs to re-open the DRM FD to create a new GEM handle
namespace. However there's no guarantee that the file-system
permissions will be set up so that the primary FD can be opened
by the compsoitor. On modern systems seatd or logind is a privileged
process responsible for doing this, and other processes aren't
expected to do it. For historical reasons systemd still allows
physically logged in users to open primary DRM nodes, but this
doesn't work on non-systemd setups and it's desirable to lock
them down at some point.
Some might suggest to open the render node instead of re-opening
the primary node. However some systems don't have a render node
at all (e.g. no GPU, or a split render/display SoC).
Solutions to this issue have been discussed in [2]. One solution
would be to open the magic /proc/self/fd/<fd> file, but it's a
Linux-specific hack (wlroots supports BSDs too). Another solution
is to add support for re-opening a DRM primary node to seatd/logind,
but they don't support it now and really haven't been designed for
this (logind would need to grow a completely new API, because it
assumes unique dev_t IDs). Also this seems like pushing down a
kernel limitation to user-space a bit too hard.
Another solution is to allow creating empty DRM leases. The lessee
FD would have its own GEM handle namespace, so wouldn't conflict
wth GBM/EGL. It would have the master bit set, but would be able
to manage zero resources. wlroots doesn't intend to share this FD
with any other process.
All in all IMHO that seems like a pretty reasonable solution to the
issue at hand.
Note, I've discussed with Jonas Γ
dahl and Mutter plans to adopt a
similar design in the future.
Example usage in wlroots is available at [3]. IGT test available
at [4].
[1]: https://github.com/swaywm/wlroots/issues/2916
[2]: https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/110
[3]: https://github.com/swaywm/wlroots/pull/3158
[4]: https://patchwork.freedesktop.org/series/94323/
Signed-off-by: Simon Ser <contact@emersion.fr>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Daniel Stone <daniels@collabora.com>
Cc: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Cc: Michel DΓ€nzer <michel@daenzer.net>
Cc: Emil Velikov <emil.l.velikov@gmail.com>
Cc: Keith Packard <keithp@keithp.com>
Cc: Boris Brezillon <boris.brezillon@collabora.com>
Cc: Dave Airlie <airlied@redhat.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210903130000.1590-2-contact@emersion.fr
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index dee4f24a1808..d72c2fac0ff1 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -489,12 +489,6 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
if (!drm_core_check_feature(dev, DRIVER_MODESET))
return -EOPNOTSUPP;
- /* need some objects */
- if (cl->object_count == 0) {
- DRM_DEBUG_LEASE("no objects in lease\n");
- return -EINVAL;
- }
-
if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
DRM_DEBUG_LEASE("invalid flags\n");
return -EINVAL;
@@ -510,23 +504,26 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
object_count = cl->object_count;
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
- array_size(object_count, sizeof(__u32)));
- if (IS_ERR(object_ids)) {
- ret = PTR_ERR(object_ids);
- goto out_lessor;
- }
-
+ /* Handle leased objects, if any */
idr_init(&leases);
+ if (object_count != 0) {
+ object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
+ array_size(object_count, sizeof(__u32)));
+ if (IS_ERR(object_ids)) {
+ ret = PTR_ERR(object_ids);
+ idr_destroy(&leases);
+ goto out_lessor;
+ }
- /* fill and validate the object idr */
- ret = fill_object_idr(dev, lessor_priv, &leases,
- object_count, object_ids);
- kfree(object_ids);
- if (ret) {
- DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret);
- idr_destroy(&leases);
- goto out_lessor;
+ /* fill and validate the object idr */
+ ret = fill_object_idr(dev, lessor_priv, &leases,
+ object_count, object_ids);
+ kfree(object_ids);
+ if (ret) {
+ DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret);
+ idr_destroy(&leases);
+ goto out_lessor;
+ }
}
/* Allocate a file descriptor for the lease */
diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h
index e4a2570a6058..e1e351682872 100644
--- a/include/uapi/drm/drm_mode.h
+++ b/include/uapi/drm/drm_mode.h
@@ -1112,7 +1112,8 @@ struct drm_mode_destroy_blob {
* Lease mode resources, creating another drm_master.
*
* The @object_ids array must reference at least one CRTC, one connector and
- * one plane if &DRM_CLIENT_CAP_UNIVERSAL_PLANES is enabled.
+ * one plane if &DRM_CLIENT_CAP_UNIVERSAL_PLANES is enabled. Alternatively,
+ * the lease can be completely empty.
*/
struct drm_mode_create_lease {
/** @object_ids: Pointer to array of object ids (__u32) */
]
|
| 404/2 |
2026/10/14 00:20 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 32965
output: 31
thoughts: 19
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and rendered in the first person:
**Analyzing Commit 62884cd386b87**
Alright, time to dive in. My immediate thought is to examine commit `62884cd386b87`. The naming convention looks familiar, I probably have a good idea of which repository this is from. I'm going to start by quickly pulling up the diff. I'll need to assess the scope of this change β single file modification, or a broader refactor? Are there dependencies I need to consider? Does the commit message provide enough context, or will I need to reconstruct the purpose from the code itself? Are there related issues or pull requests linked to the commit, which might provide useful context?
I'll be looking for potential regressions, performance impacts, and adherence to established coding standards. Are there any obvious code smells? Does it introduce any security vulnerabilities, or, critically, expose any vulnerabilities that were previously hidden? I'll probably run some of the tests while I'm at it, or, ideally, they were executed as part of the pipeline. I'm going to pay close attention to the nature of the changes. Are they adding new functionality, fixing a bug, optimizing existing code, or simply performing a refactor? And importantly, does this code fit within the established architecture of the project? What assumptions were made when this code was written? Are those assumptions still valid? I'll be particularly focused on any edge cases or unexpected behaviors.
|
| 405/2 |
2026/10/14 00:20 |
tool |
git-show |
0m
Args: map[Commit:62884cd386b87 Stat:true]
Results: map[Output:commit 62884cd386b876638720ef88374b31a84ca7ee5f
Author: Keith Packard <keithp@keithp.com>
Date: Thu Mar 16 17:56:28 2017 -0700
drm: Add four ioctls for managing drm mode object leases [v7]
drm_mode_create_lease
Creates a lease for a list of drm mode objects, returning an
fd for the new drm_master and a 64-bit identifier for the lessee
drm_mode_list_lesees
List the identifiers of the lessees for a master file
drm_mode_get_lease
List the leased objects for a master file
drm_mode_revoke_lease
Erase the set of objects managed by a lease.
This should suffice to at least create and query leases.
Changes for v2 as suggested by Daniel Vetter <daniel.vetter@ffwll.ch>:
* query ioctls only query the master associated with
the provided file.
* 'mask_lease' value has been removed
* change ioctl has been removed.
Changes for v3 suggested in part by Dave Airlie <airlied@gmail.com>
* Add revoke ioctl.
Changes for v4 suggested by Dave Airlie <airlied@gmail.com>
* Expand on the comment about the magic use of &drm_lease_idr_object
* Pad lease ioctl structures to align on 64-bit boundaries
Changes for v5 suggested by Dave Airlie <airlied@gmail.com>
* Check for non-negative object_id in create_lease to avoid debug
output from the kernel.
Changes for v6 provided by Dave Airlie <airlied@gmail.com>
* For non-universal planes add primary/cursor planes to lease
If we aren't exposing universal planes to this userspace client,
and it requests a lease on a crtc, we should implicitly export the
primary and cursor planes for the crtc.
If the lessee doesn't request universal planes, it will just see
the crtc, but if it does request them it will then see the plane
objects as well.
This also moves the object look ups earlier as a side effect, so
we'd exit the ioctl quicker for non-existant objects.
* Restrict leases to crtc/connector/planes.
This only allows leasing for objects we wish to allow.
Changes for v7 provided by Dave Airlie <airlied@gmail.com>
* Check pad args are 0
* Check create flags and object count are valid.
* Check return from fd allocation
* Refactor lease idr setup and add some simple validation
* Use idr_mutex uniformly (Keith)
Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/drm_ioctl.c | 4 +
drivers/gpu/drm/drm_lease.c | 412 ++++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/drm_mode_object.c | 5 +-
include/drm/drm_lease.h | 12 ++
include/drm/drm_mode_object.h | 2 +
include/uapi/drm/drm.h | 5 +
include/uapi/drm/drm_mode.h | 66 ++++++
7 files changed, 504 insertions(+), 2 deletions(-)
]
|
| 406/2 |
2026/10/14 00:20 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 34271
output: 43
thoughts: 49
Thoughts: Here's my take on those thoughts, tailored for an expert audience:
**Diving into `drm_lease.c` β Specifically `fill_object_idr` and `drm_mode_create_lease_ioctl`**
Alright, let's dissect what's happening around `62884cd386b87` in `drm_lease.c`. I need to refresh my memory on the interactions of `fill_object_idr` and `drm_mode_create_lease_ioctl`, and how this commit might have touched them. We're obviously looking at lease management within the DRM framework. Specifically, I need to understand how the object IDR is being populated and managed in the context of creating a lease. Is the commit focusing on changes to lease object registration, ID assignment, or maybe error handling during the lease creation process? My initial thought is to check if it's related to some kind of object protection, perhaps with how object handles are distributed between clients. I'll need to confirm if this change impacted existing object IDs, as it could have a ripple effect. This commit's diff should tell me the focus.
|
| 407/2 |
2026/10/14 00:20 |
tool |
git-show |
0m
Args: map[Commit:62884cd386b87 File:drivers/gpu/drm/drm_lease.c]
Results: map[Output:commit 62884cd386b876638720ef88374b31a84ca7ee5f
Author: Keith Packard <keithp@keithp.com>
Date: Thu Mar 16 17:56:28 2017 -0700
drm: Add four ioctls for managing drm mode object leases [v7]
drm_mode_create_lease
Creates a lease for a list of drm mode objects, returning an
fd for the new drm_master and a 64-bit identifier for the lessee
drm_mode_list_lesees
List the identifiers of the lessees for a master file
drm_mode_get_lease
List the leased objects for a master file
drm_mode_revoke_lease
Erase the set of objects managed by a lease.
This should suffice to at least create and query leases.
Changes for v2 as suggested by Daniel Vetter <daniel.vetter@ffwll.ch>:
* query ioctls only query the master associated with
the provided file.
* 'mask_lease' value has been removed
* change ioctl has been removed.
Changes for v3 suggested in part by Dave Airlie <airlied@gmail.com>
* Add revoke ioctl.
Changes for v4 suggested by Dave Airlie <airlied@gmail.com>
* Expand on the comment about the magic use of &drm_lease_idr_object
* Pad lease ioctl structures to align on 64-bit boundaries
Changes for v5 suggested by Dave Airlie <airlied@gmail.com>
* Check for non-negative object_id in create_lease to avoid debug
output from the kernel.
Changes for v6 provided by Dave Airlie <airlied@gmail.com>
* For non-universal planes add primary/cursor planes to lease
If we aren't exposing universal planes to this userspace client,
and it requests a lease on a crtc, we should implicitly export the
primary and cursor planes for the crtc.
If the lessee doesn't request universal planes, it will just see
the crtc, but if it does request them it will then see the plane
objects as well.
This also moves the object look ups earlier as a side effect, so
we'd exit the ioctl quicker for non-existant objects.
* Restrict leases to crtc/connector/planes.
This only allows leasing for objects we wish to allow.
Changes for v7 provided by Dave Airlie <airlied@gmail.com>
* Check pad args are 0
* Check create flags and object count are valid.
* Check return from fd allocation
* Refactor lease idr setup and add some simple validation
* Use idr_mutex uniformly (Keith)
Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 030db1170570..d1eb56a1eff4 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -23,6 +23,8 @@
#define drm_for_each_lessee(lessee, lessor) \
list_for_each_entry((lessee), &(lessor)->lessees, lessee_list)
+static uint64_t drm_lease_idr_object;
+
/**
* drm_lease_owner - return ancestor owner drm_master
* @master: drm_master somewhere within tree of lessees and lessors
@@ -353,3 +355,413 @@ void drm_lease_revoke(struct drm_master *top)
_drm_lease_revoke(top);
mutex_unlock(&top->dev->mode_config.idr_mutex);
}
+
+static int validate_lease(struct drm_device *dev,
+ struct drm_file *lessor_priv,
+ int object_count,
+ struct drm_mode_object **objects)
+{
+ int o;
+ int has_crtc = -1;
+ int has_connector = -1;
+ int has_plane = -1;
+
+ /* we want to confirm that there is at least one crtc, plane
+ connector object. */
+
+ for (o = 0; o < object_count; o++) {
+ if (objects[o]->type == DRM_MODE_OBJECT_CRTC && has_crtc == -1) {
+ has_crtc = o;
+ }
+ if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
+ has_connector = o;
+
+ if (lessor_priv->universal_planes) {
+ if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
+ has_plane = o;
+ }
+ }
+ if (has_crtc == -1 || has_connector == -1)
+ return -EINVAL;
+ if (lessor_priv->universal_planes && has_plane == -1)
+ return -EINVAL;
+ return 0;
+}
+
+static int fill_object_idr(struct drm_device *dev,
+ struct drm_file *lessor_priv,
+ struct idr *leases,
+ int object_count,
+ u32 *object_ids)
+{
+ struct drm_mode_object **objects;
+ u32 o;
+ int ret;
+ objects = kcalloc(object_count, sizeof(struct drm_mode_object *),
+ GFP_KERNEL);
+ if (!objects)
+ return -ENOMEM;
+
+ /* step one - get references to all the mode objects
+ and check for validity. */
+ for (o = 0; o < object_count; o++) {
+ if ((int) object_ids[o] < 0) {
+ ret = -EINVAL;
+ goto out_free_objects;
+ }
+
+ objects[o] = drm_mode_object_find(dev, lessor_priv,
+ object_ids[o],
+ DRM_MODE_OBJECT_ANY);
+ if (!objects[o]) {
+ ret = -ENOENT;
+ goto out_free_objects;
+ }
+
+ if (!drm_mode_object_lease_required(objects[o]->type)) {
+ ret = -EINVAL;
+ goto out_free_objects;
+ }
+ }
+
+ ret = validate_lease(dev, lessor_priv, object_count, objects);
+ if (ret)
+ goto out_free_objects;
+
+ /* add their IDs to the lease request - taking into account
+ universal planes */
+ for (o = 0; o < object_count; o++) {
+ struct drm_mode_object *obj = objects[o];
+ u32 object_id = objects[o]->id;
+ DRM_DEBUG_LEASE("Adding object %d to lease\n", object_id);
+
+ /*
+ * We're using an IDR to hold the set of leased
+ * objects, but we don't need to point at the object's
+ * data structure from the lease as the main crtc_idr
+ * will be used to actually find that. Instead, all we
+ * really want is a 'leased/not-leased' result, for
+ * which any non-NULL pointer will work fine.
+ */
+ ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
+ if (ret < 0) {
+ DRM_DEBUG_LEASE("Object %d cannot be inserted into leases (%d)\n",
+ object_id, ret);
+ goto out_free_objects;
+ }
+ if (obj->type == DRM_MODE_OBJECT_CRTC && !lessor_priv->universal_planes) {
+ struct drm_crtc *crtc = obj_to_crtc(obj);
+ ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
+ if (ret < 0) {
+ DRM_DEBUG_LEASE("Object primary plane %d cannot be inserted into leases (%d)\n",
+ object_id, ret);
+ goto out_free_objects;
+ }
+ if (crtc->cursor) {
+ ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
+ if (ret < 0) {
+ DRM_DEBUG_LEASE("Object cursor plane %d cannot be inserted into leases (%d)\n",
+ object_id, ret);
+ goto out_free_objects;
+ }
+ }
+ }
+ }
+
+ ret = 0;
+out_free_objects:
+ for (o = 0; o < object_count; o++) {
+ if (objects[o])
+ drm_mode_object_put(objects[o]);
+ }
+ kfree(objects);
+ return ret;
+}
+
+/**
+ * drm_mode_create_lease_ioctl - create a new lease
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_create_lease
+ * @file_priv: the file being manipulated
+ *
+ * The master associated with the specified file will have a lease
+ * created containing the objects specified in the ioctl structure.
+ * A file descriptor will be allocated for that and returned to the
+ * application.
+ */
+int drm_mode_create_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessor_priv)
+{
+ struct drm_mode_create_lease *cl = data;
+ size_t object_count;
+ int ret = 0;
+ struct idr leases;
+ struct drm_master *lessor = lessor_priv->master;
+ struct drm_master *lessee = NULL;
+ struct file *lessee_file = NULL;
+ struct file *lessor_file = lessor_priv->filp;
+ struct drm_file *lessee_priv;
+ int fd = -1;
+ uint32_t *object_ids;
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ /* Do not allow sub-leases */
+ if (lessor->lessor)
+ return -EINVAL;
+
+ /* need some objects */
+ if (cl->object_count == 0)
+ return -EINVAL;
+
+ if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK)))
+ return -EINVAL;
+
+ object_count = cl->object_count;
+
+ object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), object_count * sizeof(__u32));
+ if (IS_ERR(object_ids))
+ return PTR_ERR(object_ids);
+
+ idr_init(&leases);
+
+ /* fill and validate the object idr */
+ ret = fill_object_idr(dev, lessor_priv, &leases,
+ object_count, object_ids);
+ kfree(object_ids);
+ if (ret) {
+ idr_destroy(&leases);
+ return ret;
+ }
+
+ /* Allocate a file descriptor for the lease */
+ fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
+ if (fd < 0) {
+ idr_destroy(&leases);
+ return fd;
+ }
+
+ DRM_DEBUG_LEASE("Creating lease\n");
+ lessee = drm_lease_create(lessor, &leases);
+
+ if (IS_ERR(lessee)) {
+ ret = PTR_ERR(lessee);
+ goto out_leases;
+ }
+
+ /* Clone the lessor file to create a new file for us */
+ DRM_DEBUG_LEASE("Allocating lease file\n");
+ path_get(&lessor_file->f_path);
+ lessee_file = alloc_file(&lessor_file->f_path,
+ lessor_file->f_mode,
+ fops_get(lessor_file->f_inode->i_fop));
+
+ if (IS_ERR(lessee_file)) {
+ ret = PTR_ERR(lessee_file);
+ goto out_lessee;
+ }
+
+ /* Initialize the new file for DRM */
+ DRM_DEBUG_LEASE("Initializing the file with %p\n", lessee_file->f_op->open);
+ ret = lessee_file->f_op->open(lessee_file->f_inode, lessee_file);
+ if (ret)
+ goto out_lessee_file;
+
+ lessee_priv = lessee_file->private_data;
+
+ /* Change the file to a master one */
+ drm_master_put(&lessee_priv->master);
+ lessee_priv->master = lessee;
+ lessee_priv->is_master = 1;
+ lessee_priv->authenticated = 1;
+
+ /* Hook up the fd */
+ fd_install(fd, lessee_file);
+
+ /* Pass fd back to userspace */
+ DRM_DEBUG_LEASE("Returning fd %d id %d\n", fd, lessee->lessee_id);
+ cl->fd = fd;
+ cl->lessee_id = lessee->lessee_id;
+
+ DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl succeeded\n");
+ return 0;
+
+out_lessee_file:
+ fput(lessee_file);
+
+out_lessee:
+ drm_master_put(&lessee);
+
+out_leases:
+ put_unused_fd(fd);
+ idr_destroy(&leases);
+
+ DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl failed: %d\n", ret);
+ return ret;
+}
+
+/**
+ * drm_mode_list_lessees_ioctl - list lessee ids
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_list_lessees
+ * @lessor_priv: the file being manipulated
+ *
+ * Starting from the master associated with the specified file,
+ * the master with the provided lessee_id is found, and then
+ * an array of lessee ids associated with leases from that master
+ * are returned.
+ */
+
+int drm_mode_list_lessees_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessor_priv)
+{
+ struct drm_mode_list_lessees *arg = data;
+ __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr);
+ __u32 count_lessees = arg->count_lessees;
+ struct drm_master *lessor = lessor_priv->master, *lessee;
+ int count;
+ int ret = 0;
+
+ if (arg->pad)
+ return -EINVAL;
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ DRM_DEBUG_LEASE("List lessees for %d\n", lessor->lessee_id);
+
+ mutex_lock(&dev->mode_config.idr_mutex);
+
+ count = 0;
+ drm_for_each_lessee(lessee, lessor) {
+ /* Only list un-revoked leases */
+ if (!idr_is_empty(&lessee->leases)) {
+ if (count_lessees > count) {
+ DRM_DEBUG_LEASE("Add lessee %d\n", lessee->lessee_id);
+ ret = put_user(lessee->lessee_id, lessee_ids + count);
+ if (ret)
+ break;
+ }
+ count++;
+ }
+ }
+
+ DRM_DEBUG_LEASE("Lessor leases to %d\n", count);
+ if (ret == 0)
+ arg->count_lessees = count;
+
+ mutex_unlock(&dev->mode_config.idr_mutex);
+
+ return ret;
+}
+
+/**
+ * drm_mode_get_lease_ioctl - list leased objects
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_get_lease
+ * @file_priv: the file being manipulated
+ *
+ * Return the list of leased objects for the specified lessee
+ */
+
+int drm_mode_get_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessee_priv)
+{
+ struct drm_mode_get_lease *arg = data;
+ __u32 __user *object_ids = (__u32 __user *) (uintptr_t) (arg->objects_ptr);
+ __u32 count_objects = arg->count_objects;
+ struct drm_master *lessee = lessee_priv->master;
+ struct idr *object_idr;
+ int count;
+ void *entry;
+ int object;
+ int ret = 0;
+
+ if (arg->pad)
+ return -EINVAL;
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ DRM_DEBUG_LEASE("get lease for %d\n", lessee->lessee_id);
+
+ mutex_lock(&dev->mode_config.idr_mutex);
+
+ if (lessee->lessor == NULL)
+ /* owner can use all objects */
+ object_idr = &lessee->dev->mode_config.crtc_idr;
+ else
+ /* lessee can only use allowed object */
+ object_idr = &lessee->leases;
+
+ count = 0;
+ idr_for_each_entry(object_idr, entry, object) {
+ if (count_objects > count) {
+ DRM_DEBUG_LEASE("adding object %d\n", object);
+ ret = put_user(object, object_ids + count);
+ if (ret)
+ break;
+ }
+ count++;
+ }
+
+ DRM_DEBUG("lease holds %d objects\n", count);
+ if (ret == 0)
+ arg->count_objects = count;
+
+ mutex_unlock(&dev->mode_config.idr_mutex);
+
+ return ret;
+}
+
+/**
+ * drm_mode_revoke_lease_ioctl - revoke lease
+ * @dev: the drm device
+ * @data: pointer to struct drm_mode_revoke_lease
+ * @file_priv: the file being manipulated
+ *
+ * This removes all of the objects from the lease without
+ * actually getting rid of the lease itself; that way all
+ * references to it still work correctly
+ */
+int drm_mode_revoke_lease_ioctl(struct drm_device *dev,
+ void *data, struct drm_file *lessor_priv)
+{
+ struct drm_mode_revoke_lease *arg = data;
+ struct drm_master *lessor = lessor_priv->master;
+ struct drm_master *lessee;
+ int ret = 0;
+
+ DRM_DEBUG_LEASE("revoke lease for %d\n", arg->lessee_id);
+
+ /* Can't lease without MODESET */
+ if (!drm_core_check_feature(dev, DRIVER_MODESET))
+ return -EINVAL;
+
+ mutex_lock(&dev->mode_config.idr_mutex);
+
+ lessee = _drm_find_lessee(lessor, arg->lessee_id);
+
+ /* No such lessee */
+ if (!lessee) {
+ ret = -ENOENT;
+ goto fail;
+ }
+
+ /* Lease is not held by lessor */
+ if (lessee->lessor != lessor) {
+ ret = -EACCES;
+ goto fail;
+ }
+
+ _drm_lease_revoke(lessee);
+
+fail:
+ mutex_unlock(&dev->mode_config.idr_mutex);
+
+ return ret;
+}
]
|
| 408/2 |
2026/10/14 00:20 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 40045
output: 44
thoughts: 256
Thoughts: **Examining the DRM Lease Implementation**
Okay, let's dive into this `drm_lease.c` code. Specifically, I'm looking at commit `62884cd386b87` β that's the one that introduced it. I'm focusing on two key areas: `fill_object_idr()` and `drm_mode_create_lease_ioctl`. I see that in `fill_object_idr()`, they used `kcalloc` to allocate an array of `drm_mode_object` pointers. Seems standard enough. But I also notice how in `drm_mode_create_lease_ioctl`, they `memdup_user` the `object_ids` from userspace, initialize an `idr` structure, and then call `fill_object_idr()` to populate it. They then `kfree` the copy.
Now, a bell is ringing in the back of my head... Did they perhaps change that `kcalloc` call in `fill_object_idr()` later? It's not uncommon to optimize memory allocation strategies, or replace something that was found to be insecure. I should really check the git log of `fill_object_idr()` to confirm. Let's see if there were any later modifications to that allocation.
|
| 409/2 |
2026/10/14 00:20 |
tool |
git-log |
0m
Error:
Args: map[Count:10 PathPrefix:drivers/gpu/drm/drm_lease.c SymbolName:fill_object_idr]
Results:
|
| 410/2 |
2026/10/14 00:20 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 40649
output: 44
thoughts: 14
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing Git History with SymbolName and SourcePath**
Right, so I'm thinking, "Let's leverage `git log`". Specifically, I want to use it in conjunction with `SymbolName` and `SourcePath`. This immediately suggests a deeper dive into how we can use this command and its output for a targeted analysis. I'm picturing a scenario where we're tracing the evolution of a particular function or class (the `SymbolName`) and understanding *where* it has been changed (the `SourcePath`). The key here is efficiency. We need a way to filter the git history down to the relevant commits quickly and reliably, using the source path of interest, coupled with the name we're looking for, rather than running a very broad search on the whole codebase. This will be critical for any real-world performance. I see this as a solid approach for pinpointing the exact commits that impacted a specific symbol, saving a lot of time and effort during debugging, refactoring, or impact analysis.
|
| 411/2 |
2026/10/14 00:21 |
tool |
git-log |
0m
Args: map[Count:10 SourcePath:drivers/gpu/drm/drm_lease.c SymbolName:fill_object_idr]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
948de84233d3 drm : Insert blank lines after declarations.
e40b76428842 drm/leases: Drop object_id validation for negative ids
b5f06893c499 drm: Rename crtc_idr as object_idr to KMS cleanups
968029057192 drm/lease: look at ->universal_planes only once
a0c1af46e9d7 drm/lease: debug output for lease creation
7591844c197c drm: Fix kerneldoc warnings for drm_lease
]
|
| 412/2 |
2026/10/14 00:21 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 41206
output: 47
thoughts: 60
Thoughts: Okay, let's dive into this.
**Examining a Recent DRM Commit and Related Lease Functionality**
Alright, I'm taking a look at commit `62884cd386b87` and it's proposing some new DRM functionality: "drm: Add four ioctls for managing drm mode object leases [v7]". My initial instinct is to go beyond just the code and its description. I need to get a broader understanding. Therefore, I need to check the Git log, specifically focusing on how the `drm_mode_create_lease_ioctl` function is implemented and has evolved. I'm keen on seeing the context, rationale, and any potential upstream discussions around this lease feature. This initial commit is likely just the tip of the iceberg, and the log will give me critical insights for a thorough assessment.
|
| 413/2 |
2026/10/14 00:21 |
tool |
git-log |
0m
Args: map[Count:10 SourcePath:drivers/gpu/drm/drm_lease.c SymbolName:drm_mode_create_lease_ioctl]
Results: map[Output:f37d63e219c3 drm_lease.c: copy user-array safely
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
4bb2d367a5a2 drm/lease: allow empty leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
b216a8e7908c drm/lease: fix WARNING in idr_destroy
69ef943dbc14 drm: Use array_size() when creating lease
d7563c55ef9f Merge tag 'drm-misc-next-2018-11-07' of git://anongit.freedesktop.org/drm/drm-misc into drm-next
a0c1af46e9d7 drm/lease: debug output for lease creation
53b3b6bbfde6 Merge tag 'drm-next-2018-10-24' of git://anongit.freedesktop.org/drm/drm
69fdf4206a8b drm: Differentiate the lack of an interface from invalid parameter
]
|
| 414/2 |
2026/10/14 00:21 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 41788
output: 51
thoughts: 129
Thoughts: Here's my analysis:
**Diving into Those Recent DRM Commits**
Okay, hold on a second. Something's caught my eye looking through these recent commits, specifically related to the DRM subsystem. I need to take a closer look at a few of them. Let's see... I've got:
* `69ef943dbc14 drm: Use array_size() when creating lease`
* `b216a8e7908c drm/lease: fix WARNING in idr_destroy`
* `f37d63e219c3 drm_lease.c: copy user-array safely`
My initial thought is that these seem potentially interesting, particularly the ones that deal with `drm/lease` and the safety/management of arrays. I need to dig into `69ef943dbc14`, `b216a8e7908c`, and `f37d63e219c3`. Let me start by reviewing these individually.
|
| 415/2 |
2026/10/14 00:21 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 69ef943dbc14b21987c79f8399ffea08f9a1b446
Author: Matthew Wilcox <willy@infradead.org>
Date: Thu Feb 14 11:03:48 2019 -0800
drm: Use array_size() when creating lease
Passing an object_count of sufficient size will make
object_count * 4 wrap around to be very small, then a later function
will happily iterate off the end of the object_ids array. Using
array_size() will saturate at SIZE_MAX, the kmalloc() will fail and
we'll return an -ENOMEM to the norty userspace.
Fixes: 62884cd386b8 ("drm: Add four ioctls for managing drm mode object leases [v7]")
Signed-off-by: Matthew Wilcox <willy@infradead.org>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: <stable@vger.kernel.org> # v4.15+
Signed-off-by: Dave Airlie <airlied@redhat.com>
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 99cba8ea5d82..5df1256618cc 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -528,7 +528,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
object_count = cl->object_count;
- object_ids = memdup_user(u64_to_user_ptr(cl->object_ids), object_count * sizeof(__u32));
+ object_ids = memdup_user(u64_to_user_ptr(cl->object_ids),
+ array_size(object_count, sizeof(__u32)));
if (IS_ERR(object_ids))
return PTR_ERR(object_ids);
]
|
| 416/2 |
2026/10/14 00:21 |
tool |
git-show |
0m
Args:
Results: map[Output:commit b216a8e7908cd750550c0480cf7d2b3a37f06954
Author: Qiujun Huang <hqjagain@gmail.com>
Date: Wed Mar 18 15:53:50 2020 +0800
drm/lease: fix WARNING in idr_destroy
drm_lease_create takes ownership of leases. And leases will be released
by drm_master_put.
drm_master_put
->drm_master_destroy
->idr_destroy
So we needn't call idr_destroy again.
Reported-and-tested-by: syzbot+05835159fe322770fe3d@syzkaller.appspotmail.com
Signed-off-by: Qiujun Huang <hqjagain@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/1584518030-4173-1-git-send-email-hqjagain@gmail.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index b481cafdde28..825abe38201a 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -542,10 +542,12 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
}
DRM_DEBUG_LEASE("Creating lease\n");
+ /* lessee will take the ownership of leases */
lessee = drm_lease_create(lessor, &leases);
if (IS_ERR(lessee)) {
ret = PTR_ERR(lessee);
+ idr_destroy(&leases);
goto out_leases;
}
@@ -580,7 +582,6 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
out_leases:
put_unused_fd(fd);
- idr_destroy(&leases);
DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl failed: %d\n", ret);
return ret;
]
|
| 417/2 |
2026/10/14 00:21 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 43432
output: 43
thoughts: 2287
Thoughts: **DRM Lease Creation Vulnerability: Deep Dive**
Okay, let's break this down. We have a crash, a warning in `mm/page_alloc.c`, specifically related to an allocation order exceeding `MAX_PAGE_ORDER`. The trace leads us right to the `drm_mode_create_lease_ioctl` function. The core of the problem stems from an unbounded user-controlled allocation size within this ioctl, specifically when creating a DRM lease.
The critical path, it seems, is the `fill_object_idr()` function. It's calling a `kmalloc`-family function via `kzalloc_objs` to allocate an `objects` array. The size of this allocation, `object_count`, is directly taken from user space via the `drm_mode_create_lease` struct. This is where the vulnerability lies: no size check!
Looking at the syzkaller reproducer, with `object_count` set to 1,000,000, we're allocating 8MB for the `objects` array (8 bytes per pointer), exceeding the typical `MAX_PAGE_ORDER` of 4MB (order 10). The `kmalloc` then goes off the rails.
Interestingly, prior to that the `object_ids` array, containing 4-byte `__u32` elements, is allocated using `memdup_array_user()`, which silently fails (due to `__GFP_NOWARN`) if the allocation is too large. This creates a window. The `object_ids` allocation may succeed silently, but then the subsequent allocation of the `objects` array with `GFP_KERNEL` triggers the warning.
The provided patch looks like it has three parts:
1. Switches from `kzalloc_objs` to `kvzalloc_objs` for the `objects` array, then from `kfree` to `kvfree`. This implies a move to vmalloc, which can handle larger contiguous memory requirements.
2. Adds a crucial size check. Now, if the `object_count` would result in an allocation larger than `INT_MAX / sizeof(struct drm_mode_object *)`, it returns an error. This seems to be the critical fix to prevent the issue.
3. Switches from `memdup_array_user` to `vmemdup_array_user` for the `object_ids` array, and `kfree` to `kvfree`. Likely also using vmalloc for larger contiguous memory.
Now, let's go further back, I have to confirm. What was `kzalloc_objs` originally, which is now `kcalloc`? We have to go back to the code commit `62884cd386b87`. The original code, even back then, used `kcalloc`, meaning `kmalloc_array`, which calls `kmalloc` with `GFP_KERNEL`. This means the same vulnerability existed from the beginning, where a large `object_count` could lead to an 8MB allocation using `GFP_KERNEL`! The problem always existed!
And `memdup_user`, which would silently fail if too large, at the time, still allocated up to 4MB of user memory. Then `kcalloc` tries to allocate 8MB, triggering the warning! The bug was there from the beginning!
|
| 418/2 |
2026/10/14 00:22 |
tool |
git-show |
0m
Args: map[Commit:69050f8d6d07 File:drivers/gpu/drm/drm_lease.c]
Results: map[Output:commit 69050f8d6d075dc01af7a5f2f550a8067510366f
Author: Kees Cook <kees@kernel.org>
Date: Fri Feb 20 23:49:23 2026 -0800
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 94375c6a5425..f0a5cef17164 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,8 +386,8 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kcalloc(object_count, sizeof(struct drm_mode_object *),
- GFP_KERNEL);
+ objects = kzalloc_objs(struct drm_mode_object *, object_count,
+ GFP_KERNEL);
if (!objects)
return -ENOMEM;
]
|
| 419/2 |
2026/10/14 00:22 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 47071
output: 46
thoughts: 460
Thoughts: **Recent Code Archaeology: Digging into Lease Management**
Okay, so I'm looking at these commits, `69050f8d6d07` and `32a92f8c8932`, that are practically brand new β February 2026, wow. They're just doing some straightforward conversions, basically replacing `kcalloc` with `kzalloc_objs` and defaulting to `GFP_KERNEL`. Before that, it was the more explicit `kcalloc` with a hardcoded size. Nothing too crazy yet.
But wait, this feels... familiar. I need to trace the evolution of `drm_mode_create_lease_ioctl` and `fill_object_idr`. Were there earlier changes that set the stage for these tweaks? My gut is telling me there's more here. Let's see... could it be `62884cd386b8`, `f37d63e219c3`, or `69ef943dbc14`?
Ah, bingo. Let's look at `69ef943dbc14`... "drm: Use array_size() when creating lease." And, it's fixing the *original* lease commit! This is interesting; the fix addresses a potential integer overflow when calculating object sizes. Matthew Wilcox added `array_size()` to prevent a multiplication that could wrap, leading to an out-of-bounds read later on in the code. Clever. `array_size()` saturates at `SIZE_MAX`, forcing the `kmalloc()` to fail and returning -ENOMEM to the caller. That's a good defensive programming approach.
Okay, that nails down the size calculation. Now, let's look at commit `f37d63e219c3`: "drm_lease.c: copy user-array safely." Ah, the copy from userspace! This is about security β the fix uses `memdup_array_user` instead of just plain `memdup_user` to safeguard against overflows when duplicating user-space arrays. Smart; that's a classic vulnerability.
Alright, now the question is: what was the original author of the fix thinking? I should search for related commits to see if there's any commentary. I need to use `git log` or grepper or search the commit messages. I bet there's some useful context out there! I'll look for similar patches and see what I can find.
|
| 420/2 |
2026/10/14 00:22 |
tool |
git-log |
0m
Args: map[CodeRegexp:vmemdup_array_user Count:10 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results:
|
| 421/2 |
2026/10/14 00:22 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 48130
output: 28
thoughts: 42
Thoughts: Okay, here's my summary, presented as a first-person account reflecting the described thought process:
**Where's That Fix?**
Right, so the "fix commit" is *not* showing up directly in the `git log`. That makes sense; it's the current patch itself that's fixing the immediate issue. I need to track down the history of this fix, or related fixes, so I can see what changed. It's time to dig into the commit messages to see if I can find the origin. Let me search for key terms related to this DRM lease issue, like "drm\_lease" itself, or maybe some related functions used in this context, such as "fill\_object\_idr" or anything similar. Hopefully, the commit message provides some helpful context around this bug.
|
| 422/2 |
2026/10/14 00:22 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[fill_object_idr]]
Results:
|
| 423/2 |
2026/10/14 00:23 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 48384
output: 31
thoughts: 24
Thoughts: Here's my thought process, as if I were considering this search:
**Investigating `drm_mode_create_lease_ioctl` and `drm_lease` in Commit Messages**
Okay, so I'm thinking about digging into the commit history related to DRM leases. My initial thought is to specifically look for the `drm_mode_create_lease_ioctl` function. That's a pretty strong indicator, as it's the core system call involved in lease creation. I also need to be broad and consider variations, so I should also search generally for the term `drm_lease`. This should give me a good overview of the development, bug fixes, and usage of the feature. I'll need to use these search terms to get a comprehensive view of the context surrounding those functions and APIs, and how theyβve evolved over time. I'll need to figure out which tools I'll use, like `git log`, `git grep`, or whatever else is best.
|
| 424/2 |
2026/10/14 00:23 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[drm_mode_create_lease_ioctl]]
Results: map[Output:676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
12d43deb1ee6 drm: fix use-after-free read in drm_mode_create_lease_ioctl()
b4e7a7a88b5d drm_mode_create_lease_ioctl(): fix open-coded filp_clone_open()
7591844c197c drm: Fix kerneldoc warnings for drm_lease
bd36d3bab2e3 drm/drm_lease: Prevent deadlock in case drm_lease_create() fails
]
|
| 425/2 |
2026/10/14 00:23 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 48802
output: 24
thoughts: 16
Thoughts: Okay, here's my interpretation of what's going through my mind, rendered in the first person, as if I'm the expert reviewing commit `12d43deb1ee6`.
**Initial Assessment: Diving into Commit 12d43deb1ee6**
Alright, let's get down to brass tacks. I'm taking a look at commit `12d43deb1ee6`. Immediately, I want to see what this thing is *actually* doing. The commit hash is just a label, a pointer to a set of changes. Now, my mind is already running through a mental checklist: what was the context of this commit? What's the area of the codebase? What's the likely impact? I need to analyze its changes, and I'm already formulating questions to assess its impact. Was this a quick fix? A large feature update? A refactor? Let's get to the meat of it. Show me the diff. Let's see how smart this commit really is.
|
| 426/2 |
2026/10/14 00:23 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 12d43deb1ee639d01a2a8d2a7a4cc8ad31224475
Author: Jann Horn <jannh@google.com>
Date: Mon Oct 1 17:31:17 2018 +0200
drm: fix use-after-free read in drm_mode_create_lease_ioctl()
fd_install() moves the reference given to it into the file descriptor table
of the current process. If the current process is multithreaded, then
immediately after fd_install(), another thread can close() the file
descriptor and cause the file's resources to be cleaned up.
Since the reference to "lessee" is held by the file, we must not access
"lessee" after the fd_install() call.
As far as I can tell, to reach this codepath, the caller must have an open
file descriptor to a DRI device in master mode. I'm not sure what the
requirements for that are.
Signed-off-by: Jann Horn <jannh@google.com>
Fixes: 62884cd386b8 ("drm: Add four ioctls for managing drm mode object leases [v7]")
Cc: stable@vger.kernel.org
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20181001153117.216923-1-jannh@google.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index b54fb78a283c..b82da96ded5c 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -566,14 +566,14 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
lessee_priv->is_master = 1;
lessee_priv->authenticated = 1;
- /* Hook up the fd */
- fd_install(fd, lessee_file);
-
/* Pass fd back to userspace */
DRM_DEBUG_LEASE("Returning fd %d id %d\n", fd, lessee->lessee_id);
cl->fd = fd;
cl->lessee_id = lessee->lessee_id;
+ /* Hook up the fd */
+ fd_install(fd, lessee_file);
+
DRM_DEBUG_LEASE("drm_mode_create_lease_ioctl succeeded\n");
return 0;
]
|
| 427/2 |
2026/10/14 00:23 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 49774
output: 24
thoughts: 15
Thoughts: Okay, here's my interpretation of what's going on, framed as a thought process I might have:
**Analyzing Commit bd36d3bab2e3**
Alright, let's dive into this commit, bd36d3bab2e3. Seems like we're zeroing in on a specific piece of the puzzle here. I'm going to carefully dissect the code changes introduced by this commit, because specific commits like these are often crucial for understanding the overall trajectory of a project. I'll be looking for clues on the overall architecture of this code, and paying special attention to how these changes interact with the existing codebase. My experience tells me that these commits will either be straightforward bug fixes, or potentially major architecture shifts. I'll look at the file differences to see if there are any obvious additions, deletions, or modifications. I need to understand the 'why' behind these changes. Is this addressing a performance bottleneck? Is it a security fix? Or perhaps a refactoring to improve maintainability? Knowing this context is key to assessing the long-term impact. Given my current project goals, this analysis will allow me to assess the scope of this commit, and how it relates to my current tasks.
|
| 428/2 |
2026/10/14 00:23 |
tool |
git-show |
0m
Args:
Results: map[Output:commit bd36d3bab2e3d08f80766c86487090dbceed4651
Author: Marius Vlad <marius-cristian.vlad@nxp.com>
Date: Wed Dec 13 20:10:48 2017 +0200
drm/drm_lease: Prevent deadlock in case drm_lease_create() fails
This case can been seen when creating the lease with the same objects passed.
[ 605.515097] 2 locks held by testapp/3337:
[ 605.519027] #0: (&dev->mode_config.idr_mutex){......}, at: [<ffff0000085f1664>] drm_mode_create_lease_ioctl+0x384/0x858
[ 605.530045] #1: (&dev->mode_config.idr_mutex){......}, at: [<ffff0000085f11bc>] drm_lease_destroy+0x2c/0x110
Which was causing the process to hang:
[ 605.398827] [<ffff0000080856cc>] __switch_to+0x94/0xa8
[ 605.404030] [<ffff000008c05d00>] __schedule+0x1b0/0x698
[ 605.409322] [<ffff000008c06224>] schedule+0x3c/0xa8
[ 605.414260] [<ffff000008c06628>] schedule_preempt_disabled+0x20/0x38
[ 605.420677] [<ffff000008c07370>] mutex_lock_nested+0x158/0x340
[ 605.426572] [<ffff0000085f11bc>] drm_lease_destroy+0x2c/0x110
[ 605.432389] [<ffff0000085cecf0>] drm_master_put+0xc0/0xc8
[ 605.437845] [<ffff0000085f175c>] drm_mode_create_lease_ioctl+0x47c/0x858
[ 605.444612] [<ffff0000085d4460>] drm_ioctl+0x198/0x448
[ 605.449811] [<ffff000008201134>] do_vfs_ioctl+0xa4/0x748
[ 605.455192] [<ffff000008201864>] SyS_ioctl+0x8c/0xa0
[ 605.460216] [<ffff000008082f4c>] __sys_trace_return+0x0/0x4
drm_mode_create_lease_ioctl() calls drm_lease_create() which acquires a lock
on dev->mode_config.idr_mutex. In case of failure, drm_lease_create() calls
drm_master_put() which in turn tries to acquire the same lock when calling
drm_lease_destroy().
v2: - Reverse the order at exit in case of fail, so that unlocking takes place
before dropping the reference.
- Include detail information about deadlock (Daniel Vetter)
Signed-off-by: Marius Vlad <marius-cristian.vlad@nxp.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20171213181048.32719-1-marius-cristian.vlad@nxp.com
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index d1eb56a1eff4..59849f02e2ad 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -254,10 +254,10 @@ static struct drm_master *drm_lease_create(struct drm_master *lessor, struct idr
return lessee;
out_lessee:
- drm_master_put(&lessee);
-
mutex_unlock(&dev->mode_config.idr_mutex);
+ drm_master_put(&lessee);
+
return ERR_PTR(error);
}
]
|
| 429/2 |
2026/10/14 00:23 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 51349
output: 32
thoughts: 52
Thoughts: Okay, let's dive into this. I need to get a really solid understanding of the evolution of `drm_lease.c`, specifically focusing on how `fill_object_idr` and `drm_mode_create_lease_ioctl` have changed over time. I'm thinking a thorough commit history review is in order. Let's start by isolating all the commits that have touched `drm_lease.c`. This should give me a good timeline and context for any relevant modifications and the rationale behind them. From there, I can drill down into the specifics of these two functions, noting the changes and implications of those changes, especially as they relate to potential security vulnerabilities or performance bottlenecks. I want to see how this lease functionality has been shaped and whether the current implementation reflects any particular design choices or limitations. This approach should allow for a complete understanding of how these pieces fit together.
|
| 430/2 |
2026/10/14 00:23 |
tool |
git-log |
0m
Args: map[Count:50 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
f37d63e219c3 drm_lease.c: copy user-array safely
cde3d37b19df drm: Remove unnecessary include statements for drm_crtc_helper.h
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
4bb2d367a5a2 drm/lease: allow empty leases
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
d793b8f732d6 drm: clarify usage of drm leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
7988fdf5f0a3 drm: Don't include drm_legacy.h in drm_lease.c
948de84233d3 drm : Insert blank lines after declarations.
b216a8e7908c drm/lease: fix WARNING in idr_destroy
c942fddf8793 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
0500c04ea14a drm: drop use of drmP.h in drm/*
46b757780dfe drm/lease: Check for lessor outside of locks
ae9d6c076c0d drm/lease: Drop recursive leads checks
e40b76428842 drm/leases: Drop object_id validation for negative ids
69ef943dbc14 drm: Use array_size() when creating lease
b5f06893c499 drm: Rename crtc_idr as object_idr to KMS cleanups
ce85882860f0 drm/lease: Send a distinct uevent
968029057192 drm/lease: look at ->universal_planes only once
a0c1af46e9d7 drm/lease: debug output for lease creation
6caec6a04717 drm/lease: drop EXPORT_SYMBOL
918d89bb1a63 gpu: drm/lease: fix spelling mistake, EACCESS -> EACCES
12d43deb1ee6 drm: fix use-after-free read in drm_mode_create_lease_ioctl()
69fdf4206a8b drm: Differentiate the lack of an interface from invalid parameter
19f391eb05b8 turn filp_clone_open() into inline wrapper for dentry_open()
b4e7a7a88b5d drm_mode_create_lease_ioctl(): fix open-coded filp_clone_open()
aec06c7606be gpu: drm/lease:: Use list_{next/prev}_entry instead of list_entry
7591844c197c drm: Fix kerneldoc warnings for drm_lease
d2a48e52541c drm: move lease init after validation in drm_lease_create
bd36d3bab2e3 drm/drm_lease: Prevent deadlock in case drm_lease_create() fails
62884cd386b8 drm: Add four ioctls for managing drm mode object leases [v7]
2ed077e467ee drm: Add drm_object lease infrastructure [v5]
]
|
| 431/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 52490
output: 29
thoughts: 26
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing the Impact of Commit 2ed077e467ee**
Alright, I need to get a clear picture of what's going on. Before I dive too deep into the issue, itβs best to reference commit `2ed077e467ee`. I need to ensure that the origin of the issue is appropriately referenced, and what that specific commit was, relative to the current state of affairs. Often, a single commit can cascade into downstream changes. Seeing it directly might reveal some unexpected context or assumptions that were made at the time, helping me to understand the current situation and any potential root causes. Iβm thinking there might be an upstream dependency or a subtle interaction that wasnβt immediately obvious from the current changeset alone. It's a quick sanity check before I go too deep.
|
| 432/2 |
2026/10/14 00:24 |
tool |
git-show |
0m
Args: map[Commit:2ed077e467ee Stat:true]
Results: map[Output:commit 2ed077e467eedb033032bc4b6e349365517662d6
Author: Keith Packard <keithp@keithp.com>
Date: Tue Mar 14 22:26:41 2017 -0700
drm: Add drm_object lease infrastructure [v5]
This provides new data structures to hold "lease" information about
drm mode setting objects, and provides for creating new drm_masters
which have access to a subset of the available drm resources.
An 'owner' is a drm_master which is not leasing the objects from
another drm_master, and hence 'owns' them.
A 'lessee' is a drm_master which is leasing objects from some other
drm_master. Each lessee holds the set of objects which it is leasing
from the lessor.
A 'lessor' is a drm_master which is leasing objects to another
drm_master. This is the same as the owner in the current code.
The set of objects any drm_master 'controls' is limited to the set of
objects it leases (for lessees) or all objects (for owners).
Objects not controlled by a drm_master cannot be modified through the
various state manipulating ioctls, and any state reported back to user
space will be edited to make them appear idle and/or unusable. For
instance, connectors always report 'disconnected', while encoders
report no possible crtcs or clones.
The full list of lessees leasing objects from an owner (either
directly, or indirectly through another lessee), can be searched from
an idr in the drm_master of the owner.
Changes for v2 as suggested by Daniel Vetter <daniel.vetter@ffwll.ch>:
* Sub-leasing has been disabled.
* BUG_ON for lock checking replaced with lockdep_assert_held
* 'change' ioctl has been removed.
* Leased objects can always be controlled by the lessor; the
'mask_lease' flag has been removed
* Checking for leased status has been simplified, replacing
the drm_lease_check function with drm_lease_held.
Changes in v3, some suggested by Dave Airlie <airlied@gmail.com>
* Add revocation. This allows leases to be effectively revoked by
removing all of the objects they have access to. The lease itself
hangs around as it's hanging off a file.
* Free the leases IDR when the master is destroyed
* _drm_lease_held should look at lessees, not lessor
* Allow non-master files to check for lease status
Changes in v4, suggested by Dave Airlie <airlied@gmail.com>
* Formatting and whitespace changes
Changes in v5 (airlied)
* check DRIVER_MODESET before lease destroy call
* check DRIVER_MODESET for lease revoke (Chris)
* Use idr_mutex uniformly for all lease elements of struct drm_master. (Keith)
Signed-off-by: Keith Packard <keithp@keithp.com>
drivers/gpu/drm/Makefile | 2 +-
drivers/gpu/drm/drm_auth.c | 30 +++-
drivers/gpu/drm/drm_lease.c | 355 ++++++++++++++++++++++++++++++++++++++++++
include/drm/drm_auth.h | 21 +++
include/drm/drm_lease.h | 36 +++++
include/drm/drm_mode_object.h | 1 +
6 files changed, 443 insertions(+), 2 deletions(-)
]
|
| 433/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 53651
output: 36
thoughts: 716
Thoughts: **Analyzing the Potential Vulnerability in Commit 62884cd386b8**
Okay, let's dive into commit 62884cd386b87 and how it interacts with the newly created `drm_lease.c` from commit 2ed077e467eedb033032bc4b6e349365517662d6. That initial file just had helper functions, a decent starting point with 355 lines. But the real meat seems to be in the ioctls added in the target commit. I'm focusing on the interaction between `fill_object_idr()` and `drm_mode_create_lease_ioctl`.
I'm seeing that `drm_mode_create_lease_ioctl` takes `object_count` directly from user space via `cl->object_count`, which is a `uint32_t`. The critical part is the allocation and copying of `object_ids`. `memdup_user` is used to copy the user-provided IDs, and then `kcalloc` is used to allocate space for `objects`.
Here's the problem: there's *no* validation of `object_count`. No upper bound check, nothing. It's just blindly trusted. And if the user provides a large value for `object_count`, say 1,000,000, that translates to allocating and copying 4,000,000 bytes. That's a huge potential DoS vulnerability. And this is being done in the kernel.
What makes me most nervous is that I don't recall exactly how `memdup_user` behaved back in 2017. I'll need to check the definition in `mm/util.c` for any potential mitigation in older versions of the kernel. This might be a classic case of integer overflow or allocation-related issues, which are always fun.
I need to confirm the behavior of `memdup_user` in the kernel at the time this code was introduced. This could be a significant problem.
|
| 434/2 |
2026/10/14 00:24 |
tool |
git-log |
0m
Args: map[Count:5 MessageRegexps:[memdup_user] PathPrefix:mm/util.c]
Results: map[Output:dd2a5b5514ab mm/util: make memdup_user_nul() similar to memdup_user()
d73778e4b867 mm/util: Use dedicated slab buckets for memdup_user()
50fd2f298bef new primitive: vmemdup_user()
6c2c97a24f09 memdup_user(): switch to GFP_USER
e9d408e107db new helper: memdup_user_nul()
]
|
| 435/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 54998
output: 27
thoughts: 26
Thoughts: Okay, let's dive into commit `6c2c97a24f09` within `mm/util.c`. I need to understand what changed there. My initial thought is to quickly assess the context; what was the overall goal of the change? Was it a bug fix, performance optimization, or perhaps a new feature introduction related to memory management utilities? I'm going to look for the commit message first, as that usually provides a concise overview. Based on the file location, `mm/util.c`, I'd expect it deals with memory-related helper functions, potentially for allocation, deallocation, or addressing issues. Next, Iβll scan the diff for the core changes. I'll focus on any new function declarations, modifications to existing functions, and any changes to data structures. I'll need to pay close attention to things like atomic operations, synchronization primitives (if any), and any interactions with the page allocator or slab allocator, depending on what I see within the code. Based on the specific code changes, I'll attempt to correlate them to any known issues or areas of improvement within the memory management subsystem. Are there any potential impacts on other parts of the kernel, like interrupt handling or device drivers? Iβll need to consider those possibilities and any knock-on effects that might exist. I'll try to find any performance implications that would be important in any kernel version. Finally, Iβll compare the changes to any similar or related commits to build a complete picture of the change's purpose and impact.
|
| 436/2 |
2026/10/14 00:24 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 6c2c97a24f096e3239bc54029b808c6bcba4f358
Author: Al Viro <viro@zeniv.linux.org.uk>
Date: Sun Jan 7 13:00:27 2018 -0500
memdup_user(): switch to GFP_USER
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
diff --git a/mm/util.c b/mm/util.c
index 34e57fae959d..4b93ffa6df96 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -156,12 +156,7 @@ void *memdup_user(const void __user *src, size_t len)
{
void *p;
- /*
- * Always use GFP_KERNEL, since copy_from_user() can sleep and
- * cause pagefault, which makes it pointless to use GFP_NOFS
- * or GFP_ATOMIC.
- */
- p = kmalloc_track_caller(len, GFP_KERNEL);
+ p = kmalloc_track_caller(len, GFP_USER);
if (!p)
return ERR_PTR(-ENOMEM);
]
|
| 437/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 55736
output: 36
thoughts: 33
Thoughts: Okay, here's my take on those thoughts, framed for an expert audience:
**Investigating a Kernel Memory Allocation Detail**
Alright, so I'm thinking about `memdup_user` here. Specifically, I'm curious about the inclusion of `__GFP_NOWARN` in its implementation. It's a subtle but important detail. When did that change land? Best way to figure that out is to dig into the git log. I need to quickly see the history of changes related to `memdup_user`. I'm looking for the commit that introduced that specific flag, to understand the rationale behind it and when it was deemed necessary. Time to fire up the git commands and see what comes up. This is likely to tell me something interesting about a memory allocation strategy that's easily overlooked, but potentially quite impactful.
|
| 438/2 |
2026/10/14 00:24 |
tool |
git-log |
0m
Args: map[CodeRegexp:GFP_NOWARN Count:5 PathPrefix:mm/util.c]
Results: map[Output:f1157db8b539 slab: Adjust placement of __kvmalloc_node_noprof
dd2a5b5514ab mm/util: make memdup_user_nul() similar to memdup_user()
590b9d576cae mm: kvmalloc: align kvrealloc() with krealloc()
d73778e4b867 mm/util: Use dedicated slab buckets for memdup_user()
0708a0afe291 mm: Consider __GFP_NOWARN flag for oversized kvmalloc() calls
]
|
| 439/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 56129
output: 33
thoughts: 38
Thoughts: Okay, here's my interpretation of those thoughts, tailored for an expert audience, presented in the first person:
**Investigating a Suspect Memory Duplication**
Alright, so I'm looking into something that smells fishy. My initial instinct is to dig into commit history. I need to understand when and why `memdup_user` was touched last. Specifically, I want to cross-reference commit `dd2a5b5514ab` and `d73778e4b867` β those are potential candidates to investigate. Those commits *could* have introduced or changed behavior related to memory duplication from user space. Alternatively, I'll go directly to the source and leverage `git blame` on the `memdup_user` function itself. I'm hoping to quickly identify the author(s) of the problematic code and see if the change log or previous discussions shed any light on the current situation. I need to understand the intent behind that code and whether anything has changed, so the root cause is apparent.
|
| 440/2 |
2026/10/14 00:24 |
tool |
git-blame |
0m
Args: map[End:200 File:mm/util.c Start:180]
Results: map[Output:0b7b8704ddcee 180) }
0b7b8704ddcee 181) EXPORT_SYMBOL(kvmemdup);
0b7b8704ddcee 182)
f35157417215e 183) /**
f35157417215e 184) * kmemdup_nul - Create a NUL-terminated string from unterminated data
f35157417215e 185) * @s: The data to stringify
f35157417215e 186) * @len: The size of the data
f35157417215e 187) * @gfp: the GFP mask used in the kmalloc() call when allocating memory
a862f68a8b360 188) *
a862f68a8b360 189) * Return: newly allocated copy of @s with NUL-termination or %NULL in
a862f68a8b360 190) * case of error
f35157417215e 191) */
f35157417215e 192) char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
f35157417215e 193) {
43731516facc3 194) return s ? __kmemdup_nul(s, len, gfp) : NULL;
f35157417215e 195) }
f35157417215e 196) EXPORT_SYMBOL(kmemdup_nul);
f35157417215e 197)
d73778e4b8675 198) static kmem_buckets *user_buckets __ro_after_init;
d73778e4b8675 199)
d73778e4b8675 200) static int __init init_user_buckets(void)
]
|
| 441/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 57012
output: 31
thoughts: 18
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Hunting Down `memdup_user` in `mm/util.c`**
Alright, so the task at hand is to locate the `memdup_user` function. My initial instinct is to go straight to `mm/util.c`. That's where I'd expect to find something of this nature β a utility function related to memory management, user-space interaction, and possibly duplication. The naming convention strongly suggests itβs involved in safely copying data from userspace. I'll mentally prepare myself for potential kernel debugging, because this function is an interesting target. Given the context, this sounds like a core function, so the code should be readable and well documented. Let's see if this is as straightforward as it seems or if I have to do some deeper digging to get the full picture.
|
| 442/2 |
2026/10/14 00:24 |
tool |
grepper |
0m
Args: map[Expression:memdup_user\( PathPrefixes:[mm/util.c]]
Results: map[Output:mm/util.c=206=subsys_initcall(init_user_buckets);
--
mm/util.c-216- */
mm/util.c:217:void *memdup_user(const void __user *src, size_t len)
mm/util.c-218-{
--
mm/util.c=232=EXPORT_SYMBOL(memdup_user);
--
mm/util.c-242- */
mm/util.c:243:void *vmemdup_user(const void __user *src, size_t len)
mm/util.c-244-{
--
mm/util.c=267=char *strndup_user(const char __user *s, long n)
--
mm/util.c-279-
mm/util.c:280: p = memdup_user(s, length);
mm/util.c-281-
]
|
| 443/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 57495
output: 33
thoughts: 20
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating `mm/util.c` Line 217 with `git blame`**
Okay, so I need to understand the history of a specific line of code β line 217 in `mm/util.c`. My initial thought is to grab `git blame` and drill down. I know exactly what I'm looking for: the context of that line. I'm hoping to quickly identify the author, the commit that introduced it, and ideally, some indication of *why* that particular code exists in its current form. Perhaps there's a related bug report or commit message that sheds light on a tricky edge case. Maybe it's a performance optimization that's gone stale, or a workaround for some ancient hardware quirk. Regardless, `git blame` is my go-to for starting this kind of forensic investigation within the codebase. It's the most efficient way to immediately trace back responsibility and understand the historical motivations behind a specific line of code. Time to fire it up and see what it tells me.
|
| 444/2 |
2026/10/14 00:24 |
tool |
git-blame |
0m
Args: map[End:230 File:mm/util.c Start:215]
Results: map[Output:50fd2f298bef9 215) * contiguous, to be freed by kfree().
610a77e04a8d9 216) */
610a77e04a8d9 217) void *memdup_user(const void __user *src, size_t len)
610a77e04a8d9 218) {
610a77e04a8d9 219) void *p;
610a77e04a8d9 220)
d73778e4b8675 221) p = kmem_buckets_alloc_track_caller(user_buckets, len, GFP_USER | __GFP_NOWARN);
610a77e04a8d9 222) if (!p)
610a77e04a8d9 223) return ERR_PTR(-ENOMEM);
610a77e04a8d9 224)
610a77e04a8d9 225) if (copy_from_user(p, src, len)) {
610a77e04a8d9 226) kfree(p);
610a77e04a8d9 227) return ERR_PTR(-EFAULT);
610a77e04a8d9 228) }
610a77e04a8d9 229)
610a77e04a8d9 230) return p;
]
|
| 445/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 58229
output: 28
thoughts: 20
Thoughts: Okay, here's my interpretation of what's going on, formatted as you requested:
**Deconstructing Commit 610a77e04a8d9**
Alright, let's dive into commit 610a77e04a8d9. Given my expertise, I'm already mentally processing this as a specific point in a development timeline. The exact nature of what I'm looking for depends on the context, of course β the codebase, the project's history, the specific tasks I'm currently focused on. But my mind is immediately going to start running through potential scenarios: What kind of modifications were likely made? Were we fixing a bug, adding a new feature, refactoring something, or maybe just making a configuration change? I'm already anticipating the typical clues: What was the commit message like? Did it follow our team's conventions? Were there related JIRA tickets or pull requests that might give additional context? I'm preparing to evaluate the impact β locally, on the wider system, and potentially on our users. I'll need to assess the scope of the change, identify any potential dependencies, and ultimately gauge the overall quality and maintainability of the modifications. The specifics will vary depending on the system, of course, but the analytical framework remains the same: I'm ready to evaluate and understand.
|
| 446/2 |
2026/10/14 00:24 |
tool |
git-show |
0m
Args: map[Commit:610a77e04a8d9]
Results: map[Output:commit 610a77e04a8d9fe8764dc484e2182fa251ce1cc2
Author: Li Zefan <lizf@cn.fujitsu.com>
Date: Tue Mar 31 15:23:16 2009 -0700
memdup_user(): introduce
I notice there are many places doing copy_from_user() which follows
kmalloc():
dst = kmalloc(len, GFP_KERNEL);
if (!dst)
return -ENOMEM;
if (copy_from_user(dst, src, len)) {
kfree(dst);
return -EFAULT
}
memdup_user() is a wrapper of the above code. With this new function, we
don't have to write 'len' twice, which can lead to typos/mistakes. It
also produces smaller code and kernel text.
A quick grep shows 250+ places where memdup_user() *may* be used. I'll
prepare a patchset to do this conversion.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Americo Wang <xiyou.wangcong@gmail.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/include/linux/string.h b/include/linux/string.h
index d18fc198aa2f..8852739f36df 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -12,6 +12,7 @@
#include <linux/stddef.h> /* for NULL */
extern char *strndup_user(const char __user *, long);
+extern void *memdup_user(const void __user *, size_t);
/*
* Include machine specific inline routines
diff --git a/mm/util.c b/mm/util.c
index 37eaccdf3054..7c122e49f769 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -69,6 +69,36 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
}
EXPORT_SYMBOL(kmemdup);
+/**
+ * memdup_user - duplicate memory region from user space
+ *
+ * @src: source address in user space
+ * @len: number of bytes to copy
+ *
+ * Returns an ERR_PTR() on failure.
+ */
+void *memdup_user(const void __user *src, size_t len)
+{
+ void *p;
+
+ /*
+ * Always use GFP_KERNEL, since copy_from_user() can sleep and
+ * cause pagefault, which makes it pointless to use GFP_NOFS
+ * or GFP_ATOMIC.
+ */
+ p = kmalloc_track_caller(len, GFP_KERNEL);
+ if (!p)
+ return ERR_PTR(-ENOMEM);
+
+ if (copy_from_user(p, src, len)) {
+ kfree(p);
+ return ERR_PTR(-EFAULT);
+ }
+
+ return p;
+}
+EXPORT_SYMBOL(memdup_user);
+
/**
* __krealloc - like krealloc() but don't free @p.
* @p: object to reallocate memory for.
]
|
| 447/2 |
2026/10/14 00:24 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 59546
output: 31
thoughts: 46
Thoughts: Here's my thought process, as if I were considering this myself:
**Investigating a `memdup_user` Change**
Hold on a second... I could have sworn `__GFP_NOWARN` wasn't part of `memdup_user` originally. That's a flag that's usually used for suppressing allocation failures, right? Interesting... I need to check the Git history. Let's fire up a CodeRegexp search. I'll search the relevant repository, looking specifically for commit messages or code changes that mention *both* `memdup_user` *and* `__GFP_NOWARN`. That should pinpoint when and why this flag was introduced. I'm assuming that this is going to show up in the history.
|
| 448/2 |
2026/10/14 00:25 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:memdup_user.*__GFP_NOWARN Count:5]
Results:
|
| 449/2 |
2026/10/14 00:35 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 59818
output: 37
thoughts: 18
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Investigating Memory Allocation with `GFP_NOWARN`**
Alright, let's dive in. I need to get a handle on where we're using `GFP_NOWARN`. This is usually a sign of something delicate β maybe a critical path, or an area where we really can't afford to trigger a warning message during allocation failures. The fact that it's important enough to investigate suggests a potential performance bottleneck, or perhaps a risk of silent data corruption if allocation fails. I'll start by checking `mm/util.c` because it's a likely candidate for core memory management utilities and often contains macros or helper functions dealing with allocation flags. I want to see how `GFP_NOWARN` is being used in context β what other flags are being combined with it? Are there any specific allocation paths or scenarios where it's prevalent? Understanding the surrounding code will clarify the intent and risk profile. I need to see if we are dealing with a design problem, an optimization, or maybe a potential bug. I can't just look at the line of code - I have to see it in context.
|
| 450/2 |
2026/10/14 00:35 |
tool |
git-log |
0m
Args: map[CodeRegexp:__GFP_NOWARN Count:5 PathPrefix:mm/util.c]
Results: map[Output:f1157db8b539 slab: Adjust placement of __kvmalloc_node_noprof
dd2a5b5514ab mm/util: make memdup_user_nul() similar to memdup_user()
590b9d576cae mm: kvmalloc: align kvrealloc() with krealloc()
d73778e4b867 mm/util: Use dedicated slab buckets for memdup_user()
0708a0afe291 mm: Consider __GFP_NOWARN flag for oversized kvmalloc() calls
]
|
| 451/2 |
2026/10/14 00:35 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 60272
output: 27
thoughts: 18
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and rendered in the first person:
**Analyzing Commit d73778e4b867**
Alright, let's take a look at this commit, d73778e4b867. My initial thought process is geared towards understanding the context and impact of this specific revision. I'll need to immediately start reviewing the changes. I'll be looking for potential regressions, performance implications, and adherence to the established coding standards, of course. I'll want to quickly gauge the scope β is this a minor bug fix, a significant feature addition, or something in between? I'll be mentally parsing the code diff to identify the critical parts. I'll automatically be assessing how this commit ties into the wider architectural context. Any immediate red flags jump out, Iβll be asking the standard βwhyβ questions. Are there any unusual techniques used? Does this introduce or remove any dependencies? Whatβs the rationale behind these changes? In short, my analysis will rapidly transition from an overview to a deep dive, all based on that commit hash.
|
| 452/2 |
2026/10/14 00:35 |
tool |
git-show |
0m
Args:
Results: map[Output:commit d73778e4b86755d527a0c6b249cde846770b2f66
Author: Kees Cook <kees@kernel.org>
Date: Mon Jul 1 12:13:03 2024 -0700
mm/util: Use dedicated slab buckets for memdup_user()
Both memdup_user() and vmemdup_user() handle allocations that are
regularly used for exploiting use-after-free type confusion flaws in
the kernel (e.g. prctl() PR_SET_VMA_ANON_NAME[1] and setxattr[2][3][4]
respectively).
Since both are designed for contents coming from userspace, it allows
for userspace-controlled allocation sizes. Use a dedicated set of kmalloc
buckets so these allocations do not share caches with the global kmalloc
buckets.
After a fresh boot under Ubuntu 23.10, we can see the caches are already
in active use:
# grep ^memdup /proc/slabinfo
memdup_user-8k 4 4 8192 4 8 : ...
memdup_user-4k 8 8 4096 8 8 : ...
memdup_user-2k 16 16 2048 16 8 : ...
memdup_user-1k 0 0 1024 16 4 : ...
memdup_user-512 0 0 512 16 2 : ...
memdup_user-256 0 0 256 16 1 : ...
memdup_user-128 0 0 128 32 1 : ...
memdup_user-64 256 256 64 64 1 : ...
memdup_user-32 512 512 32 128 1 : ...
memdup_user-16 1024 1024 16 256 1 : ...
memdup_user-8 2048 2048 8 512 1 : ...
memdup_user-192 0 0 192 21 1 : ...
memdup_user-96 168 168 96 42 1 : ...
Link: https://starlabs.sg/blog/2023/07-prctl-anon_vma_name-an-amusing-heap-spray/ [1]
Link: https://duasynt.com/blog/linux-kernel-heap-spray [2]
Link: https://etenal.me/archives/1336 [3]
Link: https://github.com/a13xp0p0v/kernel-hack-drill/blob/master/drill_exploit_uaf.c [4]
Signed-off-by: Kees Cook <kees@kernel.org>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
diff --git a/mm/util.c b/mm/util.c
index 28c5356b9f1c..29189f48ee04 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -198,6 +198,16 @@ char *kmemdup_nul(const char *s, size_t len, gfp_t gfp)
}
EXPORT_SYMBOL(kmemdup_nul);
+static kmem_buckets *user_buckets __ro_after_init;
+
+static int __init init_user_buckets(void)
+{
+ user_buckets = kmem_buckets_create("memdup_user", 0, 0, INT_MAX, NULL);
+
+ return 0;
+}
+subsys_initcall(init_user_buckets);
+
/**
* memdup_user - duplicate memory region from user space
*
@@ -211,7 +221,7 @@ void *memdup_user(const void __user *src, size_t len)
{
void *p;
- p = kmalloc_track_caller(len, GFP_USER | __GFP_NOWARN);
+ p = kmem_buckets_alloc_track_caller(user_buckets, len, GFP_USER | __GFP_NOWARN);
if (!p)
return ERR_PTR(-ENOMEM);
@@ -237,7 +247,7 @@ void *vmemdup_user(const void __user *src, size_t len)
{
void *p;
- p = kvmalloc(len, GFP_USER);
+ p = kmem_buckets_valloc(user_buckets, len, GFP_USER);
if (!p)
return ERR_PTR(-ENOMEM);
]
|
| 453/2 |
2026/10/14 00:35 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 61824
output: 41
thoughts: 77
Thoughts: Here's my analysis of the code change, from the perspective of an experienced kernel developer:
**Investigating a `kmalloc` Flag Change**
Okay, so I'm looking at this commit, `d73778e4b867`, and I notice a change in how `kmalloc` is being called. Before that commit, the code used `kmalloc_track_caller` with just `len` as the argument. Now, it's adding `GFP_USER | __GFP_NOWARN`. My immediate question is: when did those flags get introduced? They are important, so I need to find out when this change occurred. To figure this out quickly, I'm going to leverage `git log`. Specifically, I'll use `-S __GFP_NOWARN` to search the commit history for changes that *introduced* or *removed* references to that flag in `mm/util.c`. That should quickly pinpoint the commit (or commits) where this flag became relevant, and give me context on the rationale behind adding it, maybe even telling me who added the changes and why. From there, I can analyze the reasons for the changes and consider their impact on the system.
|
| 454/2 |
2026/10/14 00:35 |
tool |
git-log |
0m
Args: map[CodeRegexp:GFP_USER \| __GFP_NOWARN Count:5 PathPrefix:mm/util.c]
Results: map[Output:dd2a5b5514ab mm/util: make memdup_user_nul() similar to memdup_user()
d73778e4b867 mm/util: Use dedicated slab buckets for memdup_user()
6c8fcc096be9 mm: don't let userspace spam allocations warnings
]
|
| 455/2 |
2026/10/14 00:35 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 62289
output: 24
thoughts: 2036
Thoughts: **Root Cause Analysis and Commit Identification**
Okay, so the crash I'm looking at stems from a user-controlled allocation size in the DRM lease creation ioctl. Essentially, `drm_mode_create_lease_ioctl()` is vulnerable because it attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` via the `kmalloc` family in the `fill_object_idr()` function.
The problem, as I see it, is rooted in the lack of bounds checking on `object_count`, which comes directly from user space via `cl->object_count`. This value then dictates the size of the `objects` array allocated using `kzalloc_objs()`, which expands to `kmalloc` and family. The key is that `kmalloc` uses contiguous memory, and exceeding `MAX_PAGE_ORDER` (typically 4MB) triggers a warning. While the `object_ids` array, allocated with `memdup_array_user()` *could* fail silently if the requested size exceeds some threshold, it does not. The issue manifests where the smaller `object_ids` array allocation *succeeds*, but the subsequently larger `objects` array allocation *fails* because it needs a contiguous block larger than `MAX_PAGE_ORDER`.
The root cause is the lack of bounds check on `object_count` for the allocation size of the objects array.
Given this, I have to pinpoint the commit that introduced this vulnerability. My initial thought was `6c8fcc096be9`, because it added `__GFP_NOWARN` to `memdup_user()`, but that's a red herring. The problem isn't with `memdup_user()`, but with the `kmalloc`-family allocation of `objects` in `fill_object_idr()`.
So, which commit introduced the problem? My primary suspect is `62884cd386b8`, the commit that introduced the ioctl itself. That's the one that brought in the `object_count` from user space, the call to `fill_object_idr()` using `kcalloc`, and the `kfree()`. `4bb2d367a5a2` is not a concern, because it merely allowed an empty lease.
I'm now considering the overflow with the array size calculations. This might be what triggers the issue with `memdup_array_user()`, or some other subtle problem. Commit `69ef943dbc14` changes the `memdup_user()` and it mentions that before that commit, multiplication could overflow, but in the case presented it doesn't. And the code is now `memdup_array_user()`. So, is `memdup_array_user()` a problem? Let me check its definition.
Looking at the code, `memdup_array_user()` is literally just `memdup_user(src, array_size(n, size))`. So, that shouldn't introduce any new issues.
Based on this, it all goes back to `62884cd386b8`!
|
| 456/2 |
2026/10/14 00:36 |
tool |
codesearch-definition-source |
0m
Args: map[Name:memdup_array_user]
Results: map[SourceCode: 22: /**
23: * memdup_array_user - duplicate array from user space
24: * @src: source address in user space
25: * @n: number of array members to copy
26: * @size: size of one array member
27: *
28: * Return: an ERR_PTR() on failure. Result is physically
29: * contiguous, to be freed by kfree().
30: */
31: static inline __realloc_size(2, 3)
32: void *memdup_array_user(const void __user *src, size_t n, size_t size)
33: {
34: size_t nbytes;
35:
36: if (check_mul_overflow(n, size, &nbytes))
37: return ERR_PTR(-EOVERFLOW);
38:
39: return memdup_user(src, nbytes);
40: }
SourceFile:include/linux/string.h]
|
| 457/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 65317
output: 37
thoughts: 555
Thoughts: **Analyzing Potential Memory Allocation Vulnerabilities**
Okay, so `memdup_array_user` is just a straightforward wrapper for `memdup_user`, nothing interesting there. But hang on, I need to dig deeper. I'm seeing a pattern here with these commits: `69050f8d6d07` and `32a92f8c89326`. It looks like these just swapped `kcalloc` for `kzalloc_objs`, but functionally, they are the same under the hood, since `kzalloc_objs` expands to `kmalloc_array_noprof` which, with the provided flags, is identical to `kcalloc`. This change doesn't seem to be the root cause.
Now, let's go back and look at the commit that introduced lease support, specifically `62884cd386b876638720ef88374b31a84ca7ee5f`. This is where it gets interesting! We see an allocation using `kcalloc` of `struct drm_mode_object *` based on `object_count`, and the allocation size is based on user input, and it looks like no validation or limit was applied! This could very well be where the problem was introduced.
I need to investigate further. Are there any other relevant commits, especially in `drm_lease.c` or other related areas? Could `62884cd386b8` really be the culprit? I need to know.
Now, I'm thinking about `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` - was this a *new* warning that was introduced, or was it always a bug if `order > MAX_PAGE_ORDER` was allocated? If this check *is* new, that will help to solidify the window of the introduced bug. I should probably check `mm/page_alloc.c:5340` to confirm this.
|
| 458/2 |
2026/10/14 00:36 |
tool |
git-blame |
0m
Args: map[End:5350 File:mm/page_alloc.c Start:5330]
Results: map[Output:2fc4c1d51d878 5330) static inline bool alloc_order_allowed(gfp_t gfp, unsigned int order,
2fc4c1d51d878 5331) unsigned int alloc_flags)
2fc4c1d51d878 5332) {
2fc4c1d51d878 5333) if (alloc_flags & ALLOC_NOLOCK)
2fc4c1d51d878 5334) return pcp_allowed_order(order);
2fc4c1d51d878 5335)
2fc4c1d51d878 5336) /*
2fc4c1d51d878 5337) * There are several places where we assume that the order value is sane
2fc4c1d51d878 5338) * so bail out early if the request is out of bound.
2fc4c1d51d878 5339) */
2fc4c1d51d878 5340) return !(WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp));
2fc4c1d51d878 5341) }
2fc4c1d51d878 5342)
2fc4c1d51d878 5343) static inline bool alloc_nolock_allowed(void)
2fc4c1d51d878 5344) {
3a01af8281380 5345) if (!can_spin_trylock())
2fc4c1d51d878 5346) return false;
2fc4c1d51d878 5347)
2fc4c1d51d878 5348) /* Bailout, since _deferred_grow_zone() needs to take a lock */
2fc4c1d51d878 5349) if (deferred_pages_enabled())
2fc4c1d51d878 5350) return false;
]
|
| 459/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 66948
output: 27
thoughts: 19
Thoughts: Okay, here's my interpretation of that request, formatted as requested:
**Deconstructing Commit 2fc4c1d51d878**
Alright, let's dive into commit 2fc4c1d51d878. Given the limited context, I'm already formulating hypotheses. Without knowing the codebase, the project, or the surrounding history, I'm going to approach this with a critical eye. I'll be looking for clues β the commit message (if present), the diff itself, the file changes, and the likely impact. My mental checklist kicks in: Are we talking bug fix, new feature, refactor, or optimization? Based on the hash I may be able to glean information from the commit in question.
My instinct tells me to isolate the functional changes. I'll ignore cosmetic changes as much as possible. I'll look for any potential regressions introduced, any obvious performance bottlenecks, and whether the code adheres to established style guidelines and best practices. I'll need to assess the maintainability of any modifications. Was this a good commit, or am I going to want to refactor it.
I'll also keep in mind whether this code may be a candidate for more scrutiny as the project grows.
Essentially, I'm mentally preparing for a deep dive, ready to dissect the changes methodically and form a concise, expert opinion on their quality and implications.
|
| 460/2 |
2026/10/14 00:36 |
tool |
git-show |
0m
Args: map[Commit:2fc4c1d51d878]
Results: map[Output:commit 2fc4c1d51d878bcd615774d19a97dc29ac0ce970
Author: Brendan Jackman <brendan.jackman@linux.dev>
Date: Fri Jul 3 12:31:45 2026 +0000
mm/page_alloc: unify __alloc_frozen_pages[_nolock]_noprof()
Currently the core allocator code is controlled by ALLOC_NOLOCK, but the
main entry point function is significantly different from the normal
__alloc_frozen_pages_nolock(), this is tiring when reading the code.
Plumb the ALLOC_NOLOCK control one layer up in the call stack: create an
alloc_flags argument to __alloc_frozen_pages_nolock() (which is only
exposed to mm/) and then turn the nolock variant into a thin wrapper that
just sets that flag (as well as handling NUMA_NO_NODE, similar to how some
of the wrappers in gfp.h do).
For consistency, set ALLOC_WMARK_MIN explicitly in fastpath_alloc_flags
for the new ALLOC_NOLOCK path. This was already "done" silently in
__alloc_frozen_pages_nolock_noprof(): ALLOC_WMARK_MIN is 0.
Rationale that this doesn't change anything:
1. Simple bits: A bunch of the nolock-specific handling is just moved to
the new alloc_order_allowed(), alloc_nolock_allowed() and
gfp_nolock.
2. __alloc_frozen_pages_noprof() has some extra logic that wasn't
previously in the nolock variant:
a. Application of gfp_allowed_mask; this only affects early boot,
only flags that affect the slowpath get changed here, and the
nolock allocation path isn't allowed to the GFP_BOOT_MASK flags.
b. Application of current_gfp_context() - also only affects the
slowpath
3. The slowpath itself: this is now just explicitly skipped under
!ALLOC_NOLOCK.
Ulterior motive: adding an alloc_flags arg to the allocator's mm-internal
entrypoint can later be used to do more allocation customisation without
needing to create new GFP flags.
No functional change intended.
Link: https://lore.kernel.org/20260703-alloc-trylock-v5-5-c87b714e19d3@google.com
Signed-off-by: Brendan Jackman <jackmanb@google.com>
Reviewed-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
Acked-by: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 8ce6fe2a9a72..53c4e2ef8f6d 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1790,7 +1790,8 @@ static struct folio *alloc_buddy_frozen_folio(int order, gfp_t gfp_mask,
if (alloc_try_hard)
gfp_mask |= __GFP_RETRY_MAYFAIL;
- folio = (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmask);
+ folio = (struct folio *)__alloc_frozen_pages(gfp_mask, order, nid, nmask,
+ ALLOC_DEFAULT);
/*
* If we did not specify __GFP_RETRY_MAYFAIL, but still got a
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 9c740324f916..41d630f0ea82 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -2426,9 +2426,11 @@ static struct page *alloc_pages_preferred_many(gfp_t gfp, unsigned int order,
*/
preferred_gfp = gfp | __GFP_NOWARN;
preferred_gfp &= ~(__GFP_DIRECT_RECLAIM | __GFP_NOFAIL);
- page = __alloc_frozen_pages_noprof(preferred_gfp, order, nid, nodemask);
+ page = __alloc_frozen_pages_noprof(preferred_gfp, order, nid, nodemask,
+ ALLOC_DEFAULT);
if (!page)
- page = __alloc_frozen_pages_noprof(gfp, order, nid, NULL);
+ page = __alloc_frozen_pages_noprof(gfp, order, nid, NULL,
+ ALLOC_DEFAULT);
return page;
}
@@ -2476,7 +2478,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order,
*/
page = __alloc_frozen_pages_noprof(
gfp | __GFP_THISNODE | __GFP_NORETRY, order,
- nid, NULL);
+ nid, NULL, ALLOC_DEFAULT);
if (page || !(gfp & __GFP_DIRECT_RECLAIM))
return page;
/*
@@ -2488,7 +2490,7 @@ static struct page *alloc_pages_mpol(gfp_t gfp, unsigned int order,
}
}
- page = __alloc_frozen_pages_noprof(gfp, order, nid, nodemask);
+ page = __alloc_frozen_pages_noprof(gfp, order, nid, nodemask, ALLOC_DEFAULT);
if (unlikely(pol->mode == MPOL_INTERLEAVE ||
pol->mode == MPOL_WEIGHTED_INTERLEAVE) && page) {
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 85cee8a0031f..f47a84855507 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5222,7 +5222,7 @@ unsigned long alloc_pages_bulk_noprof(gfp_t gfp, int preferred_nid,
}
nr_account++;
- prep_new_page(page, 0, gfp, 0);
+ prep_new_page(page, 0, gfp, ALLOC_DEFAULT);
set_page_refcounted(page);
page_array[nr_populated++] = page;
}
@@ -5271,24 +5271,99 @@ void free_pages_bulk(struct page **page_array, unsigned long nr_pages)
}
}
+static inline bool alloc_order_allowed(gfp_t gfp, unsigned int order,
+ unsigned int alloc_flags)
+{
+ if (alloc_flags & ALLOC_NOLOCK)
+ return pcp_allowed_order(order);
+
+ /*
+ * There are several places where we assume that the order value is sane
+ * so bail out early if the request is out of bound.
+ */
+ return !(WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp));
+}
+
+static inline bool alloc_nolock_allowed(void)
+{
+ /*
+ * In PREEMPT_RT spin_trylock() will call raw_spin_lock() which is
+ * unsafe in NMI. If spin_trylock() is called from hard IRQ the current
+ * task may be waiting for one rt_spin_lock, but rt_spin_trylock() will
+ * mark the task as the owner of another rt_spin_lock which will
+ * confuse PI logic, so return immediately if called from hard IRQ or
+ * NMI.
+ *
+ * Note, irqs_disabled() case is ok. This function can be called
+ * from raw_spin_lock_irqsave region.
+ */
+ if (IS_ENABLED(CONFIG_PREEMPT_RT) && (in_nmi() || in_hardirq()))
+ return false;
+
+ /* On UP, spin_trylock() always succeeds even when it is locked */
+ if (!IS_ENABLED(CONFIG_SMP) && in_nmi())
+ return false;
+
+ /* Bailout, since _deferred_grow_zone() needs to take a lock */
+ if (deferred_pages_enabled())
+ return false;
+
+ return true;
+}
+
+/*
+ * GFP flags to set for ALLOC_NOLOCK i.e. alloc_pages_nolock().
+ *
+ * Do not specify __GFP_DIRECT_RECLAIM, since direct claim is not allowed.
+ * Do not specify __GFP_KSWAPD_RECLAIM either, since wake up of kswapd
+ * is not safe in arbitrary context.
+ *
+ * These two are the conditions for gfpflags_allow_spinning() being true.
+ *
+ * Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason
+ * to warn. Also warn would trigger printk() which is unsafe from
+ * various contexts. We cannot use printk_deferred_enter() to mitigate,
+ * since the running context is unknown.
+ *
+ * Specify __GFP_ZERO to make sure that call to kmsan_alloc_page() below
+ * is safe in any context. Also zeroing the page is mandatory for
+ * BPF use cases.
+ *
+ * Though __GFP_NOMEMALLOC is not checked in the code path below,
+ * specify it here to highlight that alloc_pages_nolock()
+ * doesn't want to deplete reserves.
+ */
+static const gfp_t gfp_nolock = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC |
+ __GFP_COMP;
+
/*
* This is the 'heart' of the zoned buddy allocator.
*/
struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,
- int preferred_nid, nodemask_t *nodemask)
+ int preferred_nid, nodemask_t *nodemask, unsigned int alloc_flags)
{
struct page *page;
- unsigned int fastpath_alloc_flags = ALLOC_WMARK_LOW;
gfp_t alloc_gfp; /* The gfp_t that was actually used for allocation */
struct alloc_context ac = { };
+ unsigned int fastpath_alloc_flags = alloc_flags;
- /*
- * There are several places where we assume that the order value is sane
- * so bail out early if the request is out of bound.
- */
- if (WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp))
+ /* Other flags could be supported later if needed. */
+ if (WARN_ON(alloc_flags & ~ALLOC_NOLOCK))
return NULL;
+ if (!alloc_order_allowed(gfp, order, alloc_flags))
+ return NULL;
+
+ if (alloc_flags & ALLOC_NOLOCK) {
+ VM_WARN_ON_ONCE(gfp & ~__GFP_ACCOUNT);
+ if (!alloc_nolock_allowed())
+ return NULL;
+ gfp |= gfp_nolock;
+ fastpath_alloc_flags |= ALLOC_WMARK_MIN;
+ } else {
+ fastpath_alloc_flags |= ALLOC_WMARK_LOW;
+ }
+
gfp &= gfp_allowed_mask;
/*
* Apply scoped allocation constraints. This is mainly about GFP_NOFS
@@ -5303,16 +5378,19 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,
&alloc_gfp, &fastpath_alloc_flags))
return NULL;
- /*
- * Forbid the first pass from falling back to types that fragment
- * memory until all local zones are considered.
- */
- fastpath_alloc_flags |= alloc_flags_nofragment(zonelist_zone(ac.preferred_zoneref), gfp);
+ if (!(alloc_flags & ALLOC_NOLOCK)) {
+ /*
+ * Forbid the first pass from falling back to types that
+ * fragment memory until all local zones are considered.
+ */
+ fastpath_alloc_flags |= alloc_flags_nofragment(
+ zonelist_zone(ac.preferred_zoneref), gfp);
+ }
fastpath_alloc_flags |= alloc_flags_nonblocking(gfp, order) & ALLOC_HIGHATOMIC;
- /* First allocation attempt */
+ /* First allocation attempt (or, for nolock, only attempt) */
page = get_page_from_freelist(alloc_gfp, order, fastpath_alloc_flags, &ac);
- if (likely(page))
+ if (likely(page) || (alloc_flags & ALLOC_NOLOCK))
goto out;
alloc_gfp = gfp;
@@ -5329,7 +5407,8 @@ struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order,
out:
if (memcg_kmem_online() && (gfp & __GFP_ACCOUNT) && page &&
unlikely(__memcg_kmem_charge_page(page, gfp, order) != 0)) {
- free_frozen_pages(page, order);
+ __free_frozen_pages(page, order,
+ alloc_flags & ALLOC_NOLOCK ? FPI_TRYLOCK : 0);
page = NULL;
}
@@ -5345,7 +5424,8 @@ struct page *__alloc_pages_noprof(gfp_t gfp, unsigned int order,
{
struct page *page;
- page = __alloc_frozen_pages_noprof(gfp, order, preferred_nid, nodemask);
+ page = __alloc_frozen_pages_noprof(gfp, order, preferred_nid, nodemask,
+ ALLOC_DEFAULT);
if (page)
set_page_refcounted(page);
return page;
@@ -7875,80 +7955,10 @@ static bool __free_unaccepted(struct page *page)
struct page *alloc_frozen_pages_nolock_noprof(gfp_t gfp_flags, int nid, unsigned int order)
{
- /*
- * Do not specify __GFP_DIRECT_RECLAIM, since direct claim is not allowed.
- * Do not specify __GFP_KSWAPD_RECLAIM either, since wake up of kswapd
- * is not safe in arbitrary context.
- *
- * These two are the conditions for gfpflags_allow_spinning() being true.
- *
- * Specify __GFP_NOWARN since failing alloc_pages_nolock() is not a reason
- * to warn. Also warn would trigger printk() which is unsafe from
- * various contexts. We cannot use printk_deferred_enter() to mitigate,
- * since the running context is unknown.
- *
- * Specify __GFP_ZERO to make sure that call to kmsan_alloc_page() below
- * is safe in any context. Also zeroing the page is mandatory for
- * BPF use cases.
- *
- * Though __GFP_NOMEMALLOC is not checked in the code path below,
- * specify it here to highlight that alloc_pages_nolock()
- * doesn't want to deplete reserves.
- */
- gfp_t alloc_gfp = __GFP_NOWARN | __GFP_ZERO | __GFP_NOMEMALLOC | __GFP_COMP
- | gfp_flags;
- unsigned int alloc_flags = ALLOC_NOLOCK;
- struct alloc_context ac = { };
- struct page *page;
-
- VM_WARN_ON_ONCE(gfp_flags & ~__GFP_ACCOUNT);
- /*
- * In PREEMPT_RT spin_trylock() will call raw_spin_lock() which is
- * unsafe in NMI. If spin_trylock() is called from hard IRQ the current
- * task may be waiting for one rt_spin_lock, but rt_spin_trylock() will
- * mark the task as the owner of another rt_spin_lock which will
- * confuse PI logic, so return immediately if called from hard IRQ or
- * NMI.
- *
- * Note, irqs_disabled() case is ok. This function can be called
- * from raw_spin_lock_irqsave region.
- */
- if (IS_ENABLED(CONFIG_PREEMPT_RT) && (in_nmi() || in_hardirq()))
- return NULL;
-
- /* On UP, spin_trylock() always succeeds even when it is locked */
- if (!IS_ENABLED(CONFIG_SMP) && in_nmi())
- return NULL;
-
- if (!pcp_allowed_order(order))
- return NULL;
-
- /* Bailout, since _deferred_grow_zone() needs to take a lock */
- if (deferred_pages_enabled())
- return NULL;
-
if (nid == NUMA_NO_NODE)
nid = numa_node_id();
- prepare_alloc_pages(alloc_gfp, order, nid, NULL, &ac,
- &alloc_gfp, &alloc_flags);
-
- /*
- * Best effort allocation from percpu free list.
- * If it's empty attempt to spin_trylock zone->lock.
- */
- page = get_page_from_freelist(alloc_gfp, order, alloc_flags, &ac);
-
- /* Unlike regular alloc_pages() there is no __alloc_pages_slowpath(). */
-
- if (memcg_kmem_online() && page && (gfp_flags & __GFP_ACCOUNT) &&
- unlikely(__memcg_kmem_charge_page(page, alloc_gfp, order) != 0)) {
- __free_frozen_pages(page, order, FPI_TRYLOCK);
- page = NULL;
- }
- trace_mm_page_alloc(page, order, alloc_gfp, ac.migratetype);
- kmsan_alloc_page(page, order, alloc_gfp);
- return page;
+ return __alloc_frozen_pages_noprof(gfp_flags, order, nid, NULL, ALLOC_NOLOCK);
}
/**
* alloc_pages_nolock - opportunistic reentrant allocation from any context
diff --git a/mm/page_alloc.h b/mm/page_alloc.h
index 3250d44f9645..a4f4b325381a 100644
--- a/mm/page_alloc.h
+++ b/mm/page_alloc.h
@@ -11,6 +11,7 @@
#include <linux/nodemask.h>
#include <linux/types.h>
+#define ALLOC_DEFAULT 0
/* The ALLOC_WMARK bits are used as an index to zone->watermark */
#define ALLOC_WMARK_MIN WMARK_MIN
#define ALLOC_WMARK_LOW WMARK_LOW
@@ -219,7 +220,7 @@ extern bool free_pages_prepare(struct page *page, unsigned int order);
extern int user_min_free_kbytes;
struct page *__alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order, int nid,
- nodemask_t *nodemask);
+ nodemask_t *nodemask, unsigned int alloc_flags);
#define __alloc_frozen_pages(...) \
alloc_hooks(__alloc_frozen_pages_noprof(__VA_ARGS__))
void free_frozen_pages(struct page *page, unsigned int order);
@@ -230,7 +231,8 @@ struct page *alloc_frozen_pages_noprof(gfp_t, unsigned int order);
#else
static inline struct page *alloc_frozen_pages_noprof(gfp_t gfp, unsigned int order)
{
- return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL);
+ return __alloc_frozen_pages_noprof(gfp, order, numa_node_id(), NULL,
+ ALLOC_DEFAULT);
}
#endif
diff --git a/mm/slub.c b/mm/slub.c
index 1362a1f8f05c..85599d227b9b 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3264,7 +3264,8 @@ static inline struct slab *alloc_slab_page(gfp_t flags, int node,
else if (node == NUMA_NO_NODE)
page = alloc_frozen_pages(flags, order);
else
- page = __alloc_frozen_pages(flags, order, node, NULL);
+ page = __alloc_frozen_pages(flags, order, node, NULL,
+ ALLOC_DEFAULT);
if (!page)
return NULL;
@@ -5274,7 +5275,8 @@ static void *___kmalloc_large_node(size_t size, gfp_t flags, int node)
if (node == NUMA_NO_NODE)
page = alloc_frozen_pages_noprof(flags, order);
else
- page = __alloc_frozen_pages_noprof(flags, order, node, NULL);
+ page = __alloc_frozen_pages_noprof(flags, order, node, NULL,
+ ALLOC_DEFAULT);
if (page) {
ptr = page_address(page);
]
|
| 461/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 72939
output: 21
thoughts: 274
Thoughts: **My Analysis of a Potential Kernel Vulnerability**
Okay, so before commit `2fc4c1d51d878`, the code snippet related to memory allocation sanity checks in the kernel was already present:
```c
/*
* There are several places where we assume that the order value is sane
* so bail out early if the request is out of bound.
*/
if (WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp))
return NULL;
```
This is crucial. We're already checking for `order > MAX_PAGE_ORDER` with `WARN_ON_ONCE_GFP`, which is good practice. The core issue here is that any function that calls `page_alloc` with an `order` greater than `MAX_PAGE_ORDER` *without* the `__GFP_NOWARN` flag will trigger a warning. That in itself is not an issue.
However, a warning triggered by user-controllable input *could* indicate a denial-of-service (DOS) vulnerability. My instincts tell me that it's probably an ioctl, and if that's the case, we're looking at a bug, and my suspicion is pointing to `drivers/gpu/drm/drm_lease.c`! I know the DRI code well, and user access there is a common place to find issues.
Now, let's slow down and be methodical. The first thing I should do is check the `Fixes:` line in similar commits or other commits within the DRM lease subsystem. This will quickly tell me if this issue has been previously addressed. It's a key first step.
Next, I need to know: has there been an *official* upstream commit that addresses this specific bug? I'll search the git log, the Linux kernel mailing list (lore), and carefully scrutinize commit messages, looking for either the text of the patch itself or any explanation that seems relevant.
Finally, just in case, I should do some sleuthing. I'll grep the entire kernel source for `vmemdup_array_user`. This will help determine where this user-space memory duplication function was added and possibly narrow down where it is used. This can help with tracking down how the user might be able to influence the `order` parameter.
|
| 462/2 |
2026/10/14 00:36 |
tool |
grepper |
0m
Args: map[Expression:vmemdup_array_user]
Results: map[Output:arch/x86/kvm/cpuid.c=590=int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu,
--
arch/x86/kvm/cpuid.c-601- if (cpuid->nent) {
arch/x86/kvm/cpuid.c:602: e = vmemdup_array_user(entries, cpuid->nent, sizeof(*e));
arch/x86/kvm/cpuid.c-603- if (IS_ERR(e))
--
arch/x86/kvm/cpuid.c=635=int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
--
arch/x86/kvm/cpuid.c-645- if (cpuid->nent) {
arch/x86/kvm/cpuid.c:646: e2 = vmemdup_array_user(entries, cpuid->nent, sizeof(*e2));
arch/x86/kvm/cpuid.c-647- if (IS_ERR(e2))
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c=164=amdgpu_bo_create_list_entry_array(struct drm_amdgpu_bo_list_in *in)
--
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-174-
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c:175: return vmemdup_array_user(uptr, bo_number,
drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c-176- sizeof(struct drm_amdgpu_bo_list_entry));
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c=179=static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,
--
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-219-
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:220: p->chunks[i].kdata = vmemdup_array_user(u64_to_user_ptr(user_chunk.chunk_data),
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c-221- size,
--
drivers/gpu/drm/drm_gem.c=832=int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
--
drivers/gpu/drm/drm_gem.c-847-
drivers/gpu/drm/drm_gem.c:848: handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
drivers/gpu/drm/drm_gem.c-849- if (IS_ERR(handles)) {
--
drivers/tty/vt/consolemap.c=632=int con_set_unimap(struct vc_data *vc, ushort ct, struct unipair __user *list)
--
drivers/tty/vt/consolemap.c-640-
drivers/tty/vt/consolemap.c:641: struct unipair *unilist __free(kvfree) = vmemdup_array_user(list, ct, sizeof(*unilist));
drivers/tty/vt/consolemap.c-642- if (IS_ERR(unilist))
--
include/linux/string.h=32=void *memdup_array_user(const void __user *src, size_t n, size_t size)
--
include/linux/string.h-42-/**
include/linux/string.h:43: * vmemdup_array_user - duplicate array from user space
include/linux/string.h-44- * @src: source address in user space
--
include/linux/string.h=51=static inline __realloc_size(2, 3)
include/linux/string.h:52:void *vmemdup_array_user(const void __user *src, size_t n, size_t size)
include/linux/string.h-53-{
--
virt/kvm/kvm_main.c=5177=static long kvm_vm_ioctl(struct file *filp,
--
virt/kvm/kvm_main.c-5344- urouting = argp;
virt/kvm/kvm_main.c:5345: entries = vmemdup_array_user(urouting->entries,
virt/kvm/kvm_main.c-5346- routing.nr, sizeof(*entries));
]
|
| 463/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 74948
output: 44
thoughts: 35
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating Gem Object Creation and User-Space Interaction**
Alright, let's dive in. I'm trying to trace the lifecycle of DRM GEM objects within the kernel, specifically focusing on when they're looked up or initialized from user-space memory. The goal is to pinpoint potential areas for optimization, security analysis, or simply to understand the object management flow more deeply. I need to see precisely when `drm_gem_objects_lookup` or `vmemdup_array_user` are invoked within `drm_gem.c`. These two functions are key indicators: `drm_gem_objects_lookup` suggests a retrieval of pre-existing GEM objects, which implies shared memory access, while `vmemdup_array_user` is a strong signal that user space data is being copied into kernel structures, either to create new or initialize existing objects. I expect that tracking those calls will lead me toward areas which have potential performance and security implications.
|
| 464/2 |
2026/10/14 00:36 |
tool |
git-log |
0m
Error:
Args: map[Count:5 PathPrefix:drivers/gpu/drm/drm_gem.c SymbolName:drm_gem_objects_lookup]
Results:
|
| 465/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 75266
output: 44
thoughts: 15
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person:
**Analyzing the DRM GEM Commit**
Alright, let's dive in. My mind is immediately drawn to the commit related to `drm_gem.c` with the `SourcePath` β essentially, I'm keen to see what's being done at the core of the Direct Rendering Manager's Graphics Execution Manager (GEM) layer. This immediately raises a few questions: Is this a bug fix, performance optimization, or a functional addition? The context of the change is going to be crucial here.
Specifically, I'm thinking:
* **Sourcepath**: What's the context for this path? Is it for debug, tracing, or perhaps a new driver-specific implementation? Is it a way to more specifically deal with an error?
* **DRM GEM:** What part of DRM GEM is being affected? Are we talking about object allocation/management, fencing, eviction, or something deeper, like memory pinning or mapping? I hope this isn't just a basic refactoring.
I need to quickly assess the impact and novelty of this change. Is this a common pattern, or is it an edge case being addressed? How does this change interact with the rest of the DRM stack, particularly the memory manager? Does the change touch user-space APIs in any way?
I'll be looking closely at the diff. I'll need to immediately grok the code that's added or removed. What are the key data structures involved? Is it thread-safe? The quality of the commit message is critical, of course, because that's where I expect to find the rationale and context for the change. I hope this commit isn't introducing subtle regressions. Let's see...
|
| 466/2 |
2026/10/14 00:36 |
tool |
git-log |
0m
Args: map[Count:5 SourcePath:drivers/gpu/drm/drm_gem.c SymbolName:drm_gem_objects_lookup]
Results: map[Output:8b85987d3cf5 Merge drm/drm-next into drm-misc-next
dbce431756f8 drm/gem: Make drm_gem_objects_lookup() self-cleaning on failure v6
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
922682d48d62 drm/gem: Correct error condition in drm_gem_objects_lookup
cb77b79abf5f drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
]
|
| 467/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 75861
output: 25
thoughts: 17
Thoughts: Okay, here's my interpretation of that request, formatted as requested:
**Deconstructing `cb77b79abf5f`**
Alright, let's dive into this specific hash, `cb77b79abf5f`. My initial instinct is to treat this as potentially something critical. Given the context, this is most likely a commit hash, a transaction ID, or some sort of unique identifier within a system. I need to understand its significance. Is it from a version control system? A database? Is this a public identifier or a private one? The format itself suggests a hexadecimal string, which is common for these types of identifiers, but I can't jump to conclusions. I need to consider all possibilities and I need to start figuring out what to do with this. I'll need to know which platform or system this belongs to. I might need to run it against a database, a repository, or a search engine. The specifics here are key to uncovering its meaning, and where it fits into the broader picture.
|
| 468/2 |
2026/10/14 00:36 |
tool |
git-show |
0m
Args:
Results: map[Output:commit cb77b79abf5ff8f4af07f7ebef196a003c826b7a
Author: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Date: Wed Nov 12 09:27:32 2025 +0000
drm/gem: Use vmemdup_array_user in drm_gem_objects_lookup
Use a helper to shrink the code and separate the user and kernel slabs for
better security.
While at it lets remove the useless debug message.
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Reviewed-by: AndrΓ© Almeida <andrealmeid@igalia.com>
Signed-off-by: Tvrtko Ursulin <tursulin@ursulin.net>
Link: https://lore.kernel.org/r/20251112092732.23584-1-tvrtko.ursulin@igalia.com
diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c
index a1a9c828938b..68168d58a7c8 100644
--- a/drivers/gpu/drm/drm_gem.c
+++ b/drivers/gpu/drm/drm_gem.c
@@ -783,7 +783,6 @@ static int objects_lookup(struct drm_file *filp, u32 *handle, int count,
int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
int count, struct drm_gem_object ***objs_out)
{
- struct drm_device *dev = filp->minor->dev;
struct drm_gem_object **objs;
u32 *handles;
int ret;
@@ -798,15 +797,9 @@ int drm_gem_objects_lookup(struct drm_file *filp, void __user *bo_handles,
*objs_out = objs;
- handles = kvmalloc_array(count, sizeof(u32), GFP_KERNEL);
- if (!handles) {
- ret = -ENOMEM;
- goto out;
- }
-
- if (copy_from_user(handles, bo_handles, count * sizeof(u32))) {
- ret = -EFAULT;
- drm_dbg_core(dev, "Failed to copy in GEM handles\n");
+ handles = vmemdup_array_user(bo_handles, count, sizeof(u32));
+ if (IS_ERR(handles)) {
+ ret = PTR_ERR(handles);
goto out;
}
]
|
| 469/2 |
2026/10/14 00:36 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 76839
output: 42
thoughts: 2476
Thoughts: **Root Cause Analysis and Patch Verification**
Okay, let's break this down. The kernel is crashing because a user-controlled value, `object_count`, is not properly bounded when used to allocate a contiguous memory block in the DRM lease creation ioctl. This leads to an attempted allocation order exceeding `MAX_PAGE_ORDER`, specifically when calling `kzalloc_objs` (which expands to a `kmalloc`-family call) inside `fill_object_idr`. The `object_count` variable comes directly from userspace, specifically from the `drm_mode_create_lease` struct in `drm_mode_create_lease_ioctl`, and previously lacked a maximum bound.
Now, let's analyze this patch. It introduces a check: `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))`. This looks like the solution! It's an integer overflow check to prevent `object_count` from becoming too large and causing an enormous allocation. This check is added inside the `drm_mode_create_lease_ioctl` function, before the allocation occurs. This change is a good start.
The patch also changed:
- `kzalloc_objs` to `kvzalloc_objs` (and `kfree` to `kvfree`). `kvzalloc` should prevent this issue.
- `memdup_array_user` to `vmemdup_array_user`. The `vmemdup_array_user` does bounds checking.
Now, let's confirm the code history. I know that the `fill_object_idr` function, and its allocations, were introduced in commit `62884cd386b8`. This initial commit used `kcalloc` to allocate `objects` and `memdup_user` for `object_ids`. Subsequent commits then modified the allocations as described previously in this patch.
I also see that `object_count` was *not* explicitly checked against a maximum at any point before this patch, by examining the Git log with `-S object_count`. This confirms the root cause: an unbounded `object_count` allowed the allocation size to become too large. It's also interesting to trace the evolution of `memdup_user` and `kcalloc` into their current forms.
The changes in this patch seem correct: the integer overflow check on `object_count`, and the use of the appropriate `kvzalloc/vmemdup_array_user` functions, should prevent this crash.
|
| 470/2 |
2026/10/14 00:37 |
tool |
git-log |
0m
Args: map[CodeRegexp:object_count Count:20 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
f37d63e219c3 drm_lease.c: copy user-array safely
4bb2d367a5a2 drm/lease: allow empty leases
69ef943dbc14 drm: Use array_size() when creating lease
968029057192 drm/lease: look at ->universal_planes only once
a0c1af46e9d7 drm/lease: debug output for lease creation
62884cd386b8 drm: Add four ioctls for managing drm mode object leases [v7]
]
|
| 471/2 |
2026/10/14 00:37 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 80106
output: 27
thoughts: 477
Thoughts: **Analyzing the Scope of `object_count` Usage**
Okay, so `object_count` has only popped up in these eight commits. That's a manageable set to review, and it's good practice to ensure I understand its behavior across the codebase. Let's delve into each one:
1. `32a92f8c8932`: This commit is simply refactoring, shifting from `kzalloc_objs` with explicit `GFP_KERNEL` to a default parameter. No functional changes here, the underlying memory allocation logic or flags aren't altered by this. That's straightforward.
2. `69050f8d6d07`: This looks like another straightforward replacement for `kcalloc` with `kzalloc_objs` for non-scalar types. Again, no modifications to the allocation logic, size calculation is identical. Okay, moving on.
3. `f37d63e219c3`: It seems like it's a safe replacement. `memdup_user` is switched to `memdup_array_user`. There is no change in logic, which is great to see.
4. `4bb2d367a5a2`: This is where things get a bit more interesting, though it is not too critical. A check related to `object_count` being zero was removed, and a condition check was added. The core functionality shouldn't be impacted with large values of `object_count`. This is a fine change.
5. `69ef943dbc14`: Aha, another use of `array_size`. This commit is just a small refactor to be clearer.
6. `968029057192`: Now, I want to see what this commit is all about...
|
| 472/2 |
2026/10/14 00:37 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 968029057192e46dd78e807b81c2aba2d7648c38
Author: Simona Vetter <simona.vetter@ffwll.ch>
Date: Mon Nov 5 11:12:11 2018 +0100
drm/lease: look at ->universal_planes only once
It's lockless, and userspace might chance it underneath us. That's not
really a problem, all userspace gets is a slightly dysfunctional
lease with the current code. But this might change, and gcc might
decide to reload a few too many times, and then boom. So better safe
than sorry.
v2: Remove the now unused lessor_priv argument from validate_lease()
(Keith).
v3: Actually add everything ... silly me.
Cc: Keith Packard <keithp@keithp.com>
Cc: Dave Airlie <airlied@gmail.com>
Acked-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20181105101211.22737-1-daniel.vetter@ffwll.ch
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 4cfd8fe25536..3b367e07c87e 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -353,9 +353,9 @@ void drm_lease_revoke(struct drm_master *top)
}
static int validate_lease(struct drm_device *dev,
- struct drm_file *lessor_priv,
int object_count,
- struct drm_mode_object **objects)
+ struct drm_mode_object **objects,
+ bool universal_planes)
{
int o;
int has_crtc = -1;
@@ -372,14 +372,14 @@ static int validate_lease(struct drm_device *dev,
if (objects[o]->type == DRM_MODE_OBJECT_CONNECTOR && has_connector == -1)
has_connector = o;
- if (lessor_priv->universal_planes) {
+ if (universal_planes) {
if (objects[o]->type == DRM_MODE_OBJECT_PLANE && has_plane == -1)
has_plane = o;
}
}
if (has_crtc == -1 || has_connector == -1)
return -EINVAL;
- if (lessor_priv->universal_planes && has_plane == -1)
+ if (universal_planes && has_plane == -1)
return -EINVAL;
return 0;
}
@@ -393,6 +393,8 @@ static int fill_object_idr(struct drm_device *dev,
struct drm_mode_object **objects;
u32 o;
int ret;
+ bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
+
objects = kcalloc(object_count, sizeof(struct drm_mode_object *),
GFP_KERNEL);
if (!objects)
@@ -421,7 +423,7 @@ static int fill_object_idr(struct drm_device *dev,
}
}
- ret = validate_lease(dev, lessor_priv, object_count, objects);
+ ret = validate_lease(dev, object_count, objects, universal_planes);
if (ret) {
DRM_DEBUG_LEASE("lease validation failed\n");
goto out_free_objects;
@@ -448,7 +450,7 @@ static int fill_object_idr(struct drm_device *dev,
object_id, ret);
goto out_free_objects;
}
- if (obj->type == DRM_MODE_OBJECT_CRTC && !lessor_priv->universal_planes) {
+ if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
struct drm_crtc *crtc = obj_to_crtc(obj);
ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
if (ret < 0) {
]
|
| 473/2 |
2026/10/14 00:37 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 82223
output: 26
thoughts: 50
Thoughts: Okay, let's dive into this commit, `a0c1af46e9d7`. I need to understand what this "drm/lease: debug output for lease creation" actually entails. It sounds like it's adding some logging to the lease creation process within the DRM (Direct Rendering Manager) subsystem.
So, I need to get into the details of this change. I'll need to analyze the patch to see exactly what debug output has been added, and where. I'll be looking for the specific `printk` calls, the level of logging, and the information being dumped. I'll want to assess the impact on performance and identify if there is any potential for sensitive data being exposed. I should check how this output relates to other existing debug mechanisms and whether it integrates with the overall DRM debugging strategy. This is a critical area for ensuring smooth operation of graphics drivers, so any additions should be carefully evaluated for their utility, performance impact, and appropriateness. I'll also want to determine the context. Is this for development, or is it going into a release build? If the latter, are there conditional compilation macros to disable it in production?
I'm ready to dig into the diff and get to the bottom of this.
|
| 474/2 |
2026/10/14 00:37 |
tool |
git-show |
0m
Args:
Results: map[Output:commit a0c1af46e9d71fdae7df904b91542ce2518382a1
Author: Simona Vetter <simona.vetter@ffwll.ch>
Date: Fri Nov 2 14:25:41 2018 +0100
drm/lease: debug output for lease creation
I spent a bit of time scratching heads and figuring out why the igts
don't work. Probably useful to keep this work.
Cc: Keith Packard <keithp@keithp.com>
Cc: Dave Airlie <airlied@gmail.com>
Acked-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20181102132543.16486-1-daniel.vetter@ffwll.ch
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 977f069f6d90..4cfd8fe25536 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -415,14 +415,17 @@ static int fill_object_idr(struct drm_device *dev,
}
if (!drm_mode_object_lease_required(objects[o]->type)) {
+ DRM_DEBUG_KMS("invalid object for lease\n");
ret = -EINVAL;
goto out_free_objects;
}
}
ret = validate_lease(dev, lessor_priv, object_count, objects);
- if (ret)
+ if (ret) {
+ DRM_DEBUG_LEASE("lease validation failed\n");
goto out_free_objects;
+ }
/* add their IDs to the lease request - taking into account
universal planes */
@@ -505,15 +508,21 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EOPNOTSUPP;
/* Do not allow sub-leases */
- if (lessor->lessor)
+ if (lessor->lessor) {
+ DRM_DEBUG_LEASE("recursive leasing not allowed\n");
return -EINVAL;
+ }
/* need some objects */
- if (cl->object_count == 0)
+ if (cl->object_count == 0) {
+ DRM_DEBUG_LEASE("no objects in lease\n");
return -EINVAL;
+ }
- if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK)))
+ if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
+ DRM_DEBUG_LEASE("invalid flags\n");
return -EINVAL;
+ }
object_count = cl->object_count;
@@ -528,6 +537,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
object_count, object_ids);
kfree(object_ids);
if (ret) {
+ DRM_DEBUG_LEASE("lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
return ret;
}
]
|
| 475/2 |
2026/10/14 00:37 |
llm |
fixes-finder |
0m
Model:
Tokens:
input: 83502
output: 53
thoughts: 1764
Thoughts: **Analysis of the Unbounded Allocation in DRM Lease Creation**
Okay, let's break this down. My initial focus is on commit `62884cd386b8` ("drm: Add four ioctls for managing drm mode object leases [v7]"). This commit is where `drm_mode_create_lease_ioctl` and `fill_object_idr` were introduced. I immediately see the direct assignment of `cl->object_count` to `object_count`: `object_count = cl->object_count;` and then `object_ids = memdup_user(...)`, followed by a call to `fill_object_idr()`. Inside `fill_object_idr()`, `objects = kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL);` is called.
The key observation is that when `object_count` is large (say, 1,000,000), this `objects` allocation requests an order 11 memory block, which exceeds `MAX_PAGE_ORDER` and triggers a warning because `kcalloc()` does not have the `__GFP_NOWARN` flag. The memory is then freed with `kfree(objects);`. This looks like a potential vulnerability due to the user-controlled size.
I needed to make sure I had the right commit, so I quickly double-checked the commit hash. It is indeed `62884cd386b876638720ef88374b31a84ca7ee5f`, which is the one I wanted. I initially wondered if `2ed077e467eedb033032bc4b6e349365517662d6` might be it but a quick `git log -S fill_object_idr` check shows it's not related. I verified with `git log` that the commit title, the changes, and the hash all match.
The next step was to consider if other commits, such as `f37d63e219c3` (which changed `memdup_user` to `memdup_array_user`), might have introduced this issue. The explanation states that `memdup_array_user()` *uses* `memdup_user()`, which can silently fail if allocation is too big (using `__GFP_NOWARN`). However, the real problem is the subsequent allocation of the `objects` array using `kcalloc()`. I looked at previous commits and confirmed that, before `f37d63e219c3`, the problematic `memdup_user` and `kcalloc` calls were already present.
I checked earlier versions and verified that the unbounded allocation issue has existed from the very beginning, with the introduction of `drm_mode_create_lease_ioctl` and `fill_object_idr` in commit `62884cd386b8`.
The bug description confirms this: the unbounded user-controlled allocation size in the DRM lease creation ioctl is the source, and `object_count` comes directly from the user-space and is not checked. That is, the bug was introduced when the DRM lease creation ioctl was first written!
Therefore, I'm confident that the root cause lies within commit `62884cd386b876638720ef88374b31a84ca7ee5f`. I then re-confirmed the commit details: `drm: Add four ioctls for managing drm mode object leases [v7]` by Keith Packard.
|
| 476/2 |
2026/10/14 00:37 |
tool |
set-results |
0m
Args: map[FixesHash:62884cd386b876638720ef88374b31a84ca7ee5f]
Results: map[FixesHash:62884cd386b876638720ef88374b31a84ca7ee5f]
|
| 477/1 |
2026/10/14 00:37 |
action |
format-fixes |
0m
Results: map[Fixes:map[AuthorEmail:keithp@keithp.com AuthorName:Keith Packard Hash:62884cd386b876638720ef88374b31a84ca7ee5f Title:drm: Add four ioctls for managing drm mode object leases [v7]]]
|
| 478/1 |
2026/10/14 00:37 |
action |
get-maintainers |
0m
Results: map[Recipients:[map[Email:airlied@gmail.com Name:David Airlie To:true] map[Email:dri-devel@lists.freedesktop.org Name: To:true] map[Email:linux-kernel@vger.kernel.org Name: To:false] map[Email:maarten.lankhorst@linux.intel.com Name:Maarten Lankhorst To:true] map[Email:mripard@kernel.org Name:Maxime Ripard To:true] map[Email:simona@ffwll.ch Name:Simona Vetter To:true] map[Email:tzimmermann@suse.de Name:Thomas Zimmermann To:true] map[Email:keithp@keithp.com Name:Keith Packard To:true]]]
|
| 479/1 |
2026/10/14 00:37 |
action |
get-recent-commits |
0m
Results: map[RecentCommits:Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
drm_lease.c: copy user-array safely
drm: Remove unnecessary include statements for drm_crtc_helper.h
drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
drm/lease: allow empty leases
drm: clean up unused kerneldoc in drm_lease.c
drm: clarify usage of drm leases
drm: protect drm_master pointers in drm_lease.c
drm: Don't include drm_legacy.h in drm_lease.c
drm : Insert blank lines after declarations.
drm/lease: fix WARNING in idr_destroy
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
drm: drop use of drmP.h in drm/*
drm/lease: Check for lessor outside of locks
drm/lease: Drop recursive leads checks
drm/leases: Drop object_id validation for negative ids
drm: Use array_size() when creating lease
drm: Rename crtc_idr as object_idr to KMS cleanups
drm/lease: Send a distinct uevent
]
|
| 480/1 |
2026/10/14 00:37 |
agent |
description-generator |
2m
Model:
Instruction:
You are an experienced Linux kernel developer tasked with writing a commit description for
a kernel bug fixing commit. The description should start with a one-line summary,
and then include description of the bug being fixed, and how it's fixed by the provided patch.
The one-line summary should describe the change being made, rather than mention the tool that
detected the bug.
The description must not contain lines starting with '#' because they will dropped by git as comments.
The description must not contain lines starting with '--' or '---' (including inline code diffs)
because they may confuse git/patch utilities.
Your final reply should contain only the text of the commit description.
The one-line summary must be not longer than 72 characters.
IMPORTANT: Do not wrap lines manually (e.g., at 80 characters); we will reformat the text
automatically, so keep paragraphs as single lines without newlines.
Generally try to phrase the description without mentioning syzkaller
(avoid phrases like "the bug was triggered by syzkaller" or "the bug was triggered by fuzzer", etc).
How the bug was triggered is generally an irrelevant detail.
Any bug triggered by a fuzzer can also be triggered by a malicious user, or a buggy program.
If the crash is reported by a sanitizer (e.g., KASAN, KMSAN, lockdep), include the relevant
parts of the sanitizer output to illustrate the problem. Exclude less relevant sections,
as the stack trace can be very long. Describe the execution path that leads to the manifestation
of the kernel bug.
If the patch removes the WARN_ON macro, refer to the fact that WARN_ON
must not be used for conditions that can legitimately happen, and that pr_err
should be used instead if necessary.
Don't assume that panic_on_warn is set, and that WARNINGs are fatal.
While panic_on_warn may be set when the bug was reproduced, it's generally not set on production systems.
Prefer calling several tools at the same time to save round-trips.
Prompt:
The crash that corresponds to the bug is:
------------[ cut here ]------------
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline], CPU#1: syz.0.17/7032
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397, CPU#1: syz.0.17/7032
Modules linked in:
CPU: 1 UID: 0 PID: 7032 Comm: syz.0.17 Not tainted syzkaller #1 PREEMPT
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/14/2026
pstate: 63400005 (nZCv daif +PAN -UAO +TCO +DIT -SSBS BTYPE=--)
pc : alloc_order_allowed mm/page_alloc.c:5340 [inline]
pc : __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
lr : __alloc_frozen_pages_noprof+0xa8/0x640 mm/page_alloc.c:5388
sp : ffff80009d2e7580
x29: ffff80009d2e7650 x28: ffff700013a5cf18 x27: ffff80009d2e75a0
x26: 1ffff0001302e474 x25: dfff800000000000 x24: ffff700013a5ceb4
x23: 0000000000000000 x22: 0000000000000000 x21: 0000000000040dc0
x20: 0000000000000000 x19: 000000000000000b x18: 00000000ffffffff
x17: 0000000000000000 x16: ffff80008b5b9788 x15: 0000000000000005
x14: 1ffff00013a5ceb8 x13: 0000000000000000 x12: 0000000000000000
x11: ffff700013a5cebd x10: dfff800000000000 x9 : 0000000000000001
x8 : ffff8000939c7000 x7 : 0000000000000000 x6 : ffff0000e8bd0900
x5 : ffff0000e8bd0900 x4 : 0000000000000000 x3 : 0000000000000020
x2 : 0000000000000008 x1 : 0000000000000000 x0 : 0000000000000000
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline] (P)
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397 (P)
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
__do_kmalloc_node mm/slub.c:5402 [inline]
__kmalloc_noprof+0x3ec/0x6bc mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl fs/ioctl.c:583 [inline]
__arm64_sys_ioctl+0x154/0x1cc fs/ioctl.c:583
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x68/0xdc arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
irq event stamp: 4228
hardirqs last enabled at (4227): [<ffff80008b64f030>] irqentry_exit_to_kernel_mode_after_preempt include/linux/irq-entry-common.h:507 [inline]
hardirqs last enabled at (4227): [<ffff80008b64f030>] __arm64_exit_to_kernel_mode+0x64/0x78 arch/arm64/kernel/entry-common.c:60
hardirqs last disabled at (4228): [<ffff80008b64afb0>] el1_brk64+0x20/0x54 arch/arm64/kernel/entry-common.c:445
softirqs last enabled at (3568): [<ffff8000803f5178>] softirq_handle_end kernel/softirq.c:491 [inline]
softirqs last enabled at (3568): [<ffff8000803f5178>] handle_softirqs+0xc88/0xdfc kernel/softirq.c:673
softirqs last disabled at (3415): [<ffff800080020ff4>] __do_softirq+0x14/0x20 kernel/softirq.c:679
---[ end trace 0000000000000000 ]---
The explanation of the root cause of the bug is:
An analysis of the crash reveals that it is caused by an unbounded user-controlled allocation size in the DRM lease creation ioctl, which attempts to allocate a contiguous memory block larger than `MAX_PAGE_ORDER` using the `kmalloc` family of functions.
### Root Cause Analysis
The crash is a warning triggered in `alloc_order_allowed()` because `__alloc_frozen_pages_noprof()` is called with an allocation order that exceeds `MAX_PAGE_ORDER` (typically 10, which corresponds to 4MB on systems with 4KB pages).
This happens in `fill_object_idr()` when allocating the `objects` array:
```c
// drivers/gpu/drm/drm_lease.c:389
objects = kzalloc_objs(struct drm_mode_object *, object_count);
```
The `kzalloc_objs` macro expands to a `kmalloc`-family allocation (equivalent to `kcalloc(object_count, sizeof(struct drm_mode_object *), GFP_KERNEL)`).
The `object_count` comes directly from the user-space `drm_mode_create_lease` struct via `cl->object_count` in `drm_mode_create_lease_ioctl()`. There is no upper bound check on this value.
Before calling `fill_object_idr()`, `drm_mode_create_lease_ioctl()` allocates the `object_ids` array using `memdup_array_user()`:
```c
// drivers/gpu/drm/drm_lease.c:512
object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
object_count, sizeof(__u32));
```
`memdup_array_user()` uses `memdup_user()`, which allocates memory with `GFP_USER | __GFP_NOWARN`. Because of the `__GFP_NOWARN` flag, if `object_count` is extremely large (e.g., requiring > 4MB), `memdup_array_user()` will silently fail and return `-ENOMEM` without triggering any warnings.
However, there is a specific window where `object_count` is large enough to require more than 4MB for the `objects` array (which has 8-byte pointers on 64-bit systems), but small enough that the `object_ids` array (which has 4-byte `__u32` elements) fits within 4MB.
In the provided syzkaller reproducer:
```c
*(uint32_t*)0x200003c8 = 0xf4240; // object_count = 1,000,000
```
1. `object_count` is set to `1,000,000`.
2. `memdup_array_user()` allocates `1,000,000 * 4 = 4,000,000` bytes. This is order 10, which is `<= MAX_PAGE_ORDER`. The allocation succeeds.
3. `fill_object_idr()` then calls `kzalloc_objs()` to allocate `1,000,000 * 8 = 8,000,000` bytes. This requires order 11, which is `> MAX_PAGE_ORDER`.
4. Since `kzalloc_objs()` uses `GFP_KERNEL` without `__GFP_NOWARN`, the page allocator loudly complains and triggers the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, gfp)` warning.
### Proposed Fix
To fix this, the allocation of the `objects` array in `fill_object_idr()` should be changed to use `kvzalloc_objs()`, which gracefully falls back to `vmalloc()` for large allocations and does not trigger the page allocator warning. The corresponding `kfree()` must also be updated to `kvfree()`.
```c
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -386,7 +386,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +462,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
```
*(Note: While adding an arbitrary upper bound check to `object_count` in `drm_mode_create_lease_ioctl()` is another option, using `kvzalloc_objs()` is the standard kernel pattern for handling user-controlled array sizes without imposing artificial limits).*
The diff of the bug fix is:
diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c
index 5d2cf724c..6d31bc95d 100644
--- a/drivers/gpu/drm/drm_lease.c
+++ b/drivers/gpu/drm/drm_lease.c
@@ -3,6 +3,9 @@
* Copyright Β© 2017 Keith Packard <keithp@keithp.com>
*/
#include <linux/file.h>
+#include <linux/limits.h>
+#include <linux/slab.h>
+#include <linux/string.h>
#include <linux/uaccess.h>
#include <drm/drm_auth.h>
@@ -386,7 +389,7 @@ static int fill_object_idr(struct drm_device *dev,
int ret;
bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
- objects = kzalloc_objs(struct drm_mode_object *, object_count);
+ objects = kvzalloc_objs(struct drm_mode_object *, object_count);
if (!objects)
return -ENOMEM;
@@ -462,7 +465,7 @@ static int fill_object_idr(struct drm_device *dev,
if (objects[o])
drm_mode_object_put(objects[o]);
}
- kfree(objects);
+ kvfree(objects);
return ret;
}
@@ -496,6 +499,11 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
return -EINVAL;
}
+ if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *)) {
+ drm_dbg_lease(dev, "too many objects: %u\n", cl->object_count);
+ return -EINVAL;
+ }
+
lessor = drm_file_get_master(lessor_priv);
/* Do not allow sub-leases */
if (lessor->lessor) {
@@ -509,8 +517,8 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* Handle leased objects, if any */
idr_init(&leases);
if (object_count != 0) {
- object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
- object_count, sizeof(__u32));
+ object_ids = vmemdup_array_user(u64_to_user_ptr(cl->object_ids),
+ object_count, sizeof(__u32));
if (IS_ERR(object_ids)) {
ret = PTR_ERR(object_ids);
idr_destroy(&leases);
@@ -520,7 +528,7 @@ int drm_mode_create_lease_ioctl(struct drm_device *dev,
/* fill and validate the object idr */
ret = fill_object_idr(dev, lessor_priv, &leases,
object_count, object_ids);
- kfree(object_ids);
+ kvfree(object_ids);
if (ret) {
drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
idr_destroy(&leases);
Additional description of the patch:
I have created a patch to address the page allocator warning triggered in `drm_mode_create_lease_ioctl()`.
### Root Cause & Engineering Analysis
1. In `fill_object_idr()`, the temporary `objects` pointer array was allocated using `kzalloc_objs(struct drm_mode_object *, object_count)`. Because `kzalloc_objs` expands to `kmalloc` with `GFP_KERNEL` (which lacks `__GFP_NOWARN`), when a userspace caller provides a sufficiently large `cl->object_count` (e.g., 1,000,000 mode objects), the requested size exceeds `MAX_PAGE_ORDER` (order 11 > 10), triggering the `WARN_ON_ONCE_GFP(order > MAX_PAGE_ORDER, ...)` in `alloc_order_allowed()`.
2. Although `cl->object_ids` was duplicated from user space using `memdup_array_user()`, that allocation also relied on `kmalloc` and could fail under memory fragmentation or for larger order allocations.
3. While switching to the `kvmalloc` family (`kvzalloc_objs()`) enables falling back to `vmalloc()` to prevent the `MAX_PAGE_ORDER` splat, `__kvmalloc_node_noprof()` still triggers a `WARN_ON_ONCE(size > INT_MAX)` if user space passes a crazy allocation size (> 2GB). Since `cl->object_count` is an unbounded `__u32`, `object_count * sizeof(struct drm_mode_object *)` could otherwise easily exceed `INT_MAX`.
4. Furthermore, `cl->object_count` is a `__u32` in `struct drm_mode_create_lease`, but `fill_object_idr()` and `validate_lease()` accept `int object_count`. Without an upper bound, a value $\ge 2^{31}$ would suffer signed integer overflow.
### Changes Made
1. **Switch to `kvzalloc_objs()` / `kvfree()`**:
In `fill_object_idr()`, switched the `objects` array allocation from `kzalloc_objs()` to `kvzalloc_objs()` so large allocations can gracefully fall back to `vmalloc()`, and updated `kfree(objects)` to `kvfree(objects)`.
2. **Switch to `vmemdup_array_user()` / `kvfree()`**:
In `drm_mode_create_lease_ioctl()`, switched copying `cl->object_ids` from `memdup_array_user()` to `vmemdup_array_user()`, and updated `kfree(object_ids)` to `kvfree(object_ids)`.
3. **Early Upper Bounds Check**:
Added an early check `if (cl->object_count > INT_MAX / sizeof(struct drm_mode_object *))` at the start of `drm_mode_create_lease_ioctl()`, alongside the `cl->flags` validation. Placing this check before `drm_file_get_master(lessor_priv)` ensures that invalid requests are rejected early with `-EINVAL` without leaking the lessor's `drm_master` reference, prevents `__kvmalloc_node_noprof()` from triggering `WARN_ON_ONCE(size > INT_MAX)` on both allocations, and guarantees that `object_count` safely fits within a positive `int`.
4. **Header Cleanups**:
Included `<linux/limits.h>`, `<linux/slab.h>`, and `<linux/string.h>` in `drivers/gpu/drm/drm_lease.c` for `INT_MAX`, `kvzalloc_objs`/`kvfree`, and `vmemdup_array_user`.
Here are summaries of recent commits that touched the same files.
Format the summary line consistently with these, look how prefixes
are specified, letter capitalization, style, etc.
Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
drm_lease.c: copy user-array safely
drm: Remove unnecessary include statements for drm_crtc_helper.h
drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
drm/lease: allow empty leases
drm: clean up unused kerneldoc in drm_lease.c
drm: clarify usage of drm leases
drm: protect drm_master pointers in drm_lease.c
drm: Don't include drm_legacy.h in drm_lease.c
drm : Insert blank lines after declarations.
drm/lease: fix WARNING in idr_destroy
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
drm: drop use of drmP.h in drm/*
drm/lease: Check for lessor outside of locks
drm/lease: Drop recursive leads checks
drm/leases: Drop object_id validation for negative ids
drm: Use array_size() when creating lease
drm: Rename crtc_idr as object_idr to KMS cleanups
drm/lease: Send a distinct uevent
Reply: drm/lease: Use kvmalloc and bound object_count in create lease ioctl
In drm_mode_create_lease_ioctl(), user space supplies an object_count and
an array of object_ids to be leased. The kernel copies the IDs from user
space using memdup_array_user(), and then fill_object_idr() allocates a
temporary array of pointers using kzalloc_objs(struct drm_mode_object *,
object_count).
Because kzalloc_objs() performs a kmalloc-family allocation with GFP_KERNEL
(which lacks __GFP_NOWARN), if user space requests a sufficiently large
object_count (for example, 1,000,000 mode objects), the allocation for the
pointer array (1,000,000 * 8 = 8,000,000 bytes on 64-bit systems) requires
order 11 pages. This exceeds MAX_PAGE_ORDER and triggers a warning in the
page allocator:
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340
[inline]
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640
mm/page_alloc.c:5397
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline]
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
Furthermore, cl->object_count is an unbounded __u32, whereas
fill_object_idr() and validate_lease() treat object_count as a signed
integer. A value of cl->object_count greater than or equal to 2^31 results
in signed integer overflow. In addition, an allocation size exceeding
INT_MAX would trigger a WARN_ON_ONCE inside __kvmalloc_node_noprof().
Fix these issues by validating cl->object_count early in
drm_mode_create_lease_ioctl() so that requests with cl->object_count >
INT_MAX / sizeof(struct drm_mode_object *) are rejected with -EINVAL.
Additionally, switch the object_ids allocation to vmemdup_array_user() and
the objects pointer array allocation to kvzalloc_objs(), freeing both with
kvfree(), so that large allocations can fall back to vmalloc without
triggering allocator warnings or failing under memory fragmentation.
|
| 481/2 |
2026/10/14 00:37 |
llm |
description-generator |
0m
Model:
Tokens:
input: 9638
output: 32
thoughts: 601
Thoughts: **My Commit Description Generation Process**
Okay, here's what I'm thinking. I need to craft a commit description for a kernel bug fix, and I need to do it precisely. First, the instructions are very clear: I need a concise, one-line summary (under 72 characters) that focuses on the *change*, not the tool that found the bug. Then, I need to elaborate on the bug itself and how the patch resolves it.
The constraints are also strict: no lines starting with `#`, `--`, or `---`. Those will break Git, so I *must* avoid them. I need to make sure the final output is *only* the commit description text; no extra fluff. Crucially, I'm *not* manually wrapping lines. The lines should remain single, not exceeding the maximum line length. I should also avoid mentioning syzkaller or fuzzers directly in the description.
If there's a sanitizer report (KASAN, KMSAN, lockdep, etc.) or a warning, I must include *relevant* parts. No irrelevant sections, such as long stack traces unless they illustrate the bug's execution path. If the warning has a `---[ end trace ... ]---` (which is forbidden) or `------------[ cut here ]------------` I'll exclude it!
The instructions mention something about `WARN_ON`, but this patch doesn't remove `WARN_ON`. It avoids triggering `WARN_ON_ONCE_GFP` or `WARN_ON_ONCE`.
I also shouldn't assume `panic_on_warn` is set. Finally, I'll review recent commit subjects from `drivers/gpu/drm/drm_lease.c` using `git log` to ensure I'm following the standard "drm/lease:..." format.
|
| 482/2 |
2026/10/14 00:38 |
tool |
git-log |
0m
Args: map[Count:10 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
f37d63e219c3 drm_lease.c: copy user-array safely
cde3d37b19df drm: Remove unnecessary include statements for drm_crtc_helper.h
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
4bb2d367a5a2 drm/lease: allow empty leases
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
d793b8f732d6 drm: clarify usage of drm leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
7988fdf5f0a3 drm: Don't include drm_legacy.h in drm_lease.c
]
|
| 483/2 |
2026/10/14 00:38 |
llm |
description-generator |
0m
Model:
Tokens:
input: 10923
output: 32
thoughts: 99
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience:
**Investigating Potential Lease-Related Issues**
Right, let's dive into some potentially relevant commits. I'm thinking I'll start by reviewing commit `4bb2d367a5a2`, then check out `676f11b5a4a0`, `56f0729a510f`, and `7bd224b6625a` to see if there's anything germane to the issue at hand. It seems like the "drm/lease: ..." component is pretty frequently utilized in the code base, and that makes it a prime suspect. To get a broader understanding and see the history, I should really use `git log --oneline drivers/gpu/drm/drm_lease.c` and go back further in the history of that file. This should give me some context about related modifications and perhaps pinpoint the root cause or interaction if this is an evolution of a known problem.
|
| 484/2 |
2026/10/14 00:38 |
tool |
git-log |
0m
Args: map[Count:25 PathPrefix:drivers/gpu/drm/drm_lease.c]
Results: map[Output:32a92f8c8932 Convert more 'alloc_obj' cases to default GFP_KERNEL arguments
69050f8d6d07 treewide: Replace kmalloc with kmalloc_obj for non-scalar types
f37d63e219c3 drm_lease.c: copy user-array safely
cde3d37b19df drm: Remove unnecessary include statements for drm_crtc_helper.h
7bd224b6625a drm/drm_lease: Remove usage of deprecated DRM_DEBUG_LEASE
4bb2d367a5a2 drm/lease: allow empty leases
676f11b5a4a0 drm: clean up unused kerneldoc in drm_lease.c
d793b8f732d6 drm: clarify usage of drm leases
56f0729a510f drm: protect drm_master pointers in drm_lease.c
7988fdf5f0a3 drm: Don't include drm_legacy.h in drm_lease.c
948de84233d3 drm : Insert blank lines after declarations.
b216a8e7908c drm/lease: fix WARNING in idr_destroy
c942fddf8793 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157
0500c04ea14a drm: drop use of drmP.h in drm/*
46b757780dfe drm/lease: Check for lessor outside of locks
ae9d6c076c0d drm/lease: Drop recursive leads checks
e40b76428842 drm/leases: Drop object_id validation for negative ids
69ef943dbc14 drm: Use array_size() when creating lease
b5f06893c499 drm: Rename crtc_idr as object_idr to KMS cleanups
ce85882860f0 drm/lease: Send a distinct uevent
968029057192 drm/lease: look at ->universal_planes only once
a0c1af46e9d7 drm/lease: debug output for lease creation
6caec6a04717 drm/lease: drop EXPORT_SYMBOL
918d89bb1a63 gpu: drm/lease: fix spelling mistake, EACCESS -> EACCES
12d43deb1ee6 drm: fix use-after-free read in drm_mode_create_lease_ioctl()
]
|
| 485/2 |
2026/10/14 00:38 |
llm |
description-generator |
0m
Model:
Tokens:
input: 11906
output: 39
thoughts: 1323
Thoughts: **Analyzing the drm/lease Code for Lease Creation**
Alright, let's break this down. Seeing that "drm/lease: ..." prefix, I immediately know we're dealing with modifications to the DRM lease functionality, specifically `drm_lease.c`. Looking at the diff, it's clear the changes revolve around `drm_mode_create_lease_ioctl()` and the related `fill_object_idr()` function. The core concern is the allocation and handling of object arrays during lease creation. I can see the switch from `kzalloc_objs` to `kvmalloc/kvfree` and `vmemdup_array_user`, which suggests a move away from the potentially problematic page allocations. Also, I see the addition of a crucial check: `object_count` is being validated against `INT_MAX / sizeof(...)`. Good, that prevents the obvious integer overflow and potential denial of service.
Now, as for a concise summary... "drm/lease: Use kvmalloc and check bounds for object_count in lease" looks most appropriate.
That should clearly state the changes: the allocation is now using kvmalloc and the object count is validated.
The patch clearly highlights two key changes: the allocation calls and the `object_count` check. That should keep it under 70 characters. It is good!
|
| 486/2 |
2026/10/14 00:38 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:480 LineCount:60]
Results: map[Contents: 480: int ret = 0;
481: struct idr leases;
482: struct drm_master *lessor;
483: struct drm_master *lessee = NULL;
484: struct file *lessee_file = NULL;
485: struct file *lessor_file = lessor_priv->filp;
486: struct drm_file *lessee_priv;
487: int fd = -1;
488: uint32_t *object_ids;
489:
490: /* Can't lease without MODESET */
491: if (!drm_core_check_feature(dev, DRIVER_MODESET))
492: return -EOPNOTSUPP;
493:
494: if (cl->flags && (cl->flags & ~(O_CLOEXEC | O_NONBLOCK))) {
495: drm_dbg_lease(dev, "invalid flags\n");
496: return -EINVAL;
497: }
498:
499: lessor = drm_file_get_master(lessor_priv);
500: /* Do not allow sub-leases */
501: if (lessor->lessor) {
502: drm_dbg_lease(dev, "recursive leasing not allowed\n");
503: ret = -EINVAL;
504: goto out_lessor;
505: }
506:
507: object_count = cl->object_count;
508:
509: /* Handle leased objects, if any */
510: idr_init(&leases);
511: if (object_count != 0) {
512: object_ids = memdup_array_user(u64_to_user_ptr(cl->object_ids),
513: object_count, sizeof(__u32));
514: if (IS_ERR(object_ids)) {
515: ret = PTR_ERR(object_ids);
516: idr_destroy(&leases);
517: goto out_lessor;
518: }
519:
520: /* fill and validate the object idr */
521: ret = fill_object_idr(dev, lessor_priv, &leases,
522: object_count, object_ids);
523: kfree(object_ids);
524: if (ret) {
525: drm_dbg_lease(dev, "lease object lookup failed: %i\n", ret);
526: idr_destroy(&leases);
527: goto out_lessor;
528: }
529: }
530:
531: /* Allocate a file descriptor for the lease */
532: fd = get_unused_fd_flags(cl->flags & (O_CLOEXEC | O_NONBLOCK));
533: if (fd < 0) {
534: idr_destroy(&leases);
535: ret = fd;
536: goto out_lessor;
537: }
538:
539: drm_dbg_lease(dev, "Creating lease\n");
]
|
| 487/2 |
2026/10/14 00:38 |
llm |
description-generator |
0m
Model:
Tokens:
input: 14470
output: 39
thoughts: 28
Thoughts: Okay, here's my interpretation of that request, formatted as requested:
**Diving into the Lease Implementation**
Alright, so we're talking about DRM leases, specifically how they're implemented in the kernel. I need to get a really good handle on this, so I'm going to take a closer look at the `drivers/gpu/drm/drm_lease.c` file. This is crucial for understanding how resource sharing is managed in the graphics stack. I'm especially interested in lines 380 through 465. That specific block likely contains the core logic or important interactions within that module and is the section to thoroughly analyze for this exploration. I need to understand this implementation well to make sure any improvements or debugging efforts are targeted effectively. Let's see what's in there.
|
| 488/2 |
2026/10/14 00:38 |
tool |
read-file |
0m
Args: map[File:drivers/gpu/drm/drm_lease.c FirstLine:380 LineCount:85]
Results: map[Contents: 380: struct idr *leases,
381: int object_count,
382: u32 *object_ids)
383: {
384: struct drm_mode_object **objects;
385: u32 o;
386: int ret;
387: bool universal_planes = READ_ONCE(lessor_priv->universal_planes);
388:
389: objects = kzalloc_objs(struct drm_mode_object *, object_count);
390: if (!objects)
391: return -ENOMEM;
392:
393: /* step one - get references to all the mode objects
394: and check for validity. */
395: for (o = 0; o < object_count; o++) {
396: objects[o] = drm_mode_object_find(dev, lessor_priv,
397: object_ids[o],
398: DRM_MODE_OBJECT_ANY);
399: if (!objects[o]) {
400: ret = -ENOENT;
401: goto out_free_objects;
402: }
403:
404: if (!drm_mode_object_lease_required(objects[o]->type)) {
405: DRM_DEBUG_KMS("invalid object for lease\n");
406: ret = -EINVAL;
407: goto out_free_objects;
408: }
409: }
410:
411: ret = validate_lease(dev, object_count, objects, universal_planes);
412: if (ret) {
413: drm_dbg_lease(dev, "lease validation failed\n");
414: goto out_free_objects;
415: }
416:
417: /* add their IDs to the lease request - taking into account
418: universal planes */
419: for (o = 0; o < object_count; o++) {
420: struct drm_mode_object *obj = objects[o];
421: u32 object_id = objects[o]->id;
422:
423: drm_dbg_lease(dev, "Adding object %d to lease\n", object_id);
424:
425: /*
426: * We're using an IDR to hold the set of leased
427: * objects, but we don't need to point at the object's
428: * data structure from the lease as the main object_idr
429: * will be used to actually find that. Instead, all we
430: * really want is a 'leased/not-leased' result, for
431: * which any non-NULL pointer will work fine.
432: */
433: ret = idr_alloc(leases, &drm_lease_idr_object , object_id, object_id + 1, GFP_KERNEL);
434: if (ret < 0) {
435: drm_dbg_lease(dev, "Object %d cannot be inserted into leases (%d)\n",
436: object_id, ret);
437: goto out_free_objects;
438: }
439: if (obj->type == DRM_MODE_OBJECT_CRTC && !universal_planes) {
440: struct drm_crtc *crtc = obj_to_crtc(obj);
441:
442: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->primary->base.id, crtc->primary->base.id + 1, GFP_KERNEL);
443: if (ret < 0) {
444: drm_dbg_lease(dev, "Object primary plane %d cannot be inserted into leases (%d)\n",
445: object_id, ret);
446: goto out_free_objects;
447: }
448: if (crtc->cursor) {
449: ret = idr_alloc(leases, &drm_lease_idr_object, crtc->cursor->base.id, crtc->cursor->base.id + 1, GFP_KERNEL);
450: if (ret < 0) {
451: drm_dbg_lease(dev, "Object cursor plane %d cannot be inserted into leases (%d)\n",
452: object_id, ret);
453: goto out_free_objects;
454: }
455: }
456: }
457: }
458:
459: ret = 0;
460: out_free_objects:
461: for (o = 0; o < object_count; o++) {
462: if (objects[o])
463: drm_mode_object_put(objects[o]);
464: }
]
|
| 489/2 |
2026/10/14 00:38 |
llm |
description-generator |
0m
Model:
Tokens:
input: 16110
output: 838
thoughts: 8718
Thoughts: **drm/lease: Use kvmalloc and bound object_count in create lease ioctl**
In drm_mode_create_lease_ioctl(), user space supplies an object_count and an array of object_ids to be leased. The kernel first copies the IDs from user space using memdup_array_user(), and then fill_object_idr() allocates a temporary array of pointers using kzalloc_objs(struct drm_mode_object *, object_count).
Because kzalloc_objs() performs a kmalloc-family allocation with GFP_KERNEL (which does not include __GFP_NOWARN), if user space requests a sufficiently large object_count (for example, 1,000,000 mode objects), the allocation for the pointer array (1,000,000 * 8 = 8,000,000 bytes on 64-bit architectures) requires order 11 pages. This exceeds MAX_PAGE_ORDER (order 10) and triggers a warning in the page allocator:
WARNING: mm/page_alloc.c:5340 at alloc_order_allowed mm/page_alloc.c:5340 [inline]
WARNING: mm/page_alloc.c:5340 at __alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
Call trace:
alloc_order_allowed mm/page_alloc.c:5340 [inline]
__alloc_frozen_pages_noprof+0xe4/0x640 mm/page_alloc.c:5397
alloc_pages_mpol+0x1fc/0x3d0 mm/mempolicy.c:2486
alloc_frozen_pages_noprof+0xe0/0x214 mm/mempolicy.c:2557
___kmalloc_large_node+0xf0/0x160 mm/slub.c:5353
__kmalloc_large_node_noprof+0x2c/0x8c mm/slub.c:5385
fill_object_idr drivers/gpu/drm/drm_lease.c:389 [inline]
drm_mode_create_lease_ioctl+0x45c/0x15c8 drivers/gpu/drm/drm_lease.c:521
drm_ioctl_kernel+0x250/0x328 drivers/gpu/drm/drm_ioctl.c:817
drm_ioctl+0x65c/0xa58 drivers/gpu/drm/drm_ioctl.c:914
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
Furthermore, cl->object_count is an unbounded __u32, whereas fill_object_idr() and validate_lease() treat object_count as a signed integer. A value of cl->object_count greater than or equal to 2^31 results in signed integer overflow. In addition, an allocation size larger than INT_MAX would trigger a WARN_ON_ONCE inside __kvmalloc_node_noprof().
To resolve these issues, validate cl->object_count early in drm_mode_create_lease_ioctl() to ensure that cl->object_count <= INT_MAX / sizeof(struct drm_mode_object *), rejecting oversized requests with -EINVAL. Also, switch the allocations of object_ids and the objects pointer array to vmemdup_array_user() and kvzalloc_objs(), respectively, and release them with kvfree(), so that large allocations can fall back to vmalloc without triggering allocation warnings or failing due to memory fragmentation.
|