All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/amd: Fix potential buffer overflow in parse_ivrs_acpihid
@ 2025-03-25  9:22 Pavel Paklov
  2025-04-17 14:37 ` Joerg Roedel
  0 siblings, 1 reply; 2+ messages in thread
From: Pavel Paklov @ 2025-03-25  9:22 UTC (permalink / raw)
  To: Joerg Roedel
  Cc: pavel.paklov, Pavel Paklov, Suravee Suthikulpanit, Will Deacon,
	Robin Murphy, Wan Zongshun, iommu, linux-kernel, lvc-project,
	stable

There is a string parsing logic error which can lead to an overflow of hid
or uid buffers. Comparing ACPIID_LEN against a total string length doesn't
take into account the lengths of individual hid and uid buffers so the
check is insufficient in some cases. For example if the length of hid 
string is 4 and the length of the uid string is 260, the length of str 
will be equal to ACPIID_LEN + 1 but uid string will overflow uid buffer 
which size is 256.

The same applies to the hid string with length 13 and uid string with 
length 250.

Check the length of hid and uid strings separately to prevent 
buffer overflow.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: ca3bf5d47cec ("iommu/amd: Introduces ivrs_acpihid kernel parameter")
Cc: stable@vger.kernel.org
Signed-off-by: Pavel Paklov <Pavel.Paklov@cyberprotect.ru>
---
 drivers/iommu/amd/init.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index cb536d372b12..fb82f8035c0f 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -3677,6 +3677,14 @@ static int __init parse_ivrs_acpihid(char *str)
 	while (*uid == '0' && *(uid + 1))
 		uid++;
 
+	if (strlen(hid) >= ACPIHID_HID_LEN) {
+		pr_err("Invalid command line: hid is too long\n");
+		return 1;
+	} else if (strlen(uid) >= ACPIHID_UID_LEN) {
+		pr_err("Invalid command line: uid is too long\n");
+		return 1;
+	}
+
 	i = early_acpihid_map_size++;
 	memcpy(early_acpihid_map[i].hid, hid, strlen(hid));
 	memcpy(early_acpihid_map[i].uid, uid, strlen(uid));
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] iommu/amd: Fix potential buffer overflow in parse_ivrs_acpihid
  2025-03-25  9:22 [PATCH] iommu/amd: Fix potential buffer overflow in parse_ivrs_acpihid Pavel Paklov
@ 2025-04-17 14:37 ` Joerg Roedel
  0 siblings, 0 replies; 2+ messages in thread
From: Joerg Roedel @ 2025-04-17 14:37 UTC (permalink / raw)
  To: Pavel Paklov
  Cc: Suravee Suthikulpanit, Will Deacon, Robin Murphy, Wan Zongshun,
	iommu, linux-kernel, lvc-project, stable

On Tue, Mar 25, 2025 at 09:22:44AM +0000, Pavel Paklov wrote:
> Fixes: ca3bf5d47cec ("iommu/amd: Introduces ivrs_acpihid kernel parameter")
> Cc: stable@vger.kernel.org
> Signed-off-by: Pavel Paklov <Pavel.Paklov@cyberprotect.ru>
> ---
>  drivers/iommu/amd/init.c | 8 ++++++++
>  1 file changed, 8 insertions(+)

Applied for -rc, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-17 14:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25  9:22 [PATCH] iommu/amd: Fix potential buffer overflow in parse_ivrs_acpihid Pavel Paklov
2025-04-17 14:37 ` Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.