Commit graph

24 commits

Author SHA1 Message Date
Hervé Poussineau 916f69a7cb Fix a missing referencing in PsImpersonateClient (dereferenced in PsRevertThreadToSelf)
PspWriteTebImpersonationInfo may be used to set or to clear impersonation info => remove an extra assignment

svn path=/trunk/; revision=23715
2006-08-26 08:46:18 +00:00
Alex Ionescu 22917c0ebe - Properly disable impersonation in PsDisableImpersonation if it was previously enabled, instead of not disabling it. (fix a wrong check). Thanks to Arty.
svn path=/trunk/; revision=23588
2006-08-16 03:17:21 +00:00
Alex Ionescu 9b5a87cdac - Fix trace macro to print line number in decimal, not hex.
- Implement PspSetCrossThreadFlag and PspClearCrossThreadFlag and use them. Thanks to Thomas for the idea.
- Fix a bug in Fast Referencing, thanks to Thomas.

svn path=/trunk/; revision=23260
2006-07-23 21:38:31 +00:00
Magnus Olsen 6cf55b644f Patch from w3seek
svn path=/trunk/; revision=23253
2006-07-23 19:14:19 +00:00
Alex Ionescu a92eec4397 - SeAccessCheck should assume failure if no SD was passed. Also fixes bugcheck on startup since processes don't currently have SDs.
svn path=/trunk/; revision=23235
2006-07-23 07:24:20 +00:00
Alex Ionescu a818a86bf9 - Fixup PSTRACE to print much nicer output and actually work.
- Add tracing for security.c and kill.c.

svn path=/trunk/; revision=23234
2006-07-23 07:13:19 +00:00
Alex Ionescu 90ea51a96b - ImperstionationLocale -> ImpersonationLocale.
- Implement PspWriteTebImpersonationInfo for setting the impersonation locale and impersonation status in the TEB (since User-mode needs to read this value and we don't want to NtQueryInformationThread for it each time to read the ETHERAD flag).
- Complete the implementation of PspSetPrimaryToken to recalculate a process's access rights to itself based on a new primary token.
- Reorganize ps.h header like ob.h and io.h, implement Tracing support but not the tracing itself yet.
- Get rid of some deprecated cruft.

svn path=/trunk/; revision=23233
2006-07-23 05:43:28 +00:00
Alex Ionescu 59c6a927a2 - CT_ACTIVE_IMPERSTIONATION_INFO_BIT -> CT_ACTIVE_IMPERSONATION_INFO_BIT
- Added Process and Thread locking inlined functions for Ps Security functions.
- Thread safety is your friend! Huge rework of almost all the functions in ps/security.c to use the process/thread pushlocks and use interlocked operations when dealing with the ActiveImpersonationInfo thread flag.
- Added PAGED_CODE().
- Added checks for Processes with Jobs for the day that will happen.
- PsAssignImpersoonationToken with a NULL token handle means simply to revert to self.
- Don't ignore the HandleAttributes in NtOpenProcessTokenEx.
- Use SeTokenType to make sure the token passed is an impersonation token.
- Remove some fixed bugs in krnlfun.c, add more TODOs.

svn path=/trunk/; revision=23231
2006-07-22 22:57:42 +00:00
Alex Ionescu db04986dce - Give winlogon SE_ASSIGNPRIMARYTOKEN_PRIVILEGE because it was lacking it and would fail under this kernel patch.
- PspAssignPrimaryToken was good enough for actually *assigning* the token, but when NtSetInfoProcess is called with ProcessPrimaryToken, we want to do a lot more then just randomly assigning it. Added PspSetPrimaryToken which first verifies if the token being assigned is a child token and if not, checks for SeAssignPrimaryTokenPrivilege. Also added a fixme for more code that's needed, to actually re-calculate the process's granted access towards itself. Also added thread-safety.

svn path=/trunk/; revision=23226
2006-07-22 16:03:12 +00:00
Alex Ionescu 3d6bddb98f [AUDIT] security.c is mostly composed of trivial implementations of APIs that transfer one set of data from another, or simply wrap around complex Se* functions which do the actual work. There are one or two slightly more complex APIs (~15-20 lines), but they were written by Eric/Thomas, which are well-known for always writing clean code.
[FORMATTING] Re-formatted file properly, ordered functions and annotated them, added proper programmer credits, etc.
- Pushlocks need to be acquired in a -critical-, not -guarded- region.
- PsDisableImpersonation should return FALSE if it was already disbled.
- Don't forget to reference the token in PsReferenceEffectiveToken.
- PsImpersonateClient should still return success if it was given no token.
- PsImperstonateClient should de-reference the token if there is already active impersonation info.

svn path=/trunk/; revision=23152
2006-07-18 15:13:55 +00:00
Alex Ionescu d2e356eda6 - Implement Fast Referencing and fix EX_FAST_REF definition.
- Implement ObReferenceEx and ObDereferenceEx.
- Split off ObpDeferObjectCompletion. A new win2003/vista API requires direct acess to being able to defer deletes.
- Fix some bugs in Process Token management and make it all properly use Fast Referencing.
- When duplicating a token in a new process, don't de-reference it before it's even created, and also insert it.
- Change ExpChangeRundown macro to fix warnings in msvc.

svn path=/trunk/; revision=23013
2006-07-11 19:45:16 +00:00
Alex Ionescu f4539b7037 - Massive re-write of some parts of Ps, based on a patch I wrote almost a year ago and peer-reviewed with Thomas and Filip. Causes some shutdown regressions and process leaks (will fix). Needs more work. Changelog:
- Architectural changes to match information in Windows Internals 4 and other documented sources of information (Windows Internals II by Probert). Code should match Win2003 layout.
    - Handle almost any possible process/thread sub structure and add its cleanup code stubs, so that when we actually implement them, we won't forget to clean them up in the process code.
    - Add interlocked usage of process and thread flags in order to make everything more thread-safe.
    - Better handle cases where threads die instantly, race conditions, and other weird issues.
    - Better handle process termination and thread termination.
    - Implement NtCreateProcessEx and update PspCreateProcess/NtCreateProcess.
    - Improve cleanup of process object in PspProcessDelete.
    - Optimize some things like User Thread startup.
    - Add some extra asserts, paged_code checks and also user-mode security check.
    - Implement helper API PsGetNextProcessThread
    - Optimize thread reaper (thanks Filip)
    - Do proper referencing/dereferencing of thread/processes (thanks Thomas)
    - Document FIXMEs needed for Ps code to be up to standards and complete.

svn path=/trunk/; revision=22976
2006-07-09 18:54:13 +00:00
Alex Ionescu d2e5bfabe5 - Clone ObpCreateHandle to CmpCreateHandle. I am about to fix its implementation and since Cm* currently abuses Ob I feel it safer to give its own internal function.
- Make ObpCreateHandle internal to Ob as it should be. Change NtCreateProcessTokenEx to use ObOpenObjectByPointer, it has no business manually trying to create a handle. Same goes for ExpLoadInitialProcess.

svn path=/trunk/; revision=22264
2006-06-07 01:47:33 +00:00
Thomas Bluemel 656411d9b8 - support for kernel handles
- attach to owning process before accessing the handle table if necessary

svn path=/trunk/; revision=20038
2005-12-10 16:38:04 +00:00
Thomas Bluemel 0d70a37f3b - protect access to buffers in NtCreateThread and NtOpenThread
- fix incorrect usage of PSEH in NtCreateThread

svn path=/trunk/; revision=18859
2005-10-29 21:33:57 +00:00
Thomas Bluemel 5e348c00c1 - use inlined probing macros for basic types
- minor optimizations by comparing the processor mode against KernelMode (==0) instead of UserMode (==1)

svn path=/trunk/; revision=17467
2005-08-21 19:04:23 +00:00
Thomas Bluemel 10cd89fb4e - use inlined probing macros for basic types
- documented dozens of vulnerabilities in NtOpenThread, NtCreateThread and NtOpenProcess (owner may fix them)

svn path=/trunk/; revision=17462
2005-08-21 15:38:47 +00:00
Filip Navara 52f8761d3a Use W32API for NTOSKRNL.
svn path=/trunk/; revision=16053
2005-06-18 18:32:29 +00:00
Alex Ionescu 036efb7e10 Removed incorrect Create/DuplicationNotify callbacks and replaced by a more correct Open callback which is what a windows driver would get. This is needed because of some changes I'm trying to make to get Parse routines to work properly, so I had to add two hacks for now, they will be removed within 2-3 commits
svn path=/trunk/; revision=15293
2005-05-15 04:56:52 +00:00
Steven Edwards e4be245882 strip whitespace from end of lines
svn path=/trunk/; revision=15164
2005-05-09 01:38:29 +00:00
Alex Ionescu 8c4f9d3417 Update EPROCESS to latest version. Basic Fast Referencing Stubs to allow Token access. Needs to be implemented. Use ActiveProcessLinks instead of ros-specific list.
svn path=/trunk/; revision=15065
2005-05-06 22:54:40 +00:00
Alex Ionescu 7740536c18 Mini-merge from my local changes. Rewrite of Process Creation. Notable improvements:
- Subsystemization of Process Creation code. Memory code done by new Mm functions (not all used yet),
      Kernel code done by Ke*, etc.
    - Written to be compatible with the information in "Windows Internals".
    - Optimized and cleaned up.
    - ObInsertObject is now called at the end, fixing a plethora of wrong things that were covered with FIXMEs.
    - PEB is allocated with a Memory Area, and so will TEB soon, which allows 4KB allocation without 64KB gra
      nularity.
    - System DLL Mapping/Loading has been changed to be cached at system bootup, resulting in faster code.
    
Also changed Peb to report NT 5.0

NOTE: Messy, more to come soon. The full benefits of this patch won't be realized until the complete changes
      are in.

svn path=/trunk/; revision=14660
2005-04-18 00:42:31 +00:00
Thomas Bluemel 71cda6ad2a only return the token handle if creating it succeeded
svn path=/trunk/; revision=14316
2005-03-25 18:13:31 +00:00
Alex Ionescu eb54434d27 Thread/Process Termination/Repeaing Rewrite + Fixes
---------------------------------------------------

    - ps/cid.c: 
            * Moved CID Lookup functions here
            
    - ps/security.c: 
            * Moved all security related functions here. Makes other files neater and security functions
              easier to locate.
              
    - ps/thread.c: 
            * Moved most of the Thread Scheduling/Dispatching code that belongs in the Kernel to /ke and
              renamed functions from Ps to Ki.
            * Implemented PsIsSystemThread.
            * Removed Reaper Thread Init (now obsolete).
            * Renamed PiDeleteThread to PspDeleteThread.
            * Moved Thread State functions from tinfo.c to here.
            
    - ps/process.c:
            * Removed Query/Set Process functions and moved to ps/query.c
            * Renamed PiDeletePRocess to PspDeleteProcess
            * Removed obsoleted Process Termination functions, moved persistent one to kill.c
    
    - ps/create.c:
            * Moved the security APIs to security.c
            * Correctly implemented PsCreateSystemThread to actually create system threads.
        
            
    - ps/suspend.c
            * Rewrote Nt Executive functions to use Kernel functions.
            * Moved Ps* Routines into ke/kthread.c and fixed them. The implementation was wrong in
              some aspects, especially the issue of the APC looping around the KeWaitXxx call and the
              fact that the routines excluded/ignored the FreezeCount.
            
    - ps/debug.c
            * Fixed completely broken implementation of Get/SetThreadContext. The old version crashed
              when called and did not work at all. Suspend Regression test now works.
            * Moved Context<->TrapFrame functions to ke/i386/
            * Combined Set/GetThreadContext APCs into a single one, and used special context structure.
            
    - ps/query.c:
            * Moved Thread/Process Query/Set Routines here.
            
    - ps/tinfo.c:
            * Removed.
            
    - ps/kill.c
            * Removed complicated Process Termination semantics and useless Attach/Detach in favor for
              a much more lightweight function which performs the same tasks as before and actually works.
              TaskManager can now terminate foreign processes.
            * Rewrote Thread Reaping to use the HyperCritical Work Queue instead of manually controlled
              thread. This results in much less code as well as an increase in speed and less micro
              management. The reaper is PspReapRoutine. Closing CMD.EXE now works properly without
              requiring masks that were added as hacks to allow it.
            * Renamed PiTerminateProcessThreads to PspTerminateProcessThreads. Fixed it to work with new
              termination code.
            * Added PspDeleteProcess to handle Process Object deletion. Kills the CID Handle here as done
              by Hartmut.
            * Added PspDeletethread here.
            * Renamed and rewrote PsTerminateCurrentThread to PspExitThread. Used NT Implementation out-
              lined in Windows Internals, Chapter 13. Uses less locks, a more concise order of actions,
              actually parses the Termination Ports, handles Dbgk notification. Timers are now rundown,
              and Mutex rundown is in a dedicated Kernel function. Final termination handled by KeTerminate
              Thread as documented.
            * Renamed PsTerminateOtherThread to PspTerminateThreadByPointer and modified implementation to
              be compatible with the changes above.
            * Renamed and regrouped Process Termination into PspExitProcess. Also implemented as described
              above, and moved each subsystem specific termination helper into its own subsytem.
            * Improved NtTerminateProcess and added more debugging messages.
            * Improved NtTerminateThread and added check against System Thread and made it compatible with
              new implementation.
            * Corrected PsTerminateSystemThread now that we support System Threads.
            * Corrected NtRegisterThreadTerminatePort to use same structure name as on windows for the 
              port, and added tag to pool allocation (documented in pooltag.txt)
    
    include/internal/*.h:
    
            * Defined Scheduler Functions and misc new functions or renamed functions.
            
    ke/apc.c:
    
            * Fixed critical bug where APCs were not delivered at all if the thread wastion and cancels any timers that are associated
              to a thread, as well as their APCs and DPCs.
      
    REGRESSIONS FOUND: NONE
    
    BUGS/REGRESSIOSN FIXED:
                * Thread/Get Set Context now works.
                * Suspend Regression test now works.
                * Task manager can now kill foreign processes, even hung ones (like it should).
                * ExitProcess/closing cmd.exe with the 'x' button now works correctly without hacks.
      KNOWN ISSUES: I left a bit of a mess in the headers and some stuff still needs to be moved into the right 
                  places. I just wanted to have this first part ready first, so that it won't get too big.

svn path=/trunk/; revision=14174
2005-03-18 05:53:04 +00:00