Skip to content

Commit b6b26d8

Browse files
Gavrilov Iliajoergroedel
authored andcommitted
iommu/amd: Add a length limitation for the ivrs_acpihid command-line parameter
The 'acpiid' buffer in the parse_ivrs_acpihid function may overflow, because the string specifier in the format string sscanf() has no width limitation. Found by InfoTeCS on behalf of Linux Verification Center (linuxtesting.org) with SVACE. Fixes: ca3bf5d ("iommu/amd: Introduces ivrs_acpihid kernel parameter") Cc: stable@vger.kernel.org Signed-off-by: Ilia.Gavrilov <Ilia.Gavrilov@infotecs.ru> Reviewed-by: Kim Phillips <kim.phillips@amd.com> Link: https://lore.kernel.org/r/20230202082719.1513849-1-Ilia.Gavrilov@infotecs.ru Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 05d227e commit b6b26d8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

drivers/iommu/amd/init.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3475,15 +3475,26 @@ static int __init parse_ivrs_hpet(char *str)
34753475
return 1;
34763476
}
34773477

3478+
#define ACPIID_LEN (ACPIHID_UID_LEN + ACPIHID_HID_LEN)
3479+
34783480
static int __init parse_ivrs_acpihid(char *str)
34793481
{
34803482
u32 seg = 0, bus, dev, fn;
34813483
char *hid, *uid, *p, *addr;
3482-
char acpiid[ACPIHID_UID_LEN + ACPIHID_HID_LEN] = {0};
3484+
char acpiid[ACPIID_LEN] = {0};
34833485
int i;
34843486

34853487
addr = strchr(str, '@');
34863488
if (!addr) {
3489+
addr = strchr(str, '=');
3490+
if (!addr)
3491+
goto not_found;
3492+
3493+
++addr;
3494+
3495+
if (strlen(addr) > ACPIID_LEN)
3496+
goto not_found;
3497+
34873498
if (sscanf(str, "[%x:%x.%x]=%s", &bus, &dev, &fn, acpiid) == 4 ||
34883499
sscanf(str, "[%x:%x:%x.%x]=%s", &seg, &bus, &dev, &fn, acpiid) == 5) {
34893500
pr_warn("ivrs_acpihid%s option format deprecated; use ivrs_acpihid=%s@%04x:%02x:%02x.%d instead\n",
@@ -3496,6 +3507,9 @@ static int __init parse_ivrs_acpihid(char *str)
34963507
/* We have the '@', make it the terminator to get just the acpiid */
34973508
*addr++ = 0;
34983509

3510+
if (strlen(str) > ACPIID_LEN + 1)
3511+
goto not_found;
3512+
34993513
if (sscanf(str, "=%s", acpiid) != 1)
35003514
goto not_found;
35013515

0 commit comments

Comments
 (0)