QObject patches for 2018-07-27 (3.0.0-rc3)
[Qemu-devel] [PULL 2/3] qstring: Assert size calculations don't overflow
In reply to Markus ArmbrusterMessage-Id: <[email protected]>
--- qobject/qstring.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
qobject/qstring.c +5 -1
@@ -41,17 +41,19 @@ QString *qstring_from_substr(const char *str, size_t start, size_t end) {QString *qstring; +assert (start <= end +1 ); + qstring =g_malloc (sizeof (*qstring));qobject_init (QOBJECT (qstring),QTYPE_QSTRING ); qstring->length = end - start +1 ; qstring->capacity = qstring->length; +assert (qstring->capacity <SIZE_MAX ); qstring->string =g_malloc (qstring->capacity +1 );memcpy (qstring->string, str + start, qstring->length); qstring->string[qstring->length] =0 ; -return qstring; }
@@ -68,7 +70,9 @@ QString *qstring_from_str(const char *str)static void capacity_increase (QString *qstring,size_t len) {if (qstring->capacity < (qstring->length + len)) { +assert (len <=SIZE_MAX - qstring->capacity); qstring->capacity += len; +assert (qstring->capacity <=SIZE_MAX /2 ); qstring->capacity *=2 ;/* use exponential growth */ qstring->string =g_realloc (qstring->string, qstring->capacity +1 );
Signature · 1 line
2.17.1
The following changes since commit 18a398f6a39df4b08ff86ac0d38384193ca5f4cc:
Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)
are available in the Git repository at:
git://repo.or.cz/qemu/armbru.git tags/pull-qobject-2018-07-27
for you to fetch changes up to 307fb894ce0608aede990ec40ce84eaeb358c8ec:
qstring: Move qstring_from_substr()'s @end one to the right (2018-07-27 17:16:03 +0200)
----------------------------------------------------------------
QObject patches for 2018-07-27 (3.0.0-rc3)
This pull request fixes an integer overflow bug, and hardens the code in question a bit. Abuse of QMP can make the bug crash QEMU, so it seems worth fixing at this late stage.
----------------------------------------------------------------
Markus Armbruster (2):
qstring: Assert size calculations don't overflow
qstring: Move qstring_from_substr()'s @end one to the right
liujunjie (1):
qstring: Fix qstring_from_substr() not to provoke int overflow
block/blkdebug.c | 2 +- block/blkverify.c | 2 +- block/nbd.c | 2 +- include/qapi/qmp/qstring.h | 2 +- qobject/qstring.c | 12 ++++++++---- tests/check-qobject.c | 2 +- tests/check-qstring.c | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 1/3] qstring: Fix qstring_from_substr() not to provoke int overflow
From: liujunjie <[email protected]>
qstring_from_substr() parameters @start and @end are of type int. blkdebug_parse_filename(), blkverify_parse_filename(), nbd_parse_uri(), and qstring_from_str() pass @end values of type size_t or ptrdiff_t. Values exceeding INT_MAX get truncated, with possibly disastrous results.
Such huge substrings seem unlikely, but we found one in a core dump, where "info tlb" executed via QMP's human-monitor-command apparently produced 35 GiB of output.
Fix by changing the parameters size_t.
Message-Id: <[email protected]>
--- include/qapi/qmp/qstring.h | 2 +- qobject/qstring.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/qapi/qmp/qstring.h +1 -1
@@ -24,7 +24,7 @@ struct QString {QString *qstring_new (void );QString *qstring_from_str (const char *str); -QString *qstring_from_substr (const char *str,int start,int end); +QString *qstring_from_substr (const char *str,size_t start,size_t end);size_t qstring_get_length (const QString *qstring);const char *qstring_get_str (const QString *qstring);const char *qstring_get_try_str (const QString *qstring);
qobject/qstring.c +1 -1
@@ -37,7 +37,7 @@ size_t qstring_get_length(const QString *qstring)* * Return string reference */ -QString *qstring_from_substr (const char *str,int start,int end) +QString *qstring_from_substr (const char *str,size_t start,size_t end) {QString *qstring;
Signature · 1 line
2.17.1
[Qemu-devel] [PULL 3/3] qstring: Move qstring_from_substr()'s @end one to the right
In reply to Markus Armbrusterqstring_from_substr() takes the index of the substring's first and last character. qstring_from_substr(s, 0, SIZE_MAX) denotes an empty substring. Awkward.
Shift the end index one to the right. This simplifies both qstring_from_substr() and its callers.
Message-Id: <[email protected]>
--- block/blkdebug.c | 2 +- block/blkverify.c | 2 +- block/nbd.c | 2 +- qobject/qstring.c | 6 +++--- tests/check-qobject.c | 2 +- tests/check-qstring.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-)
block/blkdebug.c +1 -1
@@ -305,7 +305,7 @@ static void blkdebug_parse_filename(const char *filename, QDict *options,if (c != filename) {QString *config_path; - config_path =qstring_from_substr (filename,0 , c - filename -1 ); + config_path =qstring_from_substr (filename,0 , c - filename);qdict_put (options,"config" , config_path); }
block/blkverify.c +1 -1
@@ -80,7 +80,7 @@ static void blkverify_parse_filename(const char *filename, QDict *options, }/* TODO Implement option pass-through and set raw.filename here */ - raw_path =qstring_from_substr (filename,0 , c - filename -1 ); + raw_path =qstring_from_substr (filename,0 , c - filename);qdict_put (options,"x-raw" , raw_path);/* TODO Allow multi-level nesting and set file.filename here */
block/nbd.c +1 -1
@@ -109,7 +109,7 @@ static int nbd_parse_uri(const char *filename, QDict *options)/* strip braces from literal IPv6 address */ if (uri->server[0 ] =='[' ) { host =qstring_from_substr (uri->server,1 , -strlen (uri->server) -2 ); +strlen (uri->server) -1 ); }else { host =qstring_from_str (uri->server); }
qobject/qstring.c +3 -3
@@ -41,12 +41,12 @@ QString *qstring_from_substr(const char *str, size_t start, size_t end) {QString *qstring; -assert (start <= end +1 ); +assert (start <= end); qstring =g_malloc (sizeof (*qstring));qobject_init (QOBJECT (qstring),QTYPE_QSTRING ); - qstring->length = end - start +1 ; + qstring->length = end - start; qstring->capacity = qstring->length;assert (qstring->capacity <SIZE_MAX );
@@ -64,7 +64,7 @@ QString *qstring_from_substr(const char *str, size_t start, size_t end)*/ QString *qstring_from_str (const char *str) { -return qstring_from_substr (str,0 ,strlen (str) -1 ); +return qstring_from_substr (str,0 ,strlen (str)); }static void capacity_increase (QString *qstring,size_t len)
tests/check-qobject.c +1 -1
@@ -154,7 +154,7 @@ static void qobject_is_equal_string_test(void) str_case =qstring_from_str ("Foo" );/* Should yield "foo" */ - str_built =qstring_from_substr ("form" ,0 ,1 ); + str_built =qstring_from_substr ("form" ,0 ,2 );qstring_append_chr (str_built,'o' ); check_unequal(str_base, str_whitespace_0, str_whitespace_1,
tests/check-qstring.c +1 -1
@@ -66,7 +66,7 @@ static void qstring_from_substr_test(void) {QString *qs; - qs =qstring_from_substr ("virtualization" ,3 ,9 ); + qs =qstring_from_substr ("virtualization" ,3 ,10 );g_assert (qs !=NULL );g_assert (strcmp (qstring_get_str (qs),"tualiza" ) ==0 );
Signature · 1 line
2.17.1
Quoted 19 lines · Markus Armbruster
The following changes since commit
18a398f6a39df4b08ff86ac0d38384193ca5f4cc:Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)
are available in the Git repository at:
git://repo.or.cz/qemu/armbru.gittags/pull-qobject-2018-07-27for you to fetch changes up to
307fb894ce0608aede990ec40ce84eaeb358c8ec:qstring: Move qstring_from_substr()'s @end one to the right (2018-07-27 17:16:03 +0200)
----------------------------------------------------------------
QObject patches for 2018-07-27 (3.0.0-rc3)This pull request fixes an integer overflow bug, and hardens the code in question a bit. Abuse of QMP can make the bug crash QEMU, so it seems worth fixing at this late stage.
Quoted 7 lines
----------------------------------------------------------------
Markus Armbruster (2):
qstring: Assert size calculations don't overflow
qstring: Move qstring_from_substr()'s @end one to the rightliujunjie (1):
qstring: Fixqstring_from_substr()not to provoke int overflow
Hi -- this passes my buildtests, but the commit from liujunjie seems to be missing your maintainer signed-off-by (and possibly a reviewed-by tag ?) Can I ask you to fix that up and resend, please?
thanks
-- PMM
Quoted 25 lines · Peter Maydell
Quoted 24 lines · Markus Armbruster
The following changes since commit
18a398f6a39df4b08ff86ac0d38384193ca5f4cc:Update version for v3.0.0-rc2 release (2018-07-24 22:06:31 +0100)
are available in the Git repository at:
git://repo.or.cz/qemu/armbru.gittags/pull-qobject-2018-07-27for you to fetch changes up to
307fb894ce0608aede990ec40ce84eaeb358c8ec:qstring: Move qstring_from_substr()'s @end one to the right (2018-07-27 17:16:03 +0200)
----------------------------------------------------------------
QObject patches for 2018-07-27 (3.0.0-rc3)This pull request fixes an integer overflow bug, and hardens the code in question a bit. Abuse of QMP can make the bug crash QEMU, so it seems worth fixing at this late stage.
----------------------------------------------------------------
Markus Armbruster (2):
qstring: Assert size calculations don't overflow
qstring: Move qstring_from_substr()'s @end one to the right
Quoted 8 lines
Quoted 2 lines
liujunjie (1):
qstring: Fixqstring_from_substr()not to provoke int overflowHi -- this passes my buildtests, but the commit from liujunjie seems to be missing your maintainer signed-off-by (and possibly a reviewed-by tag ?) Can I ask you to fix that up and resend, please?
My apologies. v2 sent.