From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (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 9F01B38F251 for ; Sat, 4 Jul 2026 05:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783144685; cv=none; b=TAzIhaVzPhUZD+SZmGr76H/foPRhJTG7Swdp7B2h6ofW2ANtcyQr5oybfMNW2sYvX3cwYFbigQa7F6K1obO8YHLEDtymchzhU8HYiQipOOV8FOucgukwMk7Eg7uyoOf+DkE12Bq0zl8zh4neYfhAQxx70fTI2RKH21GzD2S0+Qw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783144685; c=relaxed/simple; bh=V7CkaRPOt1AB4wPWz8UHYq4OEut/rxvDywdfYXf8K4A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UqqMZTNGDgTdECAk0hMKVdAmXaPl9fjuR4F3hgs/mIrZBbwLRwrWRIJzqpFjuj0EeT9nsNxpeuZQL2zbigEYYb0+Tm0LzozLBKovYg4H5YJVAICaA4KaA7QTNjXiRTbFqlZXvscYCLDX2r2y8INyP1LgTNVYvMb26agbge/dEqE= 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=Z2DIkKEn; arc=none smtp.client-ip=209.85.216.50 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="Z2DIkKEn" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-383b4a3755fso384780a91.3 for ; Fri, 03 Jul 2026 22:58:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783144683; x=1783749483; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=uVPHekxxTvV9T4JJnXvyVv5aZspg0AcEDMfkFw+e5yg=; b=Z2DIkKEnmWmQdPCZy4SOgXji9aGF8gMC5wfYdELsK2ltymvfgvplRed4ohbVuV1w5Z xj9FXhsUyZF3fSrErQ2bfwvmmJVni/hz6+OLWX42Qs4xphe0Y2O6cNgFVIrv1L2FlYIv 8lNojS+YcyQa5Rm6mvehFyGdnqlSJCIimWpaGHHeNVpZgEfsrTXv0BD6EIu09720ngDv of7sSvrauL0SG5csBAbsLmxp9JHMCERZO/yOh1KzNqNtOejkwD8oPn/Cs/PTlfRR7fJT L1FXfazCUnxtR1Cr7efG8NOtoVueqbsUjCcNMBhl5I+Br4pnbr2kxisany3cNGQSuDFv eZhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783144683; x=1783749483; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=uVPHekxxTvV9T4JJnXvyVv5aZspg0AcEDMfkFw+e5yg=; b=BBVjPyDrhyOPR3kfrXYfv+pKyzjX7iPOarWClnGF5uXDc21P5i+KxsR/OrcftGgq0y nRpfGr1WokGmQyWKlbWL/be3BhehDJgamlvtl4DwoUs69cwDG0mKG288NluUYYdTA/Dg HSnCdVf478eh6CxmZSaCARDiyQEf8ceGiTRwPug93pg5/rTZkAnvy1LG0tw5HKOVv46Y KsHGqJ/KqF9EbkZxq/loIVYOukdax4xmZNjluY9X2aU+M0BHs3WGVDVQjGOVT3yGK0CC Z46qy6kE+J4vLY3RygW6IGnyq+G9w4Hbgfo/oso/6BxX1N1FUJWX+Q2ROnfeMPz+U3Yd vTAA== X-Forwarded-Encrypted: i=1; AHgh+RpZ4+ttSiCOsW8Y+ucGliGdaux45buU9VhK4xbn1N/eBu9MTCAJUx2vHX7IDe9/RtIuS8nmeyaKSNM0GJc=@vger.kernel.org X-Gm-Message-State: AOJu0YyIev1JRfq0DJQEW/xusdTOUyuV+iwNIrjz30pHcceK4Urz8bqG XgUNU6cfQ190u9EcVZqOoSdk+cm9lPbTWqpFVQPiCdkceZkw1GYtS1WBY7ghEA== X-Gm-Gg: AfdE7cmdv/RfECFG5qHK0A9lT7C98OpybHfUV5DdJR3Sr0GNSNzKR9irXBs/5WoRwnX kqg5AUO4x7V4pcFYDWNTMJUOVXLENYM1cwVGmWqlIvJ88tGYAoRHsMfH67kgqioaeE0Jxz8N0fv qF334Akx/+Rydi4tYtxsyvuhYGZEOnM+J0iFU61r3zlYaL4G2jNyLgWp0w/2N2OvnXwkWBOEOuR /G8Bfg2QBfBlQi+7IxRiUgCA7dfx5drhRl8gAtrUTPhQQdEEbpS5J5P2C5cJSoderNA1A9/nXWl EXYvBARtOPqEUMXz3xi4fZ+VHov1DxisICef5oL0ifu5RsD3jJx3KAphdcRtgYhNGBqzLsCCFSw 0ApBGUHiwN7rDezbTg1Vx+tv6gETM7V42qCsP5W6olwMm5HYhIIqhTu+QDBIe69xKnC8NtOGM48 54f1uLWfkm/1WjK88PBbVn4CBXsZSyZtbUNbNsn6sE5QWtiuvSyu2wHQzRv67Psyb1QkAn641oH tUBFkN6/4tptQ== X-Received: by 2002:a17:90b:224d:b0:381:e74f:8a6a with SMTP id 98e67ed59e1d1-3829eb1d7a8mr2296385a91.16.1783144682891; Fri, 03 Jul 2026 22:58:02 -0700 (PDT) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:880:86f9:3b00:6746]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-30f0b813cd9sm26262412eec.8.2026.07.03.22.58.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jul 2026 22:58:01 -0700 (PDT) From: Dmitry Torokhov Date: Fri, 03 Jul 2026 22:57:41 -0700 Subject: [PATCH 18/26] sh: maple: introduce callback_mutex in maple_device 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="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260703-b4-maple-cleanup-v1-18-41e424964da5@gmail.com> References: <20260703-b4-maple-cleanup-v1-0-41e424964da5@gmail.com> In-Reply-To: <20260703-b4-maple-cleanup-v1-0-41e424964da5@gmail.com> To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz Cc: Florian Fuchs , Adrian McMenamin , linux-kernel@vger.kernel.org, Dmitry Torokhov , linux-input@vger.kernel.org, linux-mtd@lists.infradead.org, linux-sh@vger.kernel.org X-Mailer: b4 0.16-dev-6911d 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