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

2017-12-06 Thread Greg KH
On Wed, Dec 06, 2017 at 07:26:13PM +0100, Krzysztof Opasiak wrote:
> 
> 
> On 12/06/2017 07:26 AM, Greg KH wrote:
> > On Tue, Dec 05, 2017 at 10:09:35PM +, andy_purc...@keysight.com 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 rootroot   0 Dec  5 21:39 ep1
> > > -rw--- 1 rootroot   0 Dec  5 21:39 ep2
> > > -rw--- 1 rootroot   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.

Ah, yeah, you are right, sorry about that, mounting filesystems at
/dev/ always confuses everyone :)

> Can we use udev for a custom files other than device nodes? Isn't it only
> uevent parser?

Yes it is, so no, it will not really work for this, sorry.

> 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.

Ah, nice, that should work well.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2017-12-06 Thread andy_purcell
   DRIVER==""

  looking at parent device '/kernel/config/usb_gadget/g1/functions':
KERNELS=="functions"
SUBSYSTEMS==""
DRIVERS==""

  looking at parent device '/kernel/config/usb_gadget/g1':
KERNELS=="g1"
SUBSYSTEMS==""
DRIVERS==""
ATTRS{UDC}==""
ATTRS{bDeviceClass}=="0x00"
ATTRS{bDeviceProtocol}=="0x00"
ATTRS{bDeviceSubClass}=="0x00"
ATTRS{bMaxPacketSize0}=="0x00"
ATTRS{bcdDevice}=="0x0414"
ATTRS{bcdUSB}=="0x"
ATTRS{idProduct}=="0x"
ATTRS{idVendor}=="0x"

  looking at parent device '/kernel/config/usb_gadget':
KERNELS=="usb_gadget"
SUBSYSTEMS==""
DRIVERS==""

  looking at parent device '/kernel/config':
    KERNELS=="config"
SUBSYSTEMS==""
    DRIVERS==""

  looking at parent device '/kernel':
KERNELS=="kernel"
SUBSYSTEMS==""
DRIVERS==""
ATTRS{fscaps}=="1"
ATTRS{rcu_expedited}=="0"
ATTRS{rcu_normal}=="0"
ATTRS{uevent_seqnum}=="1115"

set rule KERNEL=="ffs.usb488", KERNELS=="functions", ACTION=="add",   
RUN+="/etc/udev/scripts/usb488setup.sh"
reboot, attempt to start usb-device 
RESULT: script not run
... test using udevadm.
udevadm test /sys/kernel/config/usb_gadget/g1  2>&1 | grep usb488
$ udevadm test /sys/kernel/config/usb_gadget/g1/configs/c.1/ffs.usb488  2>&1 | 
grep usb488
DEVPATH=/kernel/config/usb_gadget/g1/functions/ffs.usb488   < No "run" line 


Andy Purcell





> -Original Message-
> From: Greg KH [mailto:gre...@linuxfoundation.org]
> Sent: Tuesday, December 5, 2017 11:27 PM
> To: PURCELL,ANDY (K-Loveland,ex1) <andy_purc...@keysight.com>
> Cc: linux-usb@vger.kernel.org
> Subject: Re: usb device implemented with functionfs - must app run as root?
> 
> On Tue, Dec 05, 2017 at 10:09:35PM +, andy_purc...@keysight.com 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 rootroot   0 Dec  5 21:39 ep1
> > -rw--- 1 rootroot   0 Dec  5 21:39 ep2
> > -rw--- 1 rootroot   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?
> 
> thanks,
> 
> greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2017-12-06 Thread Krzysztof Opasiak



On 12/06/2017 07:26 AM, Greg KH wrote:

On Tue, Dec 05, 2017 at 10:09:35PM +, andy_purc...@keysight.com 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 rootroot   0 Dec  5 21:39 ep1
-rw--- 1 rootroot   0 Dec  5 21:39 ep2
-rw--- 1 rootroot   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 Institute Poland
Samsung Electronics
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2017-12-05 Thread Greg KH
On Tue, Dec 05, 2017 at 10:09:35PM +, andy_purc...@keysight.com 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 rootroot   0 Dec  5 21:39 ep1
> -rw--- 1 rootroot   0 Dec  5 21:39 ep2
> -rw--- 1 rootroot   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?

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2017-12-05 Thread andy_purcell
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 rootroot   0 Dec  5 21:39 ep1
-rw--- 1 rootroot   0 Dec  5 21:39 ep2
-rw--- 1 rootroot   0 Dec  5 21:39 ep3

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

Is there a remedy for this?


Andy Purcell

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