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=1796115529; b=TWaXqjXKdMz7RvdFHxG0RipMtld9d4+339jiKcEgfCSBKmeNouyf5CVBCzChUjzXdMhF QasGVQi8DZDR7Lj5QpdNaePM8aUD0l4g/Ist4BOhudTBYs2H/M/i7qJ1QPbSL7pGMFVg0 C35jseRkkNbdrs6D9PVkBDvbRgfJAuF7lhbng8coj+I/7MjQeR+KAeBAG+vjXevuUENAG 58ALtS6QyBjZQ8znIqpldcdHPTnlkaZ0We8r1n4/clarfrPFAcHXRUuMV3CXl8wxdptDN 1iVvFSLz8+0tIK1C3A4y9vsHkzNy2IrKMMOKszf9imipZZDv9mqx7F1MvpqMtMqoHhg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796115529; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Tcq1J0PgUBs8kl+NWrpKrh8HqJd5Qgg7tNoZf/0ENsA=; b=MZrMddCkX4kuS51GOhwhbBNMHzS7SonPdMl+eqksPaLS0zhfHdvsKIHQlNgbZDRCj5t6 eOxus5GS5D1LbGsxIXA2/G0F6TDfzY0N1ttkkGu3aNxiB+DKaUb7lf1etAT5WYhqjcxgp Hc2Z6RmWlD7Efd81EJkw75ikuqFSnURHYwLmmyM221jA4TTrKkM/D6a2NPcCEd0c53qiV Q5FrrETjChgxKF2aWyz/WmnK8cWqcyBenD+vx2GYt1gkm6rUgG4eq4xwNVrySy2OSRZ33 IFVSsQrwYtgcRSCABuG3inqI494OgW4D5xeAfPldl5BbQ2gT0clIZH6WG0gQlA5fZxQ== 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=gFQKld4V; 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 DCC8C606A338 for ; Tue, 1 Dec 2026 08:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=gFQKld4V Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8280B1F0089F; Tue, 1 Dec 2026 08:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796115529; bh=Tcq1J0PgUBs8kl+NWrpKrh8HqJd5Qgg7tNoZf/0ENsA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gFQKld4V9MmsDM4fZ/YnY0KgcKEN0HyjhmMivT1EQpOF+QvbJ3xRGmDkuHetfLMGW h4DTXPR2kZXzhZPO0OxHsUW3LVNtJIQDk2FO+n8A7IsyI0tz5P8euy8f3njs5UNda9 1Xz4MgrijgTokwB0aG/1OA5OZFqhXyTC/JC/rp2xjAnMAie3ThlfOUY4T9IrUWtwtU f6zaGOU2yklMUmUlJluHPdOOe2NZwMhmw/2N4YPwkd7ri5osSBRASgnYOS+/x10Odj KMaBSHFrF4/KCgH2RYkiODRuMBkeZ9mJJuhlHyhhKo26uDimQRNB12y6Qkquzni2Np UN5ir1T++tVug== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] md: flush running sync_work in stop_sync_thread() Reply-To: sashiko-reviews@lists.linux.dev To: "Thanh Nguyen" Cc: linux-raid@vger.kernel.org, yukuai@fygo.io In-Reply-To: <20261201084150.1120-1-thanhnguyxntester@gmail.com> References: <20261201084150.1120-1-thanhnguyxntester@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 08:58:49 +0000 X-Mailing-List: linux-raid@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 1 potential issue to consider: - [Medium] md: unflushed re-queued sync_work after re-locking in stop_sync_thread() -- commit f4396ad9817951219df85157244681d0984e96d8 Author: Thanh Nguyen md: flush running sync_work in stop_sync_thread() This commit updates stop_sync_thread() to check work_busy() instead of work_pending() and to flush mddev->sync_work even when MD_RECOVERY_RUNNING is already cleared. > diff --git a/drivers/md/md.c b/drivers/md/md.c > index 47da9edc1c606..a1a4f4f76d349 100644 > --- a/drivers/md/md.c > +++ b/drivers/md/md.c > @@ -5211,8 +5211,14 @@ static void stop_sync_thread(struct mddev *mddev, = bool locked) > int sync_seq =3D atomic_read(&mddev->sync_seq); > =20 > if (!test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) { > - if (!locked) > + if (work_busy(&mddev->sync_work)) { > mddev_unlock(mddev); > + flush_work(&mddev->sync_work); > + if (locked) > + mddev_lock_nointr(mddev); > + } else if (!locked) { > + mddev_unlock(mddev); > + } > return; > } > =20 > @@ -5224,7 +5230,7 @@ static void stop_sync_thread(struct mddev *mddev, b= ool locked) > * never happen > */ > md_wakeup_thread_directly(&mddev->sync_thread); > - if (work_pending(&mddev->sync_work)) > + if (work_busy(&mddev->sync_work)) > flush_work(&mddev->sync_work); > =20 > wait_event(resync_wait, [Severity: Medium] Can mddev->sync_work be queued again after flush_work() returns and before stop_sync_thread() re-acquires reconfig_mutex? Both branches drop reconfig_mutex to flush mddev->sync_work (and in the second branch, flush_work() runs before wait_event(resync_wait, ...)) and do not re-check work_busy(&mddev->sync_work) after mddev_lock_nointr(mddev). On a read-only or read-auto array, md_check_recovery() does not check MD_RECOVERY_FROZEN before queuing sync_work when spares need change: drivers/md/md.c:md_check_recovery() { ... if (!md_is_rdwr(mddev) && !test_bit(MD_RECOVERY_NEEDED, &mddev->recovery)) goto not_running; if (!md_is_rdwr(mddev)) { if (md_spares_need_change(mddev)) { set_bit(MD_RECOVERY_RUNNING, &mddev->recovery); queue_work(md_misc_wq, &mddev->sync_work); } clear_bit(MD_RECOVERY_NEEDED, &mddev->recovery); goto not_running; } ... } This allows a newly queued md_start_sync() to hit the same use-after-free window during do_md_stop(): CPU0 (do_md_stop) CPU1 (md_thread / kworker) stop_sync_thread(mddev, true) mddev_unlock(mddev) flush_work(&mddev->sync_work) md_check_recovery() set_bit(MD_RECOVERY_RUNNING, ...) queue_work(..., &mddev->sync_work) md_start_sync() mddev_lock_nointr(mddev) goto not_running clear_bit(MD_RECOVERY_RUNNING, ...) mddev_unlock(mddev) mutex_unlock(&mddev->reconfig_mutex) mddev_lock_nointr(mddev) return /* MD_RECOVERY_RUNNING is clear */ mddev_unlock(mddev) mddev_put(mddev) ... -> mddev_free() md_wakeup_thread(mddev->thread) <-- use-after-free Should stop_sync_thread() re-check work_busy(&mddev->sync_work) and MD_RECOVERY_RUNNING after re-acquiring reconfig_mutex and loop back if a new sync_work was started while unlocked, similar to the retry loop in action_store()? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201084150.1120= -1-thanhnguyxntester@gmail.com?part=3D1