Topics

thread permissions issue


Diego Sueiro
 

Hello Zephyrs,

I'm developing a shell module for the sensor drivers and I want to
validate if the device name passed from the user is a sensor device.

I have the CONFIG_USERSAPCE=y.

After calling "dev = device_get_binding(argv[1])" I call the
"Z_SYSCALL_DRIVER_SENSOR(dev, sample_fetch)" and I get the following
error message:

thread 0x2000064c (1) does not have permission on sensor driver
0x20005ac8 [0000]
syscall cmd_get_sensor failed check: access denied


Some questions:

1 - How do I grant permission to the running thread to access the
sensor driver object?

2 - Even having the CONFIG_USERSAPCE=y set when calling
"sensor_sample_fetch" it seems that it is calling the
"_impl_sensor_sample_fetch" directly instead of
"Z_SYSCALL_HANDLER(sensor_sample_fetch, dev)" defined in the
drivers/sensor/sensor_handlers.c file. How can I have the current
thread using the userspace syscalls?

Regards,

--
*dS
Diego Sueiro


Diego Sueiro
 

On Sat, 10 Nov 2018 at 16:59, Diego Sueiro <diego.sueiro@gmail.com> wrote:

Hello Zephyrs,

I'm developing a shell module for the sensor drivers and I want to
validate if the device name passed from the user is a sensor device.

I have the CONFIG_USERSAPCE=y.

After calling "dev = device_get_binding(argv[1])" I call the
"Z_SYSCALL_DRIVER_SENSOR(dev, sample_fetch)" and I get the following
error message:

thread 0x2000064c (1) does not have permission on sensor driver
0x20005ac8 [0000]
syscall cmd_get_sensor failed check: access denied


Some questions:

1 - How do I grant permission to the running thread to access the
sensor driver object?
I managed to solve this by calling
"k_thread_access_grant(k_current_get(), dev, NULL)" before calling the
"Z_SYSCALL_DRIVER_SENSOR" macro.

2 - Even having the CONFIG_USERSAPCE=y set when calling
"sensor_sample_fetch" it seems that it is calling the
"_impl_sensor_sample_fetch" directly instead of
"Z_SYSCALL_HANDLER(sensor_sample_fetch, dev)" defined in the
drivers/sensor/sensor_handlers.c file. How can I have the current
thread using the userspace syscalls?
This question remains open.


Boie, Andrew P
 

I'm developing a shell module for the sensor drivers and I want to
validate if the device name passed from the user is a sensor device.
The userspace infrastructure has facilities for this, but as I commented in your patch, what you are doing is only intended for system call handlers. The Zephyr kernel running in supervisor mode is intended to be very lightweight and doesn't have features like this, it's a garbage-in-garbage-out type of situation.

The proper way to do this is have the shell main loop run in user mode, it's the only way to make robust assertions that malformed user input can't hose the system. I suggest just dropping the checks.

Andrew