net: sparx5: Fix return type of sparx5_port_xmit_impl
Subsystems (3)
PATCH 1/1 net: sparx5: Fix return type of sparx5_port_xmit_impl
The ndo_start_xmit field in net_device_ops is expected to be of type netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, struct net_device *dev).
The mismatched return type breaks forward edge kCFI since the underlying function definition does not match the function hook definition.
The return type of sparx5_port_xmit_impl should be changed from int to netdev_tx_t.
--- drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +2 -2
@@ -222,13 +222,13 @@ static int sparx5_inject(struct sparx5 *sparx5,return NETDEV_TX_OK ; } -int sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev) +netdev_tx_t sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev) {struct net_device_stats *stats = &dev->stats;struct sparx5_port *port =netdev_priv (dev);struct sparx5 *sparx5 = port->sparx5;u32 ifh[IFH_LEN ]; -int ret; +netdev_tx_t ret;memset (ifh,0 ,IFH_LEN *4 );sparx5_set_port_ifh (ifh, port->portno);
Signature · 1 line
2.37.2.789.g6183377224-goog
Hi,
Quoted 8 lines · Nathan Huckleberry
The
ndo_start_xmitfield innet_device_opsis expected to be of typenetdev_tx_t(*ndo_start_xmit)(structsk_buff*skb, structnet_device*dev).The mismatched return type breaks forward edge kCFI since the underlying function definition does not match the function hook definition.
The return type of
sparx5_port_xmit_implshould be changed from int tonetdev_tx_t.
I noticed that the functions that assign the return value inside sparx5_port_xmit_impl also have return type int, which would ideally also be changed. But a bigger issue might be that sparx5_ptp_txtstamp_request and sparx5_inject (called inside sparx5_port_xmit_impl) returns -EBUSY (-16), when they should return NETDEV_TX_BUSY (16). If this is an issue then it also needs to be fixed.
sparx5_fdma_xmit also has int return type, but always returns NETDEV_TX_OK right now.
Best Regards,
Casper
Hey Casper,
Quoted 13 lines · Casper Andersson
Hi,
Quoted 8 lines · Nathan Huckleberry
The
ndo_start_xmitfield innet_device_opsis expected to be of typenetdev_tx_t(*ndo_start_xmit)(structsk_buff*skb, structnet_device*dev).The mismatched return type breaks forward edge kCFI since the underlying function definition does not match the function hook definition.
The return type of
sparx5_port_xmit_implshould be changed from int tonetdev_tx_t.
Quoted 6 lines
I noticed that the functions that assign the return value inside
sparx5_port_xmit_implalso have return type int, which would ideally also be changed. But a bigger issue might be thatsparx5_ptp_txtstamp_requestandsparx5_inject(called insidesparx5_port_xmit_impl) returns-EBUSY(-16), when they should returnNETDEV_TX_BUSY(16). If this is an issue then it also needs to be fixed.
It's not clear to me what happens when returning an error vs NETDEV_TX_BUSY. The netdev_tx_t enum allows negative values, so returning an error might be valid. If anyone more familiar with this code has insight into why it's done like this, that'd be useful.
The important bit here for me is changing the return type on the hooked function since the current code will cause panics.
Quoted 7 lines
sparx5_fdma_xmitalso has int return type, but always returnsNETDEV_TX_OKright now.Best Regards,
Casper
Thanks,
Huck
Jakub Kicinski
maintainerQuoted 5 lines · On Tue, 13 Sep 2022 10:15:48 +0200 Casper Andersson wrote:
I noticed that the functions that assign the return value inside
sparx5_port_xmit_implalso have return type int, which would ideally also be changed. But a bigger issue might be thatsparx5_ptp_txtstamp_requestandsparx5_inject(called insidesparx5_port_xmit_impl) returns-EBUSY(-16),
Yes, that seems off. IIUC error codes are treated as drops, but the driver doesn't free the frame. So it's likely a leak.
Quoted 2 lines
when they should return
NETDEV_TX_BUSY(16). If this is an issue then it also needs to be fixed.
Jakub Kicinski
maintainerdrivers/net/ethernet/microchip/sparx5/sparx5_packet.c static int sparx5_inject(struct sparx5 *sparx5, · line 225
Quoted 2 lines · On Mon, 12 Sep 2022 14:44:29 -0700 Nathan Huckleberry wrote:
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +1
-1-int sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev) +netdev_tx_t sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev)
Similarly to mana this has a prototype.
PATCH v2 1/1 net: sparx5: Fix return type of sparx5_port_xmit_impl
The ndo_start_xmit field in net_device_ops is expected to be of type netdev_tx_t (*ndo_start_xmit)(struct sk_buff *skb, struct net_device *dev).
The mismatched return type breaks forward edge kCFI since the underlying function definition does not match the function hook definition.
The return type of sparx5_port_xmit_impl should be changed from int to netdev_tx_t.
---
Changes v1 -> v2
- Updated header file
drivers/net/ethernet/microchip/sparx5/sparx5_main.h | 2 +- drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +1 -1
@@ -305,7 +305,7 @@ struct frame_info {void sparx5_xtr_flush (struct sparx5 *sparx5,u8 grp);void sparx5_ifh_parse (u32 *ifh,struct frame_info *info);irqreturn_t sparx5_xtr_handler (int irq,void *_priv); -int sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev); +netdev_tx_t sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev);int sparx5_manual_injection_mode (struct sparx5 *sparx5);void sparx5_port_inj_timer_setup (struct sparx5_port *port);
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +2 -2
@@ -222,13 +222,13 @@ static int sparx5_inject(struct sparx5 *sparx5,return NETDEV_TX_OK ; } -int sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev) +netdev_tx_t sparx5_port_xmit_impl (struct sk_buff *skb,struct net_device *dev) {struct net_device_stats *stats = &dev->stats;struct sparx5_port *port =netdev_priv (dev);struct sparx5 *sparx5 = port->sparx5;u32 ifh[IFH_LEN ]; -int ret; +netdev_tx_t ret;memset (ifh,0 ,IFH_LEN *4 );sparx5_set_port_ifh (ifh, port->portno);
Signature · 1 line
2.38.0.rc1.362.ged0d419d3c-goog
This patch was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <[email protected]>:
Quoted 10 lines · On Thu, 29 Sep 2022 11:19:47 -0700 you wrote:
The
ndo_start_xmitfield innet_device_opsis expected to be of typenetdev_tx_t(*ndo_start_xmit)(structsk_buff*skb, structnet_device*dev).The mismatched return type breaks forward edge kCFI since the underlying function definition does not match the function hook definition.
The return type of
sparx5_port_xmit_implshould be changed from int tonetdev_tx_t.[...]
Here is the summary with links:
- [v2] net: sparx5: Fix return type of sparx5_port_xmit_impl
https://git.kernel.org/netdev/net/c/73ea73507359
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html