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 0A9B62C159C; Wed, 17 Sep 2025 12:51:47 +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=1758113507; cv=none; b=jt5mPe2tR8cbGXoKgeypL17IOHnbdlwpYVrsYe17Tie+xJezSAnlQcBl2otQXcJ5XRh49bWq+T+TwDoUyGUf8EQ5gtS+1hY2zwZ6gPXf+qCtZgIUTXOX39Kts4tvf45tdqcwY5SqD8IE0JXS6t1l9uTAPvr+w3tiwv7J1z66zXQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758113507; c=relaxed/simple; bh=dtK+aS4l9HaXFtjunnWWzrYWXSyE7TRJQs4PZ9ift9I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dXq3SYSU+J7sOdDbhd3kol2HQMjKqiB5qRNffZk0TiU6jnGiI7RC17ELhYQziCI06lnAWZwTsK1ZVgc9zOHjhCMbFuxnKDaGUeH2f6fhWr+jAPEFeHQ+Hvew5WulPkAl+6R8EPBOV1KE6o0kLqldGyNkcbZWq5FsUbEuPSA1MfI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ACTzLepx; 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="ACTzLepx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74B07C4CEF0; Wed, 17 Sep 2025 12:51:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1758113506; bh=dtK+aS4l9HaXFtjunnWWzrYWXSyE7TRJQs4PZ9ift9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ACTzLepx0jYT/2AVLRUyX/tcb/liOFFeV1G1V3ycyKqpt7JAKrxU5vorpuUzakLOI r5t6w6HFR3N6aa1DOT2q/v8OR+wcHAgj/ikzjffJZS6tyORYB3FfbKvmsz8BAMWRn7 QC5ddqtKGdz08ns8YG1HuA9vAbSR6Xq+xOK/Y5yw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Anssi Hannula , Marc Kleine-Budde , Sasha Levin Subject: [PATCH 6.12 106/140] can: xilinx_can: xcan_write_frame(): fix use-after-free of transmitted SKB Date: Wed, 17 Sep 2025 14:34:38 +0200 Message-ID: <20250917123346.899386131@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: Anssi Hannula [ Upstream commit ef79f00be72bd81d2e1e6f060d83cf7e425deee4 ] can_put_echo_skb() takes ownership of the SKB and it may be freed during or after the call. However, xilinx_can xcan_write_frame() keeps using SKB after the call. Fix that by only calling can_put_echo_skb() after the code is done touching the SKB. The tx_lock is held for the entire xcan_write_frame() execution and also on the can_get_echo_skb() side so the order of operations does not matter. An earlier fix commit 3d3c817c3a40 ("can: xilinx_can: Fix usage of skb memory") did not move the can_put_echo_skb() call far enough. Signed-off-by: Anssi Hannula Fixes: 1598efe57b3e ("can: xilinx_can: refactor code in preparation for CAN FD support") Link: https://patch.msgid.link/20250822095002.168389-1-anssi.hannula@bitwise.fi [mkl: add "commit" in front of sha1 in patch description] [mkl: fix indention] Signed-off-by: Marc Kleine-Budde Signed-off-by: Sasha Levin --- drivers/net/can/xilinx_can.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/can/xilinx_can.c b/drivers/net/can/xilinx_can.c index 436c0e4b0344c..91382225f1140 100644 --- a/drivers/net/can/xilinx_can.c +++ b/drivers/net/can/xilinx_can.c @@ -690,14 +690,6 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb, dlc |= XCAN_DLCR_EDL_MASK; } - if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) && - (priv->devtype.flags & XCAN_FLAG_TXFEMP)) - can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0); - else - can_put_echo_skb(skb, ndev, 0, 0); - - priv->tx_head++; - priv->write_reg(priv, XCAN_FRAME_ID_OFFSET(frame_offset), id); /* If the CAN frame is RTR frame this write triggers transmission * (not on CAN FD) @@ -730,6 +722,14 @@ static void xcan_write_frame(struct net_device *ndev, struct sk_buff *skb, data[1]); } } + + if (!(priv->devtype.flags & XCAN_FLAG_TX_MAILBOXES) && + (priv->devtype.flags & XCAN_FLAG_TXFEMP)) + can_put_echo_skb(skb, ndev, priv->tx_head % priv->tx_max, 0); + else + can_put_echo_skb(skb, ndev, 0, 0); + + priv->tx_head++; } /** -- 2.51.0