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=1794590458; b=ql2OTM12HNU/qSfx4Knv9+ohcvBZgR/407zg1xy+TaJgN29uEZMBeTkgwLD6D/8EWj53 LgeYAA+OkRVLRBOt/+SkGvx/5Dp1W/kj7iaVpedvYFNiJn9mQP9Qn6dGdOHhtJsdFNbLq 8HpsFF8Cm21zuyUPU2HO+rpHs+nmIz+7jq+bdvOHE6h0EX9Ly6VEKIjD3MKC0OHPraTao nWx9soQxYHCLB2BEuzB/RBdLjEVmWhitaLaTT+Senq85jcbrQWqyuSP1MEFFosF+bvCHZ G2BkejAGMxZ7cpix8JqH0A1jmEoPtBO3DQ1jVWvDkYE2pgBdwHUThuqze1X4Oo8pzXQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794590458; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=UgSXYHKPaO0fGYBbTt+O45hsAucjKFC6ktedrYdtix8=; b=Bc1c5xuaO4GogGIFWJ/YwO8BXz5ymRbEbWt9dqMMlF736uemPc+FBB20AkJqEervPBuO 7JLy3FC10muLJXDzh2N68xGrTKIaVrvf88qv/9FmG+YRhaSp3pRMpwgK3Pr+Yza0KE4d3 IdMhD0vL5hE4iziHN9gySB08b6o/GOahIBVYMa50CYEpe+Le2+l3eQ3doq7aMc8rglyAd wcHITDBzxwGQyV31mrcOE48DnGUcb6aCIleRLtexb9hURqqvta+4CWWZb5TRqe81B2Suq KzbX5LJfc92dWeDD5OJUfucepRBenIl5/eLf6Wd3S0+3CjEOiHHxHZ8dfDWphyppRrg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=j6l3OVqM; 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 C43D6606A339; Fri, 13 Nov 2026 17:20:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=j6l3OVqM Received: by smtp.kernel.org (Postfix) with ESMTPSA id 713481F000C4; Fri, 13 Nov 2026 17:20:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794590458; bh=UgSXYHKPaO0fGYBbTt+O45hsAucjKFC6ktedrYdtix8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j6l3OVqMhRxKGdHpt/Gi6+w2aoRjTSGVb/RziCN+luFWfdcj5cOQ8llkNKIxjhRj5 LfSa+zn7FLxKeNe44vkmQjbxfjCdWEcGfQhtGKG70Z6S0lbPiDQIBh2etOGBUvYddl wcyCjvfN1mV0n8ct3VffwdLp51ivsdian7L410Xk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Vincent Mailhol , Cunhao Lu <1579567540@qq.com>, Marc Kleine-Budde , Sasha Levin Subject: [PATCH 6.18 363/686] can: dev: can_put_echo_skb(): free skb on invalid echo index Date: Fri, 13 Nov 2026 10:48:16 -0500 Message-ID: <20261113153833.203328309@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261113153820.902362109@linuxfoundation.org> References: <20261113153820.902362109@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cunhao Lu <1579567540@qq.com> [ Upstream commit b4ebcbbf66ba6c5816dfe229effb4641c46e4b4c ] can_put_echo_skb() consumes the skb on all paths except when the echo index is out of bounds. This leaves ownership with the caller on -EINVAL, unlike the other error paths, and can leak the skb if the caller expects consistent semantics. Free the skb before returning -EINVAL so that all return paths consume it. Fixes: 6411959c10fe ("can: dev: can_put_echo_skb(): don't crash kernel if can_priv::echo_skb is accessed out of bounds") Cc: stable@vger.kernel.org Reviewed-by: Vincent Mailhol Signed-off-by: Cunhao Lu <1579567540@qq.com> Link: https://patch.msgid.link/tencent_683AA16E643DE00211CD2FB62991264DC605@qq.com Signed-off-by: Marc Kleine-Budde --- FAQ: Q: `can_skb_init_valid()` directly modifies `skb->data` without checking if the SKB is cloned or shared. Is this violating SKB shared buffer rules and causing data corruption? A: The finding about can_skb_init_valid() modifying skb->data on a potentially shared buffer is not relevant for this (correct) patch. The FDF-flag write in can_skb_init_valid() only matters for PF_PACKET use: PF_CAN allocators already set CANFD_FDF. The write exists to normalize frames for PF_PACKET observers (tcpdump/Wireshark) so they can distinguish classic CAN from CAN FD at the netdev level, and to compensate for PF_PACKET senders that omit the bit. That normalization is functionally required. The shared-buffer concern only becomes realistic through a specific chain: a PF_PACKET sender injects a CANFD-sized frame, the CAN driver's loopback puts an echo skb back into can_rcv(), and cgw (without modfuncs) clones it for forwarding to another interface. Only on that second can_skb_init_valid() call is the skb cloned. By then the bit was already set on the exclusive skb during the initial xmit path, so the flags |= CANFD_FDF write is strictly idempotent for any parallel consumer of the shared buffer - no memory-safety or information-disclosure consequence. It's a formal violation of the skb sharing rules without an observable effect, so the current code can stay as-is. Link: https://lore.kernel.org/all/54a3cc01-abcf-4a33-b932-39bb1f68cdd5@hartkopp.net/ [mkl: convert Oliver's mail to FAQ section] Signed-off-by: Sasha Levin --- drivers/net/can/dev/skb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/can/dev/skb.c b/drivers/net/can/dev/skb.c index 3ebd4f779b9bd..6fb1f9b2a9e20 100644 --- a/drivers/net/can/dev/skb.c +++ b/drivers/net/can/dev/skb.c @@ -52,6 +52,7 @@ int can_put_echo_skb(struct sk_buff *skb, struct net_device *dev, if (idx >= priv->echo_skb_max) { netdev_err(dev, "%s: BUG! Trying to access can_priv::echo_skb out of bounds (%u/max %u)\n", __func__, idx, priv->echo_skb_max); + dev_kfree_skb_any(skb); return -EINVAL; } -- 2.53.0