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=1796525127; b=Tfmx35sea4nmbtHxzV7OBJ1MmVZBj+8l/9q/71xJIvRPRfKdOXn1Fft/sOeSMVqmqDYB buhSq9BB7/bu2z763AdfuqpEPGDycivk9tBubzOs4nimb3lz3EGwWPkufBiyNu9nQIZIh WlP1N8G1S5UtXXH44B4ldMvYxvqn6nuT1iuc/3tmvuWN29YHhxyCAz02OgOQHDhlZ2s81 i+DvixQdu8pwMvnKPdVZaAm4WhFNAICAHmzLE9FHlgrTCZzsi9oBhTam3KaVJtF/pzhxA L1Pw21ZnymAFHyqhKuVp+1zeUzZB41wjw2WikUaegwDRxqp6T4M1mKbZTr8g712NxuQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796525127; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=rHZwSiQS3RAdP6iOp0dYRL7Kobjn1TV01WeMhRgiESU=; b=ERP9XWbOoRsT3tuKpzf9HRfsrOUO9BtfljIo0eVeMLUrhaorAHMpuZj75dmmr+Hxz6Yj aNWeRmxh1LyKuU0wBhF8/p6YVYs3AE0Zp6dTFzCAo9PhsudDpzVQDnoemKmCpf14R93Ob tEWVR0LuCgM6/wkndJyfLF9n93kYowHLcEL6HAyMH0PuBuoxoUHgwJr/IbMOrRfIX84VN 3+6/LomQmU7asWQ+e7pmkRSB9US6S+XMobuCVvBZ+JnQsWx3X8B2cAsnvcs8l9r1TWLDC iCKXXTbk9A9YBCHTex/T3PacgSIMkpmJuDY+s/LVQdfEImk9nWWVeWetU8n/1P25ZQQ== 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=QB4XReby; 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 DA95F606A337 for ; Sun, 6 Dec 2026 02:45:27 +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=QB4XReby Received: by smtp.kernel.org (Postfix) with ESMTPSA id 53D961F00A11; Sun, 6 Dec 2026 02:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796525127; bh=rHZwSiQS3RAdP6iOp0dYRL7Kobjn1TV01WeMhRgiESU=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=QB4XRebyGPS9ArNXtGscfVrFKbFsLUBfFNp/BjfXQUk3vqCqCd/5B0EL7OETKUT41 Jn3iJKkmLWv97iHkp3vhrvkUhno5Sp8E2mchWH2/NqReuVDBl994dlkxeEYSHVVLKo 2wA1md2vDr9SsZt3VtMhPmuK7vCqAyGQN6ORKMz2Zbi0ov/62I0vLpivjBzNoW/ENY 0juiHkABaj6Ml1F2A9Rpd2cPp0qFFvmpBNdPNL+X2gVhlkf99h8o8jd8E/1T7XVhBq oVbh8axw/WnuNZT1RzlqlBCWxPIPMaXdZ65o8L4x8XvHS1z8UpINL2vsf3voTP2/D4 +3puH0KY6ynrg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v17] can: j1939: fix "struct j1939_ecu" refcount leak Reply-To: sashiko-reviews@lists.linux.dev To: "Tetsuo Handa" , linux-can@vger.kernel.org Cc: "Marc Kleine-Budde" , "Oliver Hartkopp" , "Vincent Mailhol" , "Oleksij Rempel" In-Reply-To: <9118bc1c-d410-4db1-a19c-c522c18c2b03@I-love.SAKURA.ne.jp> References: <9118bc1c-d410-4db1-a19c-c522c18c2b03@I-love.SAKURA.ne.jp> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 02:45:26 +0000 X-Mailing-List: linux-can@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: - [Medium] can: j1939: missing rcu_barrier() in j1939_module_exit() for call_rcu() - [Medium] can: j1939: missing rcu_barrier() for __j1939_ecu_release() call_rcu() -- commit 72f10982ed821fa0b2b5d890bf51c72e33be31e3 Author: Tetsuo Handa can: j1939: fix "struct j1939_ecu" refcount leak This commit makes j1939_ecu_map_locked() a no-op once priv->rx_kref reaches zero and defers the body of __j1939_ecu_release() to an RCU callback via call_rcu(). Link: https://lore.kernel.org/all/ffdcdd9a-408b-40a0-bbb6-652900766b26@I-lo= ve.SAKURA.ne.jp/2-repro.c [1] Link: https://lore.kernel.org/all/aa93c245-399c-499b-a89e-dddefbf42fcb@I-lo= ve.SAKURA.ne.jp/4-repro.c [2] > diff --git a/net/can/j1939/bus.c b/net/can/j1939/bus.c > index eb9a3fd847f42..7f4f854e30296 100644 > --- a/net/can/j1939/bus.c > +++ b/net/can/j1939/bus.c > @@ -23,17 +23,24 @@ > */ > #define J1939_ECU_TIMER_RETRY_WARN 5 > =20 > -static void __j1939_ecu_release(struct kref *kref) > +static void __j1939_ecu_release_rcu(struct rcu_head *rcu) > { > - struct j1939_ecu *ecu =3D container_of(kref, struct j1939_ecu, kref); > + struct j1939_ecu *ecu =3D container_of(rcu, struct j1939_ecu, rcu); > struct j1939_priv *priv =3D ecu->priv; > =20 > - list_del(&ecu->list); > netdev_put(priv->ndev, &ecu->priv_dev_tracker); > kfree(ecu); > j1939_priv_put(priv); > } > =20 > +static void __j1939_ecu_release(struct kref *kref) > +{ > + struct j1939_ecu *ecu =3D container_of(kref, struct j1939_ecu, kref); > + > + list_del(&ecu->list); > + call_rcu(&ecu->rcu, __j1939_ecu_release_rcu); > +} [Severity: Medium] Can unloading can-j1939 crash with a use-after-free while __j1939_ecu_release_rcu() is still pending? j1939_module_exit() only calls can_proto_unregister() and unregister_netdevice_notifier(), neither of which waits for queued call_rcu() callbacks to execute. synchronize_rcu() only waits for RCU read-side critical sections to finish, so the module text can be unmapped before __j1939_ecu_release_rcu() runs on another CPU: CPU0 CPU1 j1939_sk_release() j1939_local_ecu_put() call_rcu(..., __j1939_ecu_release_rcu) j1939_netdev_stop() /* sleeps */ sock_put(sk) __sk_destruct() module_put(THIS_MODULE) rmmod can-j1939 j1939_module_exit() can_proto_unregister() synchronize_rcu() unregister_netdevice_notifier() /* module text unmapped */ __j1939_ecu_release_rcu() <-- use-after-free Adding rcu_barrier() to j1939_module_exit() (as in bcm_module_exit() and cgw_module_exit()) would drain pending callbacks before module unload. Also, the commit message under Problem 3 states that synchronize_rcu() in j1939_module_exit() can wait for __j1939_ecu_release_rcu() completion; that requires rcu_barrier() rather than synchronize_rcu(). [ ... ] > diff --git a/net/can/j1939/j1939-priv.h b/net/can/j1939/j1939-priv.h > index 5ed4f4b592e36..9e1380becab78 100644 > --- a/net/can/j1939/j1939-priv.h > +++ b/net/can/j1939/j1939-priv.h > @@ -43,6 +43,8 @@ struct j1939_ecu { > =20 > /* count users, to help transport protocol decide for interaction */ > int nusers; > + > + struct rcu_head rcu; > }; [Severity: Medium] Does fixing Problem 2 need call_rcu() deferral and struct rcu_head rcu in struct j1939_ecu at all? j1939_ecu_timer_handler() is the only j1939_ecu_put() caller that holds priv->lock without an independent priv reference. Taking a reference with j1939_priv_get(priv) before j1939_ecu_put(ecu) and releasing it after write_unlock(&priv->lock) fixes Problem 2 synchronously. Keeping call_rcu() widens the module-unload use-after-free window to seconds on CONFIG_RCU_LAZY=3Dy kernels unless j1939_module_exit() calls rcu_barrier(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/9118bc1c-d410-4db1-= a19c-c522c18c2b03@I-love.SAKURA.ne.jp?part=3D1