Find a file
Jesse.Zhang 7518cc4fdd amdgpu: Add parameter validation to amdgpu_bo functions to fix SIGSEGV
This commit adds essential parameter validation to several key
functions in amdgpu_bo.c to prevent null pointer dereferences
that were causing segmentation faults and improve overall code
robustness.

The changes address the following crash scenario:
Received signal SIGSEGV.
Stack trace:
 #0 [fatal_sig_handler+0x17b]
 #1 [__sigaction+0x50]
 #2 [amdgpu_bo_alloc+0x37]
 #3 [__igt_unique____real_main461+0x7d5]
 #4 [main+0x2d]
 #5 [__libc_init_first+0x90]
 #6 [__libc_start_main+0x80]
 #7 [_start+0x25]

Changes made:

1. amdgpu_bo_alloc():
   - Validate alloc_buffer and buf_handle parameters
   - Return -EINVAL if either is NULL
   - Prevents null pointer dereference in memset and subsequent operations

2. amdgpu_bo_set_metadata():
   - Validate info parameter
   - Return -EINVAL if info is NULL
   - Prevents accessing invalid metadata structure

3. amdgpu_bo_query_info():
   - Validate info parameter in addition to existing bo->handle check
   - Return -EINVAL if info is NULL
   - Prevents writing to invalid info pointer

4. amdgpu_bo_list_create():
   - Validate resources parameter
   - Return -EINVAL if resources is NULL when number_of_resources > 0
   - Prevents invalid memory access during resource array processing

These changes ensure proper error handling when callers pass invalid
null pointers, preventing potential segmentation faults and making
the API more robust against programming errors. The validation occurs
early in each function to minimize performance impact.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
2025-10-22 08:59:55 +08:00
amdgpu amdgpu: Add parameter validation to amdgpu_bo functions to fix SIGSEGV 2025-10-22 08:59:55 +08:00
android android: Fix 32-bit app crashing in 64-bit Android 2018-12-18 21:18:19 +01:00
data amdgpu: update marketing names 2025-08-11 09:52:25 -04:00
etnaviv meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
exynos meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
freedreno meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
include/drm drm/amdgpu: Add user queue HQD count to hw_ip info 2025-07-09 09:40:34 +08:00
intel meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
man Switch URLs to mesa/libdrm 2025-06-08 12:16:36 +00:00
nouveau meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
omap meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
radeon meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
tegra meson: Do not check for meson version >=0.54 2025-05-20 11:05:27 +02:00
tests xf86drm: Fix drmDevicesEqual() for nodes on the faux bus 2025-10-14 19:38:10 +03:00
vc4 Delete all Makefile.sources files 2024-07-30 10:54:23 -04:00
.editorconfig Add meson build system 2018-01-12 09:40:48 -08:00
.gitignore add a minimal .gitignore back 2019-12-17 22:37:39 +00:00
.gitlab-ci.yml Switch URLs to mesa/libdrm 2025-06-08 12:16:36 +00:00
Android.bp android: add genrule for generated_static_table_fourcc.h 2024-10-20 12:26:53 +02:00
Android.sources.bp Convert to Android.bp 2024-07-29 14:47:30 -04:00
Android.sources.bp.mk Convert to Android.bp 2024-07-29 14:47:30 -04:00
CleanSpec.mk tests: Split helpers into library 2015-12-18 17:43:40 +00:00
CONTRIBUTING.rst doc: Rename README&CONTRIBUTING to .rst 2018-10-17 17:17:19 +02:00
core-symbols.txt xf86drmMode: add drmModeCloseFB() 2023-11-20 12:55:31 +00:00
gen_table_fourcc.py gen_table_fourcc: strip _MODIFIER suffix for INVALID 2022-06-08 14:02:48 +02:00
libdrm.pc.in Revert "Fix pkgconfig includes for /usr/include/drm" 2010-04-09 16:33:38 -04:00
libdrm_lists.h use standard __typeof__() instead of GNU extension typeof() 2022-01-19 16:08:31 -08:00
libdrm_macros.h libdrm: Use mmap64 instead of __mmap2 2019-04-25 10:55:13 +01:00
libsync.h include poll.h instead of sys/poll.h 2024-04-10 23:27:16 +00:00
meson.build build: bump version to 2.4.127 2025-10-14 18:44:17 +02:00
meson_options.txt meson: auto-enable etnaviv on arm, arc, mips and loongarch architectures 2022-08-30 16:03:36 +01:00
README.rst README.rst: Include some notes about syncing uapi headers 2021-06-22 11:16:04 +00:00
RELEASING releasing: s/master/main/ 2021-12-21 13:07:01 +00:00
symbols-check.py symbols-check: Add _fbss, _fdata, _ftext 2024-03-25 15:35:58 +00:00
util_double_list.h use standard __typeof__() instead of GNU extension typeof() 2022-01-19 16:08:31 -08:00
util_math.h Fix build with -std=c11 2018-09-05 13:09:29 +01:00
xf86atomic.h atomic: fix atomic_add_unless() fallback's return value 2022-08-23 22:49:34 +00:00
xf86drm.c xf86drm: Drop drmFauxDeviceInfo 2025-10-14 19:38:10 +03:00
xf86drm.h xf86drm: Drop drmFauxDeviceInfo 2025-10-14 19:38:10 +03:00
xf86drmHash.c xf86drmHash: remove unused loop variable 2018-11-09 10:59:11 +00:00
xf86drmHash.h tests/hash: extract test out of xf86drmHash.c 2015-04-05 15:19:42 +01:00
xf86drmMode.c xf86drmMode: add drmModeCloseFB() 2023-11-20 12:55:31 +00:00
xf86drmMode.h xf86drmMode: add drmModeCloseFB() 2023-11-20 12:55:31 +00:00
xf86drmRandom.c libdrm: annotate public functions 2018-09-19 22:46:45 -07:00
xf86drmRandom.h tests/random: extract test out of xf86drmRandom.c 2015-04-05 15:33:33 +01:00
xf86drmSL.c libdrm: annotate public functions 2018-09-19 22:46:45 -07:00

libdrm - userspace library for drm
----------------------------------

This is libdrm, a userspace library for accessing the DRM, direct rendering
manager, on Linux, BSD and other operating systems that support the ioctl
interface.
The library provides wrapper functions for the ioctls to avoid exposing the
kernel interface directly, and for chipsets with drm memory manager, support
for tracking relocations and buffers.
New functionality in the kernel DRM drivers typically requires a new libdrm,
but a new libdrm will always work with an older kernel.

libdrm is a low-level library, typically used by graphics drivers such as
the Mesa drivers, the X drivers, libva and similar projects.

Syncing with the Linux kernel headers
-------------------------------------

The library should be regularly updated to match the recent changes in the
`include/uapi/drm/`.

libdrm maintains a human-readable version for the token format modifier, with
the simpler ones being extracted automatically from `drm_fourcc.h` header file
with the help of a python script.  This might not always possible, as some of
the vendors require decoding/extracting them programmatically.  For that
reason one can enhance the current vendor functions to include/provide the
newly added token formats, or, in case there's no such decoding
function, to add one that performs the tasks of extracting them.

For simpler format modifier tokens there's a script (gen_table_fourcc.py) that
creates a static table, by going over `drm_fourcc.h` header file. The script
could be further modified if it can't handle new (simpler) token format
modifiers instead of the generated static table.

Compiling
---------

To set up meson:

    meson builddir/

By default this will install into /usr/local, you can change your prefix
with --prefix=/usr (or `meson configure builddir/ -Dprefix=/usr` after 
the initial meson setup).

Then use ninja to build and install:

    ninja -C builddir/ install

If you are installing into a system location you will need to run install
separately, and as root.