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/i915/gvt: fix unterminated-string-initialization warning

Initializing const char opregion_signature[16] = OPREGION_SIGNATURE
(which is "IntelGraphicsMem") drops the NUL termination of the
string. This is intentional, but the compiler doesn't know this.

Switch to initializing header->signature directly from the string
litaral, with sizeof destination rather than source. We don't treat the
signature as a string other than for initialization; it's really just a
blob of binary data.

Add a static assert for good measure to cross-check the sizes.

Reported-by: Kees Cook <kees@kernel.org>
Closes: https://lore.kernel.org/r/20250310222355.work.417-kees@kernel.org
Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13934
Tested-by: Nicolas Chauvet <kwizart@gmail.com>
Tested-by: Damian Tometzki <damian@riscv-rocks.de>
Cc: stable@vger.kernel.org
Reviewed-by: Zhenyu Wang <zhenyuw.linux@gmail.com>
Link: https://lore.kernel.org/r/20250327124739.2609656-1-jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>

+4 -3
+4 -3
drivers/gpu/drm/i915/gvt/opregion.c
··· 222 222 u8 *buf; 223 223 struct opregion_header *header; 224 224 struct vbt v; 225 - const char opregion_signature[16] = OPREGION_SIGNATURE; 226 225 227 226 gvt_dbg_core("init vgpu%d opregion\n", vgpu->id); 228 227 vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL | ··· 235 236 /* emulated opregion with VBT mailbox only */ 236 237 buf = (u8 *)vgpu_opregion(vgpu)->va; 237 238 header = (struct opregion_header *)buf; 238 - memcpy(header->signature, opregion_signature, 239 - sizeof(opregion_signature)); 239 + 240 + static_assert(sizeof(header->signature) == sizeof(OPREGION_SIGNATURE) - 1); 241 + memcpy(header->signature, OPREGION_SIGNATURE, sizeof(header->signature)); 242 + 240 243 header->size = 0x8; 241 244 header->opregion_ver = 0x02000000; 242 245 header->mboxes = MBOX_VBT;