Skip to content

Fix stack overflow caused by infinite recursion#303

Open
marta-lewandowska wants to merge 1 commit into
rhboot:mainfrom
marta-lewandowska:fix_stack_overflow
Open

Fix stack overflow caused by infinite recursion#303
marta-lewandowska wants to merge 1 commit into
rhboot:mainfrom
marta-lewandowska:fix_stack_overflow

Conversation

@marta-lewandowska
Copy link
Copy Markdown

@marta-lewandowska marta-lewandowska commented Apr 23, 2026

if p < 4 the loop will continue forever because efidp_node_size (called by efidp_size) returns -1 if the length of the args passed to it are < 4. Fixes CVE-2026-6862

Resolves rhbz#2459982

Signed-off-by: Marta Lewandowska mlewando@redhat.com

@marta-lewandowska marta-lewandowska force-pushed the fix_stack_overflow branch 2 times, most recently from 2815924 to bc3a31b Compare April 23, 2026 11:59
Comment thread src/loadopt.c Outdated
* need to test it. if it /is/ size, there's no optional data. */
sz = ucs2size(opt->description, ret);
p = (uint8_t *)(opt->description) + sz;
if (sizeof(p) < 4)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check looks strange. p is a uint8_t pointer, so sizeof(p) is either 4 (for 32bit) or 8 (for 64bit), and sizeof(p) < 4 is always false.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right. that's not much of a fix. could you please take a look at v2? :)

@marta-lewandowska marta-lewandowska force-pushed the fix_stack_overflow branch 2 times, most recently from e729692 to c6915f6 Compare May 6, 2026 12:09
Copy link
Copy Markdown
Contributor

@lcp lcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is probably too late. If one of the EFI device path node contains 0 Length, it could cause problem in efidp_is_valid() already.
In such case, limit -= hdr->length; in efidp_is_valid() won't decrease limit and the while loop just keeps running and running...

@lcp
Copy link
Copy Markdown
Contributor

lcp commented May 11, 2026

I'd suggest to insert a if (hdr->length < 4) inside the while loop in efidp_is_valid().
https://github.com/rhboot/efivar/blob/39/src/include/efivar/efivar-dp.h#L1125

It will avoid the infinite loop I mentioned above and the negative size from efidp_size().

@marta-lewandowska
Copy link
Copy Markdown
Author

@lcp yes you're right of course. thank you for all of the help :)

Comment thread src/loadopt.c Outdated
for (sz = 0; sz < opt->file_path_list_length;
sz += efidp_size((const_efidp)(p + sz)))
;
sz += efidp_size((const_efidp)(p + sz)))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change of indentation is not necessary.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry; not intentional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another unnecessary change in src/loadopt.c remains...

If an EFI device path node has 0 length, loop will never terminate.

Resolves: bz#2459982
Resolves: CVE-2026-6862

Signed-off-by: Marta Lewandowska <mlewando@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants