From: sashiko-bot@kernel.org
To: "Thierry Reding" <thierry.reding@kernel.org>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Haotian Zhang" <vulab@iscas.ac.cn>,
"Richard Weinberger" <richard@nod.at>,
"Stefan Agner" <stefan@agner.ch>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Lucas Stach" <dev@lynxeye.de>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
"Dmitry Osipenko" <digetx@gmail.com>,
"Boris Brezillon" <bbrezillon@kernel.org>
Cc: linux-tegra@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: tegra: fix OF node leak in tegra_nand_chips_init()
Date: Thu, 08 Oct 2026 18:34:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-164461@kernel.org> (raw)
In-Reply-To: <20261008182442.2770036-1-vulab@iscas.ac.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: rawnand: tegra: UAF due to premature of_node_put() before registration
--
commit 1cf3654f6b317262348cbad1bbf461282840058e
Author: Haotian Zhang <vulab@iscas.ac.cn>
mtd: rawnand: tegra: fix OF node leak in tegra_nand_chips_init()
This commit attempts to fix a device node leak by releasing np_nand right
after calling nand_set_flash_node().
> diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c
> --- a/drivers/mtd/nand/raw/tegra_nand.c
> +++ b/drivers/mtd/nand/raw/tegra_nand.c
[ ... ]
> @@ -1119,6 +1122,7 @@ static int tegra_nand_chips_init(struct device *dev,
> mtd->owner = THIS_MODULE;
>
> nand_set_flash_node(chip, np_nand);
> + of_node_put(np_nand);
[Severity: High]
Does this introduce a use-after-free risk for the device node?
The nand_set_flash_node() helper stores the pointer in mtd->dev.of_node
but does not increment its reference count. By dropping the reference here,
could the node be freed before subsequent accesses?
Later in this function, nand_scan() dereferences this flash node to read
properties:
drivers/mtd/nand/raw/nand_base.c:of_get_nand_bus_width() {
struct device_node *dn = nand_get_flash_node(chip);
...
ret = of_property_read_u32(dn, "nand-bus-width", &val);
...
}
Furthermore, mtd_device_register() will also access the node to increment
its refcount:
drivers/mtd/mtdcore.c:add_mtd_device() {
...
mtd_check_of_node(mtd);
of_node_get(mtd_get_of_node(mtd));
...
}
If dynamic DT unloading drops the final reference before
mtd_device_register() completes, it appears these later calls might access
freed memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008182442.2770036-1-vulab@iscas.ac.cn?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Thierry Reding" <thierry.reding@kernel.org>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Haotian Zhang" <vulab@iscas.ac.cn>,
"Richard Weinberger" <richard@nod.at>,
"Stefan Agner" <stefan@agner.ch>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Lucas Stach" <dev@lynxeye.de>,
"Jonathan Hunter" <jonathanh@nvidia.com>,
"Dmitry Osipenko" <digetx@gmail.com>,
"Boris Brezillon" <bbrezillon@kernel.org>
Cc: linux-tegra@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: rawnand: tegra: fix OF node leak in tegra_nand_chips_init()
Date: Thu, 08 Oct 2026 18:34:19 +0000 [thread overview]
Message-ID: <sashiko-outbox-164461@kernel.org> (raw)
In-Reply-To: <20261008182442.2770036-1-vulab@iscas.ac.cn>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] mtd: rawnand: tegra: UAF due to premature of_node_put() before registration
--
commit 1cf3654f6b317262348cbad1bbf461282840058e
Author: Haotian Zhang <vulab@iscas.ac.cn>
mtd: rawnand: tegra: fix OF node leak in tegra_nand_chips_init()
This commit attempts to fix a device node leak by releasing np_nand right
after calling nand_set_flash_node().
> diff --git a/drivers/mtd/nand/raw/tegra_nand.c b/drivers/mtd/nand/raw/tegra_nand.c
> --- a/drivers/mtd/nand/raw/tegra_nand.c
> +++ b/drivers/mtd/nand/raw/tegra_nand.c
[ ... ]
> @@ -1119,6 +1122,7 @@ static int tegra_nand_chips_init(struct device *dev,
> mtd->owner = THIS_MODULE;
>
> nand_set_flash_node(chip, np_nand);
> + of_node_put(np_nand);
[Severity: High]
Does this introduce a use-after-free risk for the device node?
The nand_set_flash_node() helper stores the pointer in mtd->dev.of_node
but does not increment its reference count. By dropping the reference here,
could the node be freed before subsequent accesses?
Later in this function, nand_scan() dereferences this flash node to read
properties:
drivers/mtd/nand/raw/nand_base.c:of_get_nand_bus_width() {
struct device_node *dn = nand_get_flash_node(chip);
...
ret = of_property_read_u32(dn, "nand-bus-width", &val);
...
}
Furthermore, mtd_device_register() will also access the node to increment
its refcount:
drivers/mtd/mtdcore.c:add_mtd_device() {
...
mtd_check_of_node(mtd);
of_node_get(mtd_get_of_node(mtd));
...
}
If dynamic DT unloading drops the final reference before
mtd_device_register() completes, it appears these later calls might access
freed memory.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261008182442.2770036-1-vulab@iscas.ac.cn?part=1
next prev parent reply other threads:[~2026-10-08 18:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-08 18:24 [PATCH] mtd: rawnand: tegra: fix OF node leak in tegra_nand_chips_init() Haotian Zhang
2026-10-08 18:24 ` Haotian Zhang
2026-10-08 18:34 ` sashiko-bot [this message]
2026-10-08 18:34 ` sashiko-bot
2026-10-09 6:10 ` Krzysztof Kozlowski
2026-10-09 6:10 ` Krzysztof Kozlowski
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-164461@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bbrezillon@kernel.org \
--cc=dev@lynxeye.de \
--cc=digetx@gmail.com \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-tegra@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=stefan@agner.ch \
--cc=thierry.reding@kernel.org \
--cc=vigneshr@ti.com \
--cc=vulab@iscas.ac.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.