From: "NG, TZE YEE" <tze.yee.ng@altera.com>
To: Michael Walle <mwalle@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Pratyush Yadav <pratyush@kernel.org>,
Takahiro Kuwano <takahiro.kuwano@infineon.com>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: Re: [PATCH v3 0/2] mtd: spi-nor: fix use-after-free on unbind with open handles
Date: Fri, 20 Nov 2026 10:21:41 +0800 [thread overview]
Message-ID: <381b16ea-cc02-4504-bbe0-83762886b46b@altera.com> (raw)
In-Reply-To: <DMY8H2AUQ3LV.VQ3MVOE3YV41@kernel.org>
Hi Michael,
Thanks for taking a look.
On 18/11/2026 5:36 pm, Michael Walle wrote:
> Hi,
>
> On Wed Nov 18, 2026 at 9:07 AM CET, Tze Yee Ng wrote:
>> Gentle ping on this patch. Any chance for a review when you have time?
>
> I had a quick glance, and honestly, I really don't like all the
> reference and resource handling splattered all over the place.
I agree it is spread across spi-nor. It comes from one thing, which the
MTD core still uses the driver object after unbind, so spi-nor has to
keep that object and its data alive and fence its own operations.
> Also do we really need the low level kref_ handling?
A core-owned lifetime would avoid it. v2 tried that, with a release hook
and a removed flag in the core. Review found problems in that design:
the master can be freed inside __put_mtd_device(), the driver object
leaked with CONFIG_MTD_PARTITIONED_MASTER off, and a lockless removed
check raced with remove(). The kref in spi-nor is what works without a
larger change in the core; patch 1 is the only core change.
> And what about spi-nand and all the other MTD subsystems? They have the same
> problem, no?
>
> -michael
Yes. spinand allocates its object with devm_kzalloc() and frees it after
mtd_device_unregister(), and many other drivers that embed mtd_info do
the same. A generic fix belongs in the core, but it is a much larger
change that touches every MTD driver's lifetime rules.
I would prefer to keep this series as a spi-nor-only fix, since it
solves the problem for spi-nor today. James Hilliard's raw NAND series
[1] adds a generic opt-in lifetime to the core (mtd_set_release()). I
would be happy to look at moving spi-nor onto it if it lands, but maybe
in another series. Are you okay with keeping this series as is?
Thanks,
Tze Yee
[1]
https://lore.kernel.org/all/20261115-submit-rawnand-retained-handle-lifetime-v1-v5-0-cbc49c5c5e74@gmail.com/
prev parent reply other threads:[~2026-11-20 2:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 3:53 tze.yee.ng
2026-10-22 3:53 ` [PATCH v3 1/2] mtd: core: drop the module reference after ->_put_device() tze.yee.ng
2026-10-22 3:53 ` [PATCH v3 2/2] mtd: spi-nor: fix use-after-free on unbind with open handles tze.yee.ng
[not found] ` <SJ0PR03MB5950FE5D82CA5E77AAE0AC9CA17A2@SJ0PR03MB5950.namprd03.prod.outlook.com>
2026-11-18 9:36 ` [PATCH v3 0/2] " Michael Walle
2026-11-20 2:21 ` NG, TZE YEE [this message]
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=381b16ea-cc02-4504-bbe0-83762886b46b@altera.com \
--to=tze.yee.ng@altera.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=takahiro.kuwano@infineon.com \
/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
all inboxes | Powered by JetHome®