Netdev List
 help / color / mirror / Atom feed
From: Justin Iurman <justin.iurman@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, andrea.mayer@uniroma2.it,
	justin.iurman@gmail.com
Subject: [PATCH net 2/2] seg6: drop the packet if no outer source address is available
Date: Sun, 15 Nov 2026 01:00:47 +0100	[thread overview]
Message-ID: <20261115000047.14669-3-justin.iurman@gmail.com> (raw)
In-Reply-To: <20261115000047.14669-1-justin.iurman@gmail.com>

When no tunnel source is configured, set_tun_src() ignores the return
value of ipv6_dev_get_saddr(). On failure, the source address of the
freshly pushed outer header is never written, so the packet is sent
with whatever stale bytes were in the skb headroom.

Return the error from set_tun_src() and drop the packet; all callers
of the encap functions already handle their errors.

Fixes: 6c8702c60b88 ("ipv6: sr: add support for SRH encapsulation and injection with lwtunnels")
Signed-off-by: Justin Iurman <justin.iurman@gmail.com>
---
 net/ipv6/seg6_iptunnel.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/net/ipv6/seg6_iptunnel.c b/net/ipv6/seg6_iptunnel.c
index 3bc47c5614ff..395614fdb83f 100644
--- a/net/ipv6/seg6_iptunnel.c
+++ b/net/ipv6/seg6_iptunnel.c
@@ -107,12 +107,13 @@ static int nla_put_srh(struct sk_buff *skb, int attrtype,
 	return 0;
 }
 
-static void set_tun_src(struct net *net, struct net_device *dev,
-			struct in6_addr *daddr, struct in6_addr *saddr,
-			struct in6_addr *route_tunsrc)
+static int set_tun_src(struct net *net, struct net_device *dev,
+		       struct in6_addr *daddr, struct in6_addr *saddr,
+		       struct in6_addr *route_tunsrc)
 {
 	struct seg6_pernet_data *sdata = seg6_pernet(net);
 	struct in6_addr *tun_src;
+	int err = 0;
 
 	/* Priority order to select tunnel source address:
 	 *  1. per route source address (if configured)
@@ -128,12 +129,14 @@ static void set_tun_src(struct net *net, struct net_device *dev,
 		if (!ipv6_addr_any(tun_src)) {
 			memcpy(saddr, tun_src, sizeof(struct in6_addr));
 		} else {
-			ipv6_dev_get_saddr(net, dev, daddr,
-					   IPV6_PREFER_SRC_PUBLIC, saddr);
+			err = ipv6_dev_get_saddr(net, dev, daddr,
+						 IPV6_PREFER_SRC_PUBLIC, saddr);
 		}
 
 		rcu_read_unlock();
 	}
+
+	return err;
 }
 
 /* Compute flowlabel for outer IPv6 header */
@@ -213,7 +216,9 @@ static int __seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh,
 	isrh->nexthdr = proto;
 
 	hdr->daddr = isrh->segments[isrh->first_segment];
-	set_tun_src(net, dev, &hdr->daddr, &hdr->saddr, route_tunsrc);
+	err = set_tun_src(net, dev, &hdr->daddr, &hdr->saddr, route_tunsrc);
+	if (unlikely(err))
+		return err;
 
 #ifdef CONFIG_IPV6_SEG6_HMAC
 	if (sr_has_hmac(isrh)) {
@@ -304,7 +309,10 @@ static int seg6_do_srh_encap_red(struct sk_buff *skb,
 	if (skip_srh) {
 		hdr->nexthdr = proto;
 
-		set_tun_src(net, dev, &hdr->daddr, &hdr->saddr, route_tunsrc);
+		err = set_tun_src(net, dev, &hdr->daddr, &hdr->saddr,
+				  route_tunsrc);
+		if (unlikely(err))
+			return err;
 		goto out;
 	}
 
@@ -340,7 +348,9 @@ static int seg6_do_srh_encap_red(struct sk_buff *skb,
 
 srcaddr:
 	isrh->nexthdr = proto;
-	set_tun_src(net, dev, &hdr->daddr, &hdr->saddr, route_tunsrc);
+	err = set_tun_src(net, dev, &hdr->daddr, &hdr->saddr, route_tunsrc);
+	if (unlikely(err))
+		return err;
 
 #ifdef CONFIG_IPV6_SEG6_HMAC
 	if (unlikely(!skip_srh && sr_has_hmac(isrh))) {
-- 
2.34.1


  parent reply	other threads:[~2026-11-15  0:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-15  0:00 [PATCH net 0/2] ipv6: drop encapsulated packets when no source address is available Justin Iurman
2026-11-15  0:00 ` [PATCH net 1/2] ioam6: drop the packet if no outer " Justin Iurman
2026-11-15  0:00 ` Justin Iurman [this message]
2026-11-15 20:08 ` [PATCH net 0/2] ipv6: drop encapsulated packets when no " netdev-bot+sinfo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261115000047.14669-3-justin.iurman@gmail.com \
    --to=justin.iurman@gmail.com \
    --cc=andrea.mayer@uniroma2.it \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox