From: Miquel Raynal <miquel.raynal@bootlin.com>
To: "Usyskin, Alexander" <alexander.usyskin@intel.com>
Cc: Richard Weinberger <richard@sigma-star.at>,
"Richard Weinberger (sigma star gmbh)" <rw@kernel.org>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>,
"NG, TZE YEE (Altera Corp)" <tze.yee.ng@altera.com>,
"horms@kernel.org" <horms@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"edumazet@google.com" <edumazet@google.com>,
"davem@davemloft.net" <davem@davemloft.net>,
"miklos@szeredi.hu" <miklos@szeredi.hu>,
"vigneshr@ti.com" <vigneshr@ti.com>,
"david.oberhollenzer@sigma-star.at"
<david.oberhollenzer@sigma-star.at>,
"upstream+linux@sigma-star.at" <upstream+linux@sigma-star.at>,
Richard Weinberger <richard@nod.at>,
"sashiko-reviews@lists.linux.dev"
<sashiko-reviews@lists.linux.dev>
Subject: Re: [PATCH 09/10] mtd: Implement MUSE - MTD in userspace
Date: Thu, 03 Dec 2026 11:54:49 +0100 [thread overview]
Message-ID: <87wlpqiqh2.fsf@bootlin.com> (raw)
In-Reply-To: <DM3PPF2B3CC4BE4E890F30D7A4FFF26467FED4B2@DM3PPF2B3CC4BE4.namprd11.prod.outlook.com> (Alexander Usyskin's message of "Thu, 3 Dec 2026 07:57:20 +0000")
On 03/12/2026 at 07:57:20 GMT, "Usyskin, Alexander" <alexander.usyskin@intel.com> wrote:
>> Subject: Re: [PATCH 09/10] mtd: Implement MUSE - MTD in userspace
>>
>> [Adding Miquel and Alexander]
>>
>> On Montag, 30. November 2026 10:14 sashiko-bot via upstream wrote:
>> > [Severity: Medium]
>> > Can module unload race with muse_mtd_put_device() when the last MTD
>> user
>> > exits after /dev/muse has already been closed?
>> >
>> > When /dev/muse is closed while mc->mtd_users > 0, muse_ctrl_release()
>> sets
>> > mc->want_exit = true without queuing mtd_exit_work, and __fput() drops
>> the
>> > file's reference on THIS_MODULE. When the last MTD user later closes the
>> > MTD device, __put_mtd_device() drops the final module reference before
>> > calling master->_put_device():
>> >
>> > drivers/mtd/mtdcore.c:__put_mtd_device() {
>> > ...
>> > module_put(master->owner);
>> >
>> > /* must be the last as master can be freed in the _put_device */
>> > if (master->_put_device)
>> > master->_put_device(master);
>> > }
>> >
>> > That allows a concurrent module unload to destroy muse_wq and unmap
>> the
>> > module before muse_mtd_put_device() queues mtd_exit_work:
>> >
>> > CPU0 CPU1
>> > __put_mtd_device()
>> > module_put(master->owner)
>> > delete_module()
>> > muse_exit()
>> > destroy_workqueue(muse_wq)
>> > rcu_barrier()
>> > muse_mtd_put_device()
>> > muse_remove_mtd_async(mc)
>> > queue_work(muse_wq, ...) <-- use-after-free
>>
>> I wondered why this can happen, then I found that mtdcore calls
>> module_put()
>> before ->_put_device().
>> This was introduced by commit 79c4a5625021 ("mtd: call external _get and
>> _put in right order").
>>
>> How can this be correct?
>>
>
> I suppose that was oversight in my patch - I've missed that
> module_put().
Same.
> There is a patch from Tze Yee Ng that fixes this:
> "[PATCH v3 1/2] mtd: core: drop the module reference after ->_put_device()"
> https://lore.kernel.org/all/20261022035352.52129-2-tze.yee.ng@altera.com/
I will take it through mtd/next (not fixes, I haven't sent the PR yet,
because I'm late, and introducing this kind of change at the last minute
is too risky).
Cheers,
Miquèl
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-12-03 10:55 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 8:26 [PATCH 0/10] MUSE: Userspace backed MTD v4 Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 01/10] fuse: Share cuse_parse_one() as fuse_kv_parse_one() Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 02/10] fuse: Add a public header for users outside of fs/fuse/ Richard Weinberger (sigma star gmbh)
2026-11-30 9:14 ` sashiko-bot
2026-11-30 11:05 ` Amir Goldstein
2026-11-30 11:28 ` Richard Weinberger
2026-11-30 8:26 ` [PATCH 03/10] fuse: Add an interface for userspace backed devices Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 04/10] fuse: Convert CUSE to the " Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 05/10] fuse: Allow three output arguments per request Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 06/10] fuse: Add MUSE specific defines to FUSE interface Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 07/10] mtd: Add MTD_MUSE flag Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 08/10] mtd: Allow passing a custom mtdparts string to the cmdline parser Richard Weinberger (sigma star gmbh)
2026-11-30 8:26 ` [PATCH 09/10] mtd: Implement MUSE - MTD in userspace Richard Weinberger (sigma star gmbh)
2026-11-30 9:14 ` sashiko-bot
2026-12-03 7:50 ` Richard Weinberger
2026-12-03 7:57 ` Usyskin, Alexander
2026-12-03 10:54 ` Miquel Raynal [this message]
2026-11-30 8:26 ` [PATCH 10/10] MAINTAINERS: Add entry for MUSE Richard Weinberger (sigma star gmbh)
2026-11-30 11:08 ` Amir Goldstein
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=87wlpqiqh2.fsf@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=alexander.usyskin@intel.com \
--cc=davem@davemloft.net \
--cc=david.oberhollenzer@sigma-star.at \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miklos@szeredi.hu \
--cc=pabeni@redhat.com \
--cc=richard@nod.at \
--cc=richard@sigma-star.at \
--cc=rw@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tze.yee.ng@altera.com \
--cc=upstream+linux@sigma-star.at \
--cc=vigneshr@ti.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