2

The platform is a rooted Android 8.1 phone (Magisk) with the Termux Android terminal emulator and Linux environment app installed. I use this as a server on the go.

After connecting a USB smart card reader, then as root I can see its USB device files just fine. However as an ordinary user I cannot see these files, even after making the user owner of the containing directory:

$ whoami
u0_a88
$ ls -l /sys/bus/usb/devices
ls: cannot open directory '/sys/bus/usb/devices': Permission denied
$ ls -ld /sys/bus/usb/devices
drwxr-xr-x 2 root root 0 Aug 20 08:48 /sys/bus/usb/devices
$ su
# whoami
root
# ls -l /sys/bus/usb/devices/
total 0
lrwxrwxrwx 1 root root 0 Aug 20 08:49 1-0:1.0 -> ../../../devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb1/1-0:1.0
lrwxrwxrwx 1 root root 0 Aug 20 08:49 1-1 -> ../../../devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb1/1-1
lrwxrwxrwx 1 root root 0 Aug 20 08:49 1-1:1.0 -> ../../../devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb1/1-1/1-1:1.0
lrwxrwxrwx 1 root root 0 Aug 20 08:49 2-0:1.0 -> ../../../devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb2/2-0:1.0
lrwxrwxrwx 1 root root 0 Aug 20 08:49 usb1 -> ../../../devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb1
lrwxrwxrwx 1 root root 0 Aug 20 08:49 usb2 -> ../../../devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/usb2
# chown u0_a88.u0_a88 /sys/bus/usb/devices
# exit
$ ls -ld /sys/bus/usb/devices
drwxr-xr-x 2 u0_a88 u0_a88 0 Aug 20 08:54 /sys/bus/usb/devices
~$ ls -l /sys/bus/usb/devices
ls: cannot open directory '/sys/bus/usb/devices': Permission denied

What is happening here?

migrated from serverfault.com Aug 20 '18 at 9:53

This question came from our site for system and network administrators.

  • Possibly the permissions on a higher level directory apply more strict acecss controls, a quick check on a long path is with the namei command: namei -l /sys/bus/usb/devices – HBruijn Aug 20 '18 at 9:52
  • 1
    @HBruijn, If it was about regular directory permissions higher on the path, ls -ld /sys/bus/usb/devices wouldn't work either. I do wonder if this is some Android thing. – ilkkachu Aug 20 '18 at 10:02
2

As I found out, it likely has to do with SELinux:

$ su
# getenforce
Enforcing

Regular files can be given permission for access by the ordinary user as in the following example:

$ su
# echo foo >bar
# exit
$ cat foo
cat: bar: Permission denied
$ su
# ls -Z bar
u:object_r:app_data_file:s0 bar
# restorecon bar
SELinux: Loaded file_contexts
# ls -Z bar
u:object_r:app_data_file:s0:c512,c768 bar
# chown u0_a88.u0_a88 bar
# exit
$ cat bar
foo

Simply using restorecon and chmod is not sufficient, however, to give me access to /sys/bus/usb/devices:

# restorecon /sys/bus/usb/devices
# chown u0_a88.u0_a88 /sys/bus/usb/devices
# ls -Zd /sys/bus/usb/devices
u:object_r:sysfs:s0
# exit
$ ls -ld /sys/bus/usb/devices
drwxr-xr-x 2 u0_a88 u0_a88 0 Aug 23 11:49 /sys/bus/usb/devices
$ ls -l /sys/bus/usb/devices
ls: cannot open directory '/sys/bus/usb/devices': Permission denied

I didn't try changing permissions higher up the path as I’m worried about breaking the system.

(I assume that my explanation is right. Still an answer by someone knowledgeable about SELinux would be nice.)

  • Try ls -Zd /sys and change it temporarily if you don't want to interfere with your system security. – dan Aug 23 '18 at 10:26
-1

Everything inside the

/sys/bus/usb/devices/

Is containing a softlink. The softlink default permission is always 777.

But the real file located inside

/devices/soc/a800000.ssusb/a800000.dwc3/xhci-hcd.0.auto/

is the real file. You need to change the permission to 777 in the real location first to enable the user u0_a88 to open the directory/files.

  • The directory itself is not a symlink. So with permissions 0755, I should be able to see its contents, as any user. Not? – feklee Aug 20 '18 at 8:22
  • Other need execute permission to open the directory. – hazard74 Aug 20 '18 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.