Skip to contentSkip to conversation

baycom_par dereference before check.

PATCH Dave Jones 4 participants 8 messages Apr 16, 2004 – Apr 19, 2004 Network drivers

lore
Share & tools
lore

Dave Jones

author
#0 lore raw
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +6 -2
@@ -272,9 +272,13 @@
 static void par96_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	struct net_device *dev = (struct net_device *)dev_id;
-	struct baycom_state *bc = netdev_priv(dev);
+	struct baycom_state *bc;
 
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
+	if (!dev)
+		return;
+
+	bc = netdev_priv(dev);
+	if (!bc || bc->hdrv.magic != HDLCDRV_MAGIC)
 		return;
 
 	baycom_int_freq(bc);
#1 lore raw
Quoted 5 lines · Dave Jones
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +0 -0
@@ -272,9 +272,13 @@
 static void par96_interrupt(int irq, void *dev_id, struct pt_regs *regs)

drivers/net/hamradio/baycom_par.c line 280

Quoted 10 lines
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +5 -2
 {
 	struct net_device *dev = (struct net_device *)dev_id;
-	struct baycom_state *bc = netdev_priv(dev);
+	struct baycom_state *bc;
 
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
+	if (!dev)
+		return;
+
+	bc = netdev_priv(dev);

That's OK - netdev_priv(p) just adds a constant offset to p; no problem with doing that to NULL.

author
#2 lore raw
Quoted 8 lines · On Fri, Apr 16, 2004 at 10:25:41PM +0100…
Quoted 8 lines

+++ linux-2.6.5/drivers/net/hamradio/baycom_par.c 2004-04-16 22:19:33.000000000 +0100

drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +1 -1
@@ -272,9 +272,13 @@
 static void par96_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	struct net_device *dev = (struct net_device *)dev_id;
-	struct baycom_state *bc = netdev_priv(dev);
+	struct baycom_state *bc;
 
Quoted 8 lines

drivers/net/hamradio/baycom_par.c line 280

Quoted 5 lines
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +4 -1
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
+	if (!dev)
+		return;
+
+	bc = netdev_priv(dev);

That's OK - netdev_priv(p) just adds a constant offset to p; no problem with doing that to NULL.

Good point. Still doesn't strike me as particularly nice though.

Dave

#3 lore raw
Quoted 19 lines · Dave Jones
Quoted 8 lines · On Fri, Apr 16, 2004 at 10:25:41PM +0100…
Quoted 8 lines

+++ linux-2.6.5/drivers/net/hamradio/baycom_par.c 2004-04-16 22:19:33.000000000 +0100

drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +1 -1
@@ -272,9 +272,13 @@
 static void par96_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
 	struct net_device *dev = (struct net_device *)dev_id;
-	struct baycom_state *bc = netdev_priv(dev);
+	struct baycom_state *bc;
 
Quoted 8 lines

drivers/net/hamradio/baycom_par.c line 280

Quoted 5 lines
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +4 -1
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
+	if (!dev)
+		return;
+
+	bc = netdev_priv(dev);

That's OK - netdev_priv(p) just adds a constant offset to p; no problem with doing that to NULL.

Quoted 1 line

Good point. Still doesn't strike me as particularly nice though.

I would rather just remove the checks completely. The success of any of those checks is a BUG() condition that should never occur.

Jeff

author
#4 lore raw
Quoted 3 lines · Jeff Garzik
Quoted 1 line

Good point. Still doesn't strike me as particularly nice though.

I would rather just remove the checks completely. The success of any of those checks is a BUG() condition that should never occur.

That works for me too. How about this?

Dave

drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +2 -2
@@ -274,8 +274,8 @@
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct baycom_state *bc = netdev_priv(dev);
 
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
-		return;
+	BUG_ON(!bc);
+	BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);
 
 	baycom_int_freq(bc);
 	/*
#5 lore raw
Quoted 12 lines · * Dave Jones ([email protected]) wrote:
Quoted 3 lines · Jeff Garzik
Quoted 1 line

Good point. Still doesn't strike me as particularly nice though.

I would rather just remove the checks completely. The success of any of those checks is a BUG() condition that should never occur.

That works for me too. How about this?

Dave

drivers/net/hamradio/baycom_par.c line 277

Quoted 6 lines
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +1 -2
@@ -274,8 +274,8 @@
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct baycom_state *bc = netdev_priv(dev);
 
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
-		return;
+	BUG_ON(!bc);

If it's adding a constant offset to dev, the bc would be non-NULL in a bug case, no?

thanks,
-chris

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
#6 lore raw
Quoted 16 lines · Chris Wright
Quoted 14 lines · * Dave Jones ([email protected]) wrote:
Quoted 2 lines · Jeff Garzik
Quoted 1 line

Good point. Still doesn't strike me as particularly nice though.

I would rather just remove the checks completely. The success of any of those checks is a BUG() condition that should never occur.

That works for me too. How about this?

Dave

drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +0 -0
@@ -274,8 +274,8 @@
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct baycom_state *bc = netdev_priv(dev);
 
Quoted 7 lines

drivers/net/hamradio/baycom_par.c line 277

Quoted 3 lines
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +1 -2
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
-		return;
+	BUG_ON(!bc);

If it's adding a constant offset to dev, the bc would be non-NULL in a bug case, no?

I'm just going to remove the checks completely.

Jeff

#7 lore raw
In reply to Dave Jones
Quoted 13 lines · Dave Jones
Quoted 3 lines · Jeff Garzik
Quoted 1 line

Good point. Still doesn't strike me as particularly nice though.

I would rather just remove the checks completely. The success of any of those checks is a BUG() condition that should never occur.

That works for me too. How about this?

Dave

drivers/net/hamradio/baycom_par.c line 278

Quoted 7 lines
drivers/net/hamradio/baycom_par.c renamed from drivers/net/hamradio/baycom_par.c~ +2 -2
@@ -274,8 +274,8 @@
 	struct net_device *dev = (struct net_device *)dev_id;
 	struct baycom_state *bc = netdev_priv(dev);
 
-	if (!dev || !bc || bc->hdrv.magic != HDLCDRV_MAGIC)
-		return;
+	BUG_ON(!bc);
+	BUG_ON(bc->hdrv.magic != HDLCDRV_MAGIC);

I applied a patch which simplied removed the checks.

Jeff