ACPI: FPDT: properly handle invalid FPDT subtables
authorVasily Khoruzhick <anarsoul@gmail.com>
Wed, 27 Sep 2023 19:50:02 +0000 (12:50 -0700)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 3 Oct 2023 19:12:22 +0000 (21:12 +0200)
commita83c68a3bf7c418c9a46693c63c638852b0c1f4e
tree4cafbe2f77cf186530de2199df04db87681bbab9
parent8a749fd1a8720d4619c91c8b6e7528c0a355c0aa
ACPI: FPDT: properly handle invalid FPDT subtables

Buggy BIOSes may have invalid FPDT subtables, e.g. on my hardware:

S3PT subtable:

7F20FE30: 53 33 50 54 24 00 00 00-00 00 00 00 00 00 18 01  *S3PT$...........*
7F20FE40: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*
7F20FE50: 00 00 00 00

Here the first record has zero length.

FBPT subtable:

7F20FE50:             46 42 50 54-3C 00 00 00 46 42 50 54  *....FBPT<...FBPT*
7F20FE60: 02 00 30 02 00 00 00 00-00 00 00 00 00 00 00 00  *..0.............*
7F20FE70: 2A A6 BC 6E 0B 00 00 00-1A 44 41 70 0B 00 00 00  **..n.....DAp....*
7F20FE80: 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  *................*

And here FBPT table has FBPT signature repeated instead of the first
record.

Current code will be looping indefinitely due to zero length records, so
break out of the loop if record length is zero.

While we are here, add proper handling for fpdt_process_subtable()
failures.

Fixes: d1eb86e59be0 ("ACPI: tables: introduce support for FPDT table")
Cc: All applicable <stable@vger.kernel.org>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
[ rjw: Comment edit, added empty code lines ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/acpi/acpi_fpdt.c