linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
To: linux-gpio@vger.kernel.org
Cc: brgl@bgdev.pl, Kent Gibson <warthog618@gmail.com>
Subject: Re: libgpiod API v2 release
Date: Wed, 29 Mar 2023 12:03:31 +0100	[thread overview]
Message-ID: <158fba21-8d5a-ac56-ae02-2694ea9ae388@canonical.com> (raw)
In-Reply-To: <20220714031036.GA74086@sol>

Hi,

On 14/07/2022 04:10, Kent Gibson wrote:
> On Tue, Jul 12, 2022 at 09:48:45AM +0200, Alexandre Ghiti wrote:
>> Hi,
>>
>> Ubuntu kernels do not enable GPIO_CDEV_V1 as it is deprecated, but the
>> libgpiod package that we ship is still based on the latest version
>> 1.6.3 which does not implement the API v2. So I'd like to update
>> libgpiod, do you have any recommendations about what branch/sha1 I
>> should use? Do you plan to make a release that implements the API v2?
>>
> 
> Firstly, libgpiod is Bart's library so he is the authority, but this
> is my understanding...
> 
> TLDR: You should keep GPIO_CDEV_V1 enabled.
> 
> v1 is deprecated from a development perspective, so all new feature
> development will occur on v2, and new applications should target v2.
> Existing apps targetting v1, be that directly or via libgpiod v1.6.3,
> will require GPIO_CDEV_V1 until they migrate to v2.
> The mainline kernel will continue to support v1 while userspace
> transitions.
> 
> libgpiod v2 is in active development, and should reach its first release
> shortly.
> Note that it is NOT a plugin replacement for v1. It has a different API,
> for similar reasons to why we had to switch in the kernel, so apps will
> need to be actively migrated.
> 
> I wouldn't suggest making any effort to package libgpiod v2 until Bart
> makes an official release.
> 
> Cheers,
> Kent.
> 

libgpiod v2 is out now at least upstream, even if it is not yet packaged in most distributions. But this brings newly identified loss of functionality that seems to be impossible to resolve so far.

With the v1 API, it was possible to do fine-grained access and mediation control via LSM. Specifically privileged process would export pins, and then use LSM controls to allow rw access to individual pin path in sysfs to otherwise unpriviledged or confined applications. This is used a lot on Ubuntu Core with snapd and apparmor, to mediate confined applications (such that only one application at time has access to a particular pin, and to ensure they only have access to pins they need).

It doesn't seem to be possible to do such mediation with v2 api, as I don't see any LSM hooks inside the gpiochip ioctl implementation, and the character device is for the full chip, not individual pins. Similarly, mediating ioctl calls requires a lot of gpio ioctl specific knowledge (i.e. introspecting gpio_v2_line_values masks and what not).

Thus right now, I cannot migrate to v2 api, as I would loose confinement capabilities. And there is external pressure to stop using "DEPRECATED" config option in the kernel that "will be removed after 2020" as per comments and Linux documentation.

What is the LSM plan for v2 API, if any?

Ideally, it would be nice to have lsm hook to check/filter operations on allowed pin numbers.

Or for example, can we add ability to create filtered char device that self-limits itself to particular lines only, within a particular chip? As then the usual LSM could mitigate access to that, without specific gpio ioctl knowledge / introspection. (e.g. /dev/gpio/my-gpio-pins that only allows access to gpiochip0 lines 0..100)

Regards,

Dimitri.

  reply	other threads:[~2023-03-29 11:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12  7:48 libgpiod API v2 release Alexandre Ghiti
2022-07-14  3:10 ` Kent Gibson
2023-03-29 11:03   ` Dimitri John Ledkov [this message]
2023-03-29 11:36     ` Kent Gibson
2023-03-29 11:42       ` Dimitri John Ledkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=158fba21-8d5a-ac56-ae02-2694ea9ae388@canonical.com \
    --to=dimitri.ledkov@canonical.com \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).