Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: piyus@iiitd.ac.in
Cc: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, chopps@chopps.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] xfrm: iptfs: bound the reassembly copy by the buffer it copies into
Date: Mon, 23 Nov 2026 14:39:40 +0000	[thread overview]
Message-ID: <179544478062.3135.17059372621569659200@kernel.org> (raw)
In-Reply-To: <20261119142308.3272570-1-piyus@iiitd.ac.in>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The patch stops the BUG() by throwing away well-formed inner
  packets instead of reassembling them.
- [Low] The patch fixes a BUG() that a remote IPsec peer can trigger in
  the xfrm receive path (iptfs_reassem_cont() -> skb_put() ->…
- [Low] The commit message and the new code comment are inaccurate in
  ways that keep a maintainer from checking the patch.

--

xfrm: iptfs: bound the reassembly copy by the buffer it copies into

This adds checks in iptfs_reassem_cont() that compare skb_tailroom(newskb)
with copylen before each skb_put() into the reassembly skb. If there is not
enough room, the reassembly is abandoned and LINUX_MIB_XFRMINBUFFERERROR is
counted. The aim is to stop a peer-triggerable skb_over_panic() when the
reassembly skb was built by iptfs_pskb_add_frags() and later linearized.

> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>

[Severity: Low]
This fixes a BUG() that can be reached from the xfrm receive path. Should it
carry a Fixes: tag and Cc: stable?

The add_frags sharing path and the skb_put() copy come from 5f2b6a9095743a
("xfrm: iptfs: add skb-fragment sharing code").

The skb_linearize() call that turns the earlier SKB_LINEAR_ASSERT crash into
this skb_over_panic() comes from 0b352f83cabfef ("xfrm: iptfs: fix skb_put()
panic on non-linear skb during reassembly"). Its message assumes:

    the initial allocation of newskb originally reserved enough tailroom
    for the entire reassembled packet we do not need to check if we have
    enough tailroom or extend it.

Both commits are in stable kernels, and 0b352f83cabfef itself carries
Fixes: 5f2b6a909574. Without a Fixes: tag, this may not get backported to
the trees that have the bug.

> diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
> index 0313a43aa8a97..8b5cb4a6f69c7 100644
> --- a/net/xfrm/xfrm_iptfs.c
> +++ b/net/xfrm/xfrm_iptfs.c
> @@ -875,6 +875,20 @@ static u32 iptfs_reassem_cont(struct xfrm_iptfs_data *xtfs, u64 seq,
>  		}
>  		fraglen = min(blkoff, remaining);
>  		copylen = min(fraglen, iphremain);
> +		/* copylen is bounded only by the length the inner header
> +		 * claims, which says nothing about the size of the buffer being
> +		 * reassembled into: iptfs_input_ordered() prefers
> +		 * iptfs_pskb_add_frags(), whose capacity is the bytes that
> +		 * arrived, over iptfs_pskb_extract_seq(), which allocates the
> +		 * claimed length. Cast because copylen is u32 and skb_tailroom()
> +		 * returns int, so the comparison must not promote a negative
> +		 * tailroom into a large unsigned.
> +		 */
> +		if (skb_tailroom(newskb) < (int)copylen) {
> +			XFRM_INC_STATS(xs_net(xtfs->x),
> +				       LINUX_MIB_XFRMINBUFFERERROR);
> +			goto abandon;
> +		}

[Severity: Low]
Does this comment match this branch? Here copylen is min(fraglen,
iphremain), and iphremain is __iptfs_iphlen() - newskb->len. That is a fixed
20 or 40 byte header size, not the length the inner header claims.

Can an skb built by iptfs_pskb_add_frags() get into this branch at all?
iptfs_input_ordered() only calls it when capturelen > iphlen:

    capturelen <= iphlen ||
    /* Try creating skb and adding frags */
    !(skb = iptfs_pskb_add_frags(first_skb, fragwalk,
                                 data, capturelen,
                                 skbseq, iphlen))) {

So its result always has newskb->len >= __iptfs_iphlen() and skips this
block.

The other producers are already covered:

  - the reuse path guarantees headlen >= iphlen
  - iptfs_pskb_extract_seq(iplen, ...) already has tailroom >= iphremain
  - the runt iptfs_alloc_skb(skb, ipremain, false) does as well

That would make this first check unreachable. The "Bound both copies"
wording in the commit message seems to rest on the same assumption.

Two details in the commit message also look inconsistent. The quoted splat
shows:

    skbuff: skb_over_panic: text:... len:4000 put:3000 head:... data:...
                            tail:0xff0 end:0x6c0 dev:tap0

but the reproducer paragraph says:

    and skb_put(1200) is 104 bytes past the end, which is the
    len:3800 put:1200 tail:0xf28 end:0xec0 above.  The same values appear on
    every run.

Those values don't appear above. Are two different reproductions mixed
together here?

The message also says:

    without panic_on_oops the
    task is killed while xtfs->ra_newskb is left pointing at an skb whose tail
    is past its end

Does that hold on this path? It always runs with BH disabled, either in the
NET_RX softirq or under tun's local_bh_disable() around netif_receive_skb().
oops_end() in arch/x86/kernel/dumpstack.c does:

    if (in_interrupt())
        panic("Fatal exception in interrupt");

So the leftover state used to justify the signed cast doesn't seem reachable
here.

[ ... ]

> @@ -915,6 +929,15 @@ static u32 iptfs_reassem_cont(struct xfrm_iptfs_data *xtfs, u64 seq,
>  			goto abandon;
>  		}
>  
> +		/* Re-checked after skb_linearize(), which may reallocate and so
> +		 * change the tailroom this copy has to fit in.
> +		 */
> +		if (skb_tailroom(newskb) < (int)copylen) {
> +			XFRM_INC_STATS(xs_net(xtfs->x),
> +				       LINUX_MIB_XFRMINBUFFERERROR);
> +			goto abandon;
> +		}

[Severity: High]
Does this check drop well-formed inner packets instead of reassembling them?

Take an inner packet with iplen >= IPTFS_PKT_SHARE_MIN and capturelen >
iphlen. iptfs_input_ordered() tries iptfs_pskb_add_frags() before
iptfs_pskb_extract_seq(iplen, ...). That allocates only copy_len (iphlen)
of linear space:

    skb = iptfs_alloc_skb(tpl, copy_len, false);

A later continuation may not be able to share frags. This happens when
nr_frags would go past MAX_SKB_FRAGS, when the outer skb is not head_frag
and has linear data, when pp_recycle differs, or when either skb has a
frag_list. skb_linearize() then goes through __pskb_pull_tail(), which grows
the head by only eat + 128:

    if (pskb_expand_head(skb, 0, eat > 0 ? eat + 128 : 0,
                         GFP_ATOMIC))

So the tailroom left after linearizing has no relation to ipremain.

By this point the stream has already been checked: blkoff < ipremain goes
to abandon, so copylen <= ipremain <= blkoff.

The reproducer in the commit message is a consistent stream. 1000 + 16 * 100
+ 1200 = 3800 bytes, which is exactly the declared iplen. Before this patch
it crashed. With it, the packet is always dropped.

The commit message describes this as:

    abandon the
    reassembly otherwise, which is how the function already handles a stream it
    cannot complete.  This restores at the point of use the invariant the reuse
    path states

But this stream can be completed. The check detects that the invariant is
broken and drops the packet; it does not restore the invariant. The earlier
fix in 0b352f83cabfef assumed the initial newskb allocation reserved
tailroom for the whole reassembled packet.

Would it be better to grow newskb here instead? One option is
pskb_expand_head(newskb, 0, ipremain - skb_tailroom(newskb), GFP_ATOMIC)
after skb_linearize(). Another is to have reassembly skbs built by
iptfs_pskb_add_frags() reserve iplen of capacity. The reassembly would then
only be abandoned if that allocation fails.

Also, the drop is counted as LINUX_MIB_XFRMINBUFFERERROR, which
Documentation/networking/xfrm/xfrm_proc.rst describes as "No buffer is
left". No allocation failed in this case. Is that the right counter?

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119142308.3272570-1-piyus%40iiitd.ac.in

      parent reply	other threads:[~2026-11-23 14:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 14:23 [PATCH] xfrm: iptfs: bound the reassembly copy by the buffer it copies into Piyus Kedia
2026-11-19 14:28 ` netdev-bot+sinfo
2026-11-20  9:06 ` Andrii Tereshchenko
2026-11-23 14:39 ` netdev-bot+sashiko [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=179544478062.3135.17059372621569659200@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=chopps@chopps.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=piyus@iiitd.ac.in \
    --cc=steffen.klassert@secunet.com \
    /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