diff mbox series

[net,v2] ipv6: fix ndisc_is_useropt() handling for PIO

Message ID 20240730001748.147636-1-maze@google.com (mailing list archive)
State Accepted
Commit a46c68debf3be3a477a69ccbf0a1d050df841676
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] ipv6: fix ndisc_is_useropt() handling for PIO | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 42 this patch: 42
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 43 this patch: 43
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 43 this patch: 43
netdev/checkpatch warning WARNING: networking block comments don't use an empty /* line, use /* Comment...
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-07-31--12-00 (tests: 707)

Commit Message

Maciej Żenczykowski July 30, 2024, 12:17 a.m. UTC
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:
  https://android-review.googlesource.com/c/kernel/tests/+/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: 048c796beb6e ("ipv6: adjust ndisc_is_useropt() to also return true for PIO")
---
 net/ipv6/ndisc.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

Comments

Maciej Żenczykowski July 30, 2024, 12:27 a.m. UTC | #1
On Mon, Jul 29, 2024 at 5:17 PM Maciej Żenczykowski <maze@google.com> wrote:
>
> 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:
>   https://android-review.googlesource.com/c/kernel/tests/+/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: 048c796beb6e ("ipv6: adjust ndisc_is_useropt() to also return true for PIO")
> ---
>  net/ipv6/ndisc.c | 34 ++++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
> index 70a0b2ad6bd7..b8eec1b6cc2c 100644
> --- a/net/ipv6/ndisc.c
> +++ b/net/ipv6/ndisc.c
> @@ -227,6 +227,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
>                 return NULL;
>         memset(ndopts, 0, sizeof(*ndopts));
>         while (opt_len) {
> +               bool unknown = false;
>                 int l;
>                 if (opt_len < sizeof(struct nd_opt_hdr))
>                         return NULL;
> @@ -262,22 +263,23 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
>                         break;
>  #endif
>                 default:
> -                       if (ndisc_is_useropt(dev, nd_opt)) {
> -                               ndopts->nd_useropts_end = nd_opt;
> -                               if (!ndopts->nd_useropts)
> -                                       ndopts->nd_useropts = nd_opt;
> -                       } else {
> -                               /*
> -                                * Unknown options must be silently ignored,
> -                                * to accommodate future extension to the
> -                                * protocol.
> -                                */
> -                               ND_PRINTK(2, notice,
> -                                         "%s: ignored unsupported option; type=%d, len=%d\n",
> -                                         __func__,
> -                                         nd_opt->nd_opt_type,
> -                                         nd_opt->nd_opt_len);
> -                       }
> +                       unknown = true;
> +               }
> +               if (ndisc_is_useropt(dev, nd_opt)) {
> +                       ndopts->nd_useropts_end = nd_opt;
> +                       if (!ndopts->nd_useropts)
> +                               ndopts->nd_useropts = nd_opt;
> +               } else if (unknown) {
> +                       /*
> +                        * Unknown options must be silently ignored,
> +                        * to accommodate future extension to the
> +                        * protocol.
> +                        */
> +                       ND_PRINTK(2, notice,
> +                                 "%s: ignored unsupported option; type=%d, len=%d\n",
> +                                 __func__,
> +                                 nd_opt->nd_opt_type,
> +                                 nd_opt->nd_opt_len);
>                 }
>  next_opt:
>                 opt_len -= l;
> --
> 2.46.0.rc1.232.g9752f9e123-goog
>

The diff on this second version is significantly bigger (although it's
just unindenting a block), but perhaps this is better as it is much
harder to screw things up.
Paolo Abeni Aug. 1, 2024, 9:43 a.m. UTC | #2
On 7/30/24 02:27, Maciej Żenczykowski wrote:
> On Mon, Jul 29, 2024 at 5:17 PM Maciej Żenczykowski <maze@google.com> wrote:
>>
>> 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:
>>    https://android-review.googlesource.com/c/kernel/tests/+/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: 048c796beb6e ("ipv6: adjust ndisc_is_useropt() to also return true for PIO")
>> ---
>>   net/ipv6/ndisc.c | 34 ++++++++++++++++++----------------
>>   1 file changed, 18 insertions(+), 16 deletions(-)
>>
>> diff --git a/net/ipv6/ndisc.c b/net/ipv6/ndisc.c
>> index 70a0b2ad6bd7..b8eec1b6cc2c 100644
>> --- a/net/ipv6/ndisc.c
>> +++ b/net/ipv6/ndisc.c
>> @@ -227,6 +227,7 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
>>                  return NULL;
>>          memset(ndopts, 0, sizeof(*ndopts));
>>          while (opt_len) {
>> +               bool unknown = false;
>>                  int l;
>>                  if (opt_len < sizeof(struct nd_opt_hdr))
>>                          return NULL;
>> @@ -262,22 +263,23 @@ struct ndisc_options *ndisc_parse_options(const struct net_device *dev,
>>                          break;
>>   #endif
>>                  default:
>> -                       if (ndisc_is_useropt(dev, nd_opt)) {
>> -                               ndopts->nd_useropts_end = nd_opt;
>> -                               if (!ndopts->nd_useropts)
>> -                                       ndopts->nd_useropts = nd_opt;
>> -                       } else {
>> -                               /*
>> -                                * Unknown options must be silently ignored,
>> -                                * to accommodate future extension to the
>> -                                * protocol.
>> -                                */
>> -                               ND_PRINTK(2, notice,
>> -                                         "%s: ignored unsupported option; type=%d, len=%d\n",
>> -                                         __func__,
>> -                                         nd_opt->nd_opt_type,
>> -                                         nd_opt->nd_opt_len);
>> -                       }
>> +                       unknown = true;
>> +               }
>> +               if (ndisc_is_useropt(dev, nd_opt)) {
>> +                       ndopts->nd_useropts_end = nd_opt;
>> +                       if (!ndopts->nd_useropts)
>> +                               ndopts->nd_useropts = nd_opt;
>> +               } else if (unknown) {
>> +                       /*
>> +                        * Unknown options must be silently ignored,
>> +                        * to accommodate future extension to the
>> +                        * protocol.
>> +                        */
>> +                       ND_PRINTK(2, notice,
>> +                                 "%s: ignored unsupported option; type=%d, len=%d\n",
>> +                                 __func__,
>> +                                 nd_opt->nd_opt_type,
>> +                                 nd_opt->nd_opt_len);
>>                  }
>>   next_opt:
>>                  opt_len -= l;
>> --
>> 2.46.0.rc1.232.g9752f9e123-goog
>>
> 
> The diff on this second version is significantly bigger (although it's
> just unindenting a block), but perhaps this is better as it is much
> harder to screw things up.

Makes sense to me.

It would be great if you could follow-up with a self-test covering this.

Thanks,

Paolo
patchwork-bot+netdevbpf@kernel.org Aug. 1, 2024, 10:10 a.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Mon, 29 Jul 2024 17:17:48 -0700 you wrote:
> 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:
>   https://android-review.googlesource.com/c/kernel/tests/+/3196704
> fixes those up.
> 
> [...]

Here is the summary with links:
  - [net,v2] ipv6: fix ndisc_is_useropt() handling for PIO
    https://git.kernel.org/netdev/net/c/a46c68debf3b

You are awesome, thank you!
diff mbox series

Patch

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