pull request (net): ipsec 2025-01-27
Subsystems (3)
Steffen Klassert
maintainercover pull request (net): ipsec 2025-01-27
1) Fix incrementing the upper 32 bit sequence numbers for GSO skbs. From Jianbo Liu.
2) Fix an out-of-bounds read on xfrm state lookup. From Florian Westphal.
3) Fix secpath handling on packet offload mode.
From Alexandre Cassen.
4) Fix the usage of skb->sk in the xfrm layer.
5) Don't disable preemption while looking up cache state to fix PREEMPT_RT.
From Sebastian Sewior.
Please pull or let me know if there are problems.
Thanks!
The following changes since commit 9bb88c659673003453fd42e0ddf95c9628409094:
selftests: net: test extacks in netlink dumps (2024-11-24 17:00:06 -0800)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git tags/ipsec-2025-01-27
for you to fetch changes up to 6c9b7db96db62ee9ad8d359d90ff468d462518c4:
xfrm: Don't disable preemption while looking up cache state. (2025-01-24 07:46:11 +0100)
----------------------------------------------------------------
ipsec-2025-01-27
----------------------------------------------------------------
Alexandre Cassen (1):
xfrm: delete intermediate secpath entry in packet offload mode
Florian Westphal (1):
xfrm: state: fix out-of-bounds read during lookup
Jianbo Liu (1):
xfrm: replay: Fix the update of replay_esn->oseq_hi for GSO
Sebastian Sewior (1):
xfrm: Don't disable preemption while looking up cache state.
Steffen Klassert (1):
xfrm: Fix the usage of skb->sk
include/net/xfrm.h | 16 ++++++-- net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- net/ipv6/xfrm6_output.c | 4 +- net/xfrm/xfrm_interface_core.c | 2 +- net/xfrm/xfrm_output.c | 7 ++-- net/xfrm/xfrm_policy.c | 2 +- net/xfrm/xfrm_replay.c | 10 +++-- net/xfrm/xfrm_state.c | 93 ++++++++++++++++++++++++++++++++---------- 9 files changed, 100 insertions(+), 38 deletions(-)
Steffen Klassert
maintainerPATCH 1/5 xfrm: replay: Fix the update of replay_esn->oseq_hi for GSO
From: Jianbo Liu <[email protected]>
When skb needs GSO and wrap around happens, if xo->seq.low (seqno of the first skb segment) is before the last seq number but oseq (seqno of the last segment) is after it, xo->seq.low is still bigger than replay_esn->oseq while oseq is smaller than it, so the update of replay_esn->oseq_hi is missed for this case wrap around because of the change in the cited commit.
For example, if sending a packet with gso_segs=3 while old replay_esn->oseq=0xfffffffe, we calculate:
xo->seq.low = 0xfffffffe + 1 = 0x0xffffffff
oseq = 0xfffffffe + 3 = 0x1(oseq < replay_esn->oseq) is true, but (xo->seq.low < replay_esn->oseq) is false, so replay_esn->oseq_hi is not incremented.
To fix this issue, change the outer checking back for the update of replay_esn->oseq_hi. And add new checking inside for the update of packet's oseq_hi.
--- net/xfrm/xfrm_replay.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
net/xfrm/xfrm_replay.c +6 -4
@@ -714,10 +714,12 @@ static int xfrm_replay_overflow_offload_esn(struct xfrm_state *x, struct sk_buff oseq +=skb_shinfo (skb)->gso_segs; } -if (unlikely (xo->seq.low < replay_esn->oseq)) { -XFRM_SKB_CB (skb)->seq.output.hi = ++oseq_hi; - xo->seq.hi = oseq_hi; - replay_esn->oseq_hi = oseq_hi; +if (unlikely (oseq < replay_esn->oseq)) { + replay_esn->oseq_hi = ++oseq_hi; +if (xo->seq.low < replay_esn->oseq) { +XFRM_SKB_CB (skb)->seq.output.hi = oseq_hi; + xo->seq.hi = oseq_hi; + }if (replay_esn->oseq_hi ==0 ) { replay_esn->oseq--; replay_esn->oseq_hi--;
Signature · 1 line
2.34.1
Re: [PATCH 1/5] xfrm: replay: Fix the update of replay_esn->oseq_hi for GSO
This series was applied to netdev/net.git (main) by Steffen Klassert <[email protected]>:
Hello:
This series was applied to netdev/net.git (main) by Steffen Klassert <[email protected]>:
Quoted 10 lines · On Mon, 27 Jan 2025 07:07:53 +0100 you wrote:
From: Jianbo Liu <[email protected]>
When skb needs GSO and wrap around happens, if
xo->seq.low(seqno of the first skb segment) is before the last seq number but oseq (seqno of the last segment) is after it,xo->seq.lowis still bigger thanreplay_esn->oseqwhile oseq is smaller than it, so the update ofreplay_esn->oseq_hiis missed for this case wrap around because of the change in the cited commit.[...]
Here is the summary with links:
- [1/5] xfrm: replay: Fix the update of replay_esn->oseq_hi for GSO
https://git.kernel.org/netdev/net/c/c05c5e5aa163 - [2/5] xfrm: state: fix out-of-bounds read during lookup https://git.kernel.org/netdev/net/c/e952837f3ddb - [3/5] xfrm: delete intermediate secpath entry in packet offload mode https://git.kernel.org/netdev/net/c/600258d555f0 - [4/5] xfrm: Fix the usage of skb->sk https://git.kernel.org/netdev/net/c/1620c88887b1 - [5/5] xfrm: Don't disable preemption while looking up cache state. https://git.kernel.org/netdev/net/c/6c9b7db96db6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Steffen Klassert
maintainerPATCH 2/5 xfrm: state: fix out-of-bounds read during lookup
In reply to Steffen KlassertFrom: Florian Westphal <[email protected]>
lookup and resize can run in parallel.
The xfrm_state_hash_generation seqlock ensures a retry, but the hash functions can observe a hmask value that is too large for the new hlist array.
rehash does:
rcu_assign_pointer(net->xfrm.state_bydst, ndst) [..] net->xfrm.state_hmask = nhashmask;
While state lookup does:
h = xfrm_dst_hash(net, daddr, saddr, tmpl->reqid, encap_family); hlist_for_each_entry_rcu(x, net->xfrm.state_bydst + h, bydst) {
This is only safe in case the update to state_bydst is larger than net->xfrm.xfrm_state_hmask (or if the lookup function gets serialized via state spinlock again).
Fix this by prefetching state_hmask and the associated pointers. The xfrm_state_hash_generation seqlock retry will ensure that the pointer and the hmask will be consistent.
The existing helpers, like xfrm_dst_hash(), are now unsafe for RCU side, add lockdep assertions to document that they are only safe for insert side.
xfrm_state_lookup_byaddr() uses the spinlock rather than RCU. AFAICS this is an oversight from back when state lookup was converted to RCU, this lock should be replaced with RCU in a future patch.
--- net/xfrm/xfrm_state.c | 89 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 70 insertions(+), 19 deletions(-)
net/xfrm/xfrm_state.c +70 -19
@@ -34,6 +34,8 @@#define xfrm_state_deref_prot (table, net) \ rcu_dereference_protected((table), lockdep_is_held(&(net)->xfrm.xfrm_state_lock)) +#define xfrm_state_deref_check (table, net) \ + rcu_dereference_check((table), lockdep_is_held(&(net)->xfrm.xfrm_state_lock))static void xfrm_state_gc_task (struct work_struct *work);
@@ -62,6 +64,8 @@ static inline unsigned int xfrm_dst_hash(struct net *net, u32 reqid, unsigned short family) { +lockdep_assert_held (&net->xfrm.xfrm_state_lock); +return __xfrm_dst_hash (daddr, saddr, reqid, family, net->xfrm.state_hmask); }
@@ -70,6 +74,8 @@ static inline unsigned int xfrm_src_hash(struct net *net,const xfrm_address_t *saddr, unsigned short family) { + lockdep_assert_held(&net->xfrm.xfrm_state_lock); +return __xfrm_src_hash (daddr, saddr, family, net->xfrm.state_hmask); }
@@ -77,11 +83,15 @@ static inline unsigned int xfrm_spi_hash(struct net *net, const xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family) { + lockdep_assert_held(&net->xfrm.xfrm_state_lock); +return __xfrm_spi_hash (daddr, spi, proto, family, net->xfrm.state_hmask); }static unsigned int xfrm_seq_hash (struct net *net,u32 seq) { +lockdep_assert_held (&net->xfrm.xfrm_state_lock); +return __xfrm_seq_hash (seq, net->xfrm.state_hmask); }
@@ -1041,16 +1051,38 @@ xfrm_init_tempstate(struct xfrm_state *x, const struct flowi *fl, x->props.family = tmpl->encap_family; } -static struct xfrm_state *__xfrm_state_lookup_all (struct net *net,u32 mark, +struct xfrm_hash_state_ptrs { +const struct hlist_head *bydst; +const struct hlist_head *bysrc; +const struct hlist_head *byspi; +unsigned int hmask; +}; + +static void xfrm_hash_ptrs_get (const struct net *net,struct xfrm_hash_state_ptrs *ptrs) +{ +unsigned int sequence; + +do { + sequence =read_seqcount_begin (&net->xfrm.xfrm_state_hash_generation); + + ptrs->bydst =xfrm_state_deref_check (net->xfrm.state_bydst, net); + ptrs->bysrc =xfrm_state_deref_check (net->xfrm.state_bysrc, net); + ptrs->byspi =xfrm_state_deref_check (net->xfrm.state_byspi, net); + ptrs->hmask = net->xfrm.state_hmask; + }while (read_seqcount_retry (&net->xfrm.xfrm_state_hash_generation, sequence)); +} + +static struct xfrm_state *__xfrm_state_lookup_all (const struct xfrm_hash_state_ptrs *state_ptrs, +u32 mark,const xfrm_address_t *daddr,__be32 spi,u8 proto,unsigned short family,struct xfrm_dev_offload *xdo) { -unsigned int h =xfrm_spi_hash (net, daddr, spi, proto, family); +unsigned int h =__xfrm_spi_hash (daddr, spi, proto, family, state_ptrs->hmask);struct xfrm_state *x; -hlist_for_each_entry_rcu (x, net->xfrm.state_byspi + h, byspi) { +hlist_for_each_entry_rcu (x, state_ptrs->byspi + h, byspi) {#ifdef CONFIG_XFRM_OFFLOAD if (xdo->type ==XFRM_DEV_OFFLOAD_PACKET ) {if (x->xso.type !=XFRM_DEV_OFFLOAD_PACKET )
@@ -1084,15 +1116,16 @@ static struct xfrm_state *__xfrm_state_lookup_all(struct net *net, u32 mark,return NULL ; } -static struct xfrm_state *__xfrm_state_lookup (struct net *net,u32 mark, +static struct xfrm_state *__xfrm_state_lookup (const struct xfrm_hash_state_ptrs *state_ptrs, +u32 mark,const xfrm_address_t *daddr,__be32 spi,u8 proto,unsigned short family) { -unsigned int h =xfrm_spi_hash (net, daddr, spi, proto, family); +unsigned int h =__xfrm_spi_hash (daddr, spi, proto, family, state_ptrs->hmask);struct xfrm_state *x; -hlist_for_each_entry_rcu (x, net->xfrm.state_byspi + h, byspi) { +hlist_for_each_entry_rcu (x, state_ptrs->byspi + h, byspi) { if (x->props.family != family || x->id.spi != spi || x->id.proto != proto ||
@@ -1114,6 +1147,7 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark, __be32 spi, u8 proto, unsigned short family) { + struct xfrm_hash_state_ptrs state_ptrs;struct hlist_head *state_cache_input;struct xfrm_state *x =NULL ;int cpu =get_cpu ();
@@ -1135,7 +1169,9 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark, goto out; } - x =__xfrm_state_lookup (net, mark, daddr, spi, proto, family); +xfrm_hash_ptrs_get (net, &state_ptrs); + + x =__xfrm_state_lookup (&state_ptrs, mark, daddr, spi, proto, family);if (x && x->km.state ==XFRM_STATE_VALID ) {spin_lock_bh (&net->xfrm.xfrm_state_lock);
@@ -1155,15 +1191,16 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark, }EXPORT_SYMBOL (xfrm_input_state_lookup); -static struct xfrm_state *__xfrm_state_lookup_byaddr (struct net *net,u32 mark, +static struct xfrm_state *__xfrm_state_lookup_byaddr (const struct xfrm_hash_state_ptrs *state_ptrs, +u32 mark,const xfrm_address_t *daddr,const xfrm_address_t *saddr,u8 proto,unsigned short family) { -unsigned int h =xfrm_src_hash (net, daddr, saddr, family); +unsigned int h =__xfrm_src_hash (daddr, saddr, family, state_ptrs->hmask);struct xfrm_state *x; -hlist_for_each_entry_rcu (x, net->xfrm.state_bysrc + h, bysrc) { +hlist_for_each_entry_rcu (x, state_ptrs->bysrc + h, bysrc) { if (x->props.family != family || x->id.proto != proto || !xfrm_addr_equal(&x->id.daddr, daddr, family) ||
@@ -1183,14 +1220,17 @@ static struct xfrm_state *__xfrm_state_lookup_byaddr(struct net *net, u32 mark,static inline struct xfrm_state *__xfrm_state_locate (struct xfrm_state *x,int use_spi,int family) { +struct xfrm_hash_state_ptrs state_ptrs;struct net *net =xs_net (x);u32 mark = x->mark.v & x->mark.m; +xfrm_hash_ptrs_get (net, &state_ptrs); +if (use_spi) -return __xfrm_state_lookup (net, mark, &x->id.daddr, +return __xfrm_state_lookup (&state_ptrs, mark, &x->id.daddr, x->id.spi, x->id.proto, family);else -return __xfrm_state_lookup_byaddr (net, mark, +return __xfrm_state_lookup_byaddr (&state_ptrs, mark, &x->id.daddr, &x->props.saddr, x->id.proto, family);
@@ -1264,6 +1304,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr, unsigned short family, u32 if_id) {static xfrm_address_t saddr_wildcard = { }; +struct xfrm_hash_state_ptrs state_ptrs;struct net *net =xp_net (pol);unsigned int h, h_wildcard;struct xfrm_state *x, *x0, *to_put;
@@ -1328,8 +1369,10 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,else if (acquire_in_progress)/* XXX: acquire_in_progress should not happen */ WARN_ON (1 ); - h =xfrm_dst_hash (net, daddr, saddr, tmpl->reqid, encap_family); -hlist_for_each_entry_rcu (x, net->xfrm.state_bydst + h, bydst) { +xfrm_hash_ptrs_get (net, &state_ptrs); + + h =__xfrm_dst_hash (daddr, saddr, tmpl->reqid, encap_family, state_ptrs.hmask); +hlist_for_each_entry_rcu (x, state_ptrs.bydst + h, bydst) {#ifdef CONFIG_XFRM_OFFLOAD if (pol->xdo.type ==XFRM_DEV_OFFLOAD_PACKET ) {if (x->xso.type !=XFRM_DEV_OFFLOAD_PACKET )
@@ -1362,8 +1405,9 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,if (best || acquire_in_progress) goto found; - h_wildcard =xfrm_dst_hash (net, daddr, &saddr_wildcard, tmpl->reqid, encap_family); -hlist_for_each_entry_rcu (x, net->xfrm.state_bydst + h_wildcard, bydst) { + h_wildcard =__xfrm_dst_hash (daddr, &saddr_wildcard, tmpl->reqid, + encap_family, state_ptrs.hmask); +hlist_for_each_entry_rcu (x, state_ptrs.bydst + h_wildcard, bydst) {#ifdef CONFIG_XFRM_OFFLOAD if (pol->xdo.type ==XFRM_DEV_OFFLOAD_PACKET ) {if (x->xso.type !=XFRM_DEV_OFFLOAD_PACKET )
@@ -1401,7 +1445,7 @@ xfrm_state_find(const xfrm_address_t *daddr, const xfrm_address_t *saddr,if (!x && !error && !acquire_in_progress) {if (tmpl->id.spi && - (x0 =__xfrm_state_lookup_all (net, mark, daddr, + (x0 =__xfrm_state_lookup_all (&state_ptrs, mark, daddr, tmpl->id.spi, tmpl->id.proto, encap_family, &pol->xdo)) !=NULL ) {
@@ -2180,10 +2224,13 @@ struct xfrm_state * xfrm_state_lookup(struct net *net, u32 mark, const xfrm_address_t *daddr, __be32 spi, u8 proto, unsigned short family) { + struct xfrm_hash_state_ptrs state_ptrs;struct xfrm_state *x;rcu_read_lock (); - x =__xfrm_state_lookup (net, mark, daddr, spi, proto, family); +xfrm_hash_ptrs_get (net, &state_ptrs); + + x =__xfrm_state_lookup (&state_ptrs, mark, daddr, spi, proto, family);rcu_read_unlock ();return x; }
@@ -2194,10 +2241,14 @@ xfrm_state_lookup_byaddr(struct net *net, u32 mark, const xfrm_address_t *daddr, const xfrm_address_t *saddr, u8 proto, unsigned short family) { + struct xfrm_hash_state_ptrs state_ptrs;struct xfrm_state *x;spin_lock_bh (&net->xfrm.xfrm_state_lock); - x =__xfrm_state_lookup_byaddr (net, mark, daddr, saddr, proto, family); + +xfrm_hash_ptrs_get (net, &state_ptrs); + + x =__xfrm_state_lookup_byaddr (&state_ptrs, mark, daddr, saddr, proto, family);spin_unlock_bh (&net->xfrm.xfrm_state_lock);return x; }
Signature · 1 line
2.34.1
Steffen Klassert
maintainerPATCH 3/5 xfrm: delete intermediate secpath entry in packet offload mode
In reply to Steffen KlassertFrom: Alexandre Cassen <[email protected]>
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: <IRQ> ? show_regs+0x63/0x70 ? __die_body+0x20/0x60 ? __die+0x2b/0x40 ? page_fault_oops+0x15c/0x550 ? do_user_addr_fault+0x3ed/0x870 ? exc_page_fault+0x7f/0x190 ? asm_exc_page_fault+0x27/0x30 mlx5e_ipsec_handle_tx_skb+0xe7/0x2f0 [mlx5_core] mlx5e_xmit+0x58e/0x1980 [mlx5_core] ? __fib_lookup+0x6a/0xb0 dev_hard_start_xmit+0x82/0x1d0 sch_direct_xmit+0xfe/0x390 __dev_queue_xmit+0x6d8/0xee0 ? __fib_lookup+0x6a/0xb0 ? internal_add_timer+0x48/0x70 ? mod_timer+0xe2/0x2b0 neigh_resolve_output+0x115/0x1b0 __neigh_update+0x26a/0xc50 neigh_update+0x14/0x20 arp_process+0x2cb/0x8e0 ? __napi_build_skb+0x5e/0x70 arp_rcv+0x11e/0x1c0 ? dev_gro_receive+0x574/0x820 __netif_receive_skb_list_core+0x1cf/0x1f0 netif_receive_skb_list_internal+0x183/0x2a0 napi_complete_done+0x76/0x1c0 mlx5e_napi_poll+0x234/0x7a0 [mlx5_core] __napi_poll+0x2d/0x1f0 net_rx_action+0x1a6/0x370 ? atomic_notifier_call_chain+0x3b/0x50 ? irq_int_handler+0x15/0x20 [mlx5_core] handle_softirqs+0xb9/0x2f0 ? handle_irq_event+0x44/0x60 irq_exit_rcu+0xdb/0x100 common_interrupt+0x98/0xc0 </IRQ> <TASK> asm_common_interrupt+0x27/0x40 RIP: 0010:pv_native_safe_halt+0xb/0x10 Code: 09 c3 66 66 2e 0f 1f 84 00 00 00 00 00 66 90 0f 22 0f 1f 84 00 00 00 00 00 90 eb 07 0f 00 2d 7f e9 36 00 fb
40 00 83 ff 07 77 21 89 ff ff 24 fd 88 3d a1 bd 0f 21 f8
RSP: 0018:ffffffffbe603de8 EFLAGS: 00000202
RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000f92f46680
RDX: 0000000000000037 RSI: 00000000ffffffff RDI: 00000000000518d4
RBP: ffffffffbe603df0 R08: 000000cd42e4dffb R09: ffffffffbe603d70
R10: 0000004d80d62680 R11: 0000000000000001 R12: ffffffffbe60bf40
R13: 0000000000000000 R14: 0000000000000000 R15: ffffffffbe60aff8
? default_idle+0x9/0x20 arch_cpu_idle+0x9/0x10 default_idle_call+0x29/0xf0 do_idle+0x1f2/0x240 cpu_startup_entry+0x2c/0x30 rest_init+0xe7/0x100 start_kernel+0x76b/0xb90 x86_64_start_reservations+0x18/0x30 x86_64_start_kernel+0xc0/0x110 ? setup_ghcb+0xe/0x130 common_startup_64+0x13e/0x141 </TASK> Modules linked in: esp4_offload esp4 xfrm_interface
xfrm6_tunnel tunnel4 tunnel6 xfrm_user xfrm_algo binfmt_misc intel_rapl_msr intel_rapl_common kvm_amd ccp kvm input_leds serio_raw qemu_fw_cfg sch_fq_codel dm_multipath scsi_dh_rdac scsi_dh_emc scsi_dh_alua efi_pstore ip_tables x_tables autofs4 raid10 raid456 async_raid6_recov async_memcpy async_pq raid6_pq async_xor xor async_tx libcrc32c raid1 raid0 mlx5_core crct10dif_pclmul crc32_pclmul polyval_clmulni polyval_generic ghash_clmulni_intel sha256_ssse3 sha1_ssse3 ahci mlxfw i2c_i801 libahci i2c_mux i2c_smbus psample virtio_rng pci_hyperv_intf aesni_intel crypto_simd cryptd
CR2: 0000000000000000
---[ end trace 0000000000000000 ]--- 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 Kernel panic - not syncing: Fatal exception in interrupt Kernel Offset: 0x3b800000 from 0xffffffff81000000 (relocation range: 0xffffffff80000000-0xffffffffbfffffff) ---[ end Kernel panic - not syncing: Fatal exception in interrupt ]---
--- include/net/xfrm.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
include/net/xfrm.h +13 -3
@@ -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) ||
Signature · 1 line
2.34.1
Steffen Klassert
maintainerPATCH 4/5 xfrm: Fix the usage of skb->sk
In reply to Steffen Klassertxfrm assumed to always have a full socket at skb->sk. This is not always true, so fix it by converting to a full socket before it is used.
--- net/ipv4/esp4.c | 2 +- net/ipv6/esp6.c | 2 +- net/ipv6/xfrm6_output.c | 4 ++-- net/xfrm/xfrm_interface_core.c | 2 +- net/xfrm/xfrm_output.c | 7 ++++--- net/xfrm/xfrm_policy.c | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-)
net/ipv4/esp4.c +1 -1
@@ -279,7 +279,7 @@ static void esp_output_done(void *data, int err) x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)esp_output_tail_tcp (x, skb); else - xfrm_output_resume(skb->sk, skb, err); +xfrm_output_resume (skb_to_full_sk (skb ),skb ,err ); } }
net/ipv6/esp6.c +1 -1
@@ -315,7 +315,7 @@ static void esp_output_done(void *data, int err) x->encap && x->encap->encap_type == TCP_ENCAP_ESPINTCP)esp_output_tail_tcp (x, skb); else - xfrm_output_resume(skb->sk, skb, err); +xfrm_output_resume (skb_to_full_sk (skb ),skb ,err ); } }
net/ipv6/xfrm6_output.c +2 -2
@@ -82,14 +82,14 @@ static int __xfrm6_output(struct net *net, struct sock *sk, struct sk_buff *skb) toobig = skb->len > mtu && !skb_is_gso (skb); -if (toobig &&xfrm6_local_dontfrag (skb->sk)) { +if (toobig &&xfrm6_local_dontfrag (sk)) {xfrm6_local_rxpmtu (skb, mtu);kfree_skb (skb);return -EMSGSIZE ; }else if (toobig &&xfrm6_noneed_fragment (skb)) { skb->ignore_df =1 ; goto skip_frag; - }else if (!skb->ignore_df && toobig && skb->sk) { + }else if (!skb->ignore_df && toobig && sk) {xfrm_local_error (skb, mtu);kfree_skb (skb);return -EMSGSIZE ;
net/xfrm/xfrm_interface_core.c +1 -1
@@ -506,7 +506,7 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)skb_dst_set (skb, dst); skb->dev = tdev; - err =dst_output (xi->net, skb->sk, skb); + err =dst_output (xi->net,skb_to_full_sk (skb), skb);if (net_xmit_eval (err) ==0 ) {dev_sw_netstats_tx_add (dev,1 , length); }else {
net/xfrm/xfrm_output.c +4 -3
@@ -796,7 +796,7 @@ static int xfrm4_tunnel_check_size(struct sk_buff *skb) !skb_gso_validate_network_len(skb, ip_skb_dst_mtu(skb->sk, skb)))) { skb->protocol =htons (ETH_P_IP ); -if (skb->sk) +if (skb->sk &&sk_fullsock (skb->sk))xfrm_local_error (skb, mtu);else icmp_send(skb, ICMP_DEST_UNREACH,
@@ -832,6 +832,7 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb) {int mtu, ret =0 ;struct dst_entry *dst =skb_dst (skb); +struct sock *sk =skb_to_full_sk (skb);if (skb->ignore_df) goto out;
@@ -846,9 +847,9 @@ static int xfrm6_tunnel_check_size(struct sk_buff *skb) skb->dev = dst->dev; skb->protocol =htons (ETH_P_IPV6 ); -if (xfrm6_local_dontfrag (skb->sk)) +if (xfrm6_local_dontfrag (sk)) ipv6_stub->xfrm6_local_rxpmtu (skb, mtu); -else if (skb->sk) +else if (sk)xfrm_local_error (skb, mtu);else icmpv6_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu);
net/xfrm/xfrm_policy.c +1 -1
@@ -2959,7 +2959,7 @@ static void xfrm_policy_queue_process(struct timer_list *t)skb_dst_drop (skb);skb_dst_set (skb, dst); -dst_output (net, skb->sk, skb); +dst_output (net,skb_to_full_sk (skb), skb); } out:
Signature · 1 line
2.34.1
Steffen Klassert
maintainerPATCH 5/5 xfrm: Don't disable preemption while looking up cache state.
In reply to Steffen KlassertFrom: Sebastian Sewior <[email protected]>
For the state cache lookup xfrm_input_state_lookup() first disables preemption, to remain on the CPU and then retrieves a per-CPU pointer. Within the preempt-disable section it also acquires netns_xfrm::xfrm_state_lock, a spinlock_t. This lock must not be acquired with explicit disabled preemption (such as by get_cpu()) because this lock becomes a sleeping lock on PREEMPT_RT.
To remain on the same CPU is just an optimisation for the CPU local lookup. The actual modification of the per-CPU variable happens with netns_xfrm::xfrm_state_lock acquired.
Remove get_cpu() and use the state_cache_input on the current CPU.
--- net/xfrm/xfrm_state.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
net/xfrm/xfrm_state.c +1 -3
@@ -1150,9 +1150,8 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark,struct xfrm_hash_state_ptrs state_ptrs;struct hlist_head *state_cache_input;struct xfrm_state *x =NULL ; -int cpu =get_cpu (); - state_cache_input =per_cpu_ptr (net->xfrm.state_cache_input, cpu); + state_cache_input =raw_cpu_ptr (net->xfrm.state_cache_input);rcu_read_lock ();hlist_for_each_entry_rcu (x, state_cache_input, state_cache_input) {
@@ -1186,7 +1185,6 @@ struct xfrm_state *xfrm_input_state_lookup(struct net *net, u32 mark, out:rcu_read_unlock (); -put_cpu ();return x; }EXPORT_SYMBOL (xfrm_input_state_lookup);
Signature · 1 line
2.34.1