Merge tag 'gpio-updates-for-v7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux

Pull gpio updates from Bartosz Golaszewski:
 "For this merge window we have two new drivers: support for
  GPIO-signalled ACPI events on Intel platforms and a generic
  GPIO-over-pinctrl driver using the ARM SCMI protocol for
  controlling pins.

  Several things have been reworked in GPIO core: we unduplicated GPIO
  hog handling, reduced the number of SRCU locks and dereferences,
  improved support for software-node-based lookup and removed more
  legacy code after converting remaining users to modern alternatives.

  There's also a number of driver reworks and refactoring, documentation
  updates, some bug-fixes and new tests.

  GPIO core:
   - defer probe on software node lookups when the remote software node
     exists but has not been registered as a firmware node yet
   - unify GPIO hog handling by moving code duplicated in OF and ACPI
     modules into GPIO core and allow setting up hogs with software
     nodes
   - allow matching GPIO controllers by secondary firmware node if
     matching by primary does not succeed
   - demote deferral warnings to debug level as they are quite normal
     when using software nodes which don't support fw_devlink yet
   - disable the legacy GPIO character device uAPI v1 supprt in Kconfig
     by default
   - rework several core functions in preparation for the upcoming
     Revocable helper library for protecting resources against sudden
     removal, this reduces the number of SRCU dereferences in GPIO core
   - simplify file descriptor logic in GPIO character device code by
     using FD_PREPARE()
   - introduce a header defining symbols used by both GPIO consumers and
     providers to avoid having to include provider-specific headers from
     drivers which only consume GPIOs
   - replace snprintf() with strscpy() where formatting is not required

  New drivers:
   - add the gpio-by-pinctrl generic driver using the ARM SCMI protocol
     to control GPIOs (along with SCMI changes pulled from the pinctrl
     tree)
   - add a driver providing support for handling of platform events via
     GPIO-signalled ACPI events (used on Intel Nova Lake and later
     platforms)

  Driver changes:
   - extend the gpio-kempld driver with support for more recent models,
     interrupts and setting/getting multiple values at once
   - improve interrupt handling in gpio-brcmstb
   - add support for multi-SoC systems in gpio-tegra186
   - make sure we return correct values from the .get() callbacks in
     several GPIO drivers by normalizing any values other than 0, 1 or
     negative error numbers
   - use flexible arrays in several drivers to reduce the number of
     required memory allocations
   - simplify synchronous waiting for virtual drivers to probe and
     remove the dedicated, a bit overengineered helper library
     dev-sync-probe
   - remove unneeded Kconfig dependencies on OF_GPIO in several drivers
     and subsystems
   - convert the two remaining users of of_get_named_gpio() to using
     GPIO descriptors and remove the (no longer used) function along
     with the header that declares it
   - add missing includes in gpio-mmio
   - shrink and simplify code in gpio-max732x by using guard(mutex)
   - remove duplicated code handling the 'ngpios' property from
     gpio-ts4800, it's already handled in GPIO core
   - use correct variable type in gpio-aspeed
   - add support for a new model in gpio-realtek-otto
   - allow to specify the active-low setting of simulated hogs over the
     configfs interface (in addition to existing devicetree support) in
     gpio-sim

  Bug fixes:
   - clear the OF_POPULATED flag on hog nodes in GPIO chip remove path
     on OF systems
   - fix resource leaks in error path in gpiochip_add_data_with_key()
   - drop redundant device reference in gpio-mpsse

  Tests:
   - add selftests for use-after-free cases in GPIO character device
     code

  DT bindings:
   - add a DT binding document for SCMI based, gpio-over-pinctrl devices
   - fix interrupt description in microchip,mpfs-gpio
   - add new compatible for gpio-realtek-otto
   - describe the resets of the mpfs-gpio controller
   - fix maintainer's email in gpio-delay bindings
   - remove the binding document for cavium,thunder-8890 as the
     corresponding device is bound over PCI and not firmware nodes

  Documentation:
   - update the recommended way of converting legacy boards to using
     software nodes for GPIO description
   - describe GPIO line value semantics
   - misc updates to kerneldocs

  Misc:
   - convert OMAP1 ams-delta board to using GPIO hogs described with
     software nodes"

* tag 'gpio-updates-for-v7.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/brgl/linux: (79 commits)
  gpio: swnode: defer probe on references to unregistered software nodes
  dt-bindings: gpio: cavium,thunder-8890: Remove DT binding
  Documentation: gpio: update the preferred method for using software node lookup
  gpio: gpio-by-pinctrl: s/used to do/is used to do/
  gpio: aspeed: fix unsigned long int declaration
  gpio: rockchip: convert to dynamic GPIO base allocation
  gpio: remove dev-sync-probe
  gpio: virtuser: stop using dev-sync-probe
  gpio: aggregator: stop using dev-sync-probe
  gpio: sim: stop using dev-sync-probe
  gpio: Add Intel Nova Lake ACPI GPIO events driver
  gpiolib: Make deferral warnings debug messages
  gpiolib: fix hogs with multiple lines
  gpio: fix up CONFIG_OF dependencies
  gpio: gpio-by-pinctrl: add pinctrl based generic GPIO driver
  gpio: dt-bindings: Add GPIO on top of generic pin control
  firmware: arm_scmi: Allow PINCTRL_REQUEST to return EOPNOTSUPP
  pinctrl: scmi: ignore PIN_CONFIG_PERSIST_STATE
  pinctrl: scmi: Delete PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS support
  pinctrl: scmi: Add SCMI_PIN_INPUT_VALUE
  ...
This commit is contained in:
Linus Torvalds
2026-04-13 20:10:58 -07:00
77 changed files with 2078 additions and 1278 deletions

View File

@@ -1,8 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh
TEST_PROGS := gpio-mockup.sh gpio-sim.sh gpio-aggregator.sh gpio-cdev-uaf.sh
TEST_FILES := gpio-mockup-sysfs.sh
TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name
TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name \
gpio-cdev-uaf
CFLAGS += -O2 -g -Wall $(KHDR_INCLUDES)
include ../lib.mk

View File

@@ -0,0 +1,292 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* GPIO character device helper for UAF tests.
*
* Copyright 2026 Google LLC
*/
#include <errno.h>
#include <fcntl.h>
#include <linux/gpio.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define CONFIGFS_DIR "/sys/kernel/config/gpio-sim"
#define PROCFS_DIR "/proc"
static void print_usage(void)
{
printf("usage:\n");
printf(" gpio-cdev-uaf [chip|handle|event|req] [poll|read|ioctl]\n");
}
static int _create_chip(const char *name, int create)
{
char path[64];
snprintf(path, sizeof(path), CONFIGFS_DIR "/%s", name);
if (create)
return mkdir(path, 0755);
else
return rmdir(path);
}
static int create_chip(const char *name)
{
return _create_chip(name, 1);
}
static void remove_chip(const char *name)
{
_create_chip(name, 0);
}
static int _create_bank(const char *chip_name, const char *name, int create)
{
char path[64];
snprintf(path, sizeof(path), CONFIGFS_DIR "/%s/%s", chip_name, name);
if (create)
return mkdir(path, 0755);
else
return rmdir(path);
}
static int create_bank(const char *chip_name, const char *name)
{
return _create_bank(chip_name, name, 1);
}
static void remove_bank(const char *chip_name, const char *name)
{
_create_bank(chip_name, name, 0);
}
static int _enable_chip(const char *name, int enable)
{
char path[64];
int fd, ret;
snprintf(path, sizeof(path), CONFIGFS_DIR "/%s/live", name);
fd = open(path, O_WRONLY);
if (fd == -1)
return fd;
if (enable)
ret = write(fd, "1", 1);
else
ret = write(fd, "0", 1);
close(fd);
return ret == 1 ? 0 : -1;
}
static int enable_chip(const char *name)
{
return _enable_chip(name, 1);
}
static void disable_chip(const char *name)
{
_enable_chip(name, 0);
}
static int open_chip(const char *chip_name, const char *bank_name)
{
char path[64], dev_name[32];
int ret, fd;
ret = create_chip(chip_name);
if (ret) {
fprintf(stderr, "failed to create chip\n");
return ret;
}
ret = create_bank(chip_name, bank_name);
if (ret) {
fprintf(stderr, "failed to create bank\n");
goto err_remove_chip;
}
ret = enable_chip(chip_name);
if (ret) {
fprintf(stderr, "failed to enable chip\n");
goto err_remove_bank;
}
snprintf(path, sizeof(path), CONFIGFS_DIR "/%s/%s/chip_name",
chip_name, bank_name);
fd = open(path, O_RDONLY);
if (fd == -1) {
ret = fd;
fprintf(stderr, "failed to open %s\n", path);
goto err_disable_chip;
}
ret = read(fd, dev_name, sizeof(dev_name) - 1);
close(fd);
if (ret == -1) {
fprintf(stderr, "failed to read %s\n", path);
goto err_disable_chip;
}
dev_name[ret] = '\0';
if (ret && dev_name[ret - 1] == '\n')
dev_name[ret - 1] = '\0';
snprintf(path, sizeof(path), "/dev/%s", dev_name);
fd = open(path, O_RDWR);
if (fd == -1) {
ret = fd;
fprintf(stderr, "failed to open %s\n", path);
goto err_disable_chip;
}
return fd;
err_disable_chip:
disable_chip(chip_name);
err_remove_bank:
remove_bank(chip_name, bank_name);
err_remove_chip:
remove_chip(chip_name);
return ret;
}
static void close_chip(const char *chip_name, const char *bank_name)
{
disable_chip(chip_name);
remove_bank(chip_name, bank_name);
remove_chip(chip_name);
}
static int test_poll(int fd)
{
struct pollfd pfds;
pfds.fd = fd;
pfds.events = POLLIN;
pfds.revents = 0;
if (poll(&pfds, 1, 0) == -1)
return -1;
return (pfds.revents & ~(POLLHUP | POLLERR)) ? -1 : 0;
}
static int test_read(int fd)
{
char data;
if (read(fd, &data, 1) == -1 && errno == ENODEV)
return 0;
return -1;
}
static int test_ioctl(int fd)
{
if (ioctl(fd, 0, NULL) == -1 && errno == ENODEV)
return 0;
return -1;
}
int main(int argc, char **argv)
{
int cfd, fd, ret;
int (*test_func)(int);
if (argc != 3) {
print_usage();
return EXIT_FAILURE;
}
if (strcmp(argv[1], "chip") == 0 ||
strcmp(argv[1], "event") == 0 ||
strcmp(argv[1], "req") == 0) {
if (strcmp(argv[2], "poll") &&
strcmp(argv[2], "read") &&
strcmp(argv[2], "ioctl")) {
fprintf(stderr, "unknown command: %s\n", argv[2]);
return EXIT_FAILURE;
}
} else if (strcmp(argv[1], "handle") == 0) {
if (strcmp(argv[2], "ioctl")) {
fprintf(stderr, "unknown command: %s\n", argv[2]);
return EXIT_FAILURE;
}
} else {
fprintf(stderr, "unknown command: %s\n", argv[1]);
return EXIT_FAILURE;
}
if (strcmp(argv[2], "poll") == 0)
test_func = test_poll;
else if (strcmp(argv[2], "read") == 0)
test_func = test_read;
else /* strcmp(argv[2], "ioctl") == 0 */
test_func = test_ioctl;
cfd = open_chip("chip", "bank");
if (cfd == -1) {
fprintf(stderr, "failed to open chip\n");
return EXIT_FAILURE;
}
/* Step 1: Hold a FD to the test target. */
if (strcmp(argv[1], "chip") == 0) {
fd = cfd;
} else if (strcmp(argv[1], "handle") == 0) {
struct gpiohandle_request req = {0};
req.lines = 1;
if (ioctl(cfd, GPIO_GET_LINEHANDLE_IOCTL, &req) == -1) {
fprintf(stderr, "failed to get handle FD\n");
goto err_close_chip;
}
close(cfd);
fd = req.fd;
} else if (strcmp(argv[1], "event") == 0) {
struct gpioevent_request req = {0};
if (ioctl(cfd, GPIO_GET_LINEEVENT_IOCTL, &req) == -1) {
fprintf(stderr, "failed to get event FD\n");
goto err_close_chip;
}
close(cfd);
fd = req.fd;
} else { /* strcmp(argv[1], "req") == 0 */
struct gpio_v2_line_request req = {0};
req.num_lines = 1;
if (ioctl(cfd, GPIO_V2_GET_LINE_IOCTL, &req) == -1) {
fprintf(stderr, "failed to get req FD\n");
goto err_close_chip;
}
close(cfd);
fd = req.fd;
}
/* Step 2: Free the chip. */
close_chip("chip", "bank");
/* Step 3: Access the dangling FD to trigger UAF. */
ret = test_func(fd);
close(fd);
return ret ? EXIT_FAILURE : EXIT_SUCCESS;
err_close_chip:
close(cfd);
close_chip("chip", "bank");
return EXIT_FAILURE;
}

View File

@@ -0,0 +1,63 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# Copyright 2026 Google LLC
BASE_DIR=`dirname $0`
MODULE="gpio-cdev-uaf"
fail() {
echo "$*" >&2
echo "GPIO $MODULE test FAIL"
exit 1
}
skip() {
echo "$*" >&2
echo "GPIO $MODULE test SKIP"
exit 4
}
# Load the gpio-sim module. This will pull in configfs if needed too.
modprobe gpio-sim || skip "unable to load the gpio-sim module"
# Make sure configfs is mounted at /sys/kernel/config. Wait a bit if needed.
for _ in `seq 5`; do
mountpoint -q /sys/kernel/config && break
mount -t configfs none /sys/kernel/config
sleep 0.1
done
mountpoint -q /sys/kernel/config || \
skip "configfs not mounted at /sys/kernel/config"
echo "1. GPIO"
echo "1.1. poll"
$BASE_DIR/gpio-cdev-uaf chip poll || fail "failed to test chip poll"
echo "1.2. read"
$BASE_DIR/gpio-cdev-uaf chip read || fail "failed to test chip read"
echo "1.3. ioctl"
$BASE_DIR/gpio-cdev-uaf chip ioctl || fail "failed to test chip ioctl"
echo "2. linehandle"
echo "2.1. ioctl"
$BASE_DIR/gpio-cdev-uaf handle ioctl || fail "failed to test handle ioctl"
echo "3. lineevent"
echo "3.1. read"
$BASE_DIR/gpio-cdev-uaf event read || fail "failed to test event read"
echo "3.2. poll"
$BASE_DIR/gpio-cdev-uaf event poll || fail "failed to test event poll"
echo "3.3. ioctl"
$BASE_DIR/gpio-cdev-uaf event ioctl || fail "failed to test event ioctl"
echo "4. linereq"
echo "4.1. read"
$BASE_DIR/gpio-cdev-uaf req read || fail "failed to test req read"
echo "4.2. poll"
$BASE_DIR/gpio-cdev-uaf req poll || fail "failed to test req poll"
echo "4.3. ioctl"
$BASE_DIR/gpio-cdev-uaf req ioctl || fail "failed to test req ioctl"
echo "GPIO $MODULE test PASS"