From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384909; b=2U6CgifBodNtEL8gL5JGsCkVS8Kf7hTQ6N7OliIqcXtWbpX4d69dN+y39o7m5PzAD54c NPZF024nvgUUHZgDE+CqgqBBAYuNpyl/0jPAGgmaRLBUJIcKWp9vA9UYIyiWd1h5NAD4b FxuharasmQ6BLt0PKQIVVjkk051am3Bp9HZ9YCz3jsiqZ75hJY/qbdWBQnd3mcXv3I3Fb Fx1m01JLnRMeCkYSdAKU/l/CT2PfV5yOc4FNWtge6NhFYSbtmA2b6nnsSAbW0utZsvITz gFIkDk1bbVx1Ppo1GdcZVufLrsp4b+zynpkNvixo6EYTeCcCV7aCieOiErCuffXCkqQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384909; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=YZoNuU2/P1/CUtNBvTKYaLzaJOplpeo9GCFINJ5PSiI=; b=o5/vBe7gFjdelrPKibkNOZ6V4k+kuPALbv0+RsUFJyotN9gsMS29F4rpCe1kj8Qmg2n2 A51mliXKRzL6dMfHaorebQFay7A/iJGqWM/IABu79FxU/LKBUv1ocOke2oBnYzY5+eMJE ZLgd2yfqGB86dGNxP4J61nUJP/STFzuOvWdBCU+/v7d4s3Y8y5sJnlGllUvk6jtnfvQZs wTb+QHgswRBI4cTWDXjYdsBRNweRGJGOM+9ovoLlnPXCutqCsvADJ03YM2Ntfljr5cl9t IBP45KukThwZlkNQp4NQn/WAEIZbjNr76PbwntNOjQYoXMwgsiY8ynDzdehzjfA+LWg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=F0r4qxHm; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B1CA606A32C; Fri, 4 Dec 2026 11:48:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=F0r4qxHm Received: by smtp.kernel.org (Postfix) with ESMTPSA id 908D21F000CE; Fri, 4 Dec 2026 11:48:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384909; bh=YZoNuU2/P1/CUtNBvTKYaLzaJOplpeo9GCFINJ5PSiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F0r4qxHm28TwyDFDhjHgGFWxG3U0PratZL5QHxuJvzltJuAQ80E+AlR+Nc2UrZEHe HgepJZqwiBIwC5oUF+bWoGK9nkGcSl273iBxsW2UCmXCuZHhvvZWRjtcYtj1tZGc/Q DYno9a8SU37cWiiuFLYIUIyiFi6CTWt3VYPQVCSk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yibo Tan , Joel Granados , Sasha Levin Subject: [PATCH 6.6 0344/1167] sysctl: unregister tables before freeing bitmap Date: Fri, 4 Dec 2026 18:56:11 +0900 Message-ID: <20261204100710.949960644@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yibo Tan [ Upstream commit 238dfe02fb0a9f72d7fd275d74ce80f13923ef31 ] The table registered for bitmap_0001 retains a pointer to test_data.bitmap_0001. unregister_sysctl_table() prevents new handlers from starting and waits for active handlers to finish. test_sysctl_exit() currently frees the bitmap before unregistering the table. A concurrent read during module removal can therefore enter proc_do_large_bitmap() while the bitmap is freed. KASAN reports a slab-use-after-free in _find_next_bit(). Unregister all tables before freeing the bitmap so the unregister rundown provides the required lifetime boundary. The unmodified module reproduced the use-after-free in three KASAN runs. With this change, three runs each completed 100 load, read and unload race rounds without a kernel diagnostic. Fixes: 2ea622b887e7 ("tools/testing/selftests/sysctl/sysctl.sh: add proc_do_large_bitmap() test case") Assisted-by: LLM Signed-off-by: Yibo Tan Signed-off-by: Joel Granados Signed-off-by: Sasha Levin --- lib/test_sysctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test_sysctl.c b/lib/test_sysctl.c index 8036aa91a1cbd..a56e0cdd4c528 100644 --- a/lib/test_sysctl.c +++ b/lib/test_sysctl.c @@ -241,13 +241,13 @@ module_init(test_sysctl_init); static void __exit test_sysctl_exit(void) { - kfree(test_data.bitmap_0001); if (sysctl_test_headers.test_h_setup_node) unregister_sysctl_table(sysctl_test_headers.test_h_setup_node); if (sysctl_test_headers.test_h_mnt) unregister_sysctl_table(sysctl_test_headers.test_h_mnt); if (sysctl_test_headers.test_h_mnterror) unregister_sysctl_table(sysctl_test_headers.test_h_mnterror); + kfree(test_data.bitmap_0001); } module_exit(test_sysctl_exit); -- 2.53.0