Message ID | 20220912214432.928989-1-nhuck@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | net: sparx5: Fix return type of sparx5_port_xmit_impl | expand |
Hi, On 2022-09-12 14:44, Nathan Huckleberry wrote: > 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. 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, On Tue, Sep 13, 2022 at 1:15 AM Casper Andersson <casper.casan@gmail.com> wrote: > > Hi, > > On 2022-09-12 14:44, Nathan Huckleberry wrote: > > 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. > > 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. 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. > > sparx5_fdma_xmit also has int return type, but always returns > NETDEV_TX_OK right now. > > Best Regards, > Casper > Thanks, Huck
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_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), 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. > when they should return NETDEV_TX_BUSY (16). If this is an issue then > it also needs to be fixed.
On Mon, 12 Sep 2022 14:44:29 -0700 Nathan Huckleberry wrote: > -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.
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c index 21844beba72d..83c16ca5b30f 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_packet.c @@ -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);
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. Reported-by: Dan Carpenter <error27@gmail.com> Link: https://github.com/ClangBuiltLinux/linux/issues/1703 Cc: llvm@lists.linux.dev Signed-off-by: Nathan Huckleberry <nhuck@google.com> --- drivers/net/ethernet/microchip/sparx5/sparx5_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)