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=1796287417; b=eCxcDe7k4C4/Xm+cqMKLk2HRwy8Pf7qjzuhKGk196K7XW5y5EBPrL0C0YvnlOoYw3T1L B+Kzgd/Dkt7XHUcOvECtQb2gmjOLaUdttSTshH9yBnRaVmzYQYHSBKq3gLhsAkOudAtsH rEFeyOLw1IXvfAJI/rsdlINqt5sGUwh4vW+sJqVKUEgGTgvBvkOh4wTWq6M0XRKbm7DkZ 4wv8qAb6Xx6COh7Jbu1Gv8cvm/8i6rl9Dfjv81505OTGRDp356rkcgqNjMnQqFzvjaRUB fJ5cMgUtZjUEsufCwiXuspbO8jEItf9jyeUWDS1DU7MExePjlSULD7BcqbWVHWb3ejw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796287417; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=MiKtfpiSbIhBr/9jZ3SM6ywq1TIE7TtNOGoqRuyc2t8=; b=CRuXv2PtUDwkrn7KiOzgJFVwpVz4YV2JsnLVZuOKSC74VjAiGeZ2QxG2SYjv5nTAtSOS kXFGlMcyFAmBSjezf+EDANpOUtCu9yT8HRILved7DQCjfLgSpqy++tFuKy6MhWnvQw44v bM06ylF6zr6TU62wPHNKxUBEqpab7sCGQercoCwP1MvtHz9QWyvklFXN9jI2io3W5bYls WGTL02+jqwAGAQtTVDMDIwdwXj7F61w0Rk0pgVPg9FS+InrpbInboEjWbxqC4E9GHL0q0 zq/ndbzvbEmJaiCdKOf7OqmW2momorUCNbhtMaqVrazoR0XrZn0gafq/SfT5jXeumfg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bOTzU++s; 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 1D006606A322 for ; Thu, 3 Dec 2026 08:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bOTzU++s Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB3991F00893; Thu, 3 Dec 2026 08:43:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796287417; bh=MiKtfpiSbIhBr/9jZ3SM6ywq1TIE7TtNOGoqRuyc2t8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=bOTzU++s8UzA31l4W7cQEj9OaEaHU1vJgSd22k1PyRbECv2T8HKzLzVqyXEHqrd5G e17Immt8Ui8w9osmnuq6+QJmt+PzDFkVd4ZiHyU8s7Pm8rLsZYOUtcZCaQNREmITF2 cApqU7pD4BffG4KGzj6AO/FpsIGJvTlNPoSJiz4CSrxRrz15rZOR9gtAORGnB6f8UB CBka45R28V+D7qOta5X/FkkBy+FzLhsziVag76G0p+x8AYGivnjQq/vRoJWQezI0UC XT1d547wi+QACHR87aGEMR7tL5MaXN0LV6GIZsDkNGLQRb6BDKESqJCm3EEmyvP8pH 2EeIgX1zp7juQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] lib/sbitmap: test that free() clears alloc_hint and ws Reply-To: sashiko-reviews@lists.linux.dev To: "Wang Yibo" Cc: linux-scsi@vger.kernel.org In-Reply-To: <20261203083549.257985-1-wangyibo@kylinos.cn> References: <20261203083549.257985-1-wangyibo@kylinos.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 08:43:35 +0000 X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] lib/sbitmap: kunit tests fail and double-free without commit ddca9a368588 - [Medium] lib/sbitmap: KUNIT_EXPECT before second free allows double-free on failure -- commit 5850549a9d340c961f2a0bf4176c791ec3354fa2 Author: Wang Yibo lib/sbitmap: test that free() clears alloc_hint and ws This commit extends the sbitmap KUnit suite to check that sbitmap_free() clears alloc_hint and sbitmap_queue_free() clears ws, including repeated free calls on each object. Link: https://lore.kernel.org/r/20261202112938.a596225d374bdf002bd1ad81@lin= ux-foundation.org > diff --git a/lib/tests/sbitmap_kunit.c b/lib/tests/sbitmap_kunit.c > index 284dcb5d7188b..935d143316481 100644 > --- a/lib/tests/sbitmap_kunit.c > +++ b/lib/tests/sbitmap_kunit.c > @@ -45,6 +45,7 @@ static void sbitmap_test_init(struct kunit *test) > KUNIT_EXPECT_FALSE(test, sbitmap_any_bit_set(&sb)); > KUNIT_EXPECT_EQ(test, sbitmap_weight(&sb), 0U); > sbitmap_free(&sb); > + KUNIT_EXPECT_FALSE(test, sb.alloc_hint); [Severity: High] Does this commit depend on ddca9a368588 ("sbitmap: Clear alloc_hint and ws pointers after freeing"), which is missing from this branch? In this tree, sbitmap_free() leaves sb->alloc_hint non-NULL and sbitmap_queue_free() leaves sbq->ws non-NULL. Running the sbitmap KUnit suite here fails sbitmap_test_init(), sbitmap_test_free_clears_alloc_hint(), and sbitmap_test_queue_free_clears_ws(), and the repeated teardown calls double free sb.alloc_hint via free_percpu() and sbq.ws via kfree(), triggering WARN_ON_ONCE(1) in free_percpu() or slab corruption. This patch needs to be queued on top of ddca9a368588 ("sbitmap: Clear alloc_hint and ws pointers after freeing") so that neither the branch head nor git bisect runs these tests without the pointer-clearing fix. > @@ -285,6 +286,44 @@ static void sbitmap_test_iterate_set(struct kunit *t= est) > sbitmap_free(&sb); > } > =20 > +static void sbitmap_test_free_clears_alloc_hint(struct kunit *test) > +{ > + struct sbitmap sb; > + > + KUNIT_ASSERT_EQ(test, sbitmap_init_node(&sb, BITS_PER_LONG, -1, > + GFP_KERNEL, NUMA_NO_NODE, > + false, true), 0); > + KUNIT_EXPECT_TRUE(test, sb.alloc_hint); > + > + sbitmap_free(&sb); > + > + /* > + * alloc_hint is a __percpu pointer, so test it as a boolean, as in > + * sbitmap_test_init(). Clearing it makes repeated teardown safe, > + * which is what the scsi error-cleanup path relies on. > + */ > + KUNIT_EXPECT_FALSE(test, sb.alloc_hint); > + sbitmap_free(&sb); > + KUNIT_EXPECT_FALSE(test, sb.alloc_hint); > +} > + > +static void sbitmap_test_queue_free_clears_ws(struct kunit *test) > +{ > + struct sbitmap_queue sbq; > + > + KUNIT_ASSERT_EQ(test, sbitmap_queue_init_node(&sbq, BITS_PER_LONG, -1, > + false, GFP_KERNEL, > + NUMA_NO_NODE), 0); > + KUNIT_EXPECT_TRUE(test, sbq.ws); > + > + sbitmap_queue_free(&sbq); > + > + KUNIT_EXPECT_NULL(test, sbq.ws); > + /* Repeated teardown must not pass a stale ws to kfree(). */ > + sbitmap_queue_free(&sbq); > + KUNIT_EXPECT_NULL(test, sbq.ws); > +} [Severity: Medium] Can KUNIT_EXPECT_FALSE() and KUNIT_EXPECT_NULL() allow a double free if the tested invariant regresses? Unlike KUNIT_ASSERT_*(), KUNIT_EXPECT_*() records a failure and continues executing the test, and neither test checks sb.map (or sbq.sb.alloc_hint in sbitmap_test_queue_free_clears_ws()) before calling the second free. If a regression or incomplete backport leaves any of those pointers set, the second sbitmap_free() or sbitmap_queue_free() passes a dangling pointer to free_percpu(), kfree(), or kvfree() instead of aborting cleanly. Guarding the repeated teardown with KUNIT_ASSERT_FALSE() on alloc_hint and KUNIT_ASSERT_NULL() on map (and ws in sbitmap_test_queue_free_clears_ws()) would turn a failure into a clean KUnit abort. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203083549.2579= 85-1-wangyibo@kylinos.cn?part=3D1