osdep/unix/getroot: Fix potential underflow
authorLidong Chen <lidong.chen@oracle.com>
Wed, 29 Jan 2025 06:48:38 +0000 (06:48 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
commit852b7007e6ba754de9a817fe93ceec7ab1de95fd
tree0d74594e0189cca64e3ff2930604ac0b02945b18
parentbd73b94d3f5589052710068c54ccd4c664b2bd49
osdep/unix/getroot: Fix potential underflow

The entry_len is initialized in grub_find_root_devices_from_mountinfo()
to 0 before the while loop iterates through /proc/self/mountinfo. If the
file is empty or contains only invalid entries entry_len remains
0 causing entry_len - 1 in the subsequent for loop initialization
to underflow. To prevent this add a check to ensure entry_len > 0 before
entering the for loop.

Fixes: CID 473877
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name osdep-unix-getroot-Fix-potential-underflow.patch
grub-core/osdep/linux/getroot.c