[Pkg-raspi-maintainers] Bug#1009654: rpi.gpio-common: udev rule gets truncated for long device paths

Zack Yancey zack.yancey at digi.com
Wed Apr 13 17:35:58 BST 2022


Package: rpi.gpio-common
Version: 0.7.0-0.2+b1
Severity: important
Tags: newcomer
X-Debbugs-Cc: zack.yancey at digi.com

Dear Maintainer,

There's an issue with a udev rule messing up some device permissions: when I plug a device in through a usb hub, the entire PCI bus gets its permissions changed and can't be read anymore.

The problem is in /usr/lib/udev/rules.d/60-rpi.gpio-common.rules, line 3:

```
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="dialout", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
```

enabling debug logging for udev, I see this when the device gets plugged in:

```
Mar 31 13:52:16 raspberrypi systemd-udevd[1553]: gpiochip2: /usr/lib/udev/rules.d/60-rpi.gpio-common.rules:3 Running PROGRAM '/bin/sh -c 'chown root:dialout /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/active_low /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/direction /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/edge /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/value ; chmod 660 /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/active_low /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/direction /sys/devices/platform/scb/fd500000.pcie'
Mar 31 13:52:16 raspberrypi systemd-udevd[1553]: gpiochip2: Starting '/bin/sh -c 'chown root:dialout /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/active_low /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/direction /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/edge /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/value ; chmod 660 /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/active_low /sys/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.2/1-1.2.4/1-1.2.4.4/1-1.2.4.4.1/1-1.2.4.4.1:1.0/gpiochip2/direction /sys/devices/platform/scb/fd500000.pcie'
```

The command that's executed doesn't match the command that's in the rules file--it gets truncated at 1023 characters. In this case, that happens to be right on a directory name, so the chmod 660 gets applied to /sys/devices/platform/scb/fd500000.pcie instead of a specific gpio file.

I was able to work around the bug by splitting up that last line:

```
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="dialout", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys%p/active_low'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys%p/direction'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys%p/edge'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys%p/value'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chmod 660 /sys%p/active_low'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chmod 660 /sys%p/direction'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chmod 660 /sys%p/edge'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chmod 660 /sys%p/value'"
```

That lets %p get a lot larger before we start running into the apparent 1023-character limit for PROGRAM= values. There may be a better way to do this, for example moving all the chown/chmod commands to a script.

I believe this bug could also be the cause of #1001469, as the symptom looks similar.

Thanks,
Zack Yancey

-- System Information:
Distributor ID:	Raspbian
Description:	Raspbian GNU/Linux 11 (bullseye)
Release:	11
Codename:	bullseye
Architecture: armv7l

Kernel: Linux 5.10.92-v7l+ (SMP w/4 CPU threads)
Kernel taint flags: TAINT_CRAP
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

-- no debconf information



More information about the Pkg-raspi-maintainers mailing list