Skip to contentSkip to conversation

S390: file size checking in load_image_targphys and certain ram sizes

Qemu-devel In review Christian Borntraeger 4 participants 9 messages May 3, 2012 – May 18, 2012

lore
Share & tools
lore
#0 lore raw

Ben, Alex,

commit 17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]

            kernel_size = load_image_targphys(kernel_filename, 0, ram_size);

[...]

The problem is now, that load_image_targphys has max_sz as an int (32bit), but ram_size is a ram_addr_t (64bit).
So for a ramsize of lets say 3GB the comparison in load_image_targphys fails:

    if (size > max_sz) {
        return -1;
    }

There are several potential ways of solving, suggestions for a better solution than the patch below are welcome.

hw/loader.c +1 -1
index 415cdce..8a6c99d 100644
@@ -103,7 +103,7 @@ ssize_t read_targphys(const char *name,
 
 /* return the size or -1 if error */
 int load_image_targphys(const char *filename,
-                       target_phys_addr_t addr, int max_sz)
+                       target_phys_addr_t addr, uint64_t max_sz)
 {
     int size;
 
hw/loader.h +1 -1
index fbcaba9..5cfa6df 100644
@@ -4,7 +4,7 @@
 /* loader.c */
 int get_image_size(const char *filename);
 int load_image(const char *filename, uint8_t *addr); /* deprecated */
-int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
+int load_image_targphys(const char *filename, target_phys_addr_t, uint64_t);
 int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
              void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
              uint64_t *highaddr, int big_endian, int elf_machine,
#1 lore raw
Quoted 18 lines · Christian Borntraeger

Ben, Alex,

commit 17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]

           kernel_size = load_image_targphys(kernel_filename, 0, ram_size);

[...]

The problem is now, that load_image_targphys has max_sz as an int (32bit), but ram_size is a ram_addr_t (64bit).
So for a ramsize of lets say 3GB the comparison in load_image_targphys fails:

Quoted 6 lines
   if (size > max_sz) {
       return -1;
   }

There are several potential ways of solving, suggestions for a better solution than the patch below are welcome.

The proposed solution looks perfectly fine. In fact I remember having had a very similar discussion on an ARM issue and the conclusion we came up with was to use the biggest available data type: uint64_t.

Pleas repost this as a proper patch with Signed-off-by :).

Alex

#2 lore raw

PATCH 1/1 Fix size checking in load_image_targphys to accept max_size > INT_MAX

commit 17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]

            kernel_size = load_image_targphys(kernel_filename, 0, ram_size);

[...]

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes > INT_MAX.
Lets change the max_sz parameter to a uint64_t.

---
 hw/loader.c |    2 +-
 hw/loader.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/loader.c +1 -1
index 415cdce..7d64113 100644
@@ -103,7 +103,7 @@ ssize_t read_targphys(const char *name,
 
 /* return the size or -1 if error */
 int load_image_targphys(const char *filename,
-			target_phys_addr_t addr, int max_sz)
+                        target_phys_addr_t addr, uint64_t max_sz)
 {
     int size;
 
hw/loader.h +1 -1
index fbcaba9..5cfa6df 100644
@@ -4,7 +4,7 @@
 /* loader.c */
 int get_image_size(const char *filename);
 int load_image(const char *filename, uint8_t *addr); /* deprecated */
-int load_image_targphys(const char *filename, target_phys_addr_t, int max_sz);
+int load_image_targphys(const char *filename, target_phys_addr_t, uint64_t);
 int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
              void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
              uint64_t *highaddr, int big_endian, int elf_machine,
Signature · 1 line
1.7.9.6
#3 lore raw

Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX

Quoted 11 lines · Christian Borntraeger

commit 17df768c1e4580f03301d18ea938d3557d441911 load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]
           kernel_size = load_image_targphys(kernel_filename, 0, ram_size); [...]

Quoted 5 lines

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes > INT_MAX.
Lets change the max_sz parameter to a uint64_t.

A patch equivalent to this has already been submitted:
http://patchwork.ozlabs.org/patch/146165/
We should be applying that one, it has already been reviewed.

Anthony?

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX

Quoted 9 lines
Quoted 5 lines

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes > INT_MAX.
Lets change the max_sz parameter to a uint64_t.

A patch equivalent to this has already been submitted:
http://patchwork.ozlabs.org/patch/146165/
We should be applying that one, it has already been reviewed.

Right.

Quoted 2 lines

Anthony?

AFAIK Anthony is on holiday. It would be good, if we could have that before 1.1, so shall we wait or are there other maintainers willing to accept that patch?

Christian

#5 lore raw

Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX

In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 5 lines

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes > INT_MAX.
Lets change the max_sz parameter to a uint64_t.

A patch equivalent to this has already been submitted:
http://patchwork.ozlabs.org/patch/146165/
We should be applying that one, it has already been reviewed.

Anthony?

Ping?

#6 lore raw

Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX

In reply to Peter Maydell
Quoted 16 lines · Peter Maydell
Quoted 15 lines · Christian Borntraeger

commit 17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]

           kernel_size = load_image_targphys(kernel_filename, 0, ram_size);

[...]

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes > INT_MAX.
Lets change the max_sz parameter to a uint64_t.

Quoted 7 lines
Quoted 1 line

A patch equivalent to this has already been submitted:
http://patchwork.ozlabs.org/patch/146165/
We should be applying that one, it has already been reviewed.

Anthony?

Anthony,

can you apply the patchwork patch for 1.1?

Christian

#7 lore raw

Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX

Quoted 23 lines · Christian Borntraeger
Quoted 22 lines · Peter Maydell
Quoted 8 lines · Christian Borntraeger

commit 17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]

Quoted 8 lines
         kernel_size = load_image_targphys(kernel_filename, 0, ram_size);

[...]

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes > INT_MAX.
Lets change the max_sz parameter to a uint64_t.

A patch equivalent to this has already been submitted:
http://patchwork.ozlabs.org/patch/146165/
We should be applying that one, it has already been reviewed.

Quoted 5 lines
Quoted 1 line

Anthony?

Anthony,

can you apply the patchwork patch for 1.1?

Ping? Still missing in rc2.

Alex

#8 lore raw

Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX

Quoted 26 lines · Alexander Graf
Quoted 23 lines · Christian Borntraeger
Quoted 22 lines · Peter Maydell
Quoted 8 lines · Christian Borntraeger

commit 17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys() should enforce the max size

caused some problems with external kernel and specific ram sizes on s390:

We load the external kernel with

[...]

Quoted 8 lines
          kernel_size = load_image_targphys(kernel_filename, 0, ram_size);

[...]

Since load_image_targphys is declared as taking an int for max_sz, this will fail for ram sizes> INT_MAX.
Lets change the max_sz parameter to a uint64_t.

A patch equivalent to this has already been submitted:
http://patchwork.ozlabs.org/patch/146165/
We should be applying that one, it has already been reviewed.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Anthony?

Anthony,

can you apply the patchwork patch for 1.1?

Ping? Still missing in rc2.

Ack.

Regards,

Anthony Liguori

Quoted 4 lines

Alex