Skip to content

Fix version checking in Windows (proper backwards and forwards compatible version checking) - #7727

Closed
wyattoday wants to merge 17 commits into
curl:masterfrom
wyattoday:master
Closed

wyattoday wants to merge 17 commits into
curl:masterfrom
wyattoday:master

Conversation

@wyattoday

@wyattoday wyattoday commented Sep 15, 2021 •

Copy link
Copy Markdown
Contributor

VerifyVersionInfo has some of the same problems as GetVersionEx(). Specifically, the problem that we're dealing with is inaccurate version reporting if the application linking libCurl doesn't explicitly have an application manifest saying it's compatible with a version greater than or equal to the version we're testing.

Or to put it in MSDN parlance:

Windows 10: VerifyVersionInfo returns false when called by applications that do not have a compatibility manifest for Windows 8.1 or Windows 10 if the lpVersionInfo parameter is set so that it specifies Windows 8.1 or Windows 10, even when the current operating system version is Windows 8.1 or Windows 10. Specifically, VerifyVersionInfo has the following behavior:

  • If the application has no manifest, VerifyVersionInfo behaves as if the operation system version is Windows 8 (6.2).
  • If the application has a manifest that contains the GUID that corresponds to Windows 8.1, VerifyVersionInfo behaves as if the operation system version is Windows 8.1 (6.3).
  • If the application has a manifest that contains the GUID that corresponds to Windows 10, VerifyVersionInfo behaves as if the operation system version is Windows 10 (10.0).

Why is this a problem? With executables we release, we have full control over the manifests, and thus this isn't a problem. With libraries we release that link to our libraries that use libCurl, suddenly the version detection is broken if the end-developer doesn't know what manifests are, why they're needed, and how to implement them correctly. In short: it becomes a big hassle where features magically work if run from one executable linking the library and suddenly don't work if run from another executable on the same machine linking the exact same library.

Right now this only affects ALPN. However, TLS 1.3 support has arrived in Windows Server 2022 (their LTS server product) and Windows 11. And to detect and use TLS 1.3 proper version checking needs to be implemented (including checking build numbers).

So... what do we do? Well, luckily there's one version function that doesn't try to outsmart developers (yet) and still reports accurate version numbers regardless of manifests the calling executable may or may not have. Namely, RtlGetVersion()

TLDR: this fixes ALPN detection and prepares for Window Server 2022 / Windows 11 detection for TLS 1.3 support (as well as TCP fast open support on Windows).

Also, this PR reduce the code duplication in the version checking function and removes version checking when we're compiling for a later version of Windows.

…ible version checking). This fixes ALPN with executables without the proper manifest. Also begins support for TFO and TLS 1.3 on Windows.
@MarcelRaad

Copy link
Copy Markdown
Member

This again looks to me like removing support for Windows < 2000 would be a great breaking change for curl 8 :-)

@MarcelRaad

Copy link
Copy Markdown
Member

I'm not sure if removing the runtime overhead of curlx_verify_windows_version is worth cluttering every usage with an #ifdef 🤔

@wyattoday

Copy link
Copy Markdown
Contributor Author

@MarcelRaad

I'm all for that "breaking" change. There's no need to target Windows XP or older. Any computers running those OSes are just being used for botnets. There's no way to safely "airgap" them. All efforts to make it painful to use old, insecure, OSes is a positive improvement for society.

... but, I digress.

@wyattoday

Copy link
Copy Markdown
Contributor Author

I'm not sure if removing the runtime overhead of curlx_verify_windows_version is worth cluttering every usage with an #ifdef 🤔

It was less for the runtime overhead of the curlx_verify_windows_version function and more for the code reduction for dead code gated by that function that will always be present but never actually be called.

@vszakats

vszakats commented Sep 15, 2021 •

Copy link
Copy Markdown
Member

Is there a reason why RtlGetVersion() is linked and called statically, instead of calling it via GetModuleHandle() / GetProcAddress() dynamically? With the latter method it wouldn't be necessary to break compatibility to make this new/alternate version detection scheme work.

@vszakats vszakats added the Windows Windows-specific label Sep 15, 2021
@wyattoday

Copy link
Copy Markdown
Contributor Author

Is there a reason why RtlGetVersion() is linked and called statically, instead of calling it via GetModuleHandle() / GetProcAddress() dynamically? With the latter method it wouldn't be necessary to break compatibility to make this new/alternate version detection scheme work.

@vszakats Yes, less overhead (faster execution) and it still calls the function dynamically. So, the ntdll is loaded when the calling executable is executed rather than when the curlx_verify_windows_version is called.

Plus, why over-complicate things? If you're on Windows, curlx_verify_windows_version() will be called eventually. Loading using GetModuleHandle() might not work (I don't believe ntdll is linked by default by user-mode programs) so a LoadLibrary() would be required, introducing more memory management (freeing the library eventually).

@vszakats

vszakats commented Sep 15, 2021 •

Copy link
Copy Markdown
Member

The dynamic call needs to be done a single time (on the first call) then store the result in memory. ntdll.dll is always linked indirectly via necessary Win32 API DLLs (and loaded on any booted Windows system anyway), so there is no need to load anything extra. Plus this new method would replace a bunch of official version-detection calls. Also ntdll.dll is already used dynamically to detect Wine.

Overall it feels a little uneasy to use an undocumented kernel call to detect versions behind the back of the manifest, just to cover the rare case when someone gets it wrong or forgets it. E.g. the mingw/cygwin toolchain has been adding a default manifest automatically for many years.

For TLS 1.3 and other new features, targeted feature detection would seem more fitting. If this is not doable here, the dynamic option would keep curl compatible and I believe performance optimizations can be done once the new detection works as expected.

@wyattoday

wyattoday commented Sep 16, 2021 •

Copy link
Copy Markdown
Contributor Author

RtlGetVersion() has been documented for 20+ years..

Yes, the function is in an include that’s part of the WDK and not the typical Windows SDK, but that’s the nature of ntdll functions.

just to cover the rare case when someone gets it wrong or forgets it.

This has happened in the real world. Like I said in PR message, we make executables and libraries. In the executables this isn’t a problem. We control the manifests, thus the typical version functions work as expected.

For our libraries, using version functions that don’t return actual version numbers unless the correct manifests are present is a problem. The reason: we don’t control the exes.

Yes, we’ve run into this problem in real life a lot. It’s not hypothetical. It’s the reality of dealing with commercial development.

So, why are accurate version numbers important? For ALPN, not so much (but it explains some curious logging we’ve seen in the field). For TLS 1.3, very important.

Regarding your suggestion of using feature detection, there is not a public documented way to detect TLS 1.3 presence. The recommended way in the MSDN docs is to only enable it for specific versions of Windows Server / Windows “10”, namely: specific build numbers.

Long story short, accurate versions matter. This is a public function that can be used and provides accurate versions without flaky behavior.

And before we begin work on adding TLS 1.3 support for Schannel we need this (or a variation of this) PR merged so accurate versions are available, as well as build numbers.

@vszakats

vszakats commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

NTDLL is definitely something new, but linking against it statically is not a best solution. So, instead of requiring apps to include a manifest (which is the recommended/expected way to deal with this, for all libraries and code), this will force all applications to link against NTDLL and break their compatibility requirements (and their build scripts) in the process. I think it is not ideal if a 3rd-party library like libcurl imposes such requirements/limitations on apps that wants to link it.

Version detection was made extremely messy in Windows, no doubt about that, but usually it's best to accept whatever mess was produced by the vendor than trying to actively fight it.

Is it known already that it's required in upcoming SChannel to actively detect TLS 1.3-capability to be able to use it? Does it need to be explicitly enabled on new systems to use it? Can SChannel be told to use it using flags, which flags will be ignored on OS versions that don't support it?

@wyattoday

Copy link
Copy Markdown
Contributor Author

NTDLL is definitely something new, but linking against it statically is not a best solution.

That's not linking against it statically. Windows and Unix development are different. On Windows you link against a "stub" lib so that are executable "knows" to load the correct dll when the executable is loaded (as part of the startup of the executable). On unix you can just link directly with a dynamic library.

If me changing the usage of the function to manually loading the DLL in code rather than letting the linker and loader do the hard work is what it takes to get this PR merged, then I'll do it. Is it less efficient speed-wise and code-wise? Yes.

But if it's the style of the project to sometimes let the linker handle it and other times not, then, when in Rome...

Can SChannel be told to use it using flags, which flags will be ignored on OS versions that don't support it?

From the research we've done, TLS 1.3 is present in a broken form in SChannel for several builds now. It can be enabled with registry, but then the SChannel functions will fail when the TLS 1.3 flags are present on these "experimental" (broken) versions.

Hence the need to put the detection behind version checking. Hence the need for accurate version checking (that checks the build)

@vszakats

vszakats commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

This patch adds -lntdll linker option and #pragma comment(lib, "ntdll.lib") (which #pragma only works with MSVC), meaning the resulting binaries will have a new entry referencing this DLL (at the moment this DLL is indirectly referenced by Win32 API DLLs). After this patch, any app linking libcurl will have to also add -lntdll, otherwise they will get a linker error similar to this: undefined reference to '__imp_RtlGetVersion'.

On Windows when referencing APIs that may or may not be available at runtime, the standard method is to retrieve their address at runtime and gracefully fall back to a compatible code path when that API is not available.

If this call is necessary, I would not worry about the performance of the two extra API calls to retrieve the handle of the DLL than retrieve the function's address. If this causes a performance issue, the pointer can be saved and re-used from then on, e.g. in the Wine detection code and whereever else it is (will be) needed. This is also good practice to minimize redundant (and non-portable) code.

So, we don't yet know how this will work in a non-broken, final release? It seems a bit odd that SChannel TLS 1.3 support would require version detection (especially a non-official method) and explicit detection/enabling work (or registry tweak even!). Windows Server 2008 SP2/R2 required registry tweaks to enable TLS 1.2, so it wouldn't be unprecedented, though in such case this is an OS-level issue and once enable there, SChannel automatically used it. That link says that TLS 1.3 is automatically enabled in Windows 2022.

@wyattoday

Copy link
Copy Markdown
Contributor Author

After this patch, any app linking libcurl will have to also add -lntdll, otherwise they will get a linker error similar to this: undefined reference to '__imp_RtlGetVersion'.

Not in Microsoft compilers (just double-checked to confirm). And if MingW maintains any sort of compatibility with Microsoft compilers on Windows, then not there either.

On Windows when referencing APIs that may or may not be available at runtime, the standard method is to retrieve their address at runtime and gracefully fall back to a compatible code path when that API is not available.

If WinSock2 is available then ntdll is available. That's how old it is.

Like I said, if it's a prerequisite to change this to the less efficient method to get this PR merged, then so be it. I'll do it. But it's not the "standard method". The standard method is to link with a required dll at link time.

@vszakats

vszakats commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

Not in Microsoft compilers (just double-checked to confirm). And if MingW maintains any sort of compatibility with
Microsoft compilers on Windows, then not there either.

In MSVC that #pragma is the equivalent to the -lntdll linker option. Maybe Pelles C supports it, but others not so much. MinGW + LLVM says this: warning: unknown pragma ignored [-Wunknown-pragmas], GCC: warning: ignoring '#pragma comment ' [-Wunknown-pragmas].

UPDATE:

Like I said, if it's a prerequisite to change this to the less efficient method to get this PR merged, then so be it. I'll do it. But
it's not the "standard method". The standard method is to link with a required dll at link time.

I think we should first make sure that this version detection is necessary at all. Available MS documentation says that TLS 1.3 is enabled by default in Windows 2022. Is there any other source?

@wyattoday

wyattoday commented Sep 16, 2021 •

Copy link
Copy Markdown
Contributor Author

In MSVC that #pragma is the equivalent to the -lntdll linker option.

Yes, I know. I feel like we're talking past eachother. For MS compilers the #pragma is used for simplicity's sake. For non-MS compilers on Windows, I've already added the correct linker flag to the configure.

If you're saying I missed the flag in some other build system, then let me know and I'll fix it.

I think we should first make sure that this version detection is necessary at all.

For ALPN it's necessary. This already fixes that bug. See initial PR message. Yes, the previous incorrect version detection (that this PR fixes) happens in the real world. That's reason #_1 for this PR.

Regarding TLS 1.3, the MSDN docs are scant on the subject. Just that it's available in Windows Server 2022. There's no "IsFeatureTLS1_3Available" function / flag available. Just the appearance of the (working version of the) feature in Windows 10 build 20348 (a.k.a. Window Server 2022 and newer).

Unless Microsoft expands on this limited documentation between now and when we begin the PR for the TLS 1.3 support, we're going to use version detection (the build version in particular) to "detect" whether there's a working version of TLS 1.3 present in Schannel. That's reason #_2 for this PR (the foundation for the Schannel TLS 1.3 PR).

If MS adds (or, better yet, documents) a feature detection method / flag between now and when I make the PR, then reason #_2 for this PR doesn't exists. But reason #_1 still does (fixes ALPN detection).

@vszakats

vszakats commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

Yes, I know. I feel like we're talking past eachother. For MS compilers the #pragma is used for simplicity's sake. For non-MS
compilers on Windows, I've already added the correct linker flag to the configure.

What I'm saying is that this flag not only needs to be added to all the different build systems in the curl project itself (there is also CMake and Makefile.m32), it will have to be added to every apps' build systems that happen to link libcurl statically. So this effectively replaces the optional manifest with a new mandatory linker option in these cases.

For ALPN it's necessary.

This is a matter of opinion, but I feel it doesn't look like libcurl's job to fix (static libcurl + SChannel) dependent apps where a manifest was not added. If it was forgotten or left out on purpose, libcurl would behave unexpectedly compared to other components linked to the app, or compared to how it should behave with the manifest linked (or not linked). IOW if someone is leaving out the manifest it's not a libcurl problem, but a problem for all other code linked to that app. Working this around in libcurl alone will not fix that app. Not disputing that mistakes can be made here and manifests are a notorously weird system indeed, but it's been around for quite some time and for better or worse, everyone building Windows binaries need to live with them. There is also the option to use libcurl DLL which has its own manifest and will behave accordingly. Another option is to use an alternate TLS-backend, which don't suffer from feature-detection woes as SChannel.

My other issue is fixing this by making direct kernel calls from userspace code.

If others feel this justified as a fix for this specific use-case, I'd strongly vote to implement this in a non-breaking and portable (across C compilers) way using a dynamic call and fallback to official/existing detection code as necessary. Also I think it'd be necessary to avoid adding compile-time WINVER and _WIN32_WINNT checks to make the binary output as unified as possible, regardless of compiler or SDK version.

@wyattoday

wyattoday commented Sep 16, 2021 •

Copy link
Copy Markdown
Contributor Author

There is also the option to use libcurl DLL which has its own manifest and will behave accordingly.

That's not how manifests work on Windows. See initial PR message.

For ALPN it's necessary.

This is a matter of opinion [...]

It's not though. It's a real bug that happens in real-life. You can shrug your shoulders and say it doesn't matter. But you shrugging your shoulders doesn't mean the problem doesn't exist.

Another option is to use an alternate TLS-backend, which don't suffer from feature-detection woes as SChannel.

Huh? Unless curl is dropping support for SChannel I don't see this as a relevant suggestion. This accurate version detection PR (or a variation of it) is a prerequisite for us doing the work to add Schannel TLS 1.3 support to curl.

Yes, software is hard. That's what we get paid for.

What I'm saying is that this flag not only needs to be added to all the different build systems in the curl project itself (there is also CMake and Makefile.m32),

I'll fix those today, thanks.

it will have to be added to every apps' build systems that happen to link libcurl statically.

No, that's not how it works. On Windows if you link the dll or static lib with another lib and the end-program will inherit those links. On Unix it's different... but we're not talking about unix.

@vszakats

vszakats commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

It's not though. It's a real bug that happens in real-life. You can shrug your shoulders and say it doesn't matter. But you
shrugging your shoulders doesn't mean the problem doesn't exist.

Do you need to be offensive? I'm not shrugging any shoulders and I understand the problem. Also spent probably too much time around manifests and Windows version detection. What I'm saying it's not the job of a single linked library to solve the Windows manifest problem. I also deem the problem not grave enough to merit breaking compatibility, all builds, and talking directly to the kernel. This is a matter of opinion. Nor can libcurl fully solve this for any app. This is a fact.

If the libcurl DLL manifest doesn't solve the problem for user apps (which can be and it's a valid point, though I'm also linking statically so never tried), it extends the scope of the use-case.

Huh? Unless curl is dropping support for SChannel I don't see this as a relevant suggestion. This accurate version detection > PR (or a variation of it) is a prerequisite for us doing the work to add Schannel TLS 1.3 support to curl.

It's an option, not a suggestion.

it will have to be added to every apps' build systems that happen to link libcurl statically.
No, that's not how it works. On Windows if you link the dll or static lib with another lib and the end-program will inherit those > links. On Unix it's different... but we're not talking about unix.

Did you try? Have you considered other C compilers besides MSVC?

There is no concept of inheriting static library requirements when using the toolchains I mentioned above. It's an MSVC-specific feature.

@wyattoday

wyattoday commented Sep 16, 2021 •

Copy link
Copy Markdown
Contributor Author

MingW (supposedly) supports Windows-style static libraries. Someone forgot to renew the mingw.org domain, so all the docs are off the web (currently riddled with ads).

Unix-style static libraries on Windows are a different matter. (But who links to unix-style static libraries on Windows and isn't building them for themselves anyway?)

So, yes, anyone on Windows, using pre-built unix-style static libraries of libcurl, will have to add the -lntdll option to compile their program with libcurl after this PR is merged.

What I'm saying it's not the job of a single linked library to solve the Windows manifest problem. I also deem the problem not grave enough to merit breaking compatibility, all builds, and talking directly to the kernel. This is a matter of opinion.

But "talking to the kernel" to see if it's an emulator or not (wine) is "grave" enough? I mean, like I said earlier, if the only way to get this PR merged is to do things in code that the linker already does just fine, then I'll do it.

Nor can libcurl fully solve this for any app. This is a fact.

Huh? This PR literally solves this problem. That's the point of it.

If you're talking about "problems" in the general sense then, again, curl works around all sorts of problems in every platform. Choose a source file at random and you'll find some sort of workaround for all manner of odd platform-specific-weirdness. Also, see my previous sentence about Wine. There's literally a workaround for an emulator of Windows for ALPN. And I'm fixing a bug for apps run in actual Windows for ALPN.

Anyway, this fixes a bug (again, ALPN, see first post), and sets the groundwork for us to work on SChannel TLS 1.3 support.

If the consensus is that this fix isn't wanted, then that's fine. The PR can be closed and I can move on. If the consensus is that everyone would prefer doing in code what the linker does (i.e. load ntdll at runtime in the curlx_verify_windows_version function), then I'll be glad to do it (I've said this across multiple posts already).

I'm also open to real criticism of code.

@vszakats

vszakats commented Sep 16, 2021 •

Copy link
Copy Markdown
Member

To be precise, this isn't fixing any bug in libcurl. The patch is trying to workaround an issue via libcurl that is originating outside of libcurl, whereas application developers linking in your product, which happens to use libcurl, will not work as expected because said applications forget to add a manifest. As per Microsoft, a manifest is pretty much a requirement for Windows executables. It is expected to be there for accurate version detection (and presumably to alter API behaviour in other subtle ways), not only for libcurl but for any other code that's meant to run on Vista and later.

It's difficult to read through the tone of voice that appeared in the last few messages by @wyattoday, so I'm out of here with a strong vote against the current implementation (static linking to the kernel, WINVER checks, breaking compatibility, deleting existing version detection code, "preemptive" fixing, and premature optimization). And a less-strong no to the notion of trying to workaround a missing manifest in libcurl; hearing others chiming in would help here.

@wyattoday

Copy link
Copy Markdown
Contributor Author

OK, I’ll file a bug tomorrow detailing the issue. I tried explaining it in the PR, but it could benefit from standing alone without the solution to the problem muddying the waters.

And I’ll fix the remaining CI error tomorrow.

@wyattoday

Copy link
Copy Markdown
Contributor Author

All of the compilation and style CI failures have been resolved. The failing tests looks like faulty tests (or faulty environment of the tests).

So, this is either ready to merge or ready for consensus on how everyone wants to move forward on this fix.

@lixinwei715

lixinwei715 commented Sep 29, 2021 •

Copy link
Copy Markdown
Contributor

I don't think this PR should merge.
All CMake compilation on Windows still failed, see https://ci.appveyor.com/project/curlorg/curl/builds/40939635.

VS2015(https://ci.appveyor.com/project/curlorg/curl/builds/40939635/job/9warhi8gagmnihce):

2>c:\projects\curl\lib\http_chunks.h(89) : error C2065: 'SIZEOF_CURL_OFF_T' : undeclared identifier
2>c:\projects\curl\lib\http_chunks.h(89) : error C2057: expected constant expression
2>c:\projects\curl\lib\http_chunks.h(89) : warning C4200: nonstandard extension used : zero-sized array in struct/union
2>C:\projects\curl\lib\urldata.h(915) : error C2229: struct 'connectdata' has an illegal zero-sized array

VS2019(https://ci.appveyor.com/project/curlorg/curl/builds/40939635/job/ktgviudh9u59n0ht):

C:\projects\curl\lib\nonblock.c(83,1): fatal error C1189: #error:  "no non-blocking method was found/used/set" 

I could reproduce these compilation error locally.

@mback2k

mback2k commented Oct 2, 2021 •

Copy link
Copy Markdown
Member

I still think this is going the wrong direction with statically/load-time linking ntdll.lib. What do you think @jay @vszakats @MarcelRaad ?

@MarcelRaad

MarcelRaad commented Oct 2, 2021 •

Copy link
Copy Markdown
Member

Doesn't linking ntdll.lib break compatibility with Windows 9x and Windows CE? I've only ever used LoadLibrary for DLLs that are not required to be on the target system, so I don't know what happens when linking an import library without calling a function from it.

@wyattoday

wyattoday commented Oct 3, 2021 •

Copy link
Copy Markdown
Contributor Author

@MarcelRaad

Yes, but the pragma won’t be called for those platforms (thus won’t be included as a dependency) and the code-paths they’ll hit will be the Win9x code path (not the fixed NT code path).

@vszakats

vszakats commented Oct 3, 2021 •

Copy link
Copy Markdown
Member

@mback2k: AFAICS nothing has been addressed of the concerns raised:

  1. libcurl at the moment uses the official/canonical/documented way to check versions. Considering this a bug in need of a fix is a tall order. Also, addressing this in libcurl alone will leave all other libs, libcurl dependencies and other code to continue behaving the normal way.
  2. The patch intends to fix suspected future issues (despite official documentation stating that such issue are not to be expected), and issues with non-release Windows versions. I believe these should be addressed when there proof is they are required.
  3. The patch removes existing code and introduces build-time version checks which is a problem.
  4. Most importantly: The patch still wants to link statically against ntdll.dll, aka the kernel. Such dependency will be forced upon every single app that happen to link libcurl. Such behaviour for me is a no-go. It is also something rarely seen in user apps, a practice certainly not recommended by Microsoft and something rarely, if ever seen in libraries.

If it's agreed that it's libcurl's job to fix this Windows version checking issue, I believe a better course of action would be introduce a patch that adds a new internal libcurl function to check for the "real" Windows version, and do so in a way that uses GetModuleHandle(TEXT("ntdll")) to talk to the kernel. Then this function can be used in places where the official version detection method is not sufficient, without altering libcurl compatibility (with Windows versions, build systems, etc) in any way.

@wyattoday

wyattoday commented Oct 4, 2021 •

Copy link
Copy Markdown
Contributor Author

@vszakats

Just quickly since all of these were asked and answered above:

  1. [...] Considering this a bug in need of a fix is a tall order.

The bug is described here: #7742 . This also affects new features, like TLS 1.3 in SChannel.

  1. The patch intends to fix suspected future issues (despite official documentation stating that such issue are not to be expected), and issues with non-release Windows versions. I believe these should be addressed when there proof is they are required.

The ALPN bug has effected Windows 8.1 and newer users. Windows 2022 is out now (yes, it's still 2021, what can I say, MS has weird marketing 🤷‍♂️), with TLS 1.3 support, and Windows 11 "RTM" is also out for "insiders" (beta testers) and will be out for everyone tomorrow (approx 24 hours).

So... this fixes real issues right now. Both for existing features in curl, but also new features that people will want with curl (TLS 1.3, TCP Fast Open, etc., etc.).

The proof is there right now. I don't know why you keep bringing this up like this is an imaginary problem.

  1. The patch removes existing code and introduces build-time version checks which is a problem.

This path takes 2 code-paths used for version checking and combines it into 1 code path. Yes, this meant abandoning the other code-path. But it also meant there is 1 code-path that gets all the "eyeballs" (i.e. it will be run by all people on Windows rather than splitting the code into 2 camps).

Long story short: this is security-101 stuff. If you can avoid splitting your logic into 2 similar but different algorithms then you can potentially avoid nasty security bugs. It's all about risk reduction.

I don't know why this is controversial. I used the existing code-path and simply added the build number checking to it. Why the build number checking? Again, because it's required for TLS 1.3, TCP Fast Open, etc., etc..

  1. [...] The patch still wants to link statically against ntdll.dll

It's not static linking. It's dynamic linking. At link-time vs. at runtime. I said this above multiple times. If it's that you don't believe me, then I can send you some links on how static and dynamic linking work in Windows.

[...] It is also something rarely seen in user apps, a practice certainly not recommended by Microsoft and something rarely, if ever seen in libraries.

It's a user-mode kernel call. Meaning, it's meant to be called from user-mode apps.

Recommended by MS? It's in their documentation for 20+ years. And yes, I've seen similar behavior for different functionality in different libraries. This isn't behavior that's out of this world.

Also, things like the crypto-functions in Windows (that are already in curl) are thin layers over the user-mode kernel calls. There are other examples, but long story short: this is done. It's not as odd as you think it is (because, curl already does it).

@mback2k

mback2k commented Oct 4, 2021 •

Copy link
Copy Markdown
Member

It's not static linking. It's dynamic linking. At link-time vs. at runtime. I said this above multiple times. If it's that you don't believe me, then I can send you some links on how static and dynamic linking work in Windows.

You may refer to this link-time linking of a dynamic library as dynamic linking, but this still makes the executable depend on the existence of the library and the referenced function while LoadLibrary-type dynamic linking does not if handled with a fallback.

@wyattoday

Copy link
Copy Markdown
Contributor Author

@mback2k

[...] but this still makes the executable depend on the existence of the library and the referenced function [...]

Correct. And the code & build environments handle that. Namely, on Windows NT it loads the ntdll.dll (via link-time dynamic linking). On Windows 95/98/CE it doesn't.

Regarding the impact of this change, I've already addressed this above.

@mback2k

mback2k commented Oct 4, 2021

Copy link
Copy Markdown
Member

On Windows 95/98/CE it doesn't.

It doesn't and it fails with an error message. At least that is what happens on modern Windows. Did you test it on legacy Windows?

@wyattoday

wyattoday commented Oct 4, 2021 •

Copy link
Copy Markdown
Contributor Author

Nope. For unsupported and insecure versions of Windows I relied on the CI builds. It's too cost prohibitive to securely setup and air-gap an environment for versions of Windows that are vulnerable, actively exploited, and aren't actually used by real people in 2021.

Yes, real air-gapping is expensive. And because our company has no need for targeting old and unsupported OSes, we've spent the money more wisely elsewhere.

Which CI builds are targeting Windows 95/98/CE? Which CI builds are running on Windows 95/98/CE instances?

@mback2k

mback2k commented Oct 4, 2021 •

Copy link
Copy Markdown
Member

It seems like you are not getting the point. Probably nobody here is actually still using these legacy and - as you pointed out multiple times already - highly insecure versions of Windows anymore. Still we want to maintain compatibility for them if there is no real reason to break it by default. As stated before: build-time checks for Windows versions do not really make sense, as curl binaries are usually compiled on one version, but shared with others, including our official binaries. Why not just go the fully dynamic path as described before? The performance gain of avoiding it does not outweigh breaking compatibility in this case.

We don't have CIs for these old systems, but by the way: the msys1 based CI builds are still failing.

Also: there is the possibility of running these old Windows versions in VMs if needed for testing.

@vszakats

vszakats commented Oct 4, 2021 •

Copy link
Copy Markdown
Member

Dynamic linking, I stand corrected. It doesn't change the point though, this patch will directly bind a kernel level library (a DLL) with user app binaries. The undocumented API is not part of the Win32 API, and that DLL belongs to a layer below that. The API has been documented for kernel drivers, as part of the DDK/WDK. Promises/contract for kernel drivers is completely different than for user apps using the Win32 API.

I'd like to see official MS documentation that shows that kernel-level trickery is now required to enable TLS 1.3 with the most recent official Windows releases. Pointing to previously authored GitHub Issues/PRs are not enough to clear these questions. Calling "bugs" what is code implemented according to official Windows guidelines/documentation, will not make them bugs.

Suppose we want to solve these non-libcurl (ie. user apps built against libcurl where the Windows manifest was broken/forgotten) and/or potential future Windows issues in libcurl, I believe a non-intrusive patch is the better way to start moving into that direction. This patch touches too many parts in too many controversial ways to be considered for merge IMO. This also makes it very difficult to discuss it, because the premiss is unclear, the goals are unclear/multiple and it not only adds functionality, but at the same time removes existing ones and unnecessarily imposes new limitations 1 to libcurl and all libcurl dependents. Despite expressing these concerns multiple times by multiple persons, there have been no updates to this PR that would improve in these areas.

Footnotes

  1. Dropping/re-evaluating compatibility with older platforms may be a valid discusstion, but for another time when it isn't entangled with other modifications. ↩

@wyattoday

wyattoday commented Oct 4, 2021 •

Copy link
Copy Markdown
Contributor Author

@mback2k

Why not just go the fully dynamic path as described before? The performance gain of avoiding it does not outweigh breaking compatibility in this case.

I could argue that point, but won't. But, like I asked before: If I make that change will that get this PR merged and some progress towards getting TLS 1.3 support added? If so, I'll do it. Seriously.

If not, then I don't see the point in wasting my time coding-by-committee to get to a worse result that will be ultimately rejected.

but by the way: the msys1 based CI builds are still failing.

Tests unrelated to this change are failing. It looks to me to be a false-positive (i.e. error in the testing environment or error with the tests themselves).

Also: there is the possibility of running these old Windows versions in VMs if needed for testing.

Unfortunately not for us. It's an operational security risk to put a honey-pot-type system on a non-air-gapped machine (even if it's enclosed in a VM).

@vszakats

I'd like to see official MS documentation that shows that kernel-level trickery is now required to enable TLS 1.3 with the most recent official Windows releases.

Well... considering I developed the PR for TLS 1.3 support for SChannel on Windows, I'd disagree.

Or, more specifically, MS hasn't provided a "feature detection" method for the presence of SCH_CREDENTIALS support in SChannel.

I'd be happy to be proven wrong. But, since I went through every document Microsoft has published thus far on TLS 1.3 support in SChannel (including every random blog post by Microsoft engineers writing on the subject), I can tell you based on public information right now there are 2 ways to support TLS 1.3:

  1. Build specifically for Windows 10, 1809 and newer.
  2. Detect the version accurately at runtime.

If the way I've added TLS 1.3 support isn't done the "correct way", then please make a PR adding TLS 1.3 support the correct way. Or, even make comments on that PR showing the "correct way".

@jay

jay commented Oct 4, 2021

Copy link
Copy Markdown
Member

IMO I think we've reached an impasse on this, so I'm proposing #7810

jay added a commit to jay/curl that referenced this pull request Oct 4, 2021
- Use RtlVerifyVersionInfo instead of VerifyVersionInfo, when possible.

Later versions of Windows have normal version functions that compare and
return versions based on the way the application is manifested, instead
of the actual version of Windows the application is running on. We
prefer the actual version of Windows so we'll now call the Rtl variant
of version functions (RtlVerifyVersionInfo) which does a proper
comparison of the actual version.

Reported-by: Wyatt O'Day

Ref: curl#7727

Fixes curl#7742
Closes #xxxx
@vszakats

vszakats commented Oct 5, 2021

Copy link
Copy Markdown
Member

@wyattoday: I haven't mentioned any sort of "correct way" regarding TLS 1.3, so I find the snarky tone unnecessary. You keep referring to your own work as proof for how this should work. Self-referencing will not help getting to any original material that would explain what is going on around TLS 1.3. I have seen that PR, but it has this PR (and/or other version detection bits, compile-time even) mixed into it, which makes it difficult to see what it does exactly.

jay added a commit that referenced this pull request Oct 7, 2021
- Use RtlVerifyVersionInfo instead of VerifyVersionInfo, when possible.

Later versions of Windows have normal version functions that compare and
return versions based on the way the application is manifested, instead
of the actual version of Windows the application is running on. We
prefer the actual version of Windows so we'll now call the Rtl variant
of version functions (RtlVerifyVersionInfo) which does a proper
comparison of the actual version.

Reported-by: Wyatt O'Day

Ref: #7727

Fixes #7742
Closes #7810
@jay

jay commented Oct 7, 2021

Copy link
Copy Markdown
Member

IMO I think we've reached an impasse on this, so I'm proposing #7810

That PR just landed in 5044909 but there is no build number comparison so if you still need that please start a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

6 participants