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

internal/syscall/windows/registry: TestWalkFullRegistry failing on windows-amd64-longtest #35084

Closed
bradfitz opened this issue Oct 22, 2019 · 24 comments
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@bradfitz
Copy link
Contributor

The new windows-amd64-longtest is failing in:

ok  	image/png	0.222s
ok  	index/suffixarray	61.493s
ok  	internal/cpu	0.027s
ok  	internal/fmtsort	0.049s
ok  	internal/poll	1.098s
ok  	internal/reflectlite	0.066s
ok  	internal/singleflight	0.048s
ok  	internal/syscall/windows	0.112s
--- FAIL: TestWalkFullRegistry (9.46s)
    registry_test.go:554: DWORD value is not 4 bytes long
    registry_test.go:554: QWORD value is not 8 bytes long
    registry_test.go:554: QWORD value is not 8 bytes long
    registry_test.go:554: DWORD value is not 4 bytes long
    registry_test.go:554: QWORD value is not 8 bytes long
    registry_test.go:554: QWORD value is not 8 bytes long
    registry_test.go:569: value type 2097152 of DevLoader of LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}\Configuration\Reset\Driver failed: <nil>
FAIL
FAIL	internal/syscall/windows/registry	9.500s
ok  	internal/trace	1.580s
FAIL
2019/10/22 18:59:59 Failed: exit status 1

/cc @alexbrainman @zx2c4

@bradfitz bradfitz added Testing An issue that has been verified to require only test changes, not just a test failure. help wanted OS-Windows NeedsFix The path to resolution is known, but the work has not been done. labels Oct 22, 2019
@bradfitz bradfitz added this to the Go1.14 milestone Oct 22, 2019
@zx2c4
Copy link
Contributor

zx2c4 commented Oct 22, 2019

That's pretty weird.

registry_test.go:569: value type 2097152 of DevLoader of LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Class\{4d36e96c-e325-11ce-bfc1-08002be10318}\Configuration\Reset\Driver failed: <nil> implies that:

t.Fatalf("value type %d of %s of %s failed: %v", valtype, name, kname, err)

-->

_, valtype, err := k.GetValue(name, nil)

-->

err = syscall.RegQueryValueEx(syscall.Handle(k), pname, nil, &valtype, pbuf, &l)

I don't see anything in docs about RegQueryValueEx returning 0x200000.

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 22, 2019

Actually, no, it's not weird. That's just the type of those entries in the registry. New wild undocumented Windowsism? Investigating...

image

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 22, 2019

Looks like that's coming from C:\Windows\INF\c_media.inf:


[ClassInstall32.Configuration]
AddReg = ClassConfiguration_AddReg

[ClassConfiguration_AddReg]
...
HKR,Reset\Driver,DevLoader,%FLG_ADDREG_DELVAL%
...

[Strings]
...
FLG_ADDREG_DELVAL   = 0x00000004

That looks in theory fine, but I wonder if the INF loader isn't used to pulling integer flags out of the [Strings] section like that.

Either way, looks like a Windows bug.


Onto the remaining integer size mysteries.

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 22, 2019

It appears that indeed that registry key has the wrong sized value:

image

Looks like a Windows bug.

So the Go test is wrong, I guess.

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 22, 2019

@bradfitz What's the deal with the long tests? Are they something that nobody ever runs, hence you discovering this only now?

@bradfitz
Copy link
Contributor Author

@zx2c4, yup... https://golang.org/cl/202479 "dashboard: add windows and 32-bit longtest builders" for #26529

@gopherbot
Copy link

Change https://golang.org/cl/202678 mentions this issue: internal/syscall/windows/registry: fix strict assumptions in TestWalkFullRegistry

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 23, 2019

@bradfitz You wanted more detail over on the CL. Here's the root cause for the integer size bug:

image

They're writing an integer of size 8 as type REG_DWORD, which REG_DWORD requires an integer of size 4. The key is called "lParam", which means I bet this was originally of type LPARAM which is of type LONG_PTR which is the size of a pointer. So probably the original C code was something like:

RegSetValueExW(hKey, L"lParam", 0, REG_DWORD, (const BYTE *)&whatever->lParam, sizeof(whatever->lParam));

This worked fine in the 32-bit Windows days, and then broke when they recompiled that binary for 64-bit.

I only know how to report security bugs to MSRC, but not other bugs to whatever channels Microsoft has for those. If somebody wants to direct a Microsoft person toward this thread, maybe this can get fixed.

@bradfitz
Copy link
Contributor Author

@zx2c4, nice, thanks.

Maybe we can get away with a whitelist of known registry entries to skip, then?

I suspect the point of that test was just to exercise all the code paths by throwing a lot of mixed data at it.

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 23, 2019

@bradfitz Done. Not pretty, but it seems to be working, at least on my machine.

@gopherbot
Copy link

Change https://golang.org/cl/202897 mentions this issue: internal/syscall/windows/registry: blacklist certain registry keys in TestWalkFullRegistry

gopherbot pushed a commit that referenced this issue Oct 23, 2019
… TestWalkFullRegistry

It turns out that Windows has "legitimate" keys that have bogus type
values or bogus lengths that don't correspond with their type. On up to
date Windows 10 systems, this test always fails for this reason. These
keys exist because of bugs in Microsoft's code. This commit works around
the problem by simply blacklisting known instances. It also expands the
error message a bit so that we can make adjustments should the problem
ever happen again, and reformats the messages so that it makes copy and
pasting into the blacklist easier.

Updates #35084

Change-Id: I50322828c0eb0ccecbb62d6bf4f9c726fa0b3c27
Reviewed-on: https://go-review.googlesource.com/c/go/+/202897
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@alexbrainman
Copy link
Member

Here's the root cause for the integer size bug:

image

They're writing an integer of size 8 as type REG_DWORD, which REG_DWORD requires an integer of size 4. The key is called "lParam", which means I bet this was originally of type LPARAM which is of type LONG_PTR which is the size of a pointer. So probably the original C code was something like:

RegSetValueExW(hKey, L"lParam", 0, REG_DWORD, (const BYTE *)&whatever->lParam, sizeof(whatever->lParam));

This worked fine in the 32-bit Windows days, and then broke when they recompiled that binary for 64-bit.

I only know how to report security bugs to MSRC, but not other bugs to whatever channels Microsoft has for those. If somebody wants to direct a Microsoft person toward this thread, maybe this can get fixed.

@jstarks maybe you could report this bug at the right channel?

Thank you.

Alex

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 25, 2019

@jstarks maybe you could report this bug at the right channel?

Also the INF one too, above.

@jstarks
Copy link

jstarks commented Oct 25, 2019

Thanks for pointing this out; I can report these internally. But I think you'll have to keep your ignore list around, since it seems unlikely that we would backport fixes for these bugs.

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 25, 2019

Thanks for pointing this out; I can report these internally. But I think you'll have to keep your ignore list around, since it seems unlikely that we would backport fixes for these bugs.

I'm not quite sure what backport means at contemporary Microsoft. What constitutes a new version? Anniversary->Creators (the new "service pack")? Or 10->11?

@zlockard
Copy link

@zx2c4 These registry types under Class*\Configuration are correct and by design. INF files get compiled into registry state when they're added to the system. The INF is only ever read by the system one time if they're universal, as this one is - from then on, we only reference the registry state. This registry type indicates that it's actually a delete.

@zx2c4
Copy link
Contributor

zx2c4 commented Oct 25, 2019

@zlockard Indeed I saw it was FLG_ADDREG_DELVAL, but I assumed this would mean actually removing a key, rather than "adding an entry with an undocumented type that implies its absence". I assume you do this so that it's not re-added or something elsewhere? Either way, that's interesting to know. I'll update Go to account for this.

Do you have an REG_* constant name you'd prefer for the 0x200000 type?

@zlockard
Copy link

These keys get processed every time a media device gets installed (they're part of the device installation state), so we can't just delete them when we read the INF - we have to cache the intent. This logic is internal and there are more types than just this one, so don't fish this type out. For any non-standard types, you should interpret it as REG_BINARY.

@bcmills
Copy link
Contributor

bcmills commented Oct 26, 2019

Not pretty, but it seems to be working, at least on my machine.

Still failing on the windows-amd64-longtest builder, though (https://build.golang.org/log/89540253578b09ad7362d7748e00c08b9c2d5dd5):

--- FAIL: TestWalkFullRegistry (4.21s)
    registry_test.go:573: value type 1048576 of MODES of LOCAL_MACHINE\DRIVERS\DriverDatabase\DriverPackages\monitor.inf_amd64_c50c5fb00e368b98\Configurations\NonPnPMonitor.Install\Driver failed: <nil>
FAIL
FAIL	golang.org/x/sys/windows/registry	4.251s

@bcmills bcmills reopened this Oct 26, 2019
@gopherbot
Copy link

Change https://golang.org/cl/203604 mentions this issue: internal/syscall/windows/registry: remove TestWalkFullRegistry due to false assumptions

@gopherbot
Copy link

Change https://golang.org/cl/203605 mentions this issue: windows/registry: remove TestWalkFullRegistry due to false assumptions

gopherbot pushed a commit to golang/sys that referenced this issue Oct 27, 2019
This test's existence was predicated upon assumptions about the full
range of known data types and known data into those types. However,
we've learned from Microsoft that there are several undocumented secret
registry types that are in use by various parts of Windows, and we've
learned from inspection that many Microsoft uses of registry types don't
strictly adhere to the recommended value size. It's therefore foolhardy
to make any assumptions about what goes in and out of the registry, and
so this test is meaningless and error-prone.

Updates golang/go#35084

Change-Id: Ie545229afd8dc5bde90fffa0f735f7102cd4a6eb
Reviewed-on: https://go-review.googlesource.com/c/sys/+/203605
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
@dmitshur
Copy link
Contributor

dmitshur commented Mar 12, 2020

@gopherbot, please backport to Go 1.13. This is a test fix. It is needed to resolve a failure on windows-amd64-longtest builder, which could be masking other problems and making releasing Go 1.13.x more difficult.

@gopherbot
Copy link

Backport issue(s) opened: #37826 (for 1.13).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@gopherbot
Copy link

Change https://golang.org/cl/223237 mentions this issue: [release-branch.go1.13] internal/syscall/windows/registry: remove TestWalkFullRegistry due to false assumptions

gopherbot pushed a commit that referenced this issue Mar 12, 2020
…tWalkFullRegistry due to false assumptions

This test's existence was predicated upon assumptions about the full
range of known data types and known data into those types. However,
we've learned from Microsoft that there are several undocumented secret
registry types that are in use by various parts of Windows, and we've
learned from inspection that many Microsoft uses of registry types don't
strictly adhere to the recommended value size. It's therefore foolhardy
to make any assumptions about what goes in and out of the registry, and
so this test, as well as its "blacklist", are meaningless.

For #35084.
Fixes #37826.

Change-Id: I6c3fe5fb0e740e88858321b3b042c0ff1a23284e
Reviewed-on: https://go-review.googlesource.com/c/go/+/203604
Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
(cherry picked from commit 0d3092f)
Reviewed-on: https://go-review.googlesource.com/c/go/+/223237
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Alexander Rakoczy <alex@golang.org>
@golang golang locked and limited conversation to collaborators Mar 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done. OS-Windows Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

8 participants