diff mbox series

[net-next] net: dm9051: Fix use after free in dm9051_loop_tx()

Message ID 20220218152730.GA4299@kili (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: dm9051: Fix use after free in dm9051_loop_tx() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 2 maintainers not CCed: colin.king@intel.com yang.lee@linux.alibaba.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dan Carpenter Feb. 18, 2022, 3:27 p.m. UTC
This code dereferences "skb" after calling dev_kfree_skb().

Fixes: 2dc95a4d30ed ("net: Add dm9051 driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/net/ethernet/davicom/dm9051.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jakub Kicinski Feb. 19, 2022, 5:07 a.m. UTC | #1
On Fri, 18 Feb 2022 18:27:30 +0300 Dan Carpenter wrote:
> This code dereferences "skb" after calling dev_kfree_skb().
> 
> Fixes: 2dc95a4d30ed ("net: Add dm9051 driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Thanks!  Although..

> diff --git a/drivers/net/ethernet/davicom/dm9051.c b/drivers/net/ethernet/davicom/dm9051.c
> index a63d17e669a0..f6b5d2becf5e 100644
> --- a/drivers/net/ethernet/davicom/dm9051.c
> +++ b/drivers/net/ethernet/davicom/dm9051.c
> @@ -850,13 +850,13 @@ static int dm9051_loop_tx(struct board_info *db)
>  		if (skb) {
>  			ntx++;
>  			ret = dm9051_single_tx(db, skb->data, skb->len);
> +			ndev->stats.tx_bytes += skb->len;
> +			ndev->stats.tx_packets++;
>  			dev_kfree_skb(skb);
>  			if (ret < 0) {
>  				db->bc.tx_err_counter++;
>  				return 0;
>  			}
> -			ndev->stats.tx_bytes += skb->len;
> -			ndev->stats.tx_packets++;

I think the idea was (and it often is with this kind of bugs)
to count only successful transmissions. Could you re-jig it 
a little to keep those semantics?
Dan Carpenter Feb. 21, 2022, 10:31 a.m. UTC | #2
On Fri, Feb 18, 2022 at 09:07:12PM -0800, Jakub Kicinski wrote:
> On Fri, 18 Feb 2022 18:27:30 +0300 Dan Carpenter wrote:
> > This code dereferences "skb" after calling dev_kfree_skb().
> > 
> > Fixes: 2dc95a4d30ed ("net: Add dm9051 driver")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> Thanks!  Although..
> 
> > diff --git a/drivers/net/ethernet/davicom/dm9051.c b/drivers/net/ethernet/davicom/dm9051.c
> > index a63d17e669a0..f6b5d2becf5e 100644
> > --- a/drivers/net/ethernet/davicom/dm9051.c
> > +++ b/drivers/net/ethernet/davicom/dm9051.c
> > @@ -850,13 +850,13 @@ static int dm9051_loop_tx(struct board_info *db)
> >  		if (skb) {
> >  			ntx++;
> >  			ret = dm9051_single_tx(db, skb->data, skb->len);
> > +			ndev->stats.tx_bytes += skb->len;
> > +			ndev->stats.tx_packets++;
> >  			dev_kfree_skb(skb);
> >  			if (ret < 0) {
> >  				db->bc.tx_err_counter++;
> >  				return 0;
> >  			}
> > -			ndev->stats.tx_bytes += skb->len;
> > -			ndev->stats.tx_packets++;
> 
> I think the idea was (and it often is with this kind of bugs)
> to count only successful transmissions. Could you re-jig it 
> a little to keep those semantics?

Sure.  Will resend.

regards,
dan carpenter
diff mbox series

Patch

diff --git a/drivers/net/ethernet/davicom/dm9051.c b/drivers/net/ethernet/davicom/dm9051.c
index a63d17e669a0..f6b5d2becf5e 100644
--- a/drivers/net/ethernet/davicom/dm9051.c
+++ b/drivers/net/ethernet/davicom/dm9051.c
@@ -850,13 +850,13 @@  static int dm9051_loop_tx(struct board_info *db)
 		if (skb) {
 			ntx++;
 			ret = dm9051_single_tx(db, skb->data, skb->len);
+			ndev->stats.tx_bytes += skb->len;
+			ndev->stats.tx_packets++;
 			dev_kfree_skb(skb);
 			if (ret < 0) {
 				db->bc.tx_err_counter++;
 				return 0;
 			}
-			ndev->stats.tx_bytes += skb->len;
-			ndev->stats.tx_packets++;
 		}
 
 		if (netif_queue_stopped(ndev) &&