From patchwork Thu Mar 14 03:41:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhouyi Zhou X-Patchwork-Id: 2267441 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id DD6A4DFB79 for ; Thu, 14 Mar 2013 03:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933477Ab3CNDls (ORCPT ); Wed, 13 Mar 2013 23:41:48 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:36212 "EHLO mail-pb0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933437Ab3CNDls (ORCPT ); Wed, 13 Mar 2013 23:41:48 -0400 Received: by mail-pb0-f45.google.com with SMTP id ro8so1665684pbb.18 for ; Wed, 13 Mar 2013 20:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=RFvcH65NXdNvf6eH23ErglLIjDapZgYI6JrfXwJ2EK8=; b=fYiYlYI7+WyYSPL/heBqv0i/ir9y5YkP1zCOszS0Xc1UrcNE8rRBRLOt7EhecYcknN 8pYgtW+TlDUFL9VcUvm81j9kWNkyzvS7+v1ODAt24ykj78wGuKR4hIQ+LCrxFClNytSK YVReaOVIwsrTVDITnJMWsqig1gHiURTqNZfFR+GPU3dniBKIaRKjZ2QMCfdSsNOP6H/p Wpy2Ma9qAFsJdMw7AAwmgVUtRGb3CiCenZZILdgWbExo9CNKWNE46IfLKEeXbrGAqzlx 3XmUV0CX4gdR81lfZ5AbYj4gczQX+yz2MWLmAMqA+M25hXdt8/9308rWrOKhByzCd+Ul pSNQ== X-Received: by 10.68.234.100 with SMTP id ud4mr2197307pbc.8.1363232507530; Wed, 13 Mar 2013 20:41:47 -0700 (PDT) Received: from localhost.localdomain ([159.226.43.61]) by mx.google.com with ESMTPS id gf6sm1120923pbc.24.2013.03.13.20.41.43 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 13 Mar 2013 20:41:46 -0700 (PDT) From: Zhouyi Zhou To: , Cc: , , , , , , Zhouyi Zhou Subject: [PATCH 1/1] Fix dst_neigh_lookup/dst_neigh_lookup_skb return value handling bug Date: Thu, 14 Mar 2013 11:41:32 +0800 Message-Id: <1363232492-4562-1-git-send-email-zhouzhouyi@gmail.com> X-Mailer: git-send-email 1.7.10.4 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org Tested on my x86_64 machine Signed-off-by: Zhouyi Zhou Acked-by: Steve Wise --- drivers/infiniband/hw/cxgb4/cm.c | 12 ++++++++++++ include/net/dst.h | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c index 565bfb1..6b95851 100644 --- a/drivers/infiniband/hw/cxgb4/cm.c +++ b/drivers/infiniband/hw/cxgb4/cm.c @@ -1575,6 +1575,12 @@ static int c4iw_reconnect(struct c4iw_ep *ep) neigh = dst_neigh_lookup(ep->dst, &ep->com.cm_id->remote_addr.sin_addr.s_addr); + if (!neigh) { + pr_err("%s - cannot alloc neigh.\n", __func__); + err = -ENOMEM; + goto fail4; + } + /* get a l2t entry */ if (neigh->dev->flags & IFF_LOOPBACK) { PDBG("%s LOOPBACK\n", __func__); @@ -3053,6 +3059,12 @@ static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb) dst = &rt->dst; neigh = dst_neigh_lookup_skb(dst, skb); + if (!neigh) { + pr_err("%s - failed to allocate neigh!\n", + __func__); + goto free_dst; + } + if (neigh->dev->flags & IFF_LOOPBACK) { pdev = ip_dev_find(&init_net, iph->daddr); e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, diff --git a/include/net/dst.h b/include/net/dst.h index 853cda1..c083b5a 100644 --- a/include/net/dst.h +++ b/include/net/dst.h @@ -413,13 +413,15 @@ static inline int dst_neigh_output(struct dst_entry *dst, struct neighbour *n, static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr) { - return dst->ops->neigh_lookup(dst, NULL, daddr); + struct neighbour *n = dst->ops->neigh_lookup(dst, NULL, daddr); + return IS_ERR(n) ? NULL : n; } static inline struct neighbour *dst_neigh_lookup_skb(const struct dst_entry *dst, struct sk_buff *skb) { - return dst->ops->neigh_lookup(dst, skb, NULL); + struct neighbour *n = dst->ops->neigh_lookup(dst, skb, NULL); + return IS_ERR(n) ? NULL : n; } static inline void dst_link_failure(struct sk_buff *skb)