net: Fix skb_under_panic oops in neigh_resolve_output
Subsystems (2)
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
@@ -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
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()andneigh_connected_output()calldev_hard_header()with out reseting the skb tonetwork_header. This causes the retry to fail withskb_under_panic. The fix is to reset thenetwork_headerwithin the retry loop.Signed-off-by Ramesh Nagappa <[email protected]>Reviewed-by Shawn Lu <[email protected]>Reviewed-by Robert Coulson <[email protected]>Reviewed-by Billie Alsup <[email protected]>--- net/core/neighbour.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/core/neighbour.c +0
-0
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
-2err =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
-0err =dev_hard_header (skb, dev,ntohs (skb->protocol), neigh->ha,NULL , skb->len); }while (read_seqretry (&neigh->ha_lock, seq));
Thanks
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
-0do { seq = read_seqbegin(&neigh->ha_lock); + __skb_pull(skb, skb_network_offset(skb));This
__skb_pull()could be done before theread_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
-0err =dev_hard_header (skb, dev,ntohs (skb->protocol), neigh->ha,NULL , skb->len); }while (read_seqretry (&neigh->ha_lock, seq));Thanks
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
-0if (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()