kern/misc: Add sanity check after grub_strtoul() call
authorLidong Chen <lidong.chen@oracle.com>
Thu, 6 Feb 2025 18:16:57 +0000 (18:16 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
commit477e65eaa007fcdf2ed1843e8c187fe68e60d1fa
tree358f1b46dc88f735ee68916bf511e9ad1062bc80
parented888015e6db17a9ce44ec231e01596fa61469ff
kern/misc: Add sanity check after grub_strtoul() call

When the format string, fmt0, includes a positional argument
grub_strtoul() or grub_strtoull() is called to extract the argument
position. However, the returned argument position isn't fully validated.
If the format is something like "%0$x" then these functions return
0 which leads to an underflow in the calculation of the args index, curn.
The fix is to add a check to ensure the extracted argument position is
greater than 0 before computing curn. Additionally, replace one
grub_strtoull() with grub_strtoul() and change curn type to make code
more correct.

Fixes: CID 473841
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name kern-misc-Add-sanity-check-after-grub_strtoul-call.patch
grub-core/kern/misc.c