From patchwork Tue Nov 15 09:49:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 694927 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tJ2gz1vPgz9t2C for ; Tue, 15 Nov 2016 20:50:39 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id E20F6B4A; Tue, 15 Nov 2016 09:50:06 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 5ABFEB3E for ; Tue, 15 Nov 2016 09:50:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id DE18028D for ; Tue, 15 Nov 2016 09:50:04 +0000 (UTC) Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7103EC04D2F3 for ; Tue, 15 Nov 2016 09:50:04 +0000 (UTC) Received: from indiana.gru.redhat.com (ovpn-116-76.phx2.redhat.com [10.3.116.76]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAF9o0Un014920 for ; Tue, 15 Nov 2016 04:50:03 -0500 From: Thadeu Lima de Souza Cascardo To: dev@openvswitch.org Date: Tue, 15 Nov 2016 07:49:45 -0200 Message-Id: <1479203387-17549-2-git-send-email-cascardo@redhat.com> In-Reply-To: <1479203387-17549-1-git-send-email-cascardo@redhat.com> References: <1479203387-17549-1-git-send-email-cascardo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 15 Nov 2016 09:50:04 +0000 (UTC) X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/3] netdev: fix netmask in netdev_get_addrs X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When iterating on getifaddrs result, ifa_netmask is dereferenced, but it's already a pointer to struct sockaddr. This would result in wrong masks being used when comparing addresses while calculating the source address given a destination address at the routing code. For example, the mask ::ffff:116.85.0.0 would be used, causing 172.16.100.0/24 to match 172.16.101.1, though they should not match. This will not happen when using a dummy netdev, as netdev_get_addrs is not used by it. Signed-off-by: Thadeu Lima de Souza Cascardo --- lib/netdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/netdev.c b/lib/netdev.c index 6c4c657..ad90ef6 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -1913,7 +1913,7 @@ netdev_get_addrs(const char dev[], struct in6_addr **paddr, sin = ALIGNED_CAST(const struct sockaddr_in *, ifa->ifa_addr); in6_addr_set_mapped_ipv4(&addr_array[i], sin->sin_addr.s_addr); - sin = (struct sockaddr_in *) &ifa->ifa_netmask; + sin = (struct sockaddr_in *) ifa->ifa_netmask; in6_addr_set_mapped_ipv4(&mask_array[i], sin->sin_addr.s_addr); i++; } else if (family == AF_INET6) { @@ -1921,7 +1921,7 @@ netdev_get_addrs(const char dev[], struct in6_addr **paddr, sin6 = ALIGNED_CAST(const struct sockaddr_in6 *, ifa->ifa_addr); memcpy(&addr_array[i], &sin6->sin6_addr, sizeof *addr_array); - sin6 = (struct sockaddr_in6 *) &ifa->ifa_netmask; + sin6 = (struct sockaddr_in6 *) ifa->ifa_netmask; memcpy(&mask_array[i], &sin6->sin6_addr, sizeof *mask_array); i++; }