public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipsec] xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly
@ 2026-03-03 17:10 Fernando Fernandez Mancera
  2026-03-03 17:21 ` Fernando Fernandez Mancera
  0 siblings, 1 reply; 2+ messages in thread
From: Fernando Fernandez Mancera @ 2026-03-03 17:10 UTC (permalink / raw)
  To: netdev
  Cc: chopps, horms, pabeni, kuba, edumazet, davem, herbert,
	steffen.klassert, Fernando Fernandez Mancera, Hao Long

In iptfs_reassem_cont(), IP-TFS attempts to append data to the new inner
packet 'newskb' that is being reassembled. First a zero-copy approach is
tried if it succeeds then newskb becomes non-linear.

When a subsequent fragment in the same datagram does not meet the
fast-path conditions, a memory copy is performed. It calls skb_put() to
append the data and as newskb is non-linear it triggers
SKB_LINEAR_ASSERT check.

 Oops: invalid opcode: 0000 [#1] SMP NOPTI
 [...]
 RIP: 0010:skb_put+0x3c/0x40
 [...]
 Call Trace:
  <IRQ>
  iptfs_reassem_cont+0x1ab/0x5e0 [xfrm_iptfs]
  iptfs_input_ordered+0x2af/0x380 [xfrm_iptfs]
  iptfs_input+0x122/0x3e0 [xfrm_iptfs]
  xfrm_input+0x91e/0x1a50
  xfrm4_esp_rcv+0x3a/0x110
  ip_protocol_deliver_rcu+0x1d7/0x1f0
  ip_local_deliver_finish+0xbe/0x1e0
  __netif_receive_skb_core.constprop.0+0xb56/0x1120
  __netif_receive_skb_list_core+0x133/0x2b0
  netif_receive_skb_list_internal+0x1ff/0x3f0
  napi_complete_done+0x81/0x220
  virtnet_poll+0x9d6/0x116e [virtio_net]
  __napi_poll.constprop.0+0x2b/0x270
  net_rx_action+0x162/0x360
  handle_softirqs+0xdc/0x510
  __irq_exit_rcu+0xe7/0x110
  irq_exit_rcu+0xe/0x20
  common_interrupt+0x85/0xa0
  </IRQ>
  <TASK>

Fix this by checking if the skb is non-linear. If it is, linearize it by
calling skb_linearize(). As 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.

Fixes: 075694765446 ("xfrm: iptfs: handle received fragmented inner packets")
Reported-by: Hao Long <me@imlonghao.com>
Closes: https://lore.kernel.org/netdev/DGRCO9SL0T5U.JTINSHJQ9KPK@imlonghao.com/
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
 net/xfrm/xfrm_iptfs.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
index 050a82101ca5..4d1a84a6fc45 100644
--- a/net/xfrm/xfrm_iptfs.c
+++ b/net/xfrm/xfrm_iptfs.c
@@ -901,6 +901,12 @@ 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_is_nonlinear(newskb) && skb_linearize(newskb)) {
+			XFRM_INC_STATS(xs_net(xtfs->x),
+				       LINUX_MIB_XFRMINBUFFERERROR);
+			goto abandon;
+		}
+
 		/* copy fragment data into newskb */
 		if (skb_copy_seq_read(st, data, skb_put(newskb, copylen),
 				      copylen)) {
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH ipsec] xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly
  2026-03-03 17:10 [PATCH ipsec] xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly Fernando Fernandez Mancera
@ 2026-03-03 17:21 ` Fernando Fernandez Mancera
  0 siblings, 0 replies; 2+ messages in thread
From: Fernando Fernandez Mancera @ 2026-03-03 17:21 UTC (permalink / raw)
  To: netdev
  Cc: chopps, horms, pabeni, kuba, edumazet, davem, herbert,
	steffen.klassert, Hao Long

On 3/3/26 6:10 PM, Fernando Fernandez Mancera wrote:
> In iptfs_reassem_cont(), IP-TFS attempts to append data to the new inner
> packet 'newskb' that is being reassembled. First a zero-copy approach is
> tried if it succeeds then newskb becomes non-linear.
> 
> When a subsequent fragment in the same datagram does not meet the
> fast-path conditions, a memory copy is performed. It calls skb_put() to
> append the data and as newskb is non-linear it triggers
> SKB_LINEAR_ASSERT check.
> 
>   Oops: invalid opcode: 0000 [#1] SMP NOPTI
>   [...]
>   RIP: 0010:skb_put+0x3c/0x40
>   [...]
>   Call Trace:
>    <IRQ>
>    iptfs_reassem_cont+0x1ab/0x5e0 [xfrm_iptfs]
>    iptfs_input_ordered+0x2af/0x380 [xfrm_iptfs]
>    iptfs_input+0x122/0x3e0 [xfrm_iptfs]
>    xfrm_input+0x91e/0x1a50
>    xfrm4_esp_rcv+0x3a/0x110
>    ip_protocol_deliver_rcu+0x1d7/0x1f0
>    ip_local_deliver_finish+0xbe/0x1e0
>    __netif_receive_skb_core.constprop.0+0xb56/0x1120
>    __netif_receive_skb_list_core+0x133/0x2b0
>    netif_receive_skb_list_internal+0x1ff/0x3f0
>    napi_complete_done+0x81/0x220
>    virtnet_poll+0x9d6/0x116e [virtio_net]
>    __napi_poll.constprop.0+0x2b/0x270
>    net_rx_action+0x162/0x360
>    handle_softirqs+0xdc/0x510
>    __irq_exit_rcu+0xe7/0x110
>    irq_exit_rcu+0xe/0x20
>    common_interrupt+0x85/0xa0
>    </IRQ>
>    <TASK>
> 
> Fix this by checking if the skb is non-linear. If it is, linearize it by
> calling skb_linearize(). As 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.
> 
> Fixes: 075694765446 ("xfrm: iptfs: handle received fragmented inner packets")
> Reported-by: Hao Long <me@imlonghao.com>
> Closes: https://lore.kernel.org/netdev/DGRCO9SL0T5U.JTINSHJQ9KPK@imlonghao.com/
> Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
> ---
>   net/xfrm/xfrm_iptfs.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/net/xfrm/xfrm_iptfs.c b/net/xfrm/xfrm_iptfs.c
> index 050a82101ca5..4d1a84a6fc45 100644
> --- a/net/xfrm/xfrm_iptfs.c
> +++ b/net/xfrm/xfrm_iptfs.c
> @@ -901,6 +901,12 @@ 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_is_nonlinear(newskb) && skb_linearize(newskb)) {

This will indeed require a V2. skb_linearize() is enough here as this is 
calling skb_is_nonlinear() inside it. *face-palm*

> +			XFRM_INC_STATS(xs_net(xtfs->x),
> +				       LINUX_MIB_XFRMINBUFFERERROR);
> +			goto abandon;
> +		}
> +
>   		/* copy fragment data into newskb */
>   		if (skb_copy_seq_read(st, data, skb_put(newskb, copylen),
>   				      copylen)) {


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-03 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-03 17:10 [PATCH ipsec] xfrm: iptfs: fix skb_put() panic on non-linear skb during reassembly Fernando Fernandez Mancera
2026-03-03 17:21 ` Fernando Fernandez Mancera

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox