All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: miquel.raynal@bootlin.com, richard@nod.at,
	"Chris Roy" <iam@thechris.in>,
	vigneshr@ti.com
Cc: syzkaller-bugs@googlegroups.com, linux-mtd@lists.infradead.org,
	joern@barelysecure.org, linux-kernel@vger.kernel.org,
	gregkh@linuxfoundation.org,
	syzbot+7cab6a19619f1b8efc00@syzkaller.appspotmail.com
Subject: Re: [PATCH v4] mtd: block2mtd: defer device open out of param/sysfs write
Date: Sun, 20 Sep 2026 19:03:48 +0000	[thread overview]
Message-ID: <20260920190348.B4D3B1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260920185132.1266699-1-iam@thechris.in>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] mtd: block2mtd: use-after-free and resource leak on init failure
- [High] mtd: block2mtd: sysfs lock inversion bypasses workqueue deferral
--

commit c3f3ebd86ecc63dd07e6a22d8527eadaeb761633
Author: Chris Roy <iam@thechris.in>

mtd: block2mtd: defer device open out of param/sysfs write

This patch defers block2mtd_setup() device opening to a dedicated ordered
workqueue to prevent lockdep-detected lock inversion between VFS and
kernfs/overlayfs during sysfs writes. The setup work is executed via a
dynamically allocated work item, preserving synchronous behavior with
wait_for_completion().

Closes: https://syzkaller.appspot.com/bug?extid=7cab6a19619f1b8efc00

> diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
> index 349fa07be314c..30ac9325bdd2b 100644
> --- a/drivers/mtd/devices/block2mtd.c
> +++ b/drivers/mtd/devices/block2mtd.c
[ ... ]
> @@ -461,31 +466,85 @@ static int block2mtd_setup2(const char *val)
[ ... ]
>  static int block2mtd_setup(const char *val, const struct kernel_param *kp)
>  {
[ ... ]
> +	if (setup_wq) {
> +		ret = block2mtd_setup_defer(val);
> +	} else {
> +		/* Not yet deferred to setup_wq; safe to call setup2 directly */
> +		mutex_lock(&list_mutex);
> +		ret = block2mtd_setup2(val);
> +		mutex_unlock(&list_mutex);
> +	}

[Severity: High]
Does evaluating setup_wq here bypass the workqueue deferral and re-introduce
the sysfs lock inversion?

Since mod_sysfs_setup() exposes module parameters to sysfs before
do_init_module() calls block2mtd_init(), setup_wq can be NULL during a
concurrent sysfs write.

This would cause the sysfs writer to execute block2mtd_setup2() inline under
the sysfs kernfs lock.

Additionally, since setup_wq is assigned in block2mtd_init() without memory
barriers (such as smp_store_release() and smp_load_acquire()), concurrent
sysfs writers might observe a stale NULL pointer even after initialization
completes.

> +
> +	kernel_param_lock(kp->mod);
> +	module_put(kp->mod);
> +	return ret;
>  }
>  
>  
> @@ -496,10 +555,17 @@ static int __init block2mtd_init(void)
>  {
>  	int ret = 0;
>  
> +	setup_wq = alloc_ordered_workqueue("block2mtd", 0);
> +	if (!setup_wq)
> +		return -ENOMEM;

[Severity: High]
Can returning -ENOMEM here lead to a use-after-free and resource leak?

If parameters are provided during module load
(e.g., insmod block2mtd.ko block2mtd=...), block2mtd_setup() is executed
before block2mtd_init(). Because setup_wq is NULL at that time, it
synchronously registers the MTD device in the block2mtd_setup() else branch
shown above.

If alloc_ordered_workqueue() subsequently fails here, it returns -ENOMEM and
aborts the module load.

The kernel frees the module memory without calling block2mtd_exit(), leaving
the registered MTD device holding dangling function pointers to the unloaded
module text.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260920185132.1266699-1-iam@thechris.in?part=1

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

      reply	other threads:[~2026-09-20 19:03 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 15:19 [syzbot] [fs?] possible deadlock in ovl_create_object (2) syzbot
2026-09-12 13:12 ` syzbot
2026-09-16 19:48 ` Chris Roy
2026-09-16 21:37   ` Chris Roy
2026-09-16 21:52     ` syzbot
2026-09-17  6:44       ` Chris Roy
2026-09-17  6:59         ` syzbot
2026-09-17  7:33         ` Greg KH
2026-09-17  7:58           ` Chris Roy
2026-09-17  7:58             ` Chris Roy
2026-09-17  8:13             ` syzbot
2026-09-17  8:13               ` syzbot
2026-09-17 18:15             ` Jörn Engel
2026-09-17 18:15               ` Jörn Engel
2026-09-19  7:42               ` AW: " Richard Weinberger
2026-09-19  7:42                 ` Richard Weinberger
2026-09-19  8:52                 ` Chris Roy
2026-09-19  8:52                   ` Chris Roy
2026-09-19  9:07                   ` syzbot
2026-09-19  9:07                     ` syzbot
2026-09-19 14:45                   ` Jörn Engel
2026-09-19 14:45                     ` Jörn Engel
2026-09-19 15:28                     ` Chris Roy
2026-09-19 15:28                       ` Chris Roy
2026-09-19 15:38                       ` Jörn Engel
2026-09-19 15:38                         ` Jörn Engel
2026-09-20 12:52                         ` Miquel Raynal
2026-09-20 12:52                           ` Miquel Raynal
2026-09-20 16:19                           ` Jörn Engel
2026-09-20 16:19                             ` Jörn Engel
2026-09-20 18:34                             ` Chris Roy
2026-09-20 18:34                               ` Chris Roy
2026-09-19 14:21                 ` AW: " Jörn Engel
2026-09-19 14:21                   ` Jörn Engel
2026-09-19 14:28                   ` Richard Weinberger
2026-09-19 14:28                     ` Richard Weinberger
2026-09-19 14:44                     ` Chris Roy
2026-09-19 14:44                       ` Chris Roy
2026-09-20 21:09                       ` AW: " Richard Weinberger
2026-09-20 21:09                         ` Richard Weinberger
2026-09-20 21:13                         ` Chris Roy
2026-09-20 21:13                           ` Chris Roy
2026-09-20 18:51 ` [PATCH v4] mtd: block2mtd: defer device open out of param/sysfs write Chris Roy
2026-09-20 19:03   ` sashiko-bot [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=20260920190348.B4D3B1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=iam@thechris.in \
    --cc=joern@barelysecure.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=richard@nod.at \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=syzbot+7cab6a19619f1b8efc00@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.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 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.