From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795033816; b=AaNnGzgDEfa/zASPH6P9nk+llyR1Z3gc9eUDsnf+QadWJATYZWD0TpFoZ2SzYKZ6iubk 81GGo67+JRxZJ7/+axVn3T7Fs2yz/0+9rd454bpNkVu0CuLSXEvyoa4lwo1Z+oKuJWemv zZ/7ADfuiLKeTBSmzXwckwRRqiPUee/7QxeCXvJypQ6GNc8BymtJfGzhF5VNtlnkCy3Xc rGD2X/KexpwA8agcNTur4fsrQePUf/vn/j2uXd1Q/J0t8eZqDunUSjcQQbwVuZtyTP/uA 84y0l30ACcH7l81fZbbIkIub/RIiL+66NW8ZpWzvHRT2yOdKOEH2Bx81DLsaxjoUi9Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795033816; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=m3wSuuvA0IDoeHnR3qwIXrQcchdp/YX0AfB3zKAOMR0=; b=Cct8yQobGsd6YsgeVN8h0OZhAUnqMnm5tovP+3axuUXcuWzpvSzoYAQgAt+alcRB0Rg4 78m33DXTh7j9/npn3eahGTce3jwJMItGN9MFdhaTFO5z+Y1kJ6hCJ6ayhoczFH+NQR3IQ +iXPzX1edLrzdGa2HWGy4rj+G0lUp5+RcNHiPGpHqdJIcaFMm5mEXQzvNlXpXMcODHsWa JY2g0lzTfAbYEIvmU6mmogBxiVlg4D8efSWBBWqJL9VD0OBS7wa4lZJUer6la4ADjz6H5 E+kAgQxk/IkeSuplcF55dumayxHISWQT+0QxRN/3fOmGmjYjot1d6MA38mgxW0Cq0Tg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Ba82kcYH; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8BA4606A31C; Wed, 18 Nov 2026 20:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Ba82kcYH Received: by smtp.kernel.org (Postfix) with ESMTPSA id 279E31F000C4; Wed, 18 Nov 2026 20:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795033816; bh=m3wSuuvA0IDoeHnR3qwIXrQcchdp/YX0AfB3zKAOMR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ba82kcYHk57Ydc3i9lt1678k+JSgqiskPeAqHA42+m9dJdiTPWKllqr/go3EDjw6z ulivOGPxgqLku31KS9N3Mp8PKQWzryY2JrzR2cGO6ypvctgnA4O3zgoVSaGvzK5huW QdE0tznBCmvNEFi2uJMTGNfovSwqs/lMVehDWEPQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pengpeng Hou , "Rafael J. Wysocki" , Sasha Levin Subject: [PATCH 6.6 0148/3318] ACPI: FPDT: validate table and record lengths Date: Wed, 18 Nov 2026 15:12:50 +0100 Message-ID: <20261118150318.943431997@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pengpeng Hou [ Upstream commit 458b40fcdd04a9a0334830de5a536d8425454e4b ] FPDT records are supplied by firmware and are walked through length fields stored in the table itself. Check the main-table entry length before reading an entry, check the mapped subtable length before remapping it, and check each record length before saving a typed record pointer for sysfs. This keeps malformed firmware records from being interpreted as complete resume, suspend, or boot records when the current item is shorter than the structure consumed by the driver. Signed-off-by: Pengpeng Hou Link: https://patch.msgid.link/20260706094141.82438-1-pengpeng@iscas.ac.cn Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- drivers/acpi/acpi_fpdt.c | 53 +++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/drivers/acpi/acpi_fpdt.c b/drivers/acpi/acpi_fpdt.c index 271092f2700a1..058d1ad47699a 100644 --- a/drivers/acpi/acpi_fpdt.c +++ b/drivers/acpi/acpi_fpdt.c @@ -165,7 +165,7 @@ static int fpdt_process_subtable(u64 address, u32 subtable_type) struct fpdt_subtable_header *subtable_header; struct fpdt_record_header *record_header; char *signature = (subtable_type == SUBTABLE_FBPT ? "FBPT" : "S3PT"); - u32 length, offset; + u32 length, offset, remaining; int result; if (!fpdt_address_valid(address)) { @@ -179,10 +179,17 @@ static int fpdt_process_subtable(u64 address, u32 subtable_type) if (strncmp((char *)&subtable_header->signature, signature, 4)) { pr_info(FW_BUG "subtable signature and type mismatch!\n"); + acpi_os_unmap_memory(subtable_header, sizeof(*subtable_header)); return -EINVAL; } length = subtable_header->length; + if (length < sizeof(*subtable_header)) { + pr_err(FW_BUG "Invalid FPDT subtable length %u.\n", length); + acpi_os_unmap_memory(subtable_header, sizeof(*subtable_header)); + return -EINVAL; + } + acpi_os_unmap_memory(subtable_header, sizeof(*subtable_header)); subtable_header = acpi_os_map_memory(address, length); @@ -191,17 +198,29 @@ static int fpdt_process_subtable(u64 address, u32 subtable_type) offset = sizeof(*subtable_header); while (offset < length) { - record_header = (void *)subtable_header + offset; - offset += record_header->length; + remaining = length - offset; + if (remaining < sizeof(*record_header)) { + pr_err(FW_BUG "Truncated FPDT record header.\n"); + result = -EINVAL; + goto err; + } - if (!record_header->length) { - pr_err(FW_BUG "Zero-length record found in FPTD.\n"); + record_header = (void *)subtable_header + offset; + if (record_header->length < sizeof(*record_header) || + record_header->length > remaining) { + pr_err(FW_BUG "Invalid FPDT record length %u.\n", + record_header->length); result = -EINVAL; goto err; } + offset += record_header->length; switch (record_header->type) { case RECORD_S3_RESUME: + if (record_header->length < sizeof(*record_resume)) { + result = -EINVAL; + goto err; + } if (subtable_type != SUBTABLE_S3PT) { pr_err(FW_BUG "Invalid record %d for subtable %s\n", record_header->type, signature); @@ -218,6 +237,10 @@ static int fpdt_process_subtable(u64 address, u32 subtable_type) goto err; break; case RECORD_S3_SUSPEND: + if (record_header->length < sizeof(*record_suspend)) { + result = -EINVAL; + goto err; + } if (subtable_type != SUBTABLE_S3PT) { pr_err(FW_BUG "Invalid %d for subtable %s\n", record_header->type, signature); @@ -233,6 +256,10 @@ static int fpdt_process_subtable(u64 address, u32 subtable_type) goto err; break; case RECORD_BOOT: + if (record_header->length < sizeof(*record_boot)) { + result = -EINVAL; + goto err; + } if (subtable_type != SUBTABLE_FBPT) { pr_err(FW_BUG "Invalid %d for subtable %s\n", record_header->type, signature); @@ -289,7 +316,21 @@ static int __init acpi_init_fpdt(void) } while (offset < header->length) { + if (header->length - offset < sizeof(*subtable)) { + pr_err(FW_BUG "Truncated FPDT subtable entry.\n"); + result = -EINVAL; + goto err_subtable; + } + subtable = (void *)header + offset; + if (subtable->length < sizeof(*subtable) || + subtable->length > header->length - offset) { + pr_err(FW_BUG "Invalid FPDT subtable entry length %u.\n", + subtable->length); + result = -EINVAL; + goto err_subtable; + } + switch (subtable->type) { case SUBTABLE_FBPT: case SUBTABLE_S3PT: @@ -302,7 +343,7 @@ static int __init acpi_init_fpdt(void) /* Other types are reserved in ACPI 6.4 spec. */ break; } - offset += sizeof(*subtable); + offset += subtable->length; } return 0; err_subtable: -- 2.53.0