From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1795948474; b=Nl3WClYDgTjzH11sNZv8ygnI47g0m0Q7GhjoWjaaNri/SBM4EX+Qlyrx+d21URYQmal3 N28xfB9AJkMnwltZ6A1s0ErsMBP3e/SAdjNtAaZm+O9gPqq6mn/BpN5VTaqLEZHqR6tzp mPl48QE90+NDA1QNO7qa33YJQIIt+KdV6SavYcqxDYguPmBbCORld20i2xIQJHBu1QTxi F5PCJ+ak7POjdJpF8yAdV0sIngxtUE43him01e3w5sqrlzbtXrqFKNk3xQ6r3QvqSVBkG K6PgkjN1Wvhxsbyh8+IW2mSlCRFrlTE71Fi+mJXNOZJ2vYHLYq3WolQjcCYiqFhBmwQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795948474; h=DMARC-Filter:Received:DKIM-Signature:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; bh=jUwRIDiLDmw3VGBOfV7Ix3a9BwgXzNa0JfR1glLeI+Q=; b=qpyw6aK9Edwww3vDJhmLB7Sdg4M9Y+kWD35KaTWaub4jzMxlvK+E8F+QbzB5IrT43c3b CFjKBlwJj0oIgJU8RQAyCj5vMUdFzivR29ZXOf/20O4SsSfo+0oyGRMi71nujVMlDxEz0 U9D1b3mRXQD3yWuSwYZ44wWrRY1AQc6VfyWKvbNSmNHoTeusgMaEt/x0/c4FC5WWtVSSJ RtLTrs4uRBrdX0aVRCfJMO8ukRamvGjloOwJUbFiY1ORKAShRM+xncxi85K0sbwPCWZNs 9E8YanwUMWkAcCHQsojkpprB6mZrTcAuOuXroEtoULhvG1+qW49/C+Py8nnwauUajgQ== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; dkim=pass header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=YCWRwBni; arc=pass header.oldest-pass=0 smtp.remote-ip=185.203.200.13 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0168606A323 for ; Sun, 29 Nov 2026 10:34:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0168606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pengutronix.de header.i=@pengutronix.de header.a=rsa-sha256 header.s=20260414 header.b=YCWRwBni Received: from ptx.office.stw.pengutronix.de (ptx.office.stw.4.pengutronix.de [10.9.0.3]) (Authenticated sender: relay-from-ptx.office.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 9989120245E; Sun, 29 Nov 2026 11:34:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1795948470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jUwRIDiLDmw3VGBOfV7Ix3a9BwgXzNa0JfR1glLeI+Q=; b=YCWRwBniI+4TsYalVeJbKoRZdQqbWX0oznFZoJCIsf3KAKfcG4fq7guSYlOpEZQtapwOAv UKvtctiO68foHgT29l75pI2T0cgSbPw95SupNv13CdgvLa7yh7teiqOOxIDG2KNs8LJgOw N1qth9uAfwhV69XPjcbyovUbNuDW9av4kGi20+TQma3eODXV/205cQBLv7tOD40B2nLTUY vGKXZDd7cMdpHEPTZgUtAGav6uWA39ljQ8mUF5fjKkuAxw73ilA9MbNbtOF5Fmpc+tHH/a UfNEy7+WH/KRqvs9ZirK2k/lc6+BttC7fm+UFZAH8+iZFrjZ1AJchCEKecUQ+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1795948470; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jUwRIDiLDmw3VGBOfV7Ix3a9BwgXzNa0JfR1glLeI+Q=; b=Bn1aNGULGKnTWgC55pkHHl5QNSmtZUM6utE7APojvv6S1nu4dc4NSOrnH22i8Bv7rxZX9t RjaEc9HgVa9N9L79/yt3ShN00MKYVMhJmt5HzYjswVqLxh7J5saCXpT4vcRYK4Q0khhut5 M3XLKAwuogbGLSiL+Vo1IXcAPdb9DX65kGdJjEXTCZMK1Te0wqSc7U7hE5uLMsL50rQmGJ mVcAImkOyVVTv7mPpRJ+gRTmY/3AC2iqiQPIPflJAqjiHhnWyGJ5uf/dF0gdFMAgQypCLN VdEmEoLxf8kJ6STBPhet4I99VOFV/bkx2/raXRWPiFcYpBGKAy1XElxQWrhY1A== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=relay-from-ptx.office.stw.pengutronix.de smtp.mailfrom=ore@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1795948470; a=rsa-sha256; cv=none; b=Q13spDZBC9QbyWIMRvakP4D1GjI/rZYTrCpuFnqA/rEN+pqx6p7jCojObFWyxr4B/ds3BR QHEfXEGJUNpy2FO5v9CwLP6qSPnxzJUClZXXZ+fqsh9Tm6ND/SCJhiSBxWcKAzIfOk/Cq4 HdvHfMrm9KfEJBv8QMSXoud2qv/QFUTGxtSW2pQtEfoI+S3YgZFd5DPQVdKjyAitKJ8i5m obP+UlgVtGablPf9JJuL/X3q2GvgvsiTae3CEpTr22wWdFzs+FA8yryqqmCNS/CUyOoCtY hfUDv9lDjBApibjQND0zyq8ejbkNTujmVay5ms7cJhSkdDqPBatc70I1YWeIFA== Received: by ptx.office.stw.pengutronix.de (Postfix, from userid 1058) id 8D8D71BF334; Sun, 29 Nov 2026 11:34:30 +0100 (CET) Date: Sun, 29 Nov 2026 11:34:30 +0100 From: Oleksij Rempel To: Tetsuo Handa Cc: linux-can@vger.kernel.org, Marc Kleine-Budde , Robin van der Gracht , kernel@pengutronix.de, Oliver Hartkopp Subject: Re: [PATCH v15 2/3] can: j1939: fix "struct j1939_ecu" refcount leak Message-ID: References: <98c16a74-5ea7-476e-ab36-c98fb77b6be4@I-love.SAKURA.ne.jp> X-Mailing-List: linux-can@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Hi Tetsuo, On Wed, Nov 18, 2026 at 12:57:19AM +0900, Tetsuo Handa wrote: > +static bool __must_check j1939_ecu_verify_get(struct j1939_ecu *ecu) > +{ > + struct j1939_priv *priv = ecu->priv; > + > + /* Don't get an ECU ref if netdev is no longer registered or > + * __j1939_rx_release() was called or __j1939_ecu_release() was > called. > + */ > + return READ_ONCE(priv->ndev->reg_state) == NETREG_REGISTERED && > + kref_read(&priv->rx_kref) && j1939_ecu_get(ecu); > +} Let's take the patches incrementally. I will take a deeper look at 1/3 later. Could you send 2/3 and 3/3 first, as a new small series? For that, this patch needs some rework, because it relies on 1/3. I guess a small priv->stopping flag would fit better than the reg_state and rx_kref checks. It can be set under priv->lock in __j1939_rx_release() before the ECUs are unmapped, and checked where the ECU gets mapped. Then this patch does not need the bool j1939_ecu_get() from 1/3, and a similar flag may help in other places later. One more problem without 1/3: once the map is skipped, the j1939_ecu_put() in the timer handler can free priv while priv->lock is still held, as far as I can see. I guess kfree_rcu() for priv is the natural fix here. The timer handler runs in softirq context, which is an RCU read-side section, so priv would stay valid until the handler returns. If kfree_rcu() works here, could you send it as a separate patch in the same series, before this one, also with Cc: stable? Then each step stays safe for bisecting, and stable does not pick up this patch without it. Please also say in the commit message how you tested the fix. maintainer-netdev.rst asks for this in every fix. If you have a reproducer, could you send it separately? It would help me to write a selftest for it. Regards, Oleksij