5.15.222-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 654/752 selftests: nci: Fix uninitialized family ID on missing attribute
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chaithanya Lagisetty <[email protected]>
[ Upstream commit eda518d2cdb6074a0bcdfa06af291616bcb5c421 ]
get_family_id() walks the generic netlink CTRL_CMD_GETFAMILY reply looking for the CTRL_ATTR_FAMILY_ID attribute and returns the parsed value in the local variable "id". If the reply does not carry that attribute, the parsing loop never assigns "id" and the function returns an indeterminate stack value, which the caller stores in self->fid and uses for subsequent netlink requests.
Initialize "id" to 0 so a missing attribute yields a deterministic (invalid) family ID instead of a garbage value.
--- tools/testing/selftests/nci/nci_dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/nci/nci_dev.c +1 -1
@@ -182,7 +182,7 @@ static int get_family_id(int sd, __u32 pid, __u32 *event_group) } ans;struct nlattr *na;int resp_len; -__u16 id; +__u16 id =0 ;int len;int rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 655/752 selftests/nci: Fix out-of-bounds store on thread join
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Gellermann <[email protected]>
[ Upstream commit 6be581aeffc215bfc77939cd59902b0dbc4af23e ]
The NCI test collects the exit status of its helper threads by passing the address of an int to pthread_join():
int status; ... pthread_join(thread_t, (void **) &status);
pthread_join() stores a void pointer to the memory location. On 64-bit systems, a void pointer is wider than an int, so the store overruns the 4 bytes of space allocated on the stack for the integer and corrupts the adjacent stack. On our CHERI system, this caused a fault due to a capability bounds violation.
Fix this by introducing a helper that joins a thread through a void pointer and converts the result back to an integer, which is what the helper threads return.
While here, also fix the logic in disconnect_tag() if the helper thread creation failed. Previously, it would have joined a thread that was never created when pthread_create() failed.
--- tools/testing/selftests/nci/nci_dev.c | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-)
tools/testing/selftests/nci/nci_dev.c +20 -11
@@ -8,6 +8,7 @@#include <stdlib.h> #include <errno.h> +#include <stdint.h> #include <string.h> #include <sys/ioctl.h> #include <fcntl.h>
@@ -87,6 +88,16 @@ struct msgtemplate {char buf[MAX_MSG_SIZE ]; }; +static int join_thread_status (pthread_t thread) +{ +void *thread_ret =NULL ; + +if (pthread_join (thread, &thread_ret)) +return -1 ; + +return (int )(intptr_t )thread_ret; +} +static int create_nl_socket (void ) {int fd;
@@ -444,7 +455,7 @@ FIXTURE_SETUP(NCI) NFC_CMD_DEV_UP, self->dev_idex);EXPECT_EQ (rc,0 ); -pthread_join (thread_t, (void **)&status); + status =join_thread_status (thread_t);ASSERT_EQ (status,0 ); self->open_state = true; }
@@ -514,7 +525,7 @@ FIXTURE_TEARDOWN(NCI) NFC_CMD_DEV_DOWN, self->dev_idex);EXPECT_EQ (rc,0 ); -pthread_join (thread_t, (void **)&status); + status =join_thread_status (thread_t);ASSERT_EQ (status,0 ); }
@@ -585,7 +596,6 @@ int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pvoid *nla_start_poll_data[2 ] = {&dev_idx, &proto};int nla_start_poll_len[2 ] = {4 ,4 };pthread_t thread_t; -int status;int rc; rc = pthread_create(&thread_t, NULL, virtual_poll_start,
@@ -598,14 +608,12 @@ int start_polling(int dev_idx, int proto, int virtual_fd, int sd, int fid, int pif (rc !=0 )return rc; -pthread_join (thread_t, (void **)&status); -return status; +return join_thread_status (thread_t); }int stop_polling (int dev_idx,int virtual_fd,int sd,int fid,int pid) {pthread_t thread_t; -int status;int rc; rc = pthread_create(&thread_t, NULL, virtual_poll_stop,
@@ -618,8 +626,7 @@ int stop_polling(int dev_idx, int virtual_fd, int sd, int fid, int pid)if (rc !=0 )return rc; -pthread_join (thread_t, (void **)&status); -return status; +return join_thread_status (thread_t); }TEST_F (NCI , start_poll)
@@ -834,8 +841,10 @@ int disconnect_tag(int nfc_sock, int virtual_fd)return status;close (nfc_sock); -pthread_join (thread_t, (void **)&status); -return status; +if (status) +return -1 ; + +return join_thread_status (thread_t); }TEST_F (NCI , t4t_tag_read)
@@ -882,7 +891,7 @@ TEST_F(NCI, deinit) NFC_CMD_DEV_DOWN, self->dev_idex);EXPECT_EQ (rc,0 ); -pthread_join (thread_t, (void **)&status); + status =join_thread_status (thread_t); self->open_state =0 ;ASSERT_EQ (status,0 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 656/752 nfc: virtual_ncidev: Add missing ioctl compat handler
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Gellermann <[email protected]>
[ Upstream commit 51814683e28fc64eceb415962376956c3cfc75a7 ]
The compat handler for ioctls to the virtual nci device is missing. So, nci-specific ioctls of a compat task return with -1 and errno set to ENOTTY. Add a handler.
The handling of an ioctl() call of a compat task to get the index of virtual nci device (IOCTL_GET_NCIDEV_IDX) lands in the default case of the ioctl compat handler (see fs/ioctl.c):
COMPAT_SYSCALL_DEFINE3(ioctl, ...)
{
...
default:
error = do_vfs_ioctl(fd_file(f), fd, cmd, ...);
if (error != -ENOIOCTLCMD)
break;
if (fd_file(f)->f_op->compat_ioctl)
error = fd_file(f)->f_op->compat_ioctl(fd_file(f), cmd, arg);
if (error == -ENOIOCTLCMD)
error = -ENOTTY;
...
}There, do_vfs_ioctl() returns -ENOIOCTLCMD and compat_ioctl is not set for virtual_ncidev_fops, i.e. f_op->compat_ioctl == NULL. So, the ioctl() syscall returns with -1 and errno set to ENOTTY to the compat task.
To fix this, use the compat_ptr_ioctl helper for compat handling here. It shall be used for ioctls that "either ignore the argument or pass a pointer to a compatible data type". The driver's sole ioctl takes a user void pointer and copies nfc_dev->idx to it, a 4-byte integer across all ABIs.
This issue has been found by running the nci_dev kernel selftest as rv64 binary on top of a CHERI kernel, where the ioctl() ends up in the ioctl compat handler, similar to a 32-bit application on top of a 64-bit kernel.
--- drivers/nfc/virtual_ncidev.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/nfc/virtual_ncidev.c +2 -1
@@ -196,7 +196,8 @@ static const struct file_operations virtual_ncidev_fops = { .write = virtual_ncidev_write, .open = virtual_ncidev_open, .release = virtual_ncidev_close, - .unlocked_ioctl = virtual_ncidev_ioctl + .unlocked_ioctl = virtual_ncidev_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static int __init virtual_ncidev_init (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 657/752 nfc: llcp: fix sdreq TLV list leak on parse/alloc/send failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
[ Upstream commit 66f4300206b82b0b143ef0d9be90cd8d29f23a47 ]
nfc_genl_llc_sdreq() builds a list of TLV nodes while walking nested netlink attrs, but 3 error paths (nested-attr parse failure, TLV alloc ENOMEM, nfc_llcp_send_snl_sdreq() failure) all skip freeing what was already queued.
Route them through a new free_list label, mirroring the SDRES path in the same file which already does this. Harmless on the success path too -- send_snl_sdreq() drains the list as it moves nodes, so it's already empty by the time free_list runs.
--- net/nfc/netlink.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/nfc/netlink.c +5 -2
@@ -1178,7 +1178,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info)if (rc !=0 ) { rc = -EINVAL ; - goto put_local; + goto free_list; }if (!sdp_attrs[NFC_SDP_ATTR_URI ])
@@ -1197,7 +1197,7 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info) sdreq =nfc_llcp_build_sdreq_tlv (tid, uri, uri_len);if (sdreq ==NULL ) { rc = -ENOMEM ; - goto put_local; + goto free_list; } tlvs_len += sdreq->tlv_len;
@@ -1212,6 +1212,9 @@ static int nfc_genl_llc_sdreq(struct sk_buff *skb, struct genl_info *info) rc =nfc_llcp_send_snl_sdreq (local, &sdreq_list, tlvs_len); +free_list: +nfc_llcp_free_sdp_tlv_list (&sdreq_list); + put_local:nfc_llcp_local_put (local);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 658/752 nfc: st21nfca: validate ISO15693 inventory length
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 7f2ea5ed588c03d481f0301e6c3d4240132383fb ]
The ISO15693 inventory helper removes a two-byte prefix without checking that it exists, then accepts a one-byte remainder before reading data[1] as the DSFID.
Require the prefix and at least two remaining bytes before copying the UID data and reading the DSFID.
--- drivers/nfc/st21nfca/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/nfc/st21nfca/core.c +1 -3
@@ -577,9 +577,7 @@ static int st21nfca_get_iso15693_inventory(struct nfc_hci_dev *hdev,if (r <0 ) goto exit; -skb_pull (inventory_skb,2 ); - -if (inventory_skb->len ==0 || +if (!skb_pull (inventory_skb,2 ) || inventory_skb->len <2 || inventory_skb->len >NFC_ISO15693_UID_MAXSIZE ) { r = -EPROTO ; goto exit;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 659/752 nfc: llcp: fix -ENOMEM on connect with zero-length service name
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit c04981e42d94f39c1dba965cc462a046e946a6c5 ]
When service_name_len is 0, kmemdup() returns ZERO_SIZE_PTR which passes the NULL check, causing nfc_llcp_send_connect() to attempt building a zero-length service name TLV and fail with -ENOMEM.
Fix by setting service_name to NULL directly when service_name_len is 0.
--- net/nfc/llcp_sock.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
net/nfc/llcp_sock.c +10 -6
@@ -761,12 +761,16 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr, llcp_sock->service_name_len = min_t(unsigned int, addr->service_name_len,NFC_LLCP_MAX_SERVICE_NAME ); - llcp_sock->service_name =kmemdup (addr->service_name, - llcp_sock->service_name_len, -GFP_KERNEL ); -if (!llcp_sock->service_name) { - ret = -ENOMEM ; - goto sock_llcp_release; +if (llcp_sock->service_name_len ==0 ) { + llcp_sock->service_name =NULL ; + }else { + llcp_sock->service_name =kmemdup (addr->service_name, + llcp_sock->service_name_len, +GFP_KERNEL ); +if (!llcp_sock->service_name) { + ret = -ENOMEM ; + goto sock_llcp_release; + } }nfc_llcp_sock_link (&local->connecting_sockets, sk);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 660/752 nfc: llcp: fix WKS SAP hijacking via prefix match in nfc_llcp_wks_sap()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 408cff6bd60636df201274d320edfdfde9ed41db ]
nfc_llcp_wks_sap() compares only service_name_len bytes, so a short service_name like "u" matches longer WKS strings like "urn:nfc:sn:snep". Fix by requiring exact length match before strncmp().
--- net/nfc/llcp_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/nfc/llcp_core.c +2 -1
@@ -369,7 +369,8 @@ static int nfc_llcp_wks_sap(const char *service_name, size_t service_name_len)if (wks[sap] ==NULL )continue ; -if (strncmp (wks[sap], service_name, service_name_len) ==0 ) +if (strlen (wks[sap]) == service_name_len && + !strncmp (wks[sap], service_name, service_name_len))return sap; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 661/752 nfc: llcp: fix slab-out-of-bounds reads when logging service names
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 7dcf371a35632f035baf77bcf2c129165f772ce4 ]
nfc_llcp_wks_sap() and nfc_llcp_build_sdreq_tlv() pass non-null- terminated strings to pr_debug() using the %s format specifier. The buffers are allocated via kmemdup() or come from netlink attributes and are not guaranteed to be null-terminated, causing __dynamic_pr_debug() to read beyond the allocated region:
KASAN: slab-out-of-bounds Read in __dynamic_pr_debug
Fix both call sites by using %.*s with the explicit length to limit the output to the actual length of the string.
--- net/nfc/llcp_commands.c | 2 +- net/nfc/llcp_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
net/nfc/llcp_commands.c +1 -1
@@ -135,7 +135,7 @@ struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, const char *uri, {struct nfc_llcp_sdp_tlv *sdreq; -pr_debug ("uri: %s, len: %zu\n" , uri, uri_len); +pr_debug ("uri: %.*s, len: %zu\n" , (int )uri_len, uri, uri_len);/* sdreq->tlv_len is u8, takes uri_len, + 3 for header, + 1 for NULL */ if (WARN_ON_ONCE (uri_len >U8_MAX -4 ))
net/nfc/llcp_core.c +1 -1
@@ -358,7 +358,7 @@ static int nfc_llcp_wks_sap(const char *service_name, size_t service_name_len) {int sap, num_wks; -pr_debug ("%s\n" , service_name); +pr_debug ("%.*s\n" , (int )service_name_len, service_name);if (service_name ==NULL )return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 662/752 nfc: pn533: fix OOB read in pn533_acr122_is_rx_frame_valid()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Deepanshu Kartikey <[email protected]>
[ Upstream commit b61732f47316d45f27706db7812950145d3327b5 ]
frame->ccid.datalen is read directly from the USB response frame and used, unchecked, as an index into frame->data[]. A malicious or malfunctioning device can set this field to an arbitrary value, causing the driver to read far outside the received buffer.
Bound ccid.datalen against the maximum possible ACR122 frame size before using it. This replaces the existing datalen == 0 check, since datalen < 2 already covers that case and additionally rejects datalen == 1, which would still underflow the "datalen - 2" offset used below.
--- drivers/nfc/pn533/usb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/nfc/pn533/usb.c +3 -1
@@ -320,7 +320,9 @@ static bool pn533_acr122_is_rx_frame_valid(void *_frame, struct pn533 *dev)if (frame->ccid.type !=0x83 )return false; -if (!frame->ccid.datalen) +if (frame->ccid.datalen <2 || + frame->ccid.datalen >PN533_ACR122_FRAME_MAX_PAYLOAD_LEN + +PN533_ACR122_RX_FRAME_TAIL_LEN )return false;if (frame->data[frame->ccid.datalen -2 ] ==0x63 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 663/752 veth: manage XDP program pointers during channel resize
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 7104a370714346b667712913dc16abf14bbc97ed ]
veth_set_channels() tears down XDP resources for removed RX queues without clearing rq->xdp_prog. If the program is then detached or replaced, those queues keep the old pointer after bpf_prog_put(). A later channel increase can re-enable NAPI and run the freed program.
BUG: unable to handle page fault for address: ffffc90000256048
Oops: Oops: 0000 [#1] SMP KASAN NOPTI
RIP: veth_xdp_rcv_skb (include/linux/filter.h:779
include/net/xdp.h:696 drivers/net/veth.c:820)
Call Trace:
veth_xdp_rcv (drivers/net/veth.c:941)
veth_poll (drivers/net/veth.c:986)
__napi_poll (net/core/dev.c:7787)
net_rx_action (net/core/dev.c:7850 net/core/dev.c:8007)
handle_softirqs (kernel/softirq.c:645)
Kernel panic - not syncing: Fatal exception in interrupt--- drivers/net/veth.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/veth.c +2 -0
@@ -955,6 +955,7 @@ static int __veth_napi_enable_range(struct net_device *dev, int start, int end)for (i = start; i < end; i++) {struct veth_rq *rq = &priv->rq[i]; +rcu_assign_pointer (rq->xdp_prog, priv->_xdp_prog);napi_enable (&rq->xdp_napi);rcu_assign_pointer (priv->rq[i].napi, &priv->rq[i].xdp_napi); }
@@ -983,6 +984,7 @@ static void veth_napi_del_range(struct net_device *dev, int start, int end)rcu_assign_pointer (priv->rq[i].napi,NULL );napi_disable (&rq->xdp_napi); +rcu_assign_pointer (rq->xdp_prog,NULL );__netif_napi_del (&rq->xdp_napi); }synchronize_net ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 664/752 net: skbuff: fix pull-bound underflow in skb_checksum_setup_ipv6()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shihuang Liu <[email protected]>
[ Upstream commit 3b4e0b0c008a8c1b474730248cd5b873026c74bd ]
skb_maybe_pull_tail() subtracts skb_headlen(skb) from the unsigned max argument and passes the result to __pskb_pull_tail() as a signed int. The function does not ensure that max is at least skb_headlen(skb).
This can happen while parsing IPv6 extension headers when an skb already has a linear area larger than MAX_IPV6_HDR_LEN. Once the parser needs data beyond the linear area, max - skb_headlen(skb) wraps and is converted to a negative delta. __pskb_pull_tail() then passes that negative length to skb_copy_bits(), where it can become a very large copy length.
Pass the requested length itself as the pull bound at the three extension-header call sites, so the delta can no longer go negative.
--- net/core/skbuff.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
net/core/skbuff.c +6 -3
@@ -5261,7 +5261,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) err =skb_maybe_pull_tail (skb, off +sizeof (struct ipv6_opt_hdr ), -MAX_IPV6_HDR_LEN ); + off + +sizeof (struct ipv6_opt_hdr ));if (err <0 ) goto out;
@@ -5276,7 +5277,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) err =skb_maybe_pull_tail (skb, off +sizeof (struct ip_auth_hdr ), -MAX_IPV6_HDR_LEN ); + off + +sizeof (struct ip_auth_hdr ));if (err <0 ) goto out;
@@ -5291,7 +5293,8 @@ static int skb_checksum_setup_ipv6(struct sk_buff *skb, bool recalculate) err =skb_maybe_pull_tail (skb, off +sizeof (struct frag_hdr ), -MAX_IPV6_HDR_LEN ); + off + +sizeof (struct frag_hdr ));if (err <0 ) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 665/752 vrf: Stop corrupting skb->csum when capturing CHECKSUM_COMPLETE packets
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit ab7aa05c06ae340e5c7530bb78fa8d23794e460b ]
The VRF device is an Ethernet device but it can have non-Ethernet ports such as IP tunnels. Before the cited commit, capturing packets from such ports on the VRF device resulted in these packets being detected as malformed since they lack an Ethernet header.
The cited commit fixed it by pushing a dummy Ethernet header to such packets before the capture and pulling it afterwards. In the case of CHECKSUM_COMPLETE packets it also updated skb->csum with the checksum of the dummy Ethernet header. This is wrong as skb->csum should not include the checksum of the Ethernet header ("checksum of the _whole_ packet as seen by netif_rx()").
This also means that L4 protocols receive a corrupted skb->csum and potentially drop the packet, as is the case with UDP packets whose checksum was completed by software.
Fix by removing the unnecessary call to skb_postpush_rcsum().
--- drivers/net/vrf.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/vrf.c +0 -2
@@ -1287,8 +1287,6 @@ static int vrf_prepare_mac_header(struct sk_buff *skb, skb->protocol = eth->h_proto; skb->pkt_type =PACKET_HOST ; -skb_postpush_rcsum (skb, skb->data,ETH_HLEN ); -skb_pull_inline (skb,ETH_HLEN );return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 666/752 net: bcmgenet: validate Ethernet address in bcmgenet_set_mac_addr
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Fainelli <[email protected]>
[ Upstream commit 273941c85fc2632cd3e56ddff737b9245de7697d ]
bcmgenet_set_mac_addr() did not check whether the provided MAC address is a valid Ethernet address before applying it. Userspace could configure an invalid address (such as all zeroes or a multicast address) while the interface is down.
Add a call to is_valid_ether_addr() and return -EADDRNOTAVAIL if the MAC address is not valid.
--- drivers/net/ethernet/broadcom/genet/bcmgenet.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +3 -0
@@ -3627,6 +3627,9 @@ static int bcmgenet_set_mac_addr(struct net_device *dev, void *p)if (netif_running (dev))return -EBUSY ; +if (!is_valid_ether_addr (addr->sa_data)) +return -EADDRNOTAVAIL ; +eth_hw_addr_set (dev, addr->sa_data);return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 667/752 ip_gre: Reject enabling collect metadata through changelink
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xuanqiang Luo <[email protected]>
[ Upstream commit a3f315be9d30eeb6938d11fa17fd4b32d52f7c42 ]
ipgre_netlink_parms() can enable collect_md on an existing GRE, GRETAP or ERSPAN device. Unlike newlink, changelink does not enforce metadata tunnel uniqueness. Converting a non-metadata device can therefore replace the metadata receive entry for another device of the same type in the same netns. Deleting either device then clears the shared entry, breaking metadata receive lookup for the surviving device.
If parameter validation fails after collect_md is set, deleting the modified device can also clear an entry it never owned.
Reject enabling metadata mode in both changelink callbacks before any encapsulation or tunnel parameters are modified. Allow requests that repeat the metadata attribute on an existing metadata device.
--- net/ipv4/ip_gre.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/ipv4/ip_gre.c +12 -0
@@ -1415,6 +1415,12 @@ static int ipgre_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) { +NL_SET_ERR_MSG (extack, +"Enabling collect_md on an existing device is not supported" ); +return -EOPNOTSUPP ; + } + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
@@ -1447,6 +1453,12 @@ static int erspan_changelink(struct net_device *dev, struct nlattr *tb[],if (!rtnl_dev_link_net_capable (dev, t->net))return -EPERM ; +if (data && data[IFLA_GRE_COLLECT_METADATA ] && !t->collect_md) { +NL_SET_ERR_MSG (extack, +"Enabling collect_md on an existing device is not supported" ); +return -EOPNOTSUPP ; + } + err =ipgre_newlink_encap_setup (dev, data);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 668/752 vxlan: use one headroom snapshot for neighbour replies
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanghyun Park <[email protected]>
[ Upstream commit 481506a756dcd828ef42391cb08f38d8d96d38fc ]
vxlan_na_create() samples LL_RESERVED_SPACE() to size the reply skb and then samples it again to reserve headroom. A concurrent vxlan_changelink() can update needed_headroom between the two reads, creating a TOCTOU race. The second value can exceed the allocation and make the Ethernet header write out of bounds.
The race is reproducible on the unpatched kernel. It occurred when vxlan_na_create() generated a neighbour reply while vxlan_changelink() changed the link headroom. KASAN caught a four-byte write two bytes beyond a 704-byte skbuff_small_head allocation.
Snapshot the headroom once and use that value for both allocation and reservation.
--- drivers/net/vxlan/vxlan_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/vxlan/vxlan_core.c +4 -2
@@ -2086,13 +2086,15 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request,struct ipv6hdr *pip6;u8 *daddr;int na_olen =8 ;/* opt hdr + ETH_ALEN for target */ +int headroom;int ns_olen;int i, len;if (dev ==NULL || !pskb_may_pull (request, request->len))return NULL ; - len =LL_RESERVED_SPACE (dev) +sizeof (struct ipv6hdr ) + + headroom =LL_RESERVED_SPACE (dev); + len = headroom +sizeof (struct ipv6hdr ) +sizeof (*na) + na_olen + dev->needed_tailroom; reply =alloc_skb (len,GFP_ATOMIC );if (reply ==NULL )
@@ -2100,7 +2102,7 @@ static struct sk_buff *vxlan_na_create(struct sk_buff *request, reply->protocol =htons (ETH_P_IPV6 ); reply->dev = dev; -skb_reserve (reply,LL_RESERVED_SPACE (request->dev)); +skb_reserve (reply, headroom);skb_push (reply,sizeof (struct ethhdr ));skb_reset_mac_header (reply);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 669/752 net: xps: reject an out of range traffic class
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Szetei <[email protected]>
[ Upstream commit 4da3b7b8b50f3e2fde54a4c18a82a8e3f6223910 ]
Only the entries below dev->num_tc are valid in dev->tc_to_txq[], and dev->prio_tc_map[] may only name classes below it. netdev_set_num_tc() lowers dev->num_tc without touching either array.
netdev_txq_to_tc() walks all TC_MAX_QUEUE slots and netdev_get_prio_tc_map() returns the entry as it stands, so a leftover entry is handed out as a traffic class >= dev->num_tc. Taking that class from netdev_txq_to_tc(), __netif_set_xps_queue() rejects only a negative one and indexes an XPS map sized for dev->num_tc classes:
tci = j * num_tc + tc; RCU_INIT_POINTER(new_dev_maps->attr_map[tci], map);
attr_map[] holds nr_ids * num_tc entries and j runs over the ids named in the mask, so a class that is not below num_tc pushes tci past the end of the map for the last ids and the store overruns it.
Any caller that lowers num_tc leaves such entries behind, and mqprio_destroy() tears down with netdev_set_num_tc(dev, 0) rather than netdev_reset_tc(). After mqprio with 8 classes then 1, tc_to_txq[1..7] still describe txq 1..7. The splat is from an XPS write to txq 2 on a veth with 8 rx queues: attr_map[] has 8 * 1 entries, tci = j + 2, and j == 6 stores one past the end of the 88-byte map:
BUG: KASAN: slab-out-of-bounds in __netif_set_xps_queue (net/core/dev.c:2954) Write of size 8 at addr ffff88813016bc58 by task xps_oob/634 __netif_set_xps_queue (net/core/dev.c:2954) xps_rxqs_store (net/core/net-sysfs.c:1880) netdev_queue_attr_store (net/core/net-sysfs.c:1390) Allocated by task 634: __kmalloc_noprof (mm/slub.c:5439) __netif_set_xps_queue (net/core/dev.c:2937) The buggy address is located 0 bytes to the right of allocated 88-byte region [ffff88813016bc00, ffff88813016bc58)
Reject a class the map has no room for.
--- net/core/dev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/dev.c +1 -1
@@ -2650,7 +2650,7 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, dev =netdev_get_tx_queue (dev, index)->sb_dev ? : dev; tc =netdev_txq_to_tc (dev, index); -if (tc <0 ) +if (tc <0 || tc >= num_tc)return -EINVAL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 670/752 tcp: fix use-after-free of retransmit_skb_hint in tcp_send_synack()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yilin Zhang <[email protected]>
[ Upstream commit fe99bbeee5c5dbd3abc30721a8079ced59649d97 ]
When tcp_send_synack() replaces the cloned SYN skb at the head of the retransmit queue with a copy, it frees the original with tcp_rtx_queue_unlink_and_free() and only repairs tp->highest_sack. tp->retransmit_skb_hint keeps pointing at the freed skbuff_fclone_cache object.
The dangling hint is read in tcp_verify_retransmit_hint() and used as the root of the rbtree walk in tcp_xmit_retransmit_queue(). An unprivileged TFO client (sendmsg(MSG_FASTOPEN)) can arm the hint with an attacker-supplied ICMP fragmentation-needed message, after which a simultaneous open frees the armed SYN skb:
BUG: KASAN: slab-use-after-free in tcp_mark_skb_lost (net/ipv4/tcp_input.c:1316) Read of size 4 at addr ffff88800604d928 by task swapper/1/0 Call Trace: tcp_mark_skb_lost (net/ipv4/tcp_input.c:1316) tcp_simple_retransmit (net/ipv4/tcp_input.c:3158) tcp_v4_err (net/ipv4/tcp_ipv4.c:587)
Sync the hint to the copy.
--- net/ipv4/tcp_output.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv4/tcp_output.c +3 -0
@@ -3512,6 +3512,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority)*/ int tcp_send_synack (struct sock *sk) { +struct tcp_sock *tp =tcp_sk (sk);struct sk_buff *skb; skb =tcp_rtx_queue_head (sk);
@@ -3529,6 +3530,8 @@ int tcp_send_synack(struct sock *sk)if (!nskb)return -ENOMEM ;INIT_LIST_HEAD (&nskb->tcp_tsorted_anchor); +if (skb == tp->retransmit_skb_hint) + tp->retransmit_skb_hint = nskb;tcp_highest_sack_replace (sk, skb, nskb);tcp_rtx_queue_unlink_and_free (skb, sk);__skb_header_release (nskb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 671/752 net/smc: stop links when their GID is removed
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karsten Graul <[email protected]>
[ Upstream commit 29397e34c76b57ce596493008176cf374f1cb867 ]
With SMC-Rv2 the GID is an IP address that can be deleted from the device. When an IB_EVENT_GID_CHANGE event is provided then iterate over all active links and check if their GID is still defined. Otherwise stop the affected link.
Stable-dep-of: 61cb282fe97b ("net/smc: fix UAF on lgr list traversal in smcr_port_err()")
--- net/smc/smc_ib.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+)
net/smc/smc_ib.c +53 -0
@@ -217,6 +217,58 @@ int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,return -ENODEV ; } +/* check if gid is still defined on smcibdev */ +static bool smc_ib_check_link_gid (u8 gid[SMC_GID_SIZE ],bool smcrv2, +struct smc_ib_device *smcibdev,u8 ibport) +{ +const struct ib_gid_attr *attr; +bool rc = false; +int i; + +for (i =0 ; !rc && i < smcibdev->pattr[ibport -1 ].gid_tbl_len; i++) { + attr =rdma_get_gid_attr (smcibdev->ibdev, ibport, i); +if (IS_ERR (attr)) +continue ; + +rcu_read_lock (); +if ((!smcrv2 && attr->gid_type ==IB_GID_TYPE_ROCE ) || + (smcrv2 && attr->gid_type ==IB_GID_TYPE_ROCE_UDP_ENCAP && + !(ipv6_addr_type ((const struct in6_addr *)&attr->gid) + &IPV6_ADDR_LINKLOCAL ))) +if (!memcmp (gid, &attr->gid,SMC_GID_SIZE )) + rc = true; +rcu_read_unlock (); +rdma_put_gid_attr (attr); + } +return rc; +} + +/* check all links if the gid is still defined on smcibdev */ +static void smc_ib_gid_check (struct smc_ib_device *smcibdev,u8 ibport) +{ +struct smc_link_group *lgr; +int i; + +spin_lock_bh (&smc_lgr_list.lock); +list_for_each_entry (lgr, &smc_lgr_list.list, list) { +if (strncmp (smcibdev->pnetid[ibport -1 ], lgr->pnet_id, +SMC_MAX_PNETID_LEN )) +continue ;/* lgr is not affected */ +if (list_empty (&lgr->list)) +continue ; +for (i =0 ; i <SMC_LINKS_PER_LGR_MAX ; i++) { +if (lgr->lnk[i].state ==SMC_LNK_UNUSED || + lgr->lnk[i].smcibdev != smcibdev) +continue ; +if (!smc_ib_check_link_gid (lgr->lnk[i].gid, + lgr->smc_version ==SMC_V2 , + smcibdev, ibport)) +smcr_port_err (smcibdev, ibport); + } + } +spin_unlock_bh (&smc_lgr_list.lock); +} +static int smc_ib_remember_port_attr (struct smc_ib_device *smcibdev,u8 ibport) {int rc;
@@ -255,6 +307,7 @@ static void smc_ib_port_event_work(struct work_struct *work) }else {clear_bit (port_idx, smcibdev->ports_going_away);smcr_port_add (smcibdev, port_idx +1 ); +smc_ib_gid_check (smcibdev, port_idx +1 ); } } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 672/752 net/smc: fix UAF on lgr list traversal in smcr_port_err()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sidraya Jayagond <[email protected]>
[ Upstream commit 61cb282fe97b3b0ba32ca09417a693162bf4ae3f ]
smcr_port_err() traverses smc_lgr_list.list without holding smc_lgr_list.lock, allowing a concurrent smc_lgr_terminate_sched() to free an lgr while it is still being dereferenced.
Hold smc_lgr_list.lock across the traversal. Update smc_ib_gid_check() to call smcr_port_err() after releasing the lock.
--- net/smc/smc_core.c | 2 ++ net/smc/smc_ib.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
net/smc/smc_core.c +2 -0
@@ -1566,6 +1566,7 @@ void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport)struct smc_link_group *lgr, *n;int i; +spin_lock_bh (&smc_lgr_list.lock);list_for_each_entry_safe (lgr, n, &smc_lgr_list.list, list) {if (strncmp (smcibdev->pnetid[ibport -1 ], lgr->pnet_id,SMC_MAX_PNETID_LEN ))
@@ -1580,6 +1581,7 @@ void smcr_port_err(struct smc_ib_device *smcibdev, u8 ibport)smcr_link_down_cond_sched (lnk); } } +spin_unlock_bh (&smc_lgr_list.lock); }static void smc_link_down_work (struct work_struct *work)
net/smc/smc_ib.c +8 -2
@@ -247,6 +247,7 @@ static bool smc_ib_check_link_gid(u8 gid[SMC_GID_SIZE], bool smcrv2,static void smc_ib_gid_check (struct smc_ib_device *smcibdev,u8 ibport) {struct smc_link_group *lgr; +bool stale_gid = false;int i;spin_lock_bh (&smc_lgr_list.lock);
@@ -262,11 +263,16 @@ static void smc_ib_gid_check(struct smc_ib_device *smcibdev, u8 ibport)continue ;if (!smc_ib_check_link_gid (lgr->lnk[i].gid, lgr->smc_version ==SMC_V2 , - smcibdev, ibport)) -smcr_port_err (smcibdev, ibport); + smcibdev, ibport)) { + stale_gid = true; + goto out; + } } } +out:spin_unlock_bh (&smc_lgr_list.lock); +if (stale_gid) +smcr_port_err (smcibdev, ibport); }static int smc_ib_remember_port_attr (struct smc_ib_device *smcibdev,u8 ibport)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 673/752 tipc: Fix a data race on mon->peer_cnt in mon_timeout()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ginger Li <[email protected]>
[ Upstream commit 8e1937fed6738460554ec123c64839e2445e7d53 ]
mon_timeout() evaluates dom_size(mon->peer_cnt) before it takes mon->lock, while mon->peer_cnt is updated under that lock by tipc_mon_add_peer() and tipc_mon_remove_peer(). The value can therefore be stale, and the decision whether the local domain has to be recomputed can be based on an outdated member count.
Read mon->peer_cnt inside the write_lock_bh(&mon->lock) protected region.
--- net/tipc/monitor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/tipc/monitor.c +2 -1
@@ -632,9 +632,10 @@ static void mon_timeout(struct timer_list *t) {struct tipc_monitor *mon =from_timer (mon, t, timer);struct tipc_peer *self; -int best_member_cnt =dom_size (mon->peer_cnt) -1 ; +int best_member_cnt;write_lock_bh (&mon->lock); + best_member_cnt =dom_size (mon->peer_cnt) -1 ; self = mon->self;if (self && (best_member_cnt != self->applied)) {mon_update_local_domain (mon);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 674/752 llc: fix skb UAF and leaks on llc_mac_hdr_init() failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 72f9dd522f8d6c5a00be9695c7bb74631eb5069e ]
In llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(), if llc_mac_hdr_init() fails, kfree_skb(skb) is called instead of kfree_skb(nskb). This leaks the newly allocated nskb, reads from the freed skb via LLC_I_GET_NR(pdu), and double-frees skb when llc_conn_state_process() drops its reference.
In llc_sap_action_send_xid_r() and llc_sap_action_send_test_r(), nskb is leaked if llc_mac_hdr_init() returns an error.
Free nskb in all three error paths.
--- net/llc/llc_c_ac.c | 2 +- net/llc/llc_s_ac.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
net/llc/llc_c_ac.c +1 -1
@@ -443,7 +443,7 @@ int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,if (likely (!rc))llc_conn_send_pdu (sk, nskb);else -kfree_skb (skb); +kfree_skb (nskb); }if (rc) { nr =LLC_I_GET_NR (pdu);
net/llc/llc_s_ac.c +4 -0
@@ -127,6 +127,8 @@ int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb) rc =llc_mac_hdr_init (nskb, mac_sa, mac_da);if (likely (!rc)) rc =dev_queue_xmit (nskb); +else +kfree_skb (nskb); out:return rc; }
@@ -176,6 +178,8 @@ int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb) rc =llc_mac_hdr_init (nskb, mac_sa, mac_da);if (likely (!rc)) rc =dev_queue_xmit (nskb); +else +kfree_skb (nskb); out:return rc; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 675/752 bridge: check llc_mac_hdr_init() return value in br_send_bpdu()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit ac704ff08e511c87643799c385f55ecd69b85e03 ]
If llc_mac_hdr_init() fails (for instance if the port device type does not support LLC or dev_hard_header() fails), br_send_bpdu() should drop the skb instead of resetting the mac header to the LLC payload and transmitting a malformed frame.
--- net/bridge/br_stp_bpdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bridge/br_stp_bpdu.c +4 -1
@@ -52,7 +52,10 @@ static void br_send_bpdu(struct net_bridge_port *p, LLC_SAP_BSPAN, LLC_PDU_CMD);llc_pdu_init_as_ui_cmd (skb); -llc_mac_hdr_init (skb, p->dev->dev_addr, p->br->group_addr); +if (llc_mac_hdr_init (skb, p->dev->dev_addr, p->br->group_addr)) { +kfree_skb (skb); +return ; + }skb_reset_mac_header (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 676/752 net/sched: sch_teql: fix shadowed err in __teql_resolve()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 907b978e82cb4c1c245fc2985bb27c5d5c88c8f6 ]
__teql_resolve() declares an inner 'int err;' inside the 'if (neigh_event_send(n, skb_res) == 0)' block, shadowing the outer 'int err = 0;'. As a result, a negative return from dev_hard_header() is written to the inner variable and __teql_resolve() still returns 0.
Remove the shadowed variable and set the outer err to -EINVAL when dev_hard_header() returns a negative error.
--- net/sched/sch_teql.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/sched/sch_teql.c +2 -5
@@ -242,14 +242,11 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res, }if (neigh_event_send (n, skb_res) ==0 ) { -int err;char haddr[MAX_ADDR_LEN ];neigh_ha_snapshot (haddr, n, dev); - err =dev_hard_header (skb, dev,ntohs (skb_protocol (skb, false)), - haddr,NULL , skb->len); - -if (err <0 ) +if (dev_hard_header (skb, dev,ntohs (skb_protocol (skb, false)), + haddr,NULL , skb->len) <0 ) err = -EINVAL ; }else { err = (skb_res ==NULL ) ? -EAGAIN :1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 677/752 vlan: ensure sufficient headroom in vlan_dev_hard_header()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit cd5dd68267c4238795fadaf02b3575ca3f8a6500 ]
Callers that only reserve ETH_HLEN or less (such as llc_alloc_frame()), or skbs allocated before dynamic device/headroom changes (e.g. toggling VLAN_FLAG_REORDER_HDR or bonding/team switching slaves), can reach vlan_dev_hard_header() with insufficient headroom and trigger skb_under_panic().
Use skb_cow_head() in vlan_dev_hard_header() when VLAN_FLAG_REORDER_HDR is not set to ensure sufficient headroom for the VLAN header(s) and the underlying device hard header.
Use READ_ONCE() to read dev->hard_header_len and dev->needed_headroom as they can be updated concurrently under RTNL (e.g. in vlan_transfer_features()) while vlan_dev_hard_header() runs locklessly on the transmit path. Also avoid LL_RESERVED_SPACE(dev) here so that the extra HH_DATA_MOD alignment padding does not trigger unnecessary pskb_expand_head() reallocations on inner stacked VLAN devices after the outer VLAN header has been pushed.
--- net/8021q/vlan_dev.c | 5 +++++ 1 file changed, 5 insertions(+)
net/8021q/vlan_dev.c +5 -0
@@ -53,6 +53,11 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,int rc;if (!(vlan->flags &VLAN_FLAG_REORDER_HDR )) { +unsigned int hlen =READ_ONCE (dev->hard_header_len) + +READ_ONCE (dev->needed_headroom); + +if (skb_cow_head (skb, hlen) <0 ) +return -ENOMEM ; vhdr =skb_push (skb,VLAN_HLEN ); vlan_tci = vlan->vlan_id;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 678/752 autofs: fix sbi->pipe file reference leak in autofs_kill_sb()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
[ Upstream commit aa5e44b29ffe4eaa08cc2237fd65bc2596bc023e ]
When autofs_fill_super() fails before clearing AUTOFS_SBI_CATATONIC (for example, when find_get_pid() fails on an invalid pgrp mount option, or when an fs_context is closed before mounting), deactivate_locked_super() invokes autofs_kill_sb() -> autofs_catatonic_mode(sbi).
Because AUTOFS_SBI_CATATONIC is still set in sbi->flags, autofs_catatonic_mode() returns early without calling fput(sbi->pipe), permanently leaking the pipe struct file reference.
Explicitly release sbi->pipe in autofs_kill_sb() if it is still non-NULL after autofs_catatonic_mode().
--- fs/autofs/inode.c | 4 ++++ 1 file changed, 4 insertions(+)
fs/autofs/inode.c +4 -0
@@ -49,6 +49,10 @@ void autofs_kill_sb(struct super_block *sb)if (sbi) {/* Free wait queues, close pipe */ autofs_catatonic_mode (sbi); +if (sbi->pipe) { +fput (sbi->pipe); + sbi->pipe =NULL ; + }put_pid (sbi->oz_pgrp); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 679/752 rculist: add list_splice_rcu() for private lists
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit f902877b635551513729bdf9a8d1422c4aab7741 ]
This patch adds a helper function, list_splice_rcu(), to safely splice a private (non-RCU-protected) list into an RCU-protected list.
The function ensures that only the pointer visible to RCU readers (prev->next) is updated using rcu_assign_pointer(), while the rest of the list manipulations are performed with regular assignments, as the source list is private and not visible to concurrent RCU readers.
This is useful for moving elements from a private list into a global RCU-protected list, ensuring safe publication for RCU readers. Subsystems with some sort of batching mechanism from userspace can benefit from this new function.
The function __list_splice_rcu() has been added for clarity and to follow the same pattern as in the existing list_splice*() interfaces, where there is a check to ensure that the list to splice is not empty. Note that __list_splice_rcu() has no documentation for this reason.
--- include/linux/rculist.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/linux/rculist.h +29 -0
@@ -204,6 +204,35 @@ static inline void list_replace_rcu(struct list_head *old, old->prev =LIST_POISON2 ; } +static inline void __list_splice_rcu (struct list_head *list, +struct list_head *prev, +struct list_head *next) +{ +struct list_head *first = list->next; +struct list_head *last = list->prev; + + last->next = next; + first->prev = prev; + next->prev = last; +rcu_assign_pointer (list_next_rcu (prev), first); +} + +/** +* list_splice_rcu - splice a non-RCU list into an RCU-protected list, +* designed for stacks. +* @list: the non RCU-protected list to splice +* @head: the place in the existing RCU-protected list to splice +* +* The list pointed to by @head can be RCU-read traversed concurrently with +* this function. +*/ +static inline void list_splice_rcu (struct list_head *list, +struct list_head *head) +{ +if (!list_empty (list)) +__list_splice_rcu (list, head, head->next); +} +/** * __list_splice_init_rcu - join an RCU-protected list into an existing list. * @list: the RCU-protected list to splice
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 680/752 netfilter: nf_tables: join hook list via splice_list_rcu() in commit phase
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit a6134e62dba2ea4f760b29d5226907f447c92400 ]
Publish new hooks in the list into the basechain/flowtable using splice_list_rcu() to ensure netlink dump list traversal via rcu is safe while concurrent ruleset update is going on.
--- net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +2 -2
@@ -9707,8 +9707,8 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb)nft_trans_flowtable (trans), &nft_trans_flowtable_hooks (trans), NFT_MSG_NEWFLOWTABLE); -list_splice (&nft_trans_flowtable_hooks (trans), - &nft_trans_flowtable (trans)->hook_list); +list_splice_rcu (&nft_trans_flowtable_hooks (trans), + &nft_trans_flowtable (trans)->hook_list); }else {nft_clear (net,nft_trans_flowtable (trans)); nf_tables_flowtable_notify(&trans->ctx,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 681/752 KVM: x86/mmu: Use a bool for direct
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Matlack <[email protected]>
commit 27a59d57f073f21f029df1517c2c0a1abea5b0ce upstream.
The parameter "direct" can either be true or false, and all of the callers pass in a bool variable or true/false literal, so just use the type bool.
No functional change intended.
Message-Id: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +2 -2
@@ -1738,7 +1738,7 @@ static void drop_parent_pte(struct kvm_mmu_page *sp,mmu_spte_clear_no_track (parent_pte); } -static struct kvm_mmu_page *kvm_mmu_alloc_page (struct kvm_vcpu *vcpu,int direct) +static struct kvm_mmu_page *kvm_mmu_alloc_page (struct kvm_vcpu *vcpu,bool direct) {struct kvm_mmu_page *sp;
@@ -2079,7 +2079,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,gfn_t gfn, gva_t gaddr, unsigned level, - int direct, + bool direct, unsigned int access) { bool direct_mmu = vcpu->arch.mmu->direct_map;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 682/752 KVM: x86/mmu: Stop passing "direct" to mmu_alloc_root()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Matlack <[email protected]>
commit 86938ab6925b8fe174ca6abf397e6ea9d3c054a4 upstream.
The "direct" argument is vcpu->arch.mmu->root_role.direct, because unlike non-root page tables, it's impossible to have a direct root in an indirect MMU. So just use that.
Message-Id: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
arch/x86/kvm/mmu/mmu.c +6 -5
@@ -3439,8 +3439,9 @@ static int mmu_check_root(struct kvm_vcpu *vcpu, gfn_t root_gfn) }static hpa_t mmu_alloc_root (struct kvm_vcpu *vcpu,gfn_t gfn,gva_t gva, -u8 level,bool direct) +u8 level) { +bool direct = vcpu->arch.mmu->mmu_role.base.direct;struct kvm_mmu_page *sp; sp =kvm_mmu_get_page (vcpu, gfn, gva, level, direct,ACC_ALL );
@@ -3466,7 +3467,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu) root =kvm_tdp_mmu_get_vcpu_root_hpa (vcpu); mmu->root_hpa = root; }else if (shadow_root_level >=PT64_ROOT_4LEVEL ) { - root =mmu_alloc_root (vcpu,0 ,0 , shadow_root_level, true); + root =mmu_alloc_root (vcpu,0 ,0 , shadow_root_level); mmu->root_hpa = root; }else if (shadow_root_level ==PT32E_ROOT_LEVEL ) {if (WARN_ON_ONCE (!mmu->pae_root)) {
@@ -3478,7 +3479,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)WARN_ON_ONCE (IS_VALID_PAE_ROOT (mmu->pae_root[i])); root =mmu_alloc_root (vcpu, i << (30 -PAGE_SHIFT ), - i <<30 ,PT32_ROOT_LEVEL , true); + i <<30 ,PT32_ROOT_LEVEL ); mmu->pae_root[i] = root |PT_PRESENT_MASK | shadow_me_mask; }
@@ -3541,7 +3542,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)*/ if (mmu->root_level >=PT64_ROOT_4LEVEL ) { root =mmu_alloc_root (vcpu, root_gfn,0 , - mmu->shadow_root_level, false); + mmu->shadow_root_level); mmu->root_hpa = root; goto set_root_pgd; }
@@ -3587,7 +3588,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) } root =mmu_alloc_root (vcpu, root_gfn, i <<30 , -PT32_ROOT_LEVEL , false); +PT32_ROOT_LEVEL ); mmu->pae_root[i] = root | pm_mask; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 683/752 KVM: MMU: update comment on the number of page role combinations
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Bonzini <[email protected]>
commit dc1ce45575b3401102568dd60ba8894849d1d64b upstream.
Fix the number of bits in the role, and simplify the explanation of why several bits or combinations of bits are redundant.
--- arch/x86/include/asm/kvm_host.h | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
arch/x86/include/asm/kvm_host.h +18 -12
@@ -292,19 +292,25 @@ struct kvm_kernel_irq_routing_entry;* the number of unique SPs that can theoretically be created is 2^n, where n * is the number of bits that are used to compute the role. * -* But, even though there are 18 bits in the mask below, not all combinations -* of modes and flags are possible. The maximum number of possible upper-level -* shadow pages for a single gfn is in the neighborhood of 2^13. +* But, even though there are 19 bits in the mask below, not all combinations +* of modes and flags are possible: * -* - invalid shadow pages are not accounted. -* - level is effectively limited to four combinations, not 16 as the number -* bits would imply, as 4k SPs are not tracked (allowed to go unsync). -* - level is effectively unused for non-PAE paging because there is exactly -* one upper level (see 4k SP exception above). -* - quadrant is used only for non-PAE paging and is exclusive with -* gpte_is_8_bytes. -* - execonly and ad_disabled are used only for nested EPT, which makes it -* exclusive with quadrant. +* - invalid shadow pages are not accounted, so the bits are effectively 18 +* +* - quadrant will only be used if gpte_is_8_bytes=0 (non-PAE paging); +* execonly and ad_disabled are only used for nested EPT which has +* gpte_is_8_bytes=1. Therefore, 2 bits are always unused. +* +* - the 4 bits of level are effectively limited to the values 2/3/4/5, +* as 4k SPs are not tracked (allowed to go unsync). In addition non-PAE +* paging has exactly one upper level, making level completely redundant +* when gpte_is_8_bytes=0. +* +* - on top of this, smep_andnot_wp and smap_andnot_wp are only set if +* cr0_wp=0, therefore these three bits only give rise to 5 possibilities. +* +* Therefore, the maximum number of possible upper-level shadow pages for a +* single gfn is a bit less than 2^13. */ union kvm_mmu_page_role {u32 word;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 684/752 KVM: X86: Remove useless code to set role.gpte_is_8_bytes when role.direct
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lai Jiangshan <[email protected]>
commit 41e35604eaff2266ba8523787ebe99c5ca4c4045 upstream.
role.gpte_is_8_bytes is unused when role.direct; there is no point in changing a bit in the role, the value that was set when the MMU is initialized is just fine.
Message-Id: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 2 -- 1 file changed, 2 deletions(-)
arch/x86/kvm/mmu/mmu.c +0 -2
@@ -2093,8 +2093,6 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, role = vcpu->arch.mmu->mmu_role.base; role.level = level; role.direct = direct; -if (role.direct) - role.gpte_is_8_bytes = true; role.access = access;if (!direct_mmu && vcpu->arch.mmu->root_level <=PT32_ROOT_LEVEL ) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 685/752 KVM: X86: Calculate quadrant when !role.gpte_is_8_bytes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lai Jiangshan <[email protected]>
commit b46a13cb7ea1137b2e01dfaafcacd5cd79db8390 upstream.
role.quadrant is only valid when gpte size is 4 bytes and only be calculated when gpte size is 4 bytes.
Although "vcpu->arch.mmu->root_level <= PT32_ROOT_LEVEL" also means gpte size is 4 bytes, but using "!role.gpte_is_8_bytes" is clearer
Message-Id: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/mmu/mmu.c +1 -1
@@ -2094,7 +2094,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, role.level = level; role.direct = direct; role.access = access; -if (!direct_mmu && vcpu->arch.mmu->root_level <=PT32_ROOT_LEVEL ) { +if (!direct_mmu && !role.gpte_is_8_bytes) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); quadrant &= (1 << ((PT32_PT_BITS -PT64_PT_BITS ) * level)) -1 ; role.quadrant = quadrant;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 686/752 KVM: X86: Rename gpte_is_8_bytes to has_4_byte_gpte and invert the direction
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lai Jiangshan <[email protected]>
commit bb3b394d35e80d7a58ce015191e4960a13f54ba5 upstream.
This bit is very close to mean "role.quadrant is not in use", except that it is false also when the MMU is mapping guest physical addresses directly. In that case, role.quadrant is indeed not in use, but there are no guest PTEs at all.
Changing the name and direction of the bit removes the special case, since a guest with paging disabled, or not considering guest paging structures as is the case for two-dimensional paging, does not have to deal with 4-byte guest PTEs.
Message-Id: <[email protected]>
--- Documentation/virt/kvm/mmu.rst | 8 ++++---- arch/x86/include/asm/kvm_host.h | 8 ++++---- arch/x86/kvm/mmu/mmu.c | 12 ++++++------ arch/x86/kvm/mmu/mmutrace.h | 2 +- arch/x86/kvm/mmu/tdp_mmu.c | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-)
Documentation/virt/kvm/mmu.rst +4 -4
@@ -161,7 +161,7 @@ Shadow pages contain the following information: If clear, this page corresponds to a guest page table denoted by the gfn field. role.quadrant: - When role.gpte_is_8_bytes=0, the guest uses 32-bit gptes while the host uses 64-bit + When role.has_4_byte_gpte=1, the guest uses 32-bit gptes while the host uses 64-bit sptes. That means a guest page table contains more ptes than the host, so multiple shadow pages are needed to shadow one guest page. For first-level shadow pages, role.quadrant can be 0 or 1 and denotes the
@@ -177,9 +177,9 @@ Shadow pages contain the following information: The page is invalid and should not be used. It is a root page that is currently pinned (by a cpu hardware register pointing to it); once it is unpinned it will be destroyed. - role.gpte_is_8_bytes: - Reflects the size of the guest PTE for which the page is valid, i.e. '1' - if 64-bit gptes are in use, '0' if 32-bit gptes are in use. + role.has_4_byte_gpte: + Reflects the size of the guest PTE for which the page is valid, i.e. '0' + if direct map or 64-bit gptes are in use, '1' if 32-bit gptes are in use. role.efer_nx: Contains the value of efer.nx for which the page is valid. role.cr0_wp:
arch/x86/include/asm/kvm_host.h +4 -4
@@ -297,14 +297,14 @@ struct kvm_kernel_irq_routing_entry;* * - invalid shadow pages are not accounted, so the bits are effectively 18 * -* - quadrant will only be used if gpte_is_8_bytes=0 (non-PAE paging); +* - quadrant will only be used if has_4_byte_gpte=1 (non-PAE paging); * execonly and ad_disabled are only used for nested EPT which has -* gpte_is_8_bytes=1. Therefore, 2 bits are always unused. +* has_4_byte_gpte=0. Therefore, 2 bits are always unused. * * - the 4 bits of level are effectively limited to the values 2/3/4/5, * as 4k SPs are not tracked (allowed to go unsync). In addition non-PAE * paging has exactly one upper level, making level completely redundant -* when gpte_is_8_bytes=0. +* when has_4_byte_gpte=1. * * - on top of this, smep_andnot_wp and smap_andnot_wp are only set if * cr0_wp=0, therefore these three bits only give rise to 5 possibilities.
@@ -316,7 +316,7 @@ union kvm_mmu_page_role {u32 word;struct {unsigned level:4 ; -unsigned gpte_is_8_bytes:1 ; +unsigned has_4_byte_gpte:1 ;unsigned quadrant:2 ;unsigned direct:1 ;unsigned access:3 ;
arch/x86/kvm/mmu/mmu.c +6 -6
@@ -2094,7 +2094,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, role.level = level; role.direct = direct; role.access = access; -if (!direct_mmu && !role.gpte_is_8_bytes) { +if (role.has_4_byte_gpte) { quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); quadrant &= (1 << ((PT32_PT_BITS -PT64_PT_BITS ) * level)) -1 ; role.quadrant = quadrant;
@@ -4840,7 +4840,7 @@ kvm_calc_tdp_mmu_root_page_role(struct kvm_vcpu *vcpu, role.base.ad_disabled = (shadow_accessed_mask ==0 ); role.base.level =kvm_mmu_get_tdp_level (vcpu); role.base.direct = true; - role.base.gpte_is_8_bytes = true; + role.base.has_4_byte_gpte = false;return role; }
@@ -4885,7 +4885,7 @@ kvm_calc_shadow_root_page_role_common(struct kvm_vcpu *vcpu, role.base.smep_andnot_wp = role.ext.cr4_smep && !____is_cr0_wp (regs); role.base.smap_andnot_wp = role.ext.cr4_smap && !____is_cr0_wp (regs); - role.base.gpte_is_8_bytes =____is_cr0_pg (regs) &&____is_cr4_pae (regs); + role.base.has_4_byte_gpte =____is_cr0_pg (regs) && !____is_cr4_pae (regs);return role; }
@@ -4984,7 +4984,7 @@ kvm_calc_shadow_ept_root_page_role(struct kvm_vcpu *vcpu, bool accessed_dirty, role.base.smm = vcpu->arch.root_mmu.mmu_role.base.smm; role.base.level = level; - role.base.gpte_is_8_bytes = true; + role.base.has_4_byte_gpte = false; role.base.direct = false; role.base.ad_disabled = !accessed_dirty; role.base.guest_mode = true;
@@ -5267,7 +5267,7 @@ static bool detect_write_misaligned(struct kvm_mmu_page *sp, gpa_t gpa, gpa, bytes, sp->role.word); offset =offset_in_page (gpa); - pte_size = sp->role.gpte_is_8_bytes ?8 :4 ; + pte_size = sp->role.has_4_byte_gpte ?4 :8 ;/* * Sometimes, the OS only writes the last one bytes to update status
@@ -5291,7 +5291,7 @@ static u64 *get_written_sptes(struct kvm_mmu_page *sp, gpa_t gpa, int *nspte) page_offset =offset_in_page (gpa); level = sp->role.level; *nspte =1 ; -if (!sp->role.gpte_is_8_bytes) { +if (sp->role.has_4_byte_gpte) { page_offset <<=1 ;/* 32->64 */ /* * A 32-bit pde maps 4MB while the shadow pdes map
arch/x86/kvm/mmu/mmutrace.h +1 -1
@@ -35,7 +35,7 @@" %snxe %sad root %u %s%c" , \ __entry->mmu_valid_gen, \ __entry->gfn, role.level, \ - role.gpte_is_8_bytes ?8 :4 , \ + role.has_4_byte_gpte ?4 :8 , \ role.quadrant, \ role.direct ?" direct" :"" , \ access_str[role.access], \
arch/x86/kvm/mmu/tdp_mmu.c +1 -1
@@ -179,7 +179,7 @@ static union kvm_mmu_page_role page_role_for_level(struct kvm_vcpu *vcpu, role = vcpu->arch.mmu->mmu_role.base; role.level = level; role.direct = true; - role.gpte_is_8_bytes = true; + role.has_4_byte_gpte = false; role.access =ACC_ALL ;return role;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 687/752 KVM: x86/mmu: Derive shadow MMU page role from parent
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Matlack <[email protected]>
commit 2e65e842c57d72e9a573ba42bc2055b7f626ea1f upstream.
Instead of computing the shadow page role from scratch for every new page, derive most of the information from the parent shadow page. This eliminates the dependency on the vCPU root role to allocate shadow page tables, and reduces the number of parameters to kvm_mmu_get_page().
Preemptively split out the role calculation to a separate function for use in a following commit.
Note that when calculating the MMU root role, we can take @role.passthrough, @role.direct, and @role.access directly from @vcpu->arch.mmu->root_role. Only @role.level and @role.quadrant still must be overridden for PAE page directories, when shadowing 32-bit guest page tables with PAE page tables.
No functional change intended.
Message-Id: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 97 +++++++++++++++++++++++----------- arch/x86/kvm/mmu/paging_tmpl.h | 9 ++-- 2 files changed, 71 insertions(+), 35 deletions(-)
arch/x86/kvm/mmu/mmu.c +66 -31
@@ -2075,31 +2075,15 @@ static void clear_sp_write_flooding_count(u64 *spte)__clear_sp_write_flooding_count (sptep_to_sp (spte)); } -static struct kvm_mmu_page *kvm_mmu_get_page (struct kvm_vcpu *vcpu, -gfn_t gfn, -gva_t gaddr, -unsigned level, -bool direct, -unsigned int access) +static struct kvm_mmu_page *kvm_mmu_get_page (struct kvm_vcpu *vcpu,gfn_t gfn, +union kvm_mmu_page_role role) {bool direct_mmu = vcpu->arch.mmu->direct_map; -union kvm_mmu_page_role role;struct hlist_head *sp_list; -unsigned quadrant;struct kvm_mmu_page *sp;int collisions =0 ;LIST_HEAD (invalid_list); - role = vcpu->arch.mmu->mmu_role.base; - role.level = level; - role.direct = direct; - role.access = access; -if (role.has_4_byte_gpte) { - quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level)); - quadrant &= (1 << ((PT32_PT_BITS -PT64_PT_BITS ) * level)) -1 ; - role.quadrant = quadrant; - } - sp_list = &vcpu->kvm->arch.mmu_page_hash[kvm_page_table_hashfn (gfn)];for_each_valid_sp (vcpu->kvm, sp, sp_list) {if (sp->gfn != gfn) {
@@ -2117,7 +2101,7 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,* Unsync pages must not be left as is, because the new * upper-level page will be write-protected. */ -if (level >PG_LEVEL_4K && sp->unsync) +if (role.level >PG_LEVEL_4K && sp->unsync)kvm_mmu_prepare_zap_page (vcpu->kvm, sp, &invalid_list);continue ;
@@ -2155,14 +2139,14 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu, ++vcpu->kvm->stat.mmu_cache_miss; - sp =kvm_mmu_alloc_page (vcpu, direct); + sp =kvm_mmu_alloc_page (vcpu, role.direct); sp->gfn = gfn; sp->role = role;hlist_add_head (&sp->hash_link, sp_list); -if (!direct) { +if (!role.direct) {account_shadowed (vcpu->kvm, sp); -if (level ==PG_LEVEL_4K &&rmap_write_protect (vcpu, gfn)) +if (role.level ==PG_LEVEL_4K &&rmap_write_protect (vcpu, gfn))kvm_flush_remote_tlbs_with_address (vcpu->kvm, gfn,1 ); }trace_kvm_mmu_get_page (sp, true);
@@ -2174,6 +2158,54 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,return sp; } +static union kvm_mmu_page_role kvm_mmu_child_role (u64 *sptep,bool direct,unsigned int access) +{ +struct kvm_mmu_page *parent_sp =sptep_to_sp (sptep); +union kvm_mmu_page_role role; + + role = parent_sp->role; + role.level--; + role.access = access; + role.direct = direct; + +/* +* If the guest has 4-byte PTEs then that means it's using 32-bit, +* 2-level, non-PAE paging. KVM shadows such guests with PAE paging +* (i.e. 8-byte PTEs). The difference in PTE size means that KVM must +* shadow each guest page table with multiple shadow page tables, which +* requires extra bookkeeping in the role. +* +* Specifically, to shadow the guest's page directory (which covers a +* 4GiB address space), KVM uses 4 PAE page directories, each mapping +* 1GiB of the address space. @role.quadrant encodes which quarter of +* the address space each maps. +* +* To shadow the guest's page tables (which each map a 4MiB region), KVM +* uses 2 PAE page tables, each mapping a 2MiB region. For these, +* @role.quadrant encodes which half of the region they map. +* +* Note, the 4 PAE page directories are pre-allocated and the quadrant +* assigned in mmu_alloc_root(). So only page tables need to be handled +* here. +*/ +if (role.has_4_byte_gpte) { +WARN_ON_ONCE (role.level !=PG_LEVEL_4K ); + role.quadrant = (sptep - parent_sp->spt) %2 ; + } + +return role; +} + +static struct kvm_mmu_page *kvm_mmu_get_child_sp (struct kvm_vcpu *vcpu, +u64 *sptep,gfn_t gfn, +bool direct,unsigned int access) +{ +union kvm_mmu_page_role role; + + role =kvm_mmu_child_role (sptep, direct, access); +return kvm_mmu_get_page (vcpu, gfn, role); +} +static void shadow_walk_init_using_root (struct kvm_shadow_walk_iterator *iterator,struct kvm_vcpu *vcpu,hpa_t root,u64 addr)
@@ -3041,8 +3073,7 @@ static int direct_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,if (is_shadow_present_pte (*it.sptep))continue ; - sp =kvm_mmu_get_page (vcpu, base_gfn, it.addr, - it.level -1 , true,ACC_ALL ); + sp =kvm_mmu_get_child_sp (vcpu, it.sptep, base_gfn, true,ACC_ALL );link_shadow_page (vcpu, it.sptep, sp); if (is_tdp && huge_page_disallowed &&
@@ -3436,13 +3467,18 @@ static int mmu_check_root(struct kvm_vcpu *vcpu, gfn_t root_gfn)return ret; } -static hpa_t mmu_alloc_root (struct kvm_vcpu *vcpu,gfn_t gfn,gva_t gva, +static hpa_t mmu_alloc_root (struct kvm_vcpu *vcpu,gfn_t gfn,int quadrant,u8 level) { -bool direct = vcpu->arch.mmu->mmu_role.base.direct; +union kvm_mmu_page_role role = vcpu->arch.mmu->mmu_role.base;struct kvm_mmu_page *sp; - sp =kvm_mmu_get_page (vcpu, gfn, gva, level, direct,ACC_ALL ); + role.level = level; + +if (role.has_4_byte_gpte) + role.quadrant = quadrant; + + sp =kvm_mmu_get_page (vcpu, gfn, role); ++sp->root_count;return __pa (sp->spt);
@@ -3476,8 +3512,8 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)for (i =0 ; i <4 ; ++i) {WARN_ON_ONCE (IS_VALID_PAE_ROOT (mmu->pae_root[i])); - root =mmu_alloc_root (vcpu, i << (30 -PAGE_SHIFT ), - i <<30 ,PT32_ROOT_LEVEL ); + root =mmu_alloc_root (vcpu, i << (30 -PAGE_SHIFT ), i, +PT32_ROOT_LEVEL ); mmu->pae_root[i] = root |PT_PRESENT_MASK | shadow_me_mask; }
@@ -3585,8 +3621,7 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) root_gfn = pdptrs[i] >>PAGE_SHIFT ; } - root =mmu_alloc_root (vcpu, root_gfn, i <<30 , -PT32_ROOT_LEVEL ); + root =mmu_alloc_root (vcpu, root_gfn, i,PT32_ROOT_LEVEL ); mmu->pae_root[i] = root | pm_mask; }
arch/x86/kvm/mmu/paging_tmpl.h +5 -4
@@ -704,8 +704,9 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,if (!is_shadow_present_pte (*it.sptep)) { table_gfn = gw->table_gfn[it.level -2 ]; access = gw->pt_access[it.level -2 ]; - sp =kvm_mmu_get_page (vcpu, table_gfn, addr, - it.level-1 , false, access); + sp =kvm_mmu_get_child_sp (vcpu, it.sptep, table_gfn, + false, access); +/* * We must synchronize the pagetable before linking it * because the guest doesn't need to flush tlb when
@@ -763,8 +764,8 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,drop_large_spte (vcpu, it.sptep);if (!is_shadow_present_pte (*it.sptep)) { - sp =kvm_mmu_get_page (vcpu, base_gfn, addr, - it.level -1 , true, direct_access); + sp =kvm_mmu_get_child_sp (vcpu, it.sptep, base_gfn, + true, direct_access);link_shadow_page (vcpu, it.sptep, sp);if (huge_page_disallowed && req_level >= it.level)account_huge_nx_page (vcpu->kvm, sp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 688/752 KVM: x86/mmu: Always pass 0 for @quadrant when gptes are 8 bytes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Matlack <[email protected]>
commit 7f49777550e55a7d6832cbb0873f48f91c175b9c upstream.
The quadrant is only used when gptes are 4 bytes, but mmu_alloc_{direct,shadow}_roots() pass in a non-zero quadrant for PAE page directories regardless. Make this less confusing by only passing in a non-zero quadrant when it is actually necessary.
Message-Id: <[email protected]>
--- arch/x86/kvm/mmu/mmu.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
arch/x86/kvm/mmu/mmu.c +14 -6
@@ -3474,9 +3474,10 @@ static hpa_t mmu_alloc_root(struct kvm_vcpu *vcpu, gfn_t gfn, int quadrant,struct kvm_mmu_page *sp; role.level = level; + role.quadrant = quadrant; -if (role.has_4_byte_gpte) - role.quadrant = quadrant; +WARN_ON_ONCE (quadrant && !role.has_4_byte_gpte); +WARN_ON_ONCE (role.direct && role.has_4_byte_gpte); sp =kvm_mmu_get_page (vcpu, gfn, role); ++sp->root_count;
@@ -3512,7 +3513,7 @@ static int mmu_alloc_direct_roots(struct kvm_vcpu *vcpu)for (i =0 ; i <4 ; ++i) {WARN_ON_ONCE (IS_VALID_PAE_ROOT (mmu->pae_root[i])); - root =mmu_alloc_root (vcpu, i << (30 -PAGE_SHIFT ), i, + root =mmu_alloc_root (vcpu, i << (30 -PAGE_SHIFT ),0 ,PT32_ROOT_LEVEL ); mmu->pae_root[i] = root |PT_PRESENT_MASK | shadow_me_mask;
@@ -3536,9 +3537,8 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)struct kvm_mmu *mmu = vcpu->arch.mmu;u64 pdptrs[4 ], pm_mask;gfn_t root_gfn, root_pgd; +int quadrant, i, r;hpa_t root; -unsigned i; -int r; root_pgd = mmu->get_guest_pgd (vcpu); root_gfn = root_pgd >>PAGE_SHIFT ;
@@ -3621,7 +3621,15 @@ static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu) root_gfn = pdptrs[i] >>PAGE_SHIFT ; } - root =mmu_alloc_root (vcpu, root_gfn, i,PT32_ROOT_LEVEL ); +/* +* If shadowing 32-bit non-PAE page tables, each PAE page +* directory maps one quarter of the guest's non-PAE page +* directory. Othwerise each PAE page direct shadows one guest +* PAE page directory so that quadrant should be 0. +*/ + quadrant = mmu->mmu_role.base.has_4_byte_gpte ? i :0 ; + + root =mmu_alloc_root (vcpu, root_gfn, quadrant,PT32_ROOT_LEVEL ); mmu->pae_root[i] = root | pm_mask; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 689/752 KVM: x86/mmu: pull call to drop_large_spte() into __link_shadow_page()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Bonzini <[email protected]>
commit 0cd8dc739833080aa0813cbd94d907a93e3a14c3 upstream.
Before allocating a child shadow page table, all callers check whether the parent already points to a huge page and, if so, they drop that SPTE. This is done by drop_large_spte().
However, dropping the large SPTE is really only necessary before the sp is installed. While the sp is returned by kvm_mmu_get_child_sp(), installing it happens later in __link_shadow_page(). Move the call there instead of having it in each and every caller.
To ensure that the shadow page is not linked twice if it was present, do _not_ opportunistically make kvm_mmu_get_child_sp() idempotent:
instead, return an error value if the shadow page already existed. This is a bit more verbose, but clearer than NULL.
Finally, now that the drop_large_spte() name is not taken anymore, remove the two underscores in front of __drop_large_spte().
--- arch/x86/kvm/mmu/mmu.c | 49 +++++++++++++++++++--------------- arch/x86/kvm/mmu/paging_tmpl.h | 29 +++++++++----------- 2 files changed, 40 insertions(+), 38 deletions(-)
arch/x86/kvm/mmu/mmu.c +27 -22
@@ -1180,26 +1180,16 @@ static void drop_spte(struct kvm *kvm, u64 *sptep)rmap_remove (kvm, sptep); } - -static bool __drop_large_spte (struct kvm *kvm,u64 *sptep) +static void drop_large_spte (struct kvm *kvm,u64 *sptep) { -if (is_large_pte (*sptep)) { -WARN_ON (sptep_to_sp (sptep)->role.level ==PG_LEVEL_4K ); -drop_spte (kvm, sptep); -return true; - } - -return false; -} +struct kvm_mmu_page *sp; -static void drop_large_spte (struct kvm_vcpu *vcpu,u64 *sptep) -{ -if (__drop_large_spte (vcpu->kvm, sptep)) { -struct kvm_mmu_page *sp =sptep_to_sp (sptep); + sp =sptep_to_sp (sptep); +WARN_ON (sp->role.level ==PG_LEVEL_4K ); -kvm_flush_remote_tlbs_with_address (vcpu->kvm, sp->gfn, +drop_spte (kvm, sptep); +kvm_flush_remote_tlbs_with_address (kvm, sp->gfn,KVM_PAGES_PER_HPAGE (sp->role.level)); - } }/*
@@ -2202,6 +2192,9 @@ static struct kvm_mmu_page *kvm_mmu_get_child_sp(struct kvm_vcpu *vcpu, {union kvm_mmu_page_role role; +if (is_shadow_present_pte (*sptep) && !is_large_pte (*sptep)) +return ERR_PTR (-EEXIST ); + role =kvm_mmu_child_role (sptep, direct, access);return kvm_mmu_get_page (vcpu, gfn, role); }
@@ -2269,13 +2262,21 @@ static void shadow_walk_next(struct kvm_shadow_walk_iterator *iterator)__shadow_walk_next (iterator, *iterator->sptep); } -static void link_shadow_page (struct kvm_vcpu *vcpu,u64 *sptep, -struct kvm_mmu_page *sp) +static void __link_shadow_page (struct kvm_vcpu *vcpu, +struct kvm_mmu_memory_cache *cache,u64 *sptep, +struct kvm_mmu_page *sp) {u64 spte;BUILD_BUG_ON (VMX_EPT_WRITABLE_MASK !=PT_WRITABLE_MASK ); +/* +* If an SPTE is present already, it must be a leaf and therefore +* a large one. Drop it and flush the TLB before installing sp. +*/ +if (is_shadow_present_pte (*sptep)) +drop_large_spte (vcpu->kvm, sptep); + spte =make_nonleaf_spte (sp->spt,sp_ad_disabled (sp));mmu_spte_set (sptep, spte);
@@ -2286,6 +2287,12 @@ static void link_shadow_page(struct kvm_vcpu *vcpu, u64 *sptep,mark_unsync (sptep); } +static void link_shadow_page (struct kvm_vcpu *vcpu,u64 *sptep, +struct kvm_mmu_page *sp) +{ +__link_shadow_page (vcpu, &vcpu->arch.mmu_pte_list_desc_cache, sptep, sp); +} +static void validate_direct_spte (struct kvm_vcpu *vcpu,u64 *sptep,unsigned direct_access) {
@@ -3069,11 +3076,9 @@ static int direct_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code,if (it.level == level)break ; -drop_large_spte (vcpu, it.sptep); -if (is_shadow_present_pte (*it.sptep)) -continue ; - sp =kvm_mmu_get_child_sp (vcpu, it.sptep, base_gfn, true,ACC_ALL ); +if (sp ==ERR_PTR (-EEXIST )) +continue ;link_shadow_page (vcpu, it.sptep, sp); if (is_tdp && huge_page_disallowed &&
arch/x86/kvm/mmu/paging_tmpl.h +13 -16
@@ -698,15 +698,13 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,gfn_t table_gfn;clear_sp_write_flooding_count (it.sptep); -drop_large_spte (vcpu, it.sptep); - sp =NULL ; -if (!is_shadow_present_pte (*it.sptep)) { - table_gfn = gw->table_gfn[it.level -2 ]; - access = gw->pt_access[it.level -2 ]; - sp =kvm_mmu_get_child_sp (vcpu, it.sptep, table_gfn, - false, access); + table_gfn = gw->table_gfn[it.level -2 ]; + access = gw->pt_access[it.level -2 ]; + sp =kvm_mmu_get_child_sp (vcpu, it.sptep, table_gfn, + false, access); +if (sp !=ERR_PTR (-EEXIST )) {/* * We must synchronize the pagetable before linking it * because the guest doesn't need to flush tlb when
@@ -735,7 +733,7 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,if (FNAME (gpte_changed)(vcpu, gw, it.level -1 )) goto out_gpte_changed; -if (sp) +if (sp !=ERR_PTR (-EEXIST ))link_shadow_page (vcpu, it.sptep, sp); }
@@ -761,15 +759,14 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, gpa_t addr,validate_direct_spte (vcpu, it.sptep, direct_access); -drop_large_spte (vcpu, it.sptep); + sp =kvm_mmu_get_child_sp (vcpu, it.sptep, base_gfn, + true, direct_access); +if (sp ==ERR_PTR (-EEXIST )) +continue ; -if (!is_shadow_present_pte (*it.sptep)) { - sp =kvm_mmu_get_child_sp (vcpu, it.sptep, base_gfn, - true, direct_access); -link_shadow_page (vcpu, it.sptep, sp); -if (huge_page_disallowed && req_level >= it.level) -account_huge_nx_page (vcpu->kvm, sp); - } +link_shadow_page (vcpu, it.sptep, sp); +if (huge_page_disallowed && req_level >= it.level) +account_huge_nx_page (vcpu->kvm, sp); } ret = mmu_set_spte(vcpu, it.sptep, gw->pte_access, write_fault,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 690/752 KVM: x86: Fix shadow paging use-after-free due to unexpected GFN
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
commit 0cb2af2ea66ad8ff195c156ea690f11216285bdf upstream.
The shadow MMU computes GFNs for direct shadow pages using sp->gfn plus the SPTE index. This assumption breaks for shadow paging if the guest page tables are modified between VM entries (similar to commit aad885e77496, "KVM: x86/mmu: Drop/zap existing present SPTE even when creating an MMIO SPTE", 2026-03-27). The flow is as follows:
- a PDE is installed for a 2MB mapping, and a page in that area is accessed. KVM creates a kvm_mmu_page consisting of 512 4KB pages; the kvm_mmu_page is marked by FNAME(fetch) as direct-mapped because the guest's mapping is a huge page (and thus contiguous).
- the PDE mapping is changed from outside the guest.
- the guest accesses another page in the same 2MB area. KVM installs a new leaf SPTE and rmap entry; the SPTE uses the "correct" GFN (i.e. based on the new mapping, as changed in the previous step) but that GFN is outside of the [sp->gfn, sp->gfn + 511] range; therefore the rmap entry cannot be found and removed when the kvm_mmu_page is zapped.
- the memslot that covers the first 2MB mapping is deleted, and the kvm_mmu_page for the now-invalid GPA is zapped. However, rmap_remove() only looks at the [sp->gfn, sp->gfn + 511] range established in step 1, and fails to find the rmap entry that was recorded by step 3.
- any operation that causes an rmap walk for the same page accessed by step 3 then walks a stale rmap and dereferences a freed kvm_mmu_page. This includes dirty logging or MMU notifier invalidations (e.g., from MADV_DONTNEED).
The underlying issue is that KVM's walking of shadow PTEs assumes that if a SPTE is present when KVM wants to install a non-leaf SPTE, then the existing kvm_mmu_page must be for the correct gfn. Because the only way for the gfn to be wrong is if KVM messed up and failed to zap a SPTE... which shouldn't happen, but *actually* only happens in response to a guest write.
That bug dates back literally forever, as even the first version of KVM assumes that the GFN matches and walks into the "wrong" shadow page. However, that was only an imprecision until 2032a93d66fa ("KVM: MMU:
Don't allocate gfns page for direct mmu pages") came along.
Fix it by checking for a target gfn mismatch and zapping the existing SPTE. That way the old SP and rmap entries are gone, KVM installs the rmap in the right location, and everyone is happy.
--- arch/x86/kvm/mmu/mmu.c | 33 ++++++++++++++------------------- arch/x86/kvm/mmu/spte.h | 5 +++++ 2 files changed, 19 insertions(+), 19 deletions(-)
arch/x86/kvm/mmu/mmu.c +14 -19
@@ -188,6 +188,8 @@ static struct percpu_counter kvm_total_used_mmu_pages;static void mmu_spte_set (u64 *sptep,u64 spte);static union kvm_mmu_page_role kvm_mmu_calc_root_page_role (struct kvm_vcpu *vcpu); +static int mmu_page_zap_pte (struct kvm *kvm,struct kvm_mmu_page *sp, +u64 *spte,struct list_head *invalid_list);struct kvm_mmu_role_regs {const unsigned long cr0;
@@ -1180,18 +1182,6 @@ static void drop_spte(struct kvm *kvm, u64 *sptep)rmap_remove (kvm, sptep); } -static void drop_large_spte (struct kvm *kvm,u64 *sptep) -{ -struct kvm_mmu_page *sp; - - sp =sptep_to_sp (sptep); -WARN_ON (sp->role.level ==PG_LEVEL_4K ); - -drop_spte (kvm, sptep); -kvm_flush_remote_tlbs_with_address (kvm, sp->gfn, -KVM_PAGES_PER_HPAGE (sp->role.level)); -} -/* * Write-protect on the specified @sptep, @pt_protect indicates whether * spte write-protection is caused by protecting shadow page table.
@@ -2192,7 +2182,8 @@ static struct kvm_mmu_page *kvm_mmu_get_child_sp(struct kvm_vcpu *vcpu, {union kvm_mmu_page_role role; -if (is_shadow_present_pte (*sptep) && !is_large_pte (*sptep)) +if (is_shadow_present_pte (*sptep) && !is_large_pte (*sptep) && +spte_to_child_sp (*sptep) &&spte_to_child_sp (*sptep)->gfn == gfn)return ERR_PTR (-EEXIST ); role =kvm_mmu_child_role (sptep, direct, access);
@@ -2270,12 +2261,16 @@ static void __link_shadow_page(struct kvm_vcpu *vcpu,BUILD_BUG_ON (VMX_EPT_WRITABLE_MASK !=PT_WRITABLE_MASK ); -/* -* If an SPTE is present already, it must be a leaf and therefore -* a large one. Drop it and flush the TLB before installing sp. -*/ -if (is_shadow_present_pte (*sptep)) -drop_large_spte (vcpu->kvm, sptep); +if (is_shadow_present_pte (*sptep)) { +struct kvm_mmu_page *parent_sp; +LIST_HEAD (invalid_list); + + parent_sp =sptep_to_sp (sptep); +WARN_ON_ONCE (parent_sp->role.level ==PG_LEVEL_4K ); + +mmu_page_zap_pte (vcpu->kvm, parent_sp, sptep, &invalid_list); +kvm_mmu_remote_flush_or_zap (vcpu->kvm, &invalid_list, true); + } spte =make_nonleaf_spte (sp->spt,sp_ad_disabled (sp));
arch/x86/kvm/mmu/spte.h +5 -0
@@ -267,6 +267,11 @@ static inline bool is_executable_pte(u64 spte)return (spte & (shadow_x_mask | shadow_nx_mask)) == shadow_x_mask; } +static inline struct kvm_mmu_page *spte_to_child_sp (u64 spte) +{ +return to_shadow_page (spte &PT64_BASE_ADDR_MASK ); +} +static inline kvm_pfn_t spte_to_pfn (u64 pte) {return (pte &PT64_BASE_ADDR_MASK ) >>PAGE_SHIFT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 691/752 KVM: x86: Fix shadow paging use-after-free due to unexpected role
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paolo Bonzini <[email protected]>
[ Upstream commit 81ccda30b4e83d8f5cc4fd50503c44e3a33abfeb ]
Commit 0cb2af2ea66ad ("KVM: x86: Fix shadow paging use-after-free due to unexpected GFN") fixed a shadow paging mismatch between stored and computed GFNs; the bug could be triggered by changing a PDE mapping from outside the guest, and then deleting a memslot. The rmap_remove() call would miss entries created after the PDE change because the GFN of the leaf SPTE does not match the GFN of the struct kvm_mmu_page.
A similar hole however remains if the modified PDE points to a non-leaf page. In this case the gfn can be made to match, but the role does not
match: the original large 2MB page creates a kvm_mmu_page with direct=1, while the new 4KB needs a kvm_mmu_page with direct=0. However, kvm_mmu_get_child_sp() does not compare the role, and therefore reuses the page.
The next step is installing a leaf (4KB) SPTE on the new path which records an rmap entry under the gfn resolved by the walk. But when that child is zapped its parent kvm_mmu_page has direct=1 and kvm_mmu_page_get_gfn() computes the gfn for the 4KB page as sp->gfn + index instead of using sp->shadowed_translation[] (or sp->gfns[] in older kernels). It therefore fails to remove the recorded entry.
When the memslot is dropped the shadow page is freed but the rmap entry survives, as in the scenario that was already fixed. Code that later walks that gfn (dirty logging, MMU notifier invalidation, and so on) dereferences an sptep that lies in the freed page, causing the use-after-free.
--- arch/x86/kvm/mmu/mmu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/x86/kvm/mmu/mmu.c +6 -4
@@ -2180,13 +2180,15 @@ static struct kvm_mmu_page *kvm_mmu_get_child_sp(struct kvm_vcpu *vcpu, u64 *sptep, gfn_t gfn, bool direct, unsigned int access) { - union kvm_mmu_page_role role; + union kvm_mmu_page_role role = kvm_mmu_child_role(sptep, direct, access); -if (is_shadow_present_pte (*sptep) && !is_large_pte (*sptep) && -spte_to_child_sp (*sptep) &&spte_to_child_sp (*sptep)->gfn == gfn) +if (is_shadow_present_pte (*sptep) && + !is_large_pte (*sptep) && +spte_to_child_sp (*sptep) && +spte_to_child_sp (*sptep)->gfn == gfn && +spte_to_child_sp (*sptep)->role.word == role.word)return ERR_PTR (-EEXIST ); - role =kvm_mmu_child_role (sptep, direct, access);return kvm_mmu_get_page (vcpu, gfn, role); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 692/752 KVM: x86/mmu: WARN and clear role.invalid when creating a child shadow page
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 5ec42d57655c690234c14aece6dd3f209778c1d8 ]
Explicitly clear role.invalid when deriving a child shadow page's role from its parent to harden against bugs elsewhere in KVM, as violating KVM's invariant that invalid pages are NOT on the list of active MMU pages leads to use-after-free due to __kvm_mmu_prepare_zap_page() using list_add() instead of list_move() when processing an invalid shadow page, i.e. makes a bad situation far worse.
Yell loudly if the parent is invalid, as it means KVM has missed a validity check, i.e. KVM is attempting to map memory using an invalid/obsolete root, but continue on as the child is otherwise still a valid shadow page.
==================================================================
BUG: KASAN: slab-use-after-free in __kvm_mmu_get_shadow_page+0x1817/0x1860 [kvm] Write of size 8 at addr ff11000153dd1368 by task repro/853 CPU: 1 UID: 1000 PID: 853 Comm: repro Not tainted 7.2.0-rc2-3aec122bdcaf-next-vm #5 PREEMPT Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015 Call Trace: <TASK> dump_stack_lvl+0x4b/0x70 print_report+0x153/0x49c kasan_report+0xbc/0xf0 __kvm_mmu_get_shadow_page+0x1817/0x1860 [kvm] mmu_alloc_root+0x141/0x320 [kvm] kvm_mmu_load+0x612/0x20f0 [kvm] kvm_arch_vcpu_ioctl_run+0x3dd5/0x6150 [kvm] kvm_vcpu_ioctl+0x5e4/0x10d0 [kvm] __x64_sys_ioctl+0x131/0x1b0 do_syscall_64+0x67/0x5f0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 </TASK> Allocated by task 853: kasan_save_stack+0x20/0x40 kasan_save_track+0x14/0x30 __kasan_slab_alloc+0x5f/0x70 kmem_cache_alloc_noprof+0xfe/0x2e0 __kvm_mmu_topup_memory_cache+0x135/0x530 [kvm] paging64_page_fault+0x318/0x1e30 [kvm] kvm_mmu_do_page_fault+0x21d/0x630 [kvm] kvm_mmu_page_fault+0x18c/0x17b0 [kvm] kvm_arch_vcpu_ioctl_run+0x1f35/0x6150 [kvm] kvm_vcpu_ioctl+0x5e4/0x10d0 [kvm] __x64_sys_ioctl+0x131/0x1b0 do_syscall_64+0x67/0x5f0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 Freed by task 853: kasan_save_stack+0x20/0x40 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x43/0x70 kmem_cache_free+0xe2/0x400 kvm_mmu_commit_zap_page.part.0+0x1e2/0x310 [kvm] kvm_mmu_free_roots+0x283/0x560 [kvm] kvm_arch_vcpu_ioctl_run+0x33c8/0x6150 [kvm] kvm_vcpu_ioctl+0x5e4/0x10d0 [kvm] __x64_sys_ioctl+0x131/0x1b0 do_syscall_64+0x67/0x5f0 entry_SYSCALL_64_after_hwframe+0x4b/0x53
--- arch/x86/kvm/mmu/mmu.c | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/kvm/mmu/mmu.c +3 -0
@@ -2148,6 +2148,9 @@ static union kvm_mmu_page_role kvm_mmu_child_role(u64 *sptep, bool direct, unsig role.access = access; role.direct = direct; +WARN_ON_ONCE (role.invalid); + role.invalid =0 ; +/* * If the guest has 4-byte PTEs then that means it's using 32-bit, * 2-level, non-PAE paging. KVM shadows such guests with PAE paging
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 693/752 x86/mm: Fix check/use ordering in switch_mm_irqs_off()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephen Dolan <[email protected]>
This is a stable-specific fix. There is no single upstream commit to cherry-pick; the equivalent mainline fix is commit 83b0177a6c48 ("x86/mm: Fix SMP ordering in switch_mm_irqs_off()"), which is in v6.18 but does not apply to these trees because the surrounding code was refactored.
The backports of commit fea4e317f9e7 ("x86/mm: Eliminate window where TLB flushes may be inadvertently skipped") -- the fix for CVE-2025-37964 -- to the 6.1, 6.6 and 6.12 trees ended up with two code blocks in the wrong order relative to mainline. The fix depends on setting cpu_tlbstate.loaded_mm to LOADED_MM_SWITCHING *before* reading tlb_gen, so that a concurrent TLB shootdown either sees LOADED_MM_SWITCHING and sends the IPI, or the switching CPU sees the updated tlb_gen. In the stable trees the write of LOADED_MM_SWITCHING was placed after the tlb_gen read, so the race window fea4e317f9e7 was meant to close is still open and CVE-2025-37964 is unfixed there:
a process can be left running with stale TLB entries, which typically manifests as rare, hard-to-bisect memory corruption or segfaults.
This has been confirmed by several independent parties:
- reproduced on 6.1.y/6.6.y/6.12.y with the test program in [1], and confirmed fixed by this patch
- Seth Forshee saw segfaults on 6.12.y within ~30 minutes of running a test workload; with this patch it ran 18 hours cleanly [2]
- Greg Thelen reports 6.6.y- and 6.12.y-based test failures fixed by this patch [3]
Dave Hansen acked the patch [4] and has no objection to it going into stable [5].
The patch below is against 6.12.y; the identical change applies to 6.1.y and 6.6.y. (The cpumask_test_cpu()/smp_mb() portion of the mainline fix is not needed here because commit 209954cbc7d0 ("x86/mm/tlb: Update mm_cpumask lazily") was never backported to these trees.)
[1] https://lore.kernel.org/lkml/CAHDw0oGd0B4=uuv8NGqbUQ_ZVmSheU2bN70e4QhFXWvuAZdt2w@mail.gmail.com/
[2] https://lore.kernel.org/lkml/aZYWXe739XUJrBld@do-x1carbon/
[3] https://lore.kernel.org/lkml/CAHH2K0brx9omC9QYyB6Lio3t_1Lf8v=VaFoiaG23UgQ-aec89Q@mail.gmail.com/
[4] https://lore.kernel.org/lkml/[email protected]/
[5] https://lore.kernel.org/lkml/[email protected]/
[Lee: The v5.15.y backport of fea4e317f9e7 (12f703811af0) placed the
LOADED_MM_SWITCHING write after the tlb_gen read too, so v5.15.y suffers from the same issue. Applies cleanly]
--- arch/x86/mm/tlb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
arch/x86/mm/tlb.c +8 -8
@@ -596,6 +596,14 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,*/ cond_mitigation (tsk); +/* +* Indicate that CR3 is about to change. nmi_uaccess_okay() +* and others are sensitive to the window where mm_cpumask(), +* CR3 and cpu_tlbstate.loaded_mm are not all in sync. +*/ +this_cpu_write (cpu_tlbstate.loaded_mm,LOADED_MM_SWITCHING ); +barrier (); +/* * Stop remote flushes for the previous mm. * Skip kernel threads; we never send init_mm TLB flushing IPIs,
@@ -615,14 +623,6 @@ void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, next_tlb_gen =atomic64_read (&next->context.tlb_gen);choose_new_asid (next, next_tlb_gen, &new_asid, &need_flush); - -/* -* Indicate that CR3 is about to change. nmi_uaccess_okay() -* and others are sensitive to the window where mm_cpumask(), -* CR3 and cpu_tlbstate.loaded_mm are not all in sync. -*/ -this_cpu_write (cpu_tlbstate.loaded_mm,LOADED_MM_SWITCHING ); -barrier (); }if (need_flush) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 694/752 x86/PCI: Disable enhanced atomics on AMD NBIO 7.7 and 7.11
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
commit 4fde448225123442c5796f54b7a4400e2d3cbaf6 upstream.
Multiple users report data corruption during 64-bit DMA transfers on systems with AMD NBIO 7.7 and 7.11 controllers.
This occurs when BIOS enables AMD "enhanced atomic operations" on PCIe Root Ports. When enhanced atomics are enabled, any 64-bit DMA access may be corrupted.
Disable enhanced atomics using SMN for NBIO 7.7 and 7.11 based models.
--- arch/x86/pci/fixup.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+)
arch/x86/pci/fixup.c +99 -0
@@ -844,4 +844,103 @@ static void quirk_clear_strap_no_soft_re } }DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_AMD ,0x15b8 , quirk_clear_strap_no_soft_reset_dev2_f0); + +/* +* Enhanced atomic operations can cause corruption with 64-bit DMA +* on these devices. +*/ +#define RX_ENH_ATOMIC_EN BIT(8) + +static const u32 nbio_7_7_pcie_smn_addrs[] = { +0x111401d0 , +0x111411d0 , +0x111421d0 , +0x111431d0 , +0x111441d0 , +0x112401d0 , +0x112411d0 , +0x112421d0 , +0x112431d0 , +0x112441d0 , +0x112451d0 , +0x113401d0 , +0x114401d0 , +}; + +static const u32 nbio_7_11_pcie_smn_addrs[] = { +0x112401d0 , +0x112411d0 , +0x112421d0 , +0x112431d0 , +0x112441d0 , +0x112451d0 , +0x113401d0 , +0x113411d0 , +0x113421d0 , +0x113431d0 , +0x113441d0 , +0x113451d0 , +}; + +static void quirk_amd_nbio_enhanced_atomic (struct pci_dev *host_bridge, +const u32 *smn_addrs, +size_t nr_smn_addrs) +{ +bool changed = false; +size_t i; +u32 data; +int ret; + +for (i =0 ; i < nr_smn_addrs; i++) { + ret =amd_smn_read (0 , smn_addrs[i], &data); +if (ret) +continue ; +if (!(data &RX_ENH_ATOMIC_EN )) +continue ; + data = data & ~RX_ENH_ATOMIC_EN ; + ret =amd_smn_write (0 , smn_addrs[i], data); +if (ret) +continue ; +if (changed) +continue ; + ret =amd_smn_read (0 , smn_addrs[i], &data); +if (ret) +continue ; +if (data &RX_ENH_ATOMIC_EN ) +continue ; + changed = true; + } + +if (changed) +pci_info (host_bridge,"enhanced atomics disabled\n" ); +} + +static void quirk_amd_nbio_7_7_disable_enhanced_atomic (struct pci_dev *dev) +{ +quirk_amd_nbio_enhanced_atomic (dev, nbio_7_7_pcie_smn_addrs, +ARRAY_SIZE (nbio_7_7_pcie_smn_addrs)); +} + +static void quirk_amd_nbio_7_11_disable_enhanced_atomic (struct pci_dev *dev) +{ +quirk_amd_nbio_enhanced_atomic (dev, nbio_7_11_pcie_smn_addrs, +ARRAY_SIZE (nbio_7_11_pcie_smn_addrs)); +} + +/* Phoenix, Hawk Point (NBIO 7.7) */ +DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_AMD ,0x14E8 , + quirk_amd_nbio_7_7_disable_enhanced_atomic); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x14E8 , + quirk_amd_nbio_7_7_disable_enhanced_atomic); + +/* Strix, Krackan, Strix Halo (NBIO 7.11) */ +DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_AMD ,0x1507 , + quirk_amd_nbio_7_11_disable_enhanced_atomic); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x1507 , + quirk_amd_nbio_7_11_disable_enhanced_atomic); +DECLARE_PCI_FIXUP_FINAL (PCI_VENDOR_ID_AMD ,0x1122 , + quirk_amd_nbio_7_11_disable_enhanced_atomic); +DECLARE_PCI_FIXUP_RESUME (PCI_VENDOR_ID_AMD ,0x1122 , + quirk_amd_nbio_7_11_disable_enhanced_atomic); +#endif
Greg Kroah-Hartman
maintainerPATCH 695/752 tipc: reject invalid and unexpected GRP_ACK_MSG to prevent bc_ackers underflow
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 99cc2a62e07a44a22254d7beca9ef1f8ad886d0d upstream.
Commit 48a5fe38772b ("tipc: fix bc_ackers underflow on duplicate GRP_ACK_MSG") rejected duplicate/stale ACKs in tipc_group_proto_rcv() by returning early when less_eq(acked, m->bc_acked).
However, that check remains incomplete in two ways:
1. When grp->bc_ackers is zero (e.g. on a quiet group, when replicast ACKs were not requested, or after all expected members have already acknowledged), an unexpected GRP_ACK_MSG with acked > m->bc_acked passes less_eq() and unconditionally decrements grp->bc_ackers. Because bc_ackers is a u16, this wraps to 65535, causing tipc_group_bc_cong() to permanently report congestion and blocking all future group broadcasts on the socket.
2. During an active broadcast round (grp->bc_ackers > 0), the sender transmits packet S and advances grp->bc_snd_nxt to S + 1. Receivers increment their expected counter to S + 1 upon consuming packet S, so the only valid ACK value for the current round is strictly acked == grp->bc_snd_nxt.
However, tipc_group_update_bc_members() initializes each member's m->bc_acked to prev = grp->bc_snd_nxt - 1 (S - 1 before increment). This leaves a 2-sequence gap (S - 1 to S + 1) in sequence space. An incoming ACK is therefore neither rejected as duplicate nor prevented from decrementing grp->bc_ackers if an unexpected or stale value (such as S) is received. A member sending acked = S followed by acked = S + 1 could decrement grp->bc_ackers twice in the same round, prematurely clearing bc_ackers or underflowing it.
Fix this by:
- Dropping GRP_ACK_MSG immediately if grp->bc_ackers is zero.
- Requiring acked == grp->bc_snd_nxt and rejecting duplicates where m->bc_acked == acked. Because replicast broadcast rounds are strictly sequential, only grp->bc_snd_nxt can be acknowledged, and each member can acknowledge at most once per round.
Note that a related pre-existing issue in tipc_group_delete_member() (where grp->bc_ackers decrementing to zero upon member departure does not restore *grp->open or trigger a socket wakeup) will be addressed in a separate patch.
--- net/tipc/group.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/tipc/group.c +2 -2
@@ -797,10 +797,10 @@ void tipc_group_proto_rcv(struct tipc_grtipc_group_open (m, usr_wakeup);return ;case GRP_ACK_MSG : -if (!m) +if (!m || !grp->bc_ackers)return ; acked =msg_grp_bc_acked (hdr); -if (less_eq (acked, m->bc_acked)) +if (acked != grp->bc_snd_nxt || m->bc_acked == acked)return ; m->bc_acked = acked;if (--grp->bc_ackers)
Greg Kroah-Hartman
maintainerPATCH 696/752 sctp: discard the rest of the packet on a stale-cookie error
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aohan Mei <[email protected]>
commit 4498467a8af06cfa3d71cb04bd7c4170dec8f449 upstream.
When an association is in COOKIE-ECHOED state and the peer sends a bundled [ERROR(Stale Cookie)][DATA] packet from one of its non-primary addresses, processing the ERROR chunk takes the non-fatal stale-cookie retry path sctp_sf_do_5_2_6_stale(), which queues SCTP_CMD_DEL_NON_PRIMARY while keeping the association alive. sctp_cmd_del_non_primary() removes every non-primary transport - including the very transport this packet arrived on, which is still referenced by the receive lookup and shared by all chunks of the packet via chunk->transport.
sctp_assoc_rm_peer() does redirect asoc->peer.last_data_from away from the removed transport, but right afterwards the bundled DATA chunk makes sctp_assoc_bh_rcv() re-register asoc->peer.last_data_from = chunk->transport unconditionally, undoing the redirection with the just-removed transport.
Once the packet is done, the receive reference is dropped and the transport is RCU-freed, while the surviving association keeps the dangling last_data_from. A later FWD-TSN (or the delayed SACK timer) makes sctp_gen_sack() dereference it (->param_flags and friends), and sctp_make_sack()/sctp_outq_select_transport() may write to the freed object and link it into the live transport list. This is a use-after-free triggerable by any malicious SCTP peer (or a local unprivileged user acting as one) with no capabilities required:
BUG: KASAN: slab-use-after-free in sctp_do_sm+0x498a/0x5660
Read of size 4 at addr ffff88800e1e356c by task poc/115
Call Trace: sctp_do_sm <- sctp_assoc_bh_rcv <- sctp_inq_push <-
sctp_rcv <- ip_protocol_deliver_rcu <- ip_rcv
Allocated: sctp_transport_new <- sctp_assoc_add_peer <-
sctp_process_init (INIT-ACK processing)
Freed: kfree <- sctp_transport_destroy_rcu <- rcu_core
(call_rcu queued by sctp_transport_put at end of sctp_rcv)
The buggy address is located 364 bytes inside of freed 1024-byte
region [ffff88800e1e3400, ffff88800e1e3800), cache kmalloc-1kNote that commit 03a9d10ecf71 ("sctp: drop a chunk if its transport was removed") only covers the window between the receive lookup and the chunk processing (e.g. an ASCONF DEL-IP racing the socket backlog); here the transport is removed *while* the packet is being processed, by an earlier chunk of the same packet, so the drop in sctp_inq_push() does not reach this path. Verified with the bundled [ERROR(Stale Cookie)][DATA] + FWD-TSN reproducer: the KASAN report above still fires with that commit applied, and is gone with this patch on top.
Fix it by discarding the rest of the packet on this path, as suggested by Xin. After the stale-cookie ERROR has sent the association back to COOKIE-WAIT and removed the non-primary transports, the remaining chunks of the packet can only run against the restarted handshake while referencing the removed arrival transport through chunk->transport: besides the last_data_from registration above, sctp_cmd_setup_t2() and the sctp_make_*() reply builders would also copy that pointer into association-lifetime state that sctp_assoc_rm_peer() has already sanitized. Let the peer retransmit them, in line with what sctp_inq_push() does for chunks whose transport was removed before processing.
--- net/sctp/sm_statefuns.c | 2 ++ 1 file changed, 2 insertions(+)
net/sctp/sm_statefuns.c +2 -0
@@ -2604,6 +2604,8 @@ static enum sctp_disposition sctp_sf_do_sctp_add_cmd_sf (commands,SCTP_CMD_REPLY ,SCTP_CHUNK (reply)); +sctp_add_cmd_sf (commands,SCTP_CMD_DISCARD_PACKET ,SCTP_NULL ()); +return SCTP_DISPOSITION_CONSUME ; nomem:
Greg Kroah-Hartman
maintainerPATCH 697/752 af_packet: fix integer overflow in prb_calc_retire_blk_tmo()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dairui Zhang <[email protected]>
commit 56d82862a0a243ac14ba11b6d7b57ddc2d064b95 upstream.
prb_calc_retire_blk_tmo() computes in 32-bit int arithmetic:
mbits = (blk_size_in_bytes * 8) / (1024 * 1024);
If I'm reading the validation right, tp_block_size is user controlled and packet_set_ring() only rejects values that are <= 0 as int or not page aligned, so a 256MiB block goes right through (and alloc_one_pg_vec_page() even has a vzalloc fallback for it). 0x10000000 * 8 wraps to INT_MIN, and on a NIC reporting 1 Gbps (div == 1) the function ends up returning -2047.
The condition is actually (8 * size) mod 2^32 >= 2^31 && div == 1, so the trigger set is [256,512), [768,1024), [1280,1536) and [1792,2048) MiB. Other sizes wrap to non-negative values and faster links divide the unsigned value back below 2^31, which is why this doesn't blow up for everyone.
What makes it fatal is what happens next in init_prb_bdqc():
p1->interval_ktime = ms_to_ktime(prb_calc_retire_blk_tmo(...));
hrtimer_start(&p1->retire_blk_timer, p1->interval_ktime,
HRTIMER_MODE_REL_SOFT);A negative relative timeout expires immediately. The callback unconditionally returns HRTIMER_RESTART, and hrtimer_forward() turns the negative interval into hrtimer_resolution:
if (interval < hrtimer_resolution)
interval = hrtimer_resolution;
So the SOFT timer re-fires at the maximum rate forever, holding sk_receive_queue.lock each pass. One CPU spins in softirq until the socket is closed. Repeat with more rings and the machine is gone.
The overflow itself is ancient - it was introduced together with TPACKET_V3 in f6fb8f100b80 ("af-packet: TPACKET_V3 flexible buffer implementation."). Its effect prior to f7460d2989fa ("net:af_packet: Use hrtimer to do the retire operation", v6.18) was not as clear-cut, though: the return value was stored into an unsigned short retire_blk_tov, so a negative result was truncated, and a 0-jiffy delay loop could be programmed as well. Neither is nearly as detrimental as the immediate maximum-rate spin the hrtimer conversion turned it into.
(Unrelated to CVE-2019-20812 - that one was the ethtool failure path returning 0, which now returns DEFAULT_PRB_RETIRE_TOV.)
Reproducer, needs CAP_NET_RAW (a --network host container has it by default) and a 1 Gbps NIC (QEMU e1000 works):
int fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
bind(fd, ...);
int v = TPACKET_V3;
setsockopt(fd, SOL_PACKET, PACKET_VERSION, &v, sizeof(v));
struct tpacket_req3 req = {
.tp_block_size = 0x10000000,
.tp_block_nr = 1,
.tp_frame_size = 2048,
.tp_frame_nr = 0x10000000 / 2048,
.tp_retire_blk_tov = 0,
};
setsockopt(fd, SOL_PACKET, PACKET_RX_RING, &req, sizeof(req));Compute in 64 bits instead. The operands are already bounded by the existing validation, so nothing else changes. If you'd prefer a different fix, just say so and I'll respin.
--- net/packet/af_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
@@ -602,7 +602,7 @@ static int prb_calc_retire_blk_tmo(strucreturn DEFAULT_PRB_RETIRE_TOV ; div = ecmd.base.speed /1000 ; - mbits = (blk_size_in_bytes *8 ) / (1024 *1024 ); + mbits = (u64 )blk_size_in_bytes *8 / (1024 *1024 );if (div) mbits /= div;
Greg Kroah-Hartman
maintainerPATCH 698/752 fou: reject omitted FOU_ATTR_IPPROTO on FOU_ENCAP_DIRECT
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
commit d22609f3d13fc5baacd92c222731b03c593401db upstream.
Commit 7a9bc9e3f423 ("fou: Don't allow 0 for FOU_ATTR_IPPROTO.") added NLA_POLICY_MIN(NLA_U8, 1) to fou_nl_policy[FOU_ATTR_IPPROTO], which rejects an explicitly supplied FOU_ATTR_IPPROTO == 0 attribute with -ERANGE.
However, FOU_ATTR_IPPROTO is an optional netlink attribute. When a user sends FOU_CMD_ADD with FOU_ATTR_TYPE set to FOU_ENCAP_DIRECT and omits FOU_ATTR_IPPROTO entirely, nla_policy validation succeeds and parse_nl_config() leaves cfg->protocol as 0 (from memset(cfg, 0, sizeof(*cfg))). fou_create() then creates a FOU_ENCAP_DIRECT socket with fou->protocol == 0.
In fou_udp_recv(), returning -fou->protocol to udp_queue_rcv_one_skb() triggers IP protocol resubmission when fou->protocol > 0, whereas returning 0 tells the UDP tunnel layer that the skb was consumed without freeing it. When fou->protocol == 0, every packet received on the socket returns 0 from fou_udp_recv() and leaks the sk_buff.
Reject FOU_ENCAP_DIRECT when !cfg->protocol in fou_create() so that creating a direct encapsulation port without FOU_ATTR_IPPROTO fails with -EINVAL while leaving FOU_CMD_DEL and FOU_CMD_GET (which share parse_nl_config()) unaffected.
Tested in QEMU against Linux 7.3.0-rc3 by sending a FOU_CMD_ADD Generic Netlink request with FOU_ATTR_PORT = 5555 and FOU_ATTR_TYPE = FOU_ENCAP_DIRECT while omitting FOU_ATTR_IPPROTO. On the unfixed kernel, FOU_CMD_ADD succeeds (err = 0), FOU_CMD_GET reports fou->type = 1 and fou->protocol = 0, and sending 4000 UDP packets to 127.0.0.1:5555 leaks all 4000 sk_buffs (SUnreclaim in /proc/meminfo grows from 41456 kB to 59008 kB, +17552 kB); with this patch applied, FOU_CMD_ADD is rejected with -EINVAL (-22).
--- net/ipv4/fou_core.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/fou_core.c +4 -0
@@ -610,6 +610,10 @@ static int fou_create(struct net *net, s/* Initial for fou type */ switch (cfg->type) {case FOU_ENCAP_DIRECT : +if (!cfg->protocol) { + err = -EINVAL ; + goto error; + } tunnel_cfg.encap_rcv = fou_udp_recv; tunnel_cfg.gro_receive = fou_gro_receive; tunnel_cfg.gro_complete = fou_gro_complete;
Greg Kroah-Hartman
maintainerPATCH 699/752 workqueue: Fix NULL current_pwq deref in flush dependency check
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavankumar Kondeti <[email protected]>
commit db6365ced4d5855e321f772b240c0e473bcfcdd5 upstream.
check_flush_dependency() uses current_wq_worker() to determine whether the caller is a workqueue worker and then dereferences worker->current_pwq to test whether the current workqueue is WQ_MEM_RECLAIM.
current_wq_worker() only means that %current has PF_WQ_WORKER set. A kworker can reach check_flush_dependency() while it is not executing a work item. One such path is worker_thread() acting as the pool manager, where create_worker() does GFP_KERNEL allocation and the allocation path invokes the OOM notifier. In that state worker->current_pwq is NULL because current_pwq is set only by process_one_work() and cleared again after the work function returns.
[ 416.760634][ T375] Call trace: [ 416.760638][ T375] check_flush_dependency+0x80/0x120 (P) [ 416.760648][ T375] __flush_work+0x98/0x224 [ 416.760657][ T375] flush_work+0x30/0x44 [ 416.760665][ T375] ... [ 416.760710][ T375] blocking_notifier_call_chain+0x58/0xa0 [ 416.760719][ T375] out_of_memory+0xb4/0x458 [ 416.760730][ T375] __alloc_pages_may_oom+0x11c/0x1a8 [ 416.760739][ T375] __alloc_pages_slowpath+0x314/0x46c [ 416.760746][ T375] __alloc_frozen_pages_noprof+0x110/0x1a4 [ 416.760753][ T375] new_slab+0x12c/0x484 [ 416.760759][ T375] ___slab_alloc+0x7a8/0xc7c [ 416.760765][ T375] __slab_alloc+0x74/0xd8 [ 416.760772][ T375] __kmalloc_cache_node_noprof+0x2ac/0x304 [ 416.760779][ T375] alloc_worker+0x28/0x60 [ 416.760785][ T375] create_worker+0x4c/0x20c [ 416.760790][ T375] worker_thread+0xe8/0x2b8 [ 416.760796][ T375] kthread+0x1a8/0x200 [ 416.760805][ T375] ret_from_fork+0x10/0x20
Guard the WQ_MEM_RECLAIM-worker warning with worker->current_pwq. If the kworker is not currently executing a work item, there is no current workqueue to diagnose with that warning. The PF_MEMALLOC warning is left unchanged so explicit reclaim context flushing a !WQ_MEM_RECLAIM target is still reported.
--- kernel/workqueue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/workqueue.c +1 -1
@@ -2646,7 +2646,7 @@ static void check_flush_dependency(strucWARN_ONCE (current->flags &PF_MEMALLOC ,"workqueue: PF_MEMALLOC task %d(%s) is flushing !WQ_MEM_RECLAIM %s:%ps" , current->pid, current->comm, target_wq->name, target_func); - WARN_ONCE(worker && ((worker->current_pwq->wq->flags & + WARN_ONCE(worker && worker->current_pwq && ((worker->current_pwq->wq->flags & (WQ_MEM_RECLAIM | __WQ_LEGACY)) == WQ_MEM_RECLAIM), "workqueue: WQ_MEM_RECLAIM %s:%ps is flushing !WQ_MEM_RECLAIM %s:%ps", worker->current_pwq->wq->name, worker->current_func,
Greg Kroah-Hartman
maintainerPATCH 700/752 writeback: report a Tasks-RCU quiescent state per cgwb drain pass
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 407a5d205179a4ab186571b0e16ec42725dc77bc upstream.
cleanup_offline_cgwbs_workfn() drains a dying cgwb by calling cleanup_offline_cgwb() until it returns false, with a cond_resched() between passes. On a CONFIG_PREEMPTION kernel that cond_resched() does
nothing: _cond_resched() is a plain "return 0", and under PREEMPT_DYNAMIC the full and lazy modes disable it. Since commit 7dadeaa6e851 ("sched:
Further restrict the preemption modes") those are the only two models on the architectures with PREEMPT_LAZY support, arm64 and x86 among them, so the drain loop never reports a Tasks-RCU quiescent state.
A worker draining a cgwb with millions of attached inodes runs for minutes. On a 6.18 arm64 host in lazy mode the cgwb worker drained one dying cgroup's writeback domain for over 11 minutes. A BPF program unlink (bpf_trampoline_unlink_prog -> bpf_trampoline_update -> unregister_ftrace_direct -> ftrace_shutdown -> synchronize_rcu_tasks()) waited on that grace period while holding the trampoline mutex, 42 tasks queued behind it in D state, and the hung task detector fired at 614 s and panicked the host. Any BPF or ftrace detach during a long drain inherits the drain's length.
Fix this by calling cond_resched_tasks_rcu_qs() so we do not stall out anybody who calls sycnrhonize_rcu_tasks(). We put this in a do { } while loop because if we have many small cgroups cleanup_offline_cgwb() will return false and we will never call cond_resched_tasks_rcu_qs(), creating the same problem.
--- mm/backing-dev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/backing-dev.c +3 -2
@@ -693,8 +693,9 @@ static void cleanup_offline_cgwbs_workfncontinue ;spin_unlock_irq (&cgwb_lock); -while (cleanup_offline_cgwb (wb)) -cond_resched (); +do { +cond_resched_tasks_rcu_qs (); + }while (cleanup_offline_cgwb (wb));spin_lock_irq (&cgwb_lock);wb_put (wb);
Greg Kroah-Hartman
maintainerPATCH 701/752 fsl/fman: Fix clk reference leak in read_dts_node()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit a644f09b2090ad22a13fbcf9d141084f573108ef upstream.
of_clk_get() returns a clock with its reference count incremented, but read_dts_node() only uses it to read the rate and never calls clk_put(). The clock is not stored anywhere, so the reference cannot be released later either.
Release the clock once its rate has been read, which also covers the error path taken when the rate is zero.
--- drivers/net/ethernet/freescale/fman/fman.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/ethernet/freescale/fman/fman.c +1 -0
@@ -2778,6 +2778,7 @@ static struct fman *read_dts_node(struct } clk_rate =clk_get_rate (clk); +clk_put (clk);if (!clk_rate) {dev_err (&of_dev->dev,"%s: Failed to determine FM%d clock rate\n" , __func__, fman->dts_params.id);
Greg Kroah-Hartman
maintainerPATCH 702/752 ipv6: do not let ipv6_find_hdr() return an offset past the packet end
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Szetei <[email protected]>
commit ee319bd3a0e976af5087cbe59ebc50a66f31d202 upstream.
ipv6_find_hdr() walks the extension header chain, skipping each header by the length that header itself declares. ipv6_optlen() returns up to 2048, and the skip is never checked against skb->len, so the offset stored in *offset can point past the end of the packet.
openvswitch installs that offset as the transport header, and update_ipv6_checksum() then reads and writes the transport checksum field out of bounds:
BUG: KASAN: slab-use-after-free in inet_proto_csum_replace16+0x445/0x470 Read of size 2 at addr ffff88810b754b06 by task ovs_ipv6_oob/629 CPU: 4 UID: 1000 PID: 629 Comm: ovs_ipv6_oob Tainted: G N 7.3.0-rc3+ #348 Call Trace: inet_proto_csum_replace16+0x445/0x470 set_ipv6_addr+0x3dd/0x460 do_execute_actions+0x6a3d/0x7c40 ovs_execute_actions+0xfd/0x480 ovs_packet_cmd_execute+0xc38/0xf20 genl_rcv_msg+0x59e/0x870 netlink_rcv_skb+0x18b/0x450 genl_rcv+0x2d/0x40 netlink_unicast+0x6bc/0xa20 The buggy address belongs to the object at ffff88810b754980 which belongs to the cache skbuff_small_head of size 704 The buggy address is located 390 bytes inside of freed 704-byte region [ffff88810b754980, ffff88810b754c40)
Other callers use that offset too, so bound it here rather than in one caller.
Reject a header whose declared length does not fit in the packet. ipv6_find_hdr() already fails with -EBADMSG on a malformed chain, so this adds no new failure mode.
--- net/ipv6/exthdrs_core.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/exthdrs_core.c +3 -0
@@ -271,6 +271,9 @@ int ipv6_find_hdr(const struct sk_buff * hdrlen =ipv6_optlen (hp);if (!found) { +if (skb->len - start < hdrlen) +return -EBADMSG ; + nexthdr = hp->nexthdr; start += hdrlen; }
Greg Kroah-Hartman
maintainerPATCH 703/752 ipv6: sr: enforce exact attribute length for SEG6_ATTR_DST
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
commit 2d959c75c27f90e9ec489d18ce5ee6b852ad4741 upstream.
In seg6_genl_policy, SEG6_ATTR_DST is defined with .type = NLA_BINARY and .len = sizeof(struct in6_addr). For NLA_BINARY, .len only enforces the maximum payload length and permits shorter payloads (e.g., 0 bytes). When seg6_genl_set_tunsrc() copies sizeof(struct in6_addr) bytes via kmemdup(val, sizeof(*val), GFP_KERNEL), a short SEG6_ATTR_DST attribute triggers a 16-byte out-of-bounds read past skb->tail into uninitialized skb->head memory, which is stored in sdata->tun_src and leaked back to userspace via SEG6_CMD_GET_TUNSRC.
Switch SEG6_ATTR_DST in seg6_genl_policy to NLA_POLICY_EXACT_LEN(sizeof(struct in6_addr)) so that generic netlink validation rejects any attribute whose length is not exactly sizeof(struct in6_addr) with -ERANGE.
Tested in QEMU against Linux 7.3.0-rc3 by sending a SEG6_CMD_SET_TUNSRC Generic Netlink message with a 0-byte SEG6_ATTR_DST attribute followed by SEG6_CMD_GET_TUNSRC. On the unfixed kernel, SEG6_CMD_SET_TUNSRC succeeds (err = 0) and SEG6_CMD_GET_TUNSRC leaks 16 bytes of uninitialized kernel heap memory (tun_src = 836a61ecc4d25a1042a8d60411cfb378); with this patch applied, SEG6_CMD_SET_TUNSRC is rejected by netlink policy validation with -ERANGE (-34) and tun_src remains zeroed.
--- net/ipv6/seg6.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/ipv6/seg6.c +2 -2
@@ -140,8 +140,8 @@ out:static struct genl_family seg6_genl_family;static const struct nla_policy seg6_genl_policy[SEG6_ATTR_MAX +1 ] = { - [SEG6_ATTR_DST ] = { .type =NLA_BINARY , - .len =sizeof (struct in6_addr ) }, + [SEG6_ATTR_DST ] = +NLA_POLICY_EXACT_LEN (sizeof (struct in6_addr )), [SEG6_ATTR_DSTLEN ] = { .type =NLA_S32 , }, [SEG6_ATTR_HMACKEYID ] = { .type =NLA_U32 , }, [SEG6_ATTR_SECRET ] = { .type =NLA_BINARY , },
Greg Kroah-Hartman
maintainerPATCH 704/752 gpio: arizona: Fix runtime PM leak in arizona_gpio_direction_out()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit e9d810279f84b30738f7790c0ed15f8dd5b9024a upstream.
Switching a persistent GPIO line from input to output acquires a runtime PM reference on the parent device, but if the subsequent regmap_update_bits() fails the reference is never dropped and no later direction_in() can balance it since the direction was never changed. Drop the reference on the update failure path.
--- drivers/gpio/gpio-arizona.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpio/gpio-arizona.c +6 -2
@@ -118,8 +118,12 @@ static int arizona_gpio_direction_out(stif (value) value =ARIZONA_GPN_LVL ; -return regmap_update_bits (arizona->regmap,ARIZONA_GPIO1_CTRL + offset, -ARIZONA_GPN_DIR |ARIZONA_GPN_LVL , value); + ret =regmap_update_bits (arizona->regmap,ARIZONA_GPIO1_CTRL + offset, +ARIZONA_GPN_DIR |ARIZONA_GPN_LVL , value); +if (ret <0 && (val &ARIZONA_GPN_DIR ) && persistent) +pm_runtime_put_autosuspend (chip->parent); + +return ret; }static void arizona_gpio_set (struct gpio_chip *chip,unsigned offset,int value)
Greg Kroah-Hartman
maintainerPATCH 705/752 gpio: zynq: fix runtime PM leak on request error path
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ridham Khurana <[email protected]>
commit e9438ab5328a177c9c0e5df87eb92a7162841e98 upstream.
pm_runtime_get_sync() leaves the usage counter incremented even when it fails, and zynq_gpio_request() returns the error without dropping it.
gpiolib does not call ->free() when ->request() fails, so zynq_gpio_free(), which holds the only matching pm_runtime_put(), never runs. The reference is leaked and the controller can no longer runtime-suspend, so its clock stays enabled.
Switch to pm_runtime_resume_and_get(), which only increments the usage counter on success.
--- drivers/gpio/gpio-zynq.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/gpio/gpio-zynq.c +1 -9
@@ -789,15 +789,7 @@ static int __maybe_unused zynq_gpio_runtstatic int zynq_gpio_request (struct gpio_chip *chip,unsigned int offset) { -int ret; - - ret =pm_runtime_get_sync (chip->parent); - -/* -* If the device is already active pm_runtime_get() will return 1 on -* success, but gpio_request still needs to return 0. -*/ -return ret <0 ? ret :0 ; +return pm_runtime_resume_and_get (chip->parent); }static void zynq_gpio_free (struct gpio_chip *chip,unsigned int offset)
Greg Kroah-Hartman
maintainerPATCH 706/752 llc: reserve device headroom for allocated frames
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zixuan Chai <[email protected]>
commit 72b5b9a28b996e09b8b5b944370c79851bb68f52 upstream.
llc_alloc_frame() reserves link-layer headroom using the device type. This is insufficient for stacked Ethernet devices such as VLAN devices, where vlan_dev_hard_header() pushes a VLAN header before the lower device's Ethernet header. An LLC response on such a device can therefore underflow skb headroom in eth_header().
Use LL_RESERVED_SPACE() to account for the device's actual required headroom while preserving the existing LLC device-type check.
--- net/llc/llc_sap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/llc/llc_sap.c +4 -4
@@ -25,12 +25,12 @@#include <linux/llc.h> #include <linux/slab.h> -static int llc_mac_header_len (unsigned short devtype) +static int llc_mac_header_len (struct net_device *dev) { -switch (devtype) { +switch (dev->type) {case ARPHRD_ETHER :case ARPHRD_LOOPBACK : -return sizeof (struct ethhdr ); +return LL_RESERVED_SPACE (dev); }return 0 ; }
@@ -51,7 +51,7 @@ struct sk_buff *llc_alloc_frame(struct sint hlen = type ==LLC_PDU_TYPE_U ?3 :4 ;struct sk_buff *skb; - hlen +=llc_mac_header_len (dev->type); + hlen +=llc_mac_header_len (dev); skb =alloc_skb (hlen + data_size,GFP_ATOMIC );if (skb) {
Greg Kroah-Hartman
maintainerPATCH 707/752 rds: ib: Clear the sg list when mapping an MR fails
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dongliang Qin <[email protected]>
commit 58eb1b3325edac42dc6df72c80962bd53a3c8ca7 upstream.
rds_ib_map_frmr() stores the caller's scatterlist in the MR before DMA mapping and registration can fail. On failure, __rds_rdma_map() unpins the pages and frees the scatterlist, but rds_ib_free_frmr() can still return the MR to the pool with the stale pointer set.
This leaves the pool with a dangling scatterlist and can lead to local privilege escalation. KASAN detects the resulting use-after-free when the MR is later torn down:
BUG: KASAN: slab-use-after-free in __rds_ib_teardown_mr Read of size 8 Call Trace: __rds_ib_teardown_mr rds_ib_unreg_frmr rds_ib_flush_mr_pool rds_ib_flush_mrs rds_free_mr rds_setsockopt
Store the scatterlist in the MR only after DMA mapping succeeds. If DMA mapping fails, return directly while the MR fields remain clear; the caller keeps ownership of the scatterlist and its pinned pages. If a later registration step fails, unmap the scatterlist and clear the MR fields before returning.
--- net/rds/ib_frmr.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/rds/ib_frmr.c +5 -6
@@ -204,19 +204,16 @@ static int rds_ib_map_frmr(struct rds_ib*/ rds_ib_teardown_mr (ibmr); - ibmr->sg = sg; - ibmr->sg_len = sg_len; - ibmr->sg_dma_len =0 ; frmr->sg_byte_len =0 ; -WARN_ON (ibmr->sg_dma_len); - ibmr->sg_dma_len =ib_dma_map_sg (dev, ibmr->sg, ibmr->sg_len, + ibmr->sg_dma_len =ib_dma_map_sg (dev, sg, sg_len,DMA_BIDIRECTIONAL );if (unlikely (!ibmr->sg_dma_len)) {pr_warn ("RDS/IB: %s failed!\n" , __func__);return -EBUSY ; } - frmr->sg_byte_len =0 ; + ibmr->sg = sg; + ibmr->sg_len = sg_len; frmr->dma_npages =0 ; len =0 ;
@@ -264,6 +261,8 @@ out_unmap:ib_dma_unmap_sg (rds_ibdev->dev, ibmr->sg, ibmr->sg_len,DMA_BIDIRECTIONAL ); ibmr->sg_dma_len =0 ; + ibmr->sg =NULL ; + ibmr->sg_len =0 ;return ret; }
Greg Kroah-Hartman
maintainerPATCH 708/752 drm/nouveau: fix autosuspend cleanup during teardown
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit fefd9480ec361969f1a836df46326a1801062c26 upstream.
nouveau_drm_device_init() calls pm_runtime_use_autosuspend(), but nouveau_drm_device_fini() does not call the matching pm_runtime_dont_use_autosuspend().
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without calling pm_runtime_dont_use_autosuspend() during teardown, this reference is not dropped and usage_count remains unbalanced.
The documentation for pm_runtime_use_autosuspend() also notes that it is important to undo it with pm_runtime_dont_use_autosuspend() at driver exit time, unless runtime PM was initially enabled with devm_pm_runtime_enable().
Add the missing pm_runtime_dont_use_autosuspend() call to the common device teardown path.
This issue was found by manual code inspection.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -0
@@ -645,6 +645,7 @@ nouveau_drm_device_fini(struct drm_devicif (nouveau_pmops_runtime ()) {pm_runtime_get_sync (dev->dev);pm_runtime_forbid (dev->dev); +pm_runtime_dont_use_autosuspend (dev->dev); }nouveau_led_fini (dev);
Greg Kroah-Hartman
maintainerPATCH 709/752 drm/nouveau: Fix bridge reference leak in nv1a_ram_new()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 67b4411538c8341692548429d43256f25be99f7a upstream.
pci_get_domain_bus_and_slot() takes a reference to the PCI device, which is never released once the memory size has been read from its config space. Drop the reference before returning.
--- drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramnv1a.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/nouveau/nvkm/subdev/fb/ramnv1a.c +2 -0
@@ -51,6 +51,8 @@ nv1a_ram_new(struct nvkm_fb *fb, struct mib = ((mem >>4 ) &127 ) +1 ; } +pci_dev_put (bridge); +return nvkm_ram_new_ (&nv04_ram_func, fb,NVKM_RAM_TYPE_STOLEN , mib *1024 *1024 , pram); }
Greg Kroah-Hartman
maintainerPATCH 710/752 drm/nouveau: fix double-free in nvif_vmm_dtor
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 97077ac87afe9e91ec074ef0be64454e7ccbf344 upstream.
On failure, nouveau_cli_init() calls nouveau_cli_fini() to tear the client down. Then, nouveau_drm_open() also enters into its cleanup path and calls nouveau_cli_fini() AGAIN. nouveau_cli_fini() calls nouveau_vmm_fini():
void
nouveau_vmm_fini(struct nouveau_vmm *vmm)
{
nouveau_svmm_fini(&vmm->svmm);
nvif_vmm_dtor(&vmm->vmm);
vmm->cli = NULL;
}Inside nvif_vmm_dtor(), vmm->page is freed unconditionally:
void
nvif_vmm_dtor(struct nvif_vmm *vmm)
{
kfree(vmm->page);
nvif_object_dtor(&vmm->object);
}vmm->page is never cleared after being freed, so the second call of nvif_vmm_dtor() will cause a double-free.
Found by fuzzing the nouveau driver with a modified Syzkaller:
BUG: KASAN: double-free in nvif_vmm_dtor+0x31/0x50 drivers/gpu/drm/nouveau/nvif/vmm.c:194 Free of addr ffff888010fcdc30 by task syz.0.173/2567 CPU: 1 UID: 0 PID: 2567 Comm: syz.0.173 Not tainted 7.2.0 #24 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 Call Trace: <TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x95/0xe0 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xcb/0x5a0 mm/kasan/report.c:482 kasan_report_invalid_free+0xaa/0xd0 mm/kasan/report.c:557 check_slab_allocation+0xe4/0x110 mm/kasan/common.c:235 kasan_slab_pre_free include/linux/kasan.h:199 [inline] slab_free_hook mm/slub.c:2622 [inline] slab_free mm/slub.c:6377 [inline] kfree+0x192/0x590 mm/slub.c:6692 nvif_vmm_dtor+0x31/0x50 drivers/gpu/drm/nouveau/nvif/vmm.c:194 nouveau_vmm_fini+0x16/0x50 drivers/gpu/drm/nouveau/nouveau_vmm.c:127 nouveau_cli_fini+0x10e/0x210 drivers/gpu/drm/nouveau/nouveau_drm.c:225 nouveau_drm_open+0x24e/0x740 drivers/gpu/drm/nouveau/nouveau_drm.c:1255 drm_file_alloc+0x5f2/0xad0 drivers/gpu/drm/drm_file.c:176 drm_open_helper+0x1d7/0x4a0 drivers/gpu/drm/drm_file.c:335 drm_open+0x190/0x3d0 drivers/gpu/drm/drm_file.c:388 drm_stub_open+0x1f2/0x460 drivers/gpu/drm/drm_drv.c:1211 chrdev_open+0x21c/0x660 fs/char_dev.c:411 do_dentry_open+0x59d/0x12b0 fs/open.c:947 vfs_open+0x82/0x390 fs/open.c:1052 do_open fs/namei.c:4700 [inline] path_openat+0x2345/0x3420 fs/namei.c:4863 do_file_open+0x207/0x460 fs/namei.c:4892 do_sys_openat2+0xd1/0x1d0 fs/open.c:1368 do_sys_open fs/open.c:1374 [inline] __do_sys_openat fs/open.c:1390 [inline] __se_sys_openat fs/open.c:1385 [inline] __x64_sys_openat+0x144/0x200 fs/open.c:1385 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fc6d687594d Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b0 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007fc6d5295008 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 00007fc6d6b06180 RCX: 00007fc6d687594d RDX: 0000000000022501 RSI: 0000200000000000 RDI: ffffffffffffff9c RBP: 00007fc6d691c303 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007fc6d6b06218 R14: 00007fc6d6b06180 R15: 00007ffd9451d760 </TASK> Allocated by task 2567 on cpu 1 at 163.593900s: kasan_save_stack+0x24/0x50 mm/kasan/common.c:57 kasan_save_track+0x17/0x60 mm/kasan/common.c:78 poison_kmalloc_redzone mm/kasan/common.c:398 [inline] __kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415 kasan_kmalloc include/linux/kasan.h:263 [inline] __do_kmalloc_node mm/slub.c:5334 [inline] __kmalloc_noprof+0x304/0x7c0 mm/slub.c:5359 _kmalloc_noprof include/linux/slab.h:992 [inline] nvif_vmm_ctor+0x3c0/0x7e0 drivers/gpu/drm/nouveau/nvif/vmm.c:237 nouveau_vmm_init+0x40/0x90 drivers/gpu/drm/nouveau/nouveau_vmm.c:134 nouveau_cli_init+0x7b9/0xe10 drivers/gpu/drm/nouveau/nouveau_drm.c:293 nouveau_drm_open+0x236/0x740 drivers/gpu/drm/nouveau/nouveau_drm.c:1243 drm_file_alloc+0x5f2/0xad0 drivers/gpu/drm/drm_file.c:176 drm_open_helper+0x1d7/0x4a0 drivers/gpu/drm/drm_file.c:335 drm_open+0x190/0x3d0 drivers/gpu/drm/drm_file.c:388 drm_stub_open+0x1f2/0x460 drivers/gpu/drm/drm_drv.c:1211 chrdev_open+0x21c/0x660 fs/char_dev.c:411 do_dentry_open+0x59d/0x12b0 fs/open.c:947 vfs_open+0x82/0x390 fs/open.c:1052 do_open fs/namei.c:4700 [inline] path_openat+0x2345/0x3420 fs/namei.c:4863 do_file_open+0x207/0x460 fs/namei.c:4892 do_sys_openat2+0xd1/0x1d0 fs/open.c:1368 do_sys_open fs/open.c:1374 [inline] __do_sys_openat fs/open.c:1390 [inline] __se_sys_openat fs/open.c:1385 [inline] __x64_sys_openat+0x144/0x200 fs/open.c:1385 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 2567 on cpu 1 at 163.601355s: kasan_save_stack+0x24/0x50 mm/kasan/common.c:57 kasan_save_track+0x17/0x60 mm/kasan/common.c:78 kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:584 poison_slab_object mm/kasan/common.c:253 [inline] __kasan_slab_free+0x61/0x80 mm/kasan/common.c:285 kasan_slab_free include/linux/kasan.h:235 [inline] slab_free_hook mm/slub.c:2677 [inline] slab_free mm/slub.c:6377 [inline] kfree+0x383/0x590 mm/slub.c:6692 nvif_vmm_dtor+0x31/0x50 drivers/gpu/drm/nouveau/nvif/vmm.c:194 nouveau_vmm_fini+0x16/0x50 drivers/gpu/drm/nouveau/nouveau_vmm.c:127 nouveau_cli_fini+0x10e/0x210 drivers/gpu/drm/nouveau/nouveau_drm.c:225 nouveau_cli_init+0x593/0xe10 drivers/gpu/drm/nouveau/nouveau_drm.c:324 nouveau_drm_open+0x236/0x740 drivers/gpu/drm/nouveau/nouveau_drm.c:1243 drm_file_alloc+0x5f2/0xad0 drivers/gpu/drm/drm_file.c:176 drm_open_helper+0x1d7/0x4a0 drivers/gpu/drm/drm_file.c:335 drm_open+0x190/0x3d0 drivers/gpu/drm/drm_file.c:388 drm_stub_open+0x1f2/0x460 drivers/gpu/drm/drm_drv.c:1211 chrdev_open+0x21c/0x660 fs/char_dev.c:411 do_dentry_open+0x59d/0x12b0 fs/open.c:947 vfs_open+0x82/0x390 fs/open.c:1052 do_open fs/namei.c:4700 [inline] path_openat+0x2345/0x3420 fs/namei.c:4863 do_file_open+0x207/0x460 fs/namei.c:4892 do_sys_openat2+0xd1/0x1d0 fs/open.c:1368 do_sys_open fs/open.c:1374 [inline] __do_sys_openat fs/open.c:1390 [inline] __se_sys_openat fs/open.c:1385 [inline] __x64_sys_openat+0x144/0x200 fs/open.c:1385 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x115/0x690 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff888010fcdc30 which belongs to the cache kmalloc-16 of size 16 The buggy address is located 0 bytes inside of 16-byte region [ffff888010fcdc30, ffff888010fcdc40) The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x10fcd flags: 0x100000000000000(node=0|zone=1) page_type: f5(slab) raw: 0100000000000000 ffff88800d441640 dead000000000100 dead000000000122 raw: 0000000000000000 0000000000550055 00000000f5000000 0000000000000000 page dumped because: kasan: bad access detected Memory state around the buggy address: ffff888010fcdb00: fc fc 00 04 fc fc fc fc fa fb fc fc fc fc fa fb ffff888010fcdb80: fc fc fc fc fa fb fc fc fc fc 00 07 fc fc fc fc >ffff888010fcdc00: fa fb fc fc fc fc fa fb fc fc fc fc fa fb fc fc ^ ffff888010fcdc80: fc fc fa fb fc fc fc fc 00 04 fc fc fc fc fa fb ffff888010fcdd00: fc fc fc fc 00 00 fc fc fc fc fa fb fc fc fc fc
Fix by removing the redundant teardown in nouveau_drm_open(), since nouveau_cli_init() already does the cleanup work. Also clear vmm->page after its freeing.
--- drivers/gpu/drm/nouveau/nouveau_drm.c | 4 +--- drivers/gpu/drm/nouveau/nvif/vmm.c | 1 + 2 files changed, 2 insertions(+), 3 deletions(-)
drivers/gpu/drm/nouveau/nouveau_drm.c +1 -3
@@ -1123,10 +1123,8 @@ nouveau_drm_open(struct drm_device *dev,mutex_unlock (&drm->clients_lock); done: -if (ret && cli) { -nouveau_cli_fini (cli); +if (ret && cli)kfree (cli); - }pm_runtime_mark_last_busy (dev->dev);pm_runtime_put_autosuspend (dev->dev);
drivers/gpu/drm/nouveau/nvif/vmm.c +1 -0
@@ -108,6 +108,7 @@ void nvif_vmm_dtor(struct nvif_vmm *vmm) {kfree (vmm->page); + vmm->page =NULL ;nvif_object_dtor (&vmm->object); }
Greg Kroah-Hartman
maintainerPATCH 711/752 drm/nouveau: Fix gem reference leak in validate_init()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 5ea72f7b7139b123713a7983448f910bc4514d9e upstream.
On the ttm_bo_reserve() failure and "vma not found" error paths, the loop breaks without adding the looked-up object to any validate list, so the reference taken by drm_gem_object_lookup() is never released; validate_fini() only walks the spliced lists. Drop the reference before breaking out on both paths.
--- drivers/gpu/drm/nouveau/nouveau_gem.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/nouveau/nouveau_gem.c +2 -0
@@ -471,6 +471,7 @@ retry:if (unlikely (ret)) {if (ret != -ERESTARTSYS )NV_PRINTK (err, cli,"fail reserve\n" ); +drm_gem_object_put (gem);break ; } }
@@ -480,6 +481,7 @@ retry:struct nouveau_vma *vma =nouveau_vma_find (nvbo, vmm);if (!vma) {NV_PRINTK (err, cli,"vma not found!\n" ); +drm_gem_object_put (gem); ret = -EINVAL ;break ; }
Greg Kroah-Hartman
maintainerPATCH 712/752 drm/nouveau: dont bump pin count on failed re-pin in nouveau_bo_pin_locked()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peiyang He <[email protected]>
commit 6a6870d3077faa501ca97760057ddca22b68418d upstream.
nouveau_bo_pin_locked() checks whether an already pinned BO is in a memory domain compatible with a new pin request. When the domains are incompatible, it sets -EBUSY but still calls ttm_bo_pin() before returning.
Callers treat a failed nouveau_bo_pin() as not having acquired a new pin, so the extra pin count is never decreased by a matching unpin. This triggers the warning in ttm_bo_release():
WARN_ON_ONCE(bo->pin_count);
Found when fuzzing the nouveau driver with a modified Syzkaller:
WARNING: drivers/gpu/drm/ttm/ttm_bo.c:256 at ttm_bo_release+0x827/0x9e0 drivers/gpu/drm/ttm/ttm_bo.c:256, CPU#1: syz.3.24/2212 Modules linked in: CPU: 1 UID: 0 PID: 2212 Comm: syz.3.24 Not tainted 7.2.0 #24 PREEMPT(lazy) nouveau 0000:01:00.0: gsp:msg fn:103 len:0x40/0x20 res:0x19 resp:0x19 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014 RIP: 0010:ttm_bo_release+0x827/0x9e0 drivers/gpu/drm/ttm/ttm_bo.c:256 Code: 02 00 0f 85 51 01 00 00 48 8b 7b 08 e8 d2 20 01 00 e9 80 fd ff ff e8 d8 15 c0 fe 90 0f 0b 90 e9 e1 f8 ff ff e8 ca 15 c0 fe 90 <0f> 0b 90 e9 a4 f8 ff ff e8 bc 15 c0 fe be 03 00 00 00 4c 89 e7 e8 msg: 00000000: 05 00 d0 c1 04 00 f0 f1 01 30 00 00 2d 90 00 00 .........0..-... RSP: 0018:ffffc9000f5cf710 EFLAGS: 00010293 RAX: 0000000000000000 RBX: ffff888018e5d2a8 RCX: ffffffff82bb1b36 RDX: ffff888017b68000 RSI: 0000000000000004 RDI: ffff888018e5d2a8 msg: 00000010: 19 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ RBP: ffff88801261c720 R08: 0000000000000001 R09: ffffed10031cba55 R10: ffff888018e5d2ab R11: 00000000000000f3 R12: ffff888018e5d290 R13: ffff888018e5d2d4 R14: ffff88801b219c18 R15: dffffc0000000000 FS: 0000000000000000(0000) GS:ffff8880e0f6f000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b31223ffc CR3: 0000000028e00005 CR4: 0000000000770ef0 PKRU: 80000000 Call Trace: <TASK> kref_put include/linux/kref.h:65 [inline] ttm_bo_put drivers/gpu/drm/ttm/ttm_bo.c:325 [inline] ttm_bo_fini+0x55/0x80 drivers/gpu/drm/ttm/ttm_bo.c:330 nouveau_gem_object_del+0xb2/0x1b0 drivers/gpu/drm/nouveau/nouveau_gem.c:90 drm_gem_object_free+0x5f/0x90 drivers/gpu/drm/drm_gem.c:1165 kref_put include/linux/kref.h:65 [inline] __drm_gem_object_put include/drm/drm_gem.h:562 [inline] drm_gem_object_put include/drm/drm_gem.h:575 [inline] nouveau_abi16_chan_fini.constprop.0+0x44f/0x5a0 drivers/gpu/drm/nouveau/nouveau_abi16.c:195 nouveau 0000:01:00.0: syz.2.23[2209]: Unknown handle 0x00000000 nouveau_abi16_fini+0x1d0/0x340 drivers/gpu/drm/nouveau/nouveau_abi16.c:225 nouveau_drm_postclose+0x18b/0x3e0 drivers/gpu/drm/nouveau/nouveau_drm.c:1284 nouveau 0000:01:00.0: syz.2.23[2209]: validate_init drm_file_free.part.0+0x6d6/0xb60 drivers/gpu/drm/drm_file.c:267 drm_file_free drivers/gpu/drm/drm_file.c:237 [inline] drm_close_helper.isra.0+0x11a/0x160 drivers/gpu/drm/drm_file.c:290 drm_release+0x1ab/0x330 drivers/gpu/drm/drm_file.c:438 __fput+0x39c/0xa60 fs/file_table.c:512 nouveau 0000:01:00.0: syz.2.23[2209]: validate: -2 task_work_run+0x15a/0x230 kernel/task_work.c:233 exit_task_work include/linux/task_work.h:40 [inline] do_exit+0x82b/0x25a0 kernel/exit.c:1009 do_group_exit+0xc2/0x280 kernel/exit.c:1152 get_signal+0x1d6e/0x1f30 kernel/signal.c:3046 arch_do_signal_or_restart+0x7d/0x6e0 arch/x86/kernel/signal.c:337 __exit_to_user_mode_loop kernel/entry/common.c:66 [inline] exit_to_user_mode_loop+0xdf/0x440 kernel/entry/common.c:101 __exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline] syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:230 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:318 [inline] do_syscall_64+0x4f8/0x690 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f12bac8594d Code: Unable to access opcode bytes at 0x7f12bac85923. RSP: 002b:00007f12b96e70d8 EFLAGS: 00000246 ORIG_RAX: 00000000000000ca RAX: 0000000000000001 RBX: 00007f12baf15fa8 RCX: 00007f12bac8594d RDX: 00000000000f4240 RSI: 0000000000000081 RDI: 00007f12baf15fac RBP: 00007f12baf15fa0 R08: 00007f12baee8000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f12baf16038 R14: 0000000000000006 R15: 00007ffe2ed394b0 </TASK> irq event stamp: 47867 hardirqs last enabled at (47883): [<ffffffff815cafc6>] __up_console_sem+0x66/0x70 kernel/printk/printk.c:347 hardirqs last disabled at (47892): [<ffffffff815cafab>] __up_console_sem+0x4b/0x70 kernel/printk/printk.c:345 softirqs last enabled at (47880): [<ffffffff81434277>] __do_softirq kernel/softirq.c:656 [inline] softirqs last enabled at (47880): [<ffffffff81434277>] invoke_softirq kernel/softirq.c:496 [inline] softirqs last enabled at (47880): [<ffffffff81434277>] __irq_exit_rcu+0x137/0x1c0 kernel/softirq.c:735 softirqs last disabled at (47875): [<ffffffff81434277>] __do_softirq kernel/softirq.c:656 [inline] softirqs last disabled at (47875): [<ffffffff81434277>] invoke_softirq kernel/softirq.c:496 [inline] softirqs last disabled at (47875): [<ffffffff81434277>] __irq_exit_rcu+0x137/0x1c0 kernel/softirq.c:735
Fix by calling ttm_bo_pin() only when the existing placement is compatible with the new pin request. This matches the correct behavior in other DRM drivers such as amdgpu_bo_pin() in amdgpu.
--- drivers/gpu/drm/nouveau/nouveau_bo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_bo.c +2 -1
@@ -460,8 +460,9 @@ nouveau_bo_pin(struct nouveau_bo *nvbo,"0x%08x vs 0x%08x\n" , bo, bo->resource->mem_type, domain); ret = -EBUSY ; + }else { +ttm_bo_pin (&nvbo->bo); } -ttm_bo_pin (&nvbo->bo); goto out; }
Greg Kroah-Hartman
maintainerPATCH 713/752 HID: alps: fix use-after-free on input2 registration failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Changcheng <[email protected]>
commit d3aba3442798ce4a4c8ce3104d7b286d61e605f9 upstream.
alps_input_configured() stores data->input2 before calling input_register_device(). If registration fails, input_free_device() frees the input device but data->input2 still points to the freed memory. alps_input_configured() calls hid_hw_open() before allocating input2, so URBs are already active and raw_event can fire during the failure window. A U1_SP_ABSOLUTE_REPORT_ID report arriving then causes u1_raw_event() to dereference the freed data->input2 -> use-after-free.
Fix by only storing input2 into drvdata after successful registration and adding a NULL guard in the raw_event path.
--- drivers/hid/hid-alps.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/hid/hid-alps.c +4 -2
@@ -407,6 +407,8 @@ static int u1_raw_event(struct alps_devreturn 1 ;case U1_SP_ABSOLUTE_REPORT_ID : +if (!hdata->input2) +return 0 ; sp_x =get_unaligned_le16 (data+2 ); sp_y =get_unaligned_le16 (data+4 );
@@ -738,7 +740,6 @@ static int alps_input_configured(struct goto exit; } - data->input2 = input2; input2->phys = input->phys; input2->name ="DualPoint Stick" ; input2->id.bustype =BUS_I2C ;
@@ -762,11 +763,12 @@ static int alps_input_configured(struct__set_bit (INPUT_PROP_POINTER , input2->propbit);__set_bit (INPUT_PROP_POINTING_STICK , input2->propbit); -if (input_register_device (data->input2)) { +if (input_register_device (input2)) {input_free_device (input2); ret = -ENOENT ; goto exit; } + data->input2 = input2; } exit:
Greg Kroah-Hartman
maintainerPATCH 714/752 HID: quirks: add ALWAYS_POLL quirk for SDINNOVATION gaming keyboard
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Junjie Cao <[email protected]>
commit cdb669a3b8f844aca71fc3224990157d61562165 upstream.
The SDINNOVATION gaming keyboard (USB ID 36ae:feab) stops reporting input events after its RGB lighting mode is switched about twice. Disabling USB autosuspend and unbinding the other HID interfaces make no difference; the issue does not occur on Windows.
HID_QUIRK_ALWAYS_POLL alone resolves it, verified on 7.1.8 via usbhid.quirks=0x36ae:0xfeab:0x400.
--- drivers/hid/hid-ids.h | 3 +++ drivers/hid/hid-quirks.c | 1 + 2 files changed, 4 insertions(+)
drivers/hid/hid-ids.h +3 -0
@@ -1116,6 +1116,9 @@#define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001#define USB_DEVICE_ID_SAMSUNG_WIRELESS_KBD_MOUSE 0x0600 +#define USB_VENDOR_ID_SDINNOVATION 0x36ae +#define USB_DEVICE_ID_SDINNOVATION_GAMING_KBD 0xfeab +#define USB_VENDOR_ID_SEMICO 0x1a2c#define USB_DEVICE_ID_SEMICO_USB_KEYKOARD 0x0023#define USB_DEVICE_ID_SEMICO_USB_KEYKOARD2 0x0027
drivers/hid/hid-quirks.c +1 -0
@@ -171,6 +171,7 @@ static const struct hid_device_id hid_qu { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_X52_2), HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE }, { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_X52_PRO), HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE }, { HID_USB_DEVICE(USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_X65), HID_QUIRK_INCREMENT_USAGE_ON_DUPLICATE }, + { HID_USB_DEVICE(USB_VENDOR_ID_SDINNOVATION, USB_DEVICE_ID_SDINNOVATION_GAMING_KBD), HID_QUIRK_ALWAYS_POLL }, { HID_USB_DEVICE(USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD2), HID_QUIRK_NO_INIT_REPORTS }, { HID_USB_DEVICE(USB_VENDOR_ID_SEMICO, USB_DEVICE_ID_SEMICO_USB_KEYKOARD), HID_QUIRK_NO_INIT_REPORTS }, { HID_USB_DEVICE(USB_VENDOR_ID_SENNHEISER, USB_DEVICE_ID_SENNHEISER_BTD500USB), HID_QUIRK_NOGET },
Greg Kroah-Hartman
maintainerPATCH 715/752 HID: wacom: fix OOB read in wacom_wac_pen_serial_enforce()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Jie LAW <[email protected]>
commit 9aa237cf66495b2426ddde8532e9b08a0ed83aaa upstream.
The 'wacom_wac_pen_serial_enforce()' function may calculate and pass an invalid offset to hid_field_extract(), resulting in memory reads at incorrect addresses -- possibly beyond the end of the report. If a field in the HID descriptor lists more usages than its Report Count actually reserves space for, the function's inner 'j' will walk past the end of the field:
for (i = 0; i < report->maxfield; i++) {
for (j = 0; j < report->field[i]->maxusage; j++) {
...
value = hid_field_extract(hdev, raw_data + 1,
offset + j * size, size);A descriptor listing 12288 usages against Report Count 1 has the loop extract the usage at index 12287 from bit offset 98296 -- about 12 KB past a 2-byte received report. The value is stored in wacom_wac->serial[0] and can reach userspace as an MSC_SERIAL event, making this an information disclosure.
Clamp the loop to field->report_count, the number of value slots the report holds. Value slots past the last declared usage are still scanned; they reuse that usage (HID 1.11, 6.2.2.8).
Verified on v6.12.105 with a UHID reproducer: a 2-byte report from such a descriptor trips KASAN before the patch and not after it.
--- drivers/hid/wacom_sys.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hid/wacom_sys.c +3 -2
@@ -102,8 +102,9 @@ static int wacom_wac_pen_serial_enforce(/* Queue events which have invalid tool type or serial number */ for (i =0 ; i < report->maxfield; i++) { -for (j =0 ; j < report->field[i]->maxusage; j++) { -struct hid_field *field = report->field[i]; +struct hid_field *field = report->field[i]; + +for (j =0 ; j < field->report_count; j++) {struct hid_usage *usage = &field->usage[j];unsigned int equivalent_usage =wacom_equivalent_usage (usage->hid);unsigned int offset;
Greg Kroah-Hartman
maintainerPATCH 716/752 net/mlx5: Fix rev_entry reference leak in mlx5_tc_ct_shared_counter_get()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 0bf6bb567f0edaa771e7dd208ef98da50e6a4485 upstream.
When the reverse entry is found but its counter is already being released, refcount_inc_not_zero() fails and the reference taken by mlx5_tc_ct_entry_get() is never dropped before falling through to create_counter. Drop it so the reverse entry is not kept alive forever by a shared counter lookup that did not use it.
--- drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +3 -0
@@ -944,6 +944,9 @@ mlx5_tc_ct_shared_counter_get(struct mlxspin_unlock_bh (&ct_priv->ht_lock); +if (rev_entry) +mlx5_tc_ct_entry_put (rev_entry); + create_counter: shared_counter =mlx5_tc_ct_counter_create (ct_priv);
Greg Kroah-Hartman
maintainerPATCH 717/752 net/sched: reject IDR error pointers when deleting actions
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit c82b797abe668d0b668601a93ba2c0b071a63574 upstream.
tcf_action_delete() drops the reference held by its lookup before calling tcf_idr_delete_index() with the saved action index. An unlocked classifier can remove that action and reserve the same IDR slot with ERR_PTR(-EBUSY) in between.
tcf_idr_delete_index() only checks the lookup result for NULL. It therefore treats the reservation as a tc_action and dereferences tcfa_bindcnt. A hardware execution breakpoint was used to schedule the interleaving without changing the kernel source. KASAN reported this decoded trace:
BUG: KASAN: null-ptr-deref in tca_action_gd+0x5b9/0x1010
Read of size 4 at addr 0000000000000010 by task poc/150
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002
RIP: tca_action_gd+0x5c0/0x1010:
arch_atomic_read at arch/x86/include/asm/atomic.h:23
raw_atomic_read at include/linux/atomic/atomic-arch-fallback.h:457
atomic_read at include/linux/atomic/atomic-instrumented.h:33
tcf_idr_delete_index at net/sched/act_api.c:766
tcf_action_delete at net/sched/act_api.c:1859
tcf_del_notify at net/sched/act_api.c:2014
tca_action_gd at net/sched/act_api.c:2064
R13: 0000000000000010 R15: fffffffffffffff0
Kernel panic - not syncing: Fatal exceptionR15 contains ERR_PTR(-EBUSY), and adding the tcfa_bindcnt offset produces the address in R13. With the guard applied, the same reproducer returned -ENOENT without a KASAN report or panic. Treat error pointers as absent and return -ENOENT.
--- net/sched/act_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/act_api.c +1 -1
@@ -449,7 +449,7 @@ static int tcf_idr_delete_index(struct tmutex_lock (&idrinfo->lock); p =idr_find (&idrinfo->action_idr, index); -if (!p) { +if (IS_ERR_OR_NULL (p)) {mutex_unlock (&idrinfo->lock);return -ENOENT ; }
Greg Kroah-Hartman
maintainerPATCH 718/752 net: arp: terminate device name before lookup
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zijie Huang <[email protected]>
commit d8b6529e80bcb4fb8177121404cbb3377acaebd2 upstream.
The ARP ioctl copies a user-provided struct arpreq into a stack object. Its arp_dev field may contain IFNAMSIZ bytes without a NUL terminator.
Such input is passed to dev_get_by_name_rcu() or __dev_get_by_name(), where strcmp() can read past the end of the stack object when a matching alternative interface name exists.
Terminate the field before the lookup to prevent the out-of-bounds read.
--- net/ipv4/arp.c | 1 + 1 file changed, 1 insertion(+)
net/ipv4/arp.c +1 -0
@@ -1201,6 +1201,7 @@ int arp_ioctl(struct net *net, unsigned err =copy_from_user (&r, arg,sizeof (struct arpreq ));if (err)return -EFAULT ; + r.arp_dev[IFNAMSIZ -1 ] ='\0' ;break ;default :return -EINVAL ;
Greg Kroah-Hartman
maintainerPATCH 719/752 net: atl1: fix soft lockup on out-of-range cmb_tpd_next_to_clean read
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gajdos Tamás <[email protected]>
commit 43e746821f5f5afbbf68e388bf9fbe221e03bfca upstream.
Same issue as atl1c (see the first commit in this series, "net:
atl1c: fix soft lockup on out-of-range tpd_cons read"): the hardware can report an out-of-range cmb_tpd_next_to_clean (seen as 0xffff) while the PCIe link/MAC is resetting. An out-of-range value can never be reached and the loop below would spin forever. Treat it as "nothing new to clean" instead.
--- drivers/net/ethernet/atheros/atlx/atl1.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/atheros/atlx/atl1.c +3 -0
@@ -2066,6 +2066,9 @@ static int atl1_intr_tx(struct atl1_adap sw_tpd_next_to_clean =atomic_read (&tpd_ring->next_to_clean); cmb_tpd_next_to_clean =le16_to_cpu (adapter->cmb.cmb->tpd_cons_idx); +if (unlikely (cmb_tpd_next_to_clean >= tpd_ring->count)) + cmb_tpd_next_to_clean = sw_tpd_next_to_clean; +while (cmb_tpd_next_to_clean != sw_tpd_next_to_clean) { buffer_info = &tpd_ring->buffer_info[sw_tpd_next_to_clean];if (buffer_info->dma) {
Greg Kroah-Hartman
maintainerPATCH 720/752 net: hisilicon: hns_dsaf_mac: fix mdio device leak in hns_mac_register_phy()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 999e8295bc41d6ce45b8e54f88150efa96f3f01e upstream.
hns_dsaf_find_platform_device() returns the mdio platform device with its reference count incremented. hns_mac_register_phy() never drops that reference, so the mdio device can not be released.
Release the reference on both the deferred probe and the normal path.
--- drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/hisilicon/hns/hns_dsaf_mac.c +3 -0
@@ -793,6 +793,7 @@ static int hns_mac_register_phy(struct hdev_err (mac_cb->dev,"mac%d mdio is NULL, dsaf will probe again later\n" , mac_cb->mac_id); +put_device (&pdev->dev);return -EPROBE_DEFER ; }
@@ -801,6 +802,8 @@ static int hns_mac_register_phy(struct hdev_dbg (mac_cb->dev,"mac%d register phy addr:%d\n" , mac_cb->mac_id, addr); +put_device (&pdev->dev); +return rc; }
Greg Kroah-Hartman
maintainerPATCH 721/752 net: openvswitch: conntrack: avoid modifying shared unconfirmed ct entry
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
commit 26b2bd70d22457556e2fa01cbf1192cb1a94d619 upstream.
In a case where skb with an unconfirmed ct entry gets cloned, we may end up committing both but with different sets of extensions.
The series of events:
1. The first clone wants to commit and runs the helpers wiring up the extension pointer into the expectation list.
2. Then it looses the confirmation keeping the entry unconfirmed.
3. Second clone now wants to commit labels and adds the new extension for that breaking the pointer in the expectation list causing UAF on the destruction path later.
While this is possible to trigger, there should be no practical network pipeline where committing both clones without modifications into the same zone is needed. So, let's just reset the entry in case for some reason we got an skb with a shared one during commit. This doesn't affect any known use cases, but avoids any potential problems with sharing and modification of the unconfirmed ct entry.
The fixes tag points to the introduction of helpers, since that's the main UAF trigger for the sharing.
--- include/net/netfilter/nf_conntrack.h | 5 +++++ net/openvswitch/conntrack.c | 12 ++++++++++++ 2 files changed, 17 insertions(+)
include/net/netfilter/nf_conntrack.h +5 -0
@@ -192,6 +192,11 @@ static inline void nf_ct_put(struct nf_cint nf_ct_l3proto_try_module_get (unsigned short l3proto);void nf_ct_l3proto_module_put (unsigned short l3proto); +static inline bool nf_ct_shared (const struct nf_conn *ct) +{ +return refcount_read (&ct->ct_general.use) >1 ; +} +/* load module; enable/disable conntrack in this namespace */ int nf_ct_netns_get (struct net *net,u8 nfproto);void nf_ct_netns_put (struct net *net,u8 nfproto);
net/openvswitch/conntrack.c +12 -0
@@ -968,6 +968,18 @@ static int __ovs_ct_lookup(struct net *nenum ip_conntrack_info ctinfo;struct nf_conn *ct; +/* If the ct entry is not confirmed and shared with some other skb, +* e.g., a cloned one, we can't just modify it with the commit as we +* must not modify the extension set. Reset. +*/ +if (cached && info->commit) { + ct =nf_ct_get (skb, &ctinfo); +if (ct && !nf_ct_is_confirmed (ct) &&nf_ct_shared (ct)) { +nf_reset_ct (skb); + cached = false; + } + } +if (!cached) {struct nf_hook_state state = { .hook =NF_INET_PRE_ROUTING ,
Re: [PATCH 5.15 721/752] net: openvswitch: conntrack: avoid modifying shared unconfirmed ct entry
Hi Greg/Sasha,
Quoted 30 lines · Greg Kroah-Hartman
5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
commit
26b2bd70d22457556e2fa01cbf1192cb1a94d619upstream.In a case where skb with an unconfirmed ct entry gets cloned, we may end up committing both but with different sets of extensions.
The series of events:
1. The first clone wants to commit and runs the helpers wiring up the extension pointer into the expectation list.
2. Then it looses the confirmation keeping the entry unconfirmed.
3. Second clone now wants to commit labels and adds the new extension for that breaking the pointer in the expectation list causing UAF on the destruction path later.While this is possible to trigger, there should be no practical network pipeline where committing both clones without modifications into the same zone is needed. So, let's just reset the entry in case for some reason we got an skb with a shared one during commit. This doesn't affect any known use cases, but avoids any potential problems with sharing and modification of the unconfirmed ct entry.
The fixes tag points to the introduction of helpers, since that's the main UAF trigger for the sharing.
Quoted 8 lines
Fixes cae3a2627520 ("openvswitch: Allow attaching helpers to ct action")Reported-by Axel Mierczuk <[email protected]>Signed-off-by Ilya Maximets <[email protected]>Reviewed-by Aaron Conole <[email protected]>Signed-off-by Jakub Kicinski <[email protected]>Signed-off-by Greg Kroah-Hartman <[email protected]>
An AI-assisted review flagged the shared-conntrack relookup change, and I checked what the final 5.15.y helper-assignment path does with the lookup result. The reset itself is exact, but its continuation lacks the upstream confirmation guard.
Upstream helper-assignment continuation (26b2bd70d224, net/openvswitch/conntrack.c:808):
if (!nf_ct_is_confirmed(ct) && info->commit &&
info->helper && !nfct_help(ct)) {
int err = __nf_ct_try_assign_helper(ct, info->ct,
GFP_ATOMIC);
if (err)5.15.y helper-assignment continuation (d7aa8488b4a2, net/openvswitch/conntrack.c:1040):
if (info->commit && info->helper && !nfct_help(ct)) {
int err = __nf_ct_try_assign_helper(ct, info->ct,
GFP_ATOMIC);
if (err)
return err;
add_helper = true;Relookup can return a confirmed connection published since the original lookup. Without the guard, helper assignment can call nf_ct_ext_add() on that connection, triggering a WARN and potentially reallocating extensions still in use.
I think 5.15.y needs 3c1860543fccc1d0cfe3fd6b190e414a418fe60e ("openvswitch: add nf_ct_is_confirmed check before assigning the helper") before the shared-object relookup fix, thoughts?
thanks,
harshit
Quoted 43 lines
--- include/net/netfilter/nf_conntrack.h | 5 +++++ net/openvswitch/conntrack.c | 12 ++++++++++++ 2 files changed, 17 insertions(+)include/net/netfilter/nf_conntrack.h +5
-0@@ -192,6 +192,11 @@ static inline void nf_ct_put(struct nf_cint nf_ct_l3proto_try_module_get (unsigned short l3proto);void nf_ct_l3proto_module_put (unsigned short l3proto); +static inline bool nf_ct_shared (const struct nf_conn *ct) +{ +return refcount_read (&ct->ct_general.use) >1 ; +} +/* load module; enable/disable conntrack in this namespace */ int nf_ct_netns_get (struct net *net,u8 nfproto);void nf_ct_netns_put (struct net *net,u8 nfproto);net/openvswitch/conntrack.c +12
-0@@ -968,6 +968,18 @@ static int __ovs_ct_lookup(struct net *nenum ip_conntrack_info ctinfo;struct nf_conn *ct; +/* If the ct entry is not confirmed and shared with some other skb, +* e.g., a cloned one, we can't just modify it with the commit as we +* must not modify the extension set. Reset. +*/ +if (cached && info->commit) { + ct =nf_ct_get (skb, &ctinfo); +if (ct && !nf_ct_is_confirmed (ct) &&nf_ct_shared (ct)) { +nf_reset_ct (skb); + cached = false; + } + } +if (!cached) {struct nf_hook_state state = { .hook =NF_INET_PRE_ROUTING ,
Sasha Levin
maintainerRe: [PATCH 5.15 721/752] net: openvswitch: conntrack: avoid modifying shared unconfirmed ct entry
Quoted 3 lines
I think 5.15.y needs
3c1860543fccc1d0cfe3fd6b190e414a418fe60e("openvswitch: addnf_ct_is_confirmedcheck before assigning the helper") before the shared-object relookup fix, thoughts?
Agreed. The relookup fix already shipped in 5.15.222 and 5.10.271, so this goes in as a follow-up. Queued for 5.15 and 5.10, thanks.
Signature · 2 lines
Thanks, Sasha
Greg Kroah-Hartman
maintainerPATCH 722/752 net: atl1c: fix soft lockup on out-of-range tpd_cons read
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gajdos Tamás <[email protected]>
commit 36c2009d90f2210ef92e6f4f2850e8b57b09e754 upstream.
The hardware can report an out-of-range tpd_cons (seen as 0xffff) while the PCIe link/MAC is resetting. An out-of-range value can never be reached and the loop below would spin forever. To avoid a soft lockup treat it as "nothing new to clean" instead.
Reproduced on two machines, same NIC (Qualcomm Atheros AR8151 v2.0, 4-port), triggered by rebooting a Mikrotik CCR2004 PCIe card that the ports are directly linked to:
- Ubuntu 26.04.1 LTS, kernel 7.0.0-31-generic. The link-flap precursor, before the lockup was captured with a full trace elsewhere:
atl1c 0000:05:00.0 enp5s0f0: NETDEV WATCHDOG: CPU: 4: transmit queue 2 timed out 489984 ms
atl1c 0000:05:00.0: MAC state machine can't be idle since disabled for 10ms second
atl1c 0000:05:00.0: atl1c: enp5s0f0 NIC Link is Up<65535 Mbps Full Duplex> 65535 (0xffff) here is the same value tpd_cons reads back once the loop below gets stuck.
- Proxmox VE, kernel 7.0.14-11-pve. Same NIC/trigger, this time caught by the soft lockup watchdog with a full stack trace:
watchdog: BUG: soft lockup - CPU#12 stuck for 354s! [napi/eth%d-0:329]
CPU: 12 UID: 0 PID: 329 Comm: napi/eth%d-0 Tainted: P O L 7.0.14-11-pve #1 PREEMPT(lazy)
RIP: 0010:atl1c_clean_tx+0x142/0x2d0 [atl1c]
Call Trace:
<TASK>
__napi_poll+0x32/0x1e0
napi_threaded_poll_loop+0x286/0x2e0
napi_threaded_poll+0xfd/0x140
kthread+0xf7/0x130
ret_from_fork+0x2da/0x3a0
ret_from_fork_asm+0x1a/0x30
</TASK>--- drivers/net/ethernet/atheros/atl1c/atl1c_main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/atheros/atl1c/atl1c_main.c +3 -0
@@ -1611,6 +1611,9 @@ static int atl1c_clean_tx(struct napi_stAT_READ_REGW (&adapter->hw, atl1c_qregs[tpd_ring->num].tpd_cons, &hw_next_to_clean); +if (unlikely (hw_next_to_clean >= tpd_ring->count)) + hw_next_to_clean = next_to_clean; +while (next_to_clean != hw_next_to_clean) { buffer_info = &tpd_ring->buffer_info[next_to_clean];if (buffer_info->skb) {
Greg Kroah-Hartman
maintainerPATCH 723/752 net: atl1e: fix soft lockup on out-of-range hw_next_to_clean read
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gajdos Tamás <[email protected]>
commit 374bf9e4b90f979e052332c4faca2d745c491a12 upstream.
Same issue as atl1c (see the first commit in this series, "net:
atl1c: fix soft lockup on out-of-range tpd_cons read"): the hardware can report an out-of-range hw_next_to_clean (seen as 0xffff) while the PCIe link/MAC is resetting. An out-of-range value can never be reached and the loop below would spin forever. Treat it as "nothing new to clean" instead.
--- drivers/net/ethernet/atheros/atl1e/atl1e_main.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/atheros/atl1e/atl1e_main.c +3 -0
@@ -1234,6 +1234,9 @@ static bool atl1e_clean_tx_irq(struct atu16 hw_next_to_clean =AT_READ_REGW (&adapter->hw,REG_TPD_CONS_IDX );u16 next_to_clean =atomic_read (&tx_ring->next_to_clean); +if (unlikely (hw_next_to_clean >= tx_ring->count)) + hw_next_to_clean = next_to_clean; +while (next_to_clean != hw_next_to_clean) { tx_buffer = &tx_ring->tx_buffer[next_to_clean];if (tx_buffer->dma) {
Greg Kroah-Hartman
maintainerPATCH 724/752 net: usb: cdc_mbim: add MeiG Smart SRM821 to ZLP whitelist
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming Wang <[email protected]>
commit f75f21ef36285e5f56ee0c428bd2909ee81165b9 upstream.
The MeiG Smart SRM821 5G module (0x2dee:0x4d53) crashes and drops off the USB bus when it receives a Zero Length Packet (ZLP) after sending or receiving an NTB of exactly 16384 bytes (tx_max).
According to the MBIM specification, devices do not require a ZLP if the NTB size is exactly dwNtbOutMaxSize. However, the cdc_mbim driver defaults to sending ZLPs for devices not explicitly whitelisted to accommodate non-conformant hardware. This default behavior breaks the strictly conformant MeiG SRM821 module.
Add this device to the ZLP conformance whitelist (cdc_mbim_info) so the driver will pad the NTB to avoid sending ZLPs, preventing the device firmware from crashing.
--- drivers/net/usb/cdc_mbim.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/usb/cdc_mbim.c +5 -0
@@ -633,6 +633,11 @@ static const struct usb_device_id mbim_d .driver_info = (unsigned long)&cdc_mbim_info, }, +/* MeiG Smart SRM821 ZLP conformance */ + { USB_DEVICE_AND_INTERFACE_INFO(0x2dee, 0x4d53, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE), + .driver_info = (unsigned long)&cdc_mbim_info, + }, +/* Some Huawei devices, ME906s-158 (12d1:15c1) and E3372 * (12d1:157d), are known to fail unless the NDP is placed * after the IP packets. Applying the quirk to all Huawei
Greg Kroah-Hartman
maintainerPATCH 725/752 netfilter: ip6t_rpfilter: reject routes without inet6_dev
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
commit 1b9b5323725e458906c7620a3bc10398b51ad954 upstream.
ip6_route_lookup() can return an error-free route whose rt6i_idev is NULL. Lowering an external nexthop device's MTU below IPV6_MIN_MTU tears down its inet6_dev while fib6_ifdown() leaves routes using nexthop objects in the FIB. An unprivileged user can construct this state with rtnetlink in a private user and network namespace, then trigger a NULL dereference through an IPv6 rpfilter lookup:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000 KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] RIP: rpfilter_mt (net/ipv6/netfilter/ip6t_rpfilter.c:75) Call Trace: ip6t_do_table (net/ipv6/netfilter/ip6_tables.c:316) nf_hook_slow (net/netfilter/core.c:619) ipv6_rcv (net/ipv6/ip6_input.c:351) __netif_receive_skb_one_core (net/core/dev.c:6216) process_backlog (net/core/dev.c:6680) __napi_poll (net/core/dev.c:7739) net_rx_action (net/core/dev.c:7959) handle_softirqs (kernel/softirq.c:622) do_softirq.part.0 (kernel/softirq.c:523) __local_bh_enable_ip (kernel/softirq.c:450) __dev_queue_xmit (net/core/dev.c:4913) packet_sendmsg (net/packet/af_packet.c:3139) __sys_sendto (net/socket.c:2252) __x64_sys_sendto (net/socket.c:2259) do_syscall_64 (arch/x86/entry/syscall_64.c:94) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) Kernel panic - not syncing: Fatal exception in interrupt
Reject routes without an inet6_dev immediately after lookup. Such routes are not eligible for reverse-path filtering, and the check protects all later rt6i_idev dereferences.
--- net/ipv6/netfilter/ip6t_rpfilter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/netfilter/ip6t_rpfilter.c +1 -1
@@ -61,7 +61,7 @@ static bool rpfilter_lookup_reverse6(str fl6.flowi6_oif = dev->ifindex; rt = (void *)ip6_route_lookup (net, &fl6, skb, lookup_flags); -if (rt->dst.error) +if (rt->dst.error || !rt->rt6i_idev) goto out;if (rt->rt6i_flags & (RTF_REJECT |RTF_ANYCAST ))
Greg Kroah-Hartman
maintainerPATCH 726/752 netfilter: ip6t_rt: fix zero-address non-strict match out-of-bounds read
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit 82313c169eddc02b1bf5ba6b427803e272d3ec42 upstream.
rt_mt6_check() permits rules to be configured with rtinfo->addrnr == 0 even when address matching (IP6T_RT_FST_MASK) is requested.
In the IP6T_RT_FST_NSTRICT path, rt_mt6() evaluates packet routing addresses against rtinfo->addrs[i] and terminates backwards at the bottom of the loop:
if (ipv6_addr_equal(ap, &rtinfo->addrs[i])) {
i++;
}
if (i == rtinfo->addrnr)
break;When addrnr is 0, if the first packet address matches rtinfo->addrs[0], i is incremented to 1. Because i is now strictly greater than addrnr (0), the loop termination condition (i == rtinfo->addrnr) is bypassed and will never be satisfied.
If a crafted IPv6 packet contains matching routing addresses, i will advance past IP6T_RT_HOPS (16). The subsequent call to ipv6_addr_equal() reads beyond struct ip6t_rt, triggering UBSAN/KASAN out-of-bounds warnings or kernel panics.
Fix this by:
1. Rejecting rules in rt_mt6_check() where IP6T_RT_FST_MASK is set but rtinfo->addrnr is zero.
2. In rt_mt6(), moving the termination condition (i < rtinfo->addrnr) into the for-loop header condition and removing the backwards break at the end of the loop body.
--- net/ipv6/netfilter/ip6t_rt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
net/ipv6/netfilter/ip6t_rt.c +8 -3
@@ -96,7 +96,8 @@ static bool rt_mt6(const struct sk_buffunsigned int i =0 ;for (temp =0 ; - temp < (unsigned int )((hdrlen -8 ) /16 ); + temp < (unsigned int )((hdrlen -8 ) /16 ) && + i < rtinfo->addrnr; temp++) { ap =skb_header_pointer (skb, ptr
@@ -112,8 +113,6 @@ static bool rt_mt6(const struct sk_buffif (ipv6_addr_equal (ap, &rtinfo->addrs[i])) i++; -if (i == rtinfo->addrnr) -break ; }if (i == rtinfo->addrnr)return ret;
@@ -162,6 +161,12 @@ static int rt_mt6_check(const struct xt_pr_debug ("too many addresses specified\n" );return -EINVAL ; } + +if ((rtinfo->flags &IP6T_RT_FST_MASK ) && !rtinfo->addrnr) { +pr_info_ratelimited ("address list match requested but addrnr is 0\n" ); +return -EINVAL ; + } + if ((rtinfo->flags & (IP6T_RT_RES | IP6T_RT_FST_MASK)) && (!(rtinfo->flags & IP6T_RT_TYP) || (rtinfo->rt_type != 0) ||
Greg Kroah-Hartman
maintainerPATCH 727/752 nfc: fix use-after-free in nfc_get_local_general_bytes
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luxiao Xu <[email protected]>
commit dcab71a7011918f6fdba7adcec02d217dcb84b8d upstream.
Commit 6709d4b7bc2e ("net: nfc: Fix use-after-free caused by nfc_llcp_find_local") attempted to fix a use-after-free (UAF) issue by invoking nfc_llcp_local_put(local) after accessing local->gb. However, if the reference count drops to zero, local is freed immediately, leading to a use-after-free when callers access the returned pointer. Alternative approaches using dynamic allocation (e.g. kmemdup) introduced memory leaks because callers consistently treat the returned pointer as borrowed memory.
Fix this properly by refactoring nfc_llcp_general_bytes() and nfc_get_local_general_bytes() to accept a caller-provided output buffer (out_gb) and its maximum length (gb_max_len). The general bytes are safely copied into out_gb before calling nfc_llcp_local_put(local), ensuring safe lifetime management without ownership transfer complications.
Update all callers across drivers (microread, pn533, pn544, st21nfca, digital_dep, and nci) to provide their own destination buffers and pass them to nfc_get_local_general_bytes().
--- drivers/nfc/microread/microread.c | 6 +++--- drivers/nfc/pn533/pn533.c | 14 ++++++++------ drivers/nfc/pn533/pn533.h | 4 +++- drivers/nfc/pn544/pn544.c | 7 +++---- drivers/nfc/st21nfca/core.c | 8 ++++---- include/net/nfc/hci.h | 2 +- include/net/nfc/nfc.h | 3 ++- net/nfc/core.c | 15 +++++++-------- net/nfc/digital_dep.c | 8 ++++---- net/nfc/llcp_core.c | 17 +++++++++++++---- net/nfc/nci/core.c | 10 +++++----- net/nfc/nfc.h | 3 ++- 12 files changed, 55 insertions(+), 42 deletions(-)
drivers/nfc/microread/microread.c +3 -3
@@ -251,9 +251,9 @@ static int microread_start_poll(struct n param[1 ] |= (1 <<1 );if ((im_protocols | tm_protocols) &NFC_PROTO_NFC_DEP_MASK ) { - hdev->gb =nfc_get_local_general_bytes (hdev->ndev, - &hdev->gb_len); -if (hdev->gb ==NULL || hdev->gb_len ==0 ) { +nfc_get_local_general_bytes (hdev->ndev, hdev->gb, +sizeof (hdev->gb), &hdev->gb_len); +if (hdev->gb_len ==0 ) { im_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; }
drivers/nfc/pn533/pn533.c +8 -6
@@ -1357,10 +1357,11 @@ static int pn533_poll_dep(struct nfc_devu8 *next, nfcid3[NFC_NFCID3_MAXSIZE ];u8 passive_data[PASSIVE_DATA_LEN ] = {0x00 ,0xff ,0xff ,0x00 ,0x3 }; -if (!dev->gb) { - dev->gb =nfc_get_local_general_bytes (nfc_dev, &dev->gb_len); - -if (!dev->gb || !dev->gb_len) { +if (!dev->gb_len) { +nfc_get_local_general_bytes (nfc_dev, dev->gb, +sizeof (dev->gb), + &dev->gb_len); +if (!dev->gb_len) { dev->poll_dep =0 ;queue_work (dev->wq, &dev->rf_work); }
@@ -1662,8 +1663,9 @@ static int pn533_start_poll(struct nfc_d }if (tm_protocols) { - dev->gb =nfc_get_local_general_bytes (nfc_dev, &dev->gb_len); -if (dev->gb ==NULL ) +nfc_get_local_general_bytes (nfc_dev, dev->gb, +sizeof (dev->gb), &dev->gb_len); +if (dev->gb_len ==0 ) tm_protocols =0 ; }
drivers/nfc/pn533/pn533.h +3 -1
@@ -6,6 +6,8 @@* Copyright (C) 2012-2013 Tieto Poland */ +#include <net/nfc/nfc.h> +#define PN533_DEVICE_STD 0x1#define PN533_DEVICE_PASORI 0x2#define PN533_DEVICE_ACR122U 0x3
@@ -166,7 +168,7 @@ struct pn533 {struct timer_list listen_timer;int cancel_listen; -u8 *gb; +u8 gb[NFC_MAX_GT_LEN ];size_t gb_len;u8 tgt_available_prots;
drivers/nfc/pn544/pn544.c +3 -4
@@ -377,10 +377,9 @@ static int pn544_hci_start_poll(struct nreturn r;if ((im_protocols | tm_protocols) &NFC_PROTO_NFC_DEP_MASK ) { - hdev->gb =nfc_get_local_general_bytes (hdev->ndev, - &hdev->gb_len); -pr_debug ("generate local bytes %p\n" , hdev->gb); -if (hdev->gb ==NULL || hdev->gb_len ==0 ) { +nfc_get_local_general_bytes (hdev->ndev, hdev->gb, +sizeof (hdev->gb), &hdev->gb_len); +if (hdev->gb_len ==0 ) { im_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; }
drivers/nfc/st21nfca/core.c +4 -4
@@ -351,10 +351,10 @@ static int st21nfca_hci_start_poll(strucif (r <0 )return r; }else { - hdev->gb =nfc_get_local_general_bytes (hdev->ndev, - &hdev->gb_len); - -if (hdev->gb ==NULL || hdev->gb_len ==0 ) { +nfc_get_local_general_bytes (hdev->ndev, hdev->gb, +sizeof (hdev->gb), + &hdev->gb_len); +if (hdev->gb_len ==0 ) { im_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK ; }
include/net/nfc/hci.h +1 -1
@@ -144,7 +144,7 @@ struct nfc_hci_dev {data_exchange_cb_t async_cb;void *async_cb_context; -u8 *gb; +u8 gb[NFC_MAX_GT_LEN ];size_t gb_len;unsigned long quirks;
include/net/nfc/nfc.h +2 -1
@@ -269,7 +269,8 @@ struct sk_buff *nfc_alloc_recv_skb(unsigint nfc_set_remote_general_bytes (struct nfc_dev *dev,const u8 *gt,u8 gt_len); -u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,size_t *gb_len); +u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *out_gb, +size_t gb_max_len,size_t *gb_len);int nfc_fw_download_done (struct nfc_dev *dev,const char *firmware_name,u32 result);
net/nfc/core.c +7 -8
@@ -279,10 +279,10 @@ static struct nfc_target *nfc_find_targeint nfc_dep_link_up (struct nfc_dev *dev,int target_index,u8 comm_mode) { -int rc =0 ; -u8 *gb; -size_t gb_len;struct nfc_target *target; +u8 gb[NFC_MAX_GT_LEN ]; +size_t gb_len =0 ; +int rc =0 ;pr_debug ("dev_name=%s comm %d\n" ,dev_name (&dev->dev), comm_mode);
@@ -301,7 +301,7 @@ int nfc_dep_link_up(struct nfc_dev *dev, goto error; } - gb =nfc_llcp_general_bytes (dev, &gb_len); +nfc_get_local_general_bytes (dev, gb,sizeof (gb), &gb_len);if (gb_len >NFC_MAX_GT_LEN ) { rc = -EINVAL ; goto error;
@@ -644,11 +644,10 @@ int nfc_set_remote_general_bytes(struct }EXPORT_SYMBOL (nfc_set_remote_general_bytes); -u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,size_t *gb_len) +u8 *nfc_get_local_general_bytes (struct nfc_dev *dev,u8 *out_gb, +size_t gb_max_len,size_t *gb_len) { -pr_debug ("dev_name=%s\n" ,dev_name (&dev->dev)); - -return nfc_llcp_general_bytes (dev, gb_len); +return nfc_llcp_general_bytes (dev, out_gb, gb_max_len, gb_len); }EXPORT_SYMBOL (nfc_get_local_general_bytes);
net/nfc/digital_dep.c +4 -4
@@ -1490,14 +1490,14 @@ static int digital_tg_send_atr_res(struc struct digital_atr_req *atr_req) {struct digital_atr_res *atr_res; +u8 gb[NFC_MAX_GT_LEN ];struct sk_buff *skb; -u8 *gb, payload_bits; +u8 payload_bits;size_t gb_len;int rc; - gb =nfc_get_local_general_bytes (ddev->nfc_dev, &gb_len); -if (!gb) - gb_len =0 ; +nfc_get_local_general_bytes (ddev->nfc_dev, gb,sizeof (gb), + &gb_len); skb =digital_skb_alloc (ddev,sizeof (struct digital_atr_res ) + gb_len);if (!skb)
net/nfc/llcp_core.c +13 -4
@@ -653,23 +653,32 @@ out:return ret; } -u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,size_t *general_bytes_len) +u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,u8 *out_gb,size_t gb_max_len, +size_t *general_bytes_len) {struct nfc_llcp_local *local; +if (!out_gb || !general_bytes_len) +return NULL ; + local =nfc_llcp_find_local (dev); -if (local ==NULL ) { +if (!local) { *general_bytes_len =0 ;return NULL ; }nfc_llcp_build_gb (local); - *general_bytes_len = local->gb_len; +if (local->gb_len) { + *general_bytes_len =min_t (size_t, local->gb_len, gb_max_len); +memcpy (out_gb, local->gb, *general_bytes_len); + }else { + *general_bytes_len =0 ; + }nfc_llcp_local_put (local); -return local->gb; +return out_gb; }int nfc_llcp_set_remote_gb (struct nfc_dev *dev,const u8 *gb,u8 gb_len)
net/nfc/nci/core.c +5 -5
@@ -762,15 +762,15 @@ static int nci_set_local_general_bytes(s {struct nci_dev *ndev =nfc_get_drvdata (nfc_dev);struct nci_set_config_param param; +u8 gb[NFC_MAX_GT_LEN ];int rc; - param.val =nfc_get_local_general_bytes (nfc_dev, ¶m.len); -if ((param.val ==NULL ) || (param.len ==0 )) +nfc_get_local_general_bytes (nfc_dev, gb,sizeof (gb), + ¶m.len); +if (param.len ==0 )return 0 ; -if (param.len >NFC_MAX_GT_LEN ) -return -EINVAL ; - + param.val = gb; param.id =NCI_PN_ATR_REQ_GEN_BYTES ; rc = nci_request(ndev, nci_set_config_req, ¶m,
net/nfc/nfc.h +2 -1
@@ -49,7 +49,8 @@ void nfc_llcp_mac_is_up(struct nfc_dev *int nfc_llcp_register_device (struct nfc_dev *dev);void nfc_llcp_unregister_device (struct nfc_dev *dev);int nfc_llcp_set_remote_gb (struct nfc_dev *dev,const u8 *gb,u8 gb_len); -u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,size_t *general_bytes_len); +u8 *nfc_llcp_general_bytes (struct nfc_dev *dev,u8 *out_gb,size_t gb_max_len, +size_t *general_bytes_len);int nfc_llcp_data_received (struct nfc_dev *dev,struct sk_buff *skb);struct nfc_llcp_local *nfc_llcp_find_local (struct nfc_dev *dev);int nfc_llcp_local_put (struct nfc_llcp_local *local);
Greg Kroah-Hartman
maintainerPATCH 728/752 nfc: llcp: drop truncated I/RR/RNR PDUs in nfc_llcp_recv_hdlc()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
commit 273f9d667cde649f8de9d72b1303cc2f4b658c50 upstream.
nfc_llcp_recv_hdlc() reads the sequence byte skb->data[2], via nfc_llcp_ns()/nfc_llcp_nr(), before any length check. The receive path only guarantees the two-byte LLCP header -- __nfc_llcp_recv() checks it with pskb_may_pull() and nfc_llcp_recv_agf() admits two-byte inner PDUs -- so a two-byte I, RR or RNR PDU reads one byte of uninitialised skb tailroom. The byte becomes N(R)/N(S); a peer can already set those with a well-formed PDU, so this is acting on uninitialised memory, not new peer control.
Guard the read with pskb_may_pull(), as commit 95674f506c63 ("nfc: llcp:
reject PDUs shorter than the LLCP header") did for the two-byte header, so the sequence byte is present and linear before it is read. RR and RNR PDUs are LLCP_HEADER_SIZE + LLCP_SEQUENCE_SIZE bytes and an I PDU is longer, so no valid frame is rejected; a truncated PDU is malformed, so return without a DM reply.
--- net/nfc/llcp_core.c | 3 +++ 1 file changed, 3 insertions(+)
net/nfc/llcp_core.c +3 -0
@@ -1108,6 +1108,9 @@ static void nfc_llcp_recv_hdlc(struct nfstruct sock *sk;u8 dsap, ssap, ptype, ns, nr; +if (!pskb_may_pull (skb,LLCP_HEADER_SIZE +LLCP_SEQUENCE_SIZE )) +return ; + ptype =nfc_llcp_ptype (skb); dsap =nfc_llcp_dsap (skb); ssap =nfc_llcp_ssap (skb);
Greg Kroah-Hartman
maintainerPATCH 729/752 nfc: port100: reject frames whose declared length exceeds the received data
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit 092c6a605cbd6414ef499834c2e0da69c2c3388e upstream.
port100_recv_response() passes the URB transfer buffer to port100_rx_frame_is_valid(), which checksums le16_to_cpu(frame->datalen) bytes of frame->data. datalen is a 16-bit field supplied by the device and is never checked against the number of bytes actually received (urb->actual_length), so a device reporting a datalen larger than the received frame makes port100_data_checksum() read out of bounds past the transfer buffer.
Reject a response whose declared frame size does not fit the received length before validating it.
Found by 0sec (https://0sec.ai) using automated source analysis; the missing bound is evident from source. Compile-tested.
--- drivers/nfc/port100.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/nfc/port100.c +7 -0
@@ -636,6 +636,13 @@ static void port100_recv_response(struct in_frame = dev->in_urb->transfer_buffer; +if (urb->actual_length <PORT100_FRAME_HEADER_LEN || + urb->actual_length <port100_rx_frame_size (in_frame)) { +nfc_err (&dev->interface->dev,"Received a truncated frame\n" ); + cmd->status = -EIO ; + goto sched_wq; + } +if (!port100_rx_frame_is_valid (in_frame)) {nfc_err (&dev->interface->dev,"Received an invalid frame\n" ); cmd->status = -EIO ;
Greg Kroah-Hartman
maintainerPATCH 730/752 scsi: libiscsi_tcp: Check the data direction of a Data-In PDU
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
commit bce07e2f37b5e4a427d36fd6b1c14067b27591db upstream.
The Data-In branch of iscsi_tcp_hdr_dissect() resolves the ITT to a task and copies the PDU's data segment into that command's scatterlist without asking whether the command was reading. iscsi_tcp_r2t_rsp() in the same file does ask, and rejects an R2T for a command that is not DMA_TO_DEVICE.
A target that answers a WRITE command's ITT with a Data-In therefore has the initiator write target-supplied bytes into the pages that write was about to send. Those are the caller's own pinned pages for an O_DIRECT write, and page cache pages for a buffered one.
Observed against a test target that emits one 512-byte Data-In naming a 128 KB write's ITT, after the R2T for that write. With O_DIRECT the caller's buffer ends up holding 512 bytes of the target's data while pwrite() returns 131072. Buffered is quieter: pwrite() and fsync() both succeed, nothing is logged, and reading those blocks back returns the target's bytes out of the page cache without a command going on the wire.
Check the direction before using the scatterlist, the way the R2T path already does.
--- drivers/scsi/libiscsi_tcp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/scsi/libiscsi_tcp.c +3 -0
@@ -491,6 +491,9 @@ static int iscsi_tcp_data_in(struct iscsint datasn =be32_to_cpu (rhdr->datasn);unsigned total_in_length = task->sc->sdb.length; +if (task->sc->sc_data_direction !=DMA_FROM_DEVICE ) +return ISCSI_ERR_PROTO ; +/* * lib iscsi will update this in the completion handling if there * is status.
Greg Kroah-Hartman
maintainerPATCH 731/752 pinctrl: single: free the IRQ on domain creation failure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 1d9bb9c870632adea249cfdec49ac37e6f069164 upstream.
pcs_irq_init_chained_handler() requests a shared IRQ on affected SoCs, but its domain creation failure path only removes a chained handler. That does not release the action installed by request_irq(). The probe can continue without interrupt support while leaving the shared IRQ action registered.
Use pcs_irq_free() to undo the appropriate type of handler registration. At this point pcs->domain is NULL, so the helper only releases the parent IRQ handler. Then mark the IRQ invalid, as the other initialization error paths already do, to prevent another release from a later probe unwind or remove.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/pinctrl/pinctrl-single.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/pinctrl/pinctrl-single.c +2 -1
@@ -1631,7 +1631,8 @@ static int pcs_irq_init_chained_handler( &pcs_irqdomain_ops, pcs_soc);if (!pcs->domain) { -irq_set_chained_handler (pcs_soc->irq,NULL ); +pcs_irq_free (pcs); + pcs_soc->irq =-1 ;return -EINVAL ; }
Greg Kroah-Hartman
maintainerPATCH 732/752 s390/cio: Fix NULL pointer dereference in ccw_device_get_util_str()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
commit 5b76268dac968612f7283d59b539036de955b7d9 upstream.
The channel path registry entry associated with a CHPID may be removed while the subchannel's PMCW still references that CHPID. In this case, chpid_to_chp() can return NULL, leading to a NULL pointer dereference.
Add the missing NULL check before dereferencing the returned pointer.
--- drivers/s390/cio/device_ops.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/s390/cio/device_ops.c +2 -0
@@ -509,6 +509,8 @@ u8 *ccw_device_get_util_str(struct ccw_dchp_id_init (&chpid); chpid.id = sch->schib.pmcw.chpid[chp_idx]; chp =chpid_to_chp (chpid); +if (!chp) +return NULL ; util_str =kmalloc (sizeof (chp->desc_fmt3.util_str),GFP_KERNEL );if (!util_str)
Greg Kroah-Hartman
maintainerPATCH 733/752 Bluetooth: hci_sock: validate event length before filtering
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit b0a6cf99afd57a39598b1beca0e86ef5004980de upstream.
is_filtered_packet() reads the event code from skb->data[0] without first checking that the skb is nonempty. When an opcode filter is configured, it also reads the command opcode at offsets 3 or 4 without checking that a Command Complete or Command Status event is long enough.
hci_send_to_sock() invokes the filter before hci_event_packet() validates the event header. A malformed event supplied by a controller or a vhci device can therefore cause an out-of-bounds read.
Keep the unmasked event code for the opcode checks. The masked value is needed for the 64-bit event bitmap, but using it to identify command events aliases event codes above 0x3f. In particular, Synchronous Train Complete (0x4f) was treated as Command Status (0x0f) even though its payload has no opcode.
Reject actual command events that are too short for the field being inspected. A truncated command event cannot match a configured opcode.
--- net/bluetooth/hci_sock.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
net/bluetooth/hci_sock.c +14 -3
@@ -165,6 +165,7 @@ static bool is_filtered_packet(struct so {struct hci_filter *flt;int flt_type, flt_event; +u8 event;/* Apply filter */ flt = &hci_pi (sk)->filter;
@@ -178,7 +179,11 @@ static bool is_filtered_packet(struct soif (hci_skb_pkt_type (skb) !=HCI_EVENT_PKT )return false; - flt_event = (*(__u8 *)skb->data &HCI_FLT_EVENT_BITS ); +if (skb->len <1 ) +return true; + + event = *(__u8 *)skb->data; + flt_event = event &HCI_FLT_EVENT_BITS ;if (!hci_test_bit (flt_event, &flt->event_mask))return true;
@@ -187,11 +192,17 @@ static bool is_filtered_packet(struct soif (!flt->opcode)return false; -if (flt_event ==HCI_EV_CMD_COMPLETE && +if (event ==HCI_EV_CMD_COMPLETE && skb->len <5 ) +return true; + +if (event ==HCI_EV_CMD_COMPLETE && flt->opcode !=get_unaligned ((__le16 *)(skb->data +3 )))return true; -if (flt_event ==HCI_EV_CMD_STATUS && +if (event ==HCI_EV_CMD_STATUS && skb->len <6 ) +return true; + +if (event ==HCI_EV_CMD_STATUS && flt->opcode !=get_unaligned ((__le16 *)(skb->data +4 )))return true;
Greg Kroah-Hartman
maintainerPATCH 734/752 Bluetooth: hci_sock: reject out-of-range OCF values
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit e93fad891c72deb84cae49430163b384ebcc92b1 upstream.
The raw HCI socket security filter has 128 OCF bits per supported OGF, but masks the 10-bit OCF with 127 before looking up the command. An unprivileged socket can therefore submit a reserved OCF that aliases an allowlisted command modulo 128.
A conforming controller should reject reserved opcodes. Nevertheless, the security decision must apply to the opcode that will actually be sent, especially since controller-specific behavior is outside the host stack's control.
Reject OCF values that cannot be represented by the security filter instead of aliasing them onto an unrelated command.
--- net/bluetooth/hci_sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/bluetooth/hci_sock.c +2 -1
@@ -1848,7 +1848,8 @@ static int hci_sock_sendmsg(struct sockeu16 ocf =hci_opcode_ocf (opcode);if (((ogf >HCI_SFLT_MAX_OGF ) || - !hci_test_bit (ocf &HCI_FLT_OCF_BITS , + (ocf >HCI_FLT_OCF_BITS ) || + !hci_test_bit (ocf, &hci_sec_filter.ocf_mask[ogf])) && !capable (CAP_NET_RAW )) { err = -EPERM ;
Greg Kroah-Hartman
maintainerPATCH 735/752 Bluetooth: L2CAP: validate frame length before control and FCS access
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aldo Ariel Panzardo <[email protected]>
commit 6c78a213d9070b610c7f418af2c25b66180b7e37 upstream.
l2cap_data_rcv() unpacks either a two-byte or four-byte control field without first ensuring that it is present. A short ERTM or streaming-mode frame can therefore cause an out-of-bounds read.
There is a second short-frame case when CRC16 is enabled. After the control field is pulled, l2cap_check_fcs() subtracts two from skb->len without checking it. If fewer than two bytes remain, the subtraction wraps; skb_trim() leaves the buffer unchanged and the subsequent FCS load reads past the logical end of the frame.
Validate that the frame contains both its control field and, when enabled, its FCS before either field is accessed.
--- net/bluetooth/l2cap_core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +9 -1
@@ -7662,9 +7662,17 @@ static int l2cap_stream_rx(struct l2cap_static int l2cap_data_rcv (struct l2cap_chan *chan,struct sk_buff *skb) {struct l2cap_ctrl *control = &bt_cb (skb)->l2cap; -u16 len; +u16 len, min_len;u8 event; + min_len =test_bit (FLAG_EXT_CTRL , &chan->flags) ? +L2CAP_EXT_CTRL_SIZE :L2CAP_ENH_CTRL_SIZE ; +if (chan->fcs ==L2CAP_FCS_CRC16 ) + min_len +=L2CAP_FCS_SIZE ; + +if (skb->len < min_len) + goto drop; +__unpack_control (chan, skb); len = skb->len;
Greg Kroah-Hartman
maintainerPATCH 736/752 Bluetooth: RFCOMM: fix NULL dereference of dlc->session in RFCOMM_CONNINFO
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Peng <[email protected]>
commit 46f8ffd0a1f1eb6cbc94946a92c11ef601e228a1 upstream.
The RFCOMM_CONNINFO getsockopt handler accepts a socket that is not connected as long as deferred setup is enabled:
if (sk->sk_state != BT_CONNECTED &&
!rfcomm_pi(sk)->dlc->defer_setup) {
err = -ENOTCONN;
break;
}
l2cap_sk = rfcomm_pi(sk)->dlc->session->sock->sk;dlc->defer_setup is set in rfcomm_sock_init() when rfcomm_connect_ind() creates a child socket for an incoming connection on a listening socket that has BT_DEFER_SETUP enabled. It is never cleared afterwards. The session, however, can go away underneath it.
rfcomm_recv_disc() forces the dlc state before tearing it down:
d->state = BT_CLOSED; __rfcomm_dlc_close(d, err);
The RFCOMM_DEFER_SETUP early return in __rfcomm_dlc_close() only covers BT_CONNECT, BT_CONFIG, BT_OPEN and BT_CONNECT2, so with the state already BT_CLOSED that switch does not match and the function falls through to rfcomm_dlc_unlink(), which sets d->session = NULL, while d->defer_setup stays 1.
A getsockopt(SOL_RFCOMM, RFCOMM_CONNINFO) on the accepted socket after that point therefore skips the -ENOTCONN path -- sk->sk_state is BT_CLOSED, but dlc->defer_setup is still set -- and dereferences the NULL session. No race is needed: once the DISC has been processed, the dereference is unconditional.
Reproduced on a KASAN kernel under QEMU with a BR/EDR peer emulated over /dev/vhci: the peer brings up an ACL link, opens L2CAP on the RFCOMM PSM, starts a session and sends SABM for a channel bound with BT_DEFER_SETUP, and sends DISC for that dlci after the socket has been accepted. getsockopt(SOL_RFCOMM, RFCOMM_CONNINFO) on the accepted socket then hits:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000002: 0000 [#1] SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000010-0x0000000000000017] CPU: 1 UID: 0 PID: 150 Comm: init Tainted: G B 7.3.0-rc3-g5dd1818b15d9 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) RIP: 0010:rfcomm_sock_getsockopt+0x529/0x780 Call Trace: <TASK> do_sock_getsockopt+0x3ad/0x7d0 __sys_getsockopt+0x10e/0x1b0 __x64_sys_getsockopt+0xc2/0x160 do_syscall_64+0xda/0x4b0 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
0x10 is the offset of sock in struct rfcomm_session; rfcomm_sock_getsockopt_old() is inlined into rfcomm_sock_getsockopt().
Commit 43a556b2fd43 ("Bluetooth: RFCOMM: take rfcomm_mutex for the deferred setup accept") fixed the same "a remote DISC clears the session while deferred setup is still flagged" problem in rfcomm_dlc_accept(); this is the remaining instance of it, in the getsockopt path.
Deferred setup only leaves a socket usable here once it has reached BT_CONNECT2, so restrict the exception to that state and check that a session is actually present before following it.
--- net/bluetooth/rfcomm/sock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/rfcomm/sock.c +4 -2
@@ -786,8 +786,10 @@ static int rfcomm_sock_getsockopt_old(stbreak ;case RFCOMM_CONNINFO : -if (sk->sk_state !=BT_CONNECTED && - !rfcomm_pi (sk)->dlc->defer_setup) { +if ((sk->sk_state !=BT_CONNECTED && + !(sk->sk_state ==BT_CONNECT2 && +rfcomm_pi (sk)->dlc->defer_setup)) || + !rfcomm_pi (sk)->dlc->session) { err = -ENOTCONN ;break ; }
Greg Kroah-Hartman
maintainerPATCH 737/752 xfs: fix blockgc group quota scanning when usrquota isnt enforced
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
commit f8f6382ff13109e19d0fc1d0224ff7d29641e56a upstream.
LOLLM noticed the copy-paste error here -- if user quotas aren't enforced but we're near the group quota limit, we fail to set FLAG_GID and hence we might not actually free any preallocations, causing unnecessary EDQUOT. Fix that.
--- fs/xfs/xfs_icache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_icache.c +1 -1
@@ -1560,7 +1560,7 @@ xfs_blockgc_free_dquots( do_work = true; } -if (XFS_IS_UQUOTA_ENFORCED (mp) && gdqp &&xfs_dquot_lowsp (gdqp)) { +if (XFS_IS_GQUOTA_ENFORCED (mp) && gdqp &&xfs_dquot_lowsp (gdqp)) { icw.icw_gid =make_kgid (mp->m_super->s_user_ns, gdqp->q_id); icw.icw_flags |=XFS_ICWALK_FLAG_GID ; do_work = true;
Greg Kroah-Hartman
maintainerPATCH 738/752 net: tls: fix silent data drop under pipe back-pressure
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Kicinski <[email protected]>
[ Upstream commit 7e7be31bfdb066c1c780dcd6b1224078fc54063f ]
tls_sw_splice_read() uses len when advancing rxm->offset / rxm->full_len after skb_splice_bits(), rather than copied (the actual number of bytes successfully spliced into the pipe). When the destination pipe cannot accept all the requested bytes, splice_to_pipe() returns fewer bytes than len, and 'len - copied' of data is effectively skipped over.
--- net/tls/tls_sw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/tls/tls_sw.c +3 -3
@@ -2078,10 +2078,10 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos, ctx->recv_pkt =NULL ;__strp_unpause (&ctx->strp); } -if (chunk < rxm->full_len) { +if (copied < rxm->full_len) {__skb_queue_head (&ctx->rx_list, skb); - rxm->offset += len; - rxm->full_len -= len; + rxm->offset += copied; + rxm->full_len -= copied; }else {consume_skb (skb); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 739/752 eventpoll: dont decrement ep refcount while still holding the ep mutex
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linus Torvalds <[email protected]>
commit 8c2e52ebbe885c7eeaabd3b7ddcdc1246fc400d2 upstream.
Jann Horn points out that epoll is decrementing the ep refcount and then doing a
mutex_unlock(&ep->mtx);
afterwards. That's very wrong, because it can lead to a use-after-free.
That pattern is actually fine for the very last reference, because the code in question will delay the actual call to "ep_free(ep)" until after it has unlocked the mutex.
But it's wrong for the much subtler "next to last" case when somebody *else* may also be dropping their reference and free the ep while we're still using the mutex.
Note that this is true even if that other user is also using the same ep
mutex: mutexes, unlike spinlocks, can not be used for object ownership, even if they guarantee mutual exclusion.
A mutex "unlock" operation is not atomic, and as one user is still accessing the mutex as part of unlocking it, another user can come in and get the now released mutex and free the data structure while the first user is still cleaning up.
See our mutex documentation in Documentation/locking/mutex-design.rst, in particular the section [1] about semantics:
"mutex_unlock() may access the mutex structure even after it has
internally released the lock already - so it's not safe for another context to acquire the mutex and assume that the mutex_unlock() context is not using the structure anymore"
So if we drop our ep ref before the mutex unlock, but we weren't the last one, we may then unlock the mutex, another user comes in, drops _their_ reference and releases the 'ep' as it now has no users - all while the mutex_unlock() is still accessing it.
Fix this by simply moving the ep refcount dropping to outside the mutex:
the refcount itself is atomic, and doesn't need mutex protection (that's the whole _point_ of refcounts: unlike mutexes, they are inherently about object lifetimes).
--- fs/eventpoll.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fs/eventpoll.c +5 -7
@@ -770,7 +770,7 @@ static bool __ep_remove(struct eventpoll *ep, struct epitem *epi, bool force)call_rcu (&epi->rcu, epi_rcu_free);percpu_counter_dec (&ep->user->epoll_watches); -return ep_refcount_dec_and_test (ep); +return true; }/*
@@ -778,14 +778,14 @@ static bool __ep_remove(struct eventpoll *ep, struct epitem *epi, bool force)*/ static void ep_remove_safe (struct eventpoll *ep,struct epitem *epi) { -WARN_ON_ONCE (__ep_remove (ep, epi, false)); +if (__ep_remove (ep, epi, false)) +WARN_ON_ONCE (ep_refcount_dec_and_test (ep)); }static void ep_clear_and_put (struct eventpoll *ep) {struct rb_node *rbp, *next;struct epitem *epi; -bool dispose;/* We need to release all tasks waiting for these file */ if (waitqueue_active (&ep->poll_wait))
@@ -818,10 +818,8 @@ static void ep_clear_and_put(struct eventpoll *ep)cond_resched (); } - dispose =ep_refcount_dec_and_test (ep);mutex_unlock (&ep->mtx); - -if (dispose) +if (ep_refcount_dec_and_test (ep))ep_free (ep); }
@@ -1001,7 +999,7 @@ void eventpoll_release_file(struct file *file) dispose =__ep_remove (ep, epi, true);mutex_unlock (&ep->mtx); -if (dispose) +if (dispose &&ep_refcount_dec_and_test (ep))ep_free (ep); goto again; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 740/752 file: add fput() cleanup helper
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 257b1c2c78c25643526609dee0c15f1544eb3252 ]
Add a simple helper to put a file reference.
--- include/linux/file.h | 2 ++ 1 file changed, 2 insertions(+)
include/linux/file.h +2 -0
@@ -11,6 +11,7 @@#include <linux/posix_types.h> #include <linux/errno.h> #include <linux/cleanup.h> +#include <linux/err.h> struct file ;
@@ -95,6 +96,7 @@ extern void put_unused_fd(unsigned int fd); DEFINE_CLASS(get_unused_fd, int, if (_T >= 0) put_unused_fd(_T), get_unused_fd_flags(flags), unsigned flags) +DEFINE_FREE(fput, struct file *, if (!IS_ERR_OR_NULL(_T)) fput(_T))extern void fd_install (unsigned int fd,struct file *file);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 741/752 eventpoll: use hlist_is_singular_node() in __ep_remove()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 3d9fd0abc94d8cd430cc7cd7d37ce5e5aae2cd2b ]
Replace the open-coded "epi is the only entry in file->f_ep" check with hlist_is_singular_node(). Same semantics, and the helper avoids the head-cacheline access in the common false case.
Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF")
--- fs/eventpoll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/eventpoll.c +1 -1
@@ -738,7 +738,7 @@ static bool __ep_remove(struct eventpoll *ep, struct epitem *epi, bool force) to_free =NULL ; head = file->f_ep; -if (head->first == &epi->fllink && !epi->fllink.next) { +if (hlist_is_singular_node (&epi->fllink, head)) {/* See eventpoll_release() for details. */ WRITE_ONCE (file->f_ep,NULL );if (!is_file_epoll (file)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 742/752 eventpoll: split __ep_remove()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 0f7bdfd413000985de09fc39eb9efa1e091a3ce0 ]
Split __ep_remove() to delineate file removal from epoll item removal.
Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF")
--- fs/eventpoll.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
fs/eventpoll.c +23 -4
@@ -708,6 +708,9 @@ static void ep_free(struct eventpoll *ep)kfree_rcu (ep, rcu); } +static void __ep_remove_file (struct eventpoll *ep,struct epitem *epi,struct file *file); +static bool __ep_remove_epi (struct eventpoll *ep,struct epitem *epi); +/* * Removes a "struct epitem" from the eventpoll RB tree and deallocates * all the associated resources. Must be called with "mtx" held.
@@ -719,8 +722,6 @@ static void ep_free(struct eventpoll *ep)static bool __ep_remove (struct eventpoll *ep,struct epitem *epi,bool force) {struct file *file = epi->ffd.file; -struct epitems_head *to_free; -struct hlist_head *head;lockdep_assert_irqs_enabled ();
@@ -736,8 +737,21 @@ static bool __ep_remove(struct eventpoll *ep, struct epitem *epi, bool force)return false; } - to_free =NULL ; - head = file->f_ep; +__ep_remove_file (ep, epi, file); +return __ep_remove_epi (ep, epi); +} + +/* +* Called with &file->f_lock held, +* returns with it released +*/ +static void __ep_remove_file (struct eventpoll *ep,struct epitem *epi,struct file *file) +{ +struct epitems_head *to_free =NULL ; +struct hlist_head *head = file->f_ep; + +lockdep_assert_held (&ep->mtx); +if (hlist_is_singular_node (&epi->fllink, head)) {/* See eventpoll_release() for details. */ WRITE_ONCE (file->f_ep,NULL );
@@ -751,6 +765,11 @@ static bool __ep_remove(struct eventpoll *ep, struct epitem *epi, bool force)hlist_del_rcu (&epi->fllink);spin_unlock (&file->f_lock);free_ephead (to_free); +} + +static bool __ep_remove_epi (struct eventpoll *ep,struct epitem *epi) +{ +lockdep_assert_held (&ep->mtx);rb_erase_cached (&epi->rbn, &ep->rbr);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 743/752 eventpoll: kill __ep_remove()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit e9e5cd40d7c403e19f21d0f7b8b8ba3a76b58330 ]
Remove the boolean conditional in __ep_remove() and restructure the code so the check for racing with eventpoll_release_file() are only done in the ep_remove_safe() path where they belong.
Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF")
--- fs/eventpoll.c | 67 ++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 37 deletions(-)
fs/eventpoll.c +30 -37
@@ -708,49 +708,18 @@ static void ep_free(struct eventpoll *ep)kfree_rcu (ep, rcu); } -static void __ep_remove_file (struct eventpoll *ep,struct epitem *epi,struct file *file); -static bool __ep_remove_epi (struct eventpoll *ep,struct epitem *epi); - -/* -* Removes a "struct epitem" from the eventpoll RB tree and deallocates -* all the associated resources. Must be called with "mtx" held. -* If the dying flag is set, do the removal only if force is true. -* This prevents ep_clear_and_put() from dropping all the ep references -* while running concurrently with eventpoll_release_file(). -* Returns true if the eventpoll can be disposed. -*/ -static bool __ep_remove (struct eventpoll *ep,struct epitem *epi,bool force) -{ -struct file *file = epi->ffd.file; - -lockdep_assert_irqs_enabled (); - -/* -* Removes poll wait queue hooks. -*/ -ep_unregister_pollwait (ep, epi); - -/* Remove the current item from the list of epoll hooks */ -spin_lock (&file->f_lock); -if (epi->dying && !force) { -spin_unlock (&file->f_lock); -return false; - } - -__ep_remove_file (ep, epi, file); -return __ep_remove_epi (ep, epi); -} -/* * Called with &file->f_lock held, * returns with it released */ -static void __ep_remove_file (struct eventpoll *ep,struct epitem *epi,struct file *file) +static void __ep_remove_file (struct eventpoll *ep,struct epitem *epi, +struct file *file) {struct epitems_head *to_free =NULL ;struct hlist_head *head = file->f_ep;lockdep_assert_held (&ep->mtx); +lockdep_assert_held (&file->f_lock);if (hlist_is_singular_node (&epi->fllink, head)) {/* See eventpoll_release() for details. */
@@ -797,7 +766,25 @@ static bool __ep_remove_epi(struct eventpoll *ep, struct epitem *epi)*/ static void ep_remove_safe (struct eventpoll *ep,struct epitem *epi) { -if (__ep_remove (ep, epi, false)) +struct file *file = epi->ffd.file; + +lockdep_assert_irqs_enabled (); +lockdep_assert_held (&ep->mtx); + +ep_unregister_pollwait (ep, epi); + +/* sync with eventpoll_release_file() */ +if (unlikely (READ_ONCE (epi->dying))) +return ; + +spin_lock (&file->f_lock); +if (epi->dying) { +spin_unlock (&file->f_lock); +return ; + } +__ep_remove_file (ep, epi, file); + +if (__ep_remove_epi (ep, epi))WARN_ON_ONCE (ep_refcount_dec_and_test (ep)); }
@@ -1006,7 +993,7 @@ void eventpoll_release_file(struct file *file)spin_lock (&file->f_lock);if (file->f_ep && file->f_ep->first) { epi = hlist_entry(file->f_ep->first, struct epitem, fllink); - epi->dying = true; +WRITE_ONCE (epi->dying, true);spin_unlock (&file->f_lock);/*
@@ -1015,7 +1002,13 @@ void eventpoll_release_file(struct file *file)*/ ep = epi->ep;mutex_lock (&ep->mtx); - dispose =__ep_remove (ep, epi, true); + +ep_unregister_pollwait (ep, epi); + +spin_lock (&file->f_lock); +__ep_remove_file (ep, epi, file); + dispose =__ep_remove_epi (ep, epi); +mutex_unlock (&ep->mtx);if (dispose &&ep_refcount_dec_and_test (ep))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 744/752 eventpoll: drop vestigial __ prefix from ep_remove_{file,epi}()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 0feaf644f7180c4a91b6b405a881afbfd958f1cf ]
With __ep_remove() gone, the double-underscore on __ep_remove_file() and __ep_remove_epi() no longer contrasts with a __-less parent and just reads as noise. Rename both to ep_remove_file() and ep_remove_epi(). No functional change.
Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF")
--- fs/eventpoll.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/eventpoll.c +6 -6
@@ -712,7 +712,7 @@ static void ep_free(struct eventpoll *ep)* Called with &file->f_lock held, * returns with it released */ -static void __ep_remove_file (struct eventpoll *ep,struct epitem *epi, +static void ep_remove_file (struct eventpoll *ep,struct epitem *epi,struct file *file) {struct epitems_head *to_free =NULL ;
@@ -736,7 +736,7 @@ static void __ep_remove_file(struct eventpoll *ep, struct epitem *epi,free_ephead (to_free); } -static bool __ep_remove_epi (struct eventpoll *ep,struct epitem *epi) +static bool ep_remove_epi (struct eventpoll *ep,struct epitem *epi) {lockdep_assert_held (&ep->mtx);
@@ -782,9 +782,9 @@ static void ep_remove_safe(struct eventpoll *ep, struct epitem *epi)spin_unlock (&file->f_lock);return ; } -__ep_remove_file (ep, epi, file); +ep_remove_file (ep, epi, file); -if (__ep_remove_epi (ep, epi)) +if (ep_remove_epi (ep, epi))WARN_ON_ONCE (ep_refcount_dec_and_test (ep)); }
@@ -1006,8 +1006,8 @@ void eventpoll_release_file(struct file *file)ep_unregister_pollwait (ep, epi);spin_lock (&file->f_lock); -__ep_remove_file (ep, epi, file); - dispose =__ep_remove_epi (ep, epi); +ep_remove_file (ep, epi, file); + dispose =ep_remove_epi (ep, epi);mutex_unlock (&ep->mtx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 745/752 eventpoll: rename ep_remove_safe() back to ep_remove()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 0bade234723e40e4937be912e105785d6a51464e ]
The current name is just confusing and doesn't clarify anything.
Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF")
--- fs/eventpoll.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/eventpoll.c +8 -8
@@ -764,7 +764,7 @@ static bool ep_remove_epi(struct eventpoll *ep, struct epitem *epi)/* * ep_remove variant for callers owing an additional reference to the ep */ -static void ep_remove_safe (struct eventpoll *ep,struct epitem *epi) +static void ep_remove (struct eventpoll *ep,struct epitem *epi) {struct file *file = epi->ffd.file;
@@ -811,7 +811,7 @@ static void ep_clear_and_put(struct eventpoll *ep)/* * Walks through the whole tree and try to free each "struct epitem". -* Note that ep_remove_safe() will not remove the epitem in case of a +* Note that ep_remove() will not remove the epitem in case of a * racing eventpoll_release_file(); the latter will do the removal. * At this point we are sure no poll callbacks will be lingering around. * Since we still own a reference to the eventpoll struct, the loop can't
@@ -820,7 +820,7 @@ static void ep_clear_and_put(struct eventpoll *ep)for (rbp =rb_first_cached (&ep->rbr); rbp; rbp = next) { next =rb_next (rbp); epi = rb_entry(rbp, struct epitem, rbn); -ep_remove_safe (ep, epi); +ep_remove (ep, epi);cond_resched (); }
@@ -1585,21 +1585,21 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,mutex_unlock (&tep->mtx);/* -* ep_remove_safe() calls in the later error paths can't lead to +* ep_remove() calls in the later error paths can't lead to * ep_free() as the ep file itself still holds an ep reference. */ ep_get (ep);/* now check if we've created too many backpaths */ if (unlikely (full_check &&reverse_path_check ())) { -ep_remove_safe (ep, epi); +ep_remove (ep, epi);return -EINVAL ; }if (epi->event.events &EPOLLWAKEUP ) { error =ep_create_wakeup_source (epi);if (error) { -ep_remove_safe (ep, epi); +ep_remove (ep, epi);return error; } }
@@ -1623,7 +1623,7 @@ static int ep_insert(struct eventpoll *ep, const struct epoll_event *event,* high memory pressure. */ if (unlikely (!epq.epi)) { -ep_remove_safe (ep, epi); +ep_remove (ep, epi);return -ENOMEM ; }
@@ -2302,7 +2302,7 @@ int do_epoll_ctl(int epfd, int op, int fd, struct epoll_event *epds,* The eventpoll itself is still alive: the refcount * can't go to zero here. */ -ep_remove_safe (ep, epi); +ep_remove (ep, epi); error =0 ; }else { error = -ENOENT ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 746/752 eventpoll: move epi_fget() up
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 86e87059e6d1fd5115a31949726450ed03c1073b ]
We'll need it when removing files so move it up. No functional change.
Stable-dep-of: a6dc643c6931 ("eventpoll: fix ep_remove struct eventpoll / struct file UAF") [file_ref_get(&file->f_ref) from original commit left as
atomic_long_inc_not_zero(&file->f_count) due to v6.12.y missing commit 90ee6ed776c0 ("fs: port files to file_ref") and its dependent commit 08ef26ea9ab3 ("fs: add file_ref")]
--- fs/eventpoll.c | 56 +++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 28 deletions(-)
fs/eventpoll.c +28 -28
@@ -708,6 +708,34 @@ static void ep_free(struct eventpoll *ep)kfree_rcu (ep, rcu); } +/* +* The ffd.file pointer may be in the process of being torn down due to +* being closed, but we may not have finished eventpoll_release() yet. +* +* Normally, even with the atomic_long_inc_not_zero, the file may have +* been free'd and then gotten re-allocated to something else (since +* files are not RCU-delayed, they are SLAB_TYPESAFE_BY_RCU). +* +* But for epoll, users hold the ep->mtx mutex, and as such any file in +* the process of being free'd will block in eventpoll_release_file() +* and thus the underlying file allocation will not be free'd, and the +* file re-use cannot happen. +* +* For the same reason we can avoid a rcu_read_lock() around the +* operation - 'ffd.file' cannot go away even if the refcount has +* reached zero (but we must still not call out to ->poll() functions +* etc). +*/ +static struct file *epi_fget (const struct epitem *epi) +{ +struct file *file; + + file = epi->ffd.file; +if (!atomic_long_inc_not_zero (&file->f_count)) + file =NULL ; +return file; +} +/* * Called with &file->f_lock held, * returns with it released
@@ -879,34 +907,6 @@ static __poll_t __ep_eventpoll_poll(struct file *file, poll_table *wait, int depreturn res; } -/* -* The ffd.file pointer may be in the process of being torn down due to -* being closed, but we may not have finished eventpoll_release() yet. -* -* Normally, even with the atomic_long_inc_not_zero, the file may have -* been free'd and then gotten re-allocated to something else (since -* files are not RCU-delayed, they are SLAB_TYPESAFE_BY_RCU). -* -* But for epoll, users hold the ep->mtx mutex, and as such any file in -* the process of being free'd will block in eventpoll_release_file() -* and thus the underlying file allocation will not be free'd, and the -* file re-use cannot happen. -* -* For the same reason we can avoid a rcu_read_lock() around the -* operation - 'ffd.file' cannot go away even if the refcount has -* reached zero (but we must still not call out to ->poll() functions -* etc). -*/ -static struct file *epi_fget (const struct epitem *epi) -{ -struct file *file; - - file = epi->ffd.file; -if (!atomic_long_inc_not_zero (&file->f_count)) - file =NULL ; -return file; -} -/* * Differs from ep_eventpoll_poll() in that internal callers already have * the ep->mtx so we need to start from depth=1, such that mutex_lock_nested()
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 747/752 eventpoll: fix ep_remove struct eventpoll / struct file UAF
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit a6dc643c69311677c574a0f17a3f4d66a5f3744b ]
ep_remove() (via ep_remove_file()) cleared file->f_ep under file->f_lock but then kept using @file inside the critical section (is_file_epoll(), hlist_del_rcu() through the head, spin_unlock). A concurrent __fput() taking the eventpoll_release() fastpath in that window observed the transient NULL, skipped eventpoll_release_file() and ran to f_op->release / file_free().
For the epoll-watches-epoll case, f_op->release is ep_eventpoll_release() -> ep_clear_and_put() -> ep_free(), which kfree()s the watched struct eventpoll. Its embedded ->refs hlist_head is exactly where epi->fllink.pprev points, so the subsequent hlist_del_rcu()'s "*pprev = next" scribbles into freed kmalloc-192 memory.
In addition, struct file is SLAB_TYPESAFE_BY_RCU, so the slot backing @file could be recycled by alloc_empty_file() -- reinitializing f_lock and f_ep -- while ep_remove() is still nominally inside that lock. The upshot is an attacker-controllable kmem_cache_free() against the wrong slab cache.
Pin @file via epi_fget() at the top of ep_remove() and gate the critical section on the pin succeeding. With the pin held @file cannot reach refcount zero, which holds __fput() off and transitively keeps the watched struct eventpoll alive across the hlist_del_rcu() and the f_lock use, closing both UAFs.
If the pin fails @file has already reached refcount zero and its __fput() is in flight. Because we bailed before clearing f_ep, that path takes the eventpoll_release() slow path into eventpoll_release_file() and blocks on ep->mtx until the waiter side's ep_clear_and_put() drops it. The bailed epi's share of ep->refcount stays intact, so the trailing ep_refcount_dec_and_test() in ep_clear_and_put() cannot free the eventpoll out from under eventpoll_release_file(); the orphaned epi is then cleaned up there.
A successful pin also proves we are not racing eventpoll_release_file() on this epi, so drop the now-redundant re-check of epi->dying under f_lock. The cheap lockless READ_ONCE(epi->dying) fast-path bailout stays.
--- fs/eventpoll.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
fs/eventpoll.c +10 -6
@@ -794,22 +794,26 @@ static bool ep_remove_epi(struct eventpoll *ep, struct epitem *epi)*/ static void ep_remove (struct eventpoll *ep,struct epitem *epi) { -struct file *file = epi->ffd.file; + struct file *file __free(fput) = NULL;lockdep_assert_irqs_enabled ();lockdep_assert_held (&ep->mtx);ep_unregister_pollwait (ep, epi); -/* sync with eventpoll_release_file() */ +/* cheap sync with eventpoll_release_file() */ if (unlikely (READ_ONCE (epi->dying)))return ; -spin_lock (&file->f_lock); -if (epi->dying) { -spin_unlock (&file->f_lock); +/* +* If we manage to grab a reference it means we're not in +* eventpoll_release_file() and aren't going to be. +*/ + file =epi_fget (epi); +if (!file)return ; - } + +spin_lock (&file->f_lock);ep_remove_file (ep, epi, file);if (ep_remove_epi (ep, epi))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 748/752 perf test: Change all remaining #!/bin/sh to #!/bin/bash
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Clark <[email protected]>
commit 2f5d370dec3f800b44bbf7b68875d521e0af43cd upstream.
There are 43 instances of posix shell tests and 35 instances of bash. To give us a single consistent language for testing in, replace all #!/bin/sh to #!/bin/bash. Common sources that are included in both different shells will now work as expected. And we no longer have to fix up bashisms that appear to work when someone's system has sh symlinked to bash, but don't work on other systems that have both shells installed.
Although we could have chosen sh, it's not backwards compatible so it wouldn't be possible to bulk convert without re-writing the existing bash tests.
Choosing bash also gives us some nicer features including 'local' variable definitions and regexes in if statements that are already widely used in the tests.
It's not expected that there are any users with only sh available due to the large number of bash tests that exist.
Discussed in relation to running shellcheck here:
https://lore.kernel.org/linux-perf-users/e3751a74be34bbf3781c4644f518702a7270220b.1749785642.git.collin.funk1@gmail.com/
When commit b02027776ac5 ("perf tests: Fix flakiness in BPF counters test on hybrid systems") was backported to several stable series (v5.15.221, v6.1.188, v6.6.157, v6.12.110, v6.18.52, v7.2.6) it introduced specific bash syntax. For versions after 2f5d370dec3f ("perf
test: Change all remaining #!/bin/sh to #!/bin/bash") in v6.17-rc1 this is not a problem as the shebang was already hanged to #!/bin/bash. For the older stable series this introduced invalid syntax if #!/bin/sh is not bash:
$ sh -n tools/perf/tests/shell/stat_bpf_counters.sh
tools/perf/tests/shell/stat_bpf_counters.sh: 12: Syntax error: "(" unexpected $ checkbashism tools/perf/tests/shell/stat_bpf_counters.sh
possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 52 (bash arrays, ${name[0|*|@]}):
base_instructions=$(perf stat --no-big-num -e instructions:u -- "${workload[@]}" 2>&1 | \
awk -v i=0 -v c=0 '/instructions/ { \
if ($1 != "<not") { i++; c += $1 } \
} END { if (i > 0) printf "%.0f", c; else print "<not" }')
possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 57 (bash arrays, ${name[0|*|@]}):
bpf_instructions=$(perf stat --no-big-num --bpf-counters -e instructions:u \
-- "${workload[@]}" 2>&1 | \
awk -v i=0 -v c=0 '/instructions/ { \
if ($1 != "<not") { i++; c += $1 } \
} END { if (i > 0) printf "%.0f", c; else print "<not" }')
possible bashism in tools/perf/tests/shell/stat_bpf_counters.sh line 68 (bash arrays, ${name[0|*|@]}):
stat_output=$(perf stat --no-big-num \
-e instructions/name=base_instructions/u,instructions/name=bpf_instructions/bu \
-- "${workload[@]}" 2>&1)Change shebang for the stat_bpf_counters.sh script.
No upstream commit exists for this change as for versions post 6.17-rc1 the scripts were converted to #!/bin/bash already.
--- tools/perf/tests/shell/stat_bpf_counters.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/tests/shell/stat_bpf_counters.sh +1 -1
@@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # perf stat --bpf-counters test # SPDX-License-Identifier: GPL-2.0
Greg Kroah-Hartman
maintainerPATCH 749/752 tools/thermal/tmon: Fix compilation warning for wrong format
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Eckert <[email protected]>
commit 9da39ef332c417ce52732564c1c682a6e1209302 upstream.
The following warnings are shown during compilation:
tui.c: In function 'show_cooling_device':
tui.c:216:40: warning: format '%d' expects argument of type 'int', but
argument 7 has type 'long unsigned int' [-Wformat=]
216 | "%02d %12.12s%6d %6d",
| ~~^
| |
| int
| %6ld
......
219 | ptdata.cdi[j].cur_state,
| ~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
tui.c:216:44: warning: format '%d' expects argument of type 'int', but
argument 8 has type 'long unsigned int' [-Wformat=]
216 | "%02d %12.12s%6d %6d",
| ~~^
| |
| int
| %6ld
......
220 | ptdata.cdi[j].max_state);
| ~~~~~~~~~~~~~~~~~~~~~~~
| |
| long unsigned intTo fix this, the correct string format must be used for printing.
--- tools/thermal/tmon/tui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/thermal/tmon/tui.c +1 -1
@@ -213,7 +213,7 @@ void show_cooling_device(void)* cooling device instances. skip unused idr. */ mvwprintw(cooling_device_window, j + 2, 1, - "%02d %12.12s%6d %6d", + "%02d %12.12s%6lu %6lu", ptdata.cdi[j].instance, ptdata.cdi[j].type, ptdata.cdi[j].cur_state,
Greg Kroah-Hartman
maintainerPATCH 750/752 lan78xx: Enable 125 MHz CLK configuration for LAN7801 if NO EEPROM is detected
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rengarajan S <[email protected]>
commit 5160b129f65fc6e1a4aa282d44f824e12aa800ee upstream.
The 125MHz and 25MHz clock configurations are enabled in the initialization regardless of EEPROM (125MHz is needed for RGMII 1000Mbps operation). After a lite reset (lan78xx_reset), these contents go back to defaults(all 0, so no 125MHz or 25MHz clock).
--- drivers/net/usb/lan78xx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/usb/lan78xx.c +2 -0
@@ -2804,6 +2804,8 @@ static int lan78xx_reset(struct lan78xx_return ret; buf |=HW_CFG_MEF_ ; + buf |=HW_CFG_CLK125_EN_ ; + buf |=HW_CFG_REFCLK25_EN_ ; ret =lan78xx_write_reg (dev,HW_CFG , buf);if (ret <0 )
Greg Kroah-Hartman
maintainerPATCH 751/752 lan78xx: Enable Auto Speed and Auto Duplex configuration for LAN7801 if NO EEPROM is detected
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rengarajan S <[email protected]>
commit 799f532de13601f91ecb9cc6169d45d6e6933b0f upstream.
Enabled ASD/ADD configuration for LAN7801 in the absence of EEPROM. After the lite reset these contents go back to defaults where ASD/ ADD is disabled. The check is already available for LAN7800.
--- drivers/net/usb/lan78xx.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/usb/lan78xx.c +4 -1
@@ -2894,8 +2894,11 @@ static int lan78xx_reset(struct lan78xx_return ret;/* LAN7801 only has RGMII mode */ -if (dev->chipid ==ID_REV_CHIP_ID_7801_ ) +if (dev->chipid ==ID_REV_CHIP_ID_7801_ ) { buf &= ~MAC_CR_GMII_EN_ ; +/* Enable Auto Duplex and Auto speed */ + buf |=MAC_CR_AUTO_DUPLEX_ |MAC_CR_AUTO_SPEED_ ; + }if (dev->chipid ==ID_REV_CHIP_ID_7800_ || dev->chipid ==ID_REV_CHIP_ID_7850_ ) {
Greg Kroah-Hartman
maintainerPATCH 752/752 drm/amdgpu/atom: Check kcalloc() for WS buffer in amdgpu_atom_execute_table_locked()
In reply to Greg Kroah-Hartman5.15-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit cc9a8e238e42c1f43b98c097995137d644b69245 upstream.
kcalloc() may fail. When WS is non-zero and allocation fails, ectx.ws remains NULL while ectx.ws_size is set, leading to a potential NULL pointer dereference in atom_get_src_int() when accessing WS entries.
Return -ENOMEM on allocation failure to avoid the NULL dereference.
--- drivers/gpu/drm/amd/amdgpu/atom.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/atom.c +7 -2
@@ -1226,10 +1226,15 @@ static int amdgpu_atom_execute_table_loc ectx.ps = params; ectx.abort = false; ectx.last_jump =0 ; -if (ws) +if (ws) { ectx.ws =kcalloc (4 , ws,GFP_KERNEL ); -else +if (!ectx.ws) { + ret = -ENOMEM ; + goto free; + } + }else { ectx.ws =NULL ; + } debug_depth++;while (1 ) {
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.222 release. There are 752 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 9 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.222-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
Tested on AMD64 12-core and 4-core systems
and on Intel x86-64 4-core and x86 1-core systems
---------------------------------------------------------------------
There's no real need to do housework -- after four years it doesn't get any worse.
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.222 release. There are 752 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.222-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
Hi!
Quoted 4 lines
This is the start of the stable review cycle for the 5.15.222 release. There are 752 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
CIP testing did not find any problems here:
https://gitlab.com/cip-project/cip-testing/linux-stable-rc-ci/-/tree/linux-5.15.y
Best regards,
Pavel
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.222 release. There are 752 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.222-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
Built and booted successfully on RISC-V RV64 (HiFive Unmatched).
# Librecast Test Results
044/044 [ OK ] liblcrq
010/010 [ OK ] libmld
120/120 [ OK ] liblibrecast
CPU/kernel: Linux auntie 5.15.222-rc1-00753-gd7aa8488b4a2 #1 SMP Thu Oct 1 14:58:42 -00 2026 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.15.222 release. There are 752 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Fri, 02 Oct 2026 15:23:04 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.222-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.15.y
and the diffstat can be found below.thanks,
greg k-h
Tested on 2 amd64 laptops (a Lenovo ThinkPad T14 Gen 1 and an Apple MacBook Air 13" 2017). Working well, no regressions observed.
In particular, the MacBook Air that I used for testing has a SATA SSD and was affected by the SATA booting regression in 5.15.221, but with 5.15.222-rc1 it boots again.
Signature · 1 line
-Barry K. Nathan <[email protected]>