Re: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free

2017-07-20 Thread Dan Carpenter
Ah.  Good.  My mistake.

regards,
dan carpenter

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


RE: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free

2017-07-20 Thread Bogdan Purcareata
> -Original Message-
> From: Dan Carpenter [mailto:dan.carpen...@oracle.com]
> Sent: Thursday, July 20, 2017 2:18 PM
> To: Bogdan Purcareata <bogdan.purcare...@nxp.com>
> Cc: Ruxandra Ioana Radulescu <ruxandra.radule...@nxp.com>;
> gre...@linuxfoundation.org; linux-ker...@vger.kernel.org;
> de...@driverdev.osuosl.org
> Subject: Re: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free
> 
> On Thu, Jul 20, 2017 at 10:58:37AM +, Bogdan Purcareata wrote:
> > Once a Tx frame descriptor is enqueued, an interrupt might be triggered
> > to process the Tx confirmation and free the skb, hitting a memory use
> > after free when updating the tx_bytes statistic based on skb->len.
> >
> > Use the frame descriptor length instead.
> >
> > Signed-off-by: Bogdan Purcareata <bogdan.purcare...@nxp.com>
> > ---
> >  drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> > index b9a0a31..0f3e497 100644
> > --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> > +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> > @@ -616,7 +616,7 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb,
> struct net_device *net_dev)
> > free_tx_fd(priv, , NULL);
> > } else {
> > percpu_stats->tx_packets++;
> > -   percpu_stats->tx_bytes += skb->len;
> > +   percpu_stats->tx_bytes += dpaa2_fd_get_len();
> 
> This feels like the wrong thing.  Can't we just save skb->len earlier
> in the function and use it here?  This is the common case right?  So
> we'd be saving slightly wrong information for almost every packet.

The "len" field in the frame descriptor means the length of the actual data, 
like the "len" field in the skb. It's set to skb->len both for linear 
(build_single_fd) and fragmented (build_sg_fd) skbs. I thought it would be more 
straightforward to use it rather than define an additional local variable 
solely for this purpose.

Thank you!
Bogdan P.
___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel


Re: [PATCH 1/2] staging: fsl-dpaa2/eth: Fix skb use after free

2017-07-20 Thread Dan Carpenter
On Thu, Jul 20, 2017 at 10:58:37AM +, Bogdan Purcareata wrote:
> Once a Tx frame descriptor is enqueued, an interrupt might be triggered
> to process the Tx confirmation and free the skb, hitting a memory use
> after free when updating the tx_bytes statistic based on skb->len.
> 
> Use the frame descriptor length instead.
> 
> Signed-off-by: Bogdan Purcareata 
> ---
>  drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c 
> b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> index b9a0a31..0f3e497 100644
> --- a/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> +++ b/drivers/staging/fsl-dpaa2/ethernet/dpaa2-eth.c
> @@ -616,7 +616,7 @@ static netdev_tx_t dpaa2_eth_tx(struct sk_buff *skb, 
> struct net_device *net_dev)
>   free_tx_fd(priv, , NULL);
>   } else {
>   percpu_stats->tx_packets++;
> - percpu_stats->tx_bytes += skb->len;
> + percpu_stats->tx_bytes += dpaa2_fd_get_len();

This feels like the wrong thing.  Can't we just save skb->len earlier
in the function and use it here?  This is the common case right?  So
we'd be saving slightly wrong information for almost every packet.

regards,
dan carpenter

___
devel mailing list
de...@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel