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 77764323419; Wed, 17 Sep 2025 12:51:37 +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=1758113497; cv=none; b=rXQiyXludCNTL/PabKP7Bi2y13F/aF0wyTnFUrz6Wadcwywpuy7N+banejtqkpxRbTuTzw8VhHL72YRN2iXl0b0+pqPuomBYb/uPe0jfoBtpBybRchg+mjmNQE525e31njESqHuHRurplO5PVtHYPX7btudg236jm9Fa0qv9lhQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113497; c=relaxed/simple; bh=MaWTAwqWMXQeR+J67IZmRkS8UDckMifA+XDz2Pqj39I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=peFMUNF+7OFegM/0qJA8HyG2j9r6HcywdAyA8WZ08PnpfwGI1f5GC7Js2QLvZ8vKlIKLwhipEmGqPlrgp2/9wv1ka3ELtl5XtgLyEn8SbHM0CRv3UrpJOVX+bmig29fTonRfc+O9veSAh6HDzSeY6zKomirRkoJ34m5rbGj4Ydw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Q8IqCJFU; 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="Q8IqCJFU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEF2EC4CEF0; Wed, 17 Sep 2025 12:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758113497; bh=MaWTAwqWMXQeR+J67IZmRkS8UDckMifA+XDz2Pqj39I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q8IqCJFUPZ+647vPD8SLG5My7voZ+fOWknnEVasRyubWvVPgiWo0k6nYvGEIzJki7 Pnwr+USZnwZG3JD6ffpg9d+AZM93SLjhLKSs50mNfp1eE0yTISqWQVEcihVLsQhUOX hGBhrRZrff5s4Wocp5ilj0hWMaTWVHKYeeYtwfNQ= 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.12 104/140] can: j1939: j1939_sk_bind(): call j1939_priv_put() immediately when j1939_local_ecu_get() failed Date: Wed, 17 Sep 2025 14:34:36 +0200 Message-ID: <20250917123346.849640383@linuxfoundation.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20250917123344.315037637@linuxfoundation.org> References: <20250917123344.315037637@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.12-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 17226b2341d03..75c2b9b233901 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