Skip to contentSkip to conversation

QGA - Win fixes

PATCH In review Basil Salman 4 participants 10 messages Mar 11, 2020 – Mar 24, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover QGA - Win fixes

This patch series addresses serveral issues with qga-win please review them and share your thoughts.

Basil Salman (2):
qga: Installer: Wait for installation to finish
qga-win: prevent crash when executing guest-file-read with large count

Sameeh Jubran (1):
qga-win: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error

 qga/commands-win32.c      |  8 +++++++-
 qga/installer/qemu-ga.wxs |  2 +-
 qga/vss-win32/install.cpp | 11 +++++++++++
 3 files changed, 19 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.2
#1 lore raw

PATCH v3 1/3 qga: Installer: Wait for installation to finish

Installation might fail if we don't wait for the provider unregisteration process to finish.

---
 qga/installer/qemu-ga.wxs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qga/installer/qemu-ga.wxs +1 -1
index 64bf90bd85..f6781752e6 100644
@@ -81,7 +81,7 @@
               Arguments="-d --retry-path"
               >
             </ServiceInstall>
-            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="no" />
+            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="yes" />
           </Component>
           <?ifdef var.InstallVss?>
           <Component Id="qga_vss_dll" Guid="{CB19C453-FABB-4BB1-ABAB-6B74F687BFBB}">
Signature · 1 line
2.17.2
#2 lore raw

Re: [PATCH v3 1/3] qga: Installer: Wait for installation to finish

Hi Basil,

Quoted 14 lines · Basil Salman

Installation might fail if we don't wait for the provider unregisteration process to finish.

---
  qga/installer/qemu-ga.wxs | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
qga/installer/qemu-ga.wxs +0 -0
index 64bf90bd85..f6781752e6 100644

qga/installer/qemu-ga.wxs line 84

Quoted 5 lines
qga/installer/qemu-ga.wxs +1 -1
@@ -81,7 +81,7 @@
                Arguments="-d --retry-path"
                >
              </ServiceInstall>
-            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="no" />
+            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="yes" />

As 'yes' is the default, can you simply remove 'Wait="no"'?

Quoted 4 lines
qga/installer/qemu-ga.wxs +0 -0
            </Component>
            <?ifdef var.InstallVss?>
            <Component Id="qga_vss_dll" Guid="{CB19C453-FABB-4BB1-ABAB-6B74F687BFBB}">
#3 lore raw

Re: [PATCH v3 1/3] qga: Installer: Wait for installation to finish

Hi

Quoted 13 lines · Philippe Mathieu-Daudé

Hi Basil,

Quoted 9 lines · Basil Salman

Installation might fail if we don't wait for the provider unregisteration process to finish.

---
  qga/installer/qemu-ga.wxs | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

qga/installer/qemu-ga.wxs line 84

Quoted 10 lines
qga/installer/qemu-ga.wxs +1 -1
index 64bf90bd85..f6781752e6 100644
@@ -81,7 +81,7 @@
                Arguments="-d --retry-path"
                >
              </ServiceInstall>
-            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="no" />
+            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="yes" />

As 'yes' is the default, can you simply remove 'Wait="no"'?

It looks like wixl doesn't follow the WiX default value though.

tools/wixl/msi.vala:
574 (Wait != null && !rec.set_int (5, Wait ? 1 : 0)) ||

Quoted 7 lines
Quoted 5 lines
qga/installer/qemu-ga.wxs +0 -0
            </Component>
            <?ifdef var.InstallVss?>
            <Component Id="qga_vss_dll" Guid="{CB19C453-FABB-4BB1-ABAB-6B74F687BFBB}">
Signature · 1 line
Marc-André Lureau
#4 lore raw

Re: [PATCH v3 1/3] qga: Installer: Wait for installation to finish

Quoted 30 lines · Marc-André Lureau

Hi

Quoted 13 lines · Philippe Mathieu-Daudé

Hi Basil,

Quoted 9 lines · Basil Salman

Installation might fail if we don't wait for the provider unregisteration process to finish.

---
   qga/installer/qemu-ga.wxs | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

qga/installer/qemu-ga.wxs line 84

Quoted 10 lines
qga/installer/qemu-ga.wxs +1 -1
index 64bf90bd85..f6781752e6 100644
@@ -81,7 +81,7 @@
                 Arguments="-d --retry-path"
                 >
               </ServiceInstall>
-            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="no" />
+            <ServiceControl Id="StartService" Start="install" Stop="both" Remove="uninstall" Name="QEMU-GA" Wait="yes" />

As 'yes' is the default, can you simply remove 'Wait="no"'?

Quoted 4 lines

It looks like wixl doesn't follow the WiX default value though.

tools/wixl/msi.vala:
574 (Wait != null && !rec.set_int (5, Wait ? 1 : 0)) ||

I trusted the documentation...
https://wixtoolset.org/documentation/manual/v3/xsd/wix/servicecontrol.html

Thanks for looking at the implementation.

So for this patch:

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
qga/installer/qemu-ga.wxs +0 -0
             </Component>
             <?ifdef var.InstallVss?>
             <Component Id="qga_vss_dll" Guid="{CB19C453-FABB-4BB1-ABAB-6B74F687BFBB}">
#5 lore raw

PATCH v3 2/3 qga-win: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error

In reply to Basil Salman

From: Sameeh Jubran <[email protected]>

This patch handles the case where VSS Provider is already registered, where in such case qga uninstalls the provider and registers it again.

---
 qga/vss-win32/install.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)
qga/vss-win32/install.cpp +11 -0
index 6713e58670..a456841360 100644
@@ -443,6 +443,17 @@ STDAPI DllRegisterServer(void)
                                      VSS_PROV_SOFTWARE,
                                      const_cast<WCHAR*>(QGA_PROVIDER_VERSION),
                                      g_gProviderVersion);
+    if (hr == (long int) VSS_E_PROVIDER_ALREADY_REGISTERED) {
+        DllUnregisterServer();
+        hr = pVssAdmin->RegisterProvider(g_gProviderId, CLSID_QGAVSSProvider,
+                                         const_cast<WCHAR * >
+                                         (QGA_PROVIDER_LNAME),
+                                         VSS_PROV_SOFTWARE,
+                                         const_cast<WCHAR * >
+                                         (QGA_PROVIDER_VERSION),
+                                         g_gProviderVersion);
+    }
+
     if (FAILED(hr)) {
         errmsg_dialog(hr, "RegisterProvider failed");
     }
Signature · 1 line
2.17.2
#6 lore raw

PATCH v3 3/3 qga-win: prevent crash when executing guest-file-read with large count

In reply to Basil Salman

BZ: #1594054
guest-file-read command is currently implemented to read from a
file handle count number of bytes. when executed with a very large count number qemu-ga crashes.
after some digging turns out that qemu-ga crashes after trying to allocate a buffer large enough to save the data read in it, the buffer was allocated using g_malloc0 which is not fail safe, and results a crash in case of failure. g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure, A check was added for that case in order to prevent qemu-ga from crashing and to send a response to the qemu-ga client accordingly.

---
 qga/commands-win32.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
qga/commands-win32.c +7 -1
index 9c744d6405..b49920e201 100644
@@ -343,7 +343,13 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
     }
 
     fh = gfh->fh;
-    buf = g_malloc0(count+1);
+    buf = g_try_malloc0(count + 1);
+    if (!buf) {
+        error_setg(errp,
+                   "failed to allocate sufficient memory "
+                   "to complete the requested service");
+        return NULL;
+    }
     is_ok = ReadFile(fh, buf, count, &read_count, NULL);
     if (!is_ok) {
         error_setg_win32(errp, GetLastError(), "failed to read file");
Signature · 1 line
2.17.2
#7 lore raw

Re: [PATCH v3 3/3] qga-win: prevent crash when executing guest-file-read with large count

Quoted 1 line · Basil Salman

BZ: #1594054

^ This is not very helpful as it... (think to ppl with no knowledge of 'BZ', what to do with this number). Instead ...

Quoted 10 lines

guest-file-read command is currently implemented to read from a
file handle count number of bytes. when executed with a very large count number qemu-ga crashes.
after some digging turns out that qemu-ga crashes after trying to allocate a buffer large enough to save the data read in it, the buffer was allocated using g_malloc0 which is not fail safe, and results a crash in case of failure. g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure, A check was added for that case in order to prevent qemu-ga from crashing and to send a response to the qemu-ga client accordingly.

... add here (see https://wiki.qemu.org/Contribute/SubmitAPatch#Write_a_meaningful_commit_message):

Also add:

Quoted 11 lines
---
  qga/commands-win32.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
qga/commands-win32.c +0 -0
index 9c744d6405..b49920e201 100644
@@ -343,7 +343,13 @@ GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
      }

qga/commands-win32.c GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, · line 352

Quoted 10 lines
qga/commands-win32.c +7 -1
 
      fh = gfh->fh;
-    buf = g_malloc0(count+1);
+    buf = g_try_malloc0(count + 1);
+    if (!buf) {
+        error_setg(errp,
+                   "failed to allocate sufficient memory "
+                   "to complete the requested service");
+        return NULL;
+    }

Can you fix the equivalent problem in qga/commands-posix.c too please?

Also use "PATCH-for-5.0" in the patch subject so we don't miss it for the next release.

Thanks!

Phil.

Quoted 4 lines
qga/commands-win32.c +0 -0
      is_ok = ReadFile(fh, buf, count, &read_count, NULL);
      if (!is_ok) {
          error_setg_win32(errp, GetLastError(), "failed to read file");
#8 lore raw

Re: [PATCH v3 3/3] qga-win: prevent crash when executing guest-file-read with large count

Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 1 line · Basil Salman

BZ: #1594054

^ This is not very helpful as it... (think to ppl with no knowledge of 'BZ', what to do with this number). Instead ...

Quoted 10 lines

guest-file-read command is currently implemented to read from a
file handle count number of bytes. when executed with a very large count number qemu-ga crashes.
after some digging turns out that qemu-ga crashes after trying to allocate a buffer large enough to save the data read in it, the buffer was allocated using g_malloc0 which is not fail safe, and results a crash in case of failure. g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure, A check was added for that case in order to prevent qemu-ga from crashing and to send a response to the qemu-ga client accordingly.

Quoted 4 lines

... add here (see https://wiki.qemu.org/Contribute/SubmitAPatch#Write_a_meaningful_commit_message):

And per the BZ info, please also credit the reporter:

Quoted 39 lines

Also add:

Quoted 11 lines

---
  qga/commands-win32.c | 8 +++++++-

  1 file changed, 7 insertions(+), 1 deletion(-)
qga/commands-win32.c +0 -0
index 9c744d6405..b49920e201 100644
@@ -343,7 +343,13 @@ GuestFileRead *qmp_guest_file_read(int64_t 
 handle, bool has_count,

qga/commands-win32.c GuestFileRead *qmp_guest_file_read(int64_t · line 352

Quoted 10 lines
qga/commands-win32.c +7 -1
       }
       fh = gfh->fh;
-    buf = g_malloc0(count+1);
+    buf = g_try_malloc0(count + 1);
+    if (!buf) {
+        error_setg(errp,
+                   "failed to allocate sufficient memory "
+                   "to complete the requested service");
+        return NULL;
+    }

Can you fix the equivalent problem in qga/commands-posix.c too please?

Also use "PATCH-for-5.0" in the patch subject so we don't miss it for the next release.

Thanks!

Phil.

Quoted 4 lines
qga/commands-win32.c +0 -0
       is_ok = ReadFile(fh, buf, count, &read_count, NULL);
       if (!is_ok) {
           error_setg_win32(errp, GetLastError(), "failed to read file");
#9 lore raw

Re: [PATCH v3 3/3] qga-win: prevent crash when executing guest-file-read with large count

Quoting Philippe Mathieu-Daudé (2020-03-24 08:37:05)

Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Basil Salman
Quoted 1 line

BZ: #1594054

^ This is not very helpful as it... (think to ppl with no knowledge of 'BZ', what to do with this number). Instead ...

Quoted 5 lines

guest-file-read command is currently implemented to read from a file handle count number of bytes. when executed with a very large count number
qemu-ga crashes.
after some digging turns out that qemu-ga crashes after trying to

Quoted 9 lines

allocate
a buffer large enough to save the data read in it, the buffer was allocated using
g_malloc0 which is not fail safe, and results a crash in case of failure. g_malloc0 was replaced with g_try_malloc0() which returns NULL on failure,
A check was added for that case in order to prevent qemu-ga from crashing and to send a response to the qemu-ga client accordingly.

... add here (see
https://wiki.qemu.org/Contribute/SubmitAPatch#Write_a_meaningful_commit_message):

Quoted 5 lines
Quoted 1 line

And per the BZ info, please also credit the reporter:

Since I had these queued for a pull already I went ahead and rolled your suggestions (minus the posix-side fix) into this patch.

A seperate follow-up patch address the posix counterpart would still be appreciated though.

Quoted 42 lines
Quoted 41 lines

Also add:

Quoted 11 lines

---
  qga/commands-win32.c | 8 +++++++-

  1 file changed, 7 insertions(+), 1 deletion(-)
qga/commands-win32.c +0 -0
index 9c744d6405..b49920e201 100644
@@ -343,7 +343,13 @@ GuestFileRead *qmp_guest_file_read(int64_t 
 handle, bool has_count,

qga/commands-win32.c GuestFileRead *qmp_guest_file_read(int64_t · line 352

Quoted 10 lines
qga/commands-win32.c +7 -1
       }
       fh = gfh->fh;
-    buf = g_malloc0(count+1);
+    buf = g_try_malloc0(count + 1);
+    if (!buf) {
+        error_setg(errp,
+                   "failed to allocate sufficient memory "
+                   "to complete the requested service");
+        return NULL;
+    }

Can you fix the equivalent problem in qga/commands-posix.c too please?

Also use "PATCH-for-5.0" in the patch subject so we don't miss it for the next release.

Thanks!

Phil.

Quoted 4 lines
qga/commands-win32.c +0 -0
       is_ok = ReadFile(fh, buf, count, &read_count, NULL);
       if (!is_ok) {
           error_setg_win32(errp, GetLastError(), "failed to read file");