mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Adrian Ambrozewicz <aambrozewicz@nvidia.com>
To: Tze Yee Ng <tze.yee.ng@altera.com>
Cc: linux-kernel@vger.kernel.org,
	Pratyush Yadav <pratyush@kernel.org>,
	Michael Walle <mwalle@kernel.org>,
	Takahiro Kuwano <takahiro.kuwano@infineon.com>,
	linux-mtd@lists.infradead.org,
	Miquel Raynal <miquel.raynal@bootlin.com>,
	Richard Weinberger <richard@nod.at>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Alexander Usyskin <alexander.usyskin@intel.com>
Subject: Re: [PATCH v3 1/2] mtd: core: drop the module reference after ->_put_device()
Date: Sat, 28 Nov 2026 09:05:19 +0200	[thread overview]
Message-ID: <20261128070518.3376508-2-aambrozewicz@nvidia.com> (raw)
In-Reply-To: <20261022035352.52129-2-tze.yee.ng@altera.com>

On Thu, Oct 22, 2026 at 11:53:51AM +0800, Tze Yee Ng wrote:
> __put_mtd_device() calls module_put() on the MTD owner and then calls
> ->_put_device(). If ->_put_device() frees the object that embeds the
> mtd_info, it is still running code from the owner module after the
> module reference is gone, so the module can be unloaded underneath it.

I hit the same window independently, with an out-of-tree MTD driver
whose ->_put_device() frees its state at the last put: a process holds
/dev/mtdN, the parent device is removed, rmmod is retried, the file is
closed. With msleep(200) after module_put() the close oopsed in the
freed module text in 6 of 6 tries, in 0 of 200 without the delay. With
this patch and the same delay after ->_put_device(), 25 of 25 delayed
and 200 of 200 plain tries ran clean (x86_64 QEMU, v7.3-rc6 plus
unrelated patches, KASAN, lockdep). In tree, mtd_intel_dg has the same
shape.

The order comes from 79c4a5625021, which stable took as a dependency:

Fixes: 79c4a5625021 ("mtd: call external _get and _put in right order")
Cc: stable@vger.kernel.org

Tested-by: Adrian Ambrozewicz <aambrozewicz@nvidia.com>

Adding the MTD maintainers and the author of 79c4a5625021.

  reply	other threads:[~2026-11-28  7:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22  3:53 [PATCH v3 0/2] mtd: spi-nor: fix use-after-free on unbind with open handles 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-11-28  7:05   ` Adrian Ambrozewicz [this message]
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
2026-11-20  8:12       ` Michael Walle
2026-11-25  8:09         ` NG, TZE YEE

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=20261128070518.3376508-2-aambrozewicz@nvidia.com \
    --to=aambrozewicz@nvidia.com \
    --cc=alexander.usyskin@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=takahiro.kuwano@infineon.com \
    --cc=tze.yee.ng@altera.com \
    --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

all inboxes | Powered by JetHome®