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

> From: Alejandro Pacheco <[email protected]>
> An output action with max_len trims the packet with dp_packet_set_size()
> alone, keeping the layer offsets, L2 padding, checksum offload flags and
> TSO segment size of the full packet.  Completing a partial L4 checksum
> on send then works on an L4 header that was cut short or lies past the
> new end, and reads and writes past the packet data.
>
> Add dp_packet_truncate() and use it for both truncation sites.  It
> shrinks the L2 padding, clears layer offsets past the new end and drops
> the L4 checksum and segmentation offloads.  The IPv4 header checksum
> offload is kept only while the whole header remains.
>
> Fixes: 3337e6d91c5b ("userspace: Enable L4 checksum offloading by default.")
> Assisted-by: claude-opus-5-5, Claude Code
> Signed-off-by: Alejandro Pacheco <[email protected]>
> ---

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

>  lib/dp-packet.c      | 56 ++++++++++++++++++++++++++++++++++++++++++++
>  lib/dp-packet.h      |  3 ++-
>  lib/dpif.c           |  2 +-
>  tests/dpif-netdev.at | 45 +++++++++++++++++++++++++++++++++++
>  4 files changed, 104 insertions(+), 2 deletions(-)
>
> diff --git a/lib/dp-packet.c b/lib/dp-packet.c
> index fb52fec68..8febe8425 100644
> --- a/lib/dp-packet.c
> +++ b/lib/dp-packet.c
> @@ -529,6 +529,62 @@ dp_packet_resize_l2_5(struct dp_packet *b, int increment)
>      return dp_packet_data(b);
>  }
> 
> +static void
> +dp_packet_truncate_layer_offset(uint16_t *offset, uint32_t size)
> +{
> +    if (*offset != UINT16_MAX && *offset > size) {
> +        *offset = UINT16_MAX;

Concern (boundary): valid byte offsets after truncation are [0,
size-1]. An offset exactly equal to size means the layer header was
removed entirely (zero bytes remain), yet it is kept. This contradicts
the commit message ("offsets past the new end are cleared") — an offset
of `size` points one byte past the last valid byte. Concretely,
truncating to max_len=34 on the test frame leaves l4_ofs == 34 == size,
so dp_packet_l4() returns a non-NULL pointer at data+size and
dp_packet_l4_size() computes to 0. I verified the main hazard is
defused: L4 csum offloads are dropped unconditionally, and
dp_packet_ip_header_fits() short-circuits on `size >= IP_HEADER_LEN`
before dereferencing ip_ihl_ver, so no out-of-bounds access follows
through this commit's own logic. But other consumers of
dp_packet_l3()/dp_packet_l4() only test against UINT16_MAX (e.g.,
dp_packet_ip_set_header_csum asserts non-NULL and would read one byte
past the packet end — still inside the allocation since truncation never
frees tail bytes, so it is a logical over-read, not memory
corruption). `>=` would match the stated intent; `>` leaves
fully-truncated headers marked present. Low severity given current call
sites, but it is an inconsistency future callers can trip on.

> +    }
> +}
> +
> +/* Returns true if 'size' bytes at 'ip' hold an IPv4 header with all of its
> + * options. */
> +static bool
> +dp_packet_ip_header_fits(const struct ip_header *ip, size_t size)
> +{
> +    return ip && size >= IP_HEADER_LEN
> +           && IP_IHL(ip->ip_ihl_ver) * 4 <= size;
> +}

   Offload / consumer mismatch: `dp_packet_ip_header_fits()` uses
   IHL*4 <= size (inclusive), but `dp_packet_ip_set_header_csum()` uses
   ip_len < l3_size (strict).  A packet truncated to exactly the IPv4
   header keeps DP_PACKET_OL_IP_CKSUM while the checksum computation is
   skipped.  It could be sent with a stale ip_csum after a
   set_ipv4/dec_ttl/NAT action.

> +/* Removes data from the tail of 'b', leaving it 'size' bytes long.  The L2
> + * padding shrinks with the data, layer offsets past the new end are cleared,
> + * and checksum and segmentation offloads that depend on the removed data are
> + * dropped. */
> +void
> +dp_packet_truncate(struct dp_packet *b, uint32_t size)

This function only guards against size > packet_size with ovs_assert
(compiled out under NDEBUG).  A flow like trunc(N), pop_vlan, output
applied via ovs-dpctl can underflow size - cutlen, aborting assert
builds or causing an OOB send read under NDEBUG.
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to