<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic RPL, CPL and DPL question in Intel® ISA Extensions</title>
    <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102567#M6015</link>
    <description>&lt;P&gt;Good day.&lt;/P&gt;

&lt;P&gt;In Intel SDM vol. 3 / 5.6 "PRIVILEGE LEVEL CHECKING WHEN ACCESSING DATA SEGMENTS" we can read:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Before the processor loads a segment selector into&lt;BR /&gt;
	a segment register, it performs a privilege check (see Figure 5-4) by comparing the privilege levels of the currently&lt;BR /&gt;
	running program or task (the CPL), the RPL of the segment selector, and the DPL of the segment’s segment&lt;BR /&gt;
	descriptor. The processor loads the segment selector into the segment register if the DPL is numerically greater&lt;BR /&gt;
	than or equal to both the CPL and the RPL. Otherwise, a general-protection fault is generated and the segment&lt;BR /&gt;
	register is not loaded.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;So, if we have a code which runs at level 3, we can't do&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;mov eax,28h ;points to descriptor with DPL=0&lt;/EM&gt;&lt;BR /&gt;
	&lt;EM&gt;mov DS,eax&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;because it would lead to #GP, as the CPL=3, RPL=0, DPL=0.&lt;/P&gt;

&lt;P&gt;But then in manual we found this:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;It is important to note that the RPL of a segment selector for a data segment is under software control. For&lt;BR /&gt;
	example, an application program running at a CPL of 3 can set the RPL for a data- segment selector to 0.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;How it is possible?&lt;BR /&gt;
	Or I misunderstand something?&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
    <pubDate>Tue, 09 May 2017 11:31:26 GMT</pubDate>
    <dc:creator>Victor_K_</dc:creator>
    <dc:date>2017-05-09T11:31:26Z</dc:date>
    <item>
      <title>RPL, CPL and DPL question</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102567#M6015</link>
      <description>&lt;P&gt;Good day.&lt;/P&gt;

&lt;P&gt;In Intel SDM vol. 3 / 5.6 "PRIVILEGE LEVEL CHECKING WHEN ACCESSING DATA SEGMENTS" we can read:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;Before the processor loads a segment selector into&lt;BR /&gt;
	a segment register, it performs a privilege check (see Figure 5-4) by comparing the privilege levels of the currently&lt;BR /&gt;
	running program or task (the CPL), the RPL of the segment selector, and the DPL of the segment’s segment&lt;BR /&gt;
	descriptor. The processor loads the segment selector into the segment register if the DPL is numerically greater&lt;BR /&gt;
	than or equal to both the CPL and the RPL. Otherwise, a general-protection fault is generated and the segment&lt;BR /&gt;
	register is not loaded.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;So, if we have a code which runs at level 3, we can't do&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;mov eax,28h ;points to descriptor with DPL=0&lt;/EM&gt;&lt;BR /&gt;
	&lt;EM&gt;mov DS,eax&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;because it would lead to #GP, as the CPL=3, RPL=0, DPL=0.&lt;/P&gt;

&lt;P&gt;But then in manual we found this:&lt;/P&gt;

&lt;P&gt;&lt;EM&gt;It is important to note that the RPL of a segment selector for a data segment is under software control. For&lt;BR /&gt;
	example, an application program running at a CPL of 3 can set the RPL for a data- segment selector to 0.&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;How it is possible?&lt;BR /&gt;
	Or I misunderstand something?&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 11:31:26 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102567#M6015</guid>
      <dc:creator>Victor_K_</dc:creator>
      <dc:date>2017-05-09T11:31:26Z</dc:date>
    </item>
    <item>
      <title>Seems I'm at wrong forum. Can</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102568#M6016</link>
      <description>&lt;P&gt;Seems I'm at wrong forum. Can somebody tell me, where I should ask about common CPU features? I mean, like this topic subject or stack operation clarification, common instruction set etc&lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 11:06:05 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102568#M6016</guid>
      <dc:creator>Victor_K_</dc:creator>
      <dc:date>2017-05-24T11:06:05Z</dc:date>
    </item>
    <item>
      <title>When an Intel CPU is in</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102569#M6017</link>
      <description>&lt;P&gt;When an Intel CPU is in protected mode it is done as follows:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;...
; Initialize all segment registers to 10h (entry #2 in the GDT)

&amp;nbsp;&amp;nbsp; mov&amp;nbsp;ax,10h&amp;nbsp;&amp;nbsp;&amp;nbsp;; entry #2 in GDT
&amp;nbsp;&amp;nbsp;&amp;nbsp;mov&amp;nbsp;ds,ax&amp;nbsp;&amp;nbsp;&amp;nbsp; ; ds = 10h
...
&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 17:15:44 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102569#M6017</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2017-06-02T17:15:44Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;Can somebody tell me, where</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102570#M6018</link>
      <description>&amp;gt;&amp;gt;Can somebody tell me, where I should ask about common CPU features?

Victor, this is the right place to ask questions about CPU features.</description>
      <pubDate>Fri, 02 Jun 2017 17:17:23 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102570#M6018</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2017-06-02T17:17:23Z</dc:date>
    </item>
    <item>
      <title>Thanks for the answer, Sergey</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102571#M6019</link>
      <description>&lt;P&gt;Thanks for the answer, Sergey!&lt;/P&gt;

&lt;P&gt;But how it is possible when entry #2 descriptor has &lt;STRONG&gt;DPL=0&lt;/STRONG&gt; and &lt;STRONG&gt;CPL=3&lt;/STRONG&gt;? It would lead to #GP, isn't it?&lt;/P&gt;

&lt;P&gt;I'm confused by words "&lt;EM&gt;the RPL of a segment selector for a data segment is under software control. For example, an application program running at a CPL of 3 can set the RPL for a data- segment selector to 0&lt;/EM&gt;".&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jun 2017 12:23:28 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102571#M6019</guid>
      <dc:creator>Victor_K_</dc:creator>
      <dc:date>2017-06-04T12:23:28Z</dc:date>
    </item>
    <item>
      <title>Quote:Victor K. wrote:</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102572#M6020</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Victor K. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Thanks for the answer, Sergey!&lt;/P&gt;

&lt;P&gt;But how it is possible when entry #2 descriptor has &lt;STRONG&gt;DPL=0&lt;/STRONG&gt; and &lt;STRONG&gt;CPL=3&lt;/STRONG&gt;? It would lead to #GP, isn't it?&lt;/P&gt;

&lt;P&gt;I'm confused by words "&lt;EM&gt;the RPL of a segment selector for a data segment is under software control. For example, an application program running at a CPL of 3 can set the RPL for a data- segment selector to 0&lt;/EM&gt;".&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;#GP is the valid and sometimes desired outcome. The later text in the SDM Vol. 3 section 5.6&amp;nbsp; you cited gives the useful hint as to why, see the paragraph about impersonalization right before the citation. More, after your citation, there is a note about 'dangers' of using RPL 0 by the privileged code and suggestion to use the ARPL instruction.&lt;/P&gt;

&lt;P&gt;RPL allows more privileged code to work with the far pointers supplied by the potentially untrusted code in safer way.&amp;nbsp; Imagine a code executing at say CPL 1 (server) which might take pointers from the code executing at CPL 1, 2, or 3 (client).&amp;nbsp; In these cases, you do not want for the client code with CPL 2 or 3 to somehow guess a valid DPL 1 selector index and pass it to the server.&amp;nbsp; Or rather, you want the server to not allow to trick itself into writing into the memory described by corresponding descriptor, you only want it to write a segment which is also accessible to the client.&lt;/P&gt;

&lt;P&gt;So what is supposed to happen, with the IA32 protection model, is that server sets RPL to the CPL of the client and then #GP catches invalid accesses at the moment the selectors are loaded into segment registers.All this happens automatically (#GP-&amp;gt;typical abort, or whatever proper reaction is), instead of using ARPL or other explicit methods.&lt;/P&gt;

&lt;P&gt;Of course, nobody uses the mechanism now, but this is how it was designed to be used.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Jun 2017 19:14:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102572#M6020</guid>
      <dc:creator>Konstantin_B_</dc:creator>
      <dc:date>2017-06-05T19:14:38Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;...But how it is possible</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102573#M6021</link>
      <description>&amp;gt;&amp;gt;...But how it is possible when entry #2 descriptor has DPL=0 and CPL=3? It would lead to #GP, isn't it?

Victor, In case of DPL=0 and CPL=3 did you try to do it using PUSH and POP instructions?

An example in &lt;STRONG&gt;Post #3&lt;/STRONG&gt; is from a real piece of codes. It does &lt;STRONG&gt;DS&lt;/STRONG&gt; register initialization after a &lt;STRONG&gt;CPU&lt;/STRONG&gt; is switched to protected mode and a privilege level is &lt;STRONG&gt;0&lt;/STRONG&gt;.</description>
      <pubDate>Tue, 06 Jun 2017 17:12:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102573#M6021</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2017-06-06T17:12:47Z</dc:date>
    </item>
    <item>
      <title>Sergey, I know my english is</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102574#M6022</link>
      <description>&lt;P&gt;Sergey, I know my english is terrible. But what relation with push/pop instructions at all? Segment register's loading mechanism is same for "pop Sreg" and "mov Sreg,smth" instructions. My question is about ambiguos manual statements.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;2Konstantin&lt;/STRONG&gt;&lt;BR /&gt;
	My respect for fullfill answer. Please, correct me if I'm wrong:&lt;/P&gt;

&lt;P&gt;- words "&lt;EM&gt;is under software control" &lt;/EM&gt;means "client" can pass (by stack, common register or any other way, but not in the segment register) selector to the "server" with any RPL&lt;BR /&gt;
	- "client" can't succesfully execute (assume CPL=3, selector 10h points to descriptor with DPL=0)&lt;BR /&gt;
	mov ax,10h&lt;BR /&gt;
	mov DS,ax&lt;BR /&gt;
	because it would lead to #GP.&lt;/P&gt;

&lt;P&gt;To be more specific: for me "&lt;EM&gt;RPL is under software control" &lt;/EM&gt;means I can freely manipulate RPL when loading the &lt;STRONG&gt;segment register&lt;/STRONG&gt;. When I pass selector to the "server" by stack, it is not a segment register. It's just piece of data with any meaning. In this sense, we could say "selector index is under software control". It could be null, it could be out of GDT/LDT limit, it could be anyting.&lt;/P&gt;

&lt;P&gt;And related question: does CPU performs CPL/RPL/DPL checks only at selector loading stage, or does also at stage of memory access?&lt;BR /&gt;
	For example, assume CPL=3, DS is already loaded (by someone with CPL=0) with descriptor's selector with DPL=0. Would "mov eax,[eax]" lead to #GP?&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jun 2017 18:32:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102574#M6022</guid>
      <dc:creator>Victor_K_</dc:creator>
      <dc:date>2017-06-06T18:32:00Z</dc:date>
    </item>
    <item>
      <title>Quote:Victor K. wrote:</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102575#M6023</link>
      <description>&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Victor K. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Please, correct me if I'm wrong:&lt;/P&gt;

&lt;P&gt;- words "&lt;EM&gt;is under software control" &lt;/EM&gt;means "client" can pass (by stack, common register or any other way, but not in the segment register) selector to the "server" with any RPL&lt;BR /&gt;
	- "client" can't succesfully execute (assume CPL=3, selector 10h points to descriptor with DPL=0)&lt;BR /&gt;
	mov ax,10h&lt;BR /&gt;
	mov DS,ax&lt;BR /&gt;
	because it would lead to #GP.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Yes, client cannot perform such load, but this is not the point I tried to make.&amp;nbsp; It is more interesting what happens at the server side, i.e. when a code&amp;nbsp; executing at the privilege higher than the client privilege, operates on the clent-provided pointers.&lt;/P&gt;

&lt;P&gt;RPL is under software control in the sense that software can arbitrary modify the RPL value at wish.&amp;nbsp; Not all RPL values are useful, and not all RPL values can be specified when performing segment load to end in successful load.&amp;nbsp; The two sets are not necessary same.&amp;nbsp; On the other hand, the set of valid descriptor indexes is not under software control, it is determined by the content of the GDT and LDT, which are managed by OS.&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;Victor K. wrote:&lt;BR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;To be more specific: for me "&lt;EM&gt;RPL is under software control" &lt;/EM&gt;means I can freely manipulate RPL when loading the &lt;STRONG&gt;segment register&lt;/STRONG&gt;. When I pass selector to the "server" by stack, it is not a segment register. It's just piece of data with any meaning. In this sense, we could say "selector index is under software control". It could be null, it could be out of GDT/LDT limit, it could be anyting.&lt;/P&gt;

&lt;P&gt;And related question: does CPU performs CPL/RPL/DPL checks only at selector loading stage, or does also at stage of memory access?&lt;BR /&gt;
	For example, assume CPL=3, DS is already loaded (by someone with CPL=0) with descriptor's selector with DPL=0. Would "mov eax,[eax]" lead to #GP?&lt;/P&gt;

&lt;P&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Privilege checks are performed only at the segment registers load time.&amp;nbsp; If more privileged code returns to the less privileged state and leaks high-privileged descriptor in some segment register, then it opens the access to the data.&amp;nbsp; For this reason, regular inter-privilege return methods like IRET or RET invalidate content of segment registers that point to higher privileged descriptors (and really invalidate the content of descriptor caches associated with that segment).&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 00:58:25 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102575#M6023</guid>
      <dc:creator>Konstantin_B_</dc:creator>
      <dc:date>2017-06-07T00:58:25Z</dc:date>
    </item>
    <item>
      <title>Thank you, Konstantin.</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102576#M6024</link>
      <description>&lt;P&gt;Thank you, Konstantin. Problem is solved now :)&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2017 13:21:16 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102576#M6024</guid>
      <dc:creator>Victor_K_</dc:creator>
      <dc:date>2017-06-07T13:21:16Z</dc:date>
    </item>
    <item>
      <title>&gt;&gt;Before the processor loads</title>
      <link>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102577#M6025</link>
      <description>&amp;gt;&amp;gt;Before the processor loads a segment selector into a segment register, it performs a privilege check (see Figure 5-4)
&amp;gt;&amp;gt;by comparing the privilege levels of the currently running program or task (the CPL), the RPL of the segment selector,
&amp;gt;&amp;gt;and the DPL of the segment’s segment descriptor. The processor loads the segment selector into the segment
&amp;gt;&amp;gt;register if the DPL is numerically greater than or equal to both the CPL and the RPL. Otherwise, a general-protection
&amp;gt;&amp;gt;fault is generated and the segment register is not loaded.

Simply to note that It translates to:

...
			( DPL &amp;gt;= Max( RPL, CPL ) ) ? ( Access Allowed ) : ( Access Not Allowed / GPE )

			Where,

			DPL - Descriptor Privilege Level
			CPL - Current Privilege Level
			RPL - Requested Privilege Level
			GPE - General Protection Exception
...</description>
      <pubDate>Wed, 07 Jun 2017 20:40:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-ISA-Extensions/RPL-CPL-and-DPL-question/m-p/1102577#M6025</guid>
      <dc:creator>SergeyKostrov</dc:creator>
      <dc:date>2017-06-07T20:40:00Z</dc:date>
    </item>
  </channel>
</rss>

