drm/i915/gvt: Rework fix out-of-bounds buffer write into opregion->signature
With gcc-15, there is a new warning treated as error
As shown with gcc-15:
drivers/gpu/drm/i915/gvt/opregion.c: In function intel_vgpu_init_opregion:
drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of char is too long [-Werror=unterminated-string-initialization]
35 | #define OPREGION_SIGNATURE "IntelGraphicsMem"
| ^~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gvt/opregion.c:225:45: note: in expansion of macro OPREGION_SIGNATURE
225 | const char opregion_signature[16] = OPREGION_SIGNATURE;
| ^~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
Rework the previous fix by reverting it, then two options:
- Enlarge the signature field
- Reduce the string size
I would use the latter, but I don't know the runtime implication of it (hence the RFC).
This issue was discovered by building longterm kernel-6.12 in newer fedora, See also:
https://copr.fedorainfracloud.org/coprs/kwizart/kernel-longterm-6.12/
PATCH 1/3 Revert "drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]"
This reverts commit ea26c96d59b27e878fe61e8ef0fed840d2281a2f.
This fix truncates the OPREGION_SIGNATURE to fit into 16 chars instead of enlarging the target field, hence only moving the size missmatch to later.
As shown with gcc-15:drivers/gpu/drm/i915/gvt/opregion.c: In function intel_vgpu_init_opregion:drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of char is too long [-Werror=unterminated-string-initialization]
35 | #define OPREGION_SIGNATURE "IntelGraphicsMem"
| ^~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gvt/opregion.c:225:45: note: in expansion of macro OPREGION_SIGNATURE
225 | const char opregion_signature[16] = OPREGION_SIGNATURE;
| ^~~~~~~~~~~~~~~~~~cc1: all warnings being treated as errors
--- drivers/gpu/drm/i915/gvt/opregion.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gvt/opregion.c +2 -3
@@ -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,8 @@ 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)); +memcpy (header->signature,OPREGION_SIGNATURE , +sizeof (OPREGION_SIGNATURE )); header->size =0x8 ; header->opregion_ver =0x02000000 ; header->mboxes =MBOX_VBT ;
Signature · 1 line
2.49.0
Jani Nikula
maintainerRe: [PATCH 1/3] Revert "drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]"
Quoted 13 lines · Nicolas Chauvet
This reverts commit
ea26c96d59b27e878fe61e8ef0fed840d2281a2f.This fix truncates the
OPREGION_SIGNATUREto fit into 16 chars instead of enlarging the target field, hence only moving the size missmatch to later.As shown with gcc-15:
drivers/gpu/drm/i915/gvt/opregion.c: In functionintel_vgpu_init_opregion:drivers/gpu/drm/i915/gvt/opregion.c:35:28: error: initializer-string for array of char is too long [-Werror=unterminated-string-initialization]
35 | #defineOPREGION_SIGNATURE"IntelGraphicsMem"| ^~~~~~~~~~~~~~~~~~ drivers/gpu/drm/i915/gvt/opregion.c:225:45: note: in expansion of macro OPREGION_SIGNATURE 225 | const char opregion_signature[16] = OPREGION_SIGNATURE; | ^~~~~~~~~~~~~~~~~~
Quoted 6 lines
cc1: all warnings being treated as errors
Reported-by Nicolas Chauvet <[email protected]>Fixes ea26c96d59 ("drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]")Signed-off-by Nicolas Chauvet <[email protected]>
This introduces a buffer overflow.
sizeof(OPREGION_SIGNATURE) == 17.
BR,
Jani.
Quoted 27 lines
--- drivers/gpu/drm/i915/gvt/opregion.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/gpu/drm/i915/gvt/opregion.c +2
-3@@ -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,8 @@ 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)); +memcpy (header->signature,OPREGION_SIGNATURE , +sizeof (OPREGION_SIGNATURE )); header->size =0x8 ; header->opregion_ver =0x02000000 ; header->mboxes =MBOX_VBT ;
Signature · 1 line
Jani Nikula, Intel
RFC PATCH 2/3 drm/i915/gvt: Fix opregion_header->signature size
In reply to Nicolas ChauvetEnlarge the signature field to accept the string termination.
--- drivers/gpu/drm/i915/gvt/opregion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gvt/opregion.c +1 -1
@@ -43,7 +43,7 @@#define DEVICE_TYPE_EFP4 0x10struct opregion_header { -u8 signature[16 ]; +u8 signature[32 ];u32 size;u32 opregion_ver;u8 bios_ver[32 ];
Signature · 1 line
2.49.0
Jani Nikula
maintainerRe: [PATCH 2/3] [RFC] drm/i915/gvt: Fix opregion_header->signature size
Quoted 5 lines · Nicolas Chauvet
Enlarge the signature field to accept the string termination.
Fixes 93615d59912 ("Revert drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]")Signed-off-by Nicolas Chauvet <[email protected]>
Nope, can't do that. The packed struct is used for parsing data in memory.
BR,
Jani.
Quoted 17 lines
--- drivers/gpu/drm/i915/gvt/opregion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/gvt/opregion.c +1
-1@@ -43,7 +43,7 @@#define DEVICE_TYPE_EFP4 0x10struct opregion_header { -u8 signature[16 ]; +u8 signature[32 ];u32 size;u32 opregion_ver;u8 bios_ver[32 ];
Signature · 1 line
Jani Nikula, Intel
Jani Nikula
maintainerRe: [PATCH 2/3] [RFC] drm/i915/gvt: Fix opregion_header->signature size
Quoted 9 lines · Jani Nikula
Quoted 5 lines · Nicolas Chauvet
Enlarge the signature field to accept the string termination.
Fixes 93615d59912 ("Revert drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]")Signed-off-by Nicolas Chauvet <[email protected]>Nope, can't do that. The packed struct is used for parsing data in memory.
Okay, so I mixed this up with display/intel_opregion.c. So it's not used for parsing here... but it's used for generating the data in memory, and we can't change the layout or contents.
Regardless, we can't do either patch 2 or patch 3.
BR,
Jani.
Quoted 22 lines
BR,
Jani.Quoted 17 lines
--- drivers/gpu/drm/i915/gvt/opregion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/gvt/opregion.c +1
-1@@ -43,7 +43,7 @@#define DEVICE_TYPE_EFP4 0x10struct opregion_header { -u8 signature[16 ]; +u8 signature[32 ];u32 size;u32 opregion_ver;u8 bios_ver[32 ];
Signature · 1 line
Jani Nikula, Intel
Re: [PATCH 2/3] [RFC] drm/i915/gvt: Fix opregion_header->signature size
Quoted 9 lines · Jani Nikula
Quoted 7 lines · Jani Nikula
Quoted 5 lines · Nicolas Chauvet
Enlarge the signature field to accept the string termination.
Fixes 93615d59912 ("Revert drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]")Signed-off-by Nicolas Chauvet <[email protected]>
Quoted 8 lines
Quoted 2 lines
Nope, can't do that. The packed struct is used for parsing data in memory.
Okay, so I mixed this up with
display/intel_opregion.c. So it's not used for parsing here... but it's used for generating the data in memory, and we can't change the layout or contents.Regardless, we can't do either patch 2 or patch 3.
Thanks for review.
So does it means the only "Fix" is to drop Werror, at least for intel/gvt code ? I have CONFIG_DRM_I915_WERROR not set but CONFIG_DRM_WERROR=y, (same as Fedora) Unsure why the current Fedora kernel is unaffected by this build failure.
Jani Nikula
maintainerRe: [PATCH 2/3] [RFC] drm/i915/gvt: Fix opregion_header->signature size
Quoted 14 lines · Nicolas Chauvet
Quoted 12 lines · Jani Nikula
Quoted 9 lines · Jani Nikula
Quoted 5 lines · Nicolas Chauvet
Enlarge the signature field to accept the string termination.
Fixes 93615d59912 ("Revert drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]")Signed-off-by Nicolas Chauvet <[email protected]>Nope, can't do that. The packed struct is used for parsing data in memory.
Quoted 8 lines
Quoted 5 lines
Okay, so I mixed this up with
display/intel_opregion.c. So it's not used for parsing here... but it's used for generating the data in memory, and we can't change the layout or contents.Regardless, we can't do either patch 2 or patch 3.
Thanks for review.
So does it means the only "Fix" is to drop Werror, at least for intel/gvt code ?
Of course not. The fix is to address the warning.
There's another thread about this, see my suggestion there [1].
BR,
Jani.
[1] https://lore.kernel.org/r/[email protected]
Quoted 2 lines
I have
CONFIG_DRM_I915_WERRORnot set butCONFIG_DRM_WERROR=y, (same as Fedora) Unsure why the current Fedora kernel is unaffected by this build failure.
Signature · 1 line
Jani Nikula, Intel
RFC PATCH 3/3 drm/i915/gvt: change OPREGION_SIGNATURE name
In reply to Nicolas ChauvetChange the OPREGION_SIGNATURE name so it fit into the opregion_header->signature size.
--- drivers/gpu/drm/i915/gvt/opregion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/i915/gvt/opregion.c +1 -1
@@ -32,7 +32,7 @@#define _INTEL_BIOS_PRIVATE#include "display/intel_vbt_defs.h" -#define OPREGION_SIGNATURE "IntelGraphicsMem" +#define OPREGION_SIGNATURE "IntelGFXMem"#define MBOX_VBT (1<<3)/* device handle */
Signature · 1 line
2.49.0
Jani Nikula
maintainerRe: [PATCH 3/3] [RFC] drm/i915/gvt: change OPREGION_SIGNATURE name
Quoted 6 lines · Nicolas Chauvet
Change the
OPREGION_SIGNATUREname so it fit into theopregion_header->signaturesize.Fixes 93615d59912 ("Revert drm/i915/gvt: Fix out-of-bounds buffer write into opregion->signature[]")Signed-off-by Nicolas Chauvet <[email protected]>
Nope, can't do that. The signature is used for checking data in memory. Which should be obvious if you'd looked at how it's being used or if this was tested.
BR,
Jani.
Quoted 17 lines
--- drivers/gpu/drm/i915/gvt/opregion.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/i915/gvt/opregion.c +1
-1@@ -32,7 +32,7 @@#define _INTEL_BIOS_PRIVATE#include "display/intel_vbt_defs.h" -#define OPREGION_SIGNATURE "IntelGraphicsMem" +#define OPREGION_SIGNATURE "IntelGFXMem"#define MBOX_VBT (1<<3)/* device handle */
Signature · 1 line
Jani Nikula, Intel