Skip to contentSkip to conversation

net: Fix skb_under_panic oops in neigh_resolve_output

PATCH Superseded [email protected] 3 participants 4 messages Oct 5, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: Fix skb_under_panic oops in neigh_resolve_output

From: Ramesh Nagappa <[email protected]>

The retry loop in neigh_resolve_output() and neigh_connected_output() call dev_hard_header() with out reseting the skb to network_header. This causes the retry to fail with skb_under_panic. The fix is to reset the network_header within the retry loop.

---
 net/core/neighbour.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/neighbour.c +2 -2
index 117afaf..f50c542 100644
@@ -1313,6 +1313,7 @@ int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)
 
 		do {
 			seq = read_seqbegin(&neigh->ha_lock);
+			__skb_pull(skb, skb_network_offset(skb));
 			err = dev_hard_header(skb, dev, ntohs(skb->protocol),
 					      neigh->ha, NULL, skb->len);
 		} while (read_seqretry(&neigh->ha_lock, seq));
@@ -1342,10 +1343,9 @@ int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)
 	unsigned int seq;
 	int err;
 
-	__skb_pull(skb, skb_network_offset(skb));
-
 	do {
 		seq = read_seqbegin(&neigh->ha_lock);
+		__skb_pull(skb, skb_network_offset(skb));
 		err = dev_hard_header(skb, dev, ntohs(skb->protocol),
 				      neigh->ha, NULL, skb->len);
 	} while (read_seqretry(&neigh->ha_lock, seq));
Signature · 1 line
1.7.11.4
#1 lore raw
Quoted 20 lines · On Thu, 2012-10-04 at 20:05 -0700, [email protected] wrote:

From: Ramesh Nagappa <[email protected]>

The retry loop in neigh_resolve_output() and neigh_connected_output() call dev_hard_header() with out reseting the skb to network_header. This causes the retry to fail with skb_under_panic. The fix is to reset the network_header within the retry loop.

---
 net/core/neighbour.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/neighbour.c +0 -0
index 117afaf..f50c542 100644

net/core/neighbour.c int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb) · line 1316

Quoted 4 lines
net/core/neighbour.c +1 -0
@@ -1313,6 +1313,7 @@ int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb)
 
 		do {
 			seq = read_seqbegin(&neigh->ha_lock);
+			__skb_pull(skb, skb_network_offset(skb));

This __skb_pull() could be done before the read_seqbegin() to keep the protected section short.

net/core/neighbour.c int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb) · line 1348

Quoted 12 lines
net/core/neighbour.c +1 -2
 			err = dev_hard_header(skb, dev, ntohs(skb->protocol),
 					      neigh->ha, NULL, skb->len);
 		} while (read_seqretry(&neigh->ha_lock, seq));
@@ -1342,10 +1343,9 @@ int neigh_connected_output(struct neighbour *neigh, struct sk_buff *skb)
 	unsigned int seq;
 	int err;
 
-	__skb_pull(skb, skb_network_offset(skb));
-
 	do {
 		seq = read_seqbegin(&neigh->ha_lock);
+		__skb_pull(skb, skb_network_offset(skb));

This __skb_pull() could be done before the read_seqbegin() to keep the protected section short.

net/core/neighbour.c int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb) · line 1319

Quoted 3 lines
net/core/neighbour.c +0 -0
 		err = dev_hard_header(skb, dev, ntohs(skb->protocol),
 				      neigh->ha, NULL, skb->len);
 	} while (read_seqretry(&neigh->ha_lock, seq));

Thanks

#2 lore raw

Hi Eric,

Yes, that is a good optimization. neigh_resolve_output() also has the __skb_pull() outside the loop, is that required ? The changes would be like ...

neigh_resolve_output()
...
- __skb_pull(skb, skb_network_offset(skb));

        if (!neigh_event_send(neigh, skb)) {
                int err;
                struct net_device *dev = neigh->dev;
                unsigned int seq;

                if (dev->header_ops->cache && !neigh->hh.hh_len)
                        neigh_hh_init(neigh, dst);

                do {                        
+			      __skb_pull(skb, skb_network_offset(skb));
                        seq = read_seqbegin(&neigh->ha_lock);
                        err = dev_hard_header(skb, dev, ntohs(skb->protocol),
                                              neigh->ha, NULL, skb->len);
                } while (read_seqretry(&neigh->ha_lock, seq));

Thanks,
Ramesh

Quoted 17 lines

-----Original Message-----
From: Eric Dumazet [mailto:[email protected]]

net/core/neighbour.c int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb) · line 1316

Quoted 3 lines
net/core/neighbour.c +1 -0
 	do {
 		seq = read_seqbegin(&neigh->ha_lock);
+		__skb_pull(skb, skb_network_offset(skb));

This __skb_pull() could be done before the read_seqbegin() to keep the protected section short.

net/core/neighbour.c int neigh_resolve_output(struct neighbour *neigh, struct sk_buff *skb) · line 1319

Quoted 3 lines
net/core/neighbour.c +0 -0
 		err = dev_hard_header(skb, dev, ntohs(skb->protocol),
 				      neigh->ha, NULL, skb->len);
 	} while (read_seqretry(&neigh->ha_lock, seq));

Thanks

#3 lore raw
Quoted 15 lines · Ramesh Nagappa

Hi Eric,

Yes, that is a good optimization. neigh_resolve_output() also has the __skb_pull() outside the loop, is that required ? The changes would be like ...

neigh_resolve_output()
...

(quoted diff) +0 -1
-        __skb_pull(skb, skb_network_offset(skb));
 
 
        if (!neigh_event_send(neigh, skb)) {
                int err;
                struct net_device *dev = neigh->dev;
                unsigned int seq;

Review

Quoted 10 lines
(quoted diff) +1 -0
 
                if (dev->header_ops->cache && !neigh->hh.hh_len)
                        neigh_hh_init(neigh, dst);
 
                do {                        
+			      __skb_pull(skb, skb_network_offset(skb));
                        seq = read_seqbegin(&neigh->ha_lock);
                        err = dev_hard_header(skb, dev, ntohs(skb->protocol),
                                              neigh->ha, NULL, skb->len);
                } while (read_seqretry(&neigh->ha_lock, seq));

All similar constructions should be audited.

For example in net/decnet/dn_neigh.c , dn_neigh_output_packet()