🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Piyus Kedia Thu, 19 Nov 2026 14:23
[PATCH] xfrm: iptfs: bound the reassembly copy by the buffer it copies into
#19199
Author: Piyus Kedia
Date: Thu, 19 Nov 2026 14:23
140 lines
16224 bytes
iptfs_reassem_cont() takes the length to copy from the inner packet's own
IP total-length field:

	ipremain = __iptfs_iplen(newskb->data);
	...
	ipremain -= newskb->len;
	...
	copylen = min(fraglen, ipremain);

and then puts that into the reassembly buffer:

	if (skb_copy_seq_read(st, data, skb_put(newskb, copylen), copylen))

Nothing ties that claimed length to the size of newskb on the path this
takes, although the file states that it must.  iptfs_input_ordered() has
three ways to obtain the skb that becomes xtfs->ra_newskb.  The reuse path
checks the requirement and its comment gives the rule:

	} else if (data + iphlen <= skb_headlen(skb) &&
		   skb_tailroom(skb) + tail - data >= iplen) {
		/* Reuse the received skb.
		 ...
		 * For linear buffer space we only require that
		 * linear buffer space is large enough to
		 * eventually hold the entire reassembled
		 * packet (by including tailroom in the check).
		 */

The fallback allocates for it outright, iptfs_pskb_extract_seq(iplen, ...).
The third does neither: iptfs_pskb_add_frags() is preferred over the
allocating one and builds an skb whose capacity reflects capturelen, the
bytes that arrived, not iplen.  Its result becomes the reassembly buffer
just the same:

	if (skb->len < iplen) {
		/* Start reassembly */
		...
		xtfs->ra_newskb = skb;

So when the sharing path wins, the buffer carries no guarantee about iplen
and the invariant the reuse path enforces is simply absent.  A later
continuation then computes copylen from a header field that can be much
larger than the buffer, and skb_put() walks off the end of it.  skb_linearize() flattens the fragments already present;
it does not grow the tailroom to whatever the header asked for.
skb_over_panic() catches the overrun and BUG()s:

  skbuff: skb_over_panic: text:... len:4000 put:3000 head:... data:...
                          tail:0xff0 end:0x6c0 dev:tap0
  kernel BUG at net/core/skbuff.c:214!
  Oops: invalid opcode: 0000 [#1] SMP KASAN PTI
  RIP: 0010:skb_over_panic+0xcd/0xd0 net/core/skbuff.c:219
  Call Trace:
   skb_put+0xd4/0xe0 net/core/skbuff.c:2641
   iptfs_reassem_cont+0xa30/0xb30 net/xfrm/xfrm_iptfs.c:920
   iptfs_input_ordered+0x479/0x4f0 net/xfrm/xfrm_iptfs.c:1288
   iptfs_input+0x161/0x2b0 net/xfrm/xfrm_iptfs.c:1733
   xfrm_inner_mode_input+0xe0/0x190 net/xfrm/xfrm_input.c:453
   xfrm_input+0xac9/0x1320 net/xfrm/xfrm_input.c:705
   xfrmi_input+0x13a/0x170 net/xfrm/xfrm_interface_core.c:331
   xfrm4_esp_rcv+0x7f/0x1e0 net/ipv4/xfrm4_protocol.c:104
   ip_protocol_deliver_rcu+0x261/0x380 net/ipv4/ip_input.c:207
   ...

tail is 4080 against an end of 1728: a 2352-byte overrun of a buffer sized
for what arrived rather than for what the header claimed.

skb_put() tests tail against end before returning the pointer, and BUG()
does not return, so the copy never runs and nothing is written out of
bounds - this is a reachable BUG()/oops rather than memory corruption.  It
is reached from xfrm_input(), i.e. after ESP processing, so it needs a peer
that can produce packets the SA accepts.

Note that skb->tail and skb->len are already incremented when the check
fires, and the abandon path is not taken, so without panic_on_oops the
task is killed while xtfs->ra_newskb is left pointing at an skb whose tail
is past its end and whose len exceeds its buffer, still reachable from the
SA.

Reproduced deterministically: eighteen payloads on one SA - one declaring
3800 bytes with 1000 carried, sixteen 100-byte continuations that fill the
fragment array to MAX_SKB_FRAGS so iptfs_skb_can_add_frags() must fail, and
one declaring block_offset 1200.  skb_linearize() then pulls into a
kmalloc-4096 buffer (SKB_WITH_OVERHEAD 3776, 80 bytes of headroom, len 2600,
tailroom 1096) 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.

Bound both copies by the tailroom actually available and 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, without disabling the sharing optimisation.  The second check has to come after skb_linearize(), since
that may reallocate and so change the tailroom the copy has to fit in.  The
comparison is made signed because copylen is u32 while skb_tailroom()
returns int: promoting a negative tailroom to a large unsigned would defeat
the check in exactly the leftover state described above.

Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -875,6 +875,20 @@
 		}
 		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;
+		}
 		if (skb_copy_seq_read(st, data, skb_put(newskb, copylen),
 				      copylen)) {
 			XFRM_INC_STATS(xs_net(xtfs->x),
@@ -913,6 +927,15 @@
 			XFRM_INC_STATS(xs_net(xtfs->x),
 				       LINUX_MIB_XFRMINBUFFERERROR);
 			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;
 		}
 
 		/* copy fragment data into newskb */
-- 
2.43.0
Re: [PATCH] xfrm: iptfs: bound the reassembly copy by the buffer it copies into
#19204
Author: netdev-bot+sinfo
Date: Thu, 19 Nov 2026 14:28
19 lines
8553 bytes
Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
Re: [PATCH] xfrm: iptfs: bound the reassembly copy by the buffer it copies into
#21087
Author: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 14:39
199 lines
15844 bytes
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads