changing the GDT and LDT entries

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
yaami
Posts: 4
Joined: Sat Jan 08, 2011 4:17 pm

changing the GDT and LDT entries

Post by yaami »

Hi all,

Assuming that the operating system is running in the protected mode, is it possible for the user applications to change the values of the entries in the GDT and LDT. or they just read only for user applications. If we want to change them from the user-land (say), can we use any system call (linux or windows) to change.

Does the operating system put value 3 in the CPL and RPL entries in the segment selectors by default, so that the programs run in the ring 3. And is it possible to change these values.

Thanks.
Tosi
Member
Member
Posts: 255
Joined: Tue Jun 15, 2010 9:27 am
Location: Flyover State, United States
Contact:

Re: changing the GDT and LDT entries

Post by Tosi »

This topic is in the wrong forum (it should be OS development or general programming) but I will give an answer.

The short answer: What do you think? Do you think designers of these operating systems, both of which were created by large teams of experienced programmers, would seriously overlook such a grave mistake?

The long answer:
I have tried writing the GDT and IDT under Windows XP (x32). The program crashed with a GPF. No room for argument. When reading the GDT, I found out that one of the data segment regs (it was fs or gs) was different than the ds, es, and fs.

On Linux, if you are root, I think you can request the kernel to give you access to those kind of things. I know you can do it with ports, I wrote a program which messed with timers and DMA once. I ended up crashing the entire PC.

So if you're looking to be a 1337 h4x0r and rewrite system registers, look again. You can't do it.
yaami
Posts: 4
Joined: Sat Jan 08, 2011 4:17 pm

Re: changing the GDT and LDT entries

Post by yaami »

Sorry for posting this in the wrong forum. How do I move it to a different forum.

So in-short we cannot change these stuff from user-land. And regarding my other question does the OS put the user programs in ring-3 by using the value 3 in the RPL/CPL entries of the segment selectors. Is this how it puts the user programs in "user mode".

Thanks.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: changing the GDT and LDT entries

Post by Combuster »

I wonder what the reason is why you are asking us those questions that are answered by both the official processor manuals and the wiki? You don't need us for the answer.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
yaami
Posts: 4
Joined: Sat Jan 08, 2011 4:17 pm

Re: changing the GDT and LDT entries

Post by yaami »

Combuster wrote:I wonder what the reason is why you are asking us those questions that are answered by both the official processor manuals and the wiki? You don't need us for the answer.
I'm asking because I want to make sure that I understood the thing correctly. And regarding the point
OS put the user programs in ring-3 by using the value 3 in the RPL/CPL entries of the segment selectors
I could not find this thing put in words explicitly in the manual. I know that OS does put the user programs in ring-3 but how it does it was my question which I could not find the answer. Does it put, by default design, the value in the CPL/RPL. I thought I might get this answered in the forums. Though I do not want state this as an excuse for not knowing the answer or not understanding the manual, but still I'm not taking any courses and doing self study. So people out there are my teachers. Of course I do not expect you to teach me operating systems/computer architecture 101 course. But I had this doubt that I wanted to get clarified.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: changing the GDT and LDT entries

Post by Combuster »

I could not find this thing put in words explicitly in the manual
Intel 3A chapter 5 verse 5 wrote:Current privilege level (CPL) — The CPL is the privilege level of the currently
executing program or task. It is stored in bits 0 and 1 of the CS and SS segment
registers.
Better excuse wanted.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
yaami
Posts: 4
Joined: Sat Jan 08, 2011 4:17 pm

Re: changing the GDT and LDT entries

Post by yaami »

Pardon my lord Combustor, grave mistake committed.

I'm fired up now. I'll make a OS competing with MOS, and name it C-MOS, just kidding (no offense intended). But I'll try seriously to write one. I do not know why but this post got me motivated.

Thanks for the answer though. And thanks for your time to post a "verse" from the manual. I read that what I wanted to know was if OS does this. Anyway it is now clear.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: changing the GDT and LDT entries

Post by Owen »

Linux has APIs for creating an LDT and setting entries in it. Its used by, for example, WINE. One assumes that FreeBSD and other operating systems capable of running WINE have similar features.
Post Reply