Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alex Elder" <elder@riscstar.com>
Cc: linux-pci@vger.kernel.org, robh@kernel.org,
	devicetree@vger.kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 2/4] PCI: of: don't zero flags in of_pci_get_addr_flags()
Date: Tue, 01 Sep 2026 01:20:45 +0000	[thread overview]
Message-ID: <20260901012046.1BF371F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260901011338.1323243-3-elder@riscstar.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Potential NULL pointer dereference in of_pci_prop_compatible if kasprintf fails.
--

commit 036872e87dc6e9201c6f86349afb91815a638d1e
Author: Alex Elder <elder@riscstar.com>

PCI: of: don't zero flags in of_pci_get_addr_flags()

The flags variable whose address is passed to of_pci_get_addr_flags()
is zeroed before assigning a value to it.  Skip the zeroing and just
assign it instead.

> diff --git a/drivers/pci/of_property.c b/drivers/pci/of_property.c
> index 505226b876c56..22fea1905a080 100644
> --- a/drivers/pci/of_property.c
> +++ b/drivers/pci/of_property.c
> @@ -82,12 +82,10 @@ static int of_pci_get_addr_flags(const struct resource *res, u32 *flags)
>  	else
>  		return -EINVAL;
>  
> -	*flags = 0;
> +	*flags = FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss);
>  	if (res->flags & IORESOURCE_PREFETCH)
>  		*flags |= OF_PCI_ADDR_FIELD_PREFETCH;
>  
> -	*flags |= FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss);
> -
>  	return 0;
>  }

[Severity: High]
This is a pre-existing issue, but I noticed a potential null pointer
dereference in this file under low memory conditions.

Looking at of_pci_prop_compatible(), kasprintf() can fail and return a null
pointer:

drivers/pci/of_property.c:of_pci_prop_compatible() {
	...
	compat_strs[PROP_COMPAT_PCI_VVVV_DDDD] =
		kasprintf(GFP_KERNEL, "pci%x,%x", pdev->vendor, pdev->device);
	...
	ret = of_changeset_add_prop_string_array(ocs, np, "compatible",
						 compat_strs, PROP_COMPAT_NUM);
	...
}

If kasprintf() fails, the compat_strs array will contain a null pointer.
When this array is passed to of_changeset_add_prop_string_array(), it
unconditionally dereferences the strings to calculate their lengths:

drivers/of/dynamic.c:of_changeset_add_prop_string_array() {
	...
	prop.length = 0;
	for (i = 0; i < sz; i++)
		prop.length += strlen(str_array[i]) + 1;
	...
}

Would it be better to add a check for allocation failures in
of_pci_prop_compatible() before passing the array to
of_changeset_add_prop_string_array() to prevent this?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260901011338.1323243-1-elder@riscstar.com?part=2

  reply	other threads:[~2026-09-01  1:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  1:13 [PATCH v3 0/4] PCI: of: warn on bogus device_type property Alex Elder
2026-09-01  1:13 ` [PATCH v3 1/4] PCI: of: drop the reg_num argument to of_pci_set_address() Alex Elder
2026-09-01  1:16   ` sashiko-bot
2026-09-01  1:13 ` [PATCH v3 2/4] PCI: of: don't zero flags in of_pci_get_addr_flags() Alex Elder
2026-09-01  1:20   ` sashiko-bot [this message]
2026-09-01  2:42     ` Alex Elder
2026-09-01  1:13 ` [PATCH v3 3/4] PCI: of: introduce of_pci_verify_node() Alex Elder
2026-09-01  1:21   ` sashiko-bot
2026-09-01  2:42     ` Alex Elder
2026-09-01 17:32       ` Rob Herring
2026-09-02 12:54         ` Alex Elder
2026-09-01  6:11   ` Herve Codina
2026-09-01  1:13 ` [PATCH v3 4/4] of: address: kill of_node_is_pcie() Alex Elder
2026-09-01  1:18   ` sashiko-bot
2026-09-01  2:03     ` Alex Elder
2026-09-01  6:45   ` Herve Codina
2026-09-01 14:58     ` Alex Elder
2026-09-01 15:15       ` Herve Codina
2026-09-01 15:25         ` Alex Elder

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=20260901012046.1BF371F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=elder@riscstar.com \
    --cc=linux-pci@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