include/hw: field 'offset' in struct Property should be ptrdiff_t as int causes overflow
PATCH 1/1 include/hw: field 'offset' in struct Property should be ptrdiff_t as int causes overflow
'offset' field in struct Property is calculated as a diff between two pointers (hw/core/qdev-properties.c:802)
arrayprop->prop.offset = eltptr - (void *)dev;
If offset is declared as int, this subtraction can cause type overflow thus leading to the fall of the subsequent assert (hw/core/qdev-properties.c:803)
assert(qdev_get_prop_ptr(dev, &arrayprop->prop) == eltptr);
So ptrdiff_t should be used instead
--- include/hw/qdev-core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/hw/qdev-core.h +1 -1
@@ -224,7 +224,7 @@ struct BusState {struct Property {const char *name;PropertyInfo *info; -int offset; +ptrdiff_t offset;uint8_t bitnr;uint8_t qtype;int64_t defval;
Signature · 1 line
1.9.3
Stumbled over this while throwing away old mail. Andreas, what do you think?
Quoted 29 lines · Ildar Isaev
'offset' field in struct Property is calculated as a diff between two pointers (
hw/core/qdev-properties.c:802)
arrayprop->prop.offset= eltptr - (void *)dev;If offset is declared as int, this subtraction can cause type overflow thus leading to the fall of the subsequent assert (
hw/core/qdev-properties.c:803)
assert(qdev_get_prop_ptr(dev, &arrayprop->prop) == eltptr);So
ptrdiff_tshould be used insteadSigned-off-by Ildar Isaev <[email protected]>--- include/hw/qdev-core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/hw/qdev-core.h +1
-1@@ -224,7 +224,7 @@ struct BusState {struct Property {const char *name;PropertyInfo *info; -int offset; +ptrdiff_t offset;uint8_t bitnr;uint8_t qtype;int64_t defval;
Peter Maydell
Reviewed-byQuoted 2 lines · Markus Armbruster
Stumbled over this while throwing away old mail. Andreas, what do you think?
Seems right to me -- I suspect the original properties code was written with the assumption that the property field would be inside the device struct (and so offsets are small). The array properties code breaks that assumption by allocating a separate lump of memory with the properties in it; so now there's no guarantee that the two pointers being subtracted will be within 4G of each other.
Arguably for consistency the 'arrayoffset' struct member should also be a ptrdiff_t, though our current uses of it are such that it'll always be within int range.
-- PMM
Quoted 12 lines · Peter Maydell
Quoted 2 lines · Markus Armbruster
Stumbled over this while throwing away old mail. Andreas, what do you think?
Seems right to me -- I suspect the original properties code was written with the assumption that the property field would be inside the device struct (and so offsets are small). The array properties code breaks that assumption by allocating a separate lump of memory with the properties in it; so now there's no guarantee that the two pointers being subtracted will be within 4G of each other.
Quoted 5 lines
Reviewed-by Peter Maydell <[email protected]>Arguably for consistency the 'arrayoffset' struct member should also be a
ptrdiff_t, though our current uses of it are such that it'll always be within int range.
Andreas?
Am 11.11.2015 um 09:54 schrieb Markus Armbruster:
Quoted 13 lines
Quoted 12 lines · Peter Maydell
Quoted 2 lines · Markus Armbruster
Stumbled over this while throwing away old mail. Andreas, what do you think?
Seems right to me -- I suspect the original properties code was written with the assumption that the property field would be inside the device struct (and so offsets are small). The array properties code breaks that assumption by allocating a separate lump of memory with the properties in it; so now there's no guarantee that the two pointers being subtracted will be within 4G of each other.
Quoted 7 lines
Quoted 5 lines
Reviewed-by Peter Maydell <[email protected]>Arguably for consistency the 'arrayoffset' struct member should also be a
ptrdiff_t, though our current uses of it are such that it'll always be within int range.Andreas?
Found it archived. I honestly don't think it's necessary in practice to have 64-bit offsets on 64-bit host, but it builds okay, queued. Testing got stuck in ahci though, investigating.
Thanks,
Andreas
Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
Quoted 20 lines · Andreas Färber
Am 11.11.2015 um 09:54 schrieb Markus Armbruster:
Quoted 19 lines
Quoted 17 lines · Peter Maydell
Quoted 2 lines · Markus Armbruster
Stumbled over this while throwing away old mail. Andreas, what do you think?
Seems right to me -- I suspect the original properties code was written with the assumption that the property field would be inside the device struct (and so offsets are small). The array properties code breaks that assumption by allocating a separate lump of memory with the properties in it; so now there's no guarantee that the two pointers being subtracted will be within 4G of each other.
Reviewed-by Peter Maydell <[email protected]>Arguably for consistency the 'arrayoffset' struct member should also be a
ptrdiff_t, though our current uses of it are such that it'll always be within int range.
Quoted 9 lines
Quoted 1 line
Andreas?
Found it archived. I honestly don't think it's necessary in practice to have 64-bit offsets on 64-bit host, but it builds okay, queued. Testing got stuck in ahci though, investigating.
Thanks,
Andreas
Did you ever reproduce this, or does it seem to just be a race?
Am 13.11.2015 um 19:32 schrieb John Snow:
Quoted 9 lines · Andreas Färber
Quoted 6 lines
[...] Testing
got stuck in ahci though, investigating.Thanks,
AndreasDid you ever reproduce this, or does it seem to just be a race?
Once I updated to a later git commit I was no longer able to reproduce that hang to date. So it could either be a hard-to-reproduce race, or some merge yesterday made it go away.
Cheers,
Andreas
Signature · 2 lines
SUSE Linux GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Felix Imendörffer, Jane Smithard, Graham Norton; HRB 21284 (AG Nürnberg)
Quoted 9 lines · Andreas Färber
Am 13.11.2015 um 19:32 schrieb John Snow:
Quoted 8 lines · Andreas Färber
Quoted 6 lines
[...] Testing
got stuck in ahci though, investigating.Thanks,
Andreas
Quoted 9 lines
Quoted 1 line
Did you ever reproduce this, or does it seem to just be a race?
Once I updated to a later git commit I was no longer able to reproduce that hang to date. So it could either be a hard-to-reproduce race, or some merge yesterday made it go away.
Cheers,
Andreas
FWIW, on Fedora 22, I can't get my 64 or 32 bit build of the i386 target to reproduce the behavior after a couple dozen runs.
I was using the same commit you pointed to, so it seems like a race is likely. I'll keep my eye open.
--js