From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A315B33DEE5 for ; Sat, 4 Jul 2026 15:48:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783180105; cv=none; b=nyywCD9fm4Bt96YdZb8FmQaFMdGfPVTFWFCdULLZyfadAH8+IADrGjs4Pcf8VcH2nWVjyCnRDUUlwbE2QJGM1P0rZ/TOjBw0O94kxAvyQ/BLqpIyMLKtk9RRgVsHAo/3uGrYWUutp02PDR1C4sC/F7efwZiEA4AF2aiTLPf9BQc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783180105; c=relaxed/simple; bh=Vo0/uthTCA9t/S1uhiavK6qelh2NJYHHNcX+iaTVo1U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KpLOAG1fed0vtkAJn2aDdg83cV23HY968g2+oCaWf9yXIb+D/nkiPDacDV2QJBdpkpRwK/GYwlutmjde9ESEZrKoloyC2pGZfd5fgBowA6auPflCGPgWcRl+0Zy2X8B/worX8D+nLt3/81l4cFzEoIfyYNg9h7FFfvQjtRL21ZE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k/++k5es; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k/++k5es" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-493d3135f62so2011075e9.2 for ; Sat, 04 Jul 2026 08:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783180102; x=1783784902; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VYulFp3SO5/MbqdqSCJYzK/afw2ecrlo9KeAU+Q8Zjg=; b=k/++k5eshOcbx+SUqawdsrMdhiduEMBZbcWBd6iYkQ9ptN3lHZ3nn6OfvgpZ3Y3Ibr eBTc9Wb48dGIFmyT9ipaqgDMmclvuU9nM5LFJgxnRxENUeKzpXcFlNH21orXTloEmGC0 3MGiA8HWhhkVD7cyVBP/KJo6Z+BldeFSHdP+Ltccz7rj5mn0QLLrwsJ7uS6SPzyG/G2l v7j2utBE1x9yOZYwqZswVPwa0hSUyJTlsGhvpQ1P9qBJbH/dG/7QJ9iyWcMQawC0BL7a r3lCxubu03uW5YRFSz3CiUzJ1nJANaMcwjRayNeoJ5/ITD/dMngImHuuGiN1Rvis3R14 5AfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783180102; x=1783784902; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VYulFp3SO5/MbqdqSCJYzK/afw2ecrlo9KeAU+Q8Zjg=; b=YGSHrLl8Y0lPvD8OtVbOHQVDkIkvKrS3XS+DuFbqr+cZx0AKfSedc28ZmRVYTLzRuw dWG2KUqvFRd5I5e+IS95eLH6zFgzet/1p2bY6ZpHbJGGbHhc34cj48P1MRDR9ZmoF5Sc b8dl1oi1+EGsL734wUab2kaaNhA83N7lq9SMTismMgaPK602Q7jZnl/TbvNL0gPobN3P Gmm+VdtHG8lSICjqlM/PWi8RvhYGoTG4AuDn6XLOr7pgNMcR3kjuf2D6C+BPAUb+H+yg y6TpNDroeRTaVte9uHr/AwHUalGYIH6Jb2kIvFw6fwyy+1HsFexipxPQ7//KJCFTzZPs 5/BQ== X-Forwarded-Encrypted: i=1; AFNElJ/yBx8zInPxVG/k4HZGI5VewdJJhd0V+vjlbG+Srq4CtYVsecVp+H1cKZOQKIiQiAib1wlVsGvCfwWb/rY=@vger.kernel.org X-Gm-Message-State: AOJu0YzLbCTo2WR5MpGT3UYOB6vLu1XZC7SYcJllmJLMBoylCyfK/SYx DKFbpW/V1quaoZ1HSO12LEPfXYY7GAl8tgqRR30ZIbsPQb0TciPP+pI= X-Gm-Gg: AfdE7ckx7FkC2LaMLGPiybh6C88dYsWLNYcEp0Usba+8wSr1tmBeBIV8ZlcY5g3jsRy depM8joppuT5Q//gpQ9uw3kgu3bBBhuWgST4X+Ldfd2i+ZAVfUGa3cneI4qMuJSyfA1w5AqRBTx mUasfWFwnK5u1MSp1QwLKskWxUiuX0lqXULTaTKfBjKvnTlbySNyC70rsgqLVAZm9MZxE/COIhO ZmEsGO/MfkvFbLk3fzP9HKz8L82qLk/X3Lj4bEFl9x9aCATvNKbTBsTnjdinC5xe0LtNrmQzihC eCRoRrg2R/FfDZ40hqEZ8v4SF7gK9mvXZGVxyg2bYVIt8vg5+W8R6Oi9yCVFlsmMN8lqZ/Ot60F MYCjXStLsuYSfvXrDj7Nut+C74uYbTKchscmtTVQIMvKmFyHYErcattdlGEJVuCcwqZBAzisqO4 QQ+sSiFXbt/reqfHRU4j7QnocDX5Ffc1yFJyyzUOFObygI8ZE9JDHLXnj2QibBi+lTwA== X-Received: by 2002:a05:600c:4e8a:b0:493:a960:a0bf with SMTP id 5b1f17b1804b1-493d11f3296mr44682275e9.21.1783180101792; Sat, 04 Jul 2026 08:48:21 -0700 (PDT) Received: from lithos ([2a02:810d:4a94:b300:ccc7:6431:13a2:5d53]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493c63172fesm381717435e9.0.2026.07.04.08.48.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jul 2026 08:48:21 -0700 (PDT) Date: Sat, 4 Jul 2026 17:48:16 +0200 From: Florian Fuchs To: Dmitry Torokhov Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Adrian McMenamin , linux-kernel@vger.kernel.org, Dmitry Torokhov , linux-input@vger.kernel.org, linux-mtd@lists.infradead.org, linux-sh@vger.kernel.org Subject: Re: [PATCH 18/26] sh: maple: introduce callback_mutex in maple_device Message-ID: References: <20260703-b4-maple-cleanup-v1-0-41e424964da5@gmail.com> <20260703-b4-maple-cleanup-v1-18-41e424964da5@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260703-b4-maple-cleanup-v1-18-41e424964da5@gmail.com> Hi Dmitry, On 03 Jul 22:57, Dmitry Torokhov wrote: > The Maple bus core invokes client callbacks asynchronously from a > workqueue (maple_dma_handler). If a device is removed (or closed) while > a callback is in flight, it can lead to UAF bugs if the driver's private > data is freed. > > Introduce callback_mutex in struct maple_device to synchronize > callback registration/modification and callback invocation. > > Assisted-by: Antigravity:gemini-3.5-flash > Signed-off-by: Dmitry Torokhov > --- > drivers/sh/maple/maple.c | 9 +++++++-- > include/linux/maple.h | 2 ++ > 2 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c > index c0715e3ace6f..7c82b7a8a280 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); > 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); > 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); > + } > atomic_set(&mdev->busy, 0); > wake_up(&mdev->maple_wait); > break; > diff --git a/include/linux/maple.h b/include/linux/maple.h > index 641cf3330409..48ed7558b8ab 100644 > --- a/include/linux/maple.h > +++ b/include/linux/maple.h > @@ -3,6 +3,7 @@ > #define __LINUX_MAPLE_H > > #include > +#include > #include > > /* Maple Bus command and response codes */ > @@ -75,6 +76,7 @@ struct maple_device { > char product_licence[64]; > atomic_t busy; > wait_queue_head_t maple_wait; > + struct mutex callback_mutex; > struct device dev; > }; > > > -- > 2.55.0.rc0.799.gd6f94ed593-goog > Thank you so much for your efforts. I can confirm sashikos finding in my test (that I saw later), that this patch hangs the bus if a VMU memcard is inserted. So that the peripherals don't work anymore after insertion of the memcard. With a last log like: Dreamcast_visual_memory 3:01.E: VMU at (3, 1) is busy Regards Florian