linux/drivers/gpu/drm
Tvrtko Ursulin 4aa923a6e6 drm/amd/pm: Vangogh: Fix kernel memory out of bounds write
KASAN reports that the GPU metrics table allocated in
vangogh_tables_init() is not large enough for the memset done in
smu_cmn_init_soft_gpu_metrics(). Condensed report follows:

[   33.861314] BUG: KASAN: slab-out-of-bounds in smu_cmn_init_soft_gpu_metrics+0x73/0x200 [amdgpu]
[   33.861799] Write of size 168 at addr ffff888129f59500 by task mangoapp/1067
...
[   33.861808] CPU: 6 UID: 1000 PID: 1067 Comm: mangoapp Tainted: G        W          6.12.0-rc4 #356 1a56f59a8b5182eeaf67eb7cb8b13594dd23b544
[   33.861816] Tainted: [W]=WARN
[   33.861818] Hardware name: Valve Galileo/Galileo, BIOS F7G0107 12/01/2023
[   33.861822] Call Trace:
[   33.861826]  <TASK>
[   33.861829]  dump_stack_lvl+0x66/0x90
[   33.861838]  print_report+0xce/0x620
[   33.861853]  kasan_report+0xda/0x110
[   33.862794]  kasan_check_range+0xfd/0x1a0
[   33.862799]  __asan_memset+0x23/0x40
[   33.862803]  smu_cmn_init_soft_gpu_metrics+0x73/0x200 [amdgpu 13b1bc364ec578808f676eba412c20eaab792779]
[   33.863306]  vangogh_get_gpu_metrics_v2_4+0x123/0xad0 [amdgpu 13b1bc364ec578808f676eba412c20eaab792779]
[   33.864257]  vangogh_common_get_gpu_metrics+0xb0c/0xbc0 [amdgpu 13b1bc364ec578808f676eba412c20eaab792779]
[   33.865682]  amdgpu_dpm_get_gpu_metrics+0xcc/0x110 [amdgpu 13b1bc364ec578808f676eba412c20eaab792779]
[   33.866160]  amdgpu_get_gpu_metrics+0x154/0x2d0 [amdgpu 13b1bc364ec578808f676eba412c20eaab792779]
[   33.867135]  dev_attr_show+0x43/0xc0
[   33.867147]  sysfs_kf_seq_show+0x1f1/0x3b0
[   33.867155]  seq_read_iter+0x3f8/0x1140
[   33.867173]  vfs_read+0x76c/0xc50
[   33.867198]  ksys_read+0xfb/0x1d0
[   33.867214]  do_syscall_64+0x90/0x160
...
[   33.867353] Allocated by task 378 on cpu 7 at 22.794876s:
[   33.867358]  kasan_save_stack+0x33/0x50
[   33.867364]  kasan_save_track+0x17/0x60
[   33.867367]  __kasan_kmalloc+0x87/0x90
[   33.867371]  vangogh_init_smc_tables+0x3f9/0x840 [amdgpu]
[   33.867835]  smu_sw_init+0xa32/0x1850 [amdgpu]
[   33.868299]  amdgpu_device_init+0x467b/0x8d90 [amdgpu]
[   33.868733]  amdgpu_driver_load_kms+0x19/0xf0 [amdgpu]
[   33.869167]  amdgpu_pci_probe+0x2d6/0xcd0 [amdgpu]
[   33.869608]  local_pci_probe+0xda/0x180
[   33.869614]  pci_device_probe+0x43f/0x6b0

Empirically we can confirm that the former allocates 152 bytes for the
table, while the latter memsets the 168 large block.

Root cause appears that when GPU metrics tables for v2_4 parts were added
it was not considered to enlarge the table to fit.

The fix in this patch is rather "brute force" and perhaps later should be
done in a smarter way, by extracting and consolidating the part version to
size logic to a common helper, instead of brute forcing the largest
possible allocation. Nevertheless, for now this works and fixes the out of
bounds write.

v2:
 * Drop impossible v3_0 case. (Mario)

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Fixes: 41cec40bc9 ("drm/amd/pm: Vangogh: Add new gpu_metrics_v2_4 to acquire gpu_metrics")
Cc: Mario Limonciello <mario.limonciello@amd.com>
Cc: Evan Quan <evan.quan@amd.com>
Cc: Wenyou Yang <WenYou.Yang@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Link: https://lore.kernel.org/r/20241025145639.19124-1-tursulin@igalia.com
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit 0880f58f96)
Cc: stable@vger.kernel.org # v6.6+
2024-10-28 17:14:08 -04:00
..
amd drm/amd/pm: Vangogh: Fix kernel memory out of bounds write 2024-10-28 17:14:08 -04:00
arm drm: komeda: Fix an issue related to normalized zpos 2024-08-30 13:44:12 +01:00
armada drm/print: drop include debugfs.h and include where needed 2024-04-25 17:05:48 +03:00
aspeed
ast drm/ast: vga: Clear EDID if no display is connected 2024-10-17 08:50:14 +02:00
atmel-hlcdc drm: atmel-hlcdc: add LCD controller layer definition for sam9x75 2024-05-30 15:47:55 +02:00
bridge drm/bridge: tc358767: fix missing of_node_put() in for_each_endpoint_of_node() 2024-10-21 15:00:35 +02:00
ci drm/ci: increase timeout for all jobs 2024-08-28 12:21:49 -03:00
display Short summary of fixes pull: 2024-10-01 08:15:55 +10:00
etnaviv Merge drm/drm-next into drm-misc-next 2024-07-29 09:35:54 +02:00
exynos drm next for 6.12-rc1 2024-09-19 10:18:15 +02:00
fsl-dcu
gma500 drm next for 6.12-rc1 2024-09-19 10:18:15 +02:00
gud drm: add missing MODULE_DESCRIPTION() macros 2024-06-10 12:44:39 +02:00
hisilicon drm/hisilicon: Remove unused delarations 2024-08-13 16:22:43 +02:00
hyperv drm/hyperv: Use fbdev-shmem 2024-05-02 11:33:17 +02:00
i2c drm/i2c: tda998x: switch to struct drm_edid 2024-05-13 19:10:57 +02:00
i915 i915: fix DRM_I915_GVT_KVMGT dependencies 2024-10-21 09:51:05 +03:00
imagination Linux 6.11-rc7 2024-09-11 09:18:15 +02:00
imx Linux 6.11-rc7 2024-09-11 09:18:15 +02:00
ingenic drm/bridge-connector: move to DRM_DISPLAY_HELPER module 2024-09-03 10:18:31 +02:00
kmb drm/bridge-connector: move to DRM_DISPLAY_HELPER module 2024-09-03 10:18:31 +02:00
lib
lima Merge drm/drm-next into drm-misc-next 2024-07-29 09:35:54 +02:00
logicvc
loongson drm/loongson: use GEM references instead of TTMs 2024-08-01 10:03:44 +02:00
mcde
mediatek dma-mapping updates for linux 6.12 2024-09-19 11:12:49 +02:00
meson drm/bridge-connector: move to DRM_DISPLAY_HELPER module 2024-09-03 10:18:31 +02:00
mgag200 Revert "drm/mgag200: Add vblank support" 2024-10-17 08:49:45 +02:00
msm Merge tag 'drm-msm-fixes-2024-10-16' of https://gitlab.freedesktop.org/drm/msm into drm-fixes 2024-10-17 17:40:55 +10:00
mxsfb drm: lcdif: Use adjusted_mode .clock instead of .crtc_clock 2024-07-16 20:15:31 +02:00
nouveau Short summary of fixes pull: 2024-10-11 09:03:30 +10:00
omapdrm Linux 6.11-rc7 2024-09-11 09:18:15 +02:00
panel drm/panel: himax-hx83102: Adjust power and gamma to optimize brightness 2024-10-14 10:00:45 -07:00
panfrost Merge drm/drm-next into drm-misc-next 2024-07-29 09:35:54 +02:00
panthor drm/panthor: Don't add write fences to the shared BOs 2024-10-01 18:41:02 +02:00
pl111
qxl drm/qxl: Pin buffer objects for internal mappings 2024-07-10 09:12:42 +02:00
radeon drm/radeon: Fix encoder->possible_clones 2024-10-15 11:53:07 -04:00
renesas Linux 6.11-rc7 2024-09-11 09:18:15 +02:00
rockchip drm next for 6.12-rc1 2024-09-19 10:18:15 +02:00
scheduler drm/sched: Use drm sched lockdep map for submit_wq 2024-10-02 17:53:45 +02:00
solomon drm/solomon: Use fbdev-shmem 2024-05-02 11:33:18 +02:00
sprd
sti drm/sti/sti_hdmi: convert to struct drm_edid 2024-08-29 14:30:14 +03:00
stm drm/stm: add COMMON_CLK dependency 2024-09-10 13:55:49 +02:00
sun4i drm/sun4i: Fix layer zpos change/atomic modesetting 2024-06-10 12:44:41 +02:00
tegra Revert "drm/tegra: gr3d: Convert into dev_pm_domain_attach|detach_list()" 2024-10-10 13:54:50 +02:00
tests Linux 6.11-rc5 2024-08-27 14:09:45 +02:00
tidss drm/bridge-connector: move to DRM_DISPLAY_HELPER module 2024-09-03 10:18:31 +02:00
tilcdc drm/tilcdc: Use backlight power constants 2024-08-16 09:28:01 +02:00
tiny drm/tiny/gm12u320: convert to struct drm_edid 2024-08-29 14:30:15 +03:00
ttm Revert "drm/ttm: Add a flag to allow drivers to skip clear-on-free" 2024-08-28 06:45:53 -07:00
tve200
udl move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
v3d drm/v3d: Stop the active perfmon before being destroyed 2024-10-07 09:03:57 -03:00
vboxvideo Short summary of fixes pull: 2024-10-01 08:15:55 +10:00
vc4 drm/vc4: Stop the active perfmon before being destroyed 2024-10-07 09:06:46 -03:00
vgem
virtio Merge drm/drm-fixes into drm-misc-fixes 2024-07-30 09:09:23 +02:00
vkms drm/vkms: Formatting and typo fix 2024-08-15 11:01:48 -03:00
vmwgfx drm/vmwgfx: Remove unnecessary NULL checks before kvfree() 2024-10-10 23:01:45 -04:00
xe drm/xe: Don't restart parallel queues multiple times on GT reset 2024-10-24 12:42:52 -05:00
xen fix missing vmalloc.h includes 2024-04-25 20:55:49 -07:00
xlnx drm/bridge-connector: move to DRM_DISPLAY_HELPER module 2024-09-03 10:18:31 +02:00
drm_aperture.c
drm_atomic_helper.c drm: Fix kerneldoc for "Returns" section 2024-08-26 16:40:09 +02:00
drm_atomic_state_helper.c
drm_atomic_uapi.c drm: Consistently use struct drm_mode_rect for FB_DAMAGE_CLIPS 2024-09-25 12:35:05 +02:00
drm_atomic.c drm: Fix kerneldoc for "Returns" section 2024-08-26 16:40:09 +02:00
drm_auth.c
drm_blend.c
drm_bridge.c drm/bridge: Silence error messages upon probe deferral 2024-07-18 13:20:16 +02:00
drm_buddy.c drm/buddy: Add start address support to trim function 2024-08-07 18:19:00 -04:00
drm_cache.c
drm_client_modeset.c drm/client: fix null pointer dereference in drm_client_modeset_probe 2024-08-02 09:23:54 +02:00
drm_client.c drm/client: Fix error code in drm_client_buffer_vmap_local() 2024-07-29 08:50:23 +02:00
drm_color_mgmt.c minmax: add a few more MIN_T/MAX_T users 2024-07-28 13:41:14 -07:00
drm_connector.c drm/connector: kerneldoc: Fix two missing newlines in drm_connector.c 2024-08-12 09:07:31 -04:00
drm_crtc_helper_internal.h
drm_crtc_helper.c drm: prefer DRM_MODE_FMT/ARG over drm_mode_debug_printmodeline() 2024-04-15 16:22:50 +03:00
drm_crtc_internal.h drm/panic: Add a QR code panic screen 2024-08-23 16:55:35 +02:00
drm_crtc.c drm: Rename drm_plane_check_pixel_format() to drm_plane_has_format() 2024-06-24 17:08:33 +03:00
drm_damage_helper.c
drm_debugfs_crc.c
drm_debugfs.c drm/connector: hdmi: Fix writing Dynamic Range Mastering infoframes 2024-09-24 16:10:12 +02:00
drm_displayid_internal.h drm/edid: Parse topology block for all DispID structure v1.x 2024-04-22 11:38:11 +03:00
drm_displayid.c drm/edid: reduce DisplayID log spamming 2024-08-14 10:19:09 +03:00
drm_drv.c drm: Expand max DRM device number to full MINORBITS 2024-08-26 17:06:22 +02:00
drm_dumb_buffers.c
drm_edid_load.c
drm_edid.c drm: use mem_is_zero() instead of !memchr_inv(s, 0, n) 2024-08-16 12:07:46 +03:00
drm_eld.c drm/edid: move all internal declarations to drm_crtc_internal.h 2024-04-17 16:11:17 +03:00
drm_encoder_slave.c
drm_encoder.c
drm_exec.c mm: kvmalloc: align kvrealloc() with krealloc() 2024-09-01 20:25:44 -07:00
drm_fb_dma_helper.c drm/fb_dma: Add checks in drm_fb_dma_get_scanout_buffer() 2024-05-02 23:39:21 +02:00
drm_fb_helper.c drm/fbdev-helper: Remove drm_fb_helper_output_poll_changed() 2024-08-13 16:21:11 +02:00
drm_fbdev_dma.c drm/fbdev-dma: Only cleanup deferred I/O if necessary 2024-10-10 09:49:25 +02:00
drm_fbdev_shmem.c drm/fbdev-shmem: Clean up deferred I/O 2024-05-15 14:50:46 +02:00
drm_fbdev_ttm.c drm next for 6.11-rc1: 2024-07-18 09:34:02 -07:00
drm_file.c [tree-wide] finally take no_llseek out 2024-09-27 08:18:43 -07:00
drm_flip_work.c
drm_format_helper.c
drm_fourcc.c
drm_framebuffer.c
drm_gem_atomic_helper.c drm/atomic-helper: fix parameter order in drm_format_conv_state_copy() call 2024-04-19 17:36:49 +02:00
drm_gem_dma_helper.c
drm_gem_framebuffer_helper.c
drm_gem_shmem_helper.c drm/gem-shmem: Add import attachment warning to locked pin function 2024-05-29 09:30:44 +02:00
drm_gem_ttm_helper.c
drm_gem_vram_helper.c
drm_gem.c drm: Fix kerneldoc for "Returns" section 2024-08-26 16:40:09 +02:00
drm_gpuvm.c
drm_internal.h accel: Use XArray instead of IDR for minors 2024-08-26 17:06:22 +02:00
drm_ioc32.c
drm_ioctl.c drm: use "0" instead of "" for deprecated driver date 2024-05-10 20:56:12 +03:00
drm_kms_helper_common.c
drm_lease.c
drm_managed.c drm/managed: Simplify if condition 2024-07-03 10:11:03 +02:00
drm_mipi_dbi.c drm: add missing MODULE_DESCRIPTION() macros 2024-06-10 12:44:39 +02:00
drm_mipi_dsi.c drm/mipi-dsi: Add mipi_dsi_dcs_set_tear_scanline_multi 2024-08-20 14:17:54 -07:00
drm_mm.c drm/mm: Remove unused drm_mm_replace_node 2024-06-06 10:24:13 -04:00
drm_mode_config.c drm: Add might_fault to drm_modeset_lock priming 2024-07-18 15:39:54 +02:00
drm_mode_object.c drm/mode_object: Export drm_mode_obj_find_prop_id for tests 2024-05-28 09:57:28 +02:00
drm_modes.c drm: Fix kerneldoc for "Returns" section 2024-08-26 16:40:09 +02:00
drm_modeset_helper.c
drm_modeset_lock.c
drm_of.c
drm_panel_orientation_quirks.c drm: panel-orientation-quirks: Add quirk for Ayn Loki Max 2024-08-12 10:28:33 +02:00
drm_panel.c drm/panel: Avoid warnings w/ panel-simple/panel-edp at shutdown 2024-07-22 09:00:58 -07:00
drm_panic_qr.rs drm/panic: Add a QR code panic screen 2024-08-23 16:55:35 +02:00
drm_panic.c drm/panic: Add a QR code panic screen 2024-08-23 16:55:35 +02:00
drm_pci.c
drm_plane_helper.c
drm_plane.c drm: Export drm_plane_has_format() 2024-06-24 17:08:53 +03:00
drm_prime.c drm: new helper: drm_gem_prime_handle_to_dmabuf() 2024-09-10 13:44:30 -04:00
drm_print.c drm/printer: Allow NULL data in devcoredump printer 2024-08-01 11:00:12 -07:00
drm_privacy_screen_x86.c
drm_privacy_screen.c
drm_probe_helper.c drm: Remove struct drm_mode_config_funcs.output_poll_changed 2024-08-13 16:21:13 +02:00
drm_property.c
drm_rect.c drm: Fix kerneldoc for "Returns" section 2024-08-26 16:40:09 +02:00
drm_self_refresh_helper.c
drm_simple_kms_helper.c drm: add missing MODULE_DESCRIPTION() macros 2024-06-10 12:44:39 +02:00
drm_suballoc.c
drm_syncobj.c struct fd layout change (and conversion to accessor helpers) 2024-09-23 09:35:36 -07:00
drm_sysfs.c drm/edid: add a helper for EDID sysfs property show 2024-05-23 14:37:24 +03:00
drm_trace_points.c
drm_trace.h
drm_vblank_work.c drm: Add drm_vblank_work_flush_all(). 2024-06-24 18:03:18 +02:00
drm_vblank.c drm: Fix kerneldoc for "Returns" section 2024-08-26 16:40:09 +02:00
drm_vma_manager.c
drm_writeback.c
Kconfig drm/panic: Add a QR code panic screen 2024-08-23 16:55:35 +02:00
Makefile Linux 6.11-rc7 2024-09-11 09:18:15 +02:00