Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "A. Sverdlin" <alexander.sverdlin@siemens.com>,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function
Date: Thu, 19 Nov 2026 23:43:24 +0000	[thread overview]
Message-ID: <sashiko-outbox-224210@kernel.org> (raw)
In-Reply-To: <20261119232806.4093754-2-alexander.sverdlin@siemens.com>

Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] pinctrl: single: use-after-free in
  pcs_parse_one_pinctrl_entry() [1]
--

commit f9a80b7d4b1cc004ae636f5e91a037b0d6afbc93
Author: Alexander Sverdlin <alexander.sverdlin@siemens.com>

pinctrl: single: Also free the pinconf table of a duplicate function

This commit frees function->conf when pcs_parse_one_pinctrl_entry() drops
a duplicate function on consumer re-probe.

> diff --git a/drivers/pinctrl/pinctrl-single.c b/drivers/pinctrl/pinctrl-single.c
> index 52734bd7b7f06..95c8bd38459c8 100644
> --- a/drivers/pinctrl/pinctrl-single.c
> +++ b/drivers/pinctrl/pinctrl-single.c
> @@ -1102,6 +1102,7 @@ static int pcs_parse_one_pinctrl_entry(struct pcs_device *pcs,
>  	if (pinmux_generic_get_function(pcs->pctl, fsel)->data != function) {
>  		devm_kfree(pcs->dev, pins);
>  		devm_kfree(pcs->dev, vals);
> +		devm_kfree(pcs->dev, function->conf);
>  		devm_kfree(pcs->dev, function);
>  		devm_kfree(pcs->dev, pgnames);
>  	}

[Severity: Critical]
This problem wasn't introduced by this patch, but can the error path in
pcs_parse_one_pinctrl_entry() (and pcs_parse_bits_in_pinctrl_entry())
remove an already registered group and function [1] and cause a
use-after-free?

When a duplicate node is parsed, pcs_add_function() and
pinctrl_generic_add_group() return the existing selectors fsel and gsel.
If pcs_parse_pinconf() then fails, the error path unconditionally removes
both selectors from the core radix trees:

drivers/pinctrl/pinctrl-single.c:pcs_parse_one_pinctrl_entry() {
	...
	if (PCS_HAS_PINCONF && function) {
		res = pcs_parse_pinconf(pcs, np, function, map);
		if (res == 0)
			*num_maps = 2;
		else if (res == -ENOTSUPP)
			*num_maps = 1;
		else
			goto free_pingroups;
	}
	...
free_pingroups:
	pinctrl_generic_remove_group(pcs->pctl, gsel);
	*num_maps = 1;
free_function:
	pinmux_generic_remove_function(pcs->pctl, fsel);
	...
}

This deletes the original group and function descriptors while active
consumers still reference them, and leaks the duplicate function,
pgnames, and function->conf allocations.

[1] https://sashiko.dev/#/bug/linux-146c577c-dec4-4dc4-b28e-826c1cc76a9a

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119232806.4093754-1-alexander.sverdlin@siemens.com?part=1

  reply	other threads:[~2026-11-19 23:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 23:28 [PATCH 0/3] pinctrl: single: follow-up fixes from review A. Sverdlin
2026-11-19 23:28 ` [PATCH 1/3] pinctrl: single: Also free the pinconf table of a duplicate function A. Sverdlin
2026-11-19 23:43   ` sashiko-bot [this message]
2026-11-19 23:28 ` [PATCH 2/3] pinctrl: single: Don't remove deduplicated groups and functions on error A. Sverdlin
2026-11-19 23:28 ` [PATCH 3/3] pinctrl: single: Reject bit-per-mux without a usable function mask A. Sverdlin
2026-11-19 23:42   ` sashiko-bot

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=sashiko-outbox-224210@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexander.sverdlin@siemens.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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