Skip to content

Commit 736db11

Browse files
keesgregkh
authored andcommitted
iommu/amd: Avoid stack buffer overflow from kernel cmdline
[ Upstream commit 8503d0f ] While the kernel command line is considered trusted in most environments, avoid writing 1 byte past the end of "acpiid" if the "str" argument is maximum length. Reported-by: Simcha Kosman <simcha.kosman@cyberark.com> Closes: https://lore.kernel.org/all/AS8P193MB2271C4B24BCEDA31830F37AE84A52@AS8P193MB2271.EURP193.PROD.OUTLOOK.COM Fixes: b6b26d8 ("iommu/amd: Add a length limitation for the ivrs_acpihid command-line parameter") Signed-off-by: Kees Cook <kees@kernel.org> Reviewed-by: Ankit Soni <Ankit.Soni@amd.com> Link: https://lore.kernel.org/r/20250804154023.work.970-kees@kernel.org Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f4bc3cd commit 736db11

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/iommu/amd/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,7 +3596,7 @@ static int __init parse_ivrs_acpihid(char *str)
35963596
{
35973597
u32 seg = 0, bus, dev, fn;
35983598
char *hid, *uid, *p, *addr;
3599-
char acpiid[ACPIID_LEN] = {0};
3599+
char acpiid[ACPIID_LEN + 1] = { }; /* size with NULL terminator */
36003600
int i;
36013601

36023602
addr = strchr(str, '@');
@@ -3622,7 +3622,7 @@ static int __init parse_ivrs_acpihid(char *str)
36223622
/* We have the '@', make it the terminator to get just the acpiid */
36233623
*addr++ = 0;
36243624

3625-
if (strlen(str) > ACPIID_LEN + 1)
3625+
if (strlen(str) > ACPIID_LEN)
36263626
goto not_found;
36273627

36283628
if (sscanf(str, "=%s", acpiid) != 1)

0 commit comments

Comments
 (0)