Skip to content

Commit a68cb09

Browse files
lucasdemarchimehmetb0
authored andcommitted
drm/xe/reg_sr: Remove register pool
BugLink: https://bugs.launchpad.net/bugs/2097332 [ Upstream commit d7b0286 ] That pool implementation doesn't really work: if the krealloc happens to move the memory and return another address, the entries in the xarray become invalid, leading to use-after-free later: BUG: KASAN: slab-use-after-free in xe_reg_sr_apply_mmio+0x570/0x760 [xe] Read of size 4 at addr ffff8881244b2590 by task modprobe/2753 Allocated by task 2753: kasan_save_stack+0x39/0x70 kasan_save_track+0x14/0x40 kasan_save_alloc_info+0x37/0x60 __kasan_kmalloc+0xc3/0xd0 __kmalloc_node_track_caller_noprof+0x200/0x6d0 krealloc_noprof+0x229/0x380 Simplify the code to fix the bug. A better pooling strategy may be added back later if needed. Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Reviewed-by: Matt Roper <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Lucas De Marchi <[email protected]> (cherry picked from commit e5283bd) Signed-off-by: Thomas Hellström <[email protected]> Signed-off-by: Sasha Levin <[email protected]> CVE-2024-56652 Signed-off-by: Koichiro Den <[email protected]>
1 parent 2403d1c commit a68cb09

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

drivers/gpu/drm/xe/xe_reg_sr.c

+6-25
Original file line numberDiff line numberDiff line change
@@ -26,46 +26,27 @@
2626
#include "xe_reg_whitelist.h"
2727
#include "xe_rtp_types.h"
2828

29-
#define XE_REG_SR_GROW_STEP_DEFAULT 16
30-
3129
static void reg_sr_fini(struct drm_device *drm, void *arg)
3230
{
3331
struct xe_reg_sr *sr = arg;
32+
struct xe_reg_sr_entry *entry;
33+
unsigned long reg;
34+
35+
xa_for_each(&sr->xa, reg, entry)
36+
kfree(entry);
3437

3538
xa_destroy(&sr->xa);
36-
kfree(sr->pool.arr);
37-
memset(&sr->pool, 0, sizeof(sr->pool));
3839
}
3940

4041
int xe_reg_sr_init(struct xe_reg_sr *sr, const char *name, struct xe_device *xe)
4142
{
4243
xa_init(&sr->xa);
43-
memset(&sr->pool, 0, sizeof(sr->pool));
44-
sr->pool.grow_step = XE_REG_SR_GROW_STEP_DEFAULT;
4544
sr->name = name;
4645

4746
return drmm_add_action_or_reset(&xe->drm, reg_sr_fini, sr);
4847
}
4948
EXPORT_SYMBOL_IF_KUNIT(xe_reg_sr_init);
5049

51-
static struct xe_reg_sr_entry *alloc_entry(struct xe_reg_sr *sr)
52-
{
53-
if (sr->pool.used == sr->pool.allocated) {
54-
struct xe_reg_sr_entry *arr;
55-
56-
arr = krealloc_array(sr->pool.arr,
57-
ALIGN(sr->pool.allocated + 1, sr->pool.grow_step),
58-
sizeof(*arr), GFP_KERNEL);
59-
if (!arr)
60-
return NULL;
61-
62-
sr->pool.arr = arr;
63-
sr->pool.allocated += sr->pool.grow_step;
64-
}
65-
66-
return &sr->pool.arr[sr->pool.used++];
67-
}
68-
6950
static bool compatible_entries(const struct xe_reg_sr_entry *e1,
7051
const struct xe_reg_sr_entry *e2)
7152
{
@@ -111,7 +92,7 @@ int xe_reg_sr_add(struct xe_reg_sr *sr,
11192
return 0;
11293
}
11394

114-
pentry = alloc_entry(sr);
95+
pentry = kmalloc(sizeof(*pentry), GFP_KERNEL);
11596
if (!pentry) {
11697
ret = -ENOMEM;
11798
goto fail;

drivers/gpu/drm/xe/xe_reg_sr_types.h

-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ struct xe_reg_sr_entry {
2020
};
2121

2222
struct xe_reg_sr {
23-
struct {
24-
struct xe_reg_sr_entry *arr;
25-
unsigned int used;
26-
unsigned int allocated;
27-
unsigned int grow_step;
28-
} pool;
2923
struct xarray xa;
3024
const char *name;
3125

0 commit comments

Comments
 (0)