From: Thomas Huth <thuth@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-trivial@nongnu.org,
Markus Armbruster <armbru@redhat.com>,
Daniel P Berrange <berrange@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2] monitor: Fix crashes when using HMP commands without CPU
Date: Thu, 12 Jan 2017 13:28:21 +0100 [thread overview]
Message-ID: <a395cf35-a893-4237-e69c-676b9dfda70c@redhat.com> (raw)
In-Reply-To: <20170112121933.GB2513@work-vm>
On 12.01.2017 13:19, Dr. David Alan Gilbert wrote:
> * Thomas Huth (thuth@redhat.com) wrote:
>> When running certain HMP commands ("info registers", "info cpustats",
>> "nmi", "memsave" or dumping virtual memory) with the "none" machine,
>> QEMU crashes with a segmentation fault. This happens because the "none"
>> machine does not have any CPUs by default, but these HMP commands did
>> not check for a valid CPU pointer yet. Add such checks now, so we get
>> an error message about the missing CPU instead.
>>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> v2:
>> - Added more checks to cover "nmi" and "memsave", too
>>
>> hmp.c | 8 +++++++-
>> monitor.c | 37 +++++++++++++++++++++++++++++++------
>> 2 files changed, 38 insertions(+), 7 deletions(-)
>>
>> diff --git a/hmp.c b/hmp.c
>> index b869617..b1c503a 100644
>> --- a/hmp.c
>> +++ b/hmp.c
>> @@ -1013,8 +1013,14 @@ void hmp_memsave(Monitor *mon, const QDict *qdict)
>> const char *filename = qdict_get_str(qdict, "filename");
>> uint64_t addr = qdict_get_int(qdict, "val");
>> Error *err = NULL;
>> + int cpu_index = monitor_get_cpu_index();
>>
>> - qmp_memsave(addr, size, filename, true, monitor_get_cpu_index(), &err);
>> + if (cpu_index < 0) {
>> + monitor_printf(mon, "No CPU available\n");
>> + return;
>> + }
>
> OK, that includes UNASSIGNED_CPU_INDEX.
>
>> +
>> + qmp_memsave(addr, size, filename, true, cpu_index, &err);
>> hmp_handle_error(mon, &err);
>> }
>>
>> diff --git a/monitor.c b/monitor.c
>> index 0841d43..74843eb 100644
>> --- a/monitor.c
>> +++ b/monitor.c
>> @@ -1025,6 +1025,9 @@ int monitor_set_cpu(int cpu_index)
>> CPUState *mon_get_cpu(void)
>> {
>> if (!cur_mon->mon_cpu) {
>> + if (!first_cpu) {
>> + return NULL;
>> + }
>> monitor_set_cpu(first_cpu->cpu_index);
>> }
>> cpu_synchronize_state(cur_mon->mon_cpu);
>> @@ -1033,17 +1036,27 @@ CPUState *mon_get_cpu(void)
>>
>> CPUArchState *mon_get_cpu_env(void)
>> {
>> - return mon_get_cpu()->env_ptr;
>> + CPUState *cs = mon_get_cpu();
>> +
>> + return cs ? cs->env_ptr : NULL;
>> }
>>
>> int monitor_get_cpu_index(void)
>> {
>> - return mon_get_cpu()->cpu_index;
>> + CPUState *cs = mon_get_cpu();
>> +
>> + return cs ? cs->cpu_index : -1;
>> }
>
> OK, do you think that should use UNASSIGNED_CPU_INDEX
> explicitly rather than -1 ?
I wasn't aware of the fact that we've even got a macro for this ... I'll
send a v3 with that change.
> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Thanks for the review!
> I'm sure we'll find loads more similar cases where -M none breaks stuff.
I've added two more cases (migration and gdbstub) to the "Potentially
easy bugs" section on http://qemu-project.org/BiteSizedTasks now. I
think these are simple and easy tasks to get started with QEMU hacking...
Thomas
prev parent reply other threads:[~2017-01-12 12:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-12 10:23 [Qemu-devel] [PATCH v2] monitor: Fix crashes when using HMP commands without CPU Thomas Huth
2017-01-12 12:19 ` Dr. David Alan Gilbert
2017-01-12 12:28 ` Thomas Huth [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a395cf35-a893-4237-e69c-676b9dfda70c@redhat.com \
--to=thuth@redhat.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).