try to change cs register to point to kernel segment

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

try to change cs register to point to kernel segment

Post by ITchimp »

I was trying some weird things to understand the behavior of linux(32 bit)..

one of them is to manually assign the cs register to the kernel segment, of course
that gets me a segmentation fault termination... just curious what is the flow of events that
lead all the way to segmentation fault....why syscall and int 0x80 are only possible ways to enter
kernel mode???
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: try to change cs register to point to kernel segment

Post by iansjack »

You might want to read the Intel Programmer's Manuals.
sunnysideup
Member
Member
Posts: 106
Joined: Sat Feb 08, 2020 11:11 am
Libera.chat IRC: sunnysideup

Re: try to change cs register to point to kernel segment

Post by sunnysideup »

Yes.. There are only a handful of ways to enter switch modes. Try reading about call gates, interrupt gates task gates, trap gates, etc.
thewrongchristian
Member
Member
Posts: 426
Joined: Tue Apr 03, 2018 2:44 am

Re: try to change cs register to point to kernel segment

Post by thewrongchristian »

ITchimp wrote:I was trying some weird things to understand the behavior of linux(32 bit)..

one of them is to manually assign the cs register to the kernel segment, of course
that gets me a segmentation fault termination... just curious what is the flow of events that
lead all the way to segmentation fault....
The segmentation fault will have started with (I think) General Protection Fault as a result of trying to use a privileged segment in user mode.

Once linux gets control in the GPF handler, it'll post a SIGSEGV signal to the process. Now, SIGSEGV can be caught, and if so, when the returning from the GPF handler, linux will arrange for the SIGSEGV handler to be invoked in the user process. This is how some programs capture errors like this and produce crash reports rather than just dumping core.

Of course, the default action for SIGSEGV is to terminate with a core dump (if core dumps are enabled).
ITchimp wrote: why syscall and int 0x80 are only possible ways to enter
kernel mode???
It's the basic protection mechanism. By entering through a known door, the OS can frisk you to ensure what you're doing is safe.
Post Reply