From patchwork Thu Nov 19 16:42:33 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 61383 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nAJGdYVL031293 for ; Thu, 19 Nov 2009 16:42:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751480AbZKSQm2 (ORCPT ); Thu, 19 Nov 2009 11:42:28 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751634AbZKSQm2 (ORCPT ); Thu, 19 Nov 2009 11:42:28 -0500 Received: from mga01.intel.com ([192.55.52.88]:52138 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751480AbZKSQm2 (ORCPT ); Thu, 19 Nov 2009 11:42:28 -0500 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP; 19 Nov 2009 08:37:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.44,771,1249282800"; d="scan'208";a="748579363" Received: from unknown (HELO msheftyMOBL2) ([10.24.204.33]) by fmsmga001.fm.intel.com with ESMTP; 19 Nov 2009 08:48:59 -0800 From: "Sean Hefty" To: "Hefty, Sean" , References: <4329E49DC571489C9F9498770613E42D@amr.corp.intel.com> <75A0BA738B5E4574AC17BB674109FBB2@amr.corp.intel.com> Subject: [PATCH 5/9 v3] ib/addr: verify source and destination address families match Date: Thu, 19 Nov 2009 08:42:33 -0800 Message-ID: <43664E6645FF46A68C1A575E0E0D1263@amr.corp.intel.com> MIME-Version: 1.0 X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcpnGPNQqFVf+RZQRByQrHI8lNxRcwBVgAHAADHmijA= In-Reply-To: <75A0BA738B5E4574AC17BB674109FBB2@amr.corp.intel.com> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c index 788a02e..b59ba7c 100644 --- a/drivers/infiniband/core/addr.c +++ b/drivers/infiniband/core/addr.c @@ -461,18 +461,27 @@ int rdma_resolve_ip(struct rdma_addr_client *client, if (!req) return -ENOMEM; - if (src_addr) - memcpy(&req->src_addr, src_addr, ip_addr_size(src_addr)); - memcpy(&req->dst_addr, dst_addr, ip_addr_size(dst_addr)); + src_in = (struct sockaddr *) &req->src_addr; + dst_in = (struct sockaddr *) &req->dst_addr; + + if (src_addr) { + if (src_addr->sa_family != dst_addr->sa_family) { + ret = -EINVAL; + goto err; + } + + memcpy(src_in, src_addr, ip_addr_size(src_addr)); + } else { + src_in->sa_family = dst_addr->sa_family; + } + + memcpy(dst_in, dst_addr, ip_addr_size(dst_addr)); req->addr = addr; req->callback = callback; req->context = context; req->client = client; atomic_inc(&client->refcount); - src_in = (struct sockaddr *) &req->src_addr; - dst_in = (struct sockaddr *) &req->dst_addr; - req->status = addr_resolve_local(src_in, dst_in, addr); if (req->status == -EADDRNOTAVAIL) req->status = addr_resolve_remote(src_in, dst_in, addr); @@ -490,10 +499,12 @@ int rdma_resolve_ip(struct rdma_addr_client *client, default: ret = req->status; atomic_dec(&client->refcount); - kfree(req); - break; + goto err; } return ret; +err: + kfree(req); + return ret; } EXPORT_SYMBOL(rdma_resolve_ip);