In the Linux kernel, the following vulnerability has been resolved:
drm/amdgpu: Fix buffer size in gfxv943init_ cpcomputemicrocode() and rlc_microcode()
The function gfxv943initmicrocode in gfxv943.c was generating about potential truncation of output when using the snprintf function. The issue was due to the size of the buffer 'ucode_prefix' being too small to accommodate the maximum possible length of the string being written into it.
The string being written is "amdgpu/%smec.bin" or "amdgpu/%srlc.bin", where %s is replaced by the value of 'chipname'. The length of this string without the %s is 16 characters. The warning message indicated that 'chipname' could be up to 29 characters long, resulting in a total of 45 characters, which exceeds the buffer size of 30 characters.
To resolve this issue, the size of the 'ucode_prefix' buffer has been reduced from 30 to 15. This ensures that the maximum possible length of the string being written into the buffer will not exceed its size, thus preventing potential buffer overflow and truncation issues.
Fixes the below with gcc W=1: drivers/gpu/drm/amd/amdgpu/gfxv943.c: In function ‘gfxv943earlyinit’: drivers/gpu/drm/amd/amdgpu/gfxv943.c:379:52: warning: ‘%s’ directive output may be truncated writing up to 29 bytes into a region of size 23 [-Wformat-truncation=] 379 | snprintf(fwname, sizeof(fwname), "amdgpu/%srlc.bin", chipname); | ^~ ...... 439 | r = gfxv943initrlcmicrocode(adev, ucodeprefix); | ~~~~~~~~~~~~ drivers/gpu/drm/amd/amdgpu/gfxv943.c:379:9: note: ‘snprintf’ output between 16 and 45 bytes into a destination of size 30 379 | snprintf(fwname, sizeof(fwname), "amdgpu/%srlc.bin", chipname); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/gpu/drm/amd/amdgpu/gfxv943.c:413:52: warning: ‘%s’ directive output may be truncated writing up to 29 bytes into a region of size 23 [-Wformat-truncation=] 413 | snprintf(fwname, sizeof(fwname), "amdgpu/%smec.bin", chipname); | ^~ ...... 443 | r = gfxv943initcpcomputemicrocode(adev, ucodeprefix); | ~~~~~~~~~~~~ drivers/gpu/drm/amd/amdgpu/gfxv943.c:413:9: note: ‘snprintf’ output between 16 and 45 bytes into a destination of size 30 413 | snprintf(fwname, sizeof(fwname), "amdgpu/%smec.bin", chip_name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~