From 9d28a9e9b798f9e20a279905178133333212858e Mon Sep 17 00:00:00 2001 From: Paul Durrant Date: Mon, 20 May 2019 15:43:34 +0100 Subject: [PATCH] Avoid removing filters on upgrade installations When upgrading XENBUS in a situation where XENVBD has made it uninstallable (without reboot), DriverRemoveFunctionDeviceObject() in the old instance of XENBUS will cause XENFILT to be removed as PCI and IDE upper filter. Then, when the new instance of XENBUS starts, it will find an incompatible version of XEN prior to adding the registery filter entries back in. Thus, after the requested reboot XENFILT will non-functional and another reboot will be required to re-instate it. This patch removes the call to FiltersUninstall() from DriverRemoveFunctionDeviceObject() and, instead, calls it from DriverEntry() AFTER the compatibility check. This means that XENFILT will remain installed across an upgrade and will only be removed if XENBUS started but has no bound devices (i.e. it has actually been un-installed). NOTE: This also fixes an unitialized pointer in FiltersUninstallClass(). Signed-off-by: Paul Durrant --- src/xenbus/driver.c | 7 ++++--- src/xenbus/filters.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/xenbus/driver.c b/src/xenbus/driver.c index 50c7c5e..0ede4ef 100644 --- a/src/xenbus/driver.c +++ b/src/xenbus/driver.c @@ -296,9 +296,6 @@ DriverRemoveFunctionDeviceObject( RemoveEntryList(&Dx->ListEntry); ASSERT3U(Driver.References, !=, 0); References = --Driver.References; - - if (References == 1) - FiltersUninstall(); } // @@ -773,6 +770,10 @@ DriverEntry( goto done; } + // Remove the filters from the registry. They will be re-instated by + // the first successful AddDevice. + FiltersUninstall(); + DriverObject->DriverExtension->AddDevice = DriverAddDevice; for (Index = 0; Index <= IRP_MJ_MAXIMUM_FUNCTION; Index++) { diff --git a/src/xenbus/filters.c b/src/xenbus/filters.c index dfea119..fc2a1d8 100644 --- a/src/xenbus/filters.c +++ b/src/xenbus/filters.c @@ -203,7 +203,7 @@ FiltersUninstallClass( HANDLE Key; ULONG Type; ULONG Count; - PANSI_STRING Old; + PANSI_STRING Old = NULL; ULONG Index; PANSI_STRING New; NTSTATUS status; -- 2.39.5