Skip to content

Commit d41903d

Browse files
jnikulajfvogel
authored andcommitted
drm/i915/gvt: fix unterminated-string-initialization warning
commit 2e43ae7dd71cd9bb0d1bce1d3306bf77523feb81 upstream. 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 <[email protected]> Closes: https://lore.kernel.org/r/[email protected] Closes: https://gitlab.freedesktop.org/drm/i915/kernel/-/issues/13934 Tested-by: Nicolas Chauvet <[email protected]> Tested-by: Damian Tometzki <[email protected]> Cc: [email protected] Reviewed-by: Zhenyu Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jani Nikula <[email protected]> (cherry picked from commit 4f8207469094bd04aad952258ceb9ff4c77b6bfa) Signed-off-by: Jani Nikula <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 4b171d4cbfffca02df349ed8405e93ff3b01e36a) Signed-off-by: Jack Vogel <[email protected]>
1 parent fe9ac0d commit d41903d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/gpu/drm/i915/gvt/opregion.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
222222
u8 *buf;
223223
struct opregion_header *header;
224224
struct vbt v;
225-
const char opregion_signature[16] = OPREGION_SIGNATURE;
226225

227226
gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
228227
vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
@@ -236,8 +235,10 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
236235
/* emulated opregion with VBT mailbox only */
237236
buf = (u8 *)vgpu_opregion(vgpu)->va;
238237
header = (struct opregion_header *)buf;
239-
memcpy(header->signature, opregion_signature,
240-
sizeof(opregion_signature));
238+
239+
static_assert(sizeof(header->signature) == sizeof(OPREGION_SIGNATURE) - 1);
240+
memcpy(header->signature, OPREGION_SIGNATURE, sizeof(header->signature));
241+
241242
header->size = 0x8;
242243
header->opregion_ver = 0x02000000;
243244
header->mboxes = MBOX_VBT;

0 commit comments

Comments
 (0)