Re: usb device implemented with functionfs - must app run as root?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 12/06/2017 07:26 AM, Greg KH wrote:
On Tue, Dec 05, 2017 at 10:09:35PM +0000, andy_purcell@xxxxxxxxxxxx wrote:
I have implemented a USB device using functionfs.
A colleague now says our app must run as a normal user, not as root.

I tried it and it does not work.
The problem is this - the endpoint files created by the OS are owned by root.
These ep files are created after I write the descriptors and strings to the /dev/usbffs/ep0 file.

$ ls -l /dev/usbffs/
total 0
-rw-rw-rw- 1 xyzuser xyzgrp 0 Dec  5 21:36 ep0
-rw------- 1 root    root   0 Dec  5 21:39 ep1
-rw------- 1 root    root   0 Dec  5 21:39 ep2
-rw------- 1 root    root   0 Dec  5 21:39 ep3

A normal user-space app cannot open, write, read, these ep files.

Is there a remedy for this?

Write a udev rule to change the owners of those files :)

You must have done that already for the ep0 file, right?


FunctionFS is a separate file system not a group of device nodes it's just mounted under /dev/usbffs. So technically epX are not device nodes and as far as I know (please correct me if I'm wrong) there is no uevent then epX is created.

Can we use udev for a custom files other than device nodes? Isn't it only uevent parser? Not to mention about race condition between service opening the file and udev trying to execute the rule;)

I'm not sure if you use systemd or not but there is a FunctionFS based activation and this is how we solve this problem. systemd is running as a root and opens all epX files and pass them to the service which then can run with lower privileges. Additional benefit is that systemd doesn't close those fds so even if your demon crashes whole gadget is not going away, all other functions are still usable.

Best regards,
--
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux