Message ID | f417e151bc753428b66f4ca4762a78203623f83d.1735812447.git.leon@kernel.org (mailing list archive) |
---|---|
State | Awaiting Upstream |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [ipsec-rc] xfrm: delete intermediate secpath entry in packet offload mode | expand |
On Thu, Jan 02, 2025 at 12:11:11PM +0200, Leon Romanovsky wrote: > From: Alexandre Cassen <acassen@corp.free.fr> > > Packets handled by hardware have added secpath as a way to inform XFRM > core code that this path was already handled. That secpath is not needed > at all after policy is checked and it is removed later in the stack. > > However, in the case of IP forwarding is enabled (/proc/sys/net/ipv4/ip_forward), > that secpath is not removed and packets which already were handled are reentered > to the driver TX path with xfrm_offload set. > > The following kernel panic is observed in mlx5 in such case: > > mlx5_core 0000:04:00.0 enp4s0f0np0: Link up > mlx5_core 0000:04:00.1 enp4s0f1np1: Link up > Initializing XFRM netlink socket > IPsec XFRM device driver > BUG: kernel NULL pointer dereference, address: 0000000000000000 > #PF: supervisor instruction fetch in kernel mode > #PF: error_code(0x0010) - not-present page > PGD 0 P4D 0 > Oops: Oops: 0010 [#1] PREEMPT SMP > CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 6.13.0-rc1-alex #3 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-1ubuntu1.1 04/01/2014 > RIP: 0010:0x0 > Code: Unable to access opcode bytes at 0xffffffffffffffd6. > RSP: 0018:ffffb87380003800 EFLAGS: 00010206 > RAX: ffff8df004e02600 RBX: ffffb873800038d8 RCX: 00000000ffff98cf > RDX: ffff8df00733e108 RSI: ffff8df00521fb80 RDI: ffff8df001661f00 > RBP: ffffb87380003850 R08: ffff8df013980000 R09: 0000000000000010 > R10: 0000000000000002 R11: 0000000000000002 R12: ffff8df001661f00 > R13: ffff8df00521fb80 R14: ffff8df00733e108 R15: ffff8df011faf04e > FS: 0000000000000000(0000) GS:ffff8df46b800000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: ffffffffffffffd6 CR3: 0000000106384000 CR4: 0000000000350ef0 > Call Trace: ... > > Fixes: 5958372ddf62 ("xfrm: add RX datapath protection for IPsec packet offload mode") > Signed-off-by: Alexandre Cassen <acassen@corp.free.fr> > Signed-off-by: Leon Romanovsky <leonro@nvidia.com> Applied, thanks a lot!
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index 32c09e85a64ce..2c4eda6a85966 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h @@ -1224,9 +1224,19 @@ static inline int __xfrm_policy_check2(struct sock *sk, int dir, if (xo) { x = xfrm_input_state(skb); - if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET) - return (xo->flags & CRYPTO_DONE) && - (xo->status & CRYPTO_SUCCESS); + if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET) { + bool check = (xo->flags & CRYPTO_DONE) && + (xo->status & CRYPTO_SUCCESS); + + /* The packets here are plain ones and secpath was + * needed to indicate that hardware already handled + * them and there is no need to do nothing in addition. + * + * Consume secpath which was set by drivers. + */ + secpath_reset(skb); + return check; + } } return __xfrm_check_nopolicy(net, skb, dir) ||