Skip to contentSkip to conversation

fix attempt to seek outside of the file error when parsing xen ELF notes

PATCH In review Michael Chang 3 participants 4 messages Mar 3, 2016 – Mar 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix attempt to seek outside of the file error when parsing xen ELF notes

The kernel bzImage payload length appears to be incorrectly minus by 4 when trying to grub_file_offset_open for the uncompressed vmlinux image. If gzip used as compressor it will lead to the file->size read from offset of crc32 instead of the uncompressed image size.

[1]
http://www.onicos.com/staff/iz/formats/gzip.html

---
 grub-core/loader/i386/xen_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/loader/i386/xen_file.c +2 -2
index 5836218..37f9ad8 100644
@@ -55,11 +55,11 @@ grub_xen_file (grub_file_t file)
   grub_dprintf ("xen", "found bzimage payload 0x%llx-0x%llx\n",
 		(unsigned long long) (lh.setup_sects + 1) * 512
 		+ lh.payload_offset,
-		(unsigned long long) lh.payload_length - 4);
+		(unsigned long long) lh.payload_length);
 
   off_file = grub_file_offset_open (file, (lh.setup_sects + 1) * 512
 				    + lh.payload_offset,
-				    lh.payload_length - 4);
+				    lh.payload_length);
   if (!off_file)
     goto fail;
 
Signature · 1 line
1.8.5.6
#1 lore raw

03.03.2016 10:33, Michael Chang пишет:

Quoted 20 lines

The kernel bzImage payload length appears to be incorrectly minus by 4 when trying to grub_file_offset_open for the uncompressed vmlinux image. If gzip used as compressor it will lead to the file->size read from offset of crc32 instead of the uncompressed image size.

[1]
http://www.onicos.com/staff/iz/formats/gzip.html

---
 grub-core/loader/i386/xen_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/loader/i386/xen_file.c +0 -0
index 5836218..37f9ad8 100644
@@ -55,11 +55,11 @@ grub_xen_file (grub_file_t file)
   grub_dprintf ("xen", "found bzimage payload 0x%llx-0x%llx\n",
 		(unsigned long long) (lh.setup_sects + 1) * 512
 		+ lh.payload_offset,

grub-core/loader/i386/xen_file.c grub_xen_file (grub_file_t file) · line 65

Quoted 10 lines
grub-core/loader/i386/xen_file.c +2 -2
-		(unsigned long long) lh.payload_length - 4);
+		(unsigned long long) lh.payload_length);
 
   off_file = grub_file_offset_open (file, (lh.setup_sects + 1) * 512
 				    + lh.payload_offset,
-				    lh.payload_length - 4);
+				    lh.payload_length);
   if (!off_file)
     goto fail;
 

Looks strange indeed. I wonder what was original intention, code looked this way from the very beginning. May be it is required with some other format?

#2 lore raw
Quoted 23 lines · Andrei Borzenkov

03.03.2016 10:33, Michael Chang пишет:

Quoted 22 lines

The kernel bzImage payload length appears to be incorrectly minus by 4 when trying to grub_file_offset_open for the uncompressed vmlinux image. If gzip used as compressor it will lead to the file->size read from offset of crc32 instead of the uncompressed image size.

[1]
http://www.onicos.com/staff/iz/formats/gzip.html

---
 grub-core/loader/i386/xen_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/loader/i386/xen_file.c +1 -1
index 5836218..37f9ad8 100644
@@ -55,11 +55,11 @@ grub_xen_file (grub_file_t file)
   grub_dprintf ("xen", "found bzimage payload 0x%llx-0x%llx\n",
 		(unsigned long long) (lh.setup_sects + 1) * 512
 		+ lh.payload_offset,
-		(unsigned long long) lh.payload_length - 4);
+		(unsigned long long) lh.payload_length);
 
Quoted 11 lines

grub-core/loader/i386/xen_file.c grub_xen_file (grub_file_t file) · line 65

Quoted 8 lines
grub-core/loader/i386/xen_file.c +1 -1
   off_file = grub_file_offset_open (file, (lh.setup_sects + 1) * 512
 				    + lh.payload_offset,
-				    lh.payload_length - 4);
+				    lh.payload_length);
   if (!off_file)
     goto fail;
 

Looks strange indeed. I wonder what was original intention, code looked this way from the very beginning. May be it is required with some other format?

I also wonder that possibility. But looking into other formats it looks to me more likely a bug than intended.

Unless there's unexpected padding in the end of payload, it looks to me that xz would also be failed in footer sanity check as the last stream block's footer magic is discarded by that size of payload_length - 4.

Thanks,
Michael

#3 lore raw
In reply to Andrei Borzenkov
Quoted 27 lines · Andrei Borzenkov

03.03.2016 10:33, Michael Chang пишет:

Quoted 1 line

The kernel bzImage payload length appears to be incorrectly minus by 4

when

Quoted 1 line

trying to grub_file_offset_open for the uncompressed vmlinux image. If

gzip

Quoted 1 line

used as compressor it will lead to the file->size read from offset of

crc32

Review

Quoted 9 lines

instead of the uncompressed image size.

[1]
http://www.onicos.com/staff/iz/formats/gzip.html

---
 grub-core/loader/i386/xen_file.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/grub-core/loader/i386/xen_file.c

Quoted 10 lines

index 5836218..37f9ad8 100644

grub-core/loader/i386/xen_file.c +1 -1
@@ -55,11 +55,11 @@ grub_xen_file (grub_file_t file)
   grub_dprintf ("xen", "found bzimage payload 0x%llx-0x%llx\n",
              (unsigned long long) (lh.setup_sects + 1) * 512
              + lh.payload_offset,
-             (unsigned long long) lh.payload_length - 4);
+             (unsigned long long) lh.payload_length);
 
Quoted 12 lines

grub-core/loader/i386/xen_file.c grub_xen_file (grub_file_t file) · line 65

Quoted 8 lines
grub-core/loader/i386/xen_file.c +1 -1
   off_file = grub_file_offset_open (file, (lh.setup_sects + 1) * 512
                                  + lh.payload_offset,
-                                 lh.payload_length - 4);
+                                 lh.payload_length);
   if (!off_file)
     goto fail;
 

Looks strange indeed. I wonder what was original intention, code looked this way from the very beginning. May be it is required with some other format?

I don't remember and I haven't kept the image I originally used for this. So I can't check if this doesn't break anything. But it looks like it fixes stuff, so I'm going to commit it

Quoted 6 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel