diff mbox series

[net-next,4/6] net: sparx5: move SKB consumption to xmit()

Message ID 20250109-sparx5-lan969x-switch-driver-5-v1-4-13d6d8451e63@microchip.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: lan969x: add FDMA support | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1 this patch: 1
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 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

Commit Message

Daniel Machon Jan. 9, 2025, 6:37 p.m. UTC
Currently, SKB's are consumed in sparx5_port_xmit_impl(), if the FDMA
xmit() function returns NETDEV_TX_OK. In a following commit, we will ops
out the xmit() function for lan969x support, and since lan969x is going
to consume SKB's asynchronously, in the NAPI poll loop, we cannot
consume SKB's in sparx5_port_xmit_impl() anymore. Therefore, move the
call of dev_consume_skb_any() to the xmit() function.

Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
---
 drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c   | 2 ++
 drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 1 -
 2 files changed, 2 insertions(+), 1 deletion(-)

Comments

Eric Dumazet Jan. 9, 2025, 7:13 p.m. UTC | #1
On Thu, Jan 9, 2025 at 7:38 PM Daniel Machon
<daniel.machon@microchip.com> wrote:
>
> Currently, SKB's are consumed in sparx5_port_xmit_impl(), if the FDMA
> xmit() function returns NETDEV_TX_OK. In a following commit, we will ops
> out the xmit() function for lan969x support, and since lan969x is going
> to consume SKB's asynchronously, in the NAPI poll loop, we cannot
> consume SKB's in sparx5_port_xmit_impl() anymore. Therefore, move the
> call of dev_consume_skb_any() to the xmit() function.
>
> Reviewed-by: Steen Hegelund <Steen.Hegelund@microchip.com>
> Signed-off-by: Daniel Machon <daniel.machon@microchip.com>
> ---
>  drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c   | 2 ++
>  drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 1 -
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> index fdae62f557ce..cb78acd356d2 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
> @@ -239,6 +239,8 @@ int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb)
>
>         sparx5_fdma_reload(sparx5, fdma);
>
> +       dev_consume_skb_any(skb);
> +
>         return NETDEV_TX_OK;
>  }
>
> diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
> index b6f635d85820..e776fa0845c6 100644
> --- a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
> +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
> @@ -272,7 +272,6 @@ netdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev)
>             SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
>                 return NETDEV_TX_OK;

If packet is freed earlier in sparx5_fdma_xmit(), you have UAF few
lines above here ..

stats->tx_bytes += skb->len; // UAF
...
if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP &&   // UAF
SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)   // UAF


>
> -       dev_consume_skb_any(skb);
>         return NETDEV_TX_OK;
>  drop:
>         stats->tx_dropped++;
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
index fdae62f557ce..cb78acd356d2 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_fdma.c
@@ -239,6 +239,8 @@  int sparx5_fdma_xmit(struct sparx5 *sparx5, u32 *ifh, struct sk_buff *skb)
 
 	sparx5_fdma_reload(sparx5, fdma);
 
+	dev_consume_skb_any(skb);
+
 	return NETDEV_TX_OK;
 }
 
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
index b6f635d85820..e776fa0845c6 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
@@ -272,7 +272,6 @@  netdev_tx_t sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev)
 	    SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP)
 		return NETDEV_TX_OK;
 
-	dev_consume_skb_any(skb);
 	return NETDEV_TX_OK;
 drop:
 	stats->tx_dropped++;