From: Jani Nikula <jani.nikula@intel.com>
To: Zhenyu Wang <zhenyuw.linux@gmail.com>
Cc: intel-gfx@lists.freedesktop.org, Kees Cook <kees@kernel.org>,
Nicolas Chauvet <kwizart@gmail.com>,
Damian Tometzki <damian@riscv-rocks.de>,
stable@vger.kernel.org
Subject: Re: [PATCH] drm/i915/gvt: fix unterminated-string-initialization warning
Date: Tue, 01 Apr 2025 11:46:37 +0300 [thread overview]
Message-ID: <87bjtg46c2.fsf@intel.com> (raw)
In-Reply-To: <Z-la1kFHvH4zu_X5@dell-wzy>
On Sun, 30 Mar 2025, Zhenyu Wang <zhenyuw.linux@gmail.com> wrote:
> On Thu, Mar 27, 2025 at 02:47:39PM +0200, Jani Nikula wrote:
>> 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.
>>
>
> Indeed...
>
>> 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
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>> ---
>
> Reviewed-by: Zhenyu Wang <zhenyuw.linux@gmail.com>
Thanks for the review, pushed to din.
BR,
Jani.
>
>> drivers/gpu/drm/i915/gvt/opregion.c | 7 ++++---
>> 1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/i915/gvt/opregion.c b/drivers/gpu/drm/i915/gvt/opregion.c
>> index 509f9ccae3a9..dbad4d853d3a 100644
>> --- a/drivers/gpu/drm/i915/gvt/opregion.c
>> +++ b/drivers/gpu/drm/i915/gvt/opregion.c
>> @@ -222,7 +222,6 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
>> u8 *buf;
>> struct opregion_header *header;
>> struct vbt v;
>> - const char opregion_signature[16] = OPREGION_SIGNATURE;
>>
>> gvt_dbg_core("init vgpu%d opregion\n", vgpu->id);
>> vgpu_opregion(vgpu)->va = (void *)__get_free_pages(GFP_KERNEL |
>> @@ -236,8 +235,10 @@ int intel_vgpu_init_opregion(struct intel_vgpu *vgpu)
>> /* emulated opregion with VBT mailbox only */
>> buf = (u8 *)vgpu_opregion(vgpu)->va;
>> header = (struct opregion_header *)buf;
>> - memcpy(header->signature, opregion_signature,
>> - sizeof(opregion_signature));
>> +
>> + static_assert(sizeof(header->signature) == sizeof(OPREGION_SIGNATURE) - 1);
>> + memcpy(header->signature, OPREGION_SIGNATURE, sizeof(header->signature));
>> +
>> header->size = 0x8;
>> header->opregion_ver = 0x02000000;
>> header->mboxes = MBOX_VBT;
>> --
>> 2.39.5
>>
--
Jani Nikula, Intel
prev parent reply other threads:[~2025-04-01 8:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 12:47 [PATCH] drm/i915/gvt: fix unterminated-string-initialization warning Jani Nikula
2025-03-27 13:40 ` ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2025-03-27 13:58 ` ✓ i915.CI.BAT: success " Patchwork
2025-03-27 16:13 ` ✗ i915.CI.Full: failure " Patchwork
2025-03-30 14:53 ` [PATCH] " Zhenyu Wang
2025-04-01 8:46 ` Jani Nikula [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bjtg46c2.fsf@intel.com \
--to=jani.nikula@intel.com \
--cc=damian@riscv-rocks.de \
--cc=intel-gfx@lists.freedesktop.org \
--cc=kees@kernel.org \
--cc=kwizart@gmail.com \
--cc=stable@vger.kernel.org \
--cc=zhenyuw.linux@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.