Can't access gpio mapped memory on focal armhf server on pi

Bug #1889926 reported by Kyle Nitzsche
12
This bug affects 1 person
Affects Status Importance Assigned to Milestone
linux-raspi (Ubuntu)
Invalid
Undecided
Unassigned
Focal
Invalid
Undecided
Unassigned

Bug Description

On released (and apt updated) 20.04 armhf preinstalled server on Pi3B+, we cannot use pigpio C program to access memory map for gpio. Customer says the same code works fine on 18.04.

ubuntu@ubuntu:~$ sudo ./pigpio/kyle.o
2020-07-31 18:36:11 initPeripherals: mmap gpio failed (Operation not permitted)

Details on code below, but the executable is attached, and the customer says this fairly represents their code usage.

ubuntu@ubuntu:~/pigpio$ uname -a
Linux ubuntu 5.4.0-1015-raspi #15-Ubuntu SMP Fri Jul 10 05:37:25 UTC 2020 armv7l armv7l armv7l GNU/Linux

We thought perhaps these kernel configs were involved:

CONFIG_DEVMEM=y
CONFIG_ARCH_HAS_DEVMEM_IS_ALLOWED=y
CONFIG_STRICT_DEVMEM=y

... and we modified the kernel cmdline with the following, but the result was the same.
iomem=relaxed strict-devmem=0

The program is simply this https://github.com/joan2937/pigpio/ with make & make install
then this c file:

#include <pigpio.h>
#include <stdio.h>
#include <stdlib.h>

int main(void){

gpioInitialise();

}

built with gcc -Wall -I/home/ubuntu/pigpio -pthread -o kyle.o kyle.c -lpigpio -lrt

Revision history for this message
Kyle Nitzsche (knitzsche) wrote :
description: updated
Juerg Haefliger (juergh)
Changed in linux-raspi (Ubuntu):
status: New → Invalid
Changed in linux-raspi (Ubuntu Focal):
status: New → Triaged
Revision history for this message
Juerg Haefliger (juergh) wrote :

I've confirmed that 5.4 gives 'permission denied' and 5.3 seems to work fine. I suspect that this is due to the lockdown patches in 5.4.

Changed in linux-raspi (Ubuntu Focal):
status: Triaged → Confirmed
Revision history for this message
Kyle Nitzsche (knitzsche) wrote :

This is an important issue blocking the project. Can we please set the importance and assign this? Thank you.

Revision history for this message
Juerg Haefliger (juergh) wrote :

This is not a kernel problem. The problem is that the pigpio library is trying to mmap the GPIOs with PROT_EXEC which is a security risk. In Focal /dev is mounted with the noexec flag so that's no longer possible. They could patch the pigpio library to remove the PROT_EXEC flag from the mmap call but I don't know if the library relies on that in other places (it really shouldn't). There's probably a library in Ubuntu to access GPIOs which is really what they should use so they get support if something doesn't work. Closing as invalid as this is not a bug.

Changed in linux-raspi (Ubuntu Focal):
status: Confirmed → Invalid
Revision history for this message
Jon Watson (jwatson-kdp) wrote :

We are going to try editing the pigpio library and rebuilding it and seeing if it works. There doesn't appear to be a clear requirement for pigpio to rely on PROT_EXEC and it has been removed in the past.

Conversation about this is happening here:
https://github.com/joan2937/pigpio/issues/375

Revision history for this message
Jon Watson (jwatson-kdp) wrote :

We completed a test this morning with the modified pigpio library and verified our applications can now read the GPIO signals once we removed the PROT_EXEC flags from the library init code.

We will pursue getting a change in with the pigpio library separately.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.