Mark Russinovich’s technical blog covering topics such as Windows troubleshooting, technologies and security.
Microsoft Customer Support Services (CSS) is one of the biggest customers of the Sysinternals tools and they often send me interesting cases they’ve solved with them. This particular case is especially interesting because it affected a large number of users and the troubleshooting process made use of one of Process Monitor’s lesser-known features. The case opened when a customer contacted Microsoft support reporting that several of their users would occasionally get this error message when loggging on to their systems:
This caused Windows to create a temporary profile for the user’s logon session. A user profile consists of a directory, %UserProfile%, into which applications save user-specific configuration and data files, as well as a registry hive file stored in that directory, %UserProfile%\Ntuser.dat, that the Winlogon process loads when the user logs in. Applications store user settings in the registry hive by calling registry functions that refer to the HKEY_CURRENT_USER (HKCU) root key. The user’s loss of access to their profile made the problem critical, because whenever that happened, the user would apparently lose all their settings and access to files stored in their profile directory. In most cases, users contacted the company’s support desk, which would ask the user to try rebooting and logging in until the problem resolved itself.
As with all cases, Microsoft support began by asking about the system configuration, inventory of installed software, and about any recent changes the company had made to their systems. In this case, the fact that stood out was that all the systems on which the problem had occurred had recently been upgraded to a new version of Citrix Corporation's ICA client, a remote desktop application. Microsoft contacted Citrix support to see if they knew of any issues with the new client. They didn’t, but said they would investigate.
Unsure whether the ICA client upgrade was responsible for the profile problem, Microsoft support instructed the customer to enable profile logging, which you can do by configuring a registry key as per this Knowledge Base article: How to enable user environment debug logging in retail builds of Windows. The customer pushed a script out to their systems to make the required registry changes and shortly after got another call from a user with the profile problem. They grabbed a copy of the profile log off the system from %SystemRoot%\Debug\UserMode\Userenv.log and sent it into Microsoft. The log was inconclusive, but did provide an important clue: it indicated that the user’s profile had failed to load because of error 32, which is ERROR_SHARING_VIOLATION:
When a process opens a file, it specifies what kinds of sharing it allows for the file. If it is writing to the file it may allow other processes to read from the file, for example, but not to also write to the file. The sharing violation in the log file meant that another process had opened the user’s registry hive in a way that was incompatible with the way that the logon process wanted to open the file.
In the meantime, more customers around the world began contacting Microsoft and Citrix with the same issue, all had also deployed the new ICA client. Citrix support then reported that they suspected that the sharing violation might be caused by one of the ICA client’s processes, Ssonvr.exe. During installation, the ICA client registers a Network Provider DLL (Pnsson.dll) that the Windows Multiple Provider Notification Application (%SystemRoot%\System32\Mpnotify.exe) calls when the system boots. Mpnotify.exe is itself launched at logon by the Winlogon process.The Citrix notification DLL launches the Ssonvr.exe process asynchronous to the user’s logon:
The only problem with the theory was that Citrix developers insisted that the process did not attempt to load any user registry profile or even read any keys or values from one. Both Microsoft and Citrix were stumped.
Microsoft created a version of Winlogon and the kernel with additional diagnostic information and tried to reproduce the problem on lab systems configured identically to the client’s, but without success. The customer couldn’t even reproduce the problem with the modified Windows images, presumably because the images changed the timing of the system enough to avoid the problem. At this point a Microsoft support engineer suggested that the customer capture a trace of logon activity with Process Monitor.
There are a couple of ways to configure Process Monitor to record logon operations: one is to use Sysinternals PsExec to launch it in the session 0 so that it survives the logoff and subsequent logon and another is to use the boot logging feature to capture activity from early in the boot, including the logon. The engineer chose the latter, so he told the customer to run Process Monitor on one of the system’s that persistently exhibited the problem, select Enable Boot Logging from the Process Monitor Options menu, and reboot, repeating the steps until the problem reproduced. This procedure configures the Process Monitor driver to load early in the boot process and log activity to %SystemRoot%\Procmon.pmb. Once the user logged encountered the issue, they were to run Process Monitor again, at which point the driver would stop logging and Process Monitor would offer to convert the boot log into a standard Process Monitor log file.
After a couple of attempts the user captured a boot log file that they submitted to Microsoft. Microsoft support engineers scanned through the log and came across the sharing violation error when Winlogon tried to load the user’s registry hive:
It was obvious from operations immediately preceding the error that Ssonsvr.exe was the process that had the hive opened. The question was, why was Ssonsvr.exe opening the registry hive? To answer that question the engineers turned to Process Monitor’s stack trace functionality. Process Monitor captures a call stack for every operation, which represents the function call nesting responsible for the operation. By looking at a call stack you can often determine an operation’s root cause when it might not be obvious just from the process that executed it. For example, the stack shows you if a DLL loaded into the process executed the operation and, if you have symbols configured and the call originates in a Windows image or other image for which you have symbols, it will even show you the names of the responsible functions.
The stack for Ssonsvr.exe’s open of the Ntuser.dat file showed that Ssonsvr.exe wasn’t actually responsible for the operation, the Windows Logical Prefetcher was:
Introduced in Windows XP, the Logical Prefetcher is a kernel component that monitors the first ten seconds of a process launch, recording the directories and portions of files accessed by the process during that time to a file it stores in %SystemRoot%\Prefetch. So that multiple executables with the same name but in different directories get their own prefetch file, the Logical Prefetcher gives the file a name that’s a concatenation of the executable image name and the hash of the path in which the image is stored e.g. NOTEPAD.EXE-D8414F97.pf. You can actually see the files and directories the Logical Prefetcher saw an application reference the last time it launched by using the Sysinternals Strings utility to scan a prefetch file like this:
strings <prefetch file>
The next time the application launches, the Logical Prefetcher, executing in the context of the process’s first thread, looks for a prefetch file. If one exists, it opens each directory it lists to bring the directory’s metadata into memory if not already present. The Logical Prefetcher then maps each file listed in the prefetch file and references the portions accessed the last time the application ran so that they also get brought into memory. The Logical Prefetcher can speed up an application launch because it generates large, sequential I/Os instead of issuing small random accesses to file data as the application would typically do during startup.
The implication of the Logical Prefetcher in the profile problem only raised more questions, however. Why was it prefetching the user’s hive file in the context of Ssonsvr.exe when Ssonsvr.exe itself never accesses registry profiles? Microsoft support contacted the Logical Prefetcher’s development team for the answer. The developers first noted that the registry on Windows XP is read into memory using cached file I/O operations, which means that the Cache Manager’s read-ahead thread will proactively read portions of the hive. Since the read-ahead thread executes in the System process, and the Logical Prefetcher associates System process activity with the currently launching process, that a specific timing sequence of process launches and activity during the boot and log on could cause hive accesses to be seen by the Logical Prefetcher as being part of the Ssonsvr.exe launch. If the order was slightly different the next boot and log on, Winlogon might collide with the Logical Prefetcher, as seen in the captured boot log.
The Logical Prefetcher is supposed to execute transparently to other activity on a system, but its file references can lead to sharing violations like this on Windows XP systems (on server systems the Logical Prefetcher only prefetches boot activity, and it does so synchronously before the boot process proceeds). For that reason, on Windows Vista and Windows 7 systems, the Logical Prefetcher makes use of a file system minifilter driver, Fileinfo (%SystemRoot%\System32\Drivers\Fileinfo.sys), to watch for potential sharing violation collisions and prevent them by stalling a second open operation on a file being accessed by the Logical Prefetcher until the Logical Prefetcher closes the file.
Now that the problem was understood, Microsoft and Citrix brainstormed on workarounds customers could apply while Citrix worked on an update to the ICA Client that would prevent the sharing violation. One workaround was to disable application prefetching and another was to write a logoff script that deletes the Ssonsvr.exe prefetch files. Citrix published the workarounds in this Citrix Knowledge Base article and Microsoft in this Microsoft Knowledge Base article. The update to the ICA Client, which was made available a few days later, changed the network provider DLL to 10 seconds after Ssonsvr.exe launches before returning control to Mpnotify.exe. Because Winlogon waits for Mpnotify to exit before logging on a user, the Logical Prefetcher won’t associate Winlogon’s accesses of the user’s hive with Ssonsvr.exe’s startup.
As I said in the introduction, I find this case particularly interesting because it demonstrates a little known Process Monitor feature, boot logging, and the power of stack traces for root cause analysis, two key tools for everyone’s troubleshooting arsenal. It also shows how successful troubleshooting sometimes means coming up with a workaround when there’s no fix or you must wait until a vendor provides one. Another case successfully closed with Process Monitor! Please keep sending me screen shots and log files of the cases you solve.
>This is exactly the problem with the windows file sharing model: In an ideal world it should be possible for the prefethcer to open a file for reading in a way that never interferes with other processes. Today this is impossible because winlogon opens the file in a way that disallows any file sharing.
I think you're missing the point. It's up to the process that opens the file to decide what kinds of sharing it allows. If a process wants to allow other processes to read from a file it's got opened, it can do so. Presumably it will prevent concurrent access for a non-arbitrary reason. Winlogon choses to not allow other processes to read the raw contents of a hive that's loaded. It's taking advantage of the power of the sharing model to enforce it's wish.
If a process wants to read the raw contents of a hive it can save a copy with RegSaveKey or create a volume snapshot, which allows full access to the hive file with consistent contents for the snapshot's point in time.
>It's up to the process that opens the file to decide what kinds of sharing it allows. If a process wants to allow other processes to read from a file it's got opened, it can do so.
Yes, I know this.
My point is that in this case everything had been much simpler if the prefetcher could have used a NOLOCK option to open a file and read from it while being fully aware that the data might be inconsistent. In this case the prefetcher did not care at all about the content of the file.
But I fully understand that adding such a NOLOCK feature at this point in time is probably impossible - there are probably programs that open files exclusively and then writes confidential information to the files assuming that noone can read the information because the file is opened exclusively.
Interesting. Precisely I faced today several profile related errors when trying to coarce XP to use an existent folder to store the profile.
It was quite easy to test by deleting the three ntuser files and then logging in to have that user HKCU recreated. ntuser.dat and friend DO get created, but somehow the user wasn't allowed to write in the resulting hive. The registry permissions, instead of containing an entry for the user, had an entry for CREATOR OWNER, and the user wasn't able to write anything there (of course, the accounts weren't Administrators).
@stefang - Code reading from a file can tell Windows NOT to lock it at all, i.e. let other processes read from, write to, and even delete the file at will. That seems very much like a NOLOCK to me.
Hey:) i have been observing the forum lots of times - Thought I would say how much i enjoy visiting.
If everyone would give you a cent every time they used ProcessExplorer...
I get this message (or a similar one, didnt pay attention) sometimes when I start a PC but log on by using Remote Desktop Connection from another PC. Never bothered to investigate, though, just restart, log on again and Windows loads my profile with my customized desktop and all.
No, the difference is that with the current windows sharing semantics, one program can prevent any other programs from accessing a file just by opening the file in excusive mode - denying all other processes the possibility to open the file even for reading.
If program A has a file opened exclusively, it is impossible for program B to open the file - it does not matter what sharing options program B specifies. Even worse, if program B has the file open, program A will be unable to open the file because it requires exclusive access. So it is currently not possible for a windows program to open a file in a way that is fully transparent to other programs.
With my suggested NOLOCK option, program B would be able to specify that it wanted to open the file even if other programs had the file open for exclusive access.
I'm facing this issue at the moment but I'm not using citrix - just rdp to a Windows2003 terminal server. I strongly suspect it's the Symantec Antivirus 10 client that is doing this due to the messages that uhpclean fires up.
I've upgraded to v11 of Symantec to see if this fixes it - if not, then I may be able to look at this information to try and get an idea of what is going on but I'm not sure how to fix it!
Oh - I meant to say that adding that user environment debug log didn't work for me.
Hey, I'm a programmer from way way back. HP1000 systems and HPs RTE OS. That ages me pretty good.
Anyway, to get around all this file locking nonsense, back than we also had a file system implementation similar to Windows, we just located the file by reading the dirctory
and accessed the data by reading the raw disc sectors through a supported OS EXEC call.
Thus avoiding the file system all together to get at what was needed around about ways.
Yhis must be possible in Windows as well. Rhus this NOLOCK issue can be solved with a little finguer work.
Pardon a comment from a retired old timer.
ok - for some reason my log is working now. For what it's worth - enabling the boot logging will eat up your disk space faster than a competitor at a hot dog eating competition. My C drive lost 10gb of space in about an hour. Unfortunately my problem happens sometime overnight after a reboot so it's impractical to use this log function :-(
I am running procmon based on the ntuser.dat file for my user so I will be able to at least see what programs access ntuser.dat
@Andy Helsby: of course, the amount of space consumed by boot logging depends on system activity, and duration of capture. I wonder if scheduling procmon to run with a scheduled task at some point may be an option - you could set the filter as desired, choose the option to Drop Filtered Events, and perhaps log to a backing file on a different drive... Pop into the Process Monitor forum at http://forum.sysinternals.com/forum_topics.asp?FID=19 for specific questions, etc.
Thanks Molotov - after 1hr20minutes of purely watching for activity on a specific users ntuser.dat the server crashed and rebooted :-(
I'll drop into the forum when i have some more info - thanks for the help and pointers.
Hullo i've been visiting the website for awhile Finally needed to say how much i treasure this place:)
Its a blog, not a book, stop picking on typos people.