From: sashiko-bot@kernel.org
To: "Dmitry Torokhov" <dmitry.torokhov@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH 18/26] sh: maple: introduce callback_mutex in maple_device
Date: Sat, 04 Jul 2026 06:14:58 +0000 [thread overview]
Message-ID: <20260704061459.68F6C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260703-b4-maple-cleanup-v1-18-41e424964da5@gmail.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [Critical] The newly introduced callback_mutex causes a guaranteed self-deadlock when enumerating vmu-flash devices.
- [Medium] The newly introduced callback_mutex is initialized dynamically but is not destroyed during the standard device release lifecycle.
Pre-existing issues:
- [High] The patch fails to prevent the Use-After-Free race condition in the vmu-flash driver because vmu_disconnect bypasses the new callback_mutex.
--
commit 29c05632bf3bdcdb9087fb8230fb421ba8176ce5
Author: Dmitry Torokhov <dmitry.torokhov@gmail.com>
sh: maple: introduce callback_mutex in maple_device
This commit introduces callback_mutex in struct maple_device to synchronize
callback registration and invocation. It is intended to prevent
use-after-free bugs if a device is removed while a callback is in flight.
> diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
> index c0715e3ace6f1..7c82b7a8a2809 100644
> --- a/drivers/sh/maple/maple.c
> +++ b/drivers/sh/maple/maple.c
> @@ -121,6 +121,7 @@ void maple_getcond_callback(struct maple_device *dev,
> void (*callback) (struct mapleq *mq),
> unsigned long interval, unsigned long function)
> {
> + guard(mutex)(&dev->callback_mutex);
[Severity: Critical]
Does this introduce a self-deadlock when a callback registers a new callback?
When enumerating a vmu-flash device, maple_dma_handler() acquires
mdev->callback_mutex and executes the callback vmu_queryblocks().
Inside vmu_queryblocks(), the driver calls maple_getcond_callback() to
configure the next phase.
Since maple_getcond_callback() unconditionally attempts to acquire the
same non-recursive mdev->callback_mutex here, won't this immediately
deadlock the maple bus workqueue?
> dev->callback = callback;
> dev->interval = interval;
> dev->function = cpu_to_be32(function);
[ ... ]
> @@ -230,11 +231,13 @@ static struct maple_device *maple_alloc_dev(int port, int unit)
> mdev->dev.bus = &maple_bus_type;
> mdev->dev.parent = &maple_bus;
> init_waitqueue_head(&mdev->maple_wait);
> + mutex_init(&mdev->callback_mutex);
> return mdev;
> }
>
> static void maple_free_dev(struct maple_device *mdev)
> {
> + mutex_destroy(&mdev->callback_mutex);
[Severity: Medium]
Is a corresponding mutex_destroy() needed in the standard device release
path?
While mutex_destroy() is added to maple_free_dev() here, if a maple device's
reference count drops to zero after device_unregister(), the release
path maple_release_device() is executed.
Will this leave stale lockdep/RT-mutex structures behind if debugging
configs are enabled, since maple_release_device() does not destroy the
mutex before calling kfree(mdev)?
> kmem_cache_free(maple_queue_cache, mdev->mq->recvbuf);
> kfree(mdev->mq);
> kfree(mdev);
[ ... ]
> @@ -655,8 +658,10 @@ static void maple_dma_handler(struct work_struct *work)
> break;
>
> case MAPLE_RESPONSE_DATATRF:
> - if (mdev->callback)
> - mdev->callback(mq);
> + scoped_guard(mutex, &mdev->callback_mutex) {
> + if (mdev->callback)
> + mdev->callback(mq);
> + }
[Severity: High]
This is a pre-existing issue, but does this actually prevent the
use-after-free race condition for all drivers?
If a user unbinds a vmu-flash device while a maple data transfer is
in-flight, vmu_disconnect() bypasses this new mutex entirely:
drivers/mtd/maps/vmu-flash.c:vmu_disconnect() {
...
mdev->callback = NULL;
card = maple_get_drvdata(mdev);
...
kfree(card);
}
Since vmu_disconnect() modifies the callback and frees the private data
without acquiring callback_mutex, can maple_dma_handler() still
concurrently dereference the freed card data here?
> atomic_set(&mdev->busy, 0);
> wake_up(&mdev->maple_wait);
> break;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260703-b4-maple-cleanup-v1-0-41e424964da5@gmail.com?part=18
next prev parent reply other threads:[~2026-07-04 6:14 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 5:57 [PATCH 00/26] sh: maple: cleanup and modernize input drivers Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 01/26] sh: maple: include linux/device.h in linux/maple.h Dmitry Torokhov
2026-07-04 6:05 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 02/26] Input: maple_keyb - fix key press detection Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 03/26] Input: maplecontrol - only enable present axes Dmitry Torokhov
2026-07-04 6:10 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 04/26] Input: maplemouse - stop polling and clear callback on close Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 05/26] Input: maplecontrol " Dmitry Torokhov
2026-07-04 6:07 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 06/26] Input: maplecontrol - simplify maple_device retrieval in open/close Dmitry Torokhov
2026-07-04 6:10 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 07/26] Input: maple_keyb - implement open and close methods Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 08/26] Input: maplemouse - remove redundant drvdata resetting Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 09/26] Input: maple_keyb " Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 10/26] Input: maplecontrol " Dmitry Torokhov
2026-07-04 6:09 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 11/26] Input: maplemouse - remove unused mdev->driver assignment Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 12/26] Input: maplecontrol " Dmitry Torokhov
2026-07-04 6:06 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 13/26] Input: maple_keyb " Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 14/26] mtd: maps: vmu-flash: " Dmitry Torokhov
2026-07-04 6:08 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 15/26] sh: maple: remove not needed maple_unsupported_device driver Dmitry Torokhov
2026-07-04 6:11 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 16/26] sh: maple: remove unused driver field from struct maple_device Dmitry Torokhov
2026-07-04 6:09 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 17/26] sh: maple: implement bus-level probe/remove Dmitry Torokhov
2026-07-04 6:12 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 18/26] sh: maple: introduce callback_mutex in maple_device Dmitry Torokhov
2026-07-04 6:14 ` sashiko-bot [this message]
2026-07-04 15:48 ` Florian Fuchs
2026-07-04 23:50 ` Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 19/26] Input: maple_keyb - remove redundant mutex and remove method Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 20/26] Input: maple_keyb - convert to devm Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 21/26] Input: maplemouse " Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 22/26] Input: maplecontrol " Dmitry Torokhov
2026-07-04 6:13 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 23/26] Input: maple_keyb - fix style issues Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 24/26] Input: maplemouse " Dmitry Torokhov
2026-07-04 5:57 ` [PATCH 25/26] Input: maplecontrol " Dmitry Torokhov
2026-07-04 6:12 ` sashiko-bot
2026-07-04 5:57 ` [PATCH 26/26] Input: maple_keyb - remove redundant 'new' buffer from struct dc_kbd Dmitry Torokhov
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=20260704061459.68F6C1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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