@@ -12,72 +12,56 @@ extern uint32_t __switch_sp(uint32_t new_sp);
1212 */
1313void umode_validation_task (void )
1414{
15- /* --- Phase 1: Kernel Stack Isolation Test --- */
16- umode_printf ("Phase 1: Testing Kernel Stack Isolation\n" );
17- umode_printf ("\n" );
18-
19- /* Test 1-1: Baseline - Syscall with normal SP */
20- umode_printf ("Test 1-1: sys_tid() with normal SP\n" );
15+ /* Test 1: Basic syscall */
16+ umode_printf ("Test 1: Basic syscall\n" );
17+ umode_printf ("Calling sys_tid()...\n" );
2118 int my_tid = sys_tid ();
2219 if (my_tid > 0 ) {
23- umode_printf ("PASS: sys_tid() returned %d\n" , my_tid );
20+ umode_printf ("[ PASS] returned tid= %d\n" , my_tid );
2421 } else {
25- umode_printf ("FAIL: sys_tid() failed (ret =%d) \n" , my_tid );
22+ umode_printf ("[ FAIL] returned tid =%d\n" , my_tid );
2623 }
2724 umode_printf ("\n" );
2825
29- /* Test 1-2: Verify ISR uses mscratch, not malicious user SP */
30- umode_printf ("Test 1-2: sys_tid() with malicious SP\n" );
26+ /* Test 2: Syscall with corrupted SP */
27+ umode_printf ("Test 2: Syscall with corrupted SP\n" );
28+ umode_printf ("Setting SP to 0xDEADBEEF...\n" );
3129
3230 uint32_t saved_sp = __switch_sp (0xDEADBEEF );
3331 int my_tid_bad_sp = sys_tid ();
3432 __switch_sp (saved_sp );
3533
3634 if (my_tid_bad_sp > 0 ) {
37- umode_printf (
38- "PASS: sys_tid() succeeded, ISR correctly used kernel "
39- "stack\n" );
35+ umode_printf ("[PASS] kernel stack isolation working\n" );
4036 } else {
41- umode_printf ("FAIL: Syscall failed with malicious SP (ret=%d)\n" ,
42- my_tid_bad_sp );
37+ umode_printf ("[FAIL] syscall failed (ret=%d)\n" , my_tid_bad_sp );
4338 }
4439 umode_printf ("\n" );
4540
46- /* Test 1-3: Verify syscall functionality is still intact */
47- umode_printf ("Test 1-3: sys_uptime() with normal SP\n" );
41+ /* Test 3: Syscall after recovery */
42+ umode_printf ("Test 3: Syscall after recovery\n" );
43+ umode_printf ("Calling sys_uptime()...\n" );
4844 int uptime = sys_uptime ();
4945 if (uptime >= 0 ) {
50- umode_printf ("PASS: sys_uptime() returned %d\n" , uptime );
46+ umode_printf ("[ PASS] returned uptime= %d\n" , uptime );
5147 } else {
52- umode_printf ("FAIL: sys_uptime() failed (ret =%d) \n" , uptime );
48+ umode_printf ("[ FAIL] returned uptime =%d\n" , uptime );
5349 }
5450 umode_printf ("\n" );
5551
56- umode_printf ("Phase 1 All tests passed.\n" );
57- umode_printf ("\n" );
58-
59- /* --- Phase 2: Security Check (Privileged Access) --- */
60- umode_printf ("========================================\n" );
61- umode_printf ("\n" );
62- umode_printf ("Phase 2: Testing Security Isolation\n" );
63- umode_printf ("\n" );
64- umode_printf ("Action: Attempting to read 'mstatus' CSR from U-mode.\n" );
65- umode_printf ("Expect: Kernel Panic with 'Illegal instruction'.\n" );
66- umode_printf ("\n" );
67- /* Delay before suicide to ensure logs are flushed from
68- * buffer to UART.
52+ /* Test 4: Privileged CSR access
53+ * Delay before triggering exception to ensure logs are flushed.
6954 */
55+ umode_printf ("Test 4: Privileged CSR access\n" );
7056 sys_tdelay (10 );
7157
72- /* Privileged Instruction Trigger */
58+ umode_printf ( "Reading mstatus from U-mode...\n" );
7359 umode_printf ("Result: \n" );
7460 uint32_t mstatus ;
7561 asm volatile ("csrr %0, mstatus" : "=r" (mstatus ));
7662
77- /* If execution reaches here, U-mode isolation failed (still has
78- * privileges).
79- */
80- umode_printf ("FAIL: Privileged instruction executed! (mstatus=0x%lx)\n" ,
63+ /* If execution reaches here, U-mode isolation failed */
64+ umode_printf ("[FAIL] privileged instruction executed (mstatus=0x%lx)\n" ,
8165 (long ) mstatus );
8266
8367 /* Spin loop to prevent further execution. */
0 commit comments