Re: kernel stack vs. user stack

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Mulyadi,

this is a really good peace of information. I didn't understand everything
you wrote yet, but I'm on it!

Could you explain me, what exactly a stack segment is? Is it a memory range,
where the stack data (I mean, something, that I push on the stack) is saved?


best regards, 
Paul

> --- Ursprüngliche Nachricht ---
> Von: Mulyadi Santosa <mulyadi.santosa@xxxxxxxxx>
> An: Paul Duplys <kernel_newbie@xxxxxx>
> Kopie: kernelnewbies@xxxxxxxxxxxx
> Betreff: Re: kernel stack vs. user stack
> Datum: Wed, 10 Aug 2005 11:24:18 +0700
> 
> Hello....
> 
> > For security and general sanity of the system, kernel and user code
> > can't use the same stack. So each process has to have 2 stacks -- one
> > is in kernel memory, used by kernel code, and one is in user memory,
> > used by the user code.
> 
> it is important to note that kernel stack is located on memory area with 
> privilege level 0, so it can only be accessed by code which has 
> privilege level 0 too. Conversely, user stack has privilege level 3, so 
> technically it can be accessed by user mode and kernel mode. This 
> memory area's privilege is defined by the related segment descritp
> 
> During the switch between user and kernel mode (e.g by issuing system 
> call), Stack Segment selector (SS) is also updated to point on related 
> segment descriptor. IIRC, on user mode, SS is equivalent to __USER_DS, 
> while on kernel mode, it is __KERNEL_DS. Both segment actually overlaps 
> (both starts on address 0 and ends at oxFFFFFFFF) , so something else 
> is needed  to protect these two segment.
> 
> If you read on Understanding Linux Kernel 2nd ed chapter 2, you will 
> realize that the protection is doubled by paging mechanism. Page frame 
> containing kernel stack has Supervisor flag set as 0. This means it can 
> only be accessed by kernel mode codes
> 
> Perhaps the final question is "how can I determine the code is in user 
> mode or kernel mode?" remember that Linux kernel operates in protected 
> mode, thus initially codes are referenced by logical address, composed 
> by segment selector and offset. Inside the segment selector, there is 
> an RPL (requestor privilege level) field (2 bit length) which defines 
> CPL  (current privilege level). Kernel codes always issue logical 
> address which has RPL=0, whereas user mode code has RPL=3. I guess it 
> is also the work of kernel itself which is doing switching between 
> segment selectors
> 
> hope it helps
> 
> regards
> 
> Mulyadi
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 

-- 
GMX DSL = Maximale Leistung zum minimalen Preis!
2000 MB nur 2,99, Flatrate ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux