Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753842AbcKOP0t (ORCPT ); Tue, 15 Nov 2016 10:26:49 -0500 Received: from mail-pf0-f169.google.com ([209.85.192.169]:35736 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755575AbcKOP0o (ORCPT ); Tue, 15 Nov 2016 10:26:44 -0500 Subject: Re: [PATCH v3] ip6_output: ensure flow saddr actually belongs to device To: Hannes Frederic Sowa , "Jason A. Donenfeld" References: <27cccef1-06d9-74b3-5b8a-912850119a76@cumulusnetworks.com> <20161113232813.28926-1-Jason@zx2c4.com> <1479141867.3723362.787321689.4A3DCFD6@webmail.messagingengine.com> <7d8c0210-9132-c755-9053-6ec19409e343@stressinduktion.org> <7779da88-08dc-0adb-42dd-8e00502693df@stressinduktion.org> <0214eaf8-70c6-5a37-cddd-faa1c4268871@cumulusnetworks.com> <1479148385.3747043.787432273.5FCC2F4F@webmail.messagingengine.com> <7543fa0f-a053-8387-1862-d78ffadba688@stressinduktion.org> Cc: Netdev , WireGuard mailing list , LKML , YOSHIFUJI Hideaki From: David Ahern Message-ID: <4285324b-c396-dfc1-caad-c961a6564e94@cumulusnetworks.com> Date: Tue, 15 Nov 2016 08:26:42 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <7543fa0f-a053-8387-1862-d78ffadba688@stressinduktion.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1365 Lines: 31 On 11/15/16 7:45 AM, Hannes Frederic Sowa wrote: >> @@ -1012,6 +1013,16 @@ static int ip6_dst_lookup_tail(struct net *net, >> const struct sock *sk, >> } >> #endif >> >> + addr_type = ipv6_addr_type(&fl6->saddr); >> + if (addr_type == IPv6_ADDR_ANY) >> + return 0; >> + >> + err = -EINVAL; >> + bind_to_dev = __ipv6_addr_src_scope(addr_type) <= >> IPV6_ADDR_SCOPE_LINKLOCAL; >> + if (!ipv6_chk_addr(net, &fl6->saddr, bind_to_dev ? >> (*dst)->dev : NULL, 0) && >> + !ipv6_chk_acast_addr_src(net, (*dst)->dev, &fl6->saddr)) >> + goto out_err_release; >> + >> return 0; >> >> out_err_release: >> > > We should not use (*dst)->dev, as this is the resulting device after the > lookup and not necessarily corresponds to the device the user asked for. To be consistent with IPv4 the saddr check is done before the lookup and dst and flow oif should not be used. Handling LL addresses are trickier and perhaps this is not the right place to enforce that check since it requires a specific device which is only really known after lookup. Why not add the if saddr is LL verification as part of the route selection? e.g, add something like rt6_device_match to ip6_pol_route (the device match call is only used for ip6_pol_route_lookup and not ip6_pol_route - why is that?).