Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build for Windows 10+ Universal #320

Open
MatthewTingum opened this issue Aug 1, 2022 · 8 comments
Open

Build for Windows 10+ Universal #320

MatthewTingum opened this issue Aug 1, 2022 · 8 comments

Comments

@MatthewTingum
Copy link

This fails to build out of the box with the following configuration:

  • Target OS Version: Windows 10 or higher
  • Target Platform: Universal

For this, we need:

  • Spectre mitigation enabled
  • Replace deprecated functions
  • More?
@Kogotoro
Copy link

Kogotoro commented Aug 2, 2022

vs2022-17.2.6
wdk-10.1.22621.1

in libdrv, usbip_stub, usbip_vhci, usbip_vhci_ude

windows sdk version: $(LatestTargetPlatformVersion)
(installed default 10.0.20348.0 and for wdk~10.0.22621.0, so seems used 22621)

Target OS Version: Windows 10 or higher
Target Platform: Universal
Spectre mitigation disabled

Replace deprecated
ExAllocatePoolWithTag(PagedPool -> ExAllocatePool2(POOL_FLAG_PAGED
ExAllocatePoolWithTag(NonPagedPool-> ExAllocatePool2(POOL_FLAG_NON_PAGED

build every project separate, not build entire solution.

at least it builds...
about working ... not sure cause example https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/updating-deprecated-exallocatepool-calls says

// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
RtlZeroMemory(Allocation, 100);

// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED, 100, 'abcd');

and i dont saw RtlZeroMemory after ExAllocatePoolWithTag in old code? only RtlCopyMemory sometimes.


last time i try build with Spectre mitigation enabled , was some mess about missing or conflicting some system headers from wdk or sdk (but they was present somewhere in wdk/sdk folders).

and installer have 3 different versions of spectre libs for toolset v143... that we should use?

@Kogotoro
Copy link

Kogotoro commented Aug 2, 2022

upd... i just instlled last spectre libs, and it builds with Spectre mitigation enabled.

@MatthewTingum
Copy link
Author

The example is just showing that the new ExAllocatePool2 function zeros the memory for you.

Memory is zero initialized unless POOL_FLAG_UNINITIALIZED is specified.

The docs for ExAllocatePool2 also say:

If you are building a driver that targets versions of Windows prior to Windows 10, version 2004, use ExAllocatePoolZero, ExAllocatePoolUninitialized, ExAllocatePoolQuotaZero, or ExAllocatePoolQuotaUninitialized.

So maybe ExAllocatePoolZero is a better replacement for ExAllocatePoolWithTag because it has greater compatability.

@MatthewTingum
Copy link
Author

I'll put in a PR for this. My biggest concern is breaking existing workflows. The READAME states that this project is not production ready. There are tags and releases in place. Presumably, anyone using this in production is using a tagged or released build.

My plan is to:

  • Replace ExAllocatePoolWithTag with ExallocatePoolZero
    • It's a drop in replacement
    • I assume this projects doesn't depend on pool allocations being non-zeroed
      • or executable for that matter

ExAllocatrePoolZero requires the following:

To run on versions of Windows prior to Windows 10 version 2004, the driver must define POOL_ZERO_DOWN_LEVEL_SUPPORT and call ExInitializeDriverRuntime before calling this function.

This seems like a good idea, but I'm not familiar enough with the project to know if execution on the pool is necessary. If it is, we should fix that.

@Kogotoro
Copy link

Kogotoro commented Aug 3, 2022

upd:
its build... but not work xD (win10, vs2022... and other staff described above)

on win10 it bind device without errors , but device in manager shows with error =/
(same for Spectre mitigation enabled/disabled)

its google translated error from device manager:

Failed to load the driver for this device. The driver may be corrupted or missing. (Code 39)
{Driver entry point not found}
Device driver %hs could not find entry point %hs in driver %hs.

__
previosly i build it on win8.1, vs2019, wdk-10.0.18362.1
without changing 'Target OS Version','Target Platform' (ie usbip_stub, usbip_vhci was Desktop not Universal)
only disable 'spectre', and it worked on win10...

... but my build have some experimental changes... so not certain.

__
tried rebuild on (win10, vs2022...) with usbip_stub with original 'Target Platform: Desktop' and still error on device...

despite the fact that the build from vs2019 works -_-

@Kogotoro
Copy link

Kogotoro commented Aug 3, 2022

and again upd...

tried rebuild on (win10, vs2022...)
usbip_stub, usbip_vhci ~ 'Target Platform: Desktop' (probably it also be ok if i will set 'Target Platform: Universal' , not checked)

!!! and i didnt replace ExAllocatePoolWithTag with ExAllocatePool2,
instead i turn off 'treat warnings as errors'...

and it works now O_o?

@Kogotoro
Copy link

Kogotoro commented Aug 3, 2022

I'll put in a PR for this. My biggest concern is breaking existing workflows. The READAME states that this project is not production ready. There are tags and releases in place. Presumably, anyone using this in production is using a tagged or released build.

My plan is to:

  • Replace ExAllocatePoolWithTag with ExallocatePoolZero

    • It's a drop in replacement

    • I assume this projects doesn't depend on pool allocations being non-zeroed

      • or executable for that matter

ExAllocatrePoolZero requires the following:

To run on versions of Windows prior to Windows 10 version 2004, the driver must define POOL_ZERO_DOWN_LEVEL_SUPPORT and call ExInitializeDriverRuntime before calling this function.

This seems like a good idea, but I'm not familiar enough with the project to know if execution on the pool is necessary. If it is, we should fix that.

just checked... it works.
my test VBox has win10.v18362 ... so ExAllocatePool2 (what needs 19041+) not work because of this ^^'.

we also may need consider this...
https://www.osr.com/blog/2020/07/14/bug-in-new-function-exallocatepoolzero-results-in-security-vulnerability-and-crashes/
https://www.osr.com/blog/2021/01/07/mitigations-exallocatepoolzero-security-vulnerability/

@MatthewTingum
Copy link
Author

!!! and i didnt replace ExAllocatePoolWithTag with ExAllocatePool2,
instead i turn off 'treat warnings as errors'...

This isn't surprising.....
Deprecation of APIs generally involves deterrence of usage in the form of warnings followed by a complete drop of support.

we also may need consider this...
[links]

The official docs state thsi too. As you've stated, not everything zeros memory. I don't think we're missing much by not doing something that never happened.

Can we consider a test matrix for this project? There are no contribution guidelines and I don't know when I should consider a PR ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants