From: Sasha Levin Date: Sat, 27 Jan 2024 12:47:06 +0000 (-0500) Subject: Fixes for 4.19 X-Git-Tag: v6.1.76~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83bf0f90cf31737d85540c52e6c0921e666bb80d;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 4.19 Signed-off-by: Sasha Levin --- diff --git a/queue-4.19/fjes-fix-memleaks-in-fjes_hw_setup.patch b/queue-4.19/fjes-fix-memleaks-in-fjes_hw_setup.patch new file mode 100644 index 00000000000..582baa3371f --- /dev/null +++ b/queue-4.19/fjes-fix-memleaks-in-fjes_hw_setup.patch @@ -0,0 +1,109 @@ +From b4c2642b836306ccae78e7290904cc1739a9ece2 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 23 Jan 2024 01:24:42 +0800 +Subject: fjes: fix memleaks in fjes_hw_setup + +From: Zhipeng Lu + +[ Upstream commit f6cc4b6a3ae53df425771000e9c9540cce9b7bb1 ] + +In fjes_hw_setup, it allocates several memory and delay the deallocation +to the fjes_hw_exit in fjes_probe through the following call chain: + +fjes_probe + |-> fjes_hw_init + |-> fjes_hw_setup + |-> fjes_hw_exit + +However, when fjes_hw_setup fails, fjes_hw_exit won't be called and thus +all the resources allocated in fjes_hw_setup will be leaked. In this +patch, we free those resources in fjes_hw_setup and prevents such leaks. + +Fixes: 2fcbca687702 ("fjes: platform_driver's .probe and .remove routine") +Signed-off-by: Zhipeng Lu +Reviewed-by: Simon Horman +Link: https://lore.kernel.org/r/20240122172445.3841883-1-alexious@zju.edu.cn +Signed-off-by: Jakub Kicinski +Signed-off-by: Sasha Levin +--- + drivers/net/fjes/fjes_hw.c | 37 ++++++++++++++++++++++++++++++------- + 1 file changed, 30 insertions(+), 7 deletions(-) + +diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c +index 9c652c04375b..c3fa8db69b9e 100644 +--- a/drivers/net/fjes/fjes_hw.c ++++ b/drivers/net/fjes/fjes_hw.c +@@ -235,21 +235,25 @@ static int fjes_hw_setup(struct fjes_hw *hw) + + mem_size = FJES_DEV_REQ_BUF_SIZE(hw->max_epid); + hw->hw_info.req_buf = kzalloc(mem_size, GFP_KERNEL); +- if (!(hw->hw_info.req_buf)) +- return -ENOMEM; ++ if (!(hw->hw_info.req_buf)) { ++ result = -ENOMEM; ++ goto free_ep_info; ++ } + + hw->hw_info.req_buf_size = mem_size; + + mem_size = FJES_DEV_RES_BUF_SIZE(hw->max_epid); + hw->hw_info.res_buf = kzalloc(mem_size, GFP_KERNEL); +- if (!(hw->hw_info.res_buf)) +- return -ENOMEM; ++ if (!(hw->hw_info.res_buf)) { ++ result = -ENOMEM; ++ goto free_req_buf; ++ } + + hw->hw_info.res_buf_size = mem_size; + + result = fjes_hw_alloc_shared_status_region(hw); + if (result) +- return result; ++ goto free_res_buf; + + hw->hw_info.buffer_share_bit = 0; + hw->hw_info.buffer_unshare_reserve_bit = 0; +@@ -260,11 +264,11 @@ static int fjes_hw_setup(struct fjes_hw *hw) + + result = fjes_hw_alloc_epbuf(&buf_pair->tx); + if (result) +- return result; ++ goto free_epbuf; + + result = fjes_hw_alloc_epbuf(&buf_pair->rx); + if (result) +- return result; ++ goto free_epbuf; + + spin_lock_irqsave(&hw->rx_status_lock, flags); + fjes_hw_setup_epbuf(&buf_pair->tx, mac, +@@ -287,6 +291,25 @@ static int fjes_hw_setup(struct fjes_hw *hw) + fjes_hw_init_command_registers(hw, ¶m); + + return 0; ++ ++free_epbuf: ++ for (epidx = 0; epidx < hw->max_epid ; epidx++) { ++ if (epidx == hw->my_epid) ++ continue; ++ fjes_hw_free_epbuf(&hw->ep_shm_info[epidx].tx); ++ fjes_hw_free_epbuf(&hw->ep_shm_info[epidx].rx); ++ } ++ fjes_hw_free_shared_status_region(hw); ++free_res_buf: ++ kfree(hw->hw_info.res_buf); ++ hw->hw_info.res_buf = NULL; ++free_req_buf: ++ kfree(hw->hw_info.req_buf); ++ hw->hw_info.req_buf = NULL; ++free_ep_info: ++ kfree(hw->ep_shm_info); ++ hw->ep_shm_info = NULL; ++ return result; + } + + static void fjes_hw_cleanup(struct fjes_hw *hw) +-- +2.43.0 + diff --git a/queue-4.19/llc-drop-support-for-eth_p_tr_802_2.patch b/queue-4.19/llc-drop-support-for-eth_p_tr_802_2.patch new file mode 100644 index 00000000000..8c6c20e3b2a --- /dev/null +++ b/queue-4.19/llc-drop-support-for-eth_p_tr_802_2.patch @@ -0,0 +1,130 @@ +From 3b238a774a0850fb5512040cd8f0f94f60cb7ff5 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 18 Jan 2024 17:55:15 -0800 +Subject: llc: Drop support for ETH_P_TR_802_2. + +From: Kuniyuki Iwashima + +[ Upstream commit e3f9bed9bee261e3347131764e42aeedf1ffea61 ] + +syzbot reported an uninit-value bug below. [0] + +llc supports ETH_P_802_2 (0x0004) and used to support ETH_P_TR_802_2 +(0x0011), and syzbot abused the latter to trigger the bug. + + write$tun(r0, &(0x7f0000000040)={@val={0x0, 0x11}, @val, @mpls={[], @llc={@snap={0xaa, 0x1, ')', "90e5dd"}}}}, 0x16) + +llc_conn_handler() initialises local variables {saddr,daddr}.mac +based on skb in llc_pdu_decode_sa()/llc_pdu_decode_da() and passes +them to __llc_lookup(). + +However, the initialisation is done only when skb->protocol is +htons(ETH_P_802_2), otherwise, __llc_lookup_established() and +__llc_lookup_listener() will read garbage. + +The missing initialisation existed prior to commit 211ed865108e +("net: delete all instances of special processing for token ring"). + +It removed the part to kick out the token ring stuff but forgot to +close the door allowing ETH_P_TR_802_2 packets to sneak into llc_rcv(). + +Let's remove llc_tr_packet_type and complete the deprecation. + +[0]: +BUG: KMSAN: uninit-value in __llc_lookup_established+0xe9d/0xf90 + __llc_lookup_established+0xe9d/0xf90 + __llc_lookup net/llc/llc_conn.c:611 [inline] + llc_conn_handler+0x4bd/0x1360 net/llc/llc_conn.c:791 + llc_rcv+0xfbb/0x14a0 net/llc/llc_input.c:206 + __netif_receive_skb_one_core net/core/dev.c:5527 [inline] + __netif_receive_skb+0x1a6/0x5a0 net/core/dev.c:5641 + netif_receive_skb_internal net/core/dev.c:5727 [inline] + netif_receive_skb+0x58/0x660 net/core/dev.c:5786 + tun_rx_batched+0x3ee/0x980 drivers/net/tun.c:1555 + tun_get_user+0x53af/0x66d0 drivers/net/tun.c:2002 + tun_chr_write_iter+0x3af/0x5d0 drivers/net/tun.c:2048 + call_write_iter include/linux/fs.h:2020 [inline] + new_sync_write fs/read_write.c:491 [inline] + vfs_write+0x8ef/0x1490 fs/read_write.c:584 + ksys_write+0x20f/0x4c0 fs/read_write.c:637 + __do_sys_write fs/read_write.c:649 [inline] + __se_sys_write fs/read_write.c:646 [inline] + __x64_sys_write+0x93/0xd0 fs/read_write.c:646 + do_syscall_x64 arch/x86/entry/common.c:51 [inline] + do_syscall_64+0x44/0x110 arch/x86/entry/common.c:82 + entry_SYSCALL_64_after_hwframe+0x63/0x6b + +Local variable daddr created at: + llc_conn_handler+0x53/0x1360 net/llc/llc_conn.c:783 + llc_rcv+0xfbb/0x14a0 net/llc/llc_input.c:206 + +CPU: 1 PID: 5004 Comm: syz-executor994 Not tainted 6.6.0-syzkaller-14500-g1c41041124bd #0 +Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/09/2023 + +Fixes: 211ed865108e ("net: delete all instances of special processing for token ring") +Reported-by: syzbot+b5ad66046b913bc04c6f@syzkaller.appspotmail.com +Closes: https://syzkaller.appspot.com/bug?extid=b5ad66046b913bc04c6f +Signed-off-by: Kuniyuki Iwashima +Reviewed-by: Eric Dumazet +Link: https://lore.kernel.org/r/20240119015515.61898-1-kuniyu@amazon.com +Signed-off-by: Jakub Kicinski +Signed-off-by: Sasha Levin +--- + include/net/llc_pdu.h | 6 ++---- + net/llc/llc_core.c | 7 ------- + 2 files changed, 2 insertions(+), 11 deletions(-) + +diff --git a/include/net/llc_pdu.h b/include/net/llc_pdu.h +index 49aa79c7b278..581cd37aa98b 100644 +--- a/include/net/llc_pdu.h ++++ b/include/net/llc_pdu.h +@@ -262,8 +262,7 @@ static inline void llc_pdu_header_init(struct sk_buff *skb, u8 type, + */ + static inline void llc_pdu_decode_sa(struct sk_buff *skb, u8 *sa) + { +- if (skb->protocol == htons(ETH_P_802_2)) +- memcpy(sa, eth_hdr(skb)->h_source, ETH_ALEN); ++ memcpy(sa, eth_hdr(skb)->h_source, ETH_ALEN); + } + + /** +@@ -275,8 +274,7 @@ static inline void llc_pdu_decode_sa(struct sk_buff *skb, u8 *sa) + */ + static inline void llc_pdu_decode_da(struct sk_buff *skb, u8 *da) + { +- if (skb->protocol == htons(ETH_P_802_2)) +- memcpy(da, eth_hdr(skb)->h_dest, ETH_ALEN); ++ memcpy(da, eth_hdr(skb)->h_dest, ETH_ALEN); + } + + /** +diff --git a/net/llc/llc_core.c b/net/llc/llc_core.c +index 64d4bef04e73..4900a27b5176 100644 +--- a/net/llc/llc_core.c ++++ b/net/llc/llc_core.c +@@ -135,22 +135,15 @@ static struct packet_type llc_packet_type __read_mostly = { + .func = llc_rcv, + }; + +-static struct packet_type llc_tr_packet_type __read_mostly = { +- .type = cpu_to_be16(ETH_P_TR_802_2), +- .func = llc_rcv, +-}; +- + static int __init llc_init(void) + { + dev_add_pack(&llc_packet_type); +- dev_add_pack(&llc_tr_packet_type); + return 0; + } + + static void __exit llc_exit(void) + { + dev_remove_pack(&llc_packet_type); +- dev_remove_pack(&llc_tr_packet_type); + } + + module_init(llc_init); +-- +2.43.0 + diff --git a/queue-4.19/llc-make-llc_ui_sendmsg-more-robust-against-bonding-.patch b/queue-4.19/llc-make-llc_ui_sendmsg-more-robust-against-bonding-.patch new file mode 100644 index 00000000000..0458e37f6e8 --- /dev/null +++ b/queue-4.19/llc-make-llc_ui_sendmsg-more-robust-against-bonding-.patch @@ -0,0 +1,154 @@ +From 245a281da970e84defddb5767feb160379ae0fb7 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 18 Jan 2024 18:36:25 +0000 +Subject: llc: make llc_ui_sendmsg() more robust against bonding changes + +From: Eric Dumazet + +[ Upstream commit dad555c816a50c6a6a8a86be1f9177673918c647 ] + +syzbot was able to trick llc_ui_sendmsg(), allocating an skb with no +headroom, but subsequently trying to push 14 bytes of Ethernet header [1] + +Like some others, llc_ui_sendmsg() releases the socket lock before +calling sock_alloc_send_skb(). +Then it acquires it again, but does not redo all the sanity checks +that were performed. + +This fix: + +- Uses LL_RESERVED_SPACE() to reserve space. +- Check all conditions again after socket lock is held again. +- Do not account Ethernet header for mtu limitation. + +[1] + +skbuff: skb_under_panic: text:ffff800088baa334 len:1514 put:14 head:ffff0000c9c37000 data:ffff0000c9c36ff2 tail:0x5dc end:0x6c0 dev:bond0 + + kernel BUG at net/core/skbuff.c:193 ! +Internal error: Oops - BUG: 00000000f2000800 [#1] PREEMPT SMP +Modules linked in: +CPU: 0 PID: 6875 Comm: syz-executor.0 Not tainted 6.7.0-rc8-syzkaller-00101-g0802e17d9aca-dirty #0 +Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/17/2023 +pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) + pc : skb_panic net/core/skbuff.c:189 [inline] + pc : skb_under_panic+0x13c/0x140 net/core/skbuff.c:203 + lr : skb_panic net/core/skbuff.c:189 [inline] + lr : skb_under_panic+0x13c/0x140 net/core/skbuff.c:203 +sp : ffff800096f97000 +x29: ffff800096f97010 x28: ffff80008cc8d668 x27: dfff800000000000 +x26: ffff0000cb970c90 x25: 00000000000005dc x24: ffff0000c9c36ff2 +x23: ffff0000c9c37000 x22: 00000000000005ea x21: 00000000000006c0 +x20: 000000000000000e x19: ffff800088baa334 x18: 1fffe000368261ce +x17: ffff80008e4ed000 x16: ffff80008a8310f8 x15: 0000000000000001 +x14: 1ffff00012df2d58 x13: 0000000000000000 x12: 0000000000000000 +x11: 0000000000000001 x10: 0000000000ff0100 x9 : e28a51f1087e8400 +x8 : e28a51f1087e8400 x7 : ffff80008028f8d0 x6 : 0000000000000000 +x5 : 0000000000000001 x4 : 0000000000000001 x3 : ffff800082b78714 +x2 : 0000000000000001 x1 : 0000000100000000 x0 : 0000000000000089 +Call trace: + skb_panic net/core/skbuff.c:189 [inline] + skb_under_panic+0x13c/0x140 net/core/skbuff.c:203 + skb_push+0xf0/0x108 net/core/skbuff.c:2451 + eth_header+0x44/0x1f8 net/ethernet/eth.c:83 + dev_hard_header include/linux/netdevice.h:3188 [inline] + llc_mac_hdr_init+0x110/0x17c net/llc/llc_output.c:33 + llc_sap_action_send_xid_c+0x170/0x344 net/llc/llc_s_ac.c:85 + llc_exec_sap_trans_actions net/llc/llc_sap.c:153 [inline] + llc_sap_next_state net/llc/llc_sap.c:182 [inline] + llc_sap_state_process+0x1ec/0x774 net/llc/llc_sap.c:209 + llc_build_and_send_xid_pkt+0x12c/0x1c0 net/llc/llc_sap.c:270 + llc_ui_sendmsg+0x7bc/0xb1c net/llc/af_llc.c:997 + sock_sendmsg_nosec net/socket.c:730 [inline] + __sock_sendmsg net/socket.c:745 [inline] + sock_sendmsg+0x194/0x274 net/socket.c:767 + splice_to_socket+0x7cc/0xd58 fs/splice.c:881 + do_splice_from fs/splice.c:933 [inline] + direct_splice_actor+0xe4/0x1c0 fs/splice.c:1142 + splice_direct_to_actor+0x2a0/0x7e4 fs/splice.c:1088 + do_splice_direct+0x20c/0x348 fs/splice.c:1194 + do_sendfile+0x4bc/0xc70 fs/read_write.c:1254 + __do_sys_sendfile64 fs/read_write.c:1322 [inline] + __se_sys_sendfile64 fs/read_write.c:1308 [inline] + __arm64_sys_sendfile64+0x160/0x3b4 fs/read_write.c:1308 + __invoke_syscall arch/arm64/kernel/syscall.c:37 [inline] + invoke_syscall+0x98/0x2b8 arch/arm64/kernel/syscall.c:51 + el0_svc_common+0x130/0x23c arch/arm64/kernel/syscall.c:136 + do_el0_svc+0x48/0x58 arch/arm64/kernel/syscall.c:155 + el0_svc+0x54/0x158 arch/arm64/kernel/entry-common.c:678 + el0t_64_sync_handler+0x84/0xfc arch/arm64/kernel/entry-common.c:696 + el0t_64_sync+0x190/0x194 arch/arm64/kernel/entry.S:595 +Code: aa1803e6 aa1903e7 a90023f5 94792f6a (d4210000) + +Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") +Reported-and-tested-by: syzbot+2a7024e9502df538e8ef@syzkaller.appspotmail.com +Signed-off-by: Eric Dumazet +Reviewed-by: Kuniyuki Iwashima +Link: https://lore.kernel.org/r/20240118183625.4007013-1-edumazet@google.com +Signed-off-by: Jakub Kicinski +Signed-off-by: Sasha Levin +--- + net/llc/af_llc.c | 24 ++++++++++++++++-------- + 1 file changed, 16 insertions(+), 8 deletions(-) + +diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c +index 5cba9199c3c9..a5c104ea477c 100644 +--- a/net/llc/af_llc.c ++++ b/net/llc/af_llc.c +@@ -926,14 +926,15 @@ static int llc_ui_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, + */ + static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) + { ++ DECLARE_SOCKADDR(struct sockaddr_llc *, addr, msg->msg_name); + struct sock *sk = sock->sk; + struct llc_sock *llc = llc_sk(sk); +- DECLARE_SOCKADDR(struct sockaddr_llc *, addr, msg->msg_name); + int flags = msg->msg_flags; + int noblock = flags & MSG_DONTWAIT; ++ int rc = -EINVAL, copied = 0, hdrlen, hh_len; + struct sk_buff *skb = NULL; ++ struct net_device *dev; + size_t size = 0; +- int rc = -EINVAL, copied = 0, hdrlen; + + dprintk("%s: sending from %02X to %02X\n", __func__, + llc->laddr.lsap, llc->daddr.lsap); +@@ -953,22 +954,29 @@ static int llc_ui_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) + if (rc) + goto out; + } +- hdrlen = llc->dev->hard_header_len + llc_ui_header_len(sk, addr); ++ dev = llc->dev; ++ hh_len = LL_RESERVED_SPACE(dev); ++ hdrlen = llc_ui_header_len(sk, addr); + size = hdrlen + len; +- if (size > llc->dev->mtu) +- size = llc->dev->mtu; ++ size = min_t(size_t, size, READ_ONCE(dev->mtu)); + copied = size - hdrlen; + rc = -EINVAL; + if (copied < 0) + goto out; + release_sock(sk); +- skb = sock_alloc_send_skb(sk, size, noblock, &rc); ++ skb = sock_alloc_send_skb(sk, hh_len + size, noblock, &rc); + lock_sock(sk); + if (!skb) + goto out; +- skb->dev = llc->dev; ++ if (sock_flag(sk, SOCK_ZAPPED) || ++ llc->dev != dev || ++ hdrlen != llc_ui_header_len(sk, addr) || ++ hh_len != LL_RESERVED_SPACE(dev) || ++ size > READ_ONCE(dev->mtu)) ++ goto out; ++ skb->dev = dev; + skb->protocol = llc_proto_type(addr->sllc_arphrd); +- skb_reserve(skb, hdrlen); ++ skb_reserve(skb, hh_len + hdrlen); + rc = memcpy_from_msg(skb_put(skb, copied), msg, copied); + if (rc) + goto out; +-- +2.43.0 + diff --git a/queue-4.19/net-fec-fix-the-unhandled-context-fault-from-smmu.patch b/queue-4.19/net-fec-fix-the-unhandled-context-fault-from-smmu.patch new file mode 100644 index 00000000000..4225e7d8bb5 --- /dev/null +++ b/queue-4.19/net-fec-fix-the-unhandled-context-fault-from-smmu.patch @@ -0,0 +1,58 @@ +From 9daca7229e5878bf2806941cc9a5067bdecccca0 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 23 Jan 2024 10:51:41 -0600 +Subject: net: fec: fix the unhandled context fault from smmu + +From: Shenwei Wang + +[ Upstream commit 5e344807735023cd3a67c37a1852b849caa42620 ] + +When repeatedly changing the interface link speed using the command below: + +ethtool -s eth0 speed 100 duplex full +ethtool -s eth0 speed 1000 duplex full + +The following errors may sometimes be reported by the ARM SMMU driver: + +[ 5395.035364] fec 5b040000.ethernet eth0: Link is Down +[ 5395.039255] arm-smmu 51400000.iommu: Unhandled context fault: +fsr=0x402, iova=0x00000000, fsynr=0x100001, cbfrsynra=0x852, cb=2 +[ 5398.108460] fec 5b040000.ethernet eth0: Link is Up - 100Mbps/Full - +flow control off + +It is identified that the FEC driver does not properly stop the TX queue +during the link speed transitions, and this results in the invalid virtual +I/O address translations from the SMMU and causes the context faults. + +Fixes: dbc64a8ea231 ("net: fec: move calls to quiesce/resume packet processing out of fec_restart()") +Signed-off-by: Shenwei Wang +Link: https://lore.kernel.org/r/20240123165141.2008104-1-shenwei.wang@nxp.com +Signed-off-by: Paolo Abeni +Signed-off-by: Sasha Levin +--- + drivers/net/ethernet/freescale/fec_main.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c +index e4162c2271e3..9c4c892bfc83 100644 +--- a/drivers/net/ethernet/freescale/fec_main.c ++++ b/drivers/net/ethernet/freescale/fec_main.c +@@ -1798,6 +1798,7 @@ static void fec_enet_adjust_link(struct net_device *ndev) + + /* if any of the above changed restart the FEC */ + if (status_change) { ++ netif_stop_queue(ndev); + napi_disable(&fep->napi); + netif_tx_lock_bh(ndev); + fec_restart(ndev); +@@ -1807,6 +1808,7 @@ static void fec_enet_adjust_link(struct net_device *ndev) + } + } else { + if (fep->link) { ++ netif_stop_queue(ndev); + napi_disable(&fep->napi); + netif_tx_lock_bh(ndev); + fec_stop(ndev); +-- +2.43.0 + diff --git a/queue-4.19/net-mlx5-use-kfree-ft-g-in-arfs_create_groups.patch b/queue-4.19/net-mlx5-use-kfree-ft-g-in-arfs_create_groups.patch new file mode 100644 index 00000000000..9862f55b745 --- /dev/null +++ b/queue-4.19/net-mlx5-use-kfree-ft-g-in-arfs_create_groups.patch @@ -0,0 +1,36 @@ +From db8abbe6cd7f81c3443dbd93153e9860e0b43659 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 5 Jun 2020 22:22:35 +0300 +Subject: net/mlx5: Use kfree(ft->g) in arfs_create_groups() + +From: Denis Efremov + +[ Upstream commit 360000b26e37a75b3000bf0585b263809d96ffd3 ] + +Use kfree() instead of kvfree() on ft->g in arfs_create_groups() because +the memory is allocated with kcalloc(). + +Signed-off-by: Denis Efremov +Signed-off-by: Saeed Mahameed +Stable-dep-of: 3c6d5189246f ("net/mlx5e: fix a double-free in arfs_create_groups") +Signed-off-by: Sasha Levin +--- + drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c +index a4be04debe67..13496d93e7bc 100644 +--- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c ++++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c +@@ -229,7 +229,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, + sizeof(*ft->g), GFP_KERNEL); + in = kvzalloc(inlen, GFP_KERNEL); + if (!in || !ft->g) { +- kvfree(ft->g); ++ kfree(ft->g); + kvfree(in); + return -ENOMEM; + } +-- +2.43.0 + diff --git a/queue-4.19/net-mlx5e-fix-a-double-free-in-arfs_create_groups.patch b/queue-4.19/net-mlx5e-fix-a-double-free-in-arfs_create_groups.patch new file mode 100644 index 00000000000..6760d022e32 --- /dev/null +++ b/queue-4.19/net-mlx5e-fix-a-double-free-in-arfs_create_groups.patch @@ -0,0 +1,100 @@ +From 45a1badfc16c2708242b467d482a1d8a6f5a50b5 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 17 Jan 2024 15:17:36 +0800 +Subject: net/mlx5e: fix a double-free in arfs_create_groups + +From: Zhipeng Lu + +[ Upstream commit 3c6d5189246f590e4e1f167991558bdb72a4738b ] + +When `in` allocated by kvzalloc fails, arfs_create_groups will free +ft->g and return an error. However, arfs_create_table, the only caller of +arfs_create_groups, will hold this error and call to +mlx5e_destroy_flow_table, in which the ft->g will be freed again. + +Fixes: 1cabe6b0965e ("net/mlx5e: Create aRFS flow tables") +Signed-off-by: Zhipeng Lu +Reviewed-by: Simon Horman +Signed-off-by: Saeed Mahameed +Signed-off-by: Sasha Levin +--- + .../net/ethernet/mellanox/mlx5/core/en_arfs.c | 26 +++++++++++-------- + 1 file changed, 15 insertions(+), 11 deletions(-) + +diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c +index 13496d93e7bc..31da51b74c16 100644 +--- a/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c ++++ b/drivers/net/ethernet/mellanox/mlx5/core/en_arfs.c +@@ -227,11 +227,13 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, + + ft->g = kcalloc(MLX5E_ARFS_NUM_GROUPS, + sizeof(*ft->g), GFP_KERNEL); +- in = kvzalloc(inlen, GFP_KERNEL); +- if (!in || !ft->g) { +- kfree(ft->g); +- kvfree(in); ++ if (!ft->g) + return -ENOMEM; ++ ++ in = kvzalloc(inlen, GFP_KERNEL); ++ if (!in) { ++ err = -ENOMEM; ++ goto err_free_g; + } + + mc = MLX5_ADDR_OF(create_flow_group_in, in, match_criteria); +@@ -251,7 +253,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, + break; + default: + err = -EINVAL; +- goto out; ++ goto err_free_in; + } + + switch (type) { +@@ -273,7 +275,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, + break; + default: + err = -EINVAL; +- goto out; ++ goto err_free_in; + } + + MLX5_SET_CFG(in, match_criteria_enable, MLX5_MATCH_OUTER_HEADERS); +@@ -282,7 +284,7 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, + MLX5_SET_CFG(in, end_flow_index, ix - 1); + ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in); + if (IS_ERR(ft->g[ft->num_groups])) +- goto err; ++ goto err_clean_group; + ft->num_groups++; + + memset(in, 0, inlen); +@@ -291,18 +293,20 @@ static int arfs_create_groups(struct mlx5e_flow_table *ft, + MLX5_SET_CFG(in, end_flow_index, ix - 1); + ft->g[ft->num_groups] = mlx5_create_flow_group(ft->t, in); + if (IS_ERR(ft->g[ft->num_groups])) +- goto err; ++ goto err_clean_group; + ft->num_groups++; + + kvfree(in); + return 0; + +-err: ++err_clean_group: + err = PTR_ERR(ft->g[ft->num_groups]); + ft->g[ft->num_groups] = NULL; +-out: ++err_free_in: + kvfree(in); +- ++err_free_g: ++ kfree(ft->g); ++ ft->g = NULL; + return err; + } + +-- +2.43.0 + diff --git a/queue-4.19/net-rds-fix-ubsan-array-index-out-of-bounds-in-rds_c.patch b/queue-4.19/net-rds-fix-ubsan-array-index-out-of-bounds-in-rds_c.patch new file mode 100644 index 00000000000..ca2a27d9078 --- /dev/null +++ b/queue-4.19/net-rds-fix-ubsan-array-index-out-of-bounds-in-rds_c.patch @@ -0,0 +1,71 @@ +From 1ce7852534968cf7a8bdb2b39197c286ea1f2706 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 19 Jan 2024 17:48:39 -0800 +Subject: net/rds: Fix UBSAN: array-index-out-of-bounds in rds_cmsg_recv + +From: Sharath Srinivasan + +[ Upstream commit 13e788deb7348cc88df34bed736c3b3b9927ea52 ] + +Syzcaller UBSAN crash occurs in rds_cmsg_recv(), +which reads inc->i_rx_lat_trace[j + 1] with index 4 (3 + 1), +but with array size of 4 (RDS_RX_MAX_TRACES). +Here 'j' is assigned from rs->rs_rx_trace[i] and in-turn from +trace.rx_trace_pos[i] in rds_recv_track_latency(), +with both arrays sized 3 (RDS_MSG_RX_DGRAM_TRACE_MAX). So fix the +off-by-one bounds check in rds_recv_track_latency() to prevent +a potential crash in rds_cmsg_recv(). + +Found by syzcaller: +================================================================= +UBSAN: array-index-out-of-bounds in net/rds/recv.c:585:39 +index 4 is out of range for type 'u64 [4]' +CPU: 1 PID: 8058 Comm: syz-executor228 Not tainted 6.6.0-gd2f51b3516da #1 +Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), +BIOS 1.15.0-1 04/01/2014 +Call Trace: + + __dump_stack lib/dump_stack.c:88 [inline] + dump_stack_lvl+0x136/0x150 lib/dump_stack.c:106 + ubsan_epilogue lib/ubsan.c:217 [inline] + __ubsan_handle_out_of_bounds+0xd5/0x130 lib/ubsan.c:348 + rds_cmsg_recv+0x60d/0x700 net/rds/recv.c:585 + rds_recvmsg+0x3fb/0x1610 net/rds/recv.c:716 + sock_recvmsg_nosec net/socket.c:1044 [inline] + sock_recvmsg+0xe2/0x160 net/socket.c:1066 + __sys_recvfrom+0x1b6/0x2f0 net/socket.c:2246 + __do_sys_recvfrom net/socket.c:2264 [inline] + __se_sys_recvfrom net/socket.c:2260 [inline] + __x64_sys_recvfrom+0xe0/0x1b0 net/socket.c:2260 + do_syscall_x64 arch/x86/entry/common.c:51 [inline] + do_syscall_64+0x40/0x110 arch/x86/entry/common.c:82 + entry_SYSCALL_64_after_hwframe+0x63/0x6b +================================================================== + +Fixes: 3289025aedc0 ("RDS: add receive message trace used by application") +Reported-by: Chenyuan Yang +Closes: https://lore.kernel.org/linux-rdma/CALGdzuoVdq-wtQ4Az9iottBqC5cv9ZhcE5q8N7LfYFvkRsOVcw@mail.gmail.com/ +Signed-off-by: Sharath Srinivasan +Reviewed-by: Simon Horman +Signed-off-by: David S. Miller +Signed-off-by: Sasha Levin +--- + net/rds/af_rds.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/net/rds/af_rds.c b/net/rds/af_rds.c +index cd7e01ea8144..5eb71d276706 100644 +--- a/net/rds/af_rds.c ++++ b/net/rds/af_rds.c +@@ -385,7 +385,7 @@ static int rds_recv_track_latency(struct rds_sock *rs, char __user *optval, + + rs->rs_rx_traces = trace.rx_traces; + for (i = 0; i < rs->rs_rx_traces; i++) { +- if (trace.rx_trace_pos[i] > RDS_MSG_RX_DGRAM_TRACE_MAX) { ++ if (trace.rx_trace_pos[i] >= RDS_MSG_RX_DGRAM_TRACE_MAX) { + rs->rs_rx_traces = 0; + return -EFAULT; + } +-- +2.43.0 + diff --git a/queue-4.19/net-smc-fix-illegal-rmb_desc-access-in-smc-d-connect.patch b/queue-4.19/net-smc-fix-illegal-rmb_desc-access-in-smc-d-connect.patch new file mode 100644 index 00000000000..fe7f998d533 --- /dev/null +++ b/queue-4.19/net-smc-fix-illegal-rmb_desc-access-in-smc-d-connect.patch @@ -0,0 +1,87 @@ +From 9bb0230855d5ba6af84b962590c08f6fddb0ef35 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 18 Jan 2024 12:32:10 +0800 +Subject: net/smc: fix illegal rmb_desc access in SMC-D connection dump + +From: Wen Gu + +[ Upstream commit dbc153fd3c142909e564bb256da087e13fbf239c ] + +A crash was found when dumping SMC-D connections. It can be reproduced +by following steps: + +- run nginx/wrk test: + smc_run nginx + smc_run wrk -t 16 -c 1000 -d -H 'Connection: Close' + +- continuously dump SMC-D connections in parallel: + watch -n 1 'smcss -D' + + BUG: kernel NULL pointer dereference, address: 0000000000000030 + CPU: 2 PID: 7204 Comm: smcss Kdump: loaded Tainted: G E 6.7.0+ #55 + RIP: 0010:__smc_diag_dump.constprop.0+0x5e5/0x620 [smc_diag] + Call Trace: + + ? __die+0x24/0x70 + ? page_fault_oops+0x66/0x150 + ? exc_page_fault+0x69/0x140 + ? asm_exc_page_fault+0x26/0x30 + ? __smc_diag_dump.constprop.0+0x5e5/0x620 [smc_diag] + ? __kmalloc_node_track_caller+0x35d/0x430 + ? __alloc_skb+0x77/0x170 + smc_diag_dump_proto+0xd0/0xf0 [smc_diag] + smc_diag_dump+0x26/0x60 [smc_diag] + netlink_dump+0x19f/0x320 + __netlink_dump_start+0x1dc/0x300 + smc_diag_handler_dump+0x6a/0x80 [smc_diag] + ? __pfx_smc_diag_dump+0x10/0x10 [smc_diag] + sock_diag_rcv_msg+0x121/0x140 + ? __pfx_sock_diag_rcv_msg+0x10/0x10 + netlink_rcv_skb+0x5a/0x110 + sock_diag_rcv+0x28/0x40 + netlink_unicast+0x22a/0x330 + netlink_sendmsg+0x1f8/0x420 + __sock_sendmsg+0xb0/0xc0 + ____sys_sendmsg+0x24e/0x300 + ? copy_msghdr_from_user+0x62/0x80 + ___sys_sendmsg+0x7c/0xd0 + ? __do_fault+0x34/0x160 + ? do_read_fault+0x5f/0x100 + ? do_fault+0xb0/0x110 + ? __handle_mm_fault+0x2b0/0x6c0 + __sys_sendmsg+0x4d/0x80 + do_syscall_64+0x69/0x180 + entry_SYSCALL_64_after_hwframe+0x6e/0x76 + +It is possible that the connection is in process of being established +when we dump it. Assumed that the connection has been registered in a +link group by smc_conn_create() but the rmb_desc has not yet been +initialized by smc_buf_create(), thus causing the illegal access to +conn->rmb_desc. So fix it by checking before dump. + +Fixes: 4b1b7d3b30a6 ("net/smc: add SMC-D diag support") +Signed-off-by: Wen Gu +Reviewed-by: Dust Li +Reviewed-by: Wenjia Zhang +Signed-off-by: David S. Miller +Signed-off-by: Sasha Levin +--- + net/smc/smc_diag.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/net/smc/smc_diag.c b/net/smc/smc_diag.c +index 6c4a7a5938b7..3ab14678afff 100644 +--- a/net/smc/smc_diag.c ++++ b/net/smc/smc_diag.c +@@ -167,7 +167,7 @@ static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, + } + if (smc->conn.lgr && smc->conn.lgr->is_smcd && + (req->diag_ext & (1 << (SMC_DIAG_DMBINFO - 1))) && +- !list_empty(&smc->conn.lgr->list)) { ++ !list_empty(&smc->conn.lgr->list) && smc->conn.rmb_desc) { + struct smc_connection *conn = &smc->conn; + struct smcd_diag_dmbinfo dinfo; + +-- +2.43.0 + diff --git a/queue-4.19/netfilter-nf_tables-restrict-anonymous-set-and-map-n.patch b/queue-4.19/netfilter-nf_tables-restrict-anonymous-set-and-map-n.patch new file mode 100644 index 00000000000..69cc53cc4aa --- /dev/null +++ b/queue-4.19/netfilter-nf_tables-restrict-anonymous-set-and-map-n.patch @@ -0,0 +1,60 @@ +From 74225df00011f5b0f4fe61bafaf09f18ac770df4 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 19 Jan 2024 13:34:32 +0100 +Subject: netfilter: nf_tables: restrict anonymous set and map names to 16 + bytes + +From: Florian Westphal + +[ Upstream commit b462579b2b86a8f5230543cadd3a4836be27baf7 ] + +nftables has two types of sets/maps, one where userspace defines the +name, and anonymous sets/maps, where userspace defines a template name. + +For the latter, kernel requires presence of exactly one "%d". +nftables uses "__set%d" and "__map%d" for this. The kernel will +expand the format specifier and replaces it with the smallest unused +number. + +As-is, userspace could define a template name that allows to move +the set name past the 256 bytes upperlimit (post-expansion). + +I don't see how this could be a problem, but I would prefer if userspace +cannot do this, so add a limit of 16 bytes for the '%d' template name. + +16 bytes is the old total upper limit for set names that existed when +nf_tables was merged initially. + +Fixes: 387454901bd6 ("netfilter: nf_tables: Allow set names of up to 255 chars") +Signed-off-by: Florian Westphal +Signed-off-by: Pablo Neira Ayuso +Signed-off-by: Sasha Levin +--- + net/netfilter/nf_tables_api.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c +index e0c224dea316..4465b832305f 100644 +--- a/net/netfilter/nf_tables_api.c ++++ b/net/netfilter/nf_tables_api.c +@@ -26,6 +26,7 @@ + #include + + #define NFT_MODULE_AUTOLOAD_LIMIT (MODULE_NAME_LEN - sizeof("nft-expr-255-")) ++#define NFT_SET_MAX_ANONLEN 16 + + unsigned int nf_tables_net_id __read_mostly; + +@@ -3184,6 +3185,9 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, + if (p[1] != 'd' || strchr(p + 2, '%')) + return -EINVAL; + ++ if (strnlen(name, NFT_SET_MAX_ANONLEN) >= NFT_SET_MAX_ANONLEN) ++ return -EINVAL; ++ + inuse = (unsigned long *)get_zeroed_page(GFP_KERNEL); + if (inuse == NULL) + return -ENOMEM; +-- +2.43.0 + diff --git a/queue-4.19/netlink-fix-potential-sleeping-issue-in-mqueue_flush.patch b/queue-4.19/netlink-fix-potential-sleeping-issue-in-mqueue_flush.patch new file mode 100644 index 00000000000..0fecf5d9bdf --- /dev/null +++ b/queue-4.19/netlink-fix-potential-sleeping-issue-in-mqueue_flush.patch @@ -0,0 +1,76 @@ +From d6c4e112acf9f93cf4568690b351209d0cc55c85 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 22 Jan 2024 09:18:07 +0800 +Subject: netlink: fix potential sleeping issue in mqueue_flush_file + +From: Zhengchao Shao + +[ Upstream commit 234ec0b6034b16869d45128b8cd2dc6ffe596f04 ] + +I analyze the potential sleeping issue of the following processes: +Thread A Thread B +... netlink_create //ref = 1 +do_mq_notify ... + sock = netlink_getsockbyfilp ... //ref = 2 + info->notify_sock = sock; ... +... netlink_sendmsg +... skb = netlink_alloc_large_skb //skb->head is vmalloced +... netlink_unicast +... sk = netlink_getsockbyportid //ref = 3 +... netlink_sendskb +... __netlink_sendskb +... skb_queue_tail //put skb to sk_receive_queue +... sock_put //ref = 2 +... ... +... netlink_release +... deferred_put_nlk_sk //ref = 1 +mqueue_flush_file + spin_lock + remove_notification + netlink_sendskb + sock_put //ref = 0 + sk_free + ... + __sk_destruct + netlink_sock_destruct + skb_queue_purge //get skb from sk_receive_queue + ... + __skb_queue_purge_reason + kfree_skb_reason + __kfree_skb + ... + skb_release_all + skb_release_head_state + netlink_skb_destructor + vfree(skb->head) //sleeping while holding spinlock + +In netlink_sendmsg, if the memory pointed to by skb->head is allocated by +vmalloc, and is put to sk_receive_queue queue, also the skb is not freed. +When the mqueue executes flush, the sleeping bug will occur. Use +vfree_atomic instead of vfree in netlink_skb_destructor to solve the issue. + +Fixes: c05cdb1b864f ("netlink: allow large data transfers from user-space") +Signed-off-by: Zhengchao Shao +Link: https://lore.kernel.org/r/20240122011807.2110357-1-shaozhengchao@huawei.com +Signed-off-by: Paolo Abeni +Signed-off-by: Sasha Levin +--- + net/netlink/af_netlink.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c +index e91489b3274c..72936d154c96 100644 +--- a/net/netlink/af_netlink.c ++++ b/net/netlink/af_netlink.c +@@ -374,7 +374,7 @@ static void netlink_skb_destructor(struct sk_buff *skb) + if (is_vmalloc_addr(skb->head)) { + if (!skb->cloned || + !atomic_dec_return(&(skb_shinfo(skb)->dataref))) +- vfree(skb->head); ++ vfree_atomic(skb->head); + + skb->head = NULL; + } +-- +2.43.0 + diff --git a/queue-4.19/series b/queue-4.19/series index b49ba89bd5e..45643eb211b 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -20,3 +20,16 @@ x86-cpu-amd-fix-disabling-xsaves-on-amd-family-0x17-due-to-erratum.patch driver-core-annotate-dev_err_probe-with-__must_check.patch driver-code-print-symbolic-error-code.patch drivers-core-fix-kernel-doc-markup-for-dev_err_probe.patch +net-smc-fix-illegal-rmb_desc-access-in-smc-d-connect.patch +vlan-skip-nested-type-that-is-not-ifla_vlan_qos_mapp.patch +llc-make-llc_ui_sendmsg-more-robust-against-bonding-.patch +llc-drop-support-for-eth_p_tr_802_2.patch +net-rds-fix-ubsan-array-index-out-of-bounds-in-rds_c.patch +tracing-ensure-visibility-when-inserting-an-element-.patch +tcp-add-memory-barrier-to-tcp_push.patch +netlink-fix-potential-sleeping-issue-in-mqueue_flush.patch +net-mlx5-use-kfree-ft-g-in-arfs_create_groups.patch +net-mlx5e-fix-a-double-free-in-arfs_create_groups.patch +netfilter-nf_tables-restrict-anonymous-set-and-map-n.patch +fjes-fix-memleaks-in-fjes_hw_setup.patch +net-fec-fix-the-unhandled-context-fault-from-smmu.patch diff --git a/queue-4.19/tcp-add-memory-barrier-to-tcp_push.patch b/queue-4.19/tcp-add-memory-barrier-to-tcp_push.patch new file mode 100644 index 00000000000..7acfecfca8c --- /dev/null +++ b/queue-4.19/tcp-add-memory-barrier-to-tcp_push.patch @@ -0,0 +1,101 @@ +From e98887de4437c67a42fd02ed840b27a00bd78d36 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 19 Jan 2024 11:01:33 -0800 +Subject: tcp: Add memory barrier to tcp_push() + +From: Salvatore Dipietro + +[ Upstream commit 7267e8dcad6b2f9fce05a6a06335d7040acbc2b6 ] + +On CPUs with weak memory models, reads and updates performed by tcp_push +to the sk variables can get reordered leaving the socket throttled when +it should not. The tasklet running tcp_wfree() may also not observe the +memory updates in time and will skip flushing any packets throttled by +tcp_push(), delaying the sending. This can pathologically cause 40ms +extra latency due to bad interactions with delayed acks. + +Adding a memory barrier in tcp_push removes the bug, similarly to the +previous commit bf06200e732d ("tcp: tsq: fix nonagle handling"). +smp_mb__after_atomic() is used to not incur in unnecessary overhead +on x86 since not affected. + +Patch has been tested using an AWS c7g.2xlarge instance with Ubuntu +22.04 and Apache Tomcat 9.0.83 running the basic servlet below: + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class HelloWorldServlet extends HttpServlet { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=utf-8"); + OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream(),"UTF-8"); + String s = "a".repeat(3096); + osw.write(s,0,s.length()); + osw.flush(); + } +} + +Load was applied using wrk2 (https://github.com/kinvolk/wrk2) from an AWS +c6i.8xlarge instance. Before the patch an additional 40ms latency from P99.99+ +values is observed while, with the patch, the extra latency disappears. + +No patch and tcp_autocorking=1 +./wrk -t32 -c128 -d40s --latency -R10000 http://172.31.60.173:8080/hello/hello + ... + 50.000% 0.91ms + 75.000% 1.13ms + 90.000% 1.46ms + 99.000% 1.74ms + 99.900% 1.89ms + 99.990% 41.95ms <<< 40+ ms extra latency + 99.999% 48.32ms +100.000% 48.96ms + +With patch and tcp_autocorking=1 +./wrk -t32 -c128 -d40s --latency -R10000 http://172.31.60.173:8080/hello/hello + ... + 50.000% 0.90ms + 75.000% 1.13ms + 90.000% 1.45ms + 99.000% 1.72ms + 99.900% 1.83ms + 99.990% 2.11ms <<< no 40+ ms extra latency + 99.999% 2.53ms +100.000% 2.62ms + +Patch has been also tested on x86 (m7i.2xlarge instance) which it is not +affected by this issue and the patch doesn't introduce any additional +delay. + +Fixes: 7aa5470c2c09 ("tcp: tsq: move tsq_flags close to sk_wmem_alloc") +Signed-off-by: Salvatore Dipietro +Reviewed-by: Eric Dumazet +Link: https://lore.kernel.org/r/20240119190133.43698-1-dipiets@amazon.com +Signed-off-by: Paolo Abeni +Signed-off-by: Sasha Levin +--- + net/ipv4/tcp.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c +index 00648a478c6a..712186336997 100644 +--- a/net/ipv4/tcp.c ++++ b/net/ipv4/tcp.c +@@ -733,6 +733,7 @@ static void tcp_push(struct sock *sk, int flags, int mss_now, + if (!test_bit(TSQ_THROTTLED, &sk->sk_tsq_flags)) { + NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAUTOCORKING); + set_bit(TSQ_THROTTLED, &sk->sk_tsq_flags); ++ smp_mb__after_atomic(); + } + /* It is possible TX completion already happened + * before we set TSQ_THROTTLED. +-- +2.43.0 + diff --git a/queue-4.19/tracing-ensure-visibility-when-inserting-an-element-.patch b/queue-4.19/tracing-ensure-visibility-when-inserting-an-element-.patch new file mode 100644 index 00000000000..c2c650314ec --- /dev/null +++ b/queue-4.19/tracing-ensure-visibility-when-inserting-an-element-.patch @@ -0,0 +1,129 @@ +From e48729591b45f92f834da2c28f22b6af37334eec Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 22 Jan 2024 16:09:28 +0100 +Subject: tracing: Ensure visibility when inserting an element into tracing_map + +From: Petr Pavlu + +[ Upstream commit 2b44760609e9eaafc9d234a6883d042fc21132a7 ] + +Running the following two commands in parallel on a multi-processor +AArch64 machine can sporadically produce an unexpected warning about +duplicate histogram entries: + + $ while true; do + echo hist:key=id.syscall:val=hitcount > \ + /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/trigger + cat /sys/kernel/debug/tracing/events/raw_syscalls/sys_enter/hist + sleep 0.001 + done + $ stress-ng --sysbadaddr $(nproc) + +The warning looks as follows: + +[ 2911.172474] ------------[ cut here ]------------ +[ 2911.173111] Duplicates detected: 1 +[ 2911.173574] WARNING: CPU: 2 PID: 12247 at kernel/trace/tracing_map.c:983 tracing_map_sort_entries+0x3e0/0x408 +[ 2911.174702] Modules linked in: iscsi_ibft(E) iscsi_boot_sysfs(E) rfkill(E) af_packet(E) nls_iso8859_1(E) nls_cp437(E) vfat(E) fat(E) ena(E) tiny_power_button(E) qemu_fw_cfg(E) button(E) fuse(E) efi_pstore(E) ip_tables(E) x_tables(E) xfs(E) libcrc32c(E) aes_ce_blk(E) aes_ce_cipher(E) crct10dif_ce(E) polyval_ce(E) polyval_generic(E) ghash_ce(E) gf128mul(E) sm4_ce_gcm(E) sm4_ce_ccm(E) sm4_ce(E) sm4_ce_cipher(E) sm4(E) sm3_ce(E) sm3(E) sha3_ce(E) sha512_ce(E) sha512_arm64(E) sha2_ce(E) sha256_arm64(E) nvme(E) sha1_ce(E) nvme_core(E) nvme_auth(E) t10_pi(E) sg(E) scsi_mod(E) scsi_common(E) efivarfs(E) +[ 2911.174738] Unloaded tainted modules: cppc_cpufreq(E):1 +[ 2911.180985] CPU: 2 PID: 12247 Comm: cat Kdump: loaded Tainted: G E 6.7.0-default #2 1b58bbb22c97e4399dc09f92d309344f69c44a01 +[ 2911.182398] Hardware name: Amazon EC2 c7g.8xlarge/, BIOS 1.0 11/1/2018 +[ 2911.183208] pstate: 61400005 (nZCv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--) +[ 2911.184038] pc : tracing_map_sort_entries+0x3e0/0x408 +[ 2911.184667] lr : tracing_map_sort_entries+0x3e0/0x408 +[ 2911.185310] sp : ffff8000a1513900 +[ 2911.185750] x29: ffff8000a1513900 x28: ffff0003f272fe80 x27: 0000000000000001 +[ 2911.186600] x26: ffff0003f272fe80 x25: 0000000000000030 x24: 0000000000000008 +[ 2911.187458] x23: ffff0003c5788000 x22: ffff0003c16710c8 x21: ffff80008017f180 +[ 2911.188310] x20: ffff80008017f000 x19: ffff80008017f180 x18: ffffffffffffffff +[ 2911.189160] x17: 0000000000000000 x16: 0000000000000000 x15: ffff8000a15134b8 +[ 2911.190015] x14: 0000000000000000 x13: 205d373432323154 x12: 5b5d313131333731 +[ 2911.190844] x11: 00000000fffeffff x10: 00000000fffeffff x9 : ffffd1b78274a13c +[ 2911.191716] x8 : 000000000017ffe8 x7 : c0000000fffeffff x6 : 000000000057ffa8 +[ 2911.192554] x5 : ffff0012f6c24ec0 x4 : 0000000000000000 x3 : ffff2e5b72b5d000 +[ 2911.193404] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffff0003ff254480 +[ 2911.194259] Call trace: +[ 2911.194626] tracing_map_sort_entries+0x3e0/0x408 +[ 2911.195220] hist_show+0x124/0x800 +[ 2911.195692] seq_read_iter+0x1d4/0x4e8 +[ 2911.196193] seq_read+0xe8/0x138 +[ 2911.196638] vfs_read+0xc8/0x300 +[ 2911.197078] ksys_read+0x70/0x108 +[ 2911.197534] __arm64_sys_read+0x24/0x38 +[ 2911.198046] invoke_syscall+0x78/0x108 +[ 2911.198553] el0_svc_common.constprop.0+0xd0/0xf8 +[ 2911.199157] do_el0_svc+0x28/0x40 +[ 2911.199613] el0_svc+0x40/0x178 +[ 2911.200048] el0t_64_sync_handler+0x13c/0x158 +[ 2911.200621] el0t_64_sync+0x1a8/0x1b0 +[ 2911.201115] ---[ end trace 0000000000000000 ]--- + +The problem appears to be caused by CPU reordering of writes issued from +__tracing_map_insert(). + +The check for the presence of an element with a given key in this +function is: + + val = READ_ONCE(entry->val); + if (val && keys_match(key, val->key, map->key_size)) ... + +The write of a new entry is: + + elt = get_free_elt(map); + memcpy(elt->key, key, map->key_size); + entry->val = elt; + +The "memcpy(elt->key, key, map->key_size);" and "entry->val = elt;" +stores may become visible in the reversed order on another CPU. This +second CPU might then incorrectly determine that a new key doesn't match +an already present val->key and subsequently insert a new element, +resulting in a duplicate. + +Fix the problem by adding a write barrier between +"memcpy(elt->key, key, map->key_size);" and "entry->val = elt;", and for +good measure, also use WRITE_ONCE(entry->val, elt) for publishing the +element. The sequence pairs with the mentioned "READ_ONCE(entry->val);" +and the "val->key" check which has an address dependency. + +The barrier is placed on a path executed when adding an element for +a new key. Subsequent updates targeting the same key remain unaffected. + +From the user's perspective, the issue was introduced by commit +c193707dde77 ("tracing: Remove code which merges duplicates"), which +followed commit cbf4100efb8f ("tracing: Add support to detect and avoid +duplicates"). The previous code operated differently; it inherently +expected potential races which result in duplicates but merged them +later when they occurred. + +Link: https://lore.kernel.org/linux-trace-kernel/20240122150928.27725-1-petr.pavlu@suse.com + +Fixes: c193707dde77 ("tracing: Remove code which merges duplicates") +Signed-off-by: Petr Pavlu +Acked-by: Tom Zanussi +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Sasha Levin +--- + kernel/trace/tracing_map.c | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +diff --git a/kernel/trace/tracing_map.c b/kernel/trace/tracing_map.c +index 83c2a0598c64..33c463967bb3 100644 +--- a/kernel/trace/tracing_map.c ++++ b/kernel/trace/tracing_map.c +@@ -574,7 +574,12 @@ __tracing_map_insert(struct tracing_map *map, void *key, bool lookup_only) + } + + memcpy(elt->key, key, map->key_size); +- entry->val = elt; ++ /* ++ * Ensure the initialization is visible and ++ * publish the elt. ++ */ ++ smp_wmb(); ++ WRITE_ONCE(entry->val, elt); + atomic64_inc(&map->hits); + + return entry->val; +-- +2.43.0 + diff --git a/queue-4.19/vlan-skip-nested-type-that-is-not-ifla_vlan_qos_mapp.patch b/queue-4.19/vlan-skip-nested-type-that-is-not-ifla_vlan_qos_mapp.patch new file mode 100644 index 00000000000..7bcd64487c6 --- /dev/null +++ b/queue-4.19/vlan-skip-nested-type-that-is-not-ifla_vlan_qos_mapp.patch @@ -0,0 +1,58 @@ +From e7cfbc368a143a0ac6b42af3242b4e1e17509b0c Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 18 Jan 2024 21:03:06 +0800 +Subject: vlan: skip nested type that is not IFLA_VLAN_QOS_MAPPING + +From: Lin Ma + +[ Upstream commit 6c21660fe221a15c789dee2bc2fd95516bc5aeaf ] + +In the vlan_changelink function, a loop is used to parse the nested +attributes IFLA_VLAN_EGRESS_QOS and IFLA_VLAN_INGRESS_QOS in order to +obtain the struct ifla_vlan_qos_mapping. These two nested attributes are +checked in the vlan_validate_qos_map function, which calls +nla_validate_nested_deprecated with the vlan_map_policy. + +However, this deprecated validator applies a LIBERAL strictness, allowing +the presence of an attribute with the type IFLA_VLAN_QOS_UNSPEC. +Consequently, the loop in vlan_changelink may parse an attribute of type +IFLA_VLAN_QOS_UNSPEC and believe it carries a payload of +struct ifla_vlan_qos_mapping, which is not necessarily true. + +To address this issue and ensure compatibility, this patch introduces two +type checks that skip attributes whose type is not IFLA_VLAN_QOS_MAPPING. + +Fixes: 07b5b17e157b ("[VLAN]: Use rtnl_link API") +Signed-off-by: Lin Ma +Reviewed-by: Simon Horman +Link: https://lore.kernel.org/r/20240118130306.1644001-1-linma@zju.edu.cn +Signed-off-by: Jakub Kicinski +Signed-off-by: Sasha Levin +--- + net/8021q/vlan_netlink.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c +index 74042b9d7f73..231eae2f1685 100644 +--- a/net/8021q/vlan_netlink.c ++++ b/net/8021q/vlan_netlink.c +@@ -120,12 +120,16 @@ static int vlan_changelink(struct net_device *dev, struct nlattr *tb[], + } + if (data[IFLA_VLAN_INGRESS_QOS]) { + nla_for_each_nested(attr, data[IFLA_VLAN_INGRESS_QOS], rem) { ++ if (nla_type(attr) != IFLA_VLAN_QOS_MAPPING) ++ continue; + m = nla_data(attr); + vlan_dev_set_ingress_priority(dev, m->to, m->from); + } + } + if (data[IFLA_VLAN_EGRESS_QOS]) { + nla_for_each_nested(attr, data[IFLA_VLAN_EGRESS_QOS], rem) { ++ if (nla_type(attr) != IFLA_VLAN_QOS_MAPPING) ++ continue; + m = nla_data(attr); + err = vlan_dev_set_egress_priority(dev, m->from, m->to); + if (err) +-- +2.43.0 +