Skip to content

Commit aaa0c23

Browse files
zhouzhouyi-hubdavem330
authored andcommitted
Fix dst_neigh_lookup/dst_neigh_lookup_skb return value handling bug
When neighbour table is full, dst_neigh_lookup/dst_neigh_lookup_skb will return -ENOBUFS which is absolutely non zero, while all the code in kernel which use above functions assume failure only on zero return which will cause panic. (for example: : https://bugzilla.kernel.org/show_bug.cgi?id=54731). This patch corrects above error with smallest changes to kernel source code and also correct two return value check missing bugs in drivers/infiniband/hw/cxgb4/cm.c Tested on my x86_64 SMP machine Reported-by: Zhouyi Zhou <zhouzhouyi@gmail.com> Tested-by: Zhouyi Zhou <zhouzhouyi@gmail.com> Signed-off-by: Zhouyi Zhou <zhouzhouyi@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1e731cb commit aaa0c23

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

  • drivers/infiniband/hw/cxgb4
  • include/net

‎drivers/infiniband/hw/cxgb4/cm.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,12 @@ static int c4iw_reconnect(struct c4iw_ep *ep)
15751575

15761576
neigh = dst_neigh_lookup(ep->dst,
15771577
&ep->com.cm_id->remote_addr.sin_addr.s_addr);
1578+
if (!neigh) {
1579+
pr_err("%s - cannot alloc neigh.\n", __func__);
1580+
err = -ENOMEM;
1581+
goto fail4;
1582+
}
1583+
15781584
/* get a l2t entry */
15791585
if (neigh->dev->flags & IFF_LOOPBACK) {
15801586
PDBG("%s LOOPBACK\n", __func__);
@@ -3053,6 +3059,12 @@ static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
30533059
dst = &rt->dst;
30543060
neigh = dst_neigh_lookup_skb(dst, skb);
30553061

3062+
if (!neigh) {
3063+
pr_err("%s - failed to allocate neigh!\n",
3064+
__func__);
3065+
goto free_dst;
3066+
}
3067+
30563068
if (neigh->dev->flags & IFF_LOOPBACK) {
30573069
pdev = ip_dev_find(&init_net, iph->daddr);
30583070
e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,

‎include/net/dst.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,15 @@ static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n,
413413

414414
static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
415415
{
416-
return dst->ops->neigh_lookup(dst, NULL, daddr);
416+
struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr);
417+
return IS_ERR(n) ? NULL : n;
417418
}
418419

419420
static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst,
420421
struct sk_buff *skb)
421422
{
422-
return dst->ops->neigh_lookup(dst, skb, NULL);
423+
struct neighbour *n = dst->ops->neigh_lookup(dst, skb, NULL);
424+
return IS_ERR(n) ? NULL : n;
423425
}
424426

425427
static inline void dst_link_failure(struct sk_buff *skb)

0 commit comments

Comments
 (0)