Skip to content

Commit bcffd2e

Browse files
committed
iommu/amd: Fix potential buffer overflow in parse_ivrs_acpihid
commit 8dee308 Author: Pavel Paklov <[email protected]> Date: Tue Mar 25 09:22:44 2025 +0000 iommu/amd: Fix potential buffer overflow in parse_ivrs_acpihid 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: ca3bf5d ("iommu/amd: Introduces ivrs_acpihid kernel parameter") Cc: [email protected] Signed-off-by: Pavel Paklov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]> (cherry picked from commit 8dee308) Signed-off-by: Jerry Snitselaar <[email protected]> Upstream-Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git JIRA: https://issues.redhat.com/browse/RHEL-89891
1 parent 297e1d7 commit bcffd2e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/iommu/amd/init.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,14 @@ static int __init parse_ivrs_acpihid(char *str)
36383638
while (*uid == '0' && *(uid + 1))
36393639
uid++;
36403640

3641+
if (strlen(hid) >= ACPIHID_HID_LEN) {
3642+
pr_err("Invalid command line: hid is too long\n");
3643+
return 1;
3644+
} else if (strlen(uid) >= ACPIHID_UID_LEN) {
3645+
pr_err("Invalid command line: uid is too long\n");
3646+
return 1;
3647+
}
3648+
36413649
i = early_acpihid_map_size++;
36423650
memcpy(early_acpihid_map[i].hid, hid, strlen(hid));
36433651
memcpy(early_acpihid_map[i].uid, uid, strlen(uid));

0 commit comments

Comments
 (0)