Commit b2e3dfd
committed
gfx/drivers: scattered OOM and NULL-return fixes across drm / switch_nx / gx2 / mali_fbdev
Four unrelated OOM/NULL-deref bugs found in a sweep across the
gfx/drivers tree. Lumped into one commit because each is small
on its own and they all fall under the same 'unchecked allocation
in a gfx driver' theme.
=== gfx/drivers/drm_gfx.c: get_plane_prop_id ===
props = drmModeObjectGetProperties(drm.fd,
plane->plane_id, DRM_MODE_OBJECT_PLANE);
props_info = malloc(props->count_props * sizeof *props_info);
for (j = 0; j < props->count_props; ++j)
props_info[j] = drmModeGetProperty(drm.fd, props->props[j]);
Two NULL-deref sites stacked:
- drmModeObjectGetProperties returns NULL on kernel/driver
error or when the plane exposes no properties; accessing
props->count_props NULL-derefs.
- malloc is unchecked; props_info[j] = ... below NULL-derefs
on OOM.
Fix: NULL-check both; 'continue' to the next plane on either
failure. If no plane produces the requested property, the
function already falls through to 'return 0' (the 'not found'
signal) at the end.
NOTE: this function has pre-existing resource leaks
(plane_resources, plane, props, props_info are all libdrm-
allocated and never freed, including on the early 'return
props_info[j]->prop_id' path inside the loop). Those are out
of scope for this fix - plugging them needs a goto-cleanup
rewrite.
=== gfx/drivers/switch_nx_gfx.c: switch_set_texture_frame ===
if (sw->menu_texture.pixels)
sw->menu_texture.pixels = realloc(sw->menu_texture.pixels, sz);
else
sw->menu_texture.pixels = malloc(sz);
if (!sw->menu_texture.pixels)
return;
Classic realloc-assign-self leak: on OOM realloc returns NULL
but the old menu-texture buffer is still valid; the self-assign
overwrites the only pointer to it and the subsequent NULL-check
catches the crash but not the leak. Every size-change on the
menu texture (common during menu navigation - icon/thumbnail
scaling) leaks the previous buffer.
Fix: realloc-to-tmp, NULL-check, only commit the new pointer on
success.
=== gfx/drivers/gx2_gfx.c: gx2_set_shader ===
wiiu->shader_preset = calloc(1, sizeof(*wiiu->shader_preset));
if (!video_shader_load_preset_into_shader(path, wiiu->shader_preset))
calloc is unchecked. video_shader_load_preset_into_shader (in
gfx/video_shader_parse.c:2294) does not NULL-check its 'shader'
argument either - it walks through to config-file parsing and
writes into shader->... fields, NULL-derefing on the first
write.
Fix: NULL-check the calloc, bail out of set_shader before the
call on OOM.
=== gfx/drivers_context/mali_fbdev_ctx.c: gfx_ctx_mali_fbdev_clear_screen ===
int fd = open("/dev/fb0", O_RDWR);
ioctl (fd, FBIOGET_VSCREENINFO, &vinfo);
buffer_size = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
buffer = calloc(1, buffer_size);
write(fd,buffer,buffer_size);
free(buffer);
close(fd);
Three cascading failures:
- open() can return -1 (fb0 missing, permission denied,
exclusive-use by another process). ioctl(-1, ...) returns
EBADF but doesn't crash; vinfo is left uninitialised stack
garbage.
- buffer_size is derived from that garbage - could be 0, could
be multi-GB. calloc(1, absurd) returns NULL on the big
case.
- write(fd, NULL, buffer_size) on NULL buffer is EFAULT on
Linux but undefined per POSIX.
Fix: guard each step. Early-return on open() failure; close()
and return on ioctl() failure; skip the write() on calloc
failure. The whole function is a cosmetic teardown step
(clearing the framebuffer on exit), so silent no-op on error is
the right policy.
=== Thread-safety ===
All four run on the main / driver-init thread. No lock changes.
=== Reachability ===
- drm_gfx: get_plane_prop_id runs once at video-driver init on
bare-metal DRM targets; hit on every startup.
- switch_nx_gfx: set_texture_frame hits every menu-texture
size change (menu navigation).
- gx2_gfx: set_shader hits on shader-preset load (menu action).
- mali_fbdev_ctx: clear_screen runs at process exit on Mali
framebuffer targets.
All realistic on the handheld/embedded hardware these drivers
target, where OOM on 128-512MB systems is a real concern.1 parent 1efeddc commit b2e3dfd
4 files changed
Lines changed: 59 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
363 | 377 | | |
| 378 | + | |
| 379 | + | |
364 | 380 | | |
365 | 381 | | |
366 | 382 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
250 | 257 | | |
251 | 258 | | |
252 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
825 | 825 | | |
826 | 826 | | |
827 | 827 | | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
828 | 834 | | |
829 | | - | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
830 | 841 | | |
831 | 842 | | |
832 | 843 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
148 | 162 | | |
149 | 163 | | |
150 | | - | |
151 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
152 | 173 | | |
153 | 174 | | |
154 | 175 | | |
| |||
0 commit comments