Commit graph

88 commits

Author SHA1 Message Date
Yuri Benditovich
c736f5d8be driver: fix driver verifier assertion in FileCreate callback
Previous commit 4de57a9ff causes driver verifier assertion with
latest Windows builds. Note that this assertion is not in latest
WDF sources on GitHub. The verifier does not allow to forward
the MJ_CREATE requestto local IO target using "send-and-forget".
It requires the request to set completion callback.
There is an option to remove the file create callback at all, but
we prefer to have printout on file open for better diagnostics.
So we add completion callback for forwarded request and complete
the request in it.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2020-01-27 19:49:45 +02:00
Yuri Benditovich
26a3619666 driver: add file open callback for tracing
Add callback when filter device receives file open request.
Propagate open operation down the stack and log it.
ETW log will contain process id of open request.
It is possible that more than one process opens the device.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2020-01-02 21:47:41 +02:00
Yuri Benditovich
08ad758943 Use also extended rules to decide whether device should be hidden
Extended rules processing uses bitmask OR between device type
determination bitmap and class/type bitmap provided in 'Class'
parameter of the extended rule.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2019-04-15 11:19:13 +03:00
Yuri Benditovich
29b556b0ea hider: calculate device type bitmask for each child device
Device type bitmask is calculated for device class and classes
of all its interfaces by narrowing set of device classes to set
of device types.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2019-04-15 11:19:13 +03:00
Yuri Benditovich
4d1ecea50d Report superspeed properly on Win7
Win7 with USB 3.0 stack might not report superspeed
the same way as Win8 does. Use bcdUSB field of device
descriptor for that (USB 3.0 device connected to USB 2.x
port usually falls to USB 2 compatible configuration).
Getting the speed from HUB driver via IOCTL is more
complicated.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2018-10-17 15:52:34 +03:00
Yuri Benditovich
960f44ed2c Prevent USB operation with non-USB devices
This commit aims to address
https://bugzilla.redhat.com/show_bug.cgi?id=1575043
The driver definitely may try accessing USB device where
it is not USB and sending 'Submit URB' IOCTL down the stack
may cause unpredictable result. Current commit change
the order of checks when the device is enumerated by its
parent device: first ensure this is USB device, then try
to get USB-specific information.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2018-10-10 11:31:56 +03:00
Yuri Benditovich
2910063697 Use lower device for queries during initialization
It is more correct to use lower device in stack for queries
during filter initialization. Lower device is in initialized
state and can process all kinds of requests, when current one is
not ready yet.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
2017-07-12 16:58:03 +03:00
Yuri Benditovich
6da5b27ca6 Alloc: Make non-paged allocation from Nx pool on Win8 and later
This is requirement of DeviceGuard and HyperVisor Code
Integrity Readiness Test on Win10/Server2016.
We use Nx allocations for all the systems where Nx pool
is implemented, i.e. for Windows 8 and later.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-02 17:24:35 +03:00
Yuri Benditovich
7c72773cd1 FilterDevice: Do not report non-USB devices in list of devices
The driver may report non-USB device in list of devices
available for redirection (for example, this happens with
FTDI dual-port serial adapter PID 6010)

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-04-02 17:24:19 +03:00
Dmitry Fleytman
848bb79ac2 FilterDevice: Raise redirection removal event on device disconnection
This is useful for devices that change ID on reset.

Previous scheme of raising event on device
"reconnection" after port cycle does not work
for such devices because after reset
they look like another device for UsbDK.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-09 18:28:21 +02:00
Dmitry Fleytman
db95b4651e FilterDevice: Fix recognition of HUB devices
Sometimes UsbDk cannot query device descriptors for USB hubs,
in such cases it does not attach to theirs stack during parent bus
relations processing.

However, since UsbDk is registered as USB hub class filter,
WDF will call its AddDevice callback anyway.

In this case UsbDk should assume that it is dealing with a hub
and assign its usual hub strategy.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-02-02 12:04:36 +02:00
Sameeh Jubran
6b623e0ba2 Fix a possible BSOD due to null pointer
m_Relations can be null therefore we should access it carefully.

Signed-off-by: Sameeh Jubran <sameeh@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2017-01-18 15:28:09 +02:00
Dmitry Fleytman
8c7edd9997 FilterDevice: Extend IRP post processing logic
This patch adds support for IRP post processing
on failure and in all cases.

New logic will be used by following commits to
implement device text patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-07-04 11:29:27 +03:00
Dmitry Fleytman
f01408384a UsbDk: Simplify and refactor filter attachment code
This is a refactoring commit, no functional changes introduced.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:09 +03:00
Dmitry Fleytman
0b7487ba56 UsbDk: Retire old hiding logic
This commit retires old device hider logic based
on wiping PDOs from BusRelations array.

Previous commits introduce new logic based on IDs
patching.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:05 +03:00
Dmitry Fleytman
a9bbb929f5 UsbDk: Implement hider logic via patching device IDs
Wiping PDOs from BusRelations list has side effect
of absence of hotplug events from the OS.

This is not good for applications that want devices
appear hidden and start redirection process on plug
at the same time.

Following patches will retire old hiding logic.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:32:00 +03:00
Dmitry Fleytman
b354d0ea35 UsbDk: Trivial: Remove comments numbering
It is ridiculous to update numbering manually after
each change in that function.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-06-29 17:31:50 +03:00
Dmitry Fleytman
603d98e602 FilterDevice: Use generic WDF request context
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-02-10 10:56:23 +02:00
Dmitry Fleytman
6b21ddc78c FilterDevice: Use cached device descriptor for strategy selection
Querying device descriptor fails in that context.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-28 15:53:35 +02:00
Dmitry Fleytman
82b9a59bc4 UsbDk: Introduce tracing for BusRelations processing
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2016-01-25 15:05:59 +02:00
Dmitry Fleytman
fccb982f58 FilterDevice: Protect filter objects from deletion while in use
This patch makes filter object reference counting objects and
ensures reference is help to filter objects while they are in use.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-11-24 12:32:33 +02:00
Dmitry Fleytman
f228c840e1 UsbDk: Fix paged memory access under spinlock
This patch fixes access to bus device relations array
allocated from paged memory pool under child device list
spinlock.

Fixed by creation of temporary non-paged copy of the paged data.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-10-28 09:11:39 +02:00
Jay.han
4dbbf0c86c UsbDk: Add support for USB 3.0 controllers
Add search strategy for USB3 controllers:

- Standard Microsoft controller
- Renesas controller (NUSB3)
- Intel controller (IUSB3)

Signed-off-by: Jay.Han <ezzzehxx@gmail.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-05-31 10:56:18 +03:00
Dmitry Fleytman
c0fd0b9692 UsbDk: Fix extra PDO dereference for redirected objects
This problem lead to BSOD on stop redirection

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-04-30 18:54:05 +03:00
Dmitry Fleytman
cc1092cf45 FilterDevice: Fix PDO leak for hidden devices
1. Never hide PDOs indicated to PNP manager
   since we're not owning those after the indication
2. Dereferenced PDOs for hidden devices on device removal
   because we're the owner of those PDOs

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-03-25 17:37:58 +02:00
Dmitry Fleytman
381cf8ae66 UsbDk: Do not indicate PDO for hidden devices on QDR
Signed-off-by: Kirill Moizik <kirill@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2015-02-17 09:13:06 +02:00
Pavel Gurvich
7bd5c64b65 UsbDk: Fix leak of CUsbDkFilterDevice objects
If driver fails filter device creation process
before WDF device created context memory allocated
must be freed explicitely.

Bug found by HCK fault injection test.

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-09-16 08:48:24 +03:00
Dmitry Fleytman
f31d25fde7 UsbDk: Cache configuration descriptors on QDR
It is basically forbidden to send arbitrary requests to device
directly via PDO while device driver is present in device stack.
This may lead to unexpected behaviour because device may be
in many different states e.g. low power, processing other
requests etc.

In order to avoid sending descriptor requests to devices with
active functional driver we're caching all descriptors we need
on QDR post-processing while we're on top of device stack for
sure.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-09-09 18:10:47 +03:00
Dmitry Fleytman
e04099b3d6 UsbDk: Add more traces on new child registration
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-09-09 18:10:44 +03:00
Pavel Gurvich
9c891832c2 UsbDk: Fix race conditions in device enumeration
During stop redirection process driver signals
redirection stopped event before adding corresponding
device back to childen list.

In case of unfortunate timing client code that
enumerates devices right after stoppng redirection
may not get device for which redirection was stopped
in devices list.

This patch fixes the issue by changing order of
corresponding operations.

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-08-17 09:29:56 +03:00
Pavel Gurvich
47e5e036a1 UsbDk: Fix stop redirection failures
Move redirection stopped event signalling from DeviceAdd
callback to QDR post-processing callback.

DeviceAdd callback is not (usually) called for non-redirected devices.

Without this patch stop redirection process fails to
complete because corresponing event never set.

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-08-17 09:01:52 +03:00
Pavel Gurvich
72cf6b764d UsbDk: Do not create symlinks for redirector devices
Symlinks not needed anymore since we create redirector handles
in kernel.

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-06-12 01:02:49 +03:00
Dmitry Fleytman
5c4d0af852 UsbDk: Open redirector handle in driver
This commit makes redirection creation atomic operation
from user mode client point of view.

This ensures redirection will be stopped automatically
in case of unexpected user mode client termination.

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-06-12 00:57:33 +03:00
Dmitry Fleytman
d5d51dfd47 UsbDk: place all system includes into stdafx.h
This makes include policy more strict and ensures
all system includes properly wrapped with extern "C"

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-06-09 11:50:26 +03:00
Dmitry Fleytman
447de6ad71 build: add XP/2003 configurations
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-06-01 23:01:13 +03:00
Pavel Gurvich
0cf0c43f39 UsbDk: Register EvtFileClose callback for filter device
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-31 19:19:16 +03:00
Dmitry Fleytman
32ed150d95 UsbDk: Read and store device speed on child registration
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-29 15:34:06 +03:00
Pavel Gurvich
00da1f59fc UsbDk: make stop redirection synchronous
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-20 12:03:27 +03:00
Pavel Gurvich
b0e4908e3e UsbDk: do not create symlinks for HUB filters
Those symlinks are not used by user mode API

Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-20 12:03:25 +03:00
Pavel Gurvich
a77d8161e4 UsbDk: Add license-related files and headers
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-20 11:56:20 +03:00
Dmitry Fleytman
af30ad9b0a UsbDk: Move MAX_DEVICE_ID_LEN definition to Public.h
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:15 +03:00
Dmitry Fleytman
00dec94f34 UsbDk: Assign HUB strategy to devices of class HUB
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
49fceb5323 UsbDk: Trivial: clean printouts
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
375a5eb10d UsbDk: Avoid multiple redirections of the same device
For some USB devices system calls our AddDevice callback for FDO.
In addition we call the same callback for PDO of the devices we
want to redirect. In this case we will try to install our filter
two times into the same stack which is problematic.

This patch eliminates such a possibility.

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
79cac7bc0e UsbDk: Introduce filter device request context configuration
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
1fef4eee3c UsbDk: Make filter devices receive IoInCallerContext event
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
d3686076c1 UsbDk: FilterDeviceInit: introduce shortcut for strategy retrieval
Signed-off-by: Pavel Gurvich <pavel@daynix.com>
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:14 +03:00
Dmitry Fleytman
eefbd06435 UsbDk: Supply USB device descriptors on enumeration
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
1942df5521 UsbDk: Cleanup old strategy before new strategy assignment
Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00
Dmitry Fleytman
bbf9fa0300 UsbDk: Delete base strategy on hub strategy cleanup
Forgotten call of base class Delete() added

Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
2014-05-11 19:26:13 +03:00