From patchwork Tue Nov 5 16:31:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13863202 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (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 A39B22C190; Tue, 5 Nov 2024 16:31:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730824281; cv=none; b=EcuL4cywhAfpvl9D1Gp6G2NLUyINVRfo4XnAVivOpvhi5j4QUI8S6ziqGCAhB6lirQic4CVCna/77E0SxBUtYh2fKbMe9+X7zMhLZfO+BtC7QeEe+c97vb3rLZdLfslrPJI42yWkFP49bUBaayiJdbtRvdAQdKE99iewqv9gon4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730824281; c=relaxed/simple; bh=MDmKggEi6kmApuIt6Yt8mPHClxb1p8lHzd+eGxHmbHI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=D7QnGFV2oNP6FITCWCAo8tPP+MV+Rjg5nyEHs2ZHW7hSJp1PiwP/fu0jJm2pQx7/ZElZYhq9TdK79/8JYIGzypQmCVUa22GCWaDe5Ry4CuTAL547s2mPRAEZDR5gkbgl9PqOz1qhTxQGhd89Hmyzc6ZE18PlbCQgJ92C63MAzB8= 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=qVaOjrcF; arc=none smtp.client-ip=212.227.17.21 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="qVaOjrcF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1730824263; x=1731429063; i=wahrenst@gmx.net; bh=uZMKt13pgpTh6sAh8BdybJCwC1878gT2xjYhwHNe3gA=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Transfer-Encoding:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=qVaOjrcFZrNaf+cL8MfrYvZPZizl863UFQ7ALzP7jbkaWmeSledl592a5OETRGXd GXGJeVDFKadlJoHUxO8C7uagjAUCtmiSqGScB0D09DunkYInEtOyfLPsB0qQ93+G9 OwbtOomtAlnbFOdMQ4I/Bkl0W9AfIbqHUnLpLnbxU5pBZC74ihIr5dk8YD0F5PIZ6 BRJtJa+wQeXe5ToQiIu0feKMbY6AzzYG/TQMBN1V1tiBBF7qTsvVbfeQ3RxjD50F2 M7fy55gYLiBL433wYInqnVZhdX+hZEVBKpkPwSRrrOyImSCePcjD/HvOLZ7z7Mvv5 /qJ74o4RAJUVdb4n6w== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MN5if-1tRGss2Siz-00SA0u; Tue, 05 Nov 2024 17:31:03 +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 V2] net: vertexcom: mse102x: Fix possible double free of TX skb Date: Tue, 5 Nov 2024 17:31:01 +0100 Message-Id: <20241105163101.33216-1-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Provags-ID: V03:K1:XOmPgdJnJw9hThL2W2DfrsocRWKKuXAA12CFCzpFkyf+cPMtIO2 QHKBs1yiBmnaITpQf+0rnpbY6U5l8lfkPnL9E/vTtz71BEypwDJKfARBVCm0BIbnzqW3Xdv S5PMYHiwqGxRtKEB3CRSjkxBK/4N3oqBDoaALlU6kqbXjgfw7CW9/dLiqj85+r3EBqscHti D9oQPloGIwR0qoBqa2h/Q== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:sFhgYPjpdIY=;hK9vljsUSLRNjW4hVeA57JWASOv 3z6CKhwYYmWYmXOSISMxsJAIUG0Q8/Ao9I2whtNlkTF4ubUj3qus4x2fwhdO8ecyO3pzWS1FX MK1rgAcxdCtPfwtzH9aTDw4PWapRKd9Ba+GD5aSmm7BKy5m/GZ++psx8uOtYBPxl2FYoCefHh J1jhmT4MYmpZjbq3Lrrb/Aw3nTV2WtIFS/RwnidukVGCd2b1MY30poJzRAKbe+kA99EuH6Hcp Mxa/XPPiL3mBTtpclsuKLlz+qvkng4MJy08Yhq8SpMGIMxnDK7kHYcsLCcVCjlpw+mjExY4hA 6C4Cy5XINfsc5KoBcsbfeMMqVecZ9k1CP9LKkikEvC+iDS+kdcqyx+7tAQ0W7I4zmSQVDMNGj I3uG94kRRZSRAn6+Zj44GrnK+edqljhoMAHF4g7GU4RI98I0UqNB6HV5A2HJo406Gsa2fESYD Vhu1i42GrpiVaK77S3xOvUB9ywLpwho7vjAqoUiBN1U7sxxO2m3vcTfTDQzprvda+zmAKv+qX 3u9s/i6dA0YF4TaRy6GGF9AIhKtC0Sww11AClea7uWX1L6nnIYitDYZS7Yv4QRAAJzbmK1xW7 hSBHX9DeGvLahLm1TSvp/3FBORB0OibyI04MkvsMzyr9VVHyoHEypYXZBJQQA32Vt9RmzB8F9 R3OgbhLJQoUNN+rqfOOE3JTrn6TQGcbkd2CFrGDkNVAR3OhxOSOp5FpoDwv4yl15K8QtGOaHp 8/q5OQn8LsZeYH+z3ZJzPVos7gk8AdKVEypNTlh5xOaNVtZV6umZ0CbUWYkVL2nG0hU91NDTq ihWA4X493x0v+vNsc2Nr6yHQ== 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 Tue Nov 5 16:35:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wahren X-Patchwork-Id: 13863206 X-Patchwork-Delegate: kuba@kernel.org Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) (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 BBE5D1D79B6; Tue, 5 Nov 2024 16:36:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730824567; cv=none; b=sDapxP1mK+0CKVDAyKtVz+0HTQFndehysismY1tsHfptarZ3UP825O5ngQbkO9Kay0Ff8kFRfD92N6iDyuWxNBa/vJazSJ8V0ld7kYmX4xG0Nv8Yd1xUYJ10RJrVKDLZoG26TZOb/5NjQV/cEzepDV/R4cBSsWkigubEkK8Vdlg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730824567; c=relaxed/simple; bh=zBgug8KxOCsF2I+ttYqXDlHbomg2YCqtrPYDrbR4hKM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Zc0xByabEol19hMLXiIqCw1nE1B+1rNrwJky3H72I4XyFEdNv8agzwNIaUB0un/4uzUyvvCkrErsH9NQrHpXwPoum+aAu2knT1xprwWa+FzKSjjCypCE0Gn04X6wcvXT3MlrbHlMl7ThRcVfOvW6snXFt9Nsc2aIL39xLR9toRY= 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=OfqEOI+O; arc=none smtp.client-ip=212.227.17.20 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="OfqEOI+O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1730824552; x=1731429352; i=wahrenst@gmx.net; bh=O/VqUoOSYgCxS0PztdZQLikh7kxbi09He3zNeGJYB94=; 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=OfqEOI+OPmzYrU3On4qmGjvHXpURK9aQtx84Sff1feBmdbuPn116yLRDBxzyQ5mP P8PXK0c9mDOSh4QjyqZ8Gcax+GJKYxBqHHFPXF6C+hPBgsyjL/cWU7LXo8+ODxHVY 4oOdxh7upnvMRA9e66cEK7zo2uvi3bFhcUl+/lGy+kFiJyScGonkbWbxBAHNfs7KN bmkU+EwyfV3hpuMgJMG9KYN9EaAz7o2f3NzE+FSjg8iMCz0oir52mp4ecw+l/20cf lu4B+QWx174PBvZu7CkwkT+iR3dD4F6IMP0vz5zwucd+CZqOCLlPusUmLsjn6EYF5 JuIZqMbS0cc6vdoWgw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from stefanw-SCHENKER ([37.4.248.43]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MoO24-1tb8pk333A-00gmLe; Tue, 05 Nov 2024 17:35:52 +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 V2] net: vertexcom: mse102x: Fix tx_bytes calculation Date: Tue, 5 Nov 2024 17:35:45 +0100 Message-Id: <20241105163545.33585-2-wahrenst@gmx.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241105163545.33585-1-wahrenst@gmx.net> References: <20241105163101.33216-1-wahrenst@gmx.net> <20241105163545.33585-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:T6KvPqfzhbKPBZgam3WhN578u3fdkzZ3uYPiNaWCoonzwBK4moZ jzEKua6rYJGfz4N9DB1dEpE8sAF6uFuH07tzbN8AeIrEj7JPoI8W/aR0aNOTSvHu37knYSn e1uJolmILYDr9Qt4TliGRJ4B3DSKPumlm/W2KU9WfAk+wTtRxQY6b1t2BrdISNiKUTTG/YI DtUS90YIOfwbLqYJzS5Yg== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:d/xs1y8J3Y8=;9Hj4r5dZbtai7O/6AU2QhC8+KWs /uYygDK2dVSlb9qP38qbbdwBqFzaEgXydtg9sZ+XUy2JKiIJIslQMKcnUES/w3G0WuDcJDdCu BdM+DrfIrHV85vGJSUI2XuftRwlpUQZNly91CCMUYnngl2Aj3kkEFJ7rYsQvrY4Bi3yioUd2A Fs4jhk2vY9QeC9K5FuwXz+zR0ypeqMSNcxlXPCORV82r8srtdms/V8iwu5AuqCe58Siuj+Qny VPGuK/PllLX6v5Y/CNJOQoaeMIalqSZ27VxPUjt5Y/TlMWOHLfzamx6p61H2XfNx5u1wYNT8W H4MhooGBAXwT3ZOJOaRRJG3HoisjzBmSgNGmLHCYBUZqH0AWnMkj5CaXOiDGl6zYv9NeYWneW 2hn6F5hdK+kIJwynAALJZjHBI7hms65fCZLDlKT8c+pMMtE63QbB3U3ZImgjGudEGwtlDPTwb tfZcAw52ZdpBn/UxzJhdz3MPuFsuv6qpSRxqkwux2o6aAJoVQVm1e6kCYSXwVr9DOX24qU6uu MemEZJ8IR62VHSKNTL8FmFVF1N2HrBdWseDOkMV/ZnAvLjEYPwQgyg1VzOD/CISKL4cJILNAp MMW50F+8wx2nEW8PBZ2fmD2ZPGeFscoTqb0TON+grAElYF+tDRqpv0TePHN0n94i8NCctB8BI rYs2F3R7VnZ+IiJO6jNSYlSEg+Pqmo+S/omR4yNtYq2aWFRKNnpYc2dZCTp63W4eyX8KH3bHm RNROC5TMwQZoJFz8nQnOljGawVo1FFq/tfT75shbpxpIE2zEwcdyWxXVf8YQFgJ9ZkHTXveLt LQecTtWn9hppmFOQROdsEU9Q== X-Patchwork-Delegate: kuba@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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.34.1 diff --git a/drivers/net/ethernet/vertexcom/mse102x.c b/drivers/net/ethernet/vertexcom/mse102x.c index 2c37957478fb..1fffae6596de 100644 --- a/drivers/net/ethernet/vertexcom/mse102x.c +++ b/drivers/net/ethernet/vertexcom/mse102x.c @@ -443,7 +443,8 @@ static void mse102x_tx_work(struct work_struct *work) if (ret) { mse->ndev->stats.tx_dropped++; } else { - mse->ndev->stats.tx_bytes += txb->len; + mse->ndev->stats.tx_bytes += max_t(unsigned int, + txb->len, ETH_ZLEN); mse->ndev->stats.tx_packets++; }