Page 1 of 1

Invalid Multiboot 2 info from GRUB 2

Posted: Fri Nov 27, 2020 8:12 pm
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?

Re: Invalid Multiboot 2 info from GRUB 2

Posted: Fri Nov 27, 2020 8:18 pm
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.