OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 7:22 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How can I trigger a general protection fault in X86 Linux?
PostPosted: Tue Nov 20, 2018 11:28 pm 
Offline

Joined: Fri Nov 17, 2017 7:02 am
Posts: 20
I am triaging a bug in Unix-like OS, and i hit GP fault in that kernel, and system reset.
I don't know what should Linux do in this case, I want to have a try.

So, in X86 Linux, how can I trigger a GP fault?

Many thanks,
-Tao


Top
 Profile  
 
 Post subject: Re: How can I trigger a general protection fault in X86 Linu
PostPosted: Tue Nov 20, 2018 11:57 pm 
Offline

Joined: Sat Jun 09, 2018 11:51 am
Posts: 6
This should be sufficient

Code:
section .text
global _start
_start: lgdt [0x0]


FWIW, what it does for me when run is

Code:
$ ./file
Segmentation fault (core dumped)


and in the kernel log:

Code:
[10832.987652] traps: file[32233] general protection ip:8048060 sp:ffdcd2a0 error:0 in file[8048000+1000]


Basically, a "standard" UNIX-like OS should probably catch the GPF interrupt, decide that it happened because a userspace program is being naughty and not due to a kernel bug, and kill the offending process with as much/little logging as needed


Top
 Profile  
 
 Post subject: Re: How can I trigger a general protection fault in X86 Linu
PostPosted: Wed Nov 21, 2018 1:43 am 
Offline

Joined: Fri Nov 17, 2017 7:02 am
Posts: 20
By reading the Wiki for general protection, i can trigger the GP fault in Linux by setting a reserved bit in CR4.
The kernel will panic, then reboot.

Thanks,
-Tao


Top
 Profile  
 
 Post subject: Re: How can I trigger a general protection fault in X86 Linu
PostPosted: Wed Nov 28, 2018 2:26 am 
Offline
Member
Member
User avatar

Joined: Wed Aug 08, 2012 6:39 am
Posts: 42
Location: New York, NY
Are you setting that bit in a kernel module or are you doing that in userspace? If the latter, that's a serious security issue.

_________________
Cheers,

Lev


Top
 Profile  
 
 Post subject: Re: How can I trigger a general protection fault in X86 Linu
PostPosted: Wed Nov 28, 2018 8:52 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 27, 2006 9:42 am
Posts: 1925
Location: Athens, GA, USA
wangt13 wrote:
I am triaging a bug in Unix-like OS, and i hit GP fault in that kernel, and system reset.
I don't know what should Linux do in this case, I want to have a try.


Could you please give us more information about the cause of the problem? Under what circumstances does it happen, and what are trying to do to triage it (by which I assume you mean track it down so you can fix it, rather than trying to decide the priority with which it should be treated :-) )?

Also, why are you then trying to create an analogous situation in Linux? Are you certain that the specific cause of the fault can occur in Linux at all? Are you trying to find out how Linux handles it, so you can apply the same approach (which may or may not be a good idea, depending on the details of your own OS and how it differs from Linux)?

I have a sense that there might be an XY Problem in this post - that what you are asking for isn't necessarily what you need, and that you are presupposing the answer in a way that excludes a better one. If X is 'find and fix the fault in my OS', then asking for Y ('how do I replicate the error in a related but significantly different OS?') is shifting the problem in a way that may not really solve X.

_________________
Rev. First Speaker Schol-R-LEA;2 LCF ELF JAM POEE KoR KCO PPWMTF
Ordo OS Project
Lisp programmers tend to seem very odd to outsiders, just like anyone else who has had a religious experience they can't quite explain to others.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: akasei, Bing [Bot], Google [Bot] and 106 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group