Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/amd/ras: Fix NULL deref in ras_core_get_utc_second_timestamp()

ras_core_get_utc_second_timestamp() retrieves the current UTC timestamp
(in seconds since the Unix epoch) through a platform-specific RAS system
callback and is used for timestamping RAS error events.

The function checks ras_core in the conditional statement before calling
the sys_fn callback. However, when the condition fails, the function
prints an error message using ras_core->dev.

If ras_core is NULL, this can lead to a potential NULL pointer
dereference when accessing ras_core->dev.

Add an early NULL check for ras_core at the beginning of the function
and return 0 when the pointer is not valid. This prevents the
dereference and makes the control flow clearer.

Fixes: 13c91b5b4378 ("drm/amd/ras: Add rascore unified interface function")
Cc: YiPeng Chai <YiPeng.Chai@amd.com>
Cc: Dan Carpenter <dan.carpenter@linaro.org>
Cc: Tao Zhou <tao.zhou1@amd.com>
Cc: Hawking Zhang <Hawking.Zhang@amd.com>
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: YiPeng Chai <YiPeng.Chai@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Srinivasan Shanmugam and committed by
Alex Deucher
2b8101cc 15bdd0ea

+5 -2
+5 -2
drivers/gpu/drm/amd/ras/rascore/ras_core.c
··· 527 527 528 528 uint64_t ras_core_get_utc_second_timestamp(struct ras_core_context *ras_core) 529 529 { 530 - if (ras_core && ras_core->sys_fn && 531 - ras_core->sys_fn->get_utc_second_timestamp) 530 + if (!ras_core) 531 + return 0; 532 + 533 + if (ras_core->sys_fn && 534 + ras_core->sys_fn->get_utc_second_timestamp) 532 535 return ras_core->sys_fn->get_utc_second_timestamp(ras_core); 533 536 534 537 RAS_DEV_ERR(ras_core->dev, "Failed to get system timestamp!\n");