ipv6: fix ndisc_is_useropt() handling for PIO

[ Upstream commit a46c68debf3be3a477a69ccbf0a1d050df841676 ]

The current logic only works if the PIO is between two
other ND user options.  This fixes it so that the PIO
can also be either before or after other ND user options
(for example the first or last option in the RA).

side note: there's actually Android tests verifying
a portion of the old broken behaviour, so:
  3196704
fixes those up.

Cc: Jen Linkova <furry@google.com>
Cc: Lorenzo Colitti <lorenzo@google.com>
Cc: Patrick Rohr <prohr@google.com>
Cc: David Ahern <dsahern@kernel.org>
Cc: YOSHIFUJI Hideaki / 吉藤英明 <yoshfuji@linux-ipv6.org>
Cc: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Fixes: 048c796beb ("ipv6: adjust ndisc_is_useropt() to also return true for PIO")
Link: https://patch.msgid.link/20240730001748.147636-1-maze@google.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Maciej Żenczykowski 2024-07-29 17:17:48 -07:00 committed by Greg Kroah-Hartman
parent 5635301ed5
commit 93e2beae84

View file

@ -227,6 +227,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
return NULL; return NULL;
memset(ndopts, 0, sizeof(*ndopts)); memset(ndopts, 0, sizeof(*ndopts));
while (opt_len) { while (opt_len) {
bool unknown = false;
int l; int l;
if (opt_len < sizeof(struct nd_opt_hdr)) if (opt_len < sizeof(struct nd_opt_hdr))
return NULL; return NULL;
@ -262,22 +263,23 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
break; break;
#endif #endif
default: default:
if (ndisc_is_useropt(dev, nd_opt)) { unknown = true;
ndopts->nd_useropts_end = nd_opt; }
if (!ndopts->nd_useropts) if (ndisc_is_useropt(dev, nd_opt)) {
ndopts->nd_useropts = nd_opt; ndopts->nd_useropts_end = nd_opt;
} else { if (!ndopts->nd_useropts)
/* ndopts->nd_useropts = nd_opt;
* Unknown options must be silently ignored, } else if (unknown) {
* to accommodate future extension to the /*
* protocol. * Unknown options must be silently ignored,
*/ * to accommodate future extension to the
ND_PRINTK(2, notice, * protocol.
"%s: ignored unsupported option; type=%d, len=%d\n", */
__func__, ND_PRINTK(2, notice,
nd_opt->nd_opt_type, "%s: ignored unsupported option; type=%d, len=%d\n",
nd_opt->nd_opt_len); __func__,
} nd_opt->nd_opt_type,
nd_opt->nd_opt_len);
} }
next_opt: next_opt:
opt_len -= l; opt_len -= l;