diff mbox series

[net,v2] net: dpaa: Pad packets to ETH_ZLEN

Message ID 20240910143144.1439910-1-sean.anderson@linux.dev (mailing list archive)
State Accepted
Commit cbd7ec083413c6a2e0c326d49e24ec7d12c7a9e0
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] net: dpaa: Pad packets to ETH_ZLEN | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 16 this patch: 16
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 5 of 5 maintainers
netdev/build_clang success Errors and warnings before: 16 this patch: 16
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 21 this patch: 21
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-09-11--15-00 (tests: 763)

Commit Message

Sean Anderson Sept. 10, 2024, 2:31 p.m. UTC
When sending packets under 60 bytes, up to three bytes of the buffer
following the data may be leaked. Avoid this by extending all packets to
ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be
reproduced by running

	$ ping -s 11 destination

Fixes: 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")
Suggested-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---

Changes in v2:
- Fix the nonlinear varable becoming out-of-sync with the skb's
  linearization state by padding the packet before anything else.

 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Eric Dumazet Sept. 10, 2024, 2:46 p.m. UTC | #1
On Tue, Sep 10, 2024 at 4:32 PM Sean Anderson <sean.anderson@linux.dev> wrote:
>
> When sending packets under 60 bytes, up to three bytes of the buffer
> following the data may be leaked. Avoid this by extending all packets to
> ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be
> reproduced by running
>
>         $ ping -s 11 destination
>
> Fixes: 9ad1a3749333 ("dpaa_eth: add support for DPAA Ethernet")
> Suggested-by: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Sean Anderson <sean.anderson@linux.dev>

Reviewed-by: Eric Dumazet <edumazet@google.com>

Thanks !
patchwork-bot+netdevbpf@kernel.org Sept. 11, 2024, 11:20 p.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Tue, 10 Sep 2024 10:31:44 -0400 you wrote:
> When sending packets under 60 bytes, up to three bytes of the buffer
> following the data may be leaked. Avoid this by extending all packets to
> ETH_ZLEN, ensuring nothing is leaked in the padding. This bug can be
> reproduced by running
> 
> 	$ ping -s 11 destination
> 
> [...]

Here is the summary with links:
  - [net,v2] net: dpaa: Pad packets to ETH_ZLEN
    https://git.kernel.org/netdev/net/c/cbd7ec083413

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index cfe6b57b1da0..4a55e521c17e 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -2272,12 +2272,12 @@  static netdev_tx_t
 dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 {
 	const int queue_mapping = skb_get_queue_mapping(skb);
-	bool nonlinear = skb_is_nonlinear(skb);
 	struct rtnl_link_stats64 *percpu_stats;
 	struct dpaa_percpu_priv *percpu_priv;
 	struct netdev_queue *txq;
 	struct dpaa_priv *priv;
 	struct qm_fd fd;
+	bool nonlinear;
 	int offset = 0;
 	int err = 0;
 
@@ -2287,6 +2287,13 @@  dpaa_start_xmit(struct sk_buff *skb, struct net_device *net_dev)
 
 	qm_fd_clear_fd(&fd);
 
+	/* Packet data is always read as 32-bit words, so zero out any part of
+	 * the skb which might be sent if we have to pad the packet
+	 */
+	if (__skb_put_padto(skb, ETH_ZLEN, false))
+		goto enomem;
+
+	nonlinear = skb_is_nonlinear(skb);
 	if (!nonlinear) {
 		/* We're going to store the skb backpointer at the beginning
 		 * of the data buffer, so we need a privately owned skb