drm/i915/bios: vbt-related fixes
Subsystems (3)
cover drm/i915/bios: vbt-related fixes
Michał Grzelak (2):
drm/i915/bios: include whitespace into VBT signature drm/i915/bios: check if VBT#57's tables are zeroed
drivers/gpu/drm/i915/display/intel_bios.c | 17 +++++++++++++---- drivers/gpu/drm/i915/display/intel_vbt_defs.h | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/2 drm/i915/bios: include whitespace into VBT signature
From: Michał Grzelak <[email protected]>
Product name always starts after whitespace which is part of VBT signature as per spec. Extend VBT signature to contain whitespace.
Bspec: 20119
---
This probably should see a Fixes: trailer but I can't find any suitable commit to blame since this existed for quite some time already.
--- drivers/gpu/drm/i915/display/intel_bios.c | 8 ++++---- drivers/gpu/drm/i915/display/intel_vbt_defs.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/i915/display/intel_bios.c +4 -4
@@ -60,7 +60,7 @@* The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that * contain the actual configuration information. The VBT Header, and thus the -* VBT, begins with "$VBT" signature. The VBT Header contains the offset of the +* VBT, begins with "$VBT " signature. The VBT Header contains the offset of the * BDB Header. The data blocks are concatenated after the BDB Header. The data * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of * data. (Block 53, the MIPI Sequence Block is an exception.)
@@ -3131,8 +3131,8 @@ static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)return _vbt + vbt->bdb_offset; } -static const char vbt_signature[] ="$VBT" ; -static const int vbt_signature_len =4 ; +static const char vbt_signature[] ="$VBT " ; +static const int vbt_signature_len =5 ;/** * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
@@ -3235,7 +3235,7 @@ static struct vbt_header *oprom_get_vbt(struct intel_display *display,return NULL ;BUILD_BUG_ON (vbt_signature_len !=sizeof (vbt_signature) -1 ); -BUILD_BUG_ON (vbt_signature_len !=sizeof (u32)); +BUILD_BUG_ON (vbt_signature_len !=sizeof (u32) +1 ); offset =intel_rom_find (rom, *(const u32 *)vbt_signature);if (offset <0 )
drivers/gpu/drm/i915/display/intel_vbt_defs.h +1 -1
@@ -85,7 +85,7 @@ struct bdb_edid_dtd {/** * struct vbt_header - VBT Header structure -* @signature: VBT signature, always starts with "$VBT" +* @signature: VBT signature, always starts with "$VBT " * @version: Version of this structure * @header_size: Size of this structure * @vbt_size: Size of VBT (VBT Header, BDB Header and data blocks)
Signature · 1 line
2.45.2
[email protected]
AI reviewRe: [PATCH v1 1/2] drm/i915/bios: include whitespace into VBT signature
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/i915/bios: 5-byte vbt_signature breaks GVT-g VBT validation - [Low] drm/i915/bios: broken u32…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] drm/i915/bios: 5-byte vbt_signature breaks GVT-g VBT validation
- [Low] drm/i915/bios: broken u32 needle BUILD_BUG_ON in oprom_get_vbt() --
commit 625db8b840b34894e85859eb7f1834474d12585a
Author: Michał Grzelak <[email protected]>
drm/i915/bios: include whitespace into VBT signature
This commit extends vbt_signature from "$VBT" to "$VBT " and updates the corresponding signature length and documentation comments.
Quoted 4 lines
drivers/gpu/drm/i915/display/intel_bios.c +0
-0
[ ... ]
drivers/gpu/drm/i915/display/intel_bios.c static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt) · line 3130
Quoted 8 lines
drivers/gpu/drm/i915/display/intel_bios.c +2
-2@@ -3126,8 +3126,8 @@ static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)return _vbt + vbt->bdb_offset; } -static const char vbt_signature[] ="$VBT" ; -static const int vbt_signature_len =4 ; +static const char vbt_signature[] ="$VBT " ; +static const int vbt_signature_len =5 ;
[Severity: High]
Does requiring a trailing space in vbt_signature break VBT validation for Intel GVT-g guests?
In drivers/gpu/drm/i915/gvt/opregion.c, virt_vbt_generation() zero-fills struct vbt and only populates the first four bytes of v->header.signature:
drivers/gpu/drm/i915/gvt/opregion.c:virt_vbt_generation() {
memset(v, 0, sizeof(struct vbt));
v->header.signature[0] = '$';
v->header.signature[1] = 'V';
v->header.signature[2] = 'B';
v->header.signature[3] = 'T';
}With vbt_signature_len increased to 5, intel_bios_is_valid_vbt() rejects the emulated OpRegion VBT on both current and existing GVT-g hosts because vbt->signature[4] is 0x00, forcing guests to fall back to default VBT port definitions.
drivers/gpu/drm/i915/display/intel_bios.c static struct vbt_header *oprom_get_vbt(struct intel_display *display, · line 3236
Quoted 11 lines
drivers/gpu/drm/i915/display/intel_bios.c +1
-1/** * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT @@ -3230,7 +3230,7 @@ static struct vbt_header *oprom_get_vbt(struct intel_display *display,return NULL ;BUILD_BUG_ON (vbt_signature_len !=sizeof (vbt_signature) -1 ); -BUILD_BUG_ON (vbt_signature_len !=sizeof (u32)); +BUILD_BUG_ON (vbt_signature_len !=sizeof (u32) +1 ); offset =intel_rom_find (rom, *(const u32 *)vbt_signature);if (offset <0 )
[Severity: Low]
Does changing this BUILD_BUG_ON to sizeof(u32) + 1 defeat the check that intel_rom_find() searches for the full vbt_signature?
intel_rom_find() only matches a 32-bit u32 needle and returns the first 4-byte "$VBT" match in the Option ROM without checking the fifth byte, so any earlier 4-byte "$VBT" sequence without a trailing space will stop the ROM scan and cause intel_bios_is_valid_vbt() to fail.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/2 drm/i915/bios: check if VBT#57's tables are zeroed
In reply to Michał GrzelakTurns out there are VBTs which have use_vbt_vswing enabled while their vswing/pre-emphasis override tables contain only zeroes instead of register values.
Return from parsing of Vswing/Pre-emphasis Override if tables are empty. By doing so do not update metadata stored in vspeo substructure.
Return from buffers' allocation if vspeo metadata is missing. Use default vswing/pre-emphasis then because of allocation failure.
---
Somewhat uglier hack would be to simply reset use_vbt_vswing after confirming that tables are empty. However that is more tricky because it would require finding devdata that requests Vswing/Pre-emphasis Override during parse_vswing_preemphasis_override(); which sounds like both wrong abstraction layer and also more lines of code.
--- drivers/gpu/drm/i915/display/intel_bios.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/i915/display/intel_bios.c +9 -0
@@ -2232,6 +2232,12 @@ parse_vswing_preemph_override(struct intel_display *display)if (!block)return ; +/* adjust size for num_tables and num_columns fields */ +if (mem_is_zero (block->tables,get_blocksize (block) -2 )) { +drm_dbg_kms (display->drm,"VBT#57 tables are zeroed\n" ); +return ; + } + display->vbt.vspeo.tables = block->tables; display->vbt.vspeo.num_tables = block->num_tables; display->vbt.vspeo.num_columns = block->num_columns;
@@ -2665,6 +2671,9 @@ static void allocate_vswing_preemph_override(struct intel_bios_encoder_data *devif (!intel_bios_encoder_requests_vspeo (devdata))return ; +if (!devdata->display->vbt.vspeo.tables) +return ; + vspeo =kzalloc_obj (*vspeo);if (!vspeo)return ;
Signature · 1 line
2.45.2
[email protected]
AI reviewRe: [PATCH v1 2/2] drm/i915/bios: check if VBT#57's tables are zeroed
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/i915/bios: whole-block zero check in parse_vswing_preemph_override() - [Medium] drm/i915/bios…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/i915/bios: whole-block zero check in parse_vswing_preemph_override()
- [Medium] drm/i915/bios: u32 underflow in parse_vswing_preemph_override() size check
--
commit 8d486a542cefe34b382644665b58bbe94c62cdf9
Author: Michał Grzelak <[email protected]>
drm/i915/bios: check if VBT#57's tables are zeroed
This commit skips storing VBT block 57 metadata and allocating per-port override buffers when the vswing/pre-emphasis override tables are zeroed.
drivers/gpu/drm/i915/display/intel_bios.c parse_vswing_preemph_override(struct intel_display *display) · line 2234
Quoted 13 lines
drivers/gpu/drm/i915/display/intel_bios.c +5
-0@@ -2227,6 +2227,12 @@ parse_vswing_preemph_override(struct intel_display *display)if (!block)return ; +/* adjust size for num_tables and num_columns fields */ +if (mem_is_zero (block->tables,get_blocksize (block) -2 )) { +drm_dbg_kms (display->drm,"VBT#57 tables are zeroed\n" ); +return ; + }
[Severity: Medium]
Can checking the entire block->tables buffer at once still leave an individual port with an all-zero override table when block 57 is only partially populated?
block->tables contains multiple sub-tables indexed by PHY type and link rate (such as tables 0..3 in intel_bios_get_c10_vspeo() and tables 4..5 in intel_bios_get_c20_vspeo()). If one sub-table in block 57 has non-zero entries while the sub-table selected for another port or link rate is all zeroes, mem_is_zero() across the whole block returns false, and intel_bios_get_*_vspeo() still overrides the default PHY translation table with zeroes and breaks link training. Should the zero check be done on the selected sub-table slice (num_rows * num_columns * sizeof(u32) bytes at idx * num_rows * num_columns) in intel_bios_get_*_vspeo() instead?
[Severity: Medium]
Can get_blocksize(block) - 2 underflow if a malformed VBT header reports a block size of 0 or 1?
init_bdb_block() allocates max(min_size, block_size) + 3 bytes for the BDB entry, but copies the raw 3-byte BDB header without updating the 16-bit size field when block_size < min_size:
drivers/gpu/drm/i915/display/intel_bios.c:init_bdb_block() {
...
entry = kzalloc_flex(*entry, data, max(min_size, block_size) + 3);
...
memcpy(entry->data, block - 3, block_size + 3);
...
}get_blocksize(block) returns that raw 16-bit size as a u32, so subtracting 2 without first checking get_blocksize(block) >= sizeof(*block) wraps to 0xfffffffe or 0xffffffff and passes that length to mem_is_zero(), causing an out-of-bounds read past entry->data.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2