Invalid Multiboot 2 info from GRUB 2

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
kotovalexarian
Member
Member
Posts: 38
Joined: Tue Nov 24, 2020 10:17 am
Contact:

Invalid Multiboot 2 info from GRUB 2

Post by kotovalexarian »

Hello. I'm trying to parse Multiboot 2 info tags from GRUB 2. However, I only can parse the first one. Then memory looks strange.

What it parsed successfully:

Code: Select all

Multiboot 2 info
  size: 864
  reserved1: 0
Multiboot 2 tag
  type: 21 (image load base phys addr)
  size: 12
  load base addr: 4194304
The corresponding memory (20 bytes from 0 to 19) is:

Code: Select all

96 3 0 0 0 0 0 0 21 0 0 0 12 0 0 0 0 0 64 0
The first 8 bytes is header, the following 12 bytes is the tag.

However, next 8 bytes from 20 to 27 look strange:

Code: Select all

0 0 232 133 1 0 0 0
Four bytes for tag type, four bytes for tag size, according to paragraph 3.6.2 of the spec.

Here we have tag type 133 232 0 0 = 0x85e80000 = 2246574080 which is impossible (there are only 21 types).

Also we have tag size 0 0 0 1 = 1 which is also impossible (too small, must be at least 8 bytes).

Can you help me to investigate the situation?
User avatar
kotovalexarian
Member
Member
Posts: 38
Joined: Tue Nov 24, 2020 10:17 am
Contact:

Re: Invalid Multiboot 2 info from GRUB 2

Post by kotovalexarian »

Sorry, I had to look to my older code which works perfectly to learn that tags are aligned:

Code: Select all

for (
    struct multiboot_tag *tag = (struct multiboot_tag*)(base + 8);
    tag->type != MULTIBOOT_TAG_TYPE_END;
    tag = (struct multiboot_tag*)((unsigned char*)tag + ((tag->size + 7) & ~7)) // HERE!!!
) {
    if (!print_multiboot_tag(kinfo, tag)) {
        return 0;
    }
}
Topic may be closed.
Post Reply