New issue
Advanced search Search tips

Issue 844479 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 3
Type: Bug



Sign in to add a comment

rand_util_win.cc uses a deprecated MSDN method and doesn't work on brand new threads

Project Member Reported by gab@chromium.org, May 18 2018

Issue description

[8088:4640:0517/151649.162:FATAL:rand_util_win.cc(32)] Check failed: success.
Backtrace:
	base::debug::StackTrace::StackTrace [0x03330E10+32]
	base::debug::StackTrace::StackTrace [0x032F58CD+13]
	logging::LogMessage::~LogMessage [0x032982C3+83]
	base::RandBytes [0x0330135C+76]
	base::RandDouble [0x032DA000+32]
	base::internal::ServiceThread::Init [0x033626D2+114]
	base::Thread::ThreadMain [0x032E59D6+550]
	base::PlatformThread::GetCurrentThreadPriority [0x032C26E5+469]
	BaseThreadInitThunk [0x771D336A+18]
	RtlInitializeExceptionChain [0x777F92B2+99]
	RtlInitializeExceptionChain [0x777F9285+54]

Got this stack trace @ https://chromium-review.googlesource.com/c/chromium/src/+/1059459/8
when merely trying to invoke RandDouble() from a brand new thread.

I suspect it's because RtlGenRandom() is marked as deprecated on MSDN and said to require manually loading Advapi32.dll before using : https://msdn.microsoft.com/en-us/library/windows/desktop/aa387694(v=vs.85).aspx

Perhaps this happens to be okay on most threads but it isn't on a brand new threads (e.g. TaskScheduler's ServiceThread in my CL).

Also, curious : this buffer should be freed by SecureZeroMemory() according to docs but it isn't in rand_util_win.cc's impl. And rand_util_win.cc's comments refer to "Community Additions" comments on MSDN which I can't find.

All in all, I think this is due for a code update.

@dcheng as base and security owner

(in the meantime I'll just remove the random supplement added to my CL as it was just a nice-to-have)
 
Cc: jsc...@chromium.org
Pretty sure we should be marking this as WontFix (as far as rand goes) :)

That documentation is bad and jschuh@ can speak more to it. The upside is that RtlGenRandom() is part of the Windows FIPS security boundary, even in Win 10, so they literally cannot remove that method. Using CryptGenRandom is explicitly not desired (will load 3P DLLs, call into 3P DLLs, and adds a heavy amount of function indirection that, per the FIPS document, will just call RtlGenRandom). The Community Additions were the part where MSDN had wiki bits, and Microsoft officially documented that the MSDN part was out of date ;) Justin and I had the discussion about this in the way beyond (... 4 or 5 years ago) about formalizing the current impl.

The remark on SecureZeroMemory is also related to some of their FIPS stuff, and is not applicable.

RtlGenRandom is pretty never-fail, so the fact that the check is failing is a real issue worth investigating. It looks like it's related to sandboxed code, so perhaps there's something up there? Is it possible these threads are being spun up before the loader has completed loading AdvApi32?

Comment 2 by jsc...@chromium.org, May 18 2018

Status: WontFix (was: Assigned)
I concur with the rsleevi@ on all counts... but I'm replying mostly because I wanted to point out that the documentation recommends using CryptGenRandom(), which is also deprecated. Turtles... 😜

(I should also mention that loading CAPI or CNG will almost certainly break win32k lockdown, which is all manner of catastrophically bad.)
Sounds good. gab@, it does sound like there's a real initialization issue with your patchset though, as that function should never fail (from both windbg and the FIPS security policy, it's pretty much doing unexciting things).

So we should try to figure out why you're running into failures, as we want to make sure it's not sandboxing related and not related to module initialization.

Comment 4 by gab@chromium.org, May 18 2018

Ok thanks for your input. Maybe it's possible this thread is spun up early enough to sometimes get ahead  of loading AdvApi32, but that'd be surprising to me as it's spun up during BrowserMainLoop::CreateThreads() which is early as far as initializing the browser is concerned but late as far as loading DLLs is concerned... No idea, but I also don't badly need rand there so I'll just drop it and move on..

Comment 5 by jsc...@chromium.org, May 18 2018

Yeah, I was definitely concurring with rsleevi@ on the point about it not failing. That's a critical function (the sandbox even warms it up), so something is very, very wrong if it's breaking.

Comment 6 by wfh@chromium.org, May 18 2018

yes I agree with what's already been said here, I don't think we can change this code to call anything other than RtlGenRandom (via the SystemFunction036 trick) without risking breaking other stuff that relies on this running without massive other dependencies.

I doubt this is sandbox related, but more related to just a race and advapi32.dll - perhaps it's worth writing a small test program to fire up a load of threads and call RtlGenRandom and see if you can get this to happen without sandbox.

Comment 7 by gab@chromium.org, May 23 2018

Here's a minimized repro : https://chromium-review.googlesource.com/c/chromium/src/+/1066458

I couldn't repro the flakes locally.

Comment 8 by jsc...@chromium.org, May 23 2018

I'm genuinely curious what happens if we were to retry RtlGenRandom  on failure. 🤔

Comment 9 by wfh@chromium.org, May 24 2018

Cc: dcheng@chromium.org
Owner: gab@chromium.org
Status: Assigned (was: WontFix)
how about trying adding an explicit load of advapi32.dll early in process startup, to check if this is a load race or not?

Setting bug status so I see updates :)

Comment 10 by gab@chromium.org, May 24 2018

Cc: gab@chromium.org
Owner: wfh@chromium.org
Hey Will, you're welcome to give this a shot, here's a minimized repro : https://chromium-review.googlesource.com/c/chromium/src/+/1066458.

I will not be able to spend more time on this unfortunately as using rand in this code is not necessary at all and I'm already spread thin.
Components: -Internals

Sign in to add a comment