From patchwork Mon Jun 24 13:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13709450 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lf1-f100.google.com (mail-lf1-f100.google.com [209.85.167.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 918C613D51D for ; Mon, 24 Jun 2024 13:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234546; cv=none; b=sUAcqQNt/PztnKB8pQnR72T9uC1mbBUxrsDhjtDc3KSBy47VzIo2mT33tRVUBrw25U1MwcVNK92Im+TMddaJyp0Dwf+EO5OQYm3pgbEa7kErEXw1OnkK5Dz1vLJk8ABD/KuAYh8YBga7HkuEtKDQjaWUxJgAhIBhdQmypAnDhpk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234546; c=relaxed/simple; bh=F18MNQqMgi2s1pXAA8VazUOW/a2/fCiXeYMprACDpHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ur2EEa1kC9orMNs9XsohodroW9WGo87AhQ6gyxty3IGT3RjU5p5WRBzSmtFR5I9cIbnUVdvtCqr1F6qXZvGpL50mp9sq6WXnkOtYTsxOputCT8HYfdxKTjbDFPz4fLq+jVHmXM5GaKq8k9C7H3AeW+8VmruKRcRIpWn6bafh8go= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com; spf=pass smtp.mailfrom=6wind.com; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b=VQpIOSZ5; arc=none smtp.client-ip=209.85.167.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b="VQpIOSZ5" Received: by mail-lf1-f100.google.com with SMTP id 2adb3069b0e04-52cd9f9505cso3166589e87.0 for ; Mon, 24 Jun 2024 06:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1719234543; x=1719839343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cua0A6GEdu0iOk0GUptHeWMm27awSaljV0LV/Qv+59A=; b=VQpIOSZ5DnV8YzmSsUKwgl6J/svEeSgdfs33Vnl1dKAGSCpcDhvo0bbZcLpBt7ScEm JgFpfEnJeDYRZKliXsOhYcloninrfxjy8D2KMGmI8ruu+E6O1LhJvDaeB7cNtllcxxD4 iQz13uY0TKPTYwxAPsK3ES1oKdli8TS9szqVMHzH3JO4jS6LG1TivJpcmjC3vOGJ8uXC qY5YoYb0JNPV/ZxH6HPCMCezC3mkPu5PHXyAb/pGel6/bIyObKgATVx5WTBRkCNSmoDx H8+JqPvMVBNoPvV6UC51QVvZ5XuiP5tBoGgaGN3zLrhVlu6cPinxy+EF5oORSHeyekmc ZkgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234543; x=1719839343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cua0A6GEdu0iOk0GUptHeWMm27awSaljV0LV/Qv+59A=; b=XDZHzw8zpzJfYRnrqey5PQWBgbx3wwTOGGrc5G8aMch3pXRn4f2ROrCIXAjxzuP7h8 JxG8MZxCEhthSToSLxFoF7TywAzHMruzYQyTL3HbHZnIkhfWjpVwc8ZqtdUFcRVTS8eX xwSx480V9vZIg2O1+TJCNnC0TLM+158/XbnxPiW6iHOlvr9ec80aA9at/MJ2qi0JRbyw WmlrKoNTvUCzgwy1GyaEf66KvmcPZV3LCDSbN8n/1RSduRA1+KsQqsixQMD27xUSZYZU //Xmh3dk0cXBvmNk/IaPi5AEhrzP6S/mkJLF0OJxEtyko/uo6pqPjV+Aepz/lhFRyvkC FwEw== X-Forwarded-Encrypted: i=1; AJvYcCXPHzxMFdArTjaK61L+B1948JAfMu8IK1YSJH7KNvQqDBzP8G1xC29JjqHVd25pDE3QD/e0jxV9SjamK0C1e1jktnvRbFFS X-Gm-Message-State: AOJu0YyN4cFJKPzMgw4WPNJ682EHkvwiKuNgY9Vv4IwgbuxmrnCoUev2 s3q5kNZM2RWgOW7QyVl2GLjv/vZhBb3ZbhdXTNkshdTNw20QbP37luzzqWIvMWXExXCFpD2kN6W RTuVbbz/Iah4kNRNz2A//2c1mK2HagjpD X-Google-Smtp-Source: AGHT+IEBpaCODeI242sIP+AcMfTXd1Z+51gSpsbjgQUQQht0K2WifHxuQsjBq8JFYi/VigFtbtGnLlvQoPKX X-Received: by 2002:ac2:5f63:0:b0:52c:a002:1afc with SMTP id 2adb3069b0e04-52cdf7f66f2mr3244175e87.34.1719234542615; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id 5b1f17b1804b1-424817fcc5esm3530725e9.41.2024.06.24.06.09.02; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) X-Relaying-Domain: 6wind.com Received: from bretzel (bretzel.dev.6wind.com [10.17.1.57]) by smtpservice.6wind.com (Postfix) with ESMTPS id 495B86036F; Mon, 24 Jun 2024 15:09:02 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sLjRO-004067-03; Mon, 24 Jun 2024 15:09:02 +0200 From: Nicolas Dichtel To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: David Ahern , netdev@vger.kernel.org, Nicolas Dichtel , stable@vger.kernel.org Subject: [PATCH net 1/4] ipv4: fix source address selection with route leak Date: Mon, 24 Jun 2024 15:07:53 +0200 Message-ID: <20240624130859.953608-2-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240624130859.953608-1-nicolas.dichtel@6wind.com> References: <20240624130859.953608-1-nicolas.dichtel@6wind.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org By default, an address assigned to the output interface is selected when the source address is not specified. This is problematic when a route, configured in a vrf, uses an interface from another vrf (aka route leak). The original vrf does not own the selected source address. Let's add a check against the output interface and call the appropriate function to select the source address. CC: stable@vger.kernel.org Fixes: 8cbb512c923d ("net: Add source address lookup op for VRF") Signed-off-by: Nicolas Dichtel --- net/ipv4/fib_semantics.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index f669da98d11d..459082f4936d 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -2270,6 +2270,13 @@ void fib_select_path(struct net *net, struct fib_result *res, fib_select_default(fl4, res); check_saddr: - if (!fl4->saddr) - fl4->saddr = fib_result_prefsrc(net, res); + if (!fl4->saddr) { + struct net_device *l3mdev = dev_get_by_index_rcu(net, fl4->flowi4_l3mdev); + + if (!l3mdev || + l3mdev_master_dev_rcu(FIB_RES_DEV(*res)) == l3mdev) + fl4->saddr = fib_result_prefsrc(net, res); + else + fl4->saddr = inet_select_addr(l3mdev, 0, RT_SCOPE_LINK); + } } From patchwork Mon Jun 24 13:07:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13709451 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-lj1-f225.google.com (mail-lj1-f225.google.com [209.85.208.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90A7B13D62F for ; Mon, 24 Jun 2024 13:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.225 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234546; cv=none; b=ZviG/AaQRH7mYte2JfR8rfeuQlhcNvEMv+R93+skIgNLQJwdx+j+WOFx+IcBpWssZQa4UPrjuNhP1PMYDriWp9AjNiPFg/Mgm71X8dsOEWS6ie7I3zD+t1Iogpue2/f2CK9/oHaGhN7/0tbYXW6xPXBETI3EEFAu4isivJ5J2E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234546; c=relaxed/simple; bh=8oaIXIe0+bbffU+4+tyy8R/V/TlWyVTDw3J9fG4MGsU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fAIpFTcVS0YNpuog5ttTaBgeSfXfrqOk2AMAxONsUkNs+BLKQOFoPDcGEL2rzNspMuKoInGyzlJcJAWq+s8r6/F/UYN2FQuQUOKKJD0rChYugj+e14nPnKt1vy5LZYqQWZoR3oXY+2vfaohSKJzLdUlF0PL164eq0HeOwxgRj3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com; spf=pass smtp.mailfrom=6wind.com; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b=AQqvyf/W; arc=none smtp.client-ip=209.85.208.225 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b="AQqvyf/W" Received: by mail-lj1-f225.google.com with SMTP id 38308e7fff4ca-2ec1620a956so51598751fa.1 for ; Mon, 24 Jun 2024 06:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1719234543; x=1719839343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MeLUTTDqDBsmxH/CzCbI0wYe8vQnI0MozaiZWlhCOJE=; b=AQqvyf/WSThIg1dcIPAZ41xmnbVrJWe5IW83frtm4/8PJqpRB3ei1n6tUgiF4i27n6 2fHHfXTLbZ8z0uyIR0jtitNmICVZ2QiAxRfTosXkpKjGbgHWYsxm3QlZ5n68FPkm4LnC nE54t7LC6m/fYQxtbDCjVF+yxcrdrbMbebZmBw8i2QNo4yeQOg7AoAEHrLqsyLBXZLVK HFKeuZSqJOOHWcGZ6Mxmlj//ZvHpZilz6f8ox4CWZOUmOujo4NgRzPgZ1JZtTBOdEZ5m Q2/KWpqRFZC6gYHSZvHgr2jljWQ7D4ogoJVPxoj61/pcGeeS1+PYdFts9oicrBRY2Ok1 vIcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234543; x=1719839343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MeLUTTDqDBsmxH/CzCbI0wYe8vQnI0MozaiZWlhCOJE=; b=I0uQEXLVHxOcu9iQCGMzy6Qcs4I3blFyNOGtJq03PEN0Asxw7Mk92+Xq52oPACQW02 334lrer3rhyWfQUqE4cyhrj+HvWZHVR00jq5vFXMBtcG+vevjzWj3GkotJga/Rr32IFS Ogk7pa58La0LLS5488CqmZReLG6XEyFLUd3zEotXku9a9BWZbTW5p4QkAfzWF1dRJ6u4 cAObON1KfWm/VpKjwoq/OcAAAsE3uTUJsVc6InMEPjg/mBlD1MzjWTAsO+7pkB5puyVV jHwWsMfT5Fzr6hreEyX79SOlKqfV12fjIboXsjDsWANGoywfZwuPkX/bc02g8FFK5Pxy p4yA== X-Forwarded-Encrypted: i=1; AJvYcCU9etEe6hD6YlvWC8Q1Xsd2U5Dsq7mMC69wFVPvYP3Vj86oabqi0lprIr4Co00d3hNOQL4WGvPR+jk+MPxy8T76T+ExjvEa X-Gm-Message-State: AOJu0YxXy5AhKYzA5Ff2I/GHP9odBPBvQ630fl6jYXf4HNHvtR3GpcCf 8p9kKQ+uRGGAkih8Z+zchloGQ0ttygurAHTSehWOL23eOcz/LkRj6K4Z7TOLwuUcIBmFa0Lzoob IkzlT9ej6UQihyIOr+G9+g+8tqdQtO+G2 X-Google-Smtp-Source: AGHT+IELmlE6/jT14ZDxmp+y2Ey92cZln6BwHTGXEgEmu0GwEmf4G62NZJLnWwhtXIIPSyY/YKkKI9ZTVudr X-Received: by 2002:a05:651c:22f:b0:2ec:5128:1851 with SMTP id 38308e7fff4ca-2ec5b3197e3mr24276381fa.3.1719234542627; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id ffacd0b85a97d-366efb23ee2sm95047f8f.105.2024.06.24.06.09.02; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) X-Relaying-Domain: 6wind.com Received: from bretzel (bretzel.dev.6wind.com [10.17.1.57]) by smtpservice.6wind.com (Postfix) with ESMTPS id 5329D603A7; Mon, 24 Jun 2024 15:09:02 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sLjRO-00406A-0g; Mon, 24 Jun 2024 15:09:02 +0200 From: Nicolas Dichtel To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: David Ahern , netdev@vger.kernel.org, Nicolas Dichtel , stable@vger.kernel.org Subject: [PATCH net 2/4] ipv6: fix source address selection with route leak Date: Mon, 24 Jun 2024 15:07:54 +0200 Message-ID: <20240624130859.953608-3-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240624130859.953608-1-nicolas.dichtel@6wind.com> References: <20240624130859.953608-1-nicolas.dichtel@6wind.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org By default, an address assigned to the output interface is selected when the source address is not specified. This is problematic when a route, configured in a vrf, uses an interface from another vrf (aka route leak). The original vrf does not own the selected source address. Let's add a check against the output interface and call the appropriate function to select the source address. CC: stable@vger.kernel.org Fixes: 0d240e7811c4 ("net: vrf: Implement get_saddr for IPv6") Signed-off-by: Nicolas Dichtel --- include/net/ip6_route.h | 19 ++++++++++++------- net/ipv6/ip6_output.c | 1 + net/ipv6/route.c | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index a18ed24fed94..62755fab1b52 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -127,18 +127,23 @@ void rt6_age_exceptions(struct fib6_info *f6i, struct fib6_gc_args *gc_args, static inline int ip6_route_get_saddr(struct net *net, struct fib6_info *f6i, const struct in6_addr *daddr, - unsigned int prefs, + unsigned int prefs, int l3mdev_index, struct in6_addr *saddr) { + struct net_device *l3mdev; + struct net_device *dev; + bool same_vrf; int err = 0; - if (f6i && f6i->fib6_prefsrc.plen) { + rcu_read_lock(); + l3mdev = dev_get_by_index_rcu(net, l3mdev_index); + dev = f6i ? fib6_info_nh_dev(f6i) : NULL; + same_vrf = l3mdev && l3mdev_master_dev_rcu(dev) == l3mdev; + if (f6i && f6i->fib6_prefsrc.plen && same_vrf) *saddr = f6i->fib6_prefsrc.addr; - } else { - struct net_device *dev = f6i ? fib6_info_nh_dev(f6i) : NULL; - - err = ipv6_dev_get_saddr(net, dev, daddr, prefs, saddr); - } + else + err = ipv6_dev_get_saddr(net, same_vrf ? dev : l3mdev, daddr, prefs, saddr); + rcu_read_unlock(); return err; } diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 27d8725445e3..784424ac4147 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1124,6 +1124,7 @@ static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk, from = rt ? rcu_dereference(rt->from) : NULL; err = ip6_route_get_saddr(net, from, &fl6->daddr, sk ? READ_ONCE(inet6_sk(sk)->srcprefs) : 0, + fl6->flowi6_l3mdev, &fl6->saddr); rcu_read_unlock(); diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 8d72ca0b086d..c9a9506b714d 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -5689,7 +5689,7 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb, goto nla_put_failure; } else if (dest) { struct in6_addr saddr_buf; - if (ip6_route_get_saddr(net, rt, dest, 0, &saddr_buf) == 0 && + if (ip6_route_get_saddr(net, rt, dest, 0, 0, &saddr_buf) == 0 && nla_put_in6_addr(skb, RTA_PREFSRC, &saddr_buf)) goto nla_put_failure; } From patchwork Mon Jun 24 13:07:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13709453 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f97.google.com (mail-ej1-f97.google.com [209.85.218.97]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6039213D62B for ; Mon, 24 Jun 2024 13:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.97 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234547; cv=none; b=mZJTLKqKijaq+rMEjYfyZ+ZcR/iv/LSwlPIGtYsiIuqbrJ0V5oF5E9/Cy+zS4AKOl6ut6Xve2GiQzMeq18rPzcf4ioNVJQDVVKB9vrAWaB6ymXMAJ8MNFP5h7DIqwzU1YON7FbL1oDVU8cYT5PGsnJobabYnDKOYzNzxvnR3us0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234547; c=relaxed/simple; bh=YnwMFx7v27V6FYvekKLIctK4MfTa3mGutFv4M3UNWRA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XzkIMQD4FLe203+1v3wszzhe2+P0GphusrhiNkSQoWNwLTAgwG6MGf2K6JbtUrv00Hhe2tJgz96QntcNDgNPFu/bJoAbEnN6yo9FxEFK/MDnDFOPes2jMBaH16DO/rMPifFay/zbPKPjVA1bl4R00wSp5qvivXoc4dTjVUpicAA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com; spf=pass smtp.mailfrom=6wind.com; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b=Fu1ccmna; arc=none smtp.client-ip=209.85.218.97 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b="Fu1ccmna" Received: by mail-ej1-f97.google.com with SMTP id a640c23a62f3a-a7194ce90afso198427366b.2 for ; Mon, 24 Jun 2024 06:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1719234543; x=1719839343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LdqEoEJ0Pf4lgGIH6ji9Pz/3++dxBfiK/h/sDIFPHrE=; b=Fu1ccmnantlWGJLI4dH6m5m9HQa+KJbOmeQZcRKp6A3hC+VyTuYWqmTpL9tdrhwTGW tTmbQiIRdBTPOCaNw8DK2W/mijX9vRmQuX1qfitOgAYc5Yfjs3QdpDZlA+Wr+V6f8cOX AOcgWy7U3kUnnIFa9gpgn0Ah5YL2FFLrwgXq0J9vjXPpK5tiUdzCzMtVCxN+OPaK2z39 OaqX1AqBVdsQC4jCP330o1xw6YcY0KMSQCnPzTdqvNtijjPm/yGI35iM31mx6lNndlPQ 6Q64JVzW5Ooaz8RGSnNMQUv0mz73tUvB6t8wiE0anMlsrpSNWJYcVjVOJXzyKZ7+8RCZ 2Qaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234543; x=1719839343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LdqEoEJ0Pf4lgGIH6ji9Pz/3++dxBfiK/h/sDIFPHrE=; b=m+wdRodheA9H9NA9g9cwGVdYeRf/dZ+I1yLAxNGub6Rn2O4hBFirFYjQAunnHB5VSf cmrxhQIT/+zU8DFLVUoTb/O9i7gX3HA//Xy0LfpHKTmRUm4uJAXATqEYxL5jmmXNVFgY pc2n5Uw3D3A2Gio2aR+Oc/j5zw5UGKTF+03fD3rYxenyWmC0vT1cSAyneqqd2if9c6qa E5+2pm2HvLL58DC9MD+dxiRHooCQK2o7xxXy4bdY6RnTyLj2jP/EIxTnXyHnhi9aBvrL hfGm6u+VK0o7gBmPUhs3PDH+4ykT345jP9GzIvQmPr3HyFNGIX390rcL2skIX9GvFi2/ L9gg== X-Forwarded-Encrypted: i=1; AJvYcCV72po4039gROY1IDC7Jrqos4sFUOYaMAJ6xFrtWzTC+P/1vOaTfMdl8vuxFgN7SRt3NF4bkXCVq2LuxqLAUx0VAd8dkVN9 X-Gm-Message-State: AOJu0YxrzRW3TpnLWaNLTw7ps+bpIdiQ48mBrLSWZaYcc088IuYr5PXj fr8RRCE10H6fYqVcYGSwUECNuk96zHmoZRN4KxF0aC2IxwajteyflwkWON/b4ltaDuqkWdURu28 DpDo2xEvwXv8yf5S2QieFGWxHSGCJk2Om X-Google-Smtp-Source: AGHT+IHCk7wynrIl8qJrDVl6mUMvyc5T0uLPZ9fOJVKL4yEifbZ4Dcx4XDbVA+6QE1V+fboohRVwC3ANdYMU X-Received: by 2002:a17:906:4713:b0:a70:6f2c:b308 with SMTP id a640c23a62f3a-a715f94a9d8mr372023966b.29.1719234542660; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id a640c23a62f3a-a6fcf560fc5sm12243966b.229.2024.06.24.06.09.02; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) X-Relaying-Domain: 6wind.com Received: from bretzel (bretzel.dev.6wind.com [10.17.1.57]) by smtpservice.6wind.com (Postfix) with ESMTPS id 570A760490; Mon, 24 Jun 2024 15:09:02 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sLjRO-00406D-1I; Mon, 24 Jun 2024 15:09:02 +0200 From: Nicolas Dichtel To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: David Ahern , netdev@vger.kernel.org, Nicolas Dichtel , stable@vger.kernel.org Subject: [PATCH net 3/4] ipv6: take care of scope when choosing the src addr Date: Mon, 24 Jun 2024 15:07:55 +0200 Message-ID: <20240624130859.953608-4-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240624130859.953608-1-nicolas.dichtel@6wind.com> References: <20240624130859.953608-1-nicolas.dichtel@6wind.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When the source address is selected, the scope must be checked. For example, if a loopback address is assigned to the vrf device, it must not be chosen for packets sent outside. CC: stable@vger.kernel.org Fixes: afbac6010aec ("net: ipv6: Address selection needs to consider L3 domains") Signed-off-by: Nicolas Dichtel --- net/ipv6/addrconf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 5c424a0e7232..4f2c5cc31015 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1873,7 +1873,8 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev, master, &dst, scores, hiscore_idx); - if (scores[hiscore_idx].ifa) + if (scores[hiscore_idx].ifa && + scores[hiscore_idx].scopedist >= 0) goto out; } From patchwork Mon Jun 24 13:07:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dichtel X-Patchwork-Id: 13709454 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f98.google.com (mail-ej1-f98.google.com [209.85.218.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F03B1311A1 for ; Mon, 24 Jun 2024 13:09:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.98 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234547; cv=none; b=hFwRv6DdBXMfwxPoph4y5OB6mLk5etKob4dBtAO3RlOESQtptN7WYQPquZawH7ljtOuNyvsDblHMo3vAw/z+btUqTm2KhECWRGzDNfC6UFGicFLaDo++s4qUUhfN4zZ0dze2fiOJJu5MpmkffDehpwTDbd5fS/DikH6h3Tsvpu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719234547; c=relaxed/simple; bh=ROy4rBahQuH5xS/NgtUr6jAzTu27fBBfNGjSZa3LzcM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qqq8nUyKjHfGkGGo2dfX1tL6MGYSbZB5Wq112BjE1/Q9OOhzjf2MRdaMzvjModENC0hFOG2hIuoFrKs02+QGXD/tjn5dZIqyGr+Y+3SHmGxEKSLGNBw0ztx3IcroL3bNiFJojelw9EuHBEFwfyrFBTP66Mmg//Pky6NnfyIWFoI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com; spf=pass smtp.mailfrom=6wind.com; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b=QM4UQ6AX; arc=none smtp.client-ip=209.85.218.98 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.b="QM4UQ6AX" Received: by mail-ej1-f98.google.com with SMTP id a640c23a62f3a-a689ad8d1f6so540824266b.2 for ; Mon, 24 Jun 2024 06:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind.com; s=google; t=1719234543; x=1719839343; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UcwVCNb8foBMgIyCQSZ7Wl8+7ZspHNbrlVaSM6zBPxI=; b=QM4UQ6AX4iCMH/MjqD7HxXZogOle4E6JgDwRmxKXJTFrydrIb3dFsPnkgFjuiiiER+ G1MP19omfhgqyhvFKQbzKrd8O2XQpOiBflk4TpMq/+4hW3BiyuiQr4eKxEOwyqsxclKO LivJLK4qSocruGtj2jhMWy2WsfctXAyxnpZR8HXObLOu0qWBtX8byTXxeKyX9QCRr8ac l5+NFbcrZC7g5elcaTVefqanezg1eUFcLDmwq83igjrU+OLFfwdOvfudCpMwvhElEysU 9BCm+O/T2jKtngw/cWxUda4AVGkCciks22yNMfthzTln4sY5t1cqHaSJrZQZZVltTw5Y sI2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719234543; x=1719839343; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UcwVCNb8foBMgIyCQSZ7Wl8+7ZspHNbrlVaSM6zBPxI=; b=J5uOUsbMarU9GSQ4X3HpPXKPQaR8eO7IowbPrVVY02NvSRMKiH3vjpeKDOdUSBW1iX P2nb+OiApa2Uk7etHzSGQAHUgsHLInbOLdWGr7U0pqhf9/kVI7D/MUhM5vTHWYGFUUa8 /8Z/WQhozHgr/db626pRoSSxfYTIV5qT8hx6dxvetzMZcG3o2OarL9yDSayczGynUk9b jiXthUgIPF9i3m9UpaeYYBa6qJ3Z5yGFzt1ixCvzpkmOXTrYPGymD87hqS+cMhzThecT yPx58AfvwEFJre7Y9ZHN8P+GQqp96uOtuyDVdb8SWFE9gmXeCDG92/h+JWcI3Bo9o6Qb 3CgA== X-Forwarded-Encrypted: i=1; AJvYcCW5BzOuypg1WccW29do1Oo9bGaPfR46aDbBNczr2SLciQbkxms887b8TVPbn/VJ7Y6ZLdRWBEoL/id9wcP5bNByu761Z1Lz X-Gm-Message-State: AOJu0Yy2uIduMG7zIexkAeFNuF3cVpyI5m9syWked4Tf74VxXaIg9cjw 55vRHbD1iuTiUJzistxDK2nmA/toC4CRlX0Vbibgmp7PBhSkn4HSdgK7sczRLClOLABQUzvtLYS Fh6KrKz8h/87S68SwNKuifBSZBuLDOf4U X-Google-Smtp-Source: AGHT+IFpQwRzyR34qMJRZmkVTN7mdUYx2kE9+rJvMvL8VAQneQX3EF3OdDGnaXjQyvJ8hCCPeYZpRQ2b4BOs X-Received: by 2002:a17:907:c70c:b0:a6f:4f2c:1939 with SMTP id a640c23a62f3a-a7245c84ecfmr296000466b.1.1719234542672; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) Received: from smtpservice.6wind.com ([185.13.181.2]) by smtp-relay.gmail.com with ESMTP id a640c23a62f3a-a6fcf56031fsm12005066b.188.2024.06.24.06.09.02; Mon, 24 Jun 2024 06:09:02 -0700 (PDT) X-Relaying-Domain: 6wind.com Received: from bretzel (bretzel.dev.6wind.com [10.17.1.57]) by smtpservice.6wind.com (Postfix) with ESMTPS id 5AE0A60533; Mon, 24 Jun 2024 15:09:02 +0200 (CEST) Received: from dichtel by bretzel with local (Exim 4.94.2) (envelope-from ) id 1sLjRO-00406G-1t; Mon, 24 Jun 2024 15:09:02 +0200 From: Nicolas Dichtel To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: David Ahern , netdev@vger.kernel.org, Nicolas Dichtel Subject: [PATCH net 4/4] selftests: vrf_route_leaking: add local ping test Date: Mon, 24 Jun 2024 15:07:56 +0200 Message-ID: <20240624130859.953608-5-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240624130859.953608-1-nicolas.dichtel@6wind.com> References: <20240624130859.953608-1-nicolas.dichtel@6wind.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org The goal is to check that the source address selected by the kernel is routable when a leaking route is used. Signed-off-by: Nicolas Dichtel --- .../selftests/net/vrf_route_leaking.sh | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/vrf_route_leaking.sh b/tools/testing/selftests/net/vrf_route_leaking.sh index 2da32f4c479b..6c59e0bbbde3 100755 --- a/tools/testing/selftests/net/vrf_route_leaking.sh +++ b/tools/testing/selftests/net/vrf_route_leaking.sh @@ -533,6 +533,38 @@ ipv6_ping_frag_asym() ipv6_ping_frag asym } +ipv4_ping_local() +{ + local ttype="$1" + + [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE" + + log_section "IPv4 ($ttype route): VRF ICMP local error route lookup ping" + + setup_"$ttype" + + check_connectivity || return + + run_cmd ip netns exec $r1 ip vrf exec blue ping -c1 -w1 ${H2_N2_IP} + log_test $? 0 "VRF ICMP local IPv4" +} + +ipv6_ping_local() +{ + local ttype="$1" + + [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE" + + log_section "IPv6 ($ttype route): VRF ICMP local error route lookup ping" + + setup_"$ttype" + + check_connectivity6 || return + + run_cmd ip netns exec $r1 ip vrf exec blue ${ping6} -c1 -w1 ${H2_N2_IP6} + log_test $? 0 "VRF ICMP local IPv6" +} + ################################################################################ # usage @@ -555,8 +587,8 @@ EOF # Some systems don't have a ping6 binary anymore command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping) -TESTS_IPV4="ipv4_ping_ttl ipv4_traceroute ipv4_ping_frag ipv4_ping_ttl_asym ipv4_traceroute_asym" -TESTS_IPV6="ipv6_ping_ttl ipv6_traceroute ipv6_ping_ttl_asym ipv6_traceroute_asym" +TESTS_IPV4="ipv4_ping_ttl ipv4_traceroute ipv4_ping_frag ipv4_ping_local ipv4_ping_ttl_asym ipv4_traceroute_asym" +TESTS_IPV6="ipv6_ping_ttl ipv6_traceroute ipv6_ping_local ipv6_ping_ttl_asym ipv6_traceroute_asym" ret=0 nsuccess=0 @@ -594,12 +626,14 @@ do ipv4_traceroute|traceroute) ipv4_traceroute;;& ipv4_traceroute_asym|traceroute) ipv4_traceroute_asym;;& ipv4_ping_frag|ping) ipv4_ping_frag;;& + ipv4_ping_local|ping) ipv4_ping_local;;& ipv6_ping_ttl|ping) ipv6_ping_ttl;;& ipv6_ping_ttl_asym|ping) ipv6_ping_ttl_asym;;& ipv6_traceroute|traceroute) ipv6_traceroute;;& ipv6_traceroute_asym|traceroute) ipv6_traceroute_asym;;& ipv6_ping_frag|ping) ipv6_ping_frag;;& + ipv6_ping_local|ping) ipv6_ping_local;;& # setup namespaces and config, but do not run any tests setup_sym|setup) setup_sym; exit 0;;