S390: file size checking in load_image_targphys and certain ram sizes
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
@@ -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
@@ -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,
Quoted 18 lines · Christian Borntraeger
Ben, Alex,
commit
17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys()should enforce the max sizecaused 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_targphyshasmax_szas an int (32bit), butram_sizeis aram_addr_t(64bit).
So for a ramsize of lets say 3GB the comparison inload_image_targphysfails:
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
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
@@ -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
@@ -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
Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX
Quoted 11 lines · Christian Borntraeger
commit
17df768c1e4580f03301d18ea938d3557d441911load_image_targphys()should enforce the max sizecaused 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_targphysis declared as taking an int formax_sz, this will fail for ram sizes >INT_MAX.
Lets change themax_szparameter to auint64_t.Signed-off-by Christian Borntraeger <[email protected]>
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
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_targphysis declared as taking an int formax_sz, this will fail for ram sizes >INT_MAX.
Lets change themax_szparameter to auint64_t.Signed-off-by Christian Borntraeger <[email protected]>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
Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX
In reply to Peter MaydellQuoted 11 lines · Peter Maydell
Quoted 5 lines
Since
load_image_targphysis declared as taking an int formax_sz, this will fail for ram sizes >INT_MAX.
Lets change themax_szparameter to auint64_t.Signed-off-by Christian Borntraeger <[email protected]>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?
Re: [Qemu-devel] [PATCH] Fix size checking in load_image_targphys to accept max_size > INT_MAX
In reply to Peter MaydellQuoted 16 lines · Peter Maydell
Quoted 15 lines · Christian Borntraeger
commit
17df768c1e4580f03301d18ea938d3557d441911
load_image_targphys()should enforce the max sizecaused 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_targphysis declared as taking an int formax_sz, this will fail for ram sizes >INT_MAX.
Lets change themax_szparameter to auint64_t.
Quoted 7 lines
Quoted 1 line
Signed-off-by Christian Borntraeger <[email protected]>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
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 sizecaused 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_targphysis declared as taking an int formax_sz, this will fail for ram sizes >INT_MAX.
Lets change themax_szparameter to auint64_t.Signed-off-by Christian Borntraeger <[email protected]>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
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 sizecaused 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_targphysis declared as taking an int formax_sz, this will fail for ram sizes>INT_MAX.
Lets change themax_szparameter to auint64_t.Signed-off-by Christian Borntraeger<[email protected]>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