Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>
Cc: devicetree@vger.kernel.org, linux-gpio@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v4 05/10] of: property: implement the .property_get_names() fwnode operation
Date: Thu, 26 Nov 2026 09:47:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-235177@kernel.org> (raw)
In-Reply-To: <20261126-fwnode-for-each-prop-v4-5-d4b370ecfd52@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] of: property: unlocked two-pass walk in
  of_fwnode_property_get_names()
--

commit 3a7bcd3a492086f46b1c6bb63542015b4decd0a4
Author: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

of: property: implement the .property_get_names() fwnode operation

This commit implements the .property_get_names() fwnode operation for Open
Firmware device nodes.

> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 51db25cbcd4e8..00349e78fa514 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c

[ ... ]

> @@ -1120,6 +1120,37 @@ of_fwnode_property_read_string_array(const struct fwnode_handle *fwnode,
>  		of_property_count_strings(node, propname);
>  }
>  
> +static int of_fwnode_property_get_names(const struct fwnode_handle *fwnode,
> +					char ***props)
> +{
> +	const struct device_node *node = to_of_node(fwnode);
> +	struct property *prop;
> +	int count = 0, i = 0;
> +	char **names;
> +
> +	for_each_property_of_node(node, prop)
> +		count++;
> +
> +	if (count == 0)
> +		return 0;
> +
> +	names = kcalloc(count, sizeof(*names), GFP_KERNEL);
> +	if (!names)
> +		return -ENOMEM;
> +
> +	for_each_property_of_node(node, prop) {
> +		names[i] = kstrdup(prop->name, GFP_KERNEL);
> +		if (!names[i]) {
> +			kfree_strarray(names, i);
> +			return -ENOMEM;
> +		}
> +		i++;
> +	}
> +
> +	*props = names;
> +	return count;
> +}

[Severity: Medium]
Can this unlocked two-pass walk over node->properties race with concurrent
property mutations (e.g. via of_add_property(), of_remove_property(), or
overlay changesets) and write past the end of names[]?

CPU0                                     CPU1
of_fwnode_property_get_names()
  for_each_property_of_node()
    /* counts N properties */
  names = kcalloc(N, ...)
                                         of_add_property()
                                           mutex_lock(&of_mutex)
                                           __of_add_property()
                                             /* list now has N + 1 */
                                           mutex_unlock(&of_mutex)
  for_each_property_of_node()
    names[N] = kstrdup(...)  <-- out-of-bounds heap write

Live property list mutations are serialized by of_mutex and devtree_lock,
while of_fwnode_property_get_names() walks node->properties twice without
holding either lock and sleeps in GFP_KERNEL allocations.

If a property is removed between the two passes instead, the second loop
populates fewer than count entries and leaves trailing NULL pointers in
names[] while still returning count, which causes
fwnode_property_get_names() to pass NULL to strcmp().  If the current
property is removed or updated while kstrdup() sleeps,
__of_remove_property() redirects prop->next to node->deadprops, causing
the traversal to jump onto the deadprops list.

Acquiring of_mutex around the counting and copying passes would prevent
concurrent property list mutations across the two loops.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126-fwnode-for-each-prop-v4-0-d4b370ecfd52@oss.qualcomm.com?part=5

  reply	other threads:[~2026-11-26  9:47 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:36 [PATCH v4 00/10] gpio: make gpiolib-shared more fwnode-centric Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 01/10] lib: string_helpers: export and rename struct strarray Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 02/10] lib: string_helpers: implement a CLASS() for string arrays Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 03/10] fwnode: define the property_get_names() operation Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 04/10] device property: provide fwnode_property_get_names() Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 05/10] of: property: implement the .property_get_names() fwnode operation Bartosz Golaszewski
2026-11-26  9:47   ` sashiko-bot [this message]
2026-11-26  9:36 ` [PATCH v4 06/10] fwnode: define the count_references() " Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 07/10] device property: provide fwnode_property_count_references() Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 08/10] of: property: implement the count_references() fwnode operation Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 09/10] gpio: shared: remove unused field from struct gpio_shared_entry Bartosz Golaszewski
2026-11-26  9:36 ` [PATCH v4 10/10] gpio: shared: generalize most code to firmware nodes Bartosz Golaszewski

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-235177@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=robh@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