platform/x86: ibm_rtl: Fix potential OOB read at signature search
PATCH v2 1/1 platform/x86: ibm_rtl: Fix potential OOB read at signature search
The loop for signature search fetches 22 bytes of struct ibm_rtl_table at each check, while the loop count is calculated in 4 bytes unit, which means that, at the last entry, it fetches over the limit.
Rewrite the loop to use the byte offset and correct the boundary condition check for avoiding the potential OOB access.
---v1->v2: Replace loop counter with offset and correct boundary check
drivers/platform/x86/ibm_rtl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/platform/x86/ibm_rtl.c +4 -4
@@ -234,9 +234,9 @@ static const struct dmi_system_id ibm_rtl_dmi_table[] __initconst = { };static int __init ibm_rtl_init (void ) { -unsigned long ebda_addr, ebda_size; +unsigned long ebda_addr, ebda_size, offset;unsigned int ebda_kb; -int ret = -ENODEV , i; +int ret = -ENODEV ;if (force)pr_warn ("module loaded by force\n" );
@@ -271,9 +271,9 @@ static int __init ibm_rtl_init(void) {return -ENOMEM ;/* search for the _RTL_ signature at the start of the table */ -for (i =0 ; i < ebda_size/sizeof (unsigned int ); i++) { +for (offset =0 ; offset +sizeof (*rtl_table) <= ebda_size; offset +=4 ) {struct ibm_rtl_table __iomem * tmp; - tmp = (struct ibm_rtl_table __iomem *) (ebda_map + i*sizeof (unsigned int )); + tmp = (struct ibm_rtl_table __iomem *) (ebda_map + offset);if ((readq (&tmp->signature) &RTL_MASK ) ==RTL_SIGNATURE ) {phys_addr_t addr;unsigned int plen;
Signature · 1 line
2.55.0
Ilpo Järvinen
maintainerQuoted 8 lines · Takashi Iwai
The loop for signature search fetches 22 bytes of struct
ibm_rtl_tableat each check, while the loop count is calculated in 4 bytes unit, which means that, at the last entry, it fetches over the limit.Rewrite the loop to use the byte offset and correct the boundary condition check for avoiding the potential OOB access.
[...]
Thank you for your contribution, it has been applied to my local review-ilpo-next branch. Note it will show up in the public platform-drivers-x86/review-ilpo-next branch only once I've pushed my local branch there, which might take a while.
FYI [if applicable to your patch], as per Linus' policy change, also fixes are mostly routed through for-next unless the fix is for a commit introduced in the most recent cycle or is clearly a regression fix.
The list of commits applied:
[1/1] platform/x86: ibm_rtl: Fix potential OOB read at signature search
commit: f1d81af2521ad504a20481fef12c358d26e6c3a6
--
i.