From patchwork Mon Aug 7 06:41:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Langrock X-Patchwork-Id: 798489 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xQnxX55stz9t2Q for ; Mon, 7 Aug 2017 16:41:36 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752087AbdHGGle (ORCPT ); Mon, 7 Aug 2017 02:41:34 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:59538 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752065AbdHGGld (ORCPT ); Mon, 7 Aug 2017 02:41:33 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id A636220068 for ; Mon, 7 Aug 2017 08:41:32 +0200 (CEST) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id E6SSBiRLgACi for ; Mon, 7 Aug 2017 08:41:32 +0200 (CEST) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 2F87020062 for ; Mon, 7 Aug 2017 08:41:32 +0200 (CEST) Received: from [10.182.7.63] (10.182.7.63) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server (TLS) id 14.3.361.1; Mon, 7 Aug 2017 08:41:31 +0200 To: From: Christian Langrock Subject: [PATCH] ip/link_vti6.c: Fix local/remote any handling Message-ID: <4608c5ed-6b73-4bc2-f193-66e5129d855e@secunet.com> Date: Mon, 7 Aug 2017 08:41:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org According to the IPv4 behavior of 'ip' it should be possible to omit the arguments for local and remote address. Without this patch omitting these parameters would lead to uninitialized memory being interpreted as IPv6 addresses. Signed-off-by: Christian Langrock --- ip/link_vti6.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) unsigned int link = 0; @@ -167,6 +169,7 @@ get_failed: get_prefix(&addr, *argv, AF_INET6); memcpy(&daddr, addr.data, addr.bytelen); + use_daddr = true; } } else if (!matches(*argv, "local")) { NEXT_ARG(); @@ -178,6 +181,7 @@ get_failed: get_prefix(&addr, *argv, AF_INET6); memcpy(&saddr, addr.data, addr.bytelen); + use_saddr = true; } } else if (!matches(*argv, "dev")) { NEXT_ARG(); @@ -195,8 +199,10 @@ get_failed: addattr32(n, 1024, IFLA_VTI_IKEY, ikey); addattr32(n, 1024, IFLA_VTI_OKEY, okey); - addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, sizeof(saddr)); - addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, sizeof(daddr)); + if (use_saddr) + addattr_l(n, 1024, IFLA_VTI_LOCAL, &saddr, sizeof(saddr)); + if (use_daddr) + addattr_l(n, 1024, IFLA_VTI_REMOTE, &daddr, sizeof(daddr)); addattr32(n, 1024, IFLA_VTI_FWMARK, fwmark); if (link) addattr32(n, 1024, IFLA_VTI_LINK, link); diff --git a/ip/link_vti6.c b/ip/link_vti6.c index be4e33c..220b7df 100644 --- a/ip/link_vti6.c +++ b/ip/link_vti6.c @@ -60,7 +60,9 @@ static int vti6_parse_opt(struct link_util *lu, int argc, char **argv, struct rtattr *linkinfo[IFLA_INFO_MAX+1]; struct rtattr *vtiinfo[IFLA_VTI_MAX + 1]; struct in6_addr saddr; + bool use_saddr = false; struct in6_addr daddr; + bool use_daddr = false; unsigned int ikey = 0; unsigned int okey = 0;