Alejandro Pacheco via dev <[email protected]> writes:

> From: Alejandro Pacheco <[email protected]>
>
> The loops that look for the SLL or TLL option in packet_set_nd() and
> odp_set_nd() advance to the next option before subtracting its length,
> so they subtract the length of the next option instead of the current
> one.  The remaining byte count goes wrong and the loop can read and
> write options past the end of the packet.  Subtract before advancing.
>
> packet_set_nd_ext() and odp_set_nd_ext() also access the first option's
> type when the packet holds only the ND header.  Check for it first.
>
> Fixes: e60e935b1f37 ("Implement set-field for IPv6 ND fields (nd_target, 
> nd_sll, and nd_tll).")
> Fixes: 9b2b84973db7 ("Support for match & set ICMPv6 reserved and options 
> type fields")
> Assisted-by: claude-opus-5-5, Claude Code
> Signed-off-by: Alejandro Pacheco <[email protected]>
> ---
> v3: Assert the L4 header in check_set_nd() before comparing the
>     options, for the clang-analyze NonNullParamChecker warning.

The following is an AI LLM review of the patch.  A human has reviewed it
and found the report to be plausible.

>  lib/odp-execute.c    |  8 +++--
>  lib/packets.c        |  6 ++--
>  tests/test-packets.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 81 insertions(+), 4 deletions(-)
>
> diff --git a/lib/odp-execute.c b/lib/odp-execute.c
> index 618fb5ac8..3bec8ee00 100644
> --- a/lib/odp-execute.c
> +++ b/lib/odp-execute.c
> @@ -332,7 +332,11 @@ odp_set_nd_ext(struct dp_packet *packet, const struct 
> ovs_key_nd_extensions
>  {
>      const struct ovs_nd_msg *ns = dp_packet_l4(packet);
>      ovs_16aligned_be32 reserved = ns->rso_flags;
> -    uint8_t opt_type = ns->options[0].type;
> +    uint8_t opt_type = 0;
> +
> +    if (dp_packet_l4_size(packet) >= sizeof *ns + ND_LLA_OPT_LEN) {
> +        opt_type = ns->options[0].type;
> +    }
>  
>      if (mask->nd_reserved) {
>          put_16aligned_be32(&reserved, key->nd_reserved);
> @@ -374,8 +378,8 @@ odp_set_nd(struct dp_packet *packet, const struct 
> ovs_key_nd *key,
>                  break;
>              }
>  
> -            lla_opt += lla_opt->len;
>              bytes_remain -= lla_opt->len * ND_LLA_OPT_LEN;
> +            lla_opt += lla_opt->len;
>          }
>  
>          packet_set_nd(packet,
> diff --git a/lib/packets.c b/lib/packets.c
> index 80c41e4b6..995540824 100644
> --- a/lib/packets.c
> +++ b/lib/packets.c
> @@ -1652,7 +1652,9 @@ packet_set_nd_ext(struct dp_packet *packet, const 
> ovs_16aligned_be32 rso_flags,
>  
>      /* set RSO flags and option type */
>      ns->rso_flags = rso_flags;
> -    opt->type = opt_type;
> +    if (bytes_remain >= sizeof(*ns) + ND_LLA_OPT_LEN) {
> +        opt->type = opt_type;
> +    }

Correct for the options read. One adjacent concern, pre-existing but in
the same pattern this commit is hardening: line 334 (`ovs_16aligned_be32
reserved = ns->rso_flags;`) still dereferences `ns` unconditionally. The
unmasked caller (lib/odp-execute.c:561-569) checks
`dp_packet_get_nd_payload()` first, but the masked caller at line
673-675 calls `odp_set_nd_ext()` with no such check, so a packet with l4
set but shorter than `sizeof *ns` (or with l4 unset, where
`dp_packet_l4_size()` returns 0) would fault on the `rso_flags` read
before any of the new guards apply. Not introduced here; worth a
follow-up guard mirroring what packet_set_nd_ext() does.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to