From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42E36337EB9; Wed, 17 Sep 2025 12:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113034; cv=none; b=tbMGVl55IcU5rG19jO4iMG0424aMrxHvGx7Dctya2X8ra9VUW9AE+2o9446h3Ujjs626uLroKPLARGlv69MhLLQCcrVEpAJ8DE51VO3B4moPEBMIxJ86caPlIwD1GyMLNbiOLr7ZY8nxhcVkTqfGaZJVYNP87Zsa1jBV0VoR14E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113034; c=relaxed/simple; bh=23TNJUGxj52Tda96FciMTwBSNtmc8pPSE+uKP7qhfN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=InYoIamaZxm9PV0H3ZUT+Bx+pMoWtJnWsNtQv9N4XcYx8ly2pcKIP1ZtcmVHqoH3DCqXpixap9PXNn0BAEe8AMJgu/tYWQ2OaIcFD4Xf0SvJsClrYInetQaEh25m8Fj/zH+adyhtF4c3dyfAm7KjmzvGXAl9rMGH0AZ9/sHOlAY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=O5uw6mF6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="O5uw6mF6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64BC4C4CEF0; Wed, 17 Sep 2025 12:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758113033; bh=23TNJUGxj52Tda96FciMTwBSNtmc8pPSE+uKP7qhfN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O5uw6mF6uvqef1bfkGAEnHX0m4e7BktB+0ge5+HNwD3TZV8YiYj30yPJ/u0KuPkb0 jB6tebMw6dE2RNHA0PauVtUkIpDGLTp4SpA496Xbr9m5Ad4Mqk5tOQH6f8Xs8FbJEg hyKyFs5y5d5IGin2xaACtozSHwIk3GOz6hN8JrPM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tetsuo Handa , Oleksij Rempel , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 6.16 149/189] can: j1939: j1939_sk_bind(): call j1939_priv_put() immediately when j1939_local_ecu_get() failed Date: Wed, 17 Sep 2025 14:34:19 +0200 Message-ID: <20250917123355.509037299@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250917123351.839989757@linuxfoundation.org> References: <20250917123351.839989757@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tetsuo Handa [ Upstream commit f214744c8a27c3c1da6b538c232da22cd027530e ] Commit 25fe97cb7620 ("can: j1939: move j1939_priv_put() into sk_destruct callback") expects that a call to j1939_priv_put() can be unconditionally delayed until j1939_sk_sock_destruct() is called. But a refcount leak will happen when j1939_sk_bind() is called again after j1939_local_ecu_get() from previous j1939_sk_bind() call returned an error. We need to call j1939_priv_put() before j1939_sk_bind() returns an error. Fixes: 25fe97cb7620 ("can: j1939: move j1939_priv_put() into sk_destruct callback") Signed-off-by: Tetsuo Handa Tested-by: Oleksij Rempel Acked-by: Oleksij Rempel Link: https://patch.msgid.link/4f49a1bc-a528-42ad-86c0-187268ab6535@I-love.SAKURA.ne.jp Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- net/can/j1939/socket.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c index b3a45aa70cf2f..785b883a1319d 100644 --- a/net/can/j1939/socket.c +++ b/net/can/j1939/socket.c @@ -520,6 +520,9 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len) ret = j1939_local_ecu_get(priv, jsk->addr.src_name, jsk->addr.sa); if (ret) { j1939_netdev_stop(priv); + jsk->priv = NULL; + synchronize_rcu(); + j1939_priv_put(priv); goto out_release_sock; } -- 2.51.0