From: Andrea Mayer <andrea.mayer@uniroma2.it>
To: Kuniyuki Iwashima <kuniyu@google.com>
Cc: benquike@gmail.com, davem@davemloft.net, dsahern@kernel.org,
edumazet@kernel.org, horms@kernel.org, idosch@nvidia.com,
kuba@kernel.org, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, pabeni@redhat.com,
sashiko-bot@kernel.org, stefano.salsano@uniroma2.it,
Andrea Mayer <andrea.mayer@uniroma2.it>
Subject: Re: [PATCH net] ipv6: rpl: unclone the skb before modifying the packet
Date: Mon, 5 Oct 2026 18:48:19 +0200 [thread overview]
Message-ID: <20261005184819.80d7b6bfcce102437c9d21df@uniroma2.it> (raw)
In-Reply-To: <20261003193103.1178658-1-kuniyu@google.com>
On Sat, 3 Oct 2026 19:30:58 +0000
Kuniyuki Iwashima <kuniyu@google.com> wrote:
Hi Kuniyuki,
Thanks for the review and for the diff.
> [snip]
>
> > + if (skb_cloned(skb)) {
> > + if (pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
>
> ipv6_rpl_srh_rcv() already has pskb_expand_head() call later
> and I think this can be merged there.
>
> [snip]
>
> > hdr->segments_left--;
> > i = n - hdr->segments_left;
>
> This and the later swap(ipv6_hdr(skb)->daddr, ohdr->rpl_segaddr[i])
> only modify the header before the existing pskb_expand_head().
Agreed, the unclone can be merged with the existing pskb_expand_head()
once the writes are moved after it.
> Also this seems wrong because skb_postpull_rcsum() is applied to
> the modified header, which should corrupt checksum.
Yes, this is a separate bug. v1 was meant to cover only the clone for
now. I will fix it as well.
> I think we can merge the clone check and pskb_expand_head() with
> skb_cow() and tmp IPv6 buffer like this.
>
> compiled only:
>
> ---8<---
> diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
> index 09a4552f7f08..af285edd4d16 100644
> --- a/net/ipv6/exthdrs.c
> +++ b/net/ipv6/exthdrs.c
> @@ -485,6 +485,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
> struct net *net = dev_net(skb->dev);
> struct ipv6hdr *oldhdr;
> unsigned int chdr_len;
> + struct in6_addr addr;
> unsigned char *buf;
> int accept_rpl_seg;
> int i, err;
> @@ -548,9 +549,6 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
> return -1;
> }
>
> - hdr->segments_left--;
> - i = n - hdr->segments_left;
> -
> buf = kcalloc(struct_size(hdr, segments.addr, n + 2), 2, GFP_ATOMIC);
> if (unlikely(!buf)) {
> kfree_skb(skb);
> @@ -559,6 +557,8 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
>
> ohdr = (struct ipv6_rpl_sr_hdr *)buf;
> ipv6_rpl_srh_decompress(ohdr, hdr, &ipv6_hdr(skb)->daddr, n);
> + ohdr->segments_left--;
> + i = n - ohdr->segments_left;
> chdr = (struct ipv6_rpl_sr_hdr *)(buf + ((ohdr->hdrlen + 1) << 3));
>
> if (ipv6_addr_is_multicast(&ohdr->rpl_segaddr[i])) {
> @@ -575,28 +575,24 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
> return -1;
> }
>
> - swap(ipv6_hdr(skb)->daddr, ohdr->rpl_segaddr[i]);
> + addr = ohdr->rpl_segaddr[i];
> + ohdr->rpl_segaddr[i] = ipv6_hdr(skb)->daddr;
>
> - ipv6_rpl_srh_compress(chdr, ohdr, &ipv6_hdr(skb)->daddr, n);
> -
> - oldhdr = ipv6_hdr(skb);
> + ipv6_rpl_srh_compress(chdr, ohdr, &addr, n);
>
> skb_pull(skb, ((hdr->hdrlen + 1) << 3));
> - skb_postpull_rcsum(skb, oldhdr,
> + skb_postpull_rcsum(skb, ipv6_hdr(skb),
> sizeof(struct ipv6hdr) + ((hdr->hdrlen + 1) << 3));
> chdr_len = sizeof(struct ipv6hdr) + ((chdr->hdrlen + 1) << 3);
> - if (unlikely(!hdr->segments_left ||
> - skb_headroom(skb) < chdr_len + skb->mac_len)) {
> - if (pskb_expand_head(skb, chdr_len + skb->mac_len, 0,
> - GFP_ATOMIC)) {
> - __IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_OUTDISCARDS);
> - kfree_skb(skb);
> - kfree(buf);
> - return -1;
> - }
> -
> - oldhdr = ipv6_hdr(skb);
> + if (unlikely(skb_cow(skb, chdr_len + skb->mac_len))) {
> + __IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_OUTDISCARDS);
> + kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
> + kfree(buf);
> + return -1;
> }
> +
> + oldhdr = ipv6_hdr(skb);
> +
> skb_push(skb, chdr_len);
> skb_reset_network_header(skb);
> skb_mac_header_rebuild(skb);
> @@ -605,6 +601,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb, struct inet6_dev *idev)
> memmove(ipv6_hdr(skb), oldhdr, sizeof(struct ipv6hdr));
> memcpy(skb_transport_header(skb), chdr, (chdr->hdrlen + 1) << 3);
>
> + ipv6_hdr(skb)->daddr = addr;
> ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
> skb_postpush_rcsum(skb, ipv6_hdr(skb),
> sizeof(struct ipv6hdr) + ((chdr->hdrlen + 1) << 3));
> ---8<---
I will take your diff into account for v2.
Thanks,
Andrea
pw-bot: changes-requested
prev parent reply other threads:[~2026-10-05 16:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 18:21 [PATCH net] ipv6: rpl: unclone the skb before modifying the packet Andrea Mayer
2026-10-01 18:29 ` netdev-bot+sinfo
2026-10-02 22:52 ` Andrea Mayer
2026-10-03 19:30 ` Kuniyuki Iwashima
2026-10-05 16:48 ` Andrea Mayer [this message]
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=20261005184819.80d7b6bfcce102437c9d21df@uniroma2.it \
--to=andrea.mayer@uniroma2.it \
--cc=benquike@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sashiko-bot@kernel.org \
--cc=stefano.salsano@uniroma2.it \
/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