From patchwork Wed Oct 10 06:35:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stephen hemminger X-Patchwork-Id: 190564 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 326602C0088 for ; Wed, 10 Oct 2012 17:39:46 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753367Ab2JJGjo (ORCPT ); Wed, 10 Oct 2012 02:39:44 -0400 Received: from fiji.vyatta.com ([76.74.103.50]:52295 "EHLO fiji.vyatta.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752496Ab2JJGjY (ORCPT ); Wed, 10 Oct 2012 02:39:24 -0400 Received: by fiji.vyatta.com (Postfix, from userid 1051) id 1C0E515414E; Tue, 9 Oct 2012 22:27:06 -0700 (PDT) Message-Id: <20121010063623.935671507@vyatta.com> User-Agent: quilt/0.60-1 Date: Tue, 09 Oct 2012 23:35:53 -0700 From: Stephen Hemminger To: davem@davemloft.net Cc: netdev@vger.kernel.org Subject: [PATCHv2 8/8] vxlan: fix oops when give unknown ifindex References: <20121010063545.453368147@vyatta.com> Content-Disposition: inline; filename=vxlan-baddev.patch Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org If vxlan is created and the ifindex is passed; there are two cases which are incorrectly handled by the existing code. The ifindex could be zero (i.e. no device) or there could be no device with that ifindex. Signed-off-by: Stephen Hemminger --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/drivers/net/vxlan.c 2012-10-09 22:07:41.417308505 -0700 +++ b/drivers/net/vxlan.c 2012-10-09 22:09:56.715949703 -0700 @@ -1090,14 +1090,18 @@ static int vxlan_newlink(struct net *net if (data[IFLA_VXLAN_LOCAL]) vxlan->saddr = nla_get_be32(data[IFLA_VXLAN_LOCAL]); - if (data[IFLA_VXLAN_LINK]) { - vxlan->link = nla_get_u32(data[IFLA_VXLAN_LINK]); + if (data[IFLA_VXLAN_LINK] && + (vxlan->link = nla_get_u32(data[IFLA_VXLAN_LINK]))) { + struct net_device *lowerdev + = __dev_get_by_index(net, vxlan->link); - if (!tb[IFLA_MTU]) { - struct net_device *lowerdev; - lowerdev = __dev_get_by_index(net, vxlan->link); - dev->mtu = lowerdev->mtu - VXLAN_HEADROOM; + if (!lowerdev) { + pr_info("ifindex %d does not exist\n", vxlan->link); + return -ENODEV; } + + if (!tb[IFLA_MTU]) + dev->mtu = lowerdev->mtu - VXLAN_HEADROOM; } if (data[IFLA_VXLAN_TOS])