Hi,

On Mon, Aug 04, 2025 at 08:40:27AM -0700, Kees Cook wrote:
> 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.kos...@cyberark.com>
> Closes: 
> https://lore.kernel.org/all/as8p193mb2271c4b24bceda31830f37ae84...@as8p193mb2271.eurp193.prod.outlook.com
> Fixes: b6b26d86c61c ("iommu/amd: Add a length limitation for the ivrs_acpihid 
> command-line parameter")
> Signed-off-by: Kees Cook <k...@kernel.org>
> ---
> This was sent out before but it didn't end up on any public mailing list. My 
> mistake!
> Cc: Joerg Roedel <j...@8bytes.org>
> Cc: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
> Cc: Will Deacon <w...@kernel.org>
> Cc: Robin Murphy <robin.mur...@arm.com>
> Cc: <io...@lists.linux.dev>
> ---
>  drivers/iommu/amd/init.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index 7b5af6176de9..e11322d8d775 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -3638,7 +3638,7 @@ static int __init parse_ivrs_acpihid(char *str)
>  {
>       u32 seg = 0, bus, dev, fn;
>       char *hid, *uid, *p, *addr;
> -     char acpiid[ACPIID_LEN] = {0};
> +     char acpiid[ACPIID_LEN + 1] = { }; /* size with NUL terminator */

minor nits below,

s/NUL/NULL
and keeping "{0}" will be as per standard.

otherwise looks good!
Reviewed-by: Ankit Soni <ankit.s...@amd.com>

>       int i;
>  
>       addr = strchr(str, '@');
> @@ -3664,7 +3664,7 @@ static int __init parse_ivrs_acpihid(char *str)
>       /* We have the '@', make it the terminator to get just the acpiid */
>       *addr++ = 0;
>  
> -     if (strlen(str) > ACPIID_LEN + 1)
> +     if (strlen(str) > ACPIID_LEN)
>               goto not_found;
>  
>       if (sscanf(str, "=%s", acpiid) != 1)
> -- 
> 2.34.1
> 

Reply via email to