($INBOX_DIR/description missing)
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski at intel.com>
To: ell at lists.01.org
Subject: [PATCH 17/17] icmp6: Ignore bad prefixes per RFC4862
Date: Sat, 14 May 2022 00:47:13 +0200	[thread overview]
Message-ID: <20220513224713.1447773-17-andrew.zaborowski@intel.com> (raw)
In-Reply-To: 20220513224713.1447773-1-andrew.zaborowski@intel.com

[-- Attachment #1: Type: text/plain, Size: 2130 bytes --]

"Silently ignore" Prefix Information options with a preferred time
longer than valid time and those matching the link-local prefix as
mandated by RFC4862 Section 5.5.3.  These prefixes are also invalid
according to RFC4861.
---
 ell/icmp6.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/ell/icmp6.c b/ell/icmp6.c
index ab2fe9c..96ba1ec 100644
--- a/ell/icmp6.c
+++ b/ell/icmp6.c
@@ -45,6 +45,7 @@
 #include "time-private.h"
 #include "queue.h"
 #include "net.h"
+#include "net-private.h"
 #include "netlink.h"
 #include "rtnl.h"
 #include "missing.h"
@@ -817,7 +818,27 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 			i->onlink = true;
 			i->valid_lifetime = l_get_be32(opts + 4);
 			i->preferred_lifetime = l_get_be32(opts + 8);
-			memcpy(i->address, opts + 16, 16);
+
+			/*
+			 * Only the initial Prefix Length bits of the prefix
+			 * are valid.  The remaining bits "MUST" be ignored
+			 * by the receiver.
+			 */
+			memcpy(i->address, net_prefix_from_ipv6(opts + 16,
+							i->prefix_len), 16);
+
+			/*
+			 * For SLAAC (RFC4862) we need to "silently ignore"
+			 * routes with a preferred lifetime longer than valid
+			 * lifetime, and those with the link-local prefix.
+			 * Since it makes sense, do it regardless of SLAAC.
+			 */
+			if (i->preferred_lifetime > i->valid_lifetime)
+				break;
+
+			if (i->prefix_len >= 10 &&
+					IN6_IS_ADDR_LINKLOCAL(i->address))
+				break;
 
 			n_routes += 1;
 			break;
@@ -869,7 +890,14 @@ struct l_icmp6_router *_icmp6_router_parse(const struct nd_router_advert *ra,
 			i->onlink = false;
 			i->preference = preference;
 			i->valid_lifetime = l_get_be32(opts + 4);
-			memcpy(i->address, opts + 8, (i->prefix_len + 7) / 8);
+
+			/*
+			 * Only the initial Prefix Length bits of the prefix
+			 * are valid.  The remaining bits "MUST" be ignored
+			 * by the receiver.
+			 */
+			memcpy(i->address, net_prefix_from_ipv6(opts + 8,
+							i->prefix_len), 16);
 
 			n_routes += 1;
 			break;
-- 
2.32.0

             reply	other threads:[~2022-05-13 22:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-13 22:47 Andrew Zaborowski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-05-18 19:02 [PATCH 17/17] icmp6: Ignore bad prefixes per RFC4862 Denis Kenzior
2022-05-13 14:55 Andrew Zaborowski

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=20220513224713.1447773-17-andrew.zaborowski@intel.com \
    --to=ell@lists.linux.dev \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).