Skip to contentSkip to conversation

CVE-2026-31732: gpio: Fix resource leaks on errors in gpiochip_add_data_with_key()

DISCUSSION Greg Kroah-Hartman 1 participant 1 message May 1

lore
Share & tools
lore
#0 lore raw

From: Greg Kroah-Hartman <[email protected]>

Description
===========

In the Linux kernel, the following vulnerability has been resolved:

gpio: Fix resource leaks on errors in gpiochip_add_data_with_key()

Since commit aab5c6f20023 ("gpio: set device type for GPIO chips"), gdev->dev.release is unset. As a result, the reference count to gdev->dev isn't dropped on the error handling paths.

Drop the reference on errors.

Also reorder the instructions to make the error handling simpler. Now gpiochip_add_data_with_key() roughly looks like:

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Some memory allocation. Go to ERR ZONE 1 on errors. device_initialize().

gpiodev_release() takes over the responsibility for freeing the resources of gdev->dev. The subsequent error handling paths shouldn't go through ERR ZONE 1 again which leads to double free.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Some initialization mainly on gdev.
The rest of initialization. Go to ERR ZONE 2 on errors. Chip registration success and exit.

ERR ZONE 2. gpio_device_put() and exit.
ERR ZONE 1.

The Linux kernel CVE team has assigned CVE-2026-31732 to this issue.

Affected and fixed versions
===========================

	Issue introduced in 6.9 with commit aab5c6f200238ac45001bec3d5494fff8438a8dc and fixed in 6.18.22 with commit f0cf9c7b7c281956cc0dec163132cd96f76e1d60
	Issue introduced in 6.9 with commit aab5c6f200238ac45001bec3d5494fff8438a8dc and fixed in 6.19.12 with commit fb4584d2b324c522404c733c65840a1a6519ada8
	Issue introduced in 6.9 with commit aab5c6f200238ac45001bec3d5494fff8438a8dc and fixed in 7.0 with commit 16fdabe143fce2cbf89139677728e17e21b46c28

Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community.

Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at

	https://cve.org/CVERecord/?id=CVE-2026-31732

will be updated if fixes are backported, please check that for the most up to date information about this issue.

Affected files
==============

The file(s) affected by this issue are:
drivers/gpio/gpiolib.c

Mitigation
==========

The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits:

	https://git.kernel.org/stable/c/f0cf9c7b7c281956cc0dec163132cd96f76e1d60
	https://git.kernel.org/stable/c/fb4584d2b324c522404c733c65840a1a6519ada8
	https://git.kernel.org/stable/c/16fdabe143fce2cbf89139677728e17e21b46c28