Re: k_thread_user_mode_enter() usage


Vakul Garg <vakul.garg@...>
 

Hi Andy

 

To reproduce the problem, you can simply use the following one line change in tests/kernel/mem_protect/…

 

diff --git a/tests/kernel/mem_protect/userspace/src/main.c b/tests/kernel/mem_protect/userspace/src/main.c

index 0d994548d..a8e2ab77e 100644

--- a/tests/kernel/mem_protect/userspace/src/main.c

+++ b/tests/kernel/mem_protect/userspace/src/main.c

@@ -475,6 +475,7 @@ static void umode_enter_func(void)

                 * to signal a pass status or else run_test() will hang

                 * forever waiting on test_end_signal semaphore.

                 */

+               printf("I am inside user mode\n");

                ztest_test_pass();

        } else {

                zassert_unreachable("Thread did not enter user mode\n");

 

 

Regards

Vakul

 

 

From: Andy Gross [mailto:andy.gross@...]
Sent: Wednesday, March 21, 2018 9:04 PM
To: Andrew Boie <andrew.p.boie@...>
Cc: Vakul Garg <vakul.garg@...>; zephyr-users@...
Subject: RE: k_thread_user_mode_enter() usage

 

I'll try to take a look tomorrow.  Do you have a branch I can pull from?

 

Andy

 

On Mar 21, 2018 23:01, "Boie, Andrew P" <andrew.p.boie@...> wrote:

Andy,

Can you take a look at this? Seems to be rooted in the privileged stack mechanism..


-----Original Message-----
From: Vakul Garg [mailto:vakul.garg@...]
Sent: Tuesday, March 20, 2018 11:26 PM
To: Boie, Andrew P <andrew.p.boie@...>; zephyr-users@...
Cc: Andy Gross <andy.gross@...>
Subject: RE: k_thread_user_mode_enter() usage

Importance: High

Hi Andrew

I am using nxp frdm_k64f (has cortex M4 core).
In my application, I have a printf() at beginning. This is causing bus fault.
Replacing it with an infinite while(1) loop hides the bus fault but stack check still remains.

Further I tried running zephyr/tests/kernel/mem_protect/userspace.
It passes successfully.

However if I introduce a printf() in function userspace/src/main.c: umode_enter_func() under the condition when is_user_context is true, it also crashes.
But here it is different exception !!

***** USAGE FAULT *****
  Executing thread ID (thread): 0x200002ec
  Faulting instruction address:  0x61a0
  Attempt to execute undefined instruction Caught system error -- reason 0

Further decoding faulting instruction address 0x61a0 using 'addr2line' takes me to userspace/build/frdm_k64f/zephyr/priv_stacks_hash.gperf:32
The given line number is inside following function (at the location where variable map is being dereferenced to get priv_stack_addr).

u8_t *_k_priv_stack_find(void *obj)
{
    const struct _k_priv_stack_map *map =
        _k_priv_stack_map_lookup((const char *)obj, sizeof(void *));
    return map->priv_stack_addr;
}

I tried increasing MAIN/PREVILEDGED stack sizes in project config, but result is same.

Regards

Vakul

> -----Original Message-----
> From: Boie, Andrew P [mailto:andrew.p.boie@...]
> Sent: Tuesday, March 20, 2018 8:16 PM
> To: Vakul Garg <vakul.garg@...>; zephyr-
> users@...
> Cc: Andy Gross <andy.gross@...>
> Subject: RE: k_thread_user_mode_enter() usage
>
> It looks like you are getting two exceptions in a row.
> Were you able to determine the source of the bus fault? That seems
> like the real issue.
> What platform is this on?
>
> Andrew
>
> -----Original Message-----
> From: zephyr-users-bounces@...
> [mailto:zephyr-users- bounces@...] On Behalf Of
> Vakul Garg
> Sent: Tuesday, March 20, 2018 3:57 AM
> To: zephyr-users@...
> Subject: [Zephyr-users] k_thread_user_mode_enter() usage
>
> Hi
>
> I want my application auto-launched at zephyr startup to drop its
> privileges to become user mode app.
> So I moved my applications entry point to app_main() and invoked it
> from k_thread_user_mode_enter(app_main, NULL, NULL, NULL) from
> function void main().
>
> Now, before app_main() could get called, I get following error:
>
> ***** BUS FAULT *****
>   Executing thread ID (thread): 0x20002eec
>   Faulting instruction address:  0x12da
>   Precise data bus error
>   Address: 0x20011208
> Fatal fault in thread 0x20002eec! Aborting.
> ***** Stack Check Fail! *****
> Current thread ID = 0x20002eec
> Faulting instruction address = 0x2a290
>
> I checked that the stack sentinel check is failing in function
> _check_stack_sentinel().
>
> Can someone advise what I am doing wrong?
>
> Regards
>
> Vakul
>
> _______________________________________________
> Zephyr-users mailing list
> Zephyr-users@...
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flis
> t
> s.zephyrproject.org%2Fmailman%2Flistinfo%2Fzephyr-
> users&data=02%7C01%7Cvakul.garg%40nxp.com%7Cee6448f50f03472d438
> 908d58e7162a5%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63
> 6571540048549904&sdata=7%2B4eiwFRT0gglTQxGjYUNbVXu1PEoF9cp4tgK
> FaIg70%3D&reserved=0

 

Join users@lists.zephyrproject.org to automatically receive all group messages.