Skip to contentSkip to conversation

xfrm: iptfs: make room before copying a continuation in reassembly

PATCH In review Andrii Tereshchenko 2 participants 2 messages Nov 22 – Nov 24

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfrm: iptfs: make room before copying a continuation in reassembly

When iptfs_reassem_cont() cannot share a continuation as page frags, it linearizes the in-progress skb and copies the data in with skb_put(), without checking the tailroom. An skb started by iptfs_pskb_add_frags() has little room after linearizing, so a larger continuation panics the kernel in softirq:

skbuff: skb_over_panic: ... len:2884 put:1442 ... end:0x6c0 dev:eth1 kernel BUG at net/core/skbuff.c:215!

  Call Trace:
   <IRQ>
   skb_put.cold+0x1f/0x1f
   iptfs_reassem_cont+0x242/0x760
   iptfs_input_ordered+0x382/0x3e0
   iptfs_input+0x24d/0x630
   xfrm_input+0x12a5/0x29f0

After linearizing, grow the head if the rest of the inner packet does not fit, and abandon the reassembly if that fails.

Made with an AI coding assistant, reviewed by the submitter.

Fixes 5f2b6a909574 ("xfrm: iptfs: add skb-fragment sharing code")
Fixes 0b352f83cabf ("xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly")

---
v2:
- skb_linearize() first, then pskb_expand_head() only if the tailroom is still short, as Fernando Fernandez Mancera suggested. Regular traffic never took the second allocation in my tests.
- shorter changelog.
v1: https://lore.kernel.org/all/[email protected]/

The netdev AI review of the runt fix flagged this copy (Link:). Piyus Kedia's patch for the same overrun drops the valid inner packet; this one delivers it.

Tested on v7.4-rc3 and ipsec master: the panic reproduces without fault injection and is gone with this patch, failslab on either allocation only drops the packet, and W=1 and sparse are clean. The selftest is with the IPsec maintainers, as security-bugs.rst asks.

 net/xfrm/xfrm_iptfs.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/xfrm/xfrm_iptfs.c +9 -1
index 0313a43aa8a97..e9b4d23468022 100644
@@ -909,7 +909,15 @@ static u32 iptfs_reassem_cont(struct xfrm_iptfs_data *xtfs, u64 seq,
 	    iptfs_skb_can_add_frags(newskb, fragwalk, data, copylen)) {
 		iptfs_skb_add_frags(newskb, fragwalk, data, copylen);
 	} else {
-		if (skb_linearize(newskb)) {
+		/* A newskb started by iptfs_pskb_add_frags() has little
+		 * tailroom after linearizing. Make room for the rest of
+		 * the inner packet before copying.
+		 */
+		if (skb_linearize(newskb) ||
+		    (skb_tailroom(newskb) < ipremain &&
+		     pskb_expand_head(newskb, 0,
+				      ipremain - skb_tailroom(newskb),
+				      GFP_ATOMIC | __GFP_NOWARN))) {
 			XFRM_INC_STATS(xs_net(xtfs->x),
 				       LINUX_MIB_XFRMINBUFFERERROR);
 			goto abandon;

base-commit: f0e68014f4ac1653b2980ab76744f4dfdffdbac5

Signature · 1 line
2.53.0
Reviewed-by on v2 1/1
#1 lore raw
Quoted 21 lines · Andrii Tereshchenko

When iptfs_reassem_cont() cannot share a continuation as page frags, it linearizes the in-progress skb and copies the data in with skb_put(), without checking the tailroom. An skb started by iptfs_pskb_add_frags() has little room after linearizing, so a larger continuation panics the kernel in softirq:

   skbuff: skb_over_panic: ... len:2884 put:1442 ... end:0x6c0 dev:eth1
   kernel BUG at net/core/skbuff.c:215!
   Call Trace:
    <IRQ>
    skb_put.cold+0x1f/0x1f
    iptfs_reassem_cont+0x242/0x760
    iptfs_input_ordered+0x382/0x3e0
    iptfs_input+0x24d/0x630
    xfrm_input+0x12a5/0x29f0

After linearizing, grow the head if the rest of the inner packet does not fit, and abandon the reassembly if that fails.

Made with an AI coding assistant, reviewed by the submitter.

Quoted 7 lines
Fixes 5f2b6a909574 ("xfrm: iptfs: add skb-fragment sharing code")
Fixes 0b352f83cabf ("xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly")

Thanks!