L. Spiro
2007-10-16 04:29:03 UTC
Hello.
I have written a driver routine that changes its thread context to make a
quick read of RAM from another process.
As the topic here suggests, it uses KeStackAttachProcess(), performs the
quick read, and leaves with KeUnstackDetachProcess().
It is generally stable—I am not trying to read kernel RAM or anything
dangerous so I don’t get any blue screens, but if the target process closes
while my thread is over there my application deadlocks so hard it can not be
closed by any means but a reboot.
Is there any sure way to prevent this?
I tried using CLI and STI but then I get blue screens whining about
privilege levels. I use KeLowerIrql( DISPATCH_LEVEL ) but I get the same
error anyway (I thought DISPATCH_LEVEL could always use CLI?).
I think I could reduce the chances of this deadlock (currently at 94%—if the
target closes, my application WILL deadlock) using
PsGetProcessExitProcessCalled() and then aborting if TRUE, but then I think
this is only reduces the chances, not eliminates them. What if the process
is closed after I call that function but before I go into it with
KeStackAttachProcess()?
Is there any way to get a brief lock that absolutely ensures the process
cannot close while I am there?
Thank you.
P. S.: I call ObReferenceObjectByHandle() before going into the target
process. This is supposed to raise the reference count on the process so it
can’t fully close, which should have been preventing my problem.
Am I being mislead?
I have written a driver routine that changes its thread context to make a
quick read of RAM from another process.
As the topic here suggests, it uses KeStackAttachProcess(), performs the
quick read, and leaves with KeUnstackDetachProcess().
It is generally stable—I am not trying to read kernel RAM or anything
dangerous so I don’t get any blue screens, but if the target process closes
while my thread is over there my application deadlocks so hard it can not be
closed by any means but a reboot.
Is there any sure way to prevent this?
I tried using CLI and STI but then I get blue screens whining about
privilege levels. I use KeLowerIrql( DISPATCH_LEVEL ) but I get the same
error anyway (I thought DISPATCH_LEVEL could always use CLI?).
I think I could reduce the chances of this deadlock (currently at 94%—if the
target closes, my application WILL deadlock) using
PsGetProcessExitProcessCalled() and then aborting if TRUE, but then I think
this is only reduces the chances, not eliminates them. What if the process
is closed after I call that function but before I go into it with
KeStackAttachProcess()?
Is there any way to get a brief lock that absolutely ensures the process
cannot close while I am there?
Thank you.
P. S.: I call ObReferenceObjectByHandle() before going into the target
process. This is supposed to raise the reference count on the process so it
can’t fully close, which should have been preventing my problem.
Am I being mislead?