Skip to contentSkip to conversation

hamradio: avoid null deref

PATCH In review Dan Carpenter 3 participants 7 messages Dec 23, 2009 – Jan 4, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hamradio: avoid null deref

If dev == NULL we shouldn't dereference it.

drivers/net/hamradio/bpqether.c +0 -1
@@ -283,7 +283,6 @@ static netdev_tx_t bpq_xmit(struct sk_bu
 	bpq = netdev_priv(dev);
 
 	if ((dev = bpq_get_ether_dev(dev)) == NULL) {
-		dev->stats.tx_dropped++;
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
#1 lore raw

Dan Carpenter wrote, On 12/23/2009 02:25 PM:

drivers/net/hamradio/bpqether.c static netdev_tx_t bpq_xmit(struct sk_bu · line 286

Quoted 11 lines

If dev == NULL we shouldn't dereference it.

drivers/net/hamradio/bpqether.c +0 -1
@@ -283,7 +283,6 @@ static netdev_tx_t bpq_xmit(struct sk_bu
 	bpq = netdev_priv(dev);
 
 	if ((dev = bpq_get_ether_dev(dev)) == NULL) {
-		dev->stats.tx_dropped++;

Why not use a separate variable for another dev? This stat should be helpful for debugging.

Jarek P.

Quoted 3 lines
drivers/net/hamradio/bpqether.c +0 -0
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
maintainer
#2 lore raw

From: Jarek Poplawski <[email protected]>
Date: Wed, 23 Dec 2009 18:47:46 +0100

Quoted 11 lines

Dan Carpenter wrote, On 12/23/2009 02:25 PM:

Quoted 9 lines

If dev == NULL we shouldn't dereference it.

drivers/net/hamradio/bpqether.c +0 -0
@@ -283,7 +283,6 @@ static netdev_tx_t bpq_xmit(struct sk_bu
 	bpq = netdev_priv(dev);
 
Quoted 5 lines

drivers/net/hamradio/bpqether.c static netdev_tx_t bpq_xmit(struct sk_bu · line 286

Quoted 2 lines
drivers/net/hamradio/bpqether.c +0 -1
 	if ((dev = bpq_get_ether_dev(dev)) == NULL) {
-		dev->stats.tx_dropped++;

Why not use a separate variable for another dev? This stat should be helpful for debugging.

And that is definitely the intent of the code here, to bump the statistic in the original device object.

#3 lore raw

PATCH 1/1 hamradio: avoid null deref v2

In reply to Jarek Poplawski

Bump the stats on the original dev not on the newly assigned NULL version of dev.

drivers/net/hamradio/bpqether.c +2 -1
@@ -282,11 +282,12 @@ static netdev_tx_t bpq_xmit(struct sk_bu
 
 	bpq = netdev_priv(dev);
 
-	if ((dev = bpq_get_ether_dev(dev)) == NULL) {
+	if (!bpq->ethdev) {
 		dev->stats.tx_dropped++;
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
+	dev = bpq_get_ether_dev(dev);
 
 	skb->protocol = ax25_type_trans(skb, dev);
 	skb_reset_network_header(skb);
maintainer
#4 lore raw

Re: [patch] hamradio: avoid null deref v2

From: Dan Carpenter <[email protected]>
Date: Sat, 26 Dec 2009 14:38:12 +0200

Quoted 4 lines

Bump the stats on the original dev not on the newly assigned NULL version of dev.

This doesn't look real nice.

The bpq_get_ether_dev() abstraction exists so that the details of bpq->this and bpq->that are hidden behind it.

Exposing those details inline just to fix this bug makes the abstraction significantly less useful, and the code more ugly.

Please just create an "orig_dev" pointer to save the original device in, and use it to fix this problem properly.

That way you only fetch the bpq ether device pointer via the abstraction interface.

And BTW, this is how other reviewers told you to implement this fix. :-)

Thanks.

#5 lore raw

PATCH 1/1 hamradio: avoid null deref v3

This should address the problems in version 1 (lazy) and version 2 (ugly).

Bump the stats on orig_dev not on the newly assigned NULL dev variable.

drivers/net/hamradio/bpqether.c +3 -1
@@ -248,6 +248,7 @@ static netdev_tx_t bpq_xmit(struct sk_bu
 {
 	unsigned char *ptr;
 	struct bpqdev *bpq;
+	struct net_device *orig_dev;
 	int size;
 
 	/*
@@ -282,8 +283,9 @@ static netdev_tx_t bpq_xmit(struct sk_bu
 
 	bpq = netdev_priv(dev);
 
+	orig_dev = dev;
 	if ((dev = bpq_get_ether_dev(dev)) == NULL) {
-		dev->stats.tx_dropped++;
+		orig_dev->stats.tx_dropped++;
 		kfree_skb(skb);
 		return NETDEV_TX_OK;
 	}
maintainer Applied
#6 lore raw

Re: [patch] hamradio: avoid null deref v3

From: Dan Carpenter <[email protected]>
Date: Mon, 28 Dec 2009 18:54:55 +0200

Quoted 5 lines

This should address the problems in version 1 (lazy) and version 2 (ugly).

Bump the stats on orig_dev not on the newly assigned NULL dev variable.

Applied.