From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:35:25 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:35:25 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104946.200974 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQVm-0006HP-Oi; Fri, 02 Apr 2021 20:35:22 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104946.200974; Fri, 02 Apr 2021 20:35:22 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQVm-0006HH-LZ; Fri, 02 Apr 2021 20:35:22 +0000
Received: by outflank-mailman (input) for mailman id 104946;
 Fri, 02 Apr 2021 20:35:22 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQVm-0006HC-1W
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:35:22 +0000
Received: from mail-qt1-x832.google.com (unknown [2607:f8b0:4864:20::832])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 29a26884-c0b4-4434-b30c-5f0f7999e25c;
 Fri, 02 Apr 2021 20:35:20 +0000 (UTC)
Received: by mail-qt1-x832.google.com with SMTP id f12so4440419qtq.4
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:35:20 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id n1sm7299813qtp.76.2021.04.02.13.35.19
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:35:19 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 29a26884-c0b4-4434-b30c-5f0f7999e25c
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=i6qAaILGwqRNwSZIJ9xTUiOfOHhFN/yzV+q2qIFa+QM=;
        b=aoJoQkhjn4Jdfkr4oM3uDVo1HTo4TPVwNCJ6ozPMkqHRRGP3r+k+ggE5VcZmqaiwmk
         7Ab/tPS88JHanpHlanLMmHwkn2izBt7GUyhiKNPx1Vpc2iDx0TSRyOSYaURuZv/PIYkQ
         ONtbbPImW6M1P7RpcqmqSFsr/fuqsiiz2Zf1Rp+k/981AjHzdt7BRQ5xNq/thfQYLeLI
         OBq8kLkCLzKFaPFrHwy+Xr4HqUQJ5RkCI2OJAYhoa50fmrx6l/8c2dADKhbVgHpXckW1
         gBhNu2eJ5oJY1PRdNHpaqF/B+8H7/1yQtSsHbs/81W13CcovMrR0H/rMAvjYg3Ovvssp
         tbnA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=i6qAaILGwqRNwSZIJ9xTUiOfOHhFN/yzV+q2qIFa+QM=;
        b=mpRdrqkk3+I892GjATcWhHf8jhTAndJVu5JlJLY2wGg6YpQi1ICXSFI5UKiSfcBNFh
         iF4LvxPwUmfwXAGlts0fXD5RFzpkugOVJ7MGW8yirlx2V/Q8yHOYGdhlum6H+lGx09kO
         iRHUyUNEZ47mnIH4d7k5Vgh4cn+FwWWtOtcr/gZztiIurDWYO0tR/tl4lrAm5uds7ui8
         /U3lTjCcWHcKVjcaQvjQ90jBjU0FwIVAMVz5H1gazcB65TJ5yerPrVBEd0B3D46X2deP
         pX8WXLV5rfQeBE/CUYvxpP7vIPU2AhueSHQHn+qVPSaY3nHFNoO7Ga3yBzWSLtrd9Wh7
         hefg==
X-Gm-Message-State: AOAM5327yMRKJNF4/f9cxXb1SJO8baGuUkJMmVVzqCHp7e4A9LQL6PD4
	Vsu3xGqYBvlYhqFRXoJCnWxPVQjFlFs=
X-Google-Smtp-Source: ABdhPJxo/wFT2mYVIaG0KaVMsoVXdljgpXyvsr7fPhxy9Pb/sBfgpqrFbkiNCSUlgVfYBeU2F3nEJg==
X-Received: by 2002:ac8:7dd2:: with SMTP id c18mr13109461qte.301.1617395720082;
        Fri, 02 Apr 2021 13:35:20 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:34:35 -0400
Message-Id: <20210402203435.31189-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

The console monitor service will persist if DifRemove does not run.

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 49 +++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index 4d2953d..ac3847c 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -440,6 +440,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -454,23 +457,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // If there is no driver information then the NULL driver is being
-        // installed. Treat this as we would a DIF_REMOVE.
-        Error = (DriverInfoAvailable) ?
-                DifInstall(DeviceInfoSet, DeviceInfoData, Context) :
-                DifRemove(DeviceInfoSet, DeviceInfoData, Context);
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:44:39 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:44:39 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104952.200978 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQek-00077p-FI; Fri, 02 Apr 2021 20:44:38 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104952.200978; Fri, 02 Apr 2021 20:44:38 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQek-00077h-CJ; Fri, 02 Apr 2021 20:44:38 +0000
Received: by outflank-mailman (input) for mailman id 104952;
 Fri, 02 Apr 2021 20:44:37 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQej-00077c-Bc
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:44:37 +0000
Received: from mail-qv1-xf2a.google.com (unknown [2607:f8b0:4864:20::f2a])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 9ad6cfc7-c5f2-472c-95d3-4f36cfebce57;
 Fri, 02 Apr 2021 20:44:36 +0000 (UTC)
Received: by mail-qv1-xf2a.google.com with SMTP id c3so2995668qvz.7
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:44:36 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id q3sm5871195qtw.40.2021.04.02.13.44.34
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:44:35 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 9ad6cfc7-c5f2-472c-95d3-4f36cfebce57
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=viu/igbxfpb0BV7QbOUqswYRAj0zfpE5JPM2GmiOT+M=;
        b=f9FaccUo2QvqqqUMNbEJ69IxqKsLf8Km/Qd3pXxGWVBEk8Js9SYt0hIZXp4eGIQGWI
         RocyBKsN9Lc6YrsIo0F0eaCX4iENYxHtU18GLpccsAouAct65d+xZ1vXZGdQsUb5zSh3
         tE31ftkdrBFtm6yS/DO0YEZd0TbHdsaKEu8yzKYQ9dDy2OV/s0w5NVKpsfZISPtdrei8
         SAS9tYd0+tP1NTM23Ta6IGckGDZyWHkaADUEemx2qvKDGgX4NWZrXc3NlluDOznB7eBB
         ScWgyxDpRO9pKOej/ONxIbSuEboTFtQwbqMobWW0D5lJ0k6UtJE58R52PXujtsA+pgJ+
         Xw2Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=viu/igbxfpb0BV7QbOUqswYRAj0zfpE5JPM2GmiOT+M=;
        b=iUoXmPq1KiVWEd0WY2mg3XTEiERl/c5mx9Vqg+2wpktUTERFHFAo2DTzfQbI+HauI/
         LQx2qlvCd6ImBTL2c0VEX9eEEwk61oq7ZJVJr5glw2F0LsSfZx6w3o35r0ObTWzOUQpD
         wd0NFD4rcB7RiWIA3sEtcvVpj2nT4DJz0aa2ARVV6inrFeK8bADGxJIQ6xQMvfuBP3NQ
         PDTynSynRZmN6bkGzbTF3NZDdtsW1O7DttAQHsA7NvtCorOtbYJSp3Lr3jGsoSyS10wi
         QcYp+ixY71b/2rhuas3Rk0tYs0VRXJG9VOvGvMRPRQdZN8S1cAww9o/1wIsK0dCZcLHV
         6GFQ==
X-Gm-Message-State: AOAM533wXmDfnNtNpD0PAPeiOp5sh8ueKbGVfL7V3IjLu87pxKtTK/wx
	u7L+Qftn+Ks5nWQZgATq/jDQbjG+RHE=
X-Google-Smtp-Source: ABdhPJwR06HeVMJ7Q0axAFT+OUQ3E+2LImPPmfgHgWBzUgCgp5Qmk7dAvgyrnOCji0LdCyoPw6BUuQ==
X-Received: by 2002:a05:6214:945:: with SMTP id dn5mr14335420qvb.3.1617396275948;
        Fri, 02 Apr 2021 13:44:35 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:37:43 -0400
Message-Id: <20210402203743.59617-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 57 +++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index aec1ae9..866ae40 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -469,6 +469,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -483,31 +486,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // The NET class installer will call DIF_REMOVE even in the event of
-        // a NULL driver add. However, the default installer (for the NULL
-        // driver) then fails for some reason so we squash the error in
-        // post-processing.
-        if (DriverInfoAvailable) {
-            Error = DifInstall(DeviceInfoSet, DeviceInfoData, Context);
-        } else {
-            if (!Context->PostProcessing) {
-                Error = ERROR_DI_POSTPROCESSING_REQUIRED;
-            } else {
-                Error = NO_ERROR;
-            }
-        }
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:46:05 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:46:05 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104958.200982 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQg9-0007A6-Ji; Fri, 02 Apr 2021 20:46:05 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104958.200982; Fri, 02 Apr 2021 20:46:05 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQg9-00079y-Gv; Fri, 02 Apr 2021 20:46:05 +0000
Received: by outflank-mailman (input) for mailman id 104958;
 Fri, 02 Apr 2021 20:46:04 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQg8-00079t-9Z
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:46:04 +0000
Received: from mail-qk1-x731.google.com (unknown [2607:f8b0:4864:20::731])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id b5644057-dd99-416b-802f-077d53aeb30d;
 Fri, 02 Apr 2021 20:46:03 +0000 (UTC)
Received: by mail-qk1-x731.google.com with SMTP id o5so6356780qkb.0
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:46:03 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id h13sm7275972qtn.26.2021.04.02.13.46.02
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:46:02 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: b5644057-dd99-416b-802f-077d53aeb30d
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=2AG+4LBFJXnzI9eEg0GwVvaV6ghPGE0dzHAiv0rrBe8=;
        b=XITODUWfyaUEwYpVRPAhZ4yoJ9DvBewRUk96SI1kx4m5k8v2W2oSNsnUZVZoJimWAA
         90M90ixb1kmRPEJBjD37EipeCiqZT6ve6rkIGH+64kfylpJ6BW4xOyW71p/CS1vrvQdE
         hMmFOpg8y2RFQVAb0k5F5yCRyCNac8pc7JBwas5/sd6OkSEhSnibUBzt9/u69AhTXbzo
         eiUJS93DjpN5OXdsXcIkdqWNX6y4X5SxEs2c3riCblwnBuOV+awrqHISoAF2eVCpRAxj
         9qyHYEoeYJbX+DXlgC5KJQjA4WPaLU4l3FAtIct1caIzaaGKNQIk/1pWWjh0ANK52CI4
         qS6w==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=2AG+4LBFJXnzI9eEg0GwVvaV6ghPGE0dzHAiv0rrBe8=;
        b=mKqJ+wP9JI8YMeGz3aHKKla269qU1DFKqqSKHFGHkpREkj8ebgz1613PYVuX2yFsHy
         +HjIc0cIZAueG8U8bHxbCjm2d6REMYAAZPLWsG9fMaksCZ4HWtfnNYH1yESO3+NGRV6p
         uZ4BU0HmWfsFL+CFtELpSwdJpCZHaTTU/jA1GYcuTS1r2LyvwiKi/SH4M64PtTDcTwCS
         jD/64b+CkjdL8p+xMIlM4ahFtvwhdTMKXVVsi74la8KCmthtd+1E5jKuRMRAGfpaK17k
         d95DRMmOPlst3L/bgP0lEeGmqKglZymxnA6Wonm5wMBJPNVPtAlP9ZY4+zkpt0kDnnCY
         IsLQ==
X-Gm-Message-State: AOAM532OYeS13kIhKviJRx4jaZY/Ij4nMwHrbHfYQqGvmvzu2XBkIBMh
	uIqpGYJfFghl8jKhU3xy8sF+/eSaKbI=
X-Google-Smtp-Source: ABdhPJyuJ42kgEZnaBlVoyFF+5uma2bbAICZE67qDGCq3mSmJanFoVLcbpuk3pmlB1nNZBjHfkQjGw==
X-Received: by 2002:a05:620a:718:: with SMTP id 24mr15094917qkc.121.1617396363021;
        Fri, 02 Apr 2021 13:46:03 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:45:02 -0400
Message-Id: <20210402204502.130480-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

The xenagent service will persist if DifRemove does not run.

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 49 +++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index a4c883a..6ed39da 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -606,6 +606,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -620,23 +623,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // If there is no driver information then the NULL driver is being
-        // installed. Treat this as we would a DIF_REMOVE.
-        Error = (DriverInfoAvailable) ?
-                DifInstall(DeviceInfoSet, DeviceInfoData, Context) :
-                DifRemove(DeviceInfoSet, DeviceInfoData, Context);
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:46:58 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:46:58 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104964.200986 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQh0-0007CO-NK; Fri, 02 Apr 2021 20:46:58 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104964.200986; Fri, 02 Apr 2021 20:46:58 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQh0-0007CH-KH; Fri, 02 Apr 2021 20:46:58 +0000
Received: by outflank-mailman (input) for mailman id 104964;
 Fri, 02 Apr 2021 20:46:57 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQgz-0007C8-Rv
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:46:57 +0000
Received: from mail-qt1-x830.google.com (unknown [2607:f8b0:4864:20::830])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id d518544b-fdd9-4ed6-8074-785186643243;
 Fri, 02 Apr 2021 20:46:54 +0000 (UTC)
Received: by mail-qt1-x830.google.com with SMTP id j7so4455829qtx.5
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:46:54 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id z11sm8046718qkg.52.2021.04.02.13.46.53
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:46:53 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: d518544b-fdd9-4ed6-8074-785186643243
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=+ulIiU4lv+mcYQllye0qWruwKCx1Xr0E7myMKYl8FE0=;
        b=LAidyljCZWUpHI3ZFxXRm2Q0K6kWGlF83zMe1t0wm5Pn3wjmPiQb4YhEJBTlKgdvrY
         QiUT+SX44Xx2msjkmaEwkCxw6GTELQ+dZaG2WRxdnhJyUKXYQOF0H+sipMps1/ypyjJs
         p5SSALmld/qe0cudJ6EtTEhAvZTk6SrBy5AtKqLT0bPMcUt6CSamM0blrGltEO4CkMqx
         cbRUz1PEJNvZWXVD67OzDO9Q1gZsE4CvZpyW8B80n6eDIWnMmmlTwWJuyi/V6l+XpFf7
         SiZhuzDjiY690J+1T9R+/tCznu6zk9xeKVrjVffmbsmBIP+i5LOnsjuceJwmL/FiLAqX
         Kdtg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=+ulIiU4lv+mcYQllye0qWruwKCx1Xr0E7myMKYl8FE0=;
        b=KhE4w/A4Edm9B2zLTG706ABbQ3ta7guv7gIFDydohTtEw/M2f62hjuGpfOQB4Hc7JD
         k1gJ8aAVspWxqTosJ0nylqWgWck7xmmD9ZMVwjrvnQCF8x8E+KhX7+AGvaOk6+ALV86W
         WGGKaVqD7yfMEMT/JZBGgl/vu4wk37lGaJIv3rsHvGepyCeAgEFCczvS/fUXUIs4TIMu
         L6E88vfMsrecYx/M14/q8zrhoXkweXL45UIBzNkFh1FbJY2zapXWZBzJ2EjDDBPFjzwf
         lh6m/lQubR7QWbdF2UHwfa58u7Zvton69hjw5i5Ee1Dz0yYSpKky/pkC1XPo3j63kUfb
         eUJg==
X-Gm-Message-State: AOAM531u7rQBvphvPz/bOh5Oeh5YG75g0w5CB4T7+FoMGu0+GVEU3SKo
	1bVaq0eHhRoZoGsTt3zQbb4a2RhVxqo=
X-Google-Smtp-Source: ABdhPJyhpU2MsG680KX0MO2WKwW1Y62DL6RDV3xBID4XEKe75zjieN1YuCpFywbsccrTrnFX6lwhfw==
X-Received: by 2002:ac8:7dd2:: with SMTP id c18mr13143799qte.301.1617396414151;
        Fri, 02 Apr 2021 13:46:54 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:46:29 -0400
Message-Id: <20210402204629.143576-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 57 +++++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 23 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index 89547cc..950743f 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -479,6 +479,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -493,31 +496,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // The NET class installer will call DIF_REMOVE even in the event of
-        // a NULL driver add. However, the default installer (for the NULL
-        // driver) then fails for some reason so we squash the error in
-        // post-processing.
-        if (DriverInfoAvailable) {
-            Error = DifInstall(DeviceInfoSet, DeviceInfoData, Context);
-        } else {
-            if (!Context->PostProcessing) {
-                Error = ERROR_DI_POSTPROCESSING_REQUIRED; 
-            } else {
-                Error = NO_ERROR;
-            }
-        }
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:48:14 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:48:14 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104970.200990 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQiD-0007EY-Rs; Fri, 02 Apr 2021 20:48:13 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104970.200990; Fri, 02 Apr 2021 20:48:13 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQiD-0007ER-OQ; Fri, 02 Apr 2021 20:48:13 +0000
Received: by outflank-mailman (input) for mailman id 104970;
 Fri, 02 Apr 2021 20:48:12 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQiC-0007EM-Cv
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:48:12 +0000
Received: from mail-qk1-x736.google.com (unknown [2607:f8b0:4864:20::736])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 28937ab7-6719-4648-9261-cf674e13303f;
 Fri, 02 Apr 2021 20:48:11 +0000 (UTC)
Received: by mail-qk1-x736.google.com with SMTP id o5so6360995qkb.0
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:48:11 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id k138sm7987506qke.60.2021.04.02.13.48.09
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:48:10 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 28937ab7-6719-4648-9261-cf674e13303f
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=F410+6xwT8PmRWZVADNCj9U/xvbQhvoMAEjkDtJIAWM=;
        b=OQjOwM6Xyinisafwr9fCEGEh9/+2bJpI+Iqp2I/i0+ckErLRR4QPYxZ7/AKYsTVHgg
         qeTSVxPY0IEFcLX/wWWtbZy6qUalwT73R1uzYg8WR7sOymlE2ImArTnL1E6MM+U8Qy1R
         0LCEsfE5zcQcinpePnQsktYdBc8itzM8vPq0YZTPvxH4Wh2nGdOx5wt6WoGh8UgQuGzs
         lk3ULXODIo+jHjcenEElMnAzVGDrv3LizBt/g8zSJorOMbd+zbrAhE5iYePsIuWR2zry
         Cq76oIBvXyOYa/+YPfAG4jTlL5zQwGMFXkQcTTypW+4QBQ/M0dyKGAqb3hOy5O5YYpH1
         qojQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=F410+6xwT8PmRWZVADNCj9U/xvbQhvoMAEjkDtJIAWM=;
        b=ihjIqQj3zaeFbCFj8DdRQQdB0o+GqNJFQ2RxVTt68+a5fSxXHq2IJs+YgxYUw7OESi
         ImFvXSgjPVNcHORjNvh7EbQTdNmlCra3ZSdVNND5M+5irMt+62JrYIEJ/+Ch1B71h86m
         Q+NkfxSbqXRVMsXCkBqrmpMc5DShEWVMDJW5VO9iazz3nNIEWHbsG67YwWnHuHKyrY44
         rYLirQlf7nYA5U+VmLrbif+jepKbEJDnun7T/Wn+dgWnTo5+5MlTUf4CnhBlqyqmyBR9
         uHCAjYda/CbNrp2ej+R3ehTkuzF2qBAnAHdPZea4tCZF729DAIdJ2qwToI5yX5ahJHko
         +Msw==
X-Gm-Message-State: AOAM533Ly4TUG+m/tANvB2h/S6ztlR6iZcZ1ILkPqfaagzS5YI4iBntP
	vgI6++7MTZu3PHY+bzFtlWQ6AJ+mHMw=
X-Google-Smtp-Source: ABdhPJwkTAp1XO4vRtoxdRAbB+atiwKAluFbzWN38QrBUau6VdXINL6LPB9f5NIiEBA/2tudt3dXpQ==
X-Received: by 2002:a37:8905:: with SMTP id l5mr15164199qkd.321.1617396491069;
        Fri, 02 Apr 2021 13:48:11 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:48:04 -0400
Message-Id: <20210402204804.159414-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

The unplug registry entry will persist if DifRemove does not run.

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 49 +++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index bc8f605..376a6cc 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -801,6 +801,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -815,23 +818,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // If there is no driver information then the NULL driver is being
-        // installed. Treat this as we would a DIF_REMOVE.
-        Error = (DriverInfoAvailable) ?
-                DifInstall(DeviceInfoSet, DeviceInfoData, Context) :
-                DifRemove(DeviceInfoSet, DeviceInfoData, Context);
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:49:20 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:49:20 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104977.200993 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQjH-0007Gz-Vt; Fri, 02 Apr 2021 20:49:19 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104977.200993; Fri, 02 Apr 2021 20:49:19 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQjH-0007Gs-T5; Fri, 02 Apr 2021 20:49:19 +0000
Received: by outflank-mailman (input) for mailman id 104977;
 Fri, 02 Apr 2021 20:49:19 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQjH-0007Gn-1u
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:49:19 +0000
Received: from mail-qk1-x734.google.com (unknown [2607:f8b0:4864:20::734])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id 00c99c8e-0d4b-4ede-87f0-b308452c8c13;
 Fri, 02 Apr 2021 20:49:18 +0000 (UTC)
Received: by mail-qk1-x734.google.com with SMTP id y5so6258405qkl.9
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:49:18 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id c5sm8083242qkl.21.2021.04.02.13.49.16
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:49:17 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: 00c99c8e-0d4b-4ede-87f0-b308452c8c13
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=TBYFeSrSWnfJa9bJdK8ewYqUe8Oo8+JsHfcUYGnbCpk=;
        b=bjb/XC8WxRNrDP4IDepeCX6F0Y2wKB/mEjoxZjLb55JKUidzT3I3IB8+ja50yfFH1b
         6sl0f+2SnWnMcS2TGxzFoEROnjjJj62ABYALezHr4U7hUvJW4ynDExTYMOl/UgB+kxlk
         TPpp8Ltgyxr0NXiUiUoQPoIDERYBvE1ZWg/89JH2YN0mabKFFGdDO7mij2TZB2LcPr8Q
         PtkoZJePMMTQN9xed3uoLFv/YDCBGrtpntRlkQ+tliXK/XKkeXPOK6/1ZVRRR2N/JM1g
         ciS3dnJ+tzmY7wzxUV9tdijLm6Dj8i/F6MfikuLHezTuHhL3bIMKEqPbclOmuVWDILP9
         iSPg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=TBYFeSrSWnfJa9bJdK8ewYqUe8Oo8+JsHfcUYGnbCpk=;
        b=hfrBO/8RZ5u5focV2BOwmlnAVcgPD8SthiwATDn8yk6S6CniUcF3/Ga1bACZ3LZNmc
         7SB1RiVYVp99GgBbMZ5S18iMXwTObWWrStXk4ShQp3dGSd9T7Rj4qWuu+bIqeyMh+WX3
         jA0FA3ASIcd8tzD/LXxpswmdtuiluh8LkNXXw8LitsfwzFb+SOv3HCvNN/Kb6c1imH3H
         3NVMEeSiiUX5Brt42ACAMzbx/0Cw0vVeMOCaQGjltX8RLQf0ghkCKplhB1gaumZoqc9R
         pkTA/C/7pB2VpMZYOLaef+QhX4QGSj34E+23PNlGTKtfBJvEX8wbO+VbWXD+SU4UUC6L
         /Buw==
X-Gm-Message-State: AOAM5303xg2GZqUp7SXvKD/0SMyERRSyGL7FEVoHtakuibaqAbGvW/Ar
	lttqUS3qgUv6TrzNFdfD3zJULHZhktw=
X-Google-Smtp-Source: ABdhPJw4gSYkbk09ZI7/VAaPQy/R7nrU7zLRrqi+BYRVBvFzp7a9FkxxGiZyGQ7HHAjvYlL/e1ZyFw==
X-Received: by 2002:a37:9e0e:: with SMTP id h14mr15005884qke.197.1617396557683;
        Fri, 02 Apr 2021 13:49:17 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:49:10 -0400
Message-Id: <20210402204910.170475-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 49 +++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index e749506..7d72a67 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -1248,6 +1248,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -1262,23 +1265,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // If there is no driver information then the NULL driver is being
-        // installed. Treat this as we would a DIF_REMOVE.
-        Error = (DriverInfoAvailable) ?
-                DifInstall(DeviceInfoSet, DeviceInfoData, Context) :
-                DifRemove(DeviceInfoSet, DeviceInfoData, Context);
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



From win-pv-devel-bounces@lists.xenproject.org Fri Apr 02 20:49:44 2021
Return-path: <win-pv-devel-bounces@lists.xenproject.org>
Envelope-to: archives@lists.xenproject.org
Delivery-date: Fri, 02 Apr 2021 20:49:44 +0000
Received: from list by lists.xenproject.org with outflank-mailman.104981.200998 (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQjg-0007KI-2I; Fri, 02 Apr 2021 20:49:44 +0000
X-Outflank-Mailman: Message body and most headers restored to incoming version
Received: by outflank-mailman (output) from mailman id 104981.200998; Fri, 02 Apr 2021 20:49:44 +0000
Received: from localhost ([127.0.0.1] helo=lists.xenproject.org)
	by lists.xenproject.org with esmtp (Exim 4.92)
	(envelope-from <win-pv-devel-bounces@lists.xenproject.org>)
	id 1lSQjf-0007KA-VM; Fri, 02 Apr 2021 20:49:43 +0000
Received: by outflank-mailman (input) for mailman id 104981;
 Fri, 02 Apr 2021 20:49:43 +0000
Received: from us1-rack-iad1.inumbo.com ([172.99.69.81])
 by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from
 <SRS0=jQQs=I7=gmail.com=troycrosley@srs-us1.protection.inumbo.net>)
 id 1lSQjf-0007K5-3n
 for win-pv-devel@lists.xenproject.org; Fri, 02 Apr 2021 20:49:43 +0000
Received: from mail-qk1-x72a.google.com (unknown [2607:f8b0:4864:20::72a])
 by us1-rack-iad1.inumbo.com (Halon) with ESMTPS
 id cf69b0be-3bf1-414f-8792-fe61c70631b2;
 Fri, 02 Apr 2021 20:49:42 +0000 (UTC)
Received: by mail-qk1-x72a.google.com with SMTP id q3so6234666qkq.12
 for <win-pv-devel@lists.xenproject.org>; Fri, 02 Apr 2021 13:49:42 -0700 (PDT)
Received: from localhost.localdomain (ool-18bc75a6.dyn.optonline.net.
 [24.188.117.166])
 by smtp.gmail.com with ESMTPSA id v7sm7152154qtw.51.2021.04.02.13.49.40
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 02 Apr 2021 13:49:41 -0700 (PDT)
X-BeenThere: win-pv-devel@lists.xenproject.org
List-Id: Developer list for the Windows PV Drivers subproject
 <win-pv-devel.lists.xenproject.org>
List-Unsubscribe: <https://lists.xenproject.org/mailman/options/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=unsubscribe>
List-Post: <mailto:win-pv-devel@lists.xenproject.org>
List-Help: <mailto:win-pv-devel-request@lists.xenproject.org?subject=help>
List-Subscribe: <https://lists.xenproject.org/mailman/listinfo/win-pv-devel>, 
 <mailto:win-pv-devel-request@lists.xenproject.org?subject=subscribe>
Errors-To: win-pv-devel-bounces@lists.xenproject.org
Precedence: list
Sender: "win-pv-devel" <win-pv-devel-bounces@lists.xenproject.org>
X-Inumbo-ID: cf69b0be-3bf1-414f-8792-fe61c70631b2
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=esFipTJnsK4QSolAxbDKMsXQYvAmcN/zqMztC5UvHu8=;
        b=MddltfW8d9wpjyJH5C896CpdytVM1qPHQSpVdhUP9HXB+7dT57oX4Nepo2vuzuK75Z
         Tj6V1cnF708A+NTD7HxoqWmE3waGVYlXXQLTo4/w3SUB8Qf4+afi/c1cgpCuhAqlkLSR
         hBGSRX45ZvS06rMpYvb0aBEiuzQySJKSkeiFa+sM9DnN1GSOzvzBQL5ycL/UL30CHjkM
         wubsYNYSyllBlGhRephz2PIUgCGykSRU+EoWQ9zf5fr69OSzdFy+F+86+GS40nuu0OVo
         knIes8mLW6z5AMB+9+svjkUS4IlfMfJJNG3/mCzoz23RAAFArV6GC3PD8JE5YFmw0gHL
         vXkw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version
         :content-transfer-encoding;
        bh=esFipTJnsK4QSolAxbDKMsXQYvAmcN/zqMztC5UvHu8=;
        b=Ae0S3n9WuBTi2sihRGP1AHTf5pYi7txK1uJo4ImSmvyyQiqwWhl8pvMGh+4dSPeGE3
         +GqSzHzBaPDrE5ImR1TBvgU8baKlNasJGM6SDKfEiA4pBGAMU6QFIMbnNr6kGU2V/FBB
         9R0317yfpLPSvF8juUw4LUHtHbzkO3ckSFrbvzcow7lHAXDkxaXCNy+Z06a1xGyYpnF4
         WbLIJrpgMUnBFSOsY6UXhQKEsku3VmjSQfOgh83lH1a4VqJs+EmJnk/rwlwl5BZwzWmr
         ANFDxOcAm05+b5j+MJ/7255FKmVS+8CFhaszG08YNTCu68NHBrvgC29SxaE4dnRQLcsR
         v43A==
X-Gm-Message-State: AOAM533d8MDEZSdqOnR6FpmxPGBuDRgTo9khgIZN5/m/t4Om4ueUOnrr
	2JpMecV5Uop40u/qLR5oMDK436AqR3U=
X-Google-Smtp-Source: ABdhPJxnXfNdaaVcb4SeKUDkrHQ2RNShgOCruRY5KAPfUf4RTAcDtyJRC7GiRK7VIjfYS8enxZMJQw==
X-Received: by 2002:a05:620a:10a7:: with SMTP id h7mr15028339qkk.402.1617396581699;
        Fri, 02 Apr 2021 13:49:41 -0700 (PDT)
From: Troy Crosley <troycrosley@gmail.com>
To: win-pv-devel@lists.xenproject.org
Cc: paul@xen.org,
	ben.chalmers@citrix.com,
	owen.smith@citrix.com,
	Troy Crosley <troycrosley@gmail.com>,
	Joel Upham <uphamj@ainfosec.com>
Subject: [PATCH] Ensure DifRemove coinst routine runs on uninstall.
Date: Fri,  2 Apr 2021 16:49:34 -0400
Message-Id: <20210402204934.173989-1-troycrosley@gmail.com>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

In Windows 10 version 2004, The coinstallers' DIF_INSTALLDEVICE routines
do not get called on driver uninstall. In previous versions of Windows,
this occurs as part of the uninstall during the null device install and
is the only time DifRemove gets called to perform cleanup. Work around
this change by calling DifRemove from DIF_SELECTBESTCOMPATDRV, which is
the only coinstaller request that seems to happen on uninstall in
Windows 10 version 2004. In addition, improve the null driver test to
also check if DriverInfoData.DriverType is equal to SPDIT_CLASSDRIVER or
SPDIT_COMPATDRIVER, which is necessary as of some Windows version (at
least Windows 10 version 1803).

Signed-off-by: Joel Upham <uphamj@ainfosec.com>
Signed-off-by: Troy Crosley <troycrosley@gmail.com>
---
 src/coinst/coinst.c | 49 +++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 15 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index da2c59e..5ff86d4 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -1248,6 +1248,9 @@ Entry(
     )
 {
     HRESULT                         Error;
+    SP_DRVINFO_DATA                 DriverInfoData;
+    BOOLEAN                         DriverInfoAvailable;
+    BOOLEAN                         IsNullDriver;
 
     Log("%s (%s) ===>",
         MAJOR_VERSION_STR "." MINOR_VERSION_STR "." MICRO_VERSION_STR "." BUILD_NUMBER_STR,
@@ -1262,23 +1265,39 @@ Entry(
             Context->InstallResult);
     }
 
+    DriverInfoData.cbSize = sizeof(DriverInfoData);
+    DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
+                                                   DeviceInfoData,
+                                                   &DriverInfoData) ?
+                          TRUE :
+                          FALSE;
+    IsNullDriver = !(DriverInfoAvailable &&
+                    (DriverInfoData.DriverType == SPDIT_CLASSDRIVER ||
+                     DriverInfoData.DriverType == SPDIT_COMPATDRIVER));
+
     switch (Function) {
+	case DIF_SELECTBESTCOMPATDRV: {
+        //
+        // If the NULL driver will be installed, treat this as we would a
+        // DIF_REMOVE to work around the fact that Windows 10 2004 doesn't
+        // call DIF_INSTALLDEVICE on uninstall.
+        // An InstallResult value of ERROR_NO_COMPAT_DRIVERS simply means
+        // that the NULL driver was selected, and so should not be treated
+        // as an error.
+        //
+        if (Context->PostProcessing &&
+            Context->InstallResult == ERROR_NO_COMPAT_DRIVERS)
+            Context->InstallResult = NO_ERROR;
+
+        Error = (IsNullDriver) ?
+                DifRemove(DeviceInfoSet, DeviceInfoData, Context) :
+                NO_ERROR;
+        break;
+    }
     case DIF_INSTALLDEVICE: {
-        SP_DRVINFO_DATA         DriverInfoData;
-        BOOLEAN                 DriverInfoAvailable;
-
-        DriverInfoData.cbSize = sizeof (DriverInfoData);
-        DriverInfoAvailable = SetupDiGetSelectedDriver(DeviceInfoSet,
-                                                       DeviceInfoData,
-                                                       &DriverInfoData) ?
-                              TRUE :
-                              FALSE;
-
-        // If there is no driver information then the NULL driver is being
-        // installed. Treat this as we would a DIF_REMOVE.
-        Error = (DriverInfoAvailable) ?
-                DifInstall(DeviceInfoSet, DeviceInfoData, Context) :
-                DifRemove(DeviceInfoSet, DeviceInfoData, Context);
+        Error = (IsNullDriver) ?
+                NO_ERROR :
+                DifInstall(DeviceInfoSet, DeviceInfoData, Context);
         break;
     }
     case DIF_REMOVE:
-- 
2.25.1



