diff mbox

[kvm-unit-tests] x86: Test task-switch with cs.rpl != cs.dpl

Message ID 1408304076-2862-1-git-send-email-namit@cs.technion.ac.il (mailing list archive)
State New, archived
Headers show

Commit Message

Nadav Amit Aug. 17, 2014, 7:34 p.m. UTC
Commit 5045b46803 added a check that cs.dpl equals cs.rpl during task-switch.
This is a wrong check, and this test introduces a test in which cs.dpl !=
cs.rpl. To do so, it configures tss.cs to be conforming with rpl=3 and dpl=0.
Since the cpl after calling is 3, it does not make any prints in the callee.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
 x86/taskswitch2.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

Comments

Paolo Bonzini Aug. 19, 2014, 10:27 a.m. UTC | #1
Il 17/08/2014 21:34, Nadav Amit ha scritto:
> Commit 5045b46803 added a check that cs.dpl equals cs.rpl during task-switch.
> This is a wrong check, and this test introduces a test in which cs.dpl !=
> cs.rpl. To do so, it configures tss.cs to be conforming with rpl=3 and dpl=0.
> Since the cpl after calling is 3, it does not make any prints in the callee.
> 
> Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
> ---
>  x86/taskswitch2.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/x86/taskswitch2.c b/x86/taskswitch2.c
> index 92fc941..d96853f 100644
> --- a/x86/taskswitch2.c
> +++ b/x86/taskswitch2.c
> @@ -7,6 +7,8 @@
>  
>  #define MAIN_TSS_SEL (FIRST_SPARE_SEL + 0)
>  #define VM86_TSS_SEL (FIRST_SPARE_SEL + 8)
> +#define USER_CS_SEL  (FIRST_SPARE_SEL + 16)

Please call it CONFORM_CS_SEL since it's not really a user-mode selector
(DPL=0), it's just used as one (RPL=3).

> +#define USER_DS_SEL  (FIRST_SPARE_SEL + 24)

Not needed, see below.

>  
>  static volatile int test_count;
>  static volatile unsigned int test_divider;
> @@ -102,6 +104,14 @@ start:
>  	goto start;
>  }
>  
> +static void user_tss(void)
> +{
> +start:

Please add a printf and print_current_tss_info() here.

> +	test_count++;
> +	asm volatile ("iret");
> +	goto start;
> +}
> +
>  void test_kernel_mode_int()
>  {
>  	unsigned int res;
> @@ -201,6 +211,18 @@ void test_kernel_mode_int()
>  	asm volatile ("ljmp $" xstr(TSS_INTR) ", $0xf4f4f4f4");
>  	printf("Jump back succeeded\n");
>  	report("ljmp", test_count == 1);
> +
> +	/* test lcall with conforming segment, cs.dpl != cs.rpl */
> +	test_count = 0;
> +	set_intr_task_gate(0, user_tss);
> +
> +	tss_intr.cs = USER_CS_SEL | 3;
> +	tss_intr.ss = USER_DS_SEL | 3;
> +	tss_intr.ds = tss_intr.gs = tss_intr.fs = tss_intr.ss;
> +	set_gdt_entry(USER_CS_SEL, 0, 0xffffffff, 0x9f, 0xc0);
> +	set_gdt_entry(USER_DS_SEL, 0, 0xffffffff, 0xf3, 0xc0);

You can use USER_DS here.  Also, please put the test in a separate
function and call it last (after test_vm86_switch), because a failure in
this test breaks test_vm86_switch too.

Paolo

> +	asm volatile("lcall $" xstr(TSS_INTR) ", $0xf4f4f4f4");
> +	report("lcall when cs.rpl != cs.dpl", test_count == 1);
>  }
>  
>  void test_vm86_switch(void)
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/x86/taskswitch2.c b/x86/taskswitch2.c
index 92fc941..d96853f 100644
--- a/x86/taskswitch2.c
+++ b/x86/taskswitch2.c
@@ -7,6 +7,8 @@ 
 
 #define MAIN_TSS_SEL (FIRST_SPARE_SEL + 0)
 #define VM86_TSS_SEL (FIRST_SPARE_SEL + 8)
+#define USER_CS_SEL  (FIRST_SPARE_SEL + 16)
+#define USER_DS_SEL  (FIRST_SPARE_SEL + 24)
 
 static volatile int test_count;
 static volatile unsigned int test_divider;
@@ -102,6 +104,14 @@  start:
 	goto start;
 }
 
+static void user_tss(void)
+{
+start:
+	test_count++;
+	asm volatile ("iret");
+	goto start;
+}
+
 void test_kernel_mode_int()
 {
 	unsigned int res;
@@ -201,6 +211,18 @@  void test_kernel_mode_int()
 	asm volatile ("ljmp $" xstr(TSS_INTR) ", $0xf4f4f4f4");
 	printf("Jump back succeeded\n");
 	report("ljmp", test_count == 1);
+
+	/* test lcall with conforming segment, cs.dpl != cs.rpl */
+	test_count = 0;
+	set_intr_task_gate(0, user_tss);
+
+	tss_intr.cs = USER_CS_SEL | 3;
+	tss_intr.ss = USER_DS_SEL | 3;
+	tss_intr.ds = tss_intr.gs = tss_intr.fs = tss_intr.ss;
+	set_gdt_entry(USER_CS_SEL, 0, 0xffffffff, 0x9f, 0xc0);
+	set_gdt_entry(USER_DS_SEL, 0, 0xffffffff, 0xf3, 0xc0);
+	asm volatile("lcall $" xstr(TSS_INTR) ", $0xf4f4f4f4");
+	report("lcall when cs.rpl != cs.dpl", test_count == 1);
 }
 
 void test_vm86_switch(void)