Received: from smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4848345CCE for ; Mon, 27 Jul 2026 23:08:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.188.122 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785193740; cv=none; b=l/YCUJSyz68zyMxFBW4lVUQV6O53zkD+3neqXCuav/VlQg0Tv4adPNc/ybNJY/+iezPotWYjpWQIVFaWp6Cwt1MnsQRn3qiGEnWXaLZc7a/JyzazVA7N0/OyvVr/uEPj7shJIwTY6Yu7Zqvn3E5etZlBhB54jXKUEKniSCNa0xA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785193740; c=relaxed/simple; bh=kFBoFI3ovsOmazUPqfuI6TkU7yBhOyx8WNBEZc17adI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VOAxd1pETSosDWv52UXWyu8nPrfoy7CR8u+o2WdVuKYh/FDR7E35pL+AZZYJ3T2nnldem9kIsY0Uljyeu8iTQZa0f8RaBfa7kCQglAODrk2cJJGEsC/nsR9SeiM8O7+7PjBjAplcV1KAEhWhaYlcN6Gf+wpXNGtEN9VM5qtzD50= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com; spf=pass smtp.mailfrom=canonical.com; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b=FUxyw4cq; arc=none smtp.client-ip=185.125.188.122 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=canonical.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=canonical.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (4096-bit key) header.d=canonical.com header.i=@canonical.com header.b="FUxyw4cq" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id E6662513B3 for ; Mon, 27 Jul 2026 23:08:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20251003; t=1785193735; bh=bW/r02SC9rjNA9QhLqccpMSlkFEvWcl+KQu1GCQNfXg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=FUxyw4cq7pBPKWO+1CuSp6H03X9Bx2ZW3AwWrn9WqsnJ9iiCsJeihw+YDgcbXUTz+ O/D6ufOtp12oH3r4/v7FpIL4HLd59h14N+A2Tw6OhN97XsdngWS+3LO1+SBSUgzljH u/73k79Kny9haRhAuQirr0dZOQ8aWYKB9276zVDAgOkmDq04JFOAYIpZk3IUeKRkBT RXYY5NlYcJIQfKvCDN+5m9G56adEJ6jpP6aMdqkPcI/1iP7EQXfQMRD0Dj1fWTkK1y Ydu0pCRaXWjIaVbybKa2Ni/ONnvK+nMnWil6FDJu4LoLInnFTHDhqNMUAyP+Ld2VSI Klvlt1/X5A6Wb3I1xIgD+4Ftnf3Yr0/7g3JJpr0FOGBGgs8xX9O7JUbKll6fzt983Z Af2R1Vw78qAjvm3qHmOQfY/naJt/lEXJ+sS2zEmBtV1cXa6lLXKIh/+Am0NScX6eWa 3Ro3b0kfitn7ejrg3a+foCoJZSQEfO4Nz6ZO71Imtz7QftK6KGhjcnVZiNzDgMMIo4 tRaBgkljPSFx1xSjmRn1b/XMxagOeIhYoagO7RJE/35MqhE9Mo/3W1vKVi/TpaeVUm TrgPpdSB9sQXZmDg+ybWcgZO/VmjXX5vW2RipUIcz878ZKOjmJZgxg7BeKGexx26kp dHn22+0L2riSzkN1uDUAK6js= Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-47f9ae25143so2729793f8f.2 for ; Mon, 27 Jul 2026 16:08:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785193735; x=1785798535; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bW/r02SC9rjNA9QhLqccpMSlkFEvWcl+KQu1GCQNfXg=; b=OawatPQz2luMeyoqwvyHfoG7v0skeziCbBgBVeFkXypn42WsvMdQJuHgopsnRmuVDE ebv6i7+xEfBu8Wo0CGSI+MKJxPBtLiPvHYXsCC8tiflhqs0OrzeXMzD4jXgM91Cfur0f loLlXuiFCrqmXWHSDsQEe+WKVhM2GZ0QhJsJSP5R9ri0QIxoEPhiTJLIU5kOQa2N15ph 6XvMQjESFW1RmLcjnqXa1NHltMtmmSyOkRqqqS95kOcV7Cpwlwr0wvXAJd0cg731kydD iEzrMALTX59oL8cxdpav37fBNDCEVjCq14aYrLqZ/CQgDeSYYKqiBc4jAriBihEqMar6 6Ueg== X-Gm-Message-State: AOJu0YwS2s5faw9FmHzB8OWMNLHwzFhG6c6mbZjTy171yuB9t3ftCeXg FEgsr9nVpA8zf6RhfgQNwLLK8nJLpLieky3BK3TsT5QG6mdCq86E3EE0BgtyisCfuXDfH6u0gFf JyBysBW7Qnf6HPCYk9qx38awqSJYFFk0wDvSMDHXHnH1KxKnoo/zUvHmbo3gLOqEXs4hnlN0xCa sMOHsOjF/PDm+fwg== X-Gm-Gg: AR+sD11x2gnYuU873RPDPFNOjyiJO29nasVTqpL+FAAma8/mTQp+/yWyiRgO5IP1Ph2 l0kXVNx6c8i2g/SxHJ1uBNv4TKBt+uAaoduep223G9sAKzlF5TH8FqDPa9BNaKQcJi3+KRkkQDT KoYYv3q8kxfQfGZN+JvlxjULFCnWMzfN1CQA76r/h9MRJG3WDJ/x+gKK65yxv9yfmEq2BAgM5jw X3YcRdBebBiIPOrwaiIcCcECrUsChAUCimQjDD/njPVIqy/3dmWwCUPYn+YGLmhNahW254JB2vl gXj3bRMnHfa0MCsntqJA2U+zEEyFJaBMnzlvAF6ikIKRdDrQHWKMnriGY9R4X/L+6H7PVB1MziE 4Tq0b X-Received: by 2002:a05:6000:1888:b0:47f:80e5:b98c with SMTP id ffacd0b85a97d-47f9fe98e82mr12937104f8f.36.1785193735437; Mon, 27 Jul 2026 16:08:55 -0700 (PDT) X-Received: by 2002:a05:6000:1888:b0:47f:80e5:b98c with SMTP id ffacd0b85a97d-47f9fe98e82mr12937071f8f.36.1785193734811; Mon, 27 Jul 2026 16:08:54 -0700 (PDT) Received: from localhost ([176.43.219.221]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f85c6f076sm53257849f8f.34.2026.07.27.16.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jul 2026 16:08:54 -0700 (PDT) From: Cengiz Can To: =?UTF-8?q?Marek=20Beh=C3=BAn?= Cc: linux-kernel@vger.kernel.org Subject: [PATCH] bus: moxtet: fix use-after-free in debugfs files on unbind Date: Tue, 28 Jul 2026 02:08:52 +0300 Message-ID: <20260727230852.469701-1-cengiz.can@canonical.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit moxtet exposes two debugfs files, "input" and "output", whose handlers dereference the per-device struct moxtet. They are created with debugfs_create_file_unsafe(), and the handlers never take a debugfs reference. Nothing keeps the object alive while a handler runs. The struct moxtet is allocated with devm_kzalloc(). devres frees it when the SPI device is unbound. debugfs_create_file_unsafe() installs no full_proxy wrapper, so debugfs_remove_recursive() in moxtet_remove() does not wait for an in-flight handler. moxtet_remove() then destroys moxtet->lock. A read or write that races an unbind therefore touches freed memory and unlocks a destroyed mutex: output_write() moxtet_remove() moxtet = file->private_data mutex_lock(&moxtet->lock) spi_write() [sleeps] moxtet_unregister_debugfs() debugfs_remove_recursive() [no wait] mutex_destroy(&moxtet->lock) (remove returns; devres frees moxtet) The race is reachable by root via /sys/bus/spi/drivers/moxtet/unbind. Create the files with debugfs_create_file() instead. Its full_proxy wrapper makes debugfs_remove_recursive() drain any in-flight handler before it returns, so the object cannot be freed under a handler. The mechanism is confirmed under KASAN with a minimal reproducer of the same debugfs_create_file_unsafe() plus devm_kzalloc() pattern (available on request); it produces a slab-use-after-free in the handler. Fixes: 5bc7f990cd98 ("bus: Add support for Moxtet bus") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4.8 Signed-off-by: Cengiz Can --- drivers/bus/moxtet.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/bus/moxtet.c b/drivers/bus/moxtet.c index 0d68c1a9f493..5087aa7d2e5b 100644 --- a/drivers/bus/moxtet.c +++ b/drivers/bus/moxtet.c @@ -560,13 +560,13 @@ static int moxtet_register_debugfs(struct moxtet *moxtet) if (IS_ERR(root)) return PTR_ERR(root); - entry = debugfs_create_file_unsafe("input", 0444, root, moxtet, - &input_fops); + entry = debugfs_create_file("input", 0444, root, moxtet, + &input_fops); if (IS_ERR(entry)) goto err_remove; - entry = debugfs_create_file_unsafe("output", 0644, root, moxtet, - &output_fops); + entry = debugfs_create_file("output", 0644, root, moxtet, + &output_fops); if (IS_ERR(entry)) goto err_remove; -- 2.43.0