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=1796382173; b=4ypFkpqEnGpTK/jg5RKiVwhCqDJmzHOR2gGpNW4F41L8ju92+6eLot4ZzQD11vcAXDE5 3yE/PKXEOv2N25ttypfO/bXe9o/5Tyl8h9sLGd6hiB5IAGKdRcFRsDCCIZnZUZpIe4xUh rIGz1RNnlbcGaPkKTq61xOiXxMyBpj+Tl2vkFAkLFL8ry3MeOFVohTDAt1PV0ol6JTbN2 KhseasPqGFcpZ6ku8RtITJGQRq7Soiu7xo5aipNts86XeX6I3frmSsi21uAAAcivS5WjC lJEM49RSv69IeLW78TcWlO1bJoh62UFmd+QkZCgC3yRSYq77Wl9+gjw8I1GD6MFkJYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382173; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=/IpFnAHHbP6D8vb0yVmRhO6Mb+GgRFyDwGdfXZkJyfQ=; b=NtHiSwL2hLS+y7OovfSo3Mvqet7jfP7Xg9H7vFEmuuxrRc3cpO1hBPBb/Q7HvEZ3QE32 SfYEo8IGtKRtydo2AJF3nm/NHHP7z1Py4ZC6sb8LANmLziTKRJ/Bs8NnWkhZDspG8yIGK WgrKtHyYhNx7Et7fdq3AYP45P+LfB/tH1BYZtzsGfqHK0sZIi1IqZKzFW/Hkf1STMAyjO G4CkcPftBILDxoPUDsoBivY3noncCDwxotRo+mizL5oW9J68VRy/Iz/YuaAKBx4OWAaIy q+wJ2Ctza4ibZfjKQ95cK4/KhtosNowlI/rtVjK07+e5PVC0Zj/b5yn+jqBJYEiUNJQ== 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=gvy1is8k; 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 73DD2606A332; Fri, 4 Dec 2026 11:02:53 +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=gvy1is8k Received: by smtp.kernel.org (Postfix) with ESMTPSA id D66971F000CE; Fri, 4 Dec 2026 11:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796382173; bh=/IpFnAHHbP6D8vb0yVmRhO6Mb+GgRFyDwGdfXZkJyfQ=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=gvy1is8k3ib13PxuSyXa2na8RcKGkKfEscZDo5t3SCBdxRy/jYevLoPlbBGktTlNi 0Nk6HOKf++YTD2mXQgHBJMJ58y0DVVhfrDk+WJH3r8oaYjaMREzUu9evbq6iwwEQy2 ovteQc4huudJ5KuUnx5EjejSm8Dydp17VZUBd+xMT5Fsnnt2Zh0TlDtdrbxiCYyAvm Kjj2QJf6dHEPA+0+EVU/1es6SoT5du8ExtNMi/5y7gxfFk/CiA0MIfOT2+lYmrjOF+ EW1M9sAzS+X05delkFDAFC6cmTLCTnFKCENp1N2zFMwYzQa82dJC7ltoPYFE27XUIZ aU8PzaltMTpmQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] module: drain external refs before freeing a failed-init module Reply-To: sashiko-reviews@lists.linux.dev To: "Mahanta Jambigi" Cc: linux-modules@vger.kernel.org, linux-s390@vger.kernel.org, "Petr Pavlu" , "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261204104104.1711861-1-mjambigi@linux.ibm.com> References: <20261204104104.1711861-1-mjambigi@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 11:02:52 +0000 X-Mailing-List: linux-s390@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 4 potential issues to consider: - [Medium] module: non-freezable fixed msleep(20) drain loop in do_init_module() - [Medium] module: premature idempotent_complete() before drain check and free_module() - [Medium] module: atomic_sub_return() underflow re-enables try_module_get() - [Medium] module: missing acquire ordering in do_init_module() refcnt drain loop -- commit 996c0173d26a483c9d16420ac5d9f3674b09cd43 Author: Mahanta Jambigi module: drain external refs before freeing a failed-init module This commit drains external module references on init failure in do_init_module() before running MODULE_STATE_GOING teardown and free_module(), while completing idempotent finit_module() waiters before the wait. Link: https://lore.kernel.org/linux-modules/85cb4573-32dd-44fd-a034-12372a3= 62aa0@linux.ibm.com/ > diff --git a/kernel/module/main.c b/kernel/module/main.c > index 6052baf1be891..d3744f17dd098 100644 > --- a/kernel/module/main.c > +++ b/kernel/module/main.c [ ... ] > @@ -3230,6 +3236,52 @@ static noinline int do_init_module(struct module *= mod) > mod->state =3D MODULE_STATE_GOING; > synchronize_rcu(); > module_put(mod); > + > + /* > + * Release idempotent loads before waiting below, so a failed init > + * delays only the task that ran it. > + */ > + if (idem) > + idempotent_complete(idem, ret); [Severity: Medium] Should idempotent_complete() only run when references actually need to be drained? Calling it unconditionally here wakes and unhashes coalesced finit_module() waiters before MODULE_STATE_GOING teardown and free_module() finish, even in the common zero-reference failure case and when CONFIG_MODULE_UNLOAD is disabled. An immediate retry of finit_module() can then hit module_patient_check_exists() and fail with -EBUSY while the module is still linked. Concurrent finit_module() calls arriving during teardown also miss idem_hash coalescing and repeat file loading and validation before failing with -EBUSY, and delete_module() on a dependency can fail with -EWOULDBLOCK until module_unload_free() runs. Moving idempotent_complete() inside the CONFIG_MODULE_UNLOAD drain branch would keep the previous post-free_module() ordering whenever no wait occurs. > + > +#ifdef CONFIG_MODULE_UNLOAD [ ... ] > + if (atomic_sub_return(MODULE_REF_BASE, &mod->refcnt) > 0) { [Severity: Medium] Can atomic_sub_return() underflow mod->refcnt from 0 to -1 and allow a racing try_module_get() to succeed? If a buggy mod->init() calls an extra module_put(), the module_put(mod) above drops mod->refcnt to 0 without warning, and atomic_sub_return() then sets it to -1. Because try_module_get() uses atomic_inc_not_zero(), a non-RCU caller such as bpf_get_raw_tracepoint_module() (unlinked later in the MODULE_STATE_GOING notifier) can increment -1 back to 0 and return true while the module is freed: CPU0 CPU1 do_init_module() bpf_get_raw_tracepoint_module() mod->init() (extra module_put) try_module_get(mod) module_is_live(mod) -> true mod->state =3D MODULE_STATE_GOING synchronize_rcu() module_put(mod) (refcnt=3D0) atomic_sub_return(...) (refcnt=3D-1) atomic_inc_not_zero() -> true free_module(mod) use mod <-- use-after-free Using atomic_dec_if_positive(&mod->refcnt) keeps refcnt clamped at 0 so atomic_inc_not_zero() stays closed, while still returning -1 to skip the drain loop. > + unsigned long start =3D jiffies; > + unsigned long warn_at =3D start + msecs_to_jiffies(10 * 1000); > + bool warned =3D false; > + int refs; > + > + while ((refs =3D atomic_read(&mod->refcnt)) > 0) { [Severity: Medium] Does atomic_read(&mod->refcnt) need acquire ordering here to pair with atomic_dec_if_positive() in module_put()? On weakly ordered architectures, a control dependency after a relaxed atomic_read() does not order subsequent loads. Teardown right after the loop, such as srcu_module_going() reading srcu_readers_active(ssp), can observe stale pre-put state and trigger a spurious WARN_ON() or leak per-CPU memory. Using atomic_read_acquire(&mod->refcnt) in the loop condition would provide the needed acquire barrier. > + if (!warned && time_after(jiffies, warn_at)) { > + pr_warn("%s: init failed but %d reference(s) are still held after 10= s\n", > + mod->name, refs); > + warned =3D true; > + } > + msleep(20); > + } [Severity: Medium] Can polling indefinitely with msleep(20) block system suspend and hibernation? msleep() sleeps in TASK_UNINTERRUPTIBLE without TASK_FREEZABLE, so try_to_freeze_tasks() times out and aborts suspend with -EBUSY. A userspace holder frozen first cannot release the reference while the loader waits, and a leaked reference blocks suspend until reboot. Sleeping without TASK_NOLOAD also inflates the load average by 1 during the wait, and fixed 20 ms polling without backoff generates 50 Hz wakeups indefinitely. Sleeping in TASK_IDLE | TASK_FREEZABLE with schedule_timeout() and backing off the interval would avoid all three. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204104104.1711= 861-1-mjambigi@linux.ibm.com?part=3D1