From patchwork Fri Nov 8 11:43:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13868078 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (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 565111E32B3; Fri, 8 Nov 2024 11:44:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731066275; cv=none; b=frwZsQCC9HaM4jZ8F3lRtzR3ob120yWzUlPafNiftKpCra9GalNhOOE6cqR6zorCohvBtrK++fQXeC4O++6uXuqNiw4aCgzdHtWPQapJAT4PJj+oS/+pLCVAUQjDb7FDW+ar0Yn5wpcCniySuqSx3DsORINH+Wipcs3k9E/2Ek8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731066275; c=relaxed/simple; bh=MDmKggEi6kmApuIt6Yt8mPHClxb1p8lHzd+eGxHmbHI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=LeVgl1bJqMUCgMSzpv4VIyAVehavufuiMHASxNeQjYcjQaipwNqLcb3Ph/OqR8QKf0v94bxepYlhdeJSCinMHrTf3kUuN10n6rJfbKkhw2cZLkMZOiWiA02g2D4Mj82HOTy9SEAycHJVZoPsQgOA9RxydEzpiXIhXr/RGn7h2wE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=wahrenst@gmx.net header.b=QjEFxrX5; arc=none smtp.client-ip=212.227.15.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=wahrenst@gmx.net header.b="QjEFxrX5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1731066258; x=1731671058; i=wahrenst@gmx.net; bh=uZMKt13pgpTh6sAh8BdybJCwC1878gT2xjYhwHNe3gA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=QjEFxrX5FAcqKle00Mk6QvAy4zGYwSuvwG3a674lDsujhJssD5sSoF6e7fBQqRJc 7zrFJ3O8Kvzhqkexm80TM63XXJ6NtNTgpKD3c7FWf3dqfpghMsGd1dO6Fq4LmCVTR LBrFYnV68fhy/fyMR/OLTr0NmKagbOvaHuAUDZ/iYw6mWoqCpea7+aBOVxiG7P5wh myC16ou4hpSzWiFHWlM6jKMSRLSeYhv1Mjvlk5ibsKLJZ9JSSUcgiNyIhoQHfrF5b EsaLvrt7DCCSDz69VJmOlpfjfHdZX95x5Ph6AgRMzxa6EBlY1hep/8xD4lwZp0G5f zmzI7dJgR5smTnKdyA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MqJm5-1teGFl0YLL-00mD2y; Fri, 08 Nov 2024 12:44:18 +0100 From: Stefan Wahren To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Dan Carpenter , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Wahren , stable@vger.kernel.org Subject: [PATCH 1/2 net V3] net: vertexcom: mse102x: Fix possible double free of TX skb Date: Fri, 8 Nov 2024 12:43:42 +0100 Message-Id: <20241108114343.6174-2-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108114343.6174-1-wahrenst@gmx.net> References: <20241108114343.6174-1-wahrenst@gmx.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:SO7gY4fbJ/cAlEVxUg0/CUTKIBsYiOPG7sQoNN/rLyZSJoibRhZ kGbPnudNZzHaD/S9tcgm0WOgovu3t96zeHZBXefQiC2PGO7Xx3O+5kT4PHSDN+/SHe/x4xm pwpJIycBsqxr/fJj1kyN7egZ0cOUT2t8/pGfelzHV+90f54/zs/1GgCB37pEXB8mT4yIti4 4JtrRzWuk988oipPCFf0A== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:TZ+NoTfk9Wg=;gNBz0Oy+eb54xxV9QXmC3Z9cS35 x8ojWD1vVfCec9YcxeixyyaiQrhcR8GrRM00z8Z47RVqCpwNJvlr0q4lIWqk3GFI7nFodxdXj 7zuX2p5+18rNB1L6MuMZkcd+9d07e+eN1gTYDlWOS82ZPCcfj6j/QVpvtEPaJNeRbUWeR2hNX SdjCSTsmjVDcH3PjLRB4E96vIgrJ2Ufq6JH8vWzkXvri+VNdForw+CVNvyGHyg5gUgZwZ48+c bWjCiRgcpwHms3IMkSNlN17xiek+JK8C5iPMi2U1dykAlHxAO48+mS/zaEf0Gih5pNEBPlVzA IRTrDs7NuSrLOyQYQQ/3/W6Fwyz44wz7x9ODr4P/32JngmmVcNfp9TazVuYvFetuQN1h0SRtk uhbk0iKYkwiyPyamkmnFpYsTdVyYWq0fJAiO57C560uu4fmQStgNi+dV83Fpqtl2T/wblxmqY bEi/9ROCSnU3B3W3PoJPF1wTVyYUnk89J/UxBms8SWwlUdjGaFTatYO+E4ZGhgCkzGkHTLWiK JbzdoAEeCZIGvUtVXJkSQjvuutvsaRRx+M5k4EEUqxn2JuecVHase9pgcsaE6kbOeOrJ/I8uc eLH77v+6sScSngwYeMXIpCAWHRFDuV1TPYGWEdoY7lK8iYEAY5pwozGtVDnhBQm6MYhXCyi7X ys1AKfdTyokiU2jG6NnAO7CdJah3xyAaJVCgAHQcD+60zudRdtFZhCql1B3kzMPc3GSwoB5eW lEnflMrTWS7Goy+ikRT713TmwUqx81hD9Xq/5sQfgspS8SnYC5FlilgvzvKh6Qbz2ArFMq5j/ 2cZTvseOLFk8GJkDfMWcoHSA== X-Patchwork-Delegate: kuba@kernel.org The scope of the TX skb is wider than just mse102x_tx_frame_spi(), so in case the TX skb room needs to be expanded, we should free the the temporary skb instead of the original skb. Otherwise the original TX skb pointer would be freed again in mse102x_tx_work(), which leads to crashes: Internal error: Oops: 0000000096000004 [#2] PREEMPT SMP CPU: 0 PID: 712 Comm: kworker/0:1 Tainted: G D 6.6.23 Hardware name: chargebyte Charge SOM DC-ONE (DT) Workqueue: events mse102x_tx_work [mse102x] pstate: 20400009 (nzCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : skb_release_data+0xb8/0x1d8 lr : skb_release_data+0x1ac/0x1d8 sp : ffff8000819a3cc0 x29: ffff8000819a3cc0 x28: ffff0000046daa60 x27: ffff0000057f2dc0 x26: ffff000005386c00 x25: 0000000000000002 x24: 00000000ffffffff x23: 0000000000000000 x22: 0000000000000001 x21: ffff0000057f2e50 x20: 0000000000000006 x19: 0000000000000000 x18: ffff00003fdacfcc x17: e69ad452d0c49def x16: 84a005feff870102 x15: 0000000000000000 x14: 000000000000024a x13: 0000000000000002 x12: 0000000000000000 x11: 0000000000000400 x10: 0000000000000930 x9 : ffff00003fd913e8 x8 : fffffc00001bc008 x7 : 0000000000000000 x6 : 0000000000000008 x5 : ffff00003fd91340 x4 : 0000000000000000 x3 : 0000000000000009 x2 : 00000000fffffffe x1 : 0000000000000000 x0 : 0000000000000000 Call trace: skb_release_data+0xb8/0x1d8 kfree_skb_reason+0x48/0xb0 mse102x_tx_work+0x164/0x35c [mse102x] process_one_work+0x138/0x260 worker_thread+0x32c/0x438 kthread+0x118/0x11c ret_from_fork+0x10/0x20 Code: aa1303e0 97fffab6 72001c1f 54000141 (f9400660) Cc: stable@vger.kernel.org Fixes: 2f207cbf0dd4 ("net: vertexcom: Add MSE102x SPI support") Signed-off-by: Stefan Wahren --- drivers/net/ethernet/vertexcom/mse102x.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) -- 2.34.1 diff --git a/drivers/net/ethernet/vertexcom/mse102x.c b/drivers/net/ethernet/vertexcom/mse102x.c index a04d4073def9..2c37957478fb 100644 --- a/drivers/net/ethernet/vertexcom/mse102x.c +++ b/drivers/net/ethernet/vertexcom/mse102x.c @@ -222,7 +222,7 @@ static int mse102x_tx_frame_spi(struct mse102x_net *mse, struct sk_buff *txp, struct mse102x_net_spi *mses = to_mse102x_spi(mse); struct spi_transfer *xfer = &mses->spi_xfer; struct spi_message *msg = &mses->spi_msg; - struct sk_buff *tskb; + struct sk_buff *tskb = NULL; int ret; netif_dbg(mse, tx_queued, mse->ndev, "%s: skb %p, %d@%p\n", @@ -235,7 +235,6 @@ static int mse102x_tx_frame_spi(struct mse102x_net *mse, struct sk_buff *txp, if (!tskb) return -ENOMEM; - dev_kfree_skb(txp); txp = tskb; } @@ -257,6 +256,8 @@ static int mse102x_tx_frame_spi(struct mse102x_net *mse, struct sk_buff *txp, mse->stats.xfer_err++; } + dev_kfree_skb(tskb); + return ret; } From patchwork Fri Nov 8 11:43:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13868077 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (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 64DC51E2833; Fri, 8 Nov 2024 11:44:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.15.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731066274; cv=none; b=Imihh85Kw36sdrdOM5E7lfFKSykbDb3GQQ2ObCRMr4iBhveWbCIzvd/ALBrRXw8AmnUSgz/ujHtRd/Sy8F2FhB2dQTD+SteQiciVgG5vVCAgLU/E1z3Hmidshenx7P4C8achb/YYhzg1SH+NWOCdttiU26tE2s/yPZ2zt4sCAdw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731066274; c=relaxed/simple; bh=oQVviN+5i+x05HgtVOFrDfC3HzwLDkP+iQb92BTx4og=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MIBkao0xdb6zuUTj9z1UjnhR+EdmZQQw1oO+t9VrwAeo+5I0GN3r0awypHsFltV0sPRgIdlc5vW5OzrtjUyOJCRnZckkaUzLpHDL9jgn8hHAzglV5LfZpbPFoTwKNBpFB6jzW/JanKk058WNKQ0GfcrfrF6LeVmQvFqBaavkn1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net; spf=pass smtp.mailfrom=gmx.net; dkim=pass (2048-bit key) header.d=gmx.net header.i=wahrenst@gmx.net header.b=Y4scvopp; arc=none smtp.client-ip=212.227.15.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.net header.i=wahrenst@gmx.net header.b="Y4scvopp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1731066258; x=1731671058; i=wahrenst@gmx.net; bh=GxbX2oxaYRc6GmeF5zAbTlIW/0poPK+EYOQlprsP+sQ=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=Y4scvopp/F1hpDmqbVxGiCZ3tiQeiamk/dXKp9V9NdYfM7Ye6g87cNme3bQErJaa SZBzWFFWHDQTcApeMgQI+tDxY991CbvEE3eoqgKaXjMwHMRkNsGZzVjiA4vi1jzs0 wYv7kWfJFGYxWPeLjIa20/yQ2QpIS947C9ZTR+7I/RX3fQE8P9TF1BKtDaAYjk1Oj V+ikv5UDjV0t7JRd6kHwbHFWMSpC9ifbid0pxs2efviUMYN1NdbgiGN4Pj/4FBXya zSWhFbst3xIdgeot4g5VNJtLWqogy69g6alSRJKZYEgAZbcWTzCbhemYhLRthQJxy xEJPDlnWfrUv+WUrwQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MDywo-1szRnK1yDM-00FbvH; Fri, 08 Nov 2024 12:44:18 +0100 From: Stefan Wahren To: Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Dan Carpenter , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Wahren Subject: [PATCH 2/2 net V3] net: vertexcom: mse102x: Fix tx_bytes calculation Date: Fri, 8 Nov 2024 12:43:43 +0100 Message-Id: <20241108114343.6174-3-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241108114343.6174-1-wahrenst@gmx.net> References: <20241108114343.6174-1-wahrenst@gmx.net> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:JiTjpa5mpNh/IquJkgXFVbPDF+YOAjJLzyr4w/Ndl2il9OlCurg rb3muOMLHRPX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uba@kernel.org The tx_bytes should consider the actual size of the Ethernet frames without the SPI encapsulation. But we still need to take care of Ethernet padding. Fixes: 2f207cbf0dd4 ("net: vertexcom: Add MSE102x SPI support") Signed-off-by: Stefan Wahren --- drivers/net/ethernet/vertexcom/mse102x.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.34.1 diff --git a/drivers/net/ethernet/vertexcom/mse102x.c b/drivers/net/ethernet/vertexcom/mse102x.c index 2c37957478fb..89dc4c401a8d 100644 --- a/drivers/net/ethernet/vertexcom/mse102x.c +++ b/drivers/net/ethernet/vertexcom/mse102x.c @@ -437,13 +437,15 @@ static void mse102x_tx_work(struct work_struct *work) mse = &mses->mse102x; while ((txb = skb_dequeue(&mse->txq))) { + unsigned int len = max_t(unsigned int, txb->len, ETH_ZLEN); + mutex_lock(&mses->lock); ret = mse102x_tx_pkt_spi(mse, txb, work_timeout); mutex_unlock(&mses->lock); if (ret) { mse->ndev->stats.tx_dropped++; } else { - mse->ndev->stats.tx_bytes += txb->len; + mse->ndev->stats.tx_bytes += len; mse->ndev->stats.tx_packets++; }