6.6.158-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 835/1193 ALSA: virtio: reset device before deleting virtqueues
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
commit 6c05d00af307560e6a9f1631d6270d3df5aa2272 upstream.
virtsnd_remove() and virtsnd_freeze() delete the virtqueues before resetting the device. del_vqs() frees the vring backing, but does not provide a generic device quiesce operation. In particular, modern virtio-pci keeps enabled queues active until the device is reset.
Reset the device before deleting the virtqueues so it can no longer access the vring memory when that memory is released. This also covers probe failures after DRIVER_OK, which unwind through virtsnd_remove().
--- sound/virtio/virtio_card.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/virtio/virtio_card.c +2 -2
@@ -349,8 +349,8 @@ static void virtsnd_remove(struct virtioif (snd->card)snd_card_free (snd->card); - vdev->config->del_vqs (vdev);virtio_reset_device (vdev); + vdev->config->del_vqs (vdev);for (i =0 ; snd->substreams && i < snd->nsubstreams; ++i) {struct virtio_pcm_substream *vss = &snd->substreams[i];
@@ -378,8 +378,8 @@ static int virtsnd_freeze(struct virtio_virtsnd_disable_event_vq (snd);virtsnd_ctl_msg_cancel_all (snd); - vdev->config->del_vqs (vdev);virtio_reset_device (vdev); + vdev->config->del_vqs (vdev);for (i =0 ; i < snd->nsubstreams; ++i)cancel_work_sync (&snd->substreams[i].elapsed_period);
Greg Kroah-Hartman
maintainerPATCH 836/1193 ASoC: codecs: rt712-sdca-dmic: fix uninitialized stream_config->type
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit 03a5699a0a04309c597683967aaaf25d1e555ea2 upstream.
stream_config is not initialized before being passed to sdw_stream_add_slave(). The type field may contain garbage and is later copied to stream->type by sdw_config_stream().
Zero-initialize stream_config so type defaults to SDW_STREAM_PCM.
While at it, use snd_sdw_params_to_config() helper instead of open-coding the same logic.
--- sound/soc/codecs/rt712-sdca-dmic.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
sound/soc/codecs/rt712-sdca-dmic.c +5 -9
@@ -14,6 +14,7 @@#include <sound/core.h> #include <sound/pcm.h> #include <sound/pcm_params.h> +#include <sound/sdw.h> #include <sound/tlv.h> #include "rt712-sdca.h" #include "rt712-sdca-dmic.h"
@@ -640,10 +641,10 @@ static int rt712_sdca_dmic_hw_params(str {struct snd_soc_component *component = dai->component;struct rt712_sdca_dmic_priv *rt712 =snd_soc_component_get_drvdata (component); -struct sdw_stream_config stream_config; +struct sdw_stream_config stream_config = {0 };struct sdw_port_config port_config;struct sdw_stream_runtime *sdw_stream; -int retval, num_channels; +int retval;unsigned int sampling_rate;dev_dbg (dai->dev,"%s %s" , __func__, dai->name);
@@ -655,13 +656,8 @@ static int rt712_sdca_dmic_hw_params(strif (!rt712->slave)return -EINVAL ; - stream_config.frame_rate =params_rate (params); - stream_config.ch_count =params_channels (params); - stream_config.bps =snd_pcm_format_width (params_format (params)); - stream_config.direction =SDW_DATA_DIR_TX ; - - num_channels =params_channels (params); - port_config.ch_mask =GENMASK (num_channels -1 ,0 ); +/* SoundWire specific configuration */ +snd_sdw_params_to_config (substream, params, &stream_config, &port_config); port_config.num =2 ; retval = sdw_stream_add_slave(rt712->slave, &stream_config,
Greg Kroah-Hartman
maintainerPATCH 837/1193 ata: libahci: clear PxCLBU and PxFBU for AHCI_HFLAG_32BIT_ONLY
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
commit 82e47533221d4746947b74d2e79a478c36c6433a upstream.
A user reported that commit 105c42566a55 ("ata: ahci: force 32-bit DMA for JMicron JMB582/JMB585") made the JMicron JMB585 unusable on his board.
The failure is seen as soon as the ahci driver is probed, and booting with iommu=off does not solve the problem.
Looking at the AHCI specification, PxCLBU and PxFBU are both read only '0' for HBAs that do not support 64-bit addressing.
For HBAs that do support 64-bit addressing, the registers are read write, with a reset value that is Implementation Specific.
When using the AHCI_HFLAG_32BIT_ONLY flag, the HBA does support 64-bit addressing, and a 32-bit DMA mask is set by simply clearing HOST_CAP_64. Thus, in this case, we need to explicitly clear the registers to 0.
--- drivers/ata/libahci.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/ata/libahci.c +14 -1
@@ -747,15 +747,28 @@ void ahci_start_fis_rx(struct ata_port *struct ahci_port_priv *pp = ap->private_data;u32 tmp; -/* set FIS registers */ +/* +* On HBAs that only support 32-bit addressing PxCLBU is read only '0'. +* When applying the AHCI_HFLAG_32BIT_ONLY quirk, PxCLBU is RW, and the +* reset value is Implementation Specific, so we need to clear it to 0. +*/ if (hpriv->cap &HOST_CAP_64 )writel ((pp->cmd_slot_dma >>16 ) >>16 , port_mmio +PORT_LST_ADDR_HI ); +else if (hpriv->flags &AHCI_HFLAG_32BIT_ONLY ) +writel (0 , port_mmio +PORT_LST_ADDR_HI );writel (pp->cmd_slot_dma &0xffffffff , port_mmio +PORT_LST_ADDR ); +/* +* On HBAs that only support 32-bit addressing PxFBU is read only '0'. +* When applying the AHCI_HFLAG_32BIT_ONLY quirk, PxFBU is RW, and the +* reset value is Implementation Specific, so we need to clear it to 0. +*/ if (hpriv->cap &HOST_CAP_64 )writel ((pp->rx_fis_dma >>16 ) >>16 , port_mmio +PORT_FIS_ADDR_HI ); +else if (hpriv->flags &AHCI_HFLAG_32BIT_ONLY ) +writel (0 , port_mmio +PORT_FIS_ADDR_HI );writel (pp->rx_fis_dma &0xffffffff , port_mmio +PORT_FIS_ADDR );/* enable FIS reception */
Greg Kroah-Hartman
maintainerPATCH 838/1193 cifs: Fix server use-after-free in cifs_chan_skip_or_disable()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 717e0a25036b6c92cecace30913b2d874a4c22b8 upstream.
When a secondary channel is no longer supported by the server, cifs_chan_skip_or_disable() drops the channel reference with cifs_put_tcp_session() and then continues to use the server pointer by calling cifs_signal_cifsd_for_reconnect() on it and reading its primary_server pointer. cifs_put_tcp_session() can drop the last reference of the channel and tear it down, so both the channel and the primary server (whose reference is also dropped by cifs_put_tcp_session()) can be freed before they are signaled for reconnect.
Signal the channel and the primary server and capture the primary server pointer before dropping the channel reference with cifs_put_tcp_session().
--- fs/smb/client/smb2pdu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/smb/client/smb2pdu.c +7 -6
@@ -185,18 +185,19 @@ cifs_chan_skip_or_disable(struct cifs_sespin_unlock (&ses->chan_lock);/* -* the above reference of server by channel -* needs to be dropped without holding chan_lock -* as cifs_put_tcp_session takes a higher lock -* i.e. cifs_tcp_ses_lock +* signal the channel and its primary server to +* reconnect before dropping the above reference of +* server by channel, which is done without holding +* chan_lock as cifs_put_tcp_session takes a higher +* lock i.e. cifs_tcp_ses_lock */ -cifs_put_tcp_session (server, from_reconnect); -cifs_signal_cifsd_for_reconnect (server, false);/* mark primary server as needing reconnect */ pserver = server->primary_server;cifs_signal_cifsd_for_reconnect (pserver, false); + +cifs_put_tcp_session (server, from_reconnect); skip_terminate:return -EHOSTDOWN ; }
Greg Kroah-Hartman
maintainerPATCH 839/1193 exec: Cleanup POSIX timers right after de_thread()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hyunwoo Kim <[email protected]>
commit acb03d3881818581052924a9bbbe92b8741ed448 upstream.
A per-thread CPU timer holds a reference to the PID of the thread it is attached to and, while it is armed, its node is queued in that thread's posix_cputimers. The task is looked up by that PID.
When a non-leader thread exec()s, de_thread() changes which task owns that PID. pid_task(timer->it.cpu.pid, PIDTYPE_PID) then returns NULL, but the node is still queued on tsk, which is alive. timer_lock_sighand() takes a failed lookup to mean that the node is already dequeued, so it has nothing to undo.
begin_new_exec() calls posix_cpu_timers_exit(me) right after exec_task_namespaces() and that removes the leftover node, so the state normally stays invisible. But bprm->point_of_no_return is set before de_thread(), so if unshare_files(), set_mm_exe_file(), exec_mmap() or exec_task_namespaces() fails, the task dies before it gets there. exit_itimers() then frees the k_itimer while its node is still queued, and reaping tsk later erases that freed node from the rbtree.
In short:
the non-leader thread B the parent
timer_create(CLOCK_THREAD_CPUTIME_ID)
timer_settime()
arm_timer() // the node is queued on B
execve()
de_thread(B)
exchange_tids(B, leader) // B's PID now belongs to the leader release_task(leader)
__exit_signal(leader)
posix_cpu_timers_exit(leader) // cleans leader's queue, not B's __unhash_process(leader) // that PID has no task anymore
exec_mmap()
mmap_read_lock_killable(old_mm)
kill(B, SIGKILL)
// -EINTR
get_signal()
do_exit()
exit_itimers()
posix_timer_delete()
posix_cpu_timer_del()
posix_timer_unhash_and_free() // freed while still queued
wait4()
release_task(B)
posix_cpu_timers_exit(B)
cleanup_timerqueue()
timerqueue_del() // use-after-free
Move the POSIX timer cleanup right after de_thread() before any of the later failure conditions brings the task into do_exit().
[ tglx: Move the cleanup right after de_thread() ]
--- fs/exec.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
fs/exec.c +21 -8
@@ -1236,6 +1236,17 @@ void __set_task_comm(struct task_structperf_event_comm (tsk, exec); } +static void posixtimer_exec (struct task_struct *me) +{ +#ifdef CONFIG_POSIX_TIMERS +spin_lock_irq (&me->sighand->siglock); +posix_cpu_timers_exit (me); +spin_unlock_irq (&me->sighand->siglock); +exit_itimers (me); +flush_itimer_signals (); +#endif +} +/* * Calling this is the point of no return. None of the failures will be * seen by userspace since either the process is already taking a fatal
@@ -1261,6 +1272,16 @@ int begin_new_exec(struct linux_binprm * retval =de_thread (me);if (retval) goto out; + +/* +* This must be done here to ensure that POSIX CPU timers which were +* armed on the current task are dequeued from me::posix_cputimers. +* Otherwise in case of a TID switch the deletion of the related POSIX +* timer would not remove an enqueued timer because the TID lookup +* of the old TID fails. +*/ +posixtimer_exec (me); +/* see the comment in check_unsafe_exec() */ current->fs->in_exec =0 ;/*
@@ -1315,14 +1336,6 @@ int begin_new_exec(struct linux_binprm *if (retval) goto out_unlock; -#ifdef CONFIG_POSIX_TIMERS -spin_lock_irq (&me->sighand->siglock); -posix_cpu_timers_exit (me); -spin_unlock_irq (&me->sighand->siglock); -exit_itimers (me); -flush_itimer_signals (); -#endif -/* * Make the signal table private. */
Greg Kroah-Hartman
maintainerPATCH 840/1193 rds: ib: use rds_conn_drop() on protocol version mismatch
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aohan Mei <[email protected]>
commit f97d8c7bab7843631206a114986c9059da03efeb upstream.
rds_ib_cm_connect_complete() runs from the RDMA-CM event handler with conn->c_cm_lock held. When the peer negotiates a protocol version older than RDS_PROTOCOL_COMPAT_VERSION, the handler calls rds_conn_destroy(), which is only safe in the rmmod path: it synchronously tears the connection down and flush_work()es the shutdown work cp_down_w.
That shutdown work (rds_conn_shutdown()) needs cp_cm_lock, which is the very lock the event handler still holds, so the flush never
completes: the two workers wait on each other and the RDS connection workqueues stall for good.
All other RDMA-CM failure paths (REJECTED, CONNECT_ERROR, DISCONNECTED) use rds_conn_drop(), which marks the connection RDS_CONN_ERROR and schedules the shutdown work asynchronously. Use it here as well.
--- net/rds/ib_cm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/rds/ib_cm.c +1 -1
@@ -115,7 +115,7 @@ void rds_ib_cm_connect_complete(struct r &conn->c_laddr, &conn->c_faddr,RDS_PROTOCOL_MAJOR (conn->c_version), RDS_PROTOCOL_MINOR(conn->c_version)); -rds_conn_destroy (conn); +rds_conn_drop (conn);return ; } }
Greg Kroah-Hartman
maintainerPATCH 841/1193 tcp: exclude old ACKs from tcp fast path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Inbal Schussheim <[email protected]>
commit f81e6c3fb06327bc49cdd6e559845293ba06a704 upstream.
Exclude old ACKs before SND.UNA from the tcp fast path as well as ACKs after SND.NXT.
Such ACKs will fall through to the slow path, where tcp_ack() performs the appropriate validation and challenge ACK handling according to RFC5961 and Commit 3d501dd326fb1c7 ("tcp: do not accept ACK of bytes we never sent").
This prevents old ACKs from being accepted
or modifying connection state as part of the fast path before appropriate ACK validation is applied.
In particular, this prevents payload carried by a segment with an excessively old ACK from advancing RCV.NXT before the ACK is rejected.
--- net/ipv4/tcp_input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/tcp_input.c +2 -1
@@ -6029,6 +6029,7 @@ reset:* or pure receivers (this means either the sequence number or the ack * value must stay constant) * - Unexpected TCP option. +* - ACK sequence number is outside [SND.UNA, SND.NXT]. * * When these conditions are not satisfied it drops into a standard * receive procedure patterned after RFC793 to handle all cases.
@@ -6077,7 +6078,7 @@ void tcp_rcv_established(struct sock *skif ((tcp_flag_word (th) &TCP_HP_BITS ) == tp->pred_flags &&TCP_SKB_CB (skb)->seq == tp->rcv_nxt && - !after (TCP_SKB_CB (skb)->ack_seq, tp->snd_nxt)) { +between (TCP_SKB_CB (skb)->ack_seq, tp->snd_una, tp->snd_nxt)) {int tcp_header_len = tp->tcp_header_len;/* Timestamp header prediction: tcp_header_len
Greg Kroah-Hartman
maintainerPATCH 842/1193 RDMA/ucma: Serialize join and leave on copy_to_user failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Quanye Yang <[email protected]>
commit 662ade4de9ff5eceb0820a9f8e9fac70ba6a815b upstream.
rdma_join_multicast() queues RoCE work that later reads the ucma_multicast through event->param.ud.private_data, then list_add()s the CMA multicast at the head of id_priv->mc_list. rdma_leave_multicast() matches only by sockaddr and destroys the first hit.
ucma_process_join() used to drop ctx->mutex after a successful join and retake it only if copy_to_user() failed. Two concurrent JOIN_MCAST calls with the same address can therefore insert a second CMA entry before the first thread's leave. leave then cancels the newer work and the older worker still dereferences the ucma_multicast that the first thread frees.
Keep ctx->mutex held from rdma_join_multicast() through copy_to_user() and, on -EFAULT, through rdma_leave_multicast() so leave cannot miss this join. Do not leave if join itself failed: that path never published this address on mc_list, and a leave-by-addr would destroy an earlier successful join.
--- drivers/infiniband/core/ucma.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/infiniband/core/ucma.c +4 -3
@@ -1488,9 +1488,10 @@ static ssize_t ucma_process_join(structmutex_lock (&ctx->mutex); ret =rdma_join_multicast (ctx->cm_id, (struct sockaddr *)&mc->addr, join_state, mc); -mutex_unlock (&ctx->mutex); -if (ret) +if (ret) { +mutex_unlock (&ctx->mutex); goto err_xa_erase; + } resp.id = mc->id; if (copy_to_user(u64_to_user_ptr(cmd->response),
@@ -1498,6 +1499,7 @@ static ssize_t ucma_process_join(struct ret = -EFAULT ; goto err_leave_multicast; } +mutex_unlock (&ctx->mutex);xa_store (&multicast_table, mc->id, mc,0 );
@@ -1505,7 +1507,6 @@ static ssize_t ucma_process_join(structreturn 0 ; err_leave_multicast: -mutex_lock (&ctx->mutex);rdma_leave_multicast (ctx->cm_id, (struct sockaddr *) &mc->addr);mutex_unlock (&ctx->mutex);ucma_cleanup_mc_events (mc);
Greg Kroah-Hartman
maintainerPATCH 843/1193 RDMA/core: fix refcount bug in iwpm_get_nlmsg_request()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
commit 33fb59da49c4c3f5c2ec9f9d4447a56857a02c02 upstream.
iwpm_get_nlmsg_request() initializes refcount _after_ list_add_tail() making it accessible to global list where another CPU can kref_get() on nlmsg_request causing a refcount "addition on 0" bug. Fix this by initializing kref _before_ list_add_tail() so refcount for nlmsg_request can be incremented/decremented normally. In addition, also initialize every field before list_add_tail().
--- drivers/infiniband/core/iwpm_util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/infiniband/core/iwpm_util.c +5 -4
@@ -314,10 +314,6 @@ struct iwpm_nlmsg_request *iwpm_get_nlmsif (!nlmsg_request)return NULL ; -spin_lock_irqsave (&iwpm_nlmsg_req_lock, flags); -list_add_tail (&nlmsg_request->inprocess_list, &iwpm_nlmsg_req_list); -spin_unlock_irqrestore (&iwpm_nlmsg_req_lock, flags); -kref_init (&nlmsg_request->kref);kref_get (&nlmsg_request->kref); nlmsg_request->nlmsg_seq = nlmsg_seq;
@@ -326,6 +322,11 @@ struct iwpm_nlmsg_request *iwpm_get_nlms nlmsg_request->err_code =0 ;sema_init (&nlmsg_request->sem,1 );down (&nlmsg_request->sem); + +spin_lock_irqsave (&iwpm_nlmsg_req_lock, flags); +list_add_tail (&nlmsg_request->inprocess_list, &iwpm_nlmsg_req_list); +spin_unlock_irqrestore (&iwpm_nlmsg_req_lock, flags); +return nlmsg_request; }
Greg Kroah-Hartman
maintainerPATCH 808/1193 Bluetooth: btmtksdio: Fix PM runtime reference leak in shutdown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
[ Upstream commit 7b60ee5f46f2ee329de661f7c68b6818d8136220 ]
In btmtksdio_shutdown(), pm_runtime_get_sync() is called at the beginning of the function. However, if sending the WMT function control command fails later, the driver returns early.
It bypasses the corresponding pm_runtime_put_noidle() and pm_runtime_disable() calls, leaking the PM usage counter and leaving PM runtime enabled indefinitely.
Fall through to execute the PM runtime cleanup block even if WMT errors.
--- drivers/bluetooth/btmtksdio.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/bluetooth/btmtksdio.c +1 -3
@@ -1220,10 +1220,8 @@ static int btmtksdio_shutdown(struct hci_dev *hdev) wmt_params.status =NULL ; err =mtk_hci_wmt_sync (hdev, &wmt_params); -if (err <0 ) { +if (err <0 )bt_dev_err (hdev,"Failed to send wmt func ctrl (%d)" , err); -return err; - } ignore_wmt_cmd:pm_runtime_put_noidle (bdev->dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 844/1193 openvswitch: avoid reallocating confirmed conntrack labels
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
commit 3f118c8217c109fd13ca61caa301d72c483897ef upstream.
ovs_ct_get_conn_labels() adds the labels extension when a conntrack entry does not have one. Confirmed conntracks can be read locklessly, so adding an extension may reallocate and free the extension block while another CPU accesses it.
Only add the extension for unconfirmed conntracks. A confirmed conntrack without labels now fails the caller's label operation instead of reallocating its extension storage.
--- net/openvswitch/conntrack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/openvswitch/conntrack.c +1 -1
@@ -366,7 +366,7 @@ static struct nf_conn_labels *ovs_ct_getstruct nf_conn_labels *cl; cl =nf_ct_labels_find (ct); -if (!cl) { +if (!cl && !nf_ct_is_confirmed (ct)) {nf_ct_labels_ext_add (ct); cl =nf_ct_labels_find (ct); }
Greg Kroah-Hartman
maintainerPATCH 845/1193 net: xfrm: reject unrepresentable espintcp transport headers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wyatt Feng <[email protected]>
commit 96f01b53c2d05e003b040892256de54a586e8529 upstream.
ESP-in-TCP can hand xfrm packets whose transport header offset no longer fits after the stream parser trims the TCP envelope. The plain transport header reset truncates that offset and triggers the skb warning path.
Use the careful transport-header helper and drop the skb through the existing XFRM error path when the offset cannot be represented.
--- net/xfrm/espintcp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/xfrm/espintcp.c +5 -1
@@ -32,7 +32,11 @@ static void handle_esp(struct sk_buff *s {struct tcp_skb_cb *tcp_cb = (struct tcp_skb_cb *)skb->cb; -skb_reset_transport_header (skb); +if (!skb_reset_transport_header_careful (skb)) { +XFRM_INC_STATS (sock_net (sk),LINUX_MIB_XFRMINERROR ); +kfree_skb (skb); +return ; + }/* restore IP CB, we need at least IP6CB->nhoff */ memmove (skb->cb, &tcp_cb->header,sizeof (tcp_cb->header));
Greg Kroah-Hartman
maintainerPATCH 846/1193 HID: logitech-hidpp: fix race condition when accessing stale stack pointer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Benoît Sevens <[email protected]>
commit e2aaf2d3ad92ac4a8afa6b69ad4c38e7747d3d6e upstream.
The driver uses hidpp->send_receive_buf to point to a stack-allocated buffer in the synchronous command path (__do_hidpp_send_message_sync). However, this pointer is not cleared when the function returns.
If an event is processed (e.g. by a different thread) while the send_mutex is held by a new command, but before that command has updated send_receive_buf, the handler (hidpp_raw_hidpp_event) will observe that the mutex is locked and dereference the stale pointer.
This results in an out-of-bounds access on a different thread's kernel stack (or a NULL pointer dereference on the very first command).
Fix this by:
1. Clearing hidpp->send_receive_buf to NULL before releasing the mutex in the synchronous command path.
2. Moving the assignment of the local 'question' and 'answer' pointers inside the mutex_is_locked() block in the handler, and adding a NULL check before dereferencing.
--- drivers/hid/hid-logitech-hidpp.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
drivers/hid/hid-logitech-hidpp.c +17 -7
@@ -304,21 +304,22 @@ static int __do_hidpp_send_message_sync(if (ret) {dbg_hid ("__hidpp_send_report returned err: %d\n" , ret);memset (response,0 ,sizeof (struct hidpp_report )); -return ret; + goto out; }if (!wait_event_timeout (hidpp->wait, hidpp->answer_available,5 *HZ )) {dbg_hid ("%s:timeout waiting for response\n" , __func__);memset (response,0 ,sizeof (struct hidpp_report )); -return -ETIMEDOUT ; + ret = -ETIMEDOUT ; + goto out; }if (response->report_id ==REPORT_ID_HIDPP_SHORT && response->rap.sub_id ==HIDPP_ERROR ) { ret = response->rap.params[1 ];dbg_hid ("%s:got hidpp error %02X\n" , __func__, ret); -return ret; + goto out; } if ((response->report_id == REPORT_ID_HIDPP_LONG ||
@@ -326,10 +327,14 @@ static int __do_hidpp_send_message_sync( response->fap.feature_index == HIDPP20_ERROR) { ret = response->fap.params[1 ];dbg_hid ("%s:got hidpp 2.0 error %02X\n" , __func__, ret); -return ret; + goto out; } -return 0 ; + ret =0 ; + +out: + hidpp->send_receive_buf =NULL ; +return ret; }/*
@@ -3867,8 +3872,7 @@ static int hidpp_input_configured(structstatic int hidpp_raw_hidpp_event (struct hidpp_device *hidpp,u8 *data,int size) { -struct hidpp_report *question = hidpp->send_receive_buf; -struct hidpp_report *answer = hidpp->send_receive_buf; +struct hidpp_report *question, *answer;struct hidpp_report *report = (struct hidpp_report *)data;int ret;
@@ -3877,6 +3881,12 @@ static int hidpp_raw_hidpp_event(struct* previously sent command. */ if (unlikely (mutex_is_locked (&hidpp->send_mutex))) { + question = hidpp->send_receive_buf; + answer = hidpp->send_receive_buf; + +if (!question) +return 0 ; +/* * Check for a correct hidpp20 answer or the corresponding * error
Greg Kroah-Hartman
maintainerPATCH 847/1193 kselftest/arm64: Fix size of thread_data values for pthread_join()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Huth <[email protected]>
commit 3d1ba5cbfb622025690c218d8f20da92a9ecb383 upstream.
pthread_join() stores the thread's return value (a "void *", i.e. 8 bytes on 64 bit computers) into the address that is passed as second parameter. However, the entries of thread_data are only normal "int"s, i.e. only 4 bytes. The additional 4 bytes of the return value clobber whatever is adjacent on the stack, i.e. other members of the thread_data array (which will be re-written in the next iteration of the for-loop, so that nobody noticed this problem), or another other local variable on the stack for the last iteration. Use "intptr_t" to declare the thread_data array entries with the correct size.
--- tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c +1 -1
@@ -69,7 +69,7 @@ fail:int execute_test (pid_t pid) {pthread_t thread_id[MAX_THREADS ]; -int thread_data[MAX_THREADS ]; +intptr_t thread_data[MAX_THREADS ];for (int i =0 ; i <MAX_THREADS ; i++) pthread_create(&thread_id[i], NULL,
Greg Kroah-Hartman
maintainerPATCH 848/1193 arm64: hibernate: pass HVC_SET_VECTORS args to the resume hvc
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit 955d86e5f3b95b731991fdb84966c50b16314629 upstream.
swsusp_arch_suspend_exit() reinstalls the restored kernel's hyp stub vectors with an hvc, but never passes the arguments. x0 is not set to HVC_SET_VECTORS and x1 is not set to the vector address, so the stub dispatch falls through and returns without writing vbar_el2. EL2 is left pointing at the trans_pgd copy of the vectors, a page that swsusp_free() releases right after resume.
Set the arguments up the same way __hyp_set_vectors() does.
Without this fix, Vladimir was able to trigger a hang when resuming from hibernation with CONFIG_PAGE_POISONING=y and page_poison=on.
--- arch/arm64/kernel/hibernate-asm.S | 2 ++ 1 file changed, 2 insertions(+)
arch/arm64/kernel/hibernate-asm.S +2 -0
@@ -89,6 +89,8 @@ alternative_insn "dc cvau, x4", "dc civ isb cbz x24, 3f /* Do we need to re-initialise EL2? */ + mov x1, x24 + mov x0, #HVC_SET_VECTORS hvc #0 3: ret SYM_CODE_END(swsusp_arch_suspend_exit)
Greg Kroah-Hartman
maintainerPATCH 849/1193 arm64: dts: renesas: r8a779f0: Set UFS lane count
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit 8dc2615d5702059b2b71fca6f93c0d7d10ae54cb upstream.
Since commit e72323f3b09f ("scsi: ufs: core: Configure only active lanes during link"), the following error is observed on R-Car S4:
ufshcd-renesas e6860000.ufs: Tx lane mismatch [config,reported] [2,1] ufshcd-renesas e6860000.ufs: link startup failed -67
ufshcd-renesas e6860000.ufs: error -ENOLINK: Initialization failed with error -67 ufshcd-renesas e6860000.ufs: probe with driver ufshcd-renesas failed with error -67
R-Car S4 has one UFS lane per direction, as described in section 152.1 of its hardware manual. Without lanes-per-direction, the UFS platform driver defaults to two lanes.
Previously, the core used PA_CONNECTEDRXDATALANES and PA_CONNECTEDTXDATALANES to configure the link without checking them against lanes-per-direction, so the missing property did not prevent initialization.
Explicitly set lanes-per-direction to 1, now that the validation is in place.
--- arch/arm64/boot/dts/renesas/r8a779f0.dtsi | 1 + 1 file changed, 1 insertion(+)
arch/arm64/boot/dts/renesas/r8a779f0.dtsi +1 -0
@@ -733,6 +733,7 @@ clocks = <&cpg CPG_MOD 1514>, <&ufs30_clk>; clock-names = "fck", "ref_clk"; freq-table-hz = <200000000 200000000>, <38400000 38400000>; + lanes-per-direction = <1>; power-domains = <&sysc R8A779F0_PD_ALWAYS_ON>; resets = <&cpg 1514>; status = "disabled";
Greg Kroah-Hartman
maintainerPATCH 850/1193 arm64: percpu: Fix this_cpu_write() casting
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
commit 885bff055a0f251a51a0d4fd4f0a7b525582a3de upstream.
The arm64 implementation of this_cpu_write() casts 'val' to unsigned long. This is necessary to handle cases where 'val' is a pointer type, and to avoid spurious compiler warnings for the (unreachable!) cases where the pointer type would be cast to a smaller integer type.
Unfortunately, the cast is applied to 'val' rather than '(val)', which won't always generate the expected value when 'val' is an expression.
For example, for this_cpu_write(pcp, zero - 1), where 'pcp' is a u64 and 'zero' is a u32:
* 'zero' ===> (u32) 0x00000000 * 'zero - 1' ===> (u32) 0xffffffff * '(unsigned long)zero - 1' ===> (u64) 0xffffffffffffffff
* '(unsigned long)(zero - 1)' ===> (u64) 0x00000000ffffffff
Fix this by adding brackets around 'val'.
--- arch/arm64/include/asm/percpu.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/include/asm/percpu.h +4 -4
@@ -172,13 +172,13 @@ PERCPU_RET_OP(add, add, ldadd) _pcp_protect_return(__percpu_read_64, pcp)#define this_cpu_write_1 (pcp, val) \ - _pcp_protect(__percpu_write_8, pcp, (unsigned long)val) + _pcp_protect(__percpu_write_8, pcp, (unsigned long)(val))#define this_cpu_write_2 (pcp, val) \ - _pcp_protect(__percpu_write_16, pcp, (unsigned long)val) + _pcp_protect(__percpu_write_16, pcp, (unsigned long)(val))#define this_cpu_write_4 (pcp, val) \ - _pcp_protect(__percpu_write_32, pcp, (unsigned long)val) + _pcp_protect(__percpu_write_32, pcp, (unsigned long)(val))#define this_cpu_write_8 (pcp, val) \ - _pcp_protect(__percpu_write_64, pcp, (unsigned long)val) + _pcp_protect(__percpu_write_64, pcp, (unsigned long)(val))#define this_cpu_add_1 (pcp, val) \ _pcp_protect(__percpu_add_case_8, pcp, val)
Greg Kroah-Hartman
maintainerPATCH 851/1193 arm64: percpu: Fix this_cpu_and() mask generation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
commit 44274c657256b4911de82f8104e9e22f054cf742 upstream.
The arm64 implementation of this_cpu_and(pcp, val) is built in terms of ANDNOT operations, which requires the 'val' argument to be bitwise negated. The bitwise negation is not implemented correctly, with two bugs described below.
(1) The bitwise negation is performed as '~val' rather than '~(val)'. This won't always generate the expected value when 'val' is an expression.
For example, for this_cpu_and(pcp, 1 - 1):
* 'val' is '1 - 1' ===> (int) 0x00000000
* '~val' is '~1 - 1' ===> (int) 0xfffffffd
* '~(val)' is '~(1 - 1)' ===> (int) 0xffffffff
... and thus bit[1] of 'pcp' would be preserved unexpectedly by the ANDNOT operation.
(2) The bitwise negation is performed on 'val' before it has been cast to (at least) the width of 'pcp'. This won't always generate the expected value for the upper bits.
For example, for this_cpu_and(pcp, zero), where 'pcp' is a u64 and 'zero' is a u32:
* 'zero' ===> (u32) 0x00000000
* '~(zero)' ===> (u32) 0xffffffff
* '(u64)~(zero)' ===> (u64) 0x00000000ffffffff
* '~((u64)(zero))' ===> (u64) 0xffffffffffffffff
... and thus bits[63:32] of 'pcp' would be preserved unexpectedly by the ANDNOT operation.
Fix these issues by adding brackets around 'val', and by casting 'val' to an appropriately-sized type before bitwise negation.
--- arch/arm64/include/asm/percpu.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/arm64/include/asm/percpu.h +4 -4
@@ -199,13 +199,13 @@ PERCPU_RET_OP(add, add, ldadd) _pcp_protect_return(__percpu_add_return_case_64, pcp, val)#define this_cpu_and_1 (pcp, val) \ - _pcp_protect(__percpu_andnot_case_8, pcp, ~val) + _pcp_protect(__percpu_andnot_case_8, pcp, ~(u8)(val))#define this_cpu_and_2 (pcp, val) \ - _pcp_protect(__percpu_andnot_case_16, pcp, ~val) + _pcp_protect(__percpu_andnot_case_16, pcp, ~(u16)(val))#define this_cpu_and_4 (pcp, val) \ - _pcp_protect(__percpu_andnot_case_32, pcp, ~val) + _pcp_protect(__percpu_andnot_case_32, pcp, ~(u32)(val))#define this_cpu_and_8 (pcp, val) \ - _pcp_protect(__percpu_andnot_case_64, pcp, ~val) + _pcp_protect(__percpu_andnot_case_64, pcp, ~(u64)(val))#define this_cpu_or_1 (pcp, val) \ _pcp_protect(__percpu_or_case_8, pcp, val)
Greg Kroah-Hartman
maintainerPATCH 809/1193 Bluetooth: RFCOMM: avoid socket lock inversion in listener cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Juan Perdomo <[email protected]>
[ Upstream commit 801fb950cae7048eb7d83b18857d1ca37b8cd5a4 ]
rfcomm_sock_cleanup_listen() closes unaccepted child sockets through rfcomm_sock_close(), which takes the child socket lock before rfcomm_dlc_close() acquires rfcomm_mutex. The RFCOMM worker takes these locks in reverse order while handling connections and DLC state changes, so lockdep reports a possible deadlock.
Close dequeued children without taking their socket lock. The accept queue owns a reference to each child, and bt_accept_dequeue() locks the child while unlinking it and clearing its parent pointer.
Dropping the child lock makes it important to prevent a concurrent rfcomm_connect_ind() from enqueueing a new child after cleanup observes an empty queue. Set a listening socket to BT_CLOSED while its lock is still held, before dropping the lock and draining the queue. The state check in rfcomm_connect_ind() then rejects new children once cleanup starts.
--- net/bluetooth/rfcomm/sock.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
net/bluetooth/rfcomm/sock.c +10 -3
@@ -243,9 +243,7 @@ static void __rfcomm_sock_close(struct sock *sk)*/ static void rfcomm_sock_close (struct sock *sk) { -lock_sock (sk);__rfcomm_sock_close (sk); -release_sock (sk); }static void rfcomm_sock_init (struct sock *sk,struct sock *parent)
@@ -903,6 +901,7 @@ static int rfcomm_sock_compat_ioctl(struct socket *sock, unsigned int cmd, unsigstatic int rfcomm_sock_shutdown (struct socket *sock,int how) {struct sock *sk = sock->sk; +bool cleanup_listen = false;int err =0 ;BT_DBG ("sock %p, sk %p" , sock, sk);
@@ -913,9 +912,17 @@ static int rfcomm_sock_shutdown(struct socket *sock, int how)lock_sock (sk);if (!sk->sk_shutdown) { sk->sk_shutdown =SHUTDOWN_MASK ; +if (sk->sk_state ==BT_LISTEN ) { +/* Block new children before cleaning up without sk lock. */ + sk->sk_state =BT_CLOSED ; + cleanup_listen = true; + }release_sock (sk); -__rfcomm_sock_close (sk); +if (cleanup_listen) +rfcomm_sock_cleanup_listen (sk); +else +__rfcomm_sock_close (sk);lock_sock (sk); if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 810/1193 pppoatm: ensure a writable skb header and linear data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit ecc7253683a3c55caa868ce0ee530fcb0044bd3c ]
In pppoatm_send(), LLC encapsulation checks whether there is sufficient headroom for the 4-byte LLC header, but does not ensure that the skb header is writable.
Normal transmit packets passing through ppp_start_xmit() have their header unshared via skb_cow_head(). However, packets can also reach pppoatm_send() via PPP channel bridging (PPPIOCBRIDGECHAN) without going through ppp_start_xmit().
Use skb_cow_head() to ensure both sufficient headroom and a writable header before pushing the LLC header.
While at it:
- Call pskb_may_pull(skb, 1) before inspecting skb->data[0] to prevent out-of-bounds reads on zero-length or non-linear frames (e.g. from bridging).
- Defer SC_COMP_PROT protocol compression until after pppoatm_may_send() succeeds. This eliminates the temporary skb allocation on admission failure and completely removes the fragile "undo" heuristic at the nospace label, avoiding any risk of reading uninitialized headroom or performing an unbalanced skb_push().
--- net/atm/pppoatm.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-)
net/atm/pppoatm.c +17 -25
@@ -292,10 +292,13 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)struct atm_vcc *vcc;int ret; +if (!pskb_may_pull (skb,1 )) { +kfree_skb (skb); +return DROP_PACKET ; + } +ATM_SKB (skb)->vcc = pvcc->atmvcc;pr_debug ("(skb=0x%p, vcc=0x%p)\n" , skb, pvcc->atmvcc); -if (skb->data[0 ] =='\0' && (pvcc->flags &SC_COMP_PROT )) - (void )skb_pull (skb,1 ); vcc =ATM_SKB (skb)->vcc;bh_lock_sock (sk_atm (vcc));
@@ -318,23 +321,13 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)switch (pvcc->encaps) {/* LLC encapsulation needed */ case e_llc: -if (skb_headroom (skb) <LLC_LEN ) { -struct sk_buff *n; - n =skb_realloc_headroom (skb,LLC_LEN ); -if (n !=NULL && - !pppoatm_may_send (pvcc, n->truesize)) { -kfree_skb (n); - goto nospace; - } -consume_skb (skb); - skb = n; -if (skb ==NULL ) { -bh_unlock_sock (sk_atm (vcc)); -return DROP_PACKET ; - } - }else if (!pppoatm_may_send (pvcc, skb->truesize)) +if (skb_cow_head (skb,LLC_LEN )) { +bh_unlock_sock (sk_atm (vcc)); +kfree_skb (skb); +return DROP_PACKET ; + } +if (!pppoatm_may_send (pvcc, skb->truesize)) goto nospace; -memcpy (skb_push (skb,LLC_LEN ), pppllc,LLC_LEN );break ;case e_vc:if (!pppoatm_may_send (pvcc, skb->truesize))
@@ -347,6 +340,12 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)return 1 ; } +if (skb->data[0 ] =='\0' && (pvcc->flags &SC_COMP_PROT )) +skb_pull (skb,1 ); + +if (pvcc->encaps == e_llc) +memcpy (skb_push (skb,LLC_LEN ), pppllc,LLC_LEN ); +atm_account_tx (vcc, skb);pr_debug ("atm_skb(%p)->vcc(%p)->dev(%p)\n" , skb,ATM_SKB (skb)->vcc,ATM_SKB (skb)->vcc->dev);
@@ -356,13 +355,6 @@ static int pppoatm_send(struct ppp_channel *chan, struct sk_buff *skb)return ret; nospace:bh_unlock_sock (sk_atm (vcc)); -/* -* We don't have space to send this SKB now, but we might have -* already applied SC_COMP_PROT compression, so may need to undo -*/ -if ((pvcc->flags &SC_COMP_PROT ) &&skb_headroom (skb) >0 && - skb->data[-1 ] =='\0' ) - (void )skb_push (skb,1 );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 811/1193 drop_monitor: synchronize tracepoint unregistration on error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 6a038ef2b57922b6d9ca98ddac0df0681849b704 ]
If register_trace_napi_poll() fails in net_dm_trace_on_set(), unregister_trace_kfree_skb() is called to roll back the kfree_skb tracepoint registration.
However, tracepoint_synchronize_unregister() is omitted before calling cancel_work_sync() and module_put(). An in-flight probe executing concurrently on another CPU could call schedule_work() after cancel_work_sync() has already returned, leaving a pending work item scheduled after the module reference is dropped. If the module is then unloaded, executing the work item triggers a kernel panic.
Add tracepoint_synchronize_unregister() after unregister_trace_kfree_skb() in the error path, matching net_dm_trace_off_set() and net_dm_hw_probe_unregister().
--- net/core/drop_monitor.c | 1 + 1 file changed, 1 insertion(+)
net/core/drop_monitor.c +1 -0
@@ -1171,6 +1171,7 @@ static int net_dm_trace_on_set(struct netlink_ext_ack *extack) err_unregister_trace:unregister_trace_kfree_skb (ops->kfree_skb_probe,NULL ); +tracepoint_synchronize_unregister (); err_module_put:for_each_possible_cpu (cpu) {struct per_cpu_dm_data *data = &per_cpu (dm_cpu_data, cpu);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 812/1193 drop_monitor: fix out-of-bounds write in reset_per_cpu_data()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 439f392084f8f7f59ab9d47a9579185accefe1d8 ]
In reset_per_cpu_data(), al is computed as:
al = sizeof(struct net_dm_alert_msg);
al += dm_hit_limit * sizeof(struct net_dm_drop_point);
al += sizeof(struct nlattr);
skb = genlmsg_new(al, GFP_KERNEL);
...
nla = nla_reserve(skb, NLA_UNSPEC, sizeof(struct net_dm_alert_msg));
...
msg = nla_data(nla);
memset(msg, 0, al);Because al includes sizeof(struct nlattr) (the 4-byte attribute header), genlmsg_new() allocates al bytes of tailroom starting at nla. However, msg points to nla_data(nla), which is located sizeof(struct nlattr) bytes past nla. Calling memset(msg, 0, al) therefore writes al bytes starting from msg, exceeding the allocated buffer by sizeof(struct nlattr) (4 bytes) and corrupting skb_shared_info.
Fix this by letting al represent only the payload length, allocating the skb with genlmsg_new(nla_total_size(al), GFP_KERNEL), and zeroing al bytes from msg.
--- net/core/drop_monitor.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/core/drop_monitor.c +1 -2
@@ -140,9 +140,8 @@ static struct sk_buff *reset_per_cpu_data(struct per_cpu_dm_data *data) al =sizeof (struct net_dm_alert_msg ); al += dm_hit_limit *sizeof (struct net_dm_drop_point ); - al +=sizeof (struct nlattr ); - skb =genlmsg_new (al,GFP_KERNEL ); + skb =genlmsg_new (nla_total_size (al),GFP_KERNEL );if (!skb) goto err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 813/1193 KVM: PPC: Book3S HV: fix use-after-free in kvmhv_emulate_tlbie_all_lpid()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amit Machhiwal <[email protected]>
[ Upstream commit 51938dfa8a51a4f85328413fca9b6e21f9d2d088 ]
kvmhv_emulate_tlbie_all_lpid() iterates the nested-guest IDR and drops mmu_lock before calling kvmhv_emulate_tlbie_lpid(), but does not hold a reference on the kvm_nested_guest pointer obtained from the IDR. A concurrent vCPU issuing a single-LPID tlbie (is=2, ric=2) can race through kvmhv_flush_nested() -> kvmhv_remove_nested() -> idr_remove / --refcnt -> kvmhv_release_nested() -> kfree(gp) in that window, leaving the iterating vCPU with a dangling pointer. The subsequent mutex_lock(&gp->tlb_lock) and accesses to gp->shadow_pgtable, gp->shadow_lpid and gp->l1_host all touch freed memory. The free path is fully L1-controlled.
Fix this by incrementing gp->refcnt inside the loop before dropping mmu_lock, mirroring what kvmhv_get_nested() does, and releasing the reference with kvmhv_put_nested() after the per-guest work completes. This is the same get/put discipline already used at every other call site that drops mmu_lock while holding a nested-guest pointer.
--- arch/powerpc/kvm/book3s_hv_nested.c | 2 ++ 1 file changed, 2 insertions(+)
arch/powerpc/kvm/book3s_hv_nested.c +2 -0
@@ -1172,8 +1172,10 @@ static void kvmhv_emulate_tlbie_all_lpid(struct kvm_vcpu *vcpu, int ric)spin_lock (&kvm->mmu_lock);idr_for_each_entry (&kvm->arch.kvm_nested_guest_idr, gp, lpid) { + ++gp->refcnt;spin_unlock (&kvm->mmu_lock);kvmhv_emulate_tlbie_lpid (vcpu, gp, ric); +kvmhv_put_nested (gp);spin_lock (&kvm->mmu_lock); }spin_unlock (&kvm->mmu_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 804/1193 ksmbd: keep compound responses on query info errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
[ Upstream commit 9fa26285ae70ac2d3d1b47459a6b4463ab053e1c ]
Do not reset the RFC1002 length of the complete response when a query info buffer is too small. The current command will add its error response through ksmbd_iov_pin_rsp(), while resetting the base length can truncate earlier responses in a compound request.
This lets ksmbd return the earlier responses and the query-info error response together. Remove the now-unused rsp_org parameter from the pipe query-info helpers.
--- fs/smb/server/smb2pdu.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-)
fs/smb/server/smb2pdu.c +12 -19
@@ -4628,21 +4628,18 @@ int smb2_query_dir(struct ksmbd_work *work)* @reqOutputBufferLength: max buffer length expected in command response * @fixed_len: minimum fixed response length * @rsp: query info response buffer contains output buffer length -* @rsp_org: base response buffer pointer in case of chained response * * Return: 0 on success, otherwise error */ static int buffer_check_err (int reqOutputBufferLength,unsigned int fixed_len, -struct smb2_query_info_rsp *rsp, -void *rsp_org) +struct smb2_query_info_rsp *rsp) {unsigned int output_len =le32_to_cpu (rsp->OutputBufferLength);if (reqOutputBufferLength < fixed_len) {pr_err ("Invalid Buffer Size Requested\n" ); rsp->hdr.Status =STATUS_INFO_LENGTH_MISMATCH ; - *(__be32 *)rsp_org =cpu_to_be32 (sizeof (struct smb2_hdr ));return -EINVAL ; }
@@ -4653,8 +4650,7 @@ static int buffer_check_err(int reqOutputBufferLength,return 0 ; } -static void get_standard_info_pipe (struct smb2_query_info_rsp *rsp, -void *rsp_org) +static void get_standard_info_pipe (struct smb2_query_info_rsp *rsp) {struct smb2_file_standard_info *sinfo;
@@ -4669,8 +4665,7 @@ static void get_standard_info_pipe(struct smb2_query_info_rsp *rsp,cpu_to_le32 (sizeof (struct smb2_file_standard_info )); } -static void get_internal_info_pipe (struct smb2_query_info_rsp *rsp,u64 num, -void *rsp_org) +static void get_internal_info_pipe (struct smb2_query_info_rsp *rsp,u64 num) {struct smb2_file_internal_info *file_info;
@@ -4684,8 +4679,7 @@ static void get_internal_info_pipe(struct smb2_query_info_rsp *rsp, u64 num,static int smb2_get_info_file_pipe (struct ksmbd_session *sess,struct smb2_query_info_req *req, -struct smb2_query_info_rsp *rsp, -void *rsp_org) +struct smb2_query_info_rsp *rsp) {u64 id;int rc;
@@ -4710,16 +4704,16 @@ static int smb2_get_info_file_pipe(struct ksmbd_session *sess,switch (req->FileInfoClass) {case FILE_STANDARD_INFORMATION : -get_standard_info_pipe (rsp, rsp_org); +get_standard_info_pipe (rsp); rc =buffer_check_err (le32_to_cpu (req->OutputBufferLength),le32_to_cpu (rsp->OutputBufferLength), - rsp, rsp_org); + rsp);break ;case FILE_INTERNAL_INFORMATION : -get_internal_info_pipe (rsp, id, rsp_org); +get_internal_info_pipe (rsp, id); rc =buffer_check_err (le32_to_cpu (req->OutputBufferLength),le32_to_cpu (rsp->OutputBufferLength), - rsp, rsp_org); + rsp);break ;default : ksmbd_debug(SMB, "smb2_info_file_pipe for %u not supported\n",
@@ -5408,8 +5402,7 @@ static int smb2_get_info_file(struct ksmbd_work *work,if (test_share_config_flag (work->tcon->share_conf,KSMBD_SHARE_FLAG_PIPE )) {/* smb2 info file called for pipe */ - rc =smb2_get_info_file_pipe (work->sess, req, rsp, - work->response_buf); + rc =smb2_get_info_file_pipe (work->sess, req, rsp); goto iov_pin_out; }
@@ -5521,7 +5514,7 @@ static int smb2_get_info_file(struct ksmbd_work *work, } rc =buffer_check_err (le32_to_cpu (req->OutputBufferLength), fixed_len, - rsp, work->response_buf); + rsp); }ksmbd_fd_put (work, fp);
@@ -5758,7 +5751,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work, } rc =buffer_check_err (le32_to_cpu (req->OutputBufferLength), fixed_len, - rsp, work->response_buf); + rsp);path_put (&path);if (!rc)
@@ -5873,7 +5866,7 @@ static int smb2_get_info_sec(struct ksmbd_work *work, rsp->OutputBufferLength =cpu_to_le32 (secdesclen); rc =buffer_check_err (le32_to_cpu (req->OutputBufferLength),le32_to_cpu (rsp->OutputBufferLength), - rsp, work->response_buf); + rsp);if (rc) goto err_out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 853/1193 Bluetooth: eir: validate service data length before reading UUID
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aamir Ahmed <[email protected]>
commit e8241766794cf551d787fa3a77c0d54bbea6f6aa upstream.
eir_get_service_data() reads a 16-bit UUID from the service data using get_unaligned_le16() without first checking that the data is long enough to hold a UUID16 (2 bytes). If a malformed EIR entry has a service data field with only 1 byte of payload (field_len=2), eir_get_data() returns dlen=1. The subsequent get_unaligned_le16() then reads 1 byte past the field boundary.
Additionally, if the corrupted UUID happens to match, the length calculation "dlen - 2" underflows to SIZE_MAX since dlen is size_t. Current callers either pass NULL for the length parameter or bounds-check the returned length, but future callers may not.
Add a check that dlen >= sizeof(u16) and skip fields that are too short to contain a valid UUID16.
--- net/bluetooth/eir.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/bluetooth/eir.c +9 -1
@@ -370,7 +370,15 @@ void *eir_get_service_data(u8 *eir, sizesize_t dlen;while ((eir =eir_get_data (eir, eir_len,EIR_SERVICE_DATA , &dlen))) { -u16 value =get_unaligned_le16 (eir); +u16 value; + +if (dlen <sizeof (value)) { + eir += dlen; + eir_len = eir_end - eir; +continue ; + } + + value =get_unaligned_le16 (eir);if (uuid == value) {if (len)
Greg Kroah-Hartman
maintainerPATCH 862/1193 net: wwan: mhi_wwan_mbim: guard against a cyclic NDP chain
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanglei Zhu <[email protected]>
commit 5d063822ac5184939c1ed377a339a01d8ae814e8 upstream.
The NDP traversal in mhi_mbim_rx() only stops when wNextNdpIndex is zero. Nothing requires the offsets to advance, so a modem that points an NDP at itself, or at an earlier NDP, keeps the loop spinning forever on one CPU.
Break out when the next NDP offset is not larger than the current one.
Verified in a QEMU guest with a fault injector feeding the driver's receive callback an NTB whose single NDP points at itself: the unpatched driver spins in mhi_mbim_rx() with one CPU pinned at 100% and the thread never returns. With this check the loop terminates within one iteration.
Changes in v2: move the non-increasing check to the wNextNdpIndex retrieval site, as suggested by Loic Poulain, instead of tracking the previous offset in a separate variable.
--- drivers/net/wwan/mhi_wwan_mbim.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/net/wwan/mhi_wwan_mbim.c +7 -3
@@ -338,9 +338,13 @@ static void mhi_mbim_rx(struct mhi_mbim_ unlock:rcu_read_unlock (); next_ndp: -/* Other NDP to process? */ - ndpoffset = (int )le16_to_cpu (ndp16.wNextNdpIndex); -if (!ndpoffset) +/* Other NDP to process? The offsets must advance, or a +* self-referencing NDP keeps the loop spinning forever. +*/ + n = (int )le16_to_cpu (ndp16.wNextNdpIndex); +if (n > ndpoffset) + ndpoffset = n; +else break ; }
Greg Kroah-Hartman
maintainerPATCH 863/1193 net: wwan: mhi_wwan_mbim: check skb_copy_bits() return value
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanglei Zhu <[email protected]>
commit 31550d585589fde1ae95bf7f7a8188b2d2fdf1c7 upstream.
mhi_mbim_rx() ignores the return value of skb_copy_bits() when it copies each datagram out of the NTB. The datagram offset and length come from the DPE, which is only checked to lie within the NTB itself, so a modem can point a datagram outside the received skb. The copy then fails and the freshly allocated skbn is passed to netif_rx() with its uninitialized contents still in place, leaking kernel heap memory into the network stack.
Free the skb and account an error when the copy fails.
Verified in a QEMU guest with a fault injector pointing a DPE outside the received NTB: the copy fails, and the unpatched driver hands the uninitialized skbn to the network stack (observed as "unknown protocol" on bytes that were never written). With this check the failed datagram is dropped and counted as an rx error.
Changes in v2: factor the free-and-count sequence out into mhi_mbim_rx_drop(), shared with the unknown-protocol path, as suggested by Loic Poulain.
--- drivers/net/wwan/mhi_wwan_mbim.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
drivers/net/wwan/mhi_wwan_mbim.c +13 -5
@@ -240,6 +240,14 @@ static int mbim_rx_verify_ndp16(struct sreturn ret; } +static void mhi_mbim_rx_drop (struct mhi_mbim_link *link,struct sk_buff *skb) +{ +dev_kfree_skb_any (skb); +u64_stats_update_begin (&link->rx_syncp); +u64_stats_inc (&link->rx_errors); +u64_stats_update_end (&link->rx_syncp); +} +static void mhi_mbim_rx (struct mhi_mbim_context *mbim,struct sk_buff *skb) {int ndpoffset;
@@ -309,7 +317,10 @@ static void mhi_mbim_rx(struct mhi_mbim_continue ;skb_put (skbn, dgram_len); -skb_copy_bits (skb, dgram_offset, skbn->data, dgram_len); +if (skb_copy_bits (skb, dgram_offset, skbn->data, dgram_len)) { +mhi_mbim_rx_drop (link, skbn); +continue ; + }switch (skbn->data[0 ] &0xf0 ) {case 0x40 :
@@ -321,10 +332,7 @@ static void mhi_mbim_rx(struct mhi_mbim_default :net_err_ratelimited ("%s: unknown protocol\n" , link->ndev->name); -dev_kfree_skb_any (skbn); -u64_stats_update_begin (&link->rx_syncp); -u64_stats_inc (&link->rx_errors); -u64_stats_update_end (&link->rx_syncp); +mhi_mbim_rx_drop (link, skbn);continue ; }
Greg Kroah-Hartman
maintainerPATCH 864/1193 net/sched: hhf: cap hh_flows_limit at change time
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jamal Hadi Salim <[email protected]>
commit 2cef2588c995722a901368def30befeef9ae55c6 upstream.
hhf_change() stores TCA_HHF_HH_FLOWS_LIMIT with no upper bound. A huge hh_flows_limit lets each new heavy-hitter flow pass the hh_flows_current_cnt check in alloc_new_hh() and forces a fixed-size kzalloc(GFP_ATOMIC) per flow under spoofed traffic, for unbounded memory growth.
Bound the attribute with NLA_POLICY_MAX() at 2*HH_FLOWS_CNT (the hhf_init() default) and report the rejected value via extack. The deprecated nested parse is kept: legacy tc does not set NLA_F_NESTED on TCA_OPTIONS. Configs relying on hh_limit above the default were relying on unbounded, unsafe behaviour and are not supported going forward.
hhf_init() also ran hhf_change() before setting the default hh_flows_limit, so a user-supplied hh_limit at add time was clobbered back to 2048. Set the default before hhf_change() so the configured value sticks.
This is a follow-up to commit eb56a495f59b ("net/sched: hhf: clamp quantum in change and init paths"), which bounded the quantum of the same qdisc; the hh_flows_limit bound is the remaining unbounded knob of that series' scope.
Conditions to recreate the bug: CAP_NET_ADMIN in a user namespace; tc qdisc change dev X root hhf hh_limit 4294967295 succeeds and the value is echoed by tc qdisc show, unbounding heavy-hitter flow allocations; also tc qdisc add dev X root hhf hh_limit 500 stores 2048 instead of 500.
--- net/sched/sch_hhf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/sched/sch_hhf.c +5 -4
@@ -526,7 +526,7 @@ static void hhf_destroy(struct Qdisc *scstatic const struct nla_policy hhf_policy[TCA_HHF_MAX +1 ] = { [TCA_HHF_BACKLOG_LIMIT ] = { .type =NLA_U32 }, [TCA_HHF_QUANTUM ] = { .type =NLA_U32 }, - [TCA_HHF_HH_FLOWS_LIMIT ] = { .type =NLA_U32 }, + [TCA_HHF_HH_FLOWS_LIMIT ] =NLA_POLICY_MAX (NLA_U32 ,2 *HH_FLOWS_CNT ), [TCA_HHF_RESET_TIMEOUT ] = { .type =NLA_U32 }, [TCA_HHF_ADMIT_BYTES ] = { .type =NLA_U32 }, [TCA_HHF_EVICT_TIMEOUT ] = { .type =NLA_U32 },
@@ -545,7 +545,7 @@ static int hhf_change(struct Qdisc *sch,u32 new_hhf_non_hh_weight = q->hhf_non_hh_weight; err =nla_parse_nested_deprecated (tb,TCA_HHF_MAX , opt, hhf_policy, -NULL ); + extack);if (err <0 )return err;
@@ -617,6 +617,9 @@ static int hhf_init(struct Qdisc *sch, s q->hhf_evict_timeout =HZ ;/* 1 sec */ q->hhf_non_hh_weight =2 ; +/* Cap max active HHs at twice len of hh_flows table. */ + q->hh_flows_limit =2 *HH_FLOWS_CNT ; +if (opt) {int err =hhf_change (sch, opt, extack);
@@ -633,8 +636,6 @@ static int hhf_init(struct Qdisc *sch, sfor (i =0 ; i <HH_FLOWS_CNT ; i++)INIT_LIST_HEAD (&q->hh_flows[i]); -/* Cap max active HHs at twice len of hh_flows table. */ - q->hh_flows_limit =2 *HH_FLOWS_CNT ; q->hh_flows_overlimit =0 ; q->hh_flows_total_cnt =0 ; q->hh_flows_current_cnt =0 ;
Greg Kroah-Hartman
maintainerPATCH 865/1193 net/packet: clear RX owner on VNET header error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Amirkan <[email protected]>
commit 33ff111d7ba3beb86e28938d6382bb5beabd865a upstream.
Commit 61fad6816fc1 ("net/packet: tpacket_rcv: avoid a producer race condition") added rx_owner_map and made tpacket_rcv() claim a V1 or V2 ring slot before converting the virtio-net header. If the conversion fails, the drop path leaves the slot claimed.
With a one-frame TPACKET_V2 ring, an unsupported UDP GSO packet leaves the only slot unavailable, so the ring also drops the next valid packet.
Clear the ownership bit on this error path. TPACKET_V3 already clears its block state here.
--- net/packet/af_packet.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/packet/af_packet.c +3 -1
@@ -2434,7 +2434,9 @@ static int tpacket_rcv(struct sk_buff *s virtio_net_hdr_from_skb(skb, h.raw + macoff - sizeof(struct virtio_net_hdr), vio_le(), true, 0)) { -if (po->tp_version ==TPACKET_V3 ) +if (po->tp_version <=TPACKET_V2 ) +__clear_bit (slot_id, po->rx_ring.rx_owner_map); +else prb_clear_blk_fill_status (&po->rx_ring); goto drop_n_account; }
Greg Kroah-Hartman
maintainerPATCH 866/1193 net/packet: avoid truncating TPACKET_V3 private size
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Amirkan <[email protected]>
commit 37213e61120297920ae4c937fcb326a360da5084 upstream.
tpacket_req3.tp_sizeof_priv is an unsigned int, and packet_set_ring() validates the full value against the block size. init_prb_bdqc() then stores it in the unsigned short blk_sizeof_priv field.
Commit 2b6867c2ce76 ("net/packet: fix overflow in check for priv area size") fixed the validation arithmetic, but an accepted value above USHRT_MAX still narrows when it is stored.
For a 131072-byte block, tp_sizeof_priv=65536 is valid. The narrowing makes offset_to_first_pkt 48 instead of 65584, so packet records can be placed in the private area that userspace asked the kernel to preserve.
blk_sizeof_priv is internal state, so widen it to hold the validated UAPI value.
--- net/packet/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/internal.h +1 -1
@@ -21,7 +21,7 @@ struct tpacket_kbdq_core {unsigned char reset_pending_on_curr_blk;unsigned char delete_blk_timer;unsigned short kactive_blk_num; -unsigned short blk_sizeof_priv; +unsigned int blk_sizeof_priv;/* last_kactive_blk_num: * trick to see if user-space has caught up
Greg Kroah-Hartman
maintainerPATCH 867/1193 scsi: core: Validate MODE SENSE lengths in scsi_cdl_enable()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alberto Carboneri <[email protected]>
commit 3d676e458fe0c566f5a62753dc696b6a862fc412 upstream.
scsi_cdl_enable() uses length fields returned by MODE SENSE to locate the ATA feature mode page in a 64-byte stack buffer. A target can report a total length shorter than its mode header and block descriptors. The unsigned subtraction used for the MODE SELECT length can wrap, and the separately computed buf_data can point beyond buf.
During automatic scan, enable is false, so the read-modify-write of buf_data[4] can clear the low two bits of a target-selected out-of-bounds stack byte. scsi_mode_select() can then copy up to 64 bytes from outside the buffer into the outgoing MODE SELECT payload, disclosing stack contents to the target.
This is reachable while scanning a USB storage device that identifies as an ATA device and advertises CDL support. No filesystem mount or userspace access to the block device is required.
On upstream commit cee9395acd80 ("Linux 7.3-rc1"), a build-specific, one-vCPU QEMU/Raw Gadget proof using QEMU-only multi-UDC allocator sampling executed a fixed proof command inside the guest and created a UID-0-owned marker during automatic enumeration, with KASLR and NX enabled.
The issue was independently found during security research at Drivesec S.r.l.
Cap the available length to the buffer size. Validate and consume the mode header and block descriptor lengths before using the page, and require the five bytes needed to access the CDL field.
--- drivers/scsi/scsi.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
drivers/scsi/scsi.c +19 -5
@@ -711,6 +711,7 @@ int scsi_cdl_enable(struct scsi_device *struct scsi_mode_data data;struct scsi_sense_hdr sshdr;char *buf_data; +size_t avail, offset;int len; ret = scsi_mode_sense(sdev, 0x08, 0x0a, 0xf2, buf, sizeof(buf),
@@ -719,11 +720,24 @@ int scsi_cdl_enable(struct scsi_device *return -EINVAL ;/* Enable or disable CDL using the ATA feature page */ - len =min_t (size_t,sizeof (buf), - data.length - data.header_length - - data.block_descriptor_length); - buf_data = buf + data.header_length + - data.block_descriptor_length; + avail =min_t (size_t, data.length,sizeof (buf)); +if (data.header_length > avail) +return -EINVAL ; + + offset = data.header_length; + avail -= data.header_length; + +if (data.block_descriptor_length > avail) +return -EINVAL ; + + offset += data.block_descriptor_length; + avail -= data.block_descriptor_length; + +if (avail <5 ) +return -EINVAL ; + + buf_data = buf + offset; + len = avail;/* * If we want to enable CDL and CDL is already enabled on the
Greg Kroah-Hartman
maintainerPATCH 868/1193 xfrm: serialize state GC with device state flush
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 89fefad9f971bc637fb22373078144f2563c4be9 upstream.
The deferred-device pass in xfrm_dev_state_flush() finds states under xfrm_state_dev_gc_lock, but drops the lock before calling xfrm_dev_state_free() because the driver callback may sleep. The device GC list does not hold an xfrm_state reference, so the state GC worker can destroy the same state concurrently.
The race can proceed as follows:
CPU 0 CPU 1
find x on the device GC list
drop xfrm_state_dev_gc_lock
read x->xso.dev
xfrm_state_gc_destroy(x) xfrm_dev_state_free(x) xfrm_state_free(x)
continue xfrm_dev_state_free(x)
Both paths can invoke the driver callback and drop the device reference. CPU 0 can also access the xfrm_state after CPU 1 has freed it.
KASAN reported:
BUG: KASAN: slab-use-after-free in xfrm_dev_state_free+0x24c/0x2a0 Read of size 8 at addr ffff88810bbaa960 by task poc/102 Call Trace: xfrm_dev_state_free+0x24c/0x2a0 xfrm_dev_state_flush+0x353/0x400 xfrm_dev_event+0x26d/0x3a0 notifier_call_chain+0xc0/0x280 __dev_notify_flags+0x169/0x250 netif_change_flags+0xe7/0x160 dev_change_flags+0x96/0x220 devinet_ioctl+0x7f4/0x1880 Allocated by task 87: xfrm_state_alloc+0x1e/0x5c0 xfrm_add_sa+0xe7f/0x5820 xfrm_user_rcv_msg+0x4f3/0x940 Freed by task 57: kmem_cache_free+0xcb/0x3d0 xfrm_state_gc_task+0x4a8/0x650 process_one_work+0x63a/0x1070
Serialize xfrm_state destruction against the deferred-device pass with a mutex. Keep xfrm_state_dev_gc_lock limited to list operations and retain the existing callback and device-reference release ordering.
--- net/xfrm/xfrm_state.c | 5 +++++ 1 file changed, 5 insertions(+)
net/xfrm/xfrm_state.c +5 -0
@@ -226,6 +226,7 @@ static struct xfrm_state_afinfo __rcu *xstatic DEFINE_SPINLOCK (xfrm_state_gc_lock);static DEFINE_SPINLOCK (xfrm_state_dev_gc_lock); +static DEFINE_MUTEX (xfrm_state_gc_mutex);int __xfrm_state_delete (struct xfrm_state *x);
@@ -570,8 +571,10 @@ static void xfrm_state_gc_task(struct wosynchronize_rcu (); +mutex_lock (&xfrm_state_gc_mutex);hlist_for_each_entry_safe (x, tmp, &gc_list, gclist)xfrm_state_gc_destroy (x); +mutex_unlock (&xfrm_state_gc_mutex); }static enum hrtimer_restart xfrm_timer_handler (struct hrtimer *me)
@@ -928,6 +931,7 @@ restart: out:spin_unlock_bh (&net->xfrm.xfrm_state_lock); +mutex_lock (&xfrm_state_gc_mutex);spin_lock_bh (&xfrm_state_dev_gc_lock); restart_gc:hlist_for_each_entry_safe (x, tmp, &xfrm_state_dev_gc_list, dev_gclist) {
@@ -942,6 +946,7 @@ restart_gc: }spin_unlock_bh (&xfrm_state_dev_gc_lock); +mutex_unlock (&xfrm_state_gc_mutex);xfrm_flush_gc ();
Greg Kroah-Hartman
maintainerPATCH 869/1193 memstick: ms_block: destroy io_queue workqueue on removal
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yifei Gao <[email protected]>
commit 90af7fde083e1b22c349c3a8b1626728e44e474c upstream.
msb_init_disk() creates the per-card ordered workqueue msb->io_queue with alloc_ordered_workqueue(). It is torn down with destroy_workqueue() only on the init error path; msb_remove() never destroys it. msb_stop() merely flushes the queue, and neither msb_data_clear() nor put_disk() free it. As a result every card insert/remove cycle leaks the workqueue and its kworker, exhausting kernel memory over repeated cycles.
Destroy the workqueue in msb_remove() after the disk has been removed and the queue drained.
--- drivers/memstick/core/ms_block.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/memstick/core/ms_block.c +2 -0
@@ -2206,6 +2206,8 @@ static void msb_remove(struct memstick_dmsb_data_clear (msb);mutex_unlock (&msb_disk_lock); +destroy_workqueue (msb->io_queue); +put_disk (msb->disk);memstick_set_drvdata (card,NULL ); }
Greg Kroah-Hartman
maintainerPATCH 870/1193 mm/mlock: use the IRQ-safe accessor for NR_MLOCK in __munlock_folio()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
commit e14a3454806468b086fe2e4ca2e1bff95b528531 upstream.
NR_MLOCK is updated from interrupt context. __free_pages_prepare() clears a stray PG_mlocked and adjusts NR_MLOCK, and a folio can reach it with the flag still set from a bio completion handler:
__free_pages_ok+0x6af/0x7a0 <IRQ> __bio_release_pages+0xde/0x260 __iomap_dio_bio_end_io+0x16e/0x1a0 blk_update_request+0x14b/0x3d0 blk_mq_end_request+0x18/0x30 blk_done_softirq+0x49/0x60
The folio gets there like this. A MAP_SHARED file mapping is mlocked, so its page cache folios carry PG_mlocked, and an O_DIRECT write sourced from that mapping GUP-pins those same folios. munlock() then runs mlock_vma_pages_range(), which clears VM_LOCKED before walking the page tables to munlock each folio. A concurrent hole punch reaches the folio through the rmap (i_mmap_rwsem, not mmap_lock) and can land inside that
window: __folio_remove_rmap() -> munlock_vma_folio() sees VM_LOCKED already clear, so it neither queues the folio on the mlock batch nor takes a reference, and the pte it clears makes the pending mlock_pte_range() walk skip the folio at its !pte_present() check. filemap_remove_folio() then drops the page cache reference, leaving the bio's pin as the last one, released from the completion handler above.
So __zone_stat_mod_folio() here needs interrupts disabled, not merely preemption, and __munlock_folio() has a path where they are not: when the folio has already been taken off the LRU by somebody else the function jumps straight to the counter update without taking the lruvec lock. The read-modify-write of the per-CPU NR_MLOCK diff can then be interrupted by the softirq above, and one of the two decrements is lost, leaving Mlocked in /proc/meminfo permanently overstated.
Use zone_stat_mod_folio(). mod_zone_state()'s this_cpu_try_cmpxchg() is atomic against a same-CPU interrupt and retries, and on the path where the lruvec lock is held its cost is negligible next to the lock itself.
The UNEVICTABLE_PG* events are deliberately left on the __ accessors: they occupy different vm_event_states slots from the UNEVICTABLE_PGCLEARED that __free_pages_prepare() bumps, and nothing updates those two from interrupt context.
--- mm/mlock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mlock.c +1 -1
@@ -141,7 +141,7 @@ static struct lruvec *__munlock_folio(st munlock:if (folio_test_clear_mlocked (folio)) { -__zone_stat_mod_folio (folio,NR_MLOCK , -nr_pages); +zone_stat_mod_folio (folio,NR_MLOCK , -nr_pages);if (isolated || !folio_test_unevictable (folio))__count_vm_events (UNEVICTABLE_PGMUNLOCKED , nr_pages);else
Greg Kroah-Hartman
maintainerPATCH 871/1193 keys: translate request_key_auth pid for the reading procfs instance
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 0d6a4268b06084baafd8ee5d66955c7e1c2e053b upstream.
request_key_auth_describe() prints rka->pid into /proc/keys as a raw pid_t in the initial pid namespace. A reader can open /proc/keys through a mount in another pid namespace. That reader sees a number with no meaning there. The number can even name an unrelated task. The line needs VIEW on the key. So the reader either shares the key owner's uid or possesses the key.
The fix keeps a struct pid. Commit 4f82f45730c6 ("net ip6 flowlabel:
Make owner a union of struct pid * and kuid_t") gave /proc/net/ip6_flowlabel the same storage. The print goes through pid_nr_ns(). It renders against the pid namespace of the procfs instance the line is read through. Commit ad08978ab41c ("ipv6/flowlabel: simplify pid namespace lookup") moved that print to the same anchor. Output through an initial namespace /proc does not change. The line shows 0 for a requestor with no number in that namespace.
Translating at read time was the alternative. find_pid_ns() can resolve a recycled number. The line would then name a live task with no connection to the key. A stored struct pid gives 0 instead when the requestor has no number there.
--- include/keys/request_key_auth-type.h | 2 +- security/keys/request_key_auth.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
include/keys/request_key_auth-type.h +1 -1
@@ -22,7 +22,7 @@ struct request_key_auth {const struct cred *cred;void *callout_info;size_t callout_len; -pid_t pid; +struct pid *pid;char op[8 ]; } __randomize_layout;
security/keys/request_key_auth.c +9 -3
@@ -9,6 +9,8 @@#include <linux/sched.h> #include <linux/err.h> +#include <linux/pid.h> +#include <linux/proc_fs.h> #include <linux/seq_file.h> #include <linux/slab.h> #include <linux/uaccess.h>
@@ -73,7 +75,10 @@ static void request_key_auth_describe(coseq_puts (m,"key:" );seq_puts (m, key->description);if (key_is_positive (key)) -seq_printf (m," pid:%d ci:%zu" , rka->pid, rka->callout_len); +seq_printf (m," pid:%d ci:%zu" , +pid_nr_ns (rka->pid, +proc_pid_ns (file_inode (m->file)->i_sb)), + rka->callout_len); }/*
@@ -113,6 +118,7 @@ static void free_request_key_auth(structif (rka->cred)put_cred (rka->cred);kfree (rka->callout_info); +put_pid (rka->pid);kfree (rka); }
@@ -226,14 +232,14 @@ struct key *request_key_auth_new(struct irka = cred->request_key_auth->payload.data[0 ]; rka->cred =get_cred (irka->cred); - rka->pid = irka->pid; + rka->pid =get_pid (irka->pid);up_read (&cred->request_key_auth->sem); }else {/* it isn't - use this process as the context */ rka->cred =get_cred (cred); - rka->pid = current->pid; + rka->pid =get_pid (task_pid (current)); } rka->target_key =key_get (target);
Greg Kroah-Hartman
maintainerPATCH 854/1193 Bluetooth: hci_codec: validate vendor codec count length
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
commit d0795cfd6f655f4de84868a4f4bb41a03f037b3d upstream.
The Read Local Supported Codecs parsers consume the variable-sized standard codec array before parsing the vendor codec count. Although the initial reply-size check includes a vendor count byte in the fixed layout, it does not guarantee that the byte remains after the standard codec array.
If a controller reply ends immediately after that array, calculating the vendor codec array size reads vnd_codecs->num beyond the skb data. Use skb_pull_data() to validate and consume each codec header before using its count in both command variants.
--- net/bluetooth/hci_codec.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
net/bluetooth/hci_codec.c +18 -18
@@ -145,11 +145,12 @@ void hci_read_supported_codecs(struct hcskb_pull (skb,sizeof (rp->status)); - std_codecs = (void *)skb->data; + std_codecs =skb_pull_data (skb,sizeof (*std_codecs)); +if (!std_codecs) + goto error;/* validate codecs length before accessing */ -if (skb->len <flex_array_size (std_codecs, codec, std_codecs->num) - +sizeof (std_codecs->num)) +if (skb->len <flex_array_size (std_codecs, codec, std_codecs->num)) goto error;/* enumerate codec capabilities of standard codecs */
@@ -161,15 +162,14 @@ void hci_read_supported_codecs(struct hc LOCAL_CODEC_ACL_MASK | LOCAL_CODEC_SCO_MASK, &caps); } -skb_pull (skb,flex_array_size (std_codecs, codec, std_codecs->num) - +sizeof (std_codecs->num)); +skb_pull (skb,flex_array_size (std_codecs, codec, std_codecs->num)); - vnd_codecs = (void *)skb->data; + vnd_codecs =skb_pull_data (skb,sizeof (*vnd_codecs)); +if (!vnd_codecs) + goto error;/* validate vendor codecs length before accessing */ -if (skb->len < -flex_array_size (vnd_codecs, codec, vnd_codecs->num) - +sizeof (vnd_codecs->num)) +if (skb->len <flex_array_size (vnd_codecs, codec, vnd_codecs->num)) goto error;/* enumerate vendor codec capabilities */
@@ -214,11 +214,12 @@ void hci_read_supported_codecs_v2(structskb_pull (skb,sizeof (rp->status)); - std_codecs = (void *)skb->data; + std_codecs =skb_pull_data (skb,sizeof (*std_codecs)); +if (!std_codecs) + goto error;/* check for payload data length before accessing */ -if (skb->len <flex_array_size (std_codecs, codec, std_codecs->num) - +sizeof (std_codecs->num)) +if (skb->len <flex_array_size (std_codecs, codec, std_codecs->num)) goto error;memset (&caps,0 ,sizeof (caps));
@@ -229,15 +230,14 @@ void hci_read_supported_codecs_v2(struct &caps); } -skb_pull (skb,flex_array_size (std_codecs, codec, std_codecs->num) - +sizeof (std_codecs->num)); +skb_pull (skb,flex_array_size (std_codecs, codec, std_codecs->num)); - vnd_codecs = (void *)skb->data; + vnd_codecs =skb_pull_data (skb,sizeof (*vnd_codecs)); +if (!vnd_codecs) + goto error;/* check for payload data length before accessing */ -if (skb->len < -flex_array_size (vnd_codecs, codec, vnd_codecs->num) - +sizeof (vnd_codecs->num)) +if (skb->len <flex_array_size (vnd_codecs, codec, vnd_codecs->num)) goto error;for (i =0 ; i < vnd_codecs->num; i++) {
Greg Kroah-Hartman
maintainerPATCH 872/1193 KEYS: trusted: Fix tpm2_load_cmd() boundary check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jarkko Sakkinen <[email protected]>
commit 114f00d738f15dd8c7318369edcdc53dd6d08763 upstream.
tpm2_load_cmd() does boundary checks against the ASN.1 size i.e., payload->blob_len. Address this by passing the decoded blob size to tpm2_load_cmd(), and use it for the boundary checks.
--- security/keys/trusted-keys/trusted_tpm2.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
security/keys/trusted-keys/trusted_tpm2.c +7 -5
@@ -108,7 +108,7 @@ struct tpm2_key_context {static int tpm2_key_decode (struct trusted_key_payload *payload,struct trusted_key_options *options, -u8 **buf) +u8 **buf,unsigned int *blob_len) {int ret;struct tpm2_key_context ctx;
@@ -129,6 +129,7 @@ static int tpm2_key_decode(struct trustereturn -ENOMEM ; *buf = blob; + *blob_len = ctx.priv_len + ctx.pub_len; options->keyhandle = ctx.parent;memcpy (blob, ctx.priv, ctx.priv_len);
@@ -384,10 +385,11 @@ static int tpm2_load_cmd(struct tpm_chipint rc;u32 attrs; - rc =tpm2_key_decode (payload, options, &blob); + rc =tpm2_key_decode (payload, options, &blob, &blob_len);if (rc) {/* old form */ blob = payload->blob; + blob_len = payload->blob_len; payload->old_format =1 ; }else {/* Bind for cleanup: */
@@ -399,17 +401,17 @@ static int tpm2_load_cmd(struct tpm_chipreturn -EINVAL ;/* must be big enough for at least the two be16 size counts */ -if (payload->blob_len <4 ) +if (blob_len <4 )return -EINVAL ; private_len =get_unaligned_be16 (blob);/* must be big enough for following public_len */ -if (private_len +2 +2 > (payload->blob_len)) +if (private_len +2 +2 > blob_len)return -E2BIG ; public_len =get_unaligned_be16 (blob +2 + private_len); -if (private_len +2 + public_len +2 > payload->blob_len) +if (private_len +2 + public_len +2 > blob_len)return -E2BIG ; pub = blob +2 + private_len +2 ;
Greg Kroah-Hartman
maintainerPATCH 873/1193 i2c: at91: release DMA channels on remove and probe error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit f7eeb1af8537b05953fb1c88ab8b59d94059a381 upstream.
at91_twi_configure_dma() requests exclusive tx/rx DMA channels, but nothing ever releases them on driver detach, and the probe error path after the channels are acquired (i2c_add_numbered_adapter() failure) returns without releasing them either, because the remove callback is not invoked after a failed probe.
Move the release into a helper, call it from the existing configure-failure path, the adapter-registration failure path, and at91_twi_remove().
--- drivers/i2c/busses/i2c-at91-core.c | 3 +++ drivers/i2c/busses/i2c-at91-master.c | 12 +++++++++++- drivers/i2c/busses/i2c-at91.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-at91-core.c +3 -0
@@ -258,6 +258,7 @@ static int at91_twi_probe(struct platforpm_runtime_disable (dev->dev);pm_runtime_set_suspended (dev->dev); +at91_twi_dma_release (dev);return rc; }
@@ -274,6 +275,8 @@ static void at91_twi_remove(struct platfi2c_del_adapter (&dev->adapter);clk_disable_unprepare (dev->clk); +at91_twi_dma_release (dev); +pm_runtime_disable (dev->dev);pm_runtime_set_suspended (dev->dev); }
drivers/i2c/busses/i2c-at91-master.c +11 -1
@@ -818,11 +818,21 @@ static int at91_twi_configure_dma(struct error:if (ret != -EPROBE_DEFER )dev_info (dev->dev,"can't get DMA channel, continue without DMA support\n" ); +at91_twi_dma_release (dev); +return ret; +} + +void at91_twi_dma_release (struct at91_twi_dev *dev) +{ +struct at91_twi_dma *dma = &dev->dma; +if (dma->chan_rx)dma_release_channel (dma->chan_rx);if (dma->chan_tx)dma_release_channel (dma->chan_tx); -return ret; + dma->chan_rx =NULL ; + dma->chan_tx =NULL ; + dev->use_dma = false; } static int at91_init_twi_recovery_gpio(struct platform_device *pdev,
drivers/i2c/busses/i2c-at91.h +1 -0
@@ -172,6 +172,7 @@ void at91_twi_irq_restore(struct at91_twvoid at91_init_twi_bus (struct at91_twi_dev *dev);void at91_init_twi_bus_master (struct at91_twi_dev *dev); +void at91_twi_dma_release (struct at91_twi_dev *dev);int at91_twi_probe_master (struct platform_device *pdev,u32 phy_addr,struct at91_twi_dev *dev);
Greg Kroah-Hartman
maintainerPATCH 874/1193 i2c: atr: fix dangling adapter pointer on add failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit ad34235808b63a70ca4989b7a2852923193d06ef upstream.
i2c_atr_add_adapter() stores atr->adapter[chan_id] before i2c_add_adapter() so that the I2C bus notifier can match child clients during registration. On failure the channel is freed but the slot was left pointing at freed memory, which can lead to use-after-free in i2c_atr_del_adapter() / cleanup and also block reuse with -EEXIST.
Clear the slot on the i2c_add_adapter() error path before freeing chan.
--- drivers/i2c/i2c-atr.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/i2c-atr.c +1 -0
@@ -632,6 +632,7 @@ int i2c_atr_add_adapter(struct i2c_atr * ret =i2c_add_adapter (&chan->adap);if (ret) { + atr->adapter[chan_id] =NULL ;dev_err (dev,"failed to add atr-adapter %u (error=%d)\n" , chan_id, ret); goto err_fwnode_put;
Greg Kroah-Hartman
maintainerPATCH 875/1193 i2c: imx: release DMA channels on probe error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit e9f03b9625e2eeaca357b065c92d5b14064a1583 upstream.
i2c_imx_dma_request() acquires exclusive tx/rx DMA channels and is
optional: on errors other than -EPROBE_DEFER the driver falls back to PIO mode and probe continues. If i2c_add_numbered_adapter() then fails, probe returns through clk_notifier_unregister without releasing the channels, because the remove callback is not invoked after a failed probe.
Release the channels on the probe error path, mirroring i2c_imx_remove().
--- drivers/i2c/busses/i2c-imx.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-imx.c +2 -0
@@ -1609,6 +1609,8 @@ static int i2c_imx_probe(struct platform clk_notifier_unregister:clk_notifier_unregister (i2c_imx->clk, &i2c_imx->clk_change_nb); +if (i2c_imx->dma) +i2c_imx_dma_free (i2c_imx);free_irq (irq, i2c_imx); rpm_disable:pm_runtime_put_noidle (&pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 876/1193 i2c: imx: disable autosuspend on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit e0c3e9d76adbe522dd420a766ce42d03ce887c29 upstream.
i2c_imx_probe() enables runtime PM autosuspend with pm_runtime_use_autosuspend(). The probe error path correctly undoes this setting with pm_runtime_dont_use_autosuspend(), but the normal remove path only disables runtime PM.
The runtime PM API requires pm_runtime_use_autosuspend() to be undone with pm_runtime_dont_use_autosuspend() at driver exit unless runtime PM was enabled with devm_pm_runtime_enable(). Leaving the autosuspend flag set therefore leaves the runtime PM state incompletely cleaned up after the driver is unbound.
Add the missing pm_runtime_dont_use_autosuspend() call to the remove path.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-imx.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/busses/i2c-imx.c +1 -0
@@ -1651,6 +1651,7 @@ static void i2c_imx_remove(struct platfopm_runtime_put_noidle (&pdev->dev);pm_runtime_disable (&pdev->dev); +pm_runtime_dont_use_autosuspend (&pdev->dev); }static int __maybe_unused i2c_imx_runtime_suspend (struct device *dev)
Greg Kroah-Hartman
maintainerPATCH 877/1193 IB/mlx4: Fix use-after-free on pkey sysfs registration failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
commit 1af874e9f4ce22ccf8b10ab5462f32c70d3be21a upstream.
register_pkey_tree() ignores errors from register_one_pkey_tree() and continues registering the remaining slaves. The per-slave error path has already released the pkey parent kobjects, but their pointers remain stored in the device. A later device cleanup therefore passes the stale pointers to kobject_put(), causing a use-after-free.
Clear the parent pointers after releasing a failed slave tree and skip unregistered trees during device cleanup. This preserves the existing best-effort registration behavior while preventing a second cleanup of the failed tree.
--- drivers/infiniband/hw/mlx4/sysfs.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/hw/mlx4/sysfs.c +4 -0
@@ -753,11 +753,13 @@ err_add:kobject_put (p); }kobject_put (dev->dev_ports_parent[slave]); + dev->dev_ports_parent[slave] =NULL ; err_ports:kobject_put (dev->pkeys.device_parent[slave]);/* extra put for the device_parent create_and_add */ kobject_put (dev->pkeys.device_parent[slave]); + dev->pkeys.device_parent[slave] =NULL ; fail_dev:kobject_put (dev->iov_parent);
@@ -787,6 +789,8 @@ static void unregister_pkey_tree(structreturn ;for (slave = device->dev->persist->num_vfs; slave >=0 ; --slave) { +if (!device->pkeys.device_parent[slave]) +continue ;list_for_each_entry_safe (p, t, &device->pkeys.pkey_port_list[slave], entry) {
Greg Kroah-Hartman
maintainerPATCH 878/1193 IB/hfi1: Resolve the credit-return buffer through the send contexts node
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
commit 975396b9e5a4028e649f4b9a6a5ca5dfb76a824b upstream.
hfi1_file_mmap()'s PIO_CRED case derives this context's credit-return page offset, and the DMA handle for it, from dd->cr_base[uctxt->numa_id]. uctxt->numa_id is the node of whichever CPU the process happened to be running on, but the entry itself lives in the credit-return allocation of the send context's own node:
sc->hw_free = &sc->dd->cr_base[sc->node].va[gc].cr[index];
and user send contexts are allocated with sc_alloc(dd, SC_USER, ..., dd->node), the HFI-local node. On a multi-socket host with the process running off that node the two allocations differ, so the subtraction produces an offset into an unrelated buffer and the DMA handle belongs to the wrong allocation.
Use the send context's own node for all three references. The continuation lines are reindented at the same time; they mixed spaces and tabs.
--- drivers/infiniband/hw/hfi1/file_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +4 -4
@@ -382,10 +382,10 @@ static int hfi1_file_mmap(struct file *f* of enabled contexts > 64 and 128 respectively). */ cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->numa_id].va) & -PAGE_MASK ; - memvirt = dd->cr_base[uctxt->numa_id].va + cr_page_offset; - memdma = dd->cr_base[uctxt->numa_id].dma + cr_page_offset; + (u64 )dd->cr_base[uctxt->sc->node].va) & +PAGE_MASK ; + memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; + memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
Greg Kroah-Hartman
maintainerPATCH 879/1193 IB/hfi1: Fix the PIO_CRED credit-return mmap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuhei Takeshita <[email protected]>
commit 62f0f34fbd2b2d5653d33d3b9d42fdcabb1c0101 upstream.
hfi1_file_mmap()'s PIO_CRED case must hand user space the single credit-return page that holds this context's entry. That page is the second or third page of the per-node credit-return allocation once the hardware send context index reaches 64 or 128, so the failure below is
intermittent: when the entry lands on the first page the offset is zero and everything works.
Two things are wrong.
First, cr_page_offset is a byte offset but .va is a struct credit_return *, so adding it is pointer arithmetic and scales the offset by sizeof(struct credit_return) == 64. memvirt then lands 256 KiB or 512 KiB past a 10240-byte allocation. With an IOMMU translating, that address is inside the vmalloc range but in no vm_area, so dma_mmap_coherent() -> iommu_dma_mmap() finds no pages, vmalloc_to_pfn() returns page_to_pfn(NULL), and remap_pfn_range() installs a frame above MAXPHYADDR. The first user read then takes:
psm2_ep_open_pr: Corrupted page table at address 7a14d007e000 PGD 800000013886a067 P4D 800000013886a067 PUD 13886b067 PMD 13886c067
PTE 800049168e911235 Oops: Bad pagetable: 000d [#1] SMP PTI
Second, and still wrong once the arithmetic is corrected, dma_mmap_coherent() describes a whole coherent buffer and selects the page within it with vma->vm_pgoff. Offsetting cpu_addr has no effect:
for a vmap'd allocation iommu_dma_mmap() uses cpu_addr only to locate the vm_area and then maps pages[vm_pgoff], which hfi1_file_mmap() has just set to 0. User space therefore always receives the first credit-return page, every credit read is for the wrong context, and send PIO stalls forever.
Use the DMA API as intended: pass the base of the allocation with its full length and select the page with vm_pgoff. A separate length is needed because memlen must keep describing the VMA for the existing size check. The dma-direct path stays correct as well, since dma_direct_mmap() adds the same vm_pgoff to the base pfn.
Tested on a Dell T7610 (Xeon E5-2650 v2, Intel IOMMU in DMA-FQ mode) against a Threadripper PRO 3995WX peer, both Omni-Path 100. Before this change psm2_ep_open() Oopses the kernel; with only the arithmetic corrected psm2_ep_open() succeeds but any transfer that uses send PIO hangs, PSM2_SDMA=2 (send PIO disabled) completing normally while PSM2_SDMA=0 (send PIO only) hangs every time. With this change send PIO, send DMA and the default mixed mode all work.
--- drivers/infiniband/hw/hfi1/file_ops.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/infiniband/hw/hfi1/file_ops.c +16 -5
@@ -326,6 +326,7 @@ static int hfi1_file_mmap(struct file *fvoid *memvirt =NULL ;dma_addr_t memdma =0 ;u8 subctxt, mapio =0 , vmf =0 , type; +size_t memdmalen =0 ;ssize_t memlen =0 ;int ret =0 ;u16 ctxt;
@@ -371,7 +372,9 @@ static int hfi1_file_mmap(struct file *f mapio =1 ;break ;case PIO_CRED : { +struct credit_return_base *cr = &dd->cr_base[uctxt->sc->node];u64 cr_page_offset; +if (flags &VM_WRITE ) { ret = -EPERM ; goto done;
@@ -381,11 +384,18 @@ static int hfi1_file_mmap(struct file *f* second or third page allocated for credit returns (if number * of enabled contexts > 64 and 128 respectively). */ - cr_page_offset = ((u64 )uctxt->sc->hw_free - - (u64 )dd->cr_base[uctxt->sc->node].va) & + cr_page_offset = ((u64 )uctxt->sc->hw_free - (u64 )cr->va) &PAGE_MASK ; - memvirt = dd->cr_base[uctxt->sc->node].va + cr_page_offset; - memdma = dd->cr_base[uctxt->sc->node].dma + cr_page_offset; +/* +* dma_mmap_coherent() describes the whole coherent buffer and +* selects the page within it with vma->vm_pgoff, so pass the +* base of the allocation and its length and let vm_pgoff pick +* the page. +*/ + vma->vm_pgoff = cr_page_offset >>PAGE_SHIFT ; + memvirt = cr->va; + memdma = cr->dma; + memdmalen =TXE_NUM_CONTEXTS *sizeof (struct credit_return ); memlen =PAGE_SIZE ; flags &= ~VM_MAYWRITE ; flags |=VM_DONTCOPY |VM_DONTEXPAND ;
@@ -567,7 +577,8 @@ static int hfi1_file_mmap(struct file *f ret =0 ; }else if (memdma) { ret =dma_mmap_coherent (&dd->pcidev->dev, vma, - memvirt, memdma, memlen); + memvirt, memdma, + memdmalen ? memdmalen : memlen); }else if (mapio) { ret = io_remap_pfn_range(vma, vma->vm_start, PFN_DOWN(memaddr),
Greg Kroah-Hartman
maintainerPATCH 880/1193 selinux: preserve user SID across nested backing files
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 8c0c602202b9a4909b00bc3354e3c0355bc69e65 upstream.
SELinux saves the user file SID in a backing-file security blob so it remains available after mmap() replaces vma->vm_file with a backing file.
For nested backing files (overlayfs over overlayfs, or FUSE passthrough backed by overlayfs), user_file may itself be a backing file. Its fsec->sid is the SID of the mounter that opened it, rather than the user that opened the top-level file. mprotect() then checks fd { use } against the mounter SID. This can incorrectly deny access without a domain transition, or check the wrong target SID after one.
Copy the saved user SID when user_file is a backing file. Keep using the regular file SID for the first backing layer.
With two nested overlayfs mounts and SELinux enforcing, mprotect(PROT_READ) returns EACCES with an fd { use } denial against the mounter SID. With this change, mprotect() succeeds.
Tested on arm64 QEMU with a small BusyBox initramfs and a purpose-built SELinux policy. The original test was also repeated with Fedora Cloud Base 44 userspace and gave the same result.
--- security/selinux/hooks.c | 9 ++++++++- security/selinux/include/objsec.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-)
security/selinux/hooks.c +8 -1
@@ -3661,13 +3661,20 @@ static int selinux_file_alloc_security(sreturn 0 ; } +static inline u32 selinux_file_user_sid (const struct file *file) +{ +if (unlikely (file->f_mode &FMODE_BACKING )) +return selinux_backing_file (file)->uf_sid; +return selinux_file (file)->sid; +} +static int selinux_backing_file_alloc (struct file *backing_file,const struct file *user_file) {struct backing_file_security_struct *bfsec; bfsec =selinux_backing_file (backing_file); - bfsec->uf_sid =selinux_file (user_file)->sid; + bfsec->uf_sid =selinux_file_user_sid (user_file);return 0 ; }
security/selinux/include/objsec.h +1 -1
@@ -61,7 +61,7 @@ struct file_security_struct { };struct backing_file_security_struct { -u32 uf_sid;/* associated user file fsec->sid */ +u32 uf_sid;/* top-level user file fsec->sid */ };struct superblock_security_struct {
Greg Kroah-Hartman
maintainerPATCH 881/1193 selinux: recheck intermediate backing files on mprotect()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit 78fc54b934bfb2c18aad8154c7302067146946f9 upstream.
mprotect() can be used to bypass the SELinux checks that mmap() performs against the intermediate layers of a stacked filesystem.
mmap() checks every backing layer as the request descends through the stack. mprotect() only has the lowest backing file in vma->vm_file, so it rechecks the top-level user and the lowest mounter, but skips the mounters of every layer in between. With two nested overlayfs mounts and a policy denying mounter_t -> middle_file_t:file { execute }, a direct mmap(PROT_EXEC) is denied:
avc: denied { execute } for pid=71 comm="nested_exec"
path="/payload" dev="overlay" ino=9 scontext=user_u:base_r:mounter_t tcontext=user_u:object_r:middle_file_t tclass=file permissive=0
while mmap(PROT_NONE) followed by mprotect(PROT_EXEC) succeeds.
Preserve each intermediate path, mounter SID and file-description SID in the backing-file security blob, copying the saved entries when another backing layer is opened. Allocate the array only for nested backing files, and release it and the path references in the backing_file_free hook.
During mprotect(), recheck fd { use } and the requested inode permissions for every saved mounter, and include the intermediate layers in the execmod checks. Policy for nested stacking may then need to grant intermediate mounters what a direct mmap() already requires, and execmod on intermediate labels for binaries using text relocations.
Tested on arm64 QEMU with a small BusyBox initramfs and a purpose-built SELinux policy, on a mainline tree containing
commit f2381b546e7e ("fs: fix user path of nested backing files").
--- security/selinux/hooks.c | 141 +++++++++++++++++++++++++++++++++----- security/selinux/include/objsec.h | 8 ++ 2 files changed, 133 insertions(+), 16 deletions(-)
security/selinux/hooks.c +125 -16
@@ -1649,26 +1649,32 @@ static int cred_has_capability(const strreturn rc; } -/* Check whether a task has a particular permission to an inode. -The 'adp' parameter is optional and allows other audit -data to be passed (e.g. the dentry). */ -static int inode_has_perm (const struct cred *cred, -struct inode *inode, -u32 perms, -struct common_audit_data *adp) +/* +* Check whether a SID has a particular permission to an inode. The 'adp' +* parameter is optional and allows other audit data to be passed (e.g. the +* dentry). +*/ +static int inode_sid_has_perm (u32 sid,struct inode *inode,u32 perms, +struct common_audit_data *adp) {struct inode_security_struct *isec; -u32 sid;if (unlikely (IS_PRIVATE (inode)))return 0 ; - sid =cred_sid (cred); isec =selinux_inode (inode);return avc_has_perm (sid, isec->sid, isec->sclass, perms, adp); } +static int inode_has_perm (const struct cred *cred, +struct inode *inode, +u32 perms, +struct common_audit_data *adp) +{ +return inode_sid_has_perm (cred_sid (cred), inode, perms, adp); +} +/* Same as inode_has_perm, but pass explicit audit data containing the dentry to help the auditing code to more easily generate the pathname if needed. */
@@ -3672,13 +3678,63 @@ static int selinux_backing_file_alloc(st const struct file *user_file) {struct backing_file_security_struct *bfsec; +const struct backing_file_security_struct *ubfsec; +struct backing_file_security_layer *layer; +u32 i; bfsec =selinux_backing_file (backing_file); bfsec->uf_sid =selinux_file_user_sid (user_file); +if (!(user_file->f_mode &FMODE_BACKING )) +return 0 ; + + ubfsec =selinux_backing_file (user_file); +/* a wrapped count would make kmalloc_array() return ZERO_SIZE_PTR */ +if (unlikely (ubfsec->layer_count ==U32_MAX )) +return -EOVERFLOW ; + +/* +* The final VMA only retains the lowest backing file, so record the +* whole chain here rather than in the mmap hook, where concurrent +* mappings would have to be serialized. Size it dynamically: erofs +* inode sharing adds a backing file without bumping s_stack_depth. +*/ + bfsec->layers =kmalloc_array (ubfsec->layer_count +1 , +sizeof (*bfsec->layers),GFP_KERNEL ); +if (!bfsec->layers) +return -ENOMEM ; + +for (i =0 ; i < ubfsec->layer_count; i++) { + layer = &bfsec->layers[i]; + *layer = ubfsec->layers[i]; +path_get (&layer->path); + } + +/* f_path, not file_user_path(): this layer, not the top-level file */ + layer = &bfsec->layers[i]; + layer->path = user_file->f_path; + layer->mounter_sid =cred_sid (user_file->f_cred); + layer->fd_sid =selinux_file (user_file)->sid; +path_get (&layer->path); + bfsec->layer_count = ubfsec->layer_count +1 ;return 0 ; } +static void selinux_backing_file_free (struct file *backing_file) +{ +struct backing_file_security_struct *bfsec; + +/* security_backing_file_free() may be called twice after an error */ +if (!backing_file_security (backing_file)) +return ; + + bfsec =selinux_backing_file (backing_file); +while (bfsec->layer_count) +path_put (&bfsec->layers[--bfsec->layer_count].path); +kfree (bfsec->layers); + bfsec->layers =NULL ; +} +/* * Check whether a task has the ioctl permission and cmd * operation to an inode.
@@ -3796,6 +3852,53 @@ static int selinux_file_ioctl_compat(strstatic int default_noexec__ro_after_init ; +static u32 file_map_prot_to_av (unsigned long prot,bool shared) +{ +u32 av =FILE__READ ; + +if (shared && (prot &PROT_WRITE )) + av |=FILE__WRITE ; +if (prot &PROT_EXEC ) + av |=FILE__EXECUTE ; + +return av; +} + +static int backing_mounters_has_perm (const struct file *file,u32 av) +{ +const struct backing_file_security_struct *bfsec; +const struct backing_file_security_layer *layer; +struct common_audit_data ad; +struct inode *inode; +u32 i; +int rc; + +if (WARN_ON_ONCE (!(file->f_mode &FMODE_BACKING ))) +return -EIO ; + + bfsec =selinux_backing_file (file); +for (i =0 ; i < bfsec->layer_count; i++) { + layer = &bfsec->layers[i]; + inode =d_inode (layer->path.dentry); + + ad.type =LSM_AUDIT_DATA_PATH ; + ad.u.path = layer->path; + +if (layer->mounter_sid != layer->fd_sid) { + rc =avc_has_perm (layer->mounter_sid, layer->fd_sid, +SECCLASS_FD ,FD__USE , &ad); +if (rc) +return rc; + } + + rc =inode_sid_has_perm (layer->mounter_sid, inode, av, &ad); +if (rc) +return rc; + } + +return 0 ; +} +static int __file_map_prot_check (const struct file *file,unsigned long prot,bool shared,bool mounter_check,bool bf_user_file)
@@ -3829,14 +3932,10 @@ static int __file_map_prot_check(const sif (file) {const struct cred *cred = mounter_check ? file->f_cred :current_cred (); -/* "read" always possible, "write" only if shared */ -u32 av =FILE__READ ; -if (shared && prot_write) - av |=FILE__WRITE ; -if (prot_exec) - av |=FILE__EXECUTE ; -return __file_has_perm (cred, file, av, bf_user_file); +return __file_has_perm (cred, file, +file_map_prot_to_av (prot, shared), + bf_user_file); }return 0 ;
@@ -3931,6 +4030,7 @@ static int selinux_file_mprotect(structint rc;const struct cred *cred =current_cred ();u32 sid =cred_sid (cred); +u32 av;const struct file *file = vma->vm_file;bool backing_file;bool shared = vma->vm_flags &VM_SHARED ;
@@ -3974,6 +4074,10 @@ static int selinux_file_mprotect(structif (rc)return rc;if (backing_file) { + rc =backing_mounters_has_perm (file, +FILE__EXECMOD ); +if (rc) +return rc; rc =file_has_perm (file->f_cred, file,FILE__EXECMOD );if (rc)
@@ -3986,6 +4090,10 @@ static int selinux_file_mprotect(structif (rc)return rc;if (backing_file) { + av =file_map_prot_to_av (prot, shared); + rc =backing_mounters_has_perm (file, av); +if (rc) +return rc; rc =file_map_prot_check (file, prot, shared, true);if (rc)return rc;
@@ -7212,6 +7320,7 @@ static struct security_hook_list selinuxLSM_HOOK_INIT (file_permission, selinux_file_permission),LSM_HOOK_INIT (file_alloc_security, selinux_file_alloc_security),LSM_HOOK_INIT (backing_file_alloc, selinux_backing_file_alloc), +LSM_HOOK_INIT (backing_file_free, selinux_backing_file_free),LSM_HOOK_INIT (file_ioctl, selinux_file_ioctl),LSM_HOOK_INIT (file_ioctl_compat, selinux_file_ioctl_compat), LSM_HOOK_INIT(mmap_file, selinux_mmap_file),
security/selinux/include/objsec.h +8 -0
@@ -60,8 +60,16 @@ struct file_security_struct {u32 pseqno;/* Policy seqno at the time of file open */ }; +struct backing_file_security_layer { +struct path path;/* this layer's real path */ +u32 mounter_sid;/* SID of the mounter that opened it */ +u32 fd_sid;/* SID of its open file description */ +}; +struct backing_file_security_struct {u32 uf_sid;/* top-level user file fsec->sid */ +u32 layer_count;/* number of intermediate backing files */ +struct backing_file_security_layer *layers; };struct superblock_security_struct {
Greg Kroah-Hartman
maintainerPATCH 855/1193 Bluetooth: hci_sync: Serialize local codec list cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 9a10987a2f160a44a638c9a35994ca6e3089696e upstream.
hci_dev_close_sync() clears hdev->local_codecs after releasing hdev->lock. Codec list additions and both traversals in sco_sock_getsockopt() use that lock, but the close path does not. A close and BT_CODEC query can therefore interleave as follows:
hci_dev_close_sync() sco_sock_getsockopt()
hci_dev_lock()
fetch codec entry
hci_codec_list_clear()
kfree(entry)
read entry->idThe reader then accesses an entry which the close path has freed. KASAN reported:
BUG: KASAN: slab-use-after-free in sco_sock_getsockopt+0xfa0/0xfe0 Read of size 1 at addr ffff8881001c3450 Call Trace: sco_sock_getsockopt+0xfa0/0xfe0 do_sock_getsockopt+0x537/0x7b0 __sys_getsockopt+0xf2/0x170 Allocated by task 92: hci_codec_list_add.isra.0+0x2c/0x440 hci_read_codec_capabilities+0x224/0x590 hci_read_supported_codecs+0x2c2/0x640 Freed by task 92: kfree+0x131/0x3c0 hci_codec_list_clear+0xd8/0x160 hci_dev_close_sync+0x92a/0xfa0
Take hdev->lock around the clear operation at its existing point in the close path. This makes the clear wait for active readers and prevents a new traversal until the list is empty without changing teardown ordering.
--- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_sync.c +2 -0
@@ -5465,7 +5465,9 @@ int hci_dev_close_sync(struct hci_dev *hmemset (hdev->eir,0 ,sizeof (hdev->eir));memset (hdev->dev_class,0 ,sizeof (hdev->dev_class));bacpy (&hdev->random_addr,BDADDR_ANY ); +hci_dev_lock (hdev);hci_codec_list_clear (&hdev->local_codecs); +hci_dev_unlock (hdev);hci_dev_put (hdev);return err;
Greg Kroah-Hartman
maintainerPATCH 882/1193 selinux: always fill AVC decision in avc_has_perm_noaudit()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
commit 8861db305103107199b1426f25fde1fb6d465583 upstream.
avc_has_perm_noaudit() is documented to return a copy of the access decision in @avd, but its early return for an empty requested permission set leaves the buffer untouched. All callers pass an uninitialized stack variable and afterwards feed it to avc_audit(), and the inode hook even stores it in the per-task decision cache.
Fill in a deny-all, audit-all decision, similar to avd_init(), so every caller receives a defined value at no cost on the hot path.
--- security/selinux/avc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
security/selinux/avc.c +4 -1
@@ -1151,8 +1151,11 @@ inline int avc_has_perm_noaudit(u32 ssidu32 denied;struct avc_node *node; -if (WARN_ON (!requested)) +if (WARN_ON (!requested)) { +/* Provide a deny-all, audit-all decision to the caller. */ + *avd = (struct av_decision ){ .auditdeny =0xffffffff };return -EACCES ; + }rcu_read_lock (); node =avc_lookup (ssid, tsid, tclass);
Greg Kroah-Hartman
maintainerPATCH 883/1193 mmc: core: Cancel SDIO IRQ work before freeing host
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 6feadbecdae60a6324c967f3b1493741083793a3 upstream.
A host controller that uses sdio_signal_irq() schedules host->sdio_irq_work from its interrupt handler. That work is only cancelled on the suspend path (mmc_sdio_suspend()), not on the remove/free path, so a worker armed just before the controller freed its IRQ can run after mmc_host_classdev_release() has freed the host and dereference it through container_of().
Cancel host->sdio_irq_work in mmc_free_host(), like the existing host->detect drain added by commit 1036f69e2513 ("mmc: core: Cancel delayed work before releasing host").
This issue was found by an in-house static analysis tool.
--- drivers/mmc/core/host.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/core/host.c +1 -0
@@ -692,6 +692,7 @@ EXPORT_SYMBOL(mmc_remove_host);void mmc_free_host (struct mmc_host *host) {cancel_delayed_work_sync (&host->detect); +cancel_work_sync (&host->sdio_irq_work);mmc_pwrseq_free (host);put_device (&host->class_dev); }
Greg Kroah-Hartman
maintainerPATCH 884/1193 mmc: core: Fix OF node reference leak on card add failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhu Ling <[email protected]>
commit 08b54e16d547d5c1aa61bf7a3595bb1620975eeb upstream.
mmc_of_find_child_device() returns a device node with its reference count incremented. mmc_add_card() stores the reference before calling device_add(), while the card is marked present only after device_add() succeeds.
If device_add() fails, the callers release the card through mmc_remove_card(). However, mmc_remove_card() only drops the OF node reference for a present card, leaking the reference on this error path.
Move of_node_put() outside the present-card conditional so the reference is released for both registered cards and card-add failures.
--- drivers/mmc/core/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/core/bus.c +1 -1
@@ -397,8 +397,8 @@ void mmc_remove_card(struct mmc_card *ca mmc_hostname(card->host), card->rca); }device_del (&card->dev); -of_node_put (card->dev.of_node); } +of_node_put (card->dev.of_node);if (host->cqe_enabled) { host->cqe_ops->cqe_disable (host);
Greg Kroah-Hartman
maintainerPATCH 885/1193 mmc: hsq: Fix use-after-free in retry work
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 5d132990475f02cfa1debe03d50b479432864ebd upstream.
mmc_hsq_pump_requests() queues retry_work when request_atomic() returns -EBUSY; today sdhci-sprd is the only consumer that implements request_atomic(). The work is embedded in a devm-allocated mmc_hsq, but is never cancelled during driver removal. Work still pending at unbind can therefore run after the devm allocation has been released and dereference hsq->mmc and hsq->mrq.
Use devm_work_autocancel() to cancel and drain retry_work before the devm allocation is released. By the time devres cleanup begins, mmc_remove_host() has already stopped the host, so no new requests can arm the work.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mmc_hsq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/mmc/host/mmc_hsq.c +7 -1
@@ -7,6 +7,7 @@* Author: Baolin Wang <[email protected]> */ +#include <linux/devm-helpers.h> #include <linux/mmc/card.h> #include <linux/mmc/host.h> #include <linux/module.h>
@@ -324,6 +325,7 @@ static const struct mmc_cqe_ops mmc_hsq_int mmc_hsq_init (struct mmc_hsq *hsq,struct mmc_host *mmc) { +int ret;int i; hsq->num_slots =HSQ_NUM_SLOTS ; hsq->next_tag =HSQ_INVALID_TAG ;
@@ -341,7 +343,11 @@ int mmc_hsq_init(struct mmc_hsq *hsq, stfor (i =0 ; i <HSQ_NUM_SLOTS ; i++) hsq->tag_slot[i] =HSQ_INVALID_TAG ; -INIT_WORK (&hsq->retry_work, mmc_hsq_retry_handler); + ret =devm_work_autocancel (mmc_dev (mmc), &hsq->retry_work, + mmc_hsq_retry_handler); +if (ret) +return ret; +spin_lock_init (&hsq->lock);init_waitqueue_head (&hsq->wait_queue);
Greg Kroah-Hartman
maintainerPATCH 886/1193 mmc: mxcmmc: cancel data work and watchdog on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit d3a421c82412344022982d5b91ba23194a0a6f29 upstream.
mxcmci_remove() frees the host through the devm tail, but neither it nor mmc_remove_host() drains the driver's own asynchronous state. host->watchdog, a 10 s timer armed on the DMA path in mxcmci_setup_data(), is deleted only by the DMA- and IRQ-complete paths, which the remove path does not explicitly drain; it can therefore fire after the host is freed and dereference it in mxcmci_watchdog(). host->datawork, armed from the IRQ handler on the PIO path, is not cancelled by the remove path either.
Free the devm-registered IRQ, then cancel datawork and delete the watchdog in mxcmci_remove(), before dma_release_channel(). Freeing the IRQ first keeps a trailing handler from re-arming datawork between the cancel and the host free. Both callbacks are non-self-rearming.
This issue was found by an in-house static analysis tool.
--- drivers/mmc/host/mxcmmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/host/mxcmmc.c +4 -0
@@ -1169,6 +1169,10 @@ static void mxcmci_remove(struct platformmc_remove_host (mmc); +devm_free_irq (&pdev->dev,platform_get_irq (pdev,0 ), host); +cancel_work_sync (&host->datawork); +timer_delete_sync (&host->watchdog); +if (host->pdata && host->pdata->exit) host->pdata->exit (&pdev->dev, mmc);
Greg Kroah-Hartman
maintainerPATCH 887/1193 mmc: rtsx_pci_sdmmc: ignore broken write-protect on ThinkPad X260
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Maillard <[email protected]>
commit 9c182bc5d7817437a7d04ab96133f9191846d93d upstream.
The Realtek RTS522A card reader in the Lenovo ThinkPad X260 (subsystem 17aa:504a) incorrectly reports inserted SD cards as write-protected.
This causes the MMC core to expose the card as read-only:
mmcblk0: mmc0:aaaa SN256 238 GiB (ro)
and /sys/block/mmcblk0/ro reports 1.
Setting MMC_CAP2_NO_WRITE_PROTECT makes the card writable again. Limit the quirk to the affected Lenovo subsystem.
--- drivers/mmc/host/rtsx_pci_sdmmc.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mmc/host/rtsx_pci_sdmmc.c +5 -0
@@ -1488,6 +1488,11 @@ static void realtek_init_host(struct rea mmc->caps = mmc->caps |MMC_CAP_AGGRESSIVE_PM ; mmc->caps2 =MMC_CAP2_NO_PRESCAN_POWERUP |MMC_CAP2_FULL_PWR_CYCLE |MMC_CAP2_NO_SDIO ; + +if (pcr->pci->device ==0x522a && + pcr->pci->subsystem_vendor ==PCI_VENDOR_ID_LENOVO && + pcr->pci->subsystem_device ==0x504a ) + mmc->caps2 |=MMC_CAP2_NO_WRITE_PROTECT ; mmc->max_current_330 =400 ; mmc->max_current_180 =800 ; mmc->ops = &realtek_pci_sdmmc_ops;
Greg Kroah-Hartman
maintainerPATCH 888/1193 mmc: sdhci-of-aspeed: Remove children before releasing SDC resources
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 4396d70bb7fec531bcf934fed016b2f3300c670b upstream.
Probe failure and removal leave SDHCI child devices registered after the parent clock and managed resources are released.
Unregister the OF children in reverse order before disabling the parent clock on both paths. Use of_platform_device_destroy() because manual child creation does not set the flag required by of_platform_depopulate().
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/mmc/host/sdhci-of-aspeed.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-of-aspeed.c +4 -1
@@ -561,12 +561,14 @@ static int aspeed_sdc_probe(struct platfif (!cpdev) {of_node_put (child); ret = -ENODEV ; - goto err_clk; + goto err_children; } }return 0 ; +err_children: +device_for_each_child_reverse (&pdev->dev,NULL , of_platform_device_destroy); err_clk:clk_disable_unprepare (sdc->clk);return ret;
@@ -576,6 +578,7 @@ static void aspeed_sdc_remove(struct pla {struct aspeed_sdc *sdc =dev_get_drvdata (&pdev->dev); +device_for_each_child_reverse (&pdev->dev,NULL , of_platform_device_destroy);clk_disable_unprepare (sdc->clk); }
Greg Kroah-Hartman
maintainerPATCH 889/1193 mmc: sdio_uart: fix xmit_fifo leak when the port table is full
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Felix Gu <[email protected]>
commit 53823e25793a97d07e6e98e0904bbf74cac8bc76 upstream.
sdio_uart_add_port() allocates the transmit fifo before claiming a slot in sdio_uart_table[]. When all UART_NR slots are taken, it returns -EBUSY with the fifo still allocated, but the probe error path only kfree()s the port, leaking the transmit fifo.
Free the fifo in the failure path of sdio_uart_add_port() itself so the function retains nothing on error.
--- drivers/mmc/core/sdio_uart.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mmc/core/sdio_uart.c +3 -0
@@ -104,6 +104,9 @@ static int sdio_uart_add_port(struct sdi }spin_unlock (&sdio_uart_table_lock); +if (ret) +kfifo_free (&port->xmit_fifo); +return ret; }
Greg Kroah-Hartman
maintainerPATCH 890/1193 mmc: sh_mmcif: initialize IRQ-thread mutex before requesting interrupt
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit d5ea0d226e8f0801d78702142a124d78c317d822 upstream.
The threaded IRQ handler can run before devm_request_threaded_irq() returns, but thread_lock was initialized afterwards. Initialize it before requesting either interrupt.
--- drivers/mmc/host/sh_mmcif.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/mmc/host/sh_mmcif.c +1 -2
@@ -1423,6 +1423,7 @@ static int sh_mmcif_probe(struct platfor host->pd = pdev;spin_lock_init (&host->lock); +mutex_init (&host->thread_lock); mmc->ops = &sh_mmcif_ops;sh_mmcif_init_ocr (host);
@@ -1483,8 +1484,6 @@ static int sh_mmcif_probe(struct platfor } } -mutex_init (&host->thread_lock); - ret =mmc_add_host (mmc);if (ret <0 ) goto err_clk;
Greg Kroah-Hartman
maintainerPATCH 891/1193 mmc: spi: reset bytes_xfered before retrying CRC failures
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 8b0cc8707f65e0f51912e764e1b309b2559db1ec upstream.
mmc_spi_data_do() updates data->bytes_xfered after each block has been transferred successfully. If a later block in the same data request fails with a CRC error, data->bytes_xfered may therefore contain the number of bytes completed before the failing block.
mmc_spi_request() has a private recovery path for such CRC failures. It sends STOP_TRANSMISSION, clears data->error and jumps back to crc_recover to issue the same command and data request again. However, it does not clear data->bytes_xfered before the retry.
If the retry succeeds, the request is completed with the bytes from the failed attempt still included in data->bytes_xfered. For a multi-block request this can make the completed request report more bytes than were transferred by the successful retry, and can even exceed the request size when most blocks completed before the CRC error.
This is most likely to be observed on MMC-over-SPI systems where long multi-block transfers occasionally hit a data CRC error but the mmc_spi-internal retry succeeds. The data itself is retried, but the completion accounting is not.
Clear data->bytes_xfered together with data->error before repeating the request so the final completion reports only the bytes transferred by the successful attempt.
--- drivers/mmc/host/mmc_spi.c | 1 + 1 file changed, 1 insertion(+)
drivers/mmc/host/mmc_spi.c +1 -0
@@ -954,6 +954,7 @@ crc_recover: status =mmc_spi_command_send (host, mrq, &stop,0 ); crc_retry--; mrq->data->error =0 ; + mrq->data->bytes_xfered =0 ; goto crc_recover; }
Greg Kroah-Hartman
maintainerPATCH 856/1193 dmaengine: sun6i: fix non-atomic read of DMA position registers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Lugnberg <[email protected]>
commit c90b6973daa37f4c283342dff881ae001dea4fe6 upstream.
sun6i_get_chan_size() reads DMA_CHAN_LLI_ADDR and DMA_CHAN_CUR_CNT in two separate readl() calls with no synchronisation between them:
pos = readl(pchan->base + DMA_CHAN_LLI_ADDR);
bytes = readl(pchan->base + DMA_CHAN_CUR_CNT);DMA_CHAN_LLI_ADDR holds the physical address of the *next* descriptor the engine will load once the current one completes. DMA_CHAN_CUR_CNT holds the remaining byte count for the *current* descriptor. If the DMA engine advances to the next LLI entry between the two reads, pos becomes stale: it still points to what was the next descriptor at the time of the first read, but that descriptor is now the current one and CUR_CNT reflects its initial (full) byte count. The subsequent virtual-chain walk starts one entry too early and accumulates an extra full period's worth of bytes into the residue estimate.
Fix this by re-reading DMA_CHAN_LLI_ADDR after DMA_CHAN_CUR_CNT and retrying if the value changed. This double-read pattern guarantees that both registers were sampled during the same descriptor interval. The cost is at most one extra readl() pair per call in the racy case, which occurs only at descriptor boundaries (~every 2 ms) and is negligible.
--- drivers/dma/sun6i-dma.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/dma/sun6i-dma.c +4 -2
@@ -353,8 +353,10 @@ static size_t sun6i_get_chan_size(structsize_t bytes;dma_addr_t pos; - pos =readl (pchan->base +DMA_CHAN_LLI_ADDR ); - bytes =readl (pchan->base +DMA_CHAN_CUR_CNT ); +do { + pos =readl (pchan->base +DMA_CHAN_LLI_ADDR ); + bytes =readl (pchan->base +DMA_CHAN_CUR_CNT ); + }while (pos !=readl (pchan->base +DMA_CHAN_LLI_ADDR ));if (pos ==LLI_LAST_ITEM )return bytes;
Greg Kroah-Hartman
maintainerPATCH 892/1193 mmc: sdhci_am654: Reset command and data lines on failed tuning
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diogo Ivo (Schneider Electric) <[email protected]>
commit 7197d9107d9545730153b82ea5a411c5208b443f upstream.
The CMD/DATA reset after tuning should be performed regardless of whether tuning succeeded or failed, since tuning data may remain in the buffer in either case. Move the error return after the reset so that the controller is always cleaned up.
--- drivers/mmc/host/sdhci_am654.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mmc/host/sdhci_am654.c +1 -3
@@ -416,15 +416,13 @@ static int sdhci_am654_execute_tuning(ststruct sdhci_host *host =mmc_priv (mmc);int err =sdhci_execute_tuning (mmc, opcode); -if (err) -return err;/* * Tuning data remains in the buffer after tuning. * Do a command and data reset to get rid of it */ sdhci_reset (host,SDHCI_RESET_CMD |SDHCI_RESET_DATA ); -return 0 ; +return err; }static u32 sdhci_am654_cqhci_irq (struct sdhci_host *host,u32 intmask)
Greg Kroah-Hartman
maintainerPATCH 893/1193 Input: adp5588-keys - cache GPIO state before registering the gpiochip
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alvin Šipraga <[email protected]>
commit 21efadc62272cabee9bec27777ae75d84a9ca8a8 upstream.
So as not to clobber any pre-programmed GPIO state in the execution of its gpiochip ops, the driver caches things during probe time. However, since those ops can be called both during and immediately after the call to devm_gpiochip_add_data(), it is imperative that things are cached before that. That's not the case right now, so reorder the two steps to prevent any clobbering.
In the concrete example which motivated this change, a bootloader was preconfiguring an important GPIO output to HIGH before booting the kernel. Linux would then inadvertently set that output to LOW while configuring a GPIO hog on a discrete GPIO line within the same 8-bit bank (because the cached value was 0=LOW).
--- drivers/input/keyboard/adp5588-keys.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/input/keyboard/adp5588-keys.c +6 -6
@@ -453,12 +453,6 @@ static int adp5588_gpio_add(struct adp55mutex_init (&kpad->gpio_lock); - error =devm_gpiochip_add_data (dev, &kpad->gc, kpad); -if (error) { -dev_err (dev,"gpiochip_add failed: %d\n" , error); -return error; - } -for (i =0 ; i <=ADP5588_BANK (ADP5588_MAXGPIO ); i++) { kpad->dat_out[i] =adp5588_read (kpad->client,GPIO_DAT_OUT1 + i);
@@ -466,6 +460,12 @@ static int adp5588_gpio_add(struct adp55 kpad->pull_dis[i] =adp5588_read (kpad->client,GPIO_PULL1 + i); } + error =devm_gpiochip_add_data (dev, &kpad->gc, kpad); +if (error) { +dev_err (dev,"gpiochip_add failed: %d\n" , error); +return error; + } +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 894/1193 Input: atkbd - skip deactivate for Xiaomi Redmi Book Pro 16 2026
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Turtanov <[email protected]>
commit aefbda23eeba234c3ff0f135dc5be6e294bd25a6 upstream.
The internal keyboard of the Xiaomi Redmi Book Pro 16 2026 (board TM2425) does not work: atkbd_probe() succeeds and every command is ACKed, but no scancodes ever arrive afterwards.
Testing on the hardware through serio_raw shows that ATKBD_CMD_RESET_DIS (0xF5) is the culprit. After 0xF5 the embedded controller keeps ACKing commands but stops delivering scancodes, and neither ATKBD_CMD_ENABLE (0xF4) nor ATKBD_CMD_RESET_BAT (0xFF) bring them back. Only re-enabling the keyboard interface at the controller level (i8042 command 0xAE, or rewriting the command byte as i8042_port_close() does) revives it. Running the init sequence without 0xF5 (0xED 0x00, 0xF3 0x00, 0xF4) keeps the keyboard working.
'i8042.dumbkbd=1' also works around this, but then the driver never writes to the keyboard and the LEDs cannot be controlled. Use the existing atkbd_deactivate_fixup quirk instead, as done for the sibling TM2424 by commit 3a046db33bb9 ("Input: atkbd - skip deactivate for Xiaomi Book Pro 14's internal keyboard"). Tested on v7.2: keyboard, Caps Lock LED and s2idle suspend/resume all work.
DMI: XIAOMI REDMI Book Pro 16 2026/TM2425, BIOS RMAPT6B0P0909 05/22/2026
--- drivers/input/keyboard/atkbd.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/input/keyboard/atkbd.c +8 -0
@@ -1982,6 +1982,14 @@ static const struct dmi_system_id atkbd_ }, .callback = atkbd_deactivate_fixup, }, + { + /* Xiaomi Redmi Book Pro 16 2026 (TM2425) */ + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "XIAOMI"), + DMI_MATCH(DMI_PRODUCT_NAME, "REDMI Book Pro 16 2026"), + }, + .callback = atkbd_deactivate_fixup, + }, { } };
Greg Kroah-Hartman
maintainerPATCH 895/1193 Input: cyttsp5 - clamp the HID report size before memcpy
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 85f080fb87ed5cd3e46121be677f52c82f26a0ab upstream.
The size field comes from the device and is used as the memcpy() length into response_buf, which is CY_MAX_INPUT bytes.
--- drivers/input/touchscreen/cyttsp5.c | 1 + 1 file changed, 1 insertion(+)
drivers/input/touchscreen/cyttsp5.c +1 -0
@@ -711,6 +711,7 @@ static irqreturn_t cyttsp5_handle_irq(in size =2 ; }else { report_id = ts->input_buf[2 ]; + size =min (size,CY_MAX_INPUT ); }switch (report_id) {
Greg Kroah-Hartman
maintainerPATCH 896/1193 Input: evdev - zero absinfo before partial copy in EVIOCSABS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit 8b852965b8eaf910c314dc346967ed82c8d4f235 upstream.
The EVIOCSABS handler copies at most the user supplied ioctl size into an uninitialized on-stack struct input_absinfo:
if (copy_from_user(&abs, p, min_t(size_t, size, sizeof(struct input_absinfo))))
The size comes from _IOC_SIZE() of the ioctl command and is therefore fully controlled by userspace. A short size leaves the trailing part of the structure holding whatever was on the kernel stack, and the whole structure is then stored into the device:
dev->absinfo[t] = abs;
EVIOCGABS hands that back to userspace, disclosing the stale stack bytes. Only the resolution field is currently cleared, which covers the legacy struct layout but not an arbitrarily short size.
Zero the structure before the copy so any part not supplied by the caller reads back as zero. The existing resolution fixup is kept, since it also handles a size that partially overlaps that field.
--- drivers/input/evdev.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/evdev.c +2 -0
@@ -1231,6 +1231,8 @@ static long evdev_do_ioctl(struct file * t =_IOC_NR (cmd) &ABS_MAX ; +memset (&abs,0 ,sizeof (abs)); +if (copy_from_user (&abs, p,min_t (size_t, size,sizeof (struct input_absinfo ))))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 897/1193 Input: i8042 - add quirk for Acer Aspire Go 15 AG15-42P
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chris Sommers <[email protected]>
commit 25e424eb4ae1a662d9c3573218d06ac32f797fc5 upstream.
On the Acer Aspire Go 15 (AG15-42P), the internal keyboard drops out ~5 seconds after boot on both Linux and Linux-LTS kernels. Keystrokes on the built-in keyboard stop registering while the trackpad and external keyboards remain functional.
Testing confirms that booting with the i8042.reset kernel parameter resolves the issue and keeps the internal keyboard responsive.
Add SERIO_QUIRK_RESET_ALWAYS to i8042_dmi_quirk_table for the Acer Aspire AG15-42P to automatically apply this quirk on boot.
--- drivers/input/serio/i8042-acpipnpio.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/input/serio/i8042-acpipnpio.h +7 -0
@@ -261,6 +261,13 @@ static const struct dmi_system_id i8042_ { .matches = {DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), + DMI_MATCH(DMI_PRODUCT_NAME, "Aspire AG15-42P"), + }, + .driver_data = (void *)(SERIO_QUIRK_RESET_ALWAYS ) + }, + { + .matches = { +DMI_MATCH (DMI_SYS_VENDOR ,"Acer" ), DMI_MATCH(DMI_PRODUCT_NAME, "Aspire ES1-132"), }, .driver_data = (void *)(SERIO_QUIRK_RESET_ALWAYS )
Greg Kroah-Hartman
maintainerPATCH 898/1193 Input: rmi_smbus - fix out-of-bounds read in rmi_smb_write_block()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit 51cfe54f815ae175c7d1126b983d4d7c89715004 upstream.
When chunking writes into SMBus blocks in rmi_smb_write_block(), the loop calculates block_len using the original total length (len) instead of the remaining length (cur_len).
If len is greater than 32 bytes (SMB_MAX_COUNT), block_len remains 32 for every iteration, even on the final partial chunk where fewer than 32 bytes remain. This causes smb_block_write() to read 32 bytes from the advanced data buffer pointer, reading past the end of the input buffer.
Fix this by calculating block_len using cur_len and advancing the buffer and address pointers by block_len.
--- drivers/input/rmi4/rmi_smbus.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/input/rmi4/rmi_smbus.c +5 -5
@@ -140,7 +140,7 @@ static int rmi_smb_write_block(struct rmu8 commandcode;struct rmi_smb_xport *rmi_smb = container_of(xport, struct rmi_smb_xport, xport); -int cur_len = (int )len; +size_t cur_len = len;mutex_lock (&rmi_smb->page_mutex);
@@ -148,7 +148,7 @@ static int rmi_smb_write_block(struct rm/* * break into 32 bytes chunks to write get command code */ -int block_len =min_t (int, len,SMB_MAX_COUNT ); +int block_len =min_t (size_t, cur_len,SMB_MAX_COUNT ); retval =rmi_smb_get_command_code (xport, rmiaddr, block_len, false, &commandcode);
@@ -161,9 +161,9 @@ static int rmi_smb_write_block(struct rm goto exit;/* prepare to write next block of bytes */ - cur_len -=SMB_MAX_COUNT ; - databuff +=SMB_MAX_COUNT ; - rmiaddr +=SMB_MAX_COUNT ; + cur_len -= block_len; + databuff += block_len; + rmiaddr += block_len; } exit:mutex_unlock (&rmi_smb->page_mutex);
Greg Kroah-Hartman
maintainerPATCH 899/1193 Input: soc_button_array - fix MS Surface Pro 11 probe failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit ed22ad5fdbdbf9b4cb4ad3003f60314b5a5eb89d upstream.
On the MS Surface Pro 11 soc_button_array probing races with the GPIO driver probing. If soc_button_array wins the race then gpiod_get() returns EPROBE_DEFER, which should normally take care of retrying later, but the soc_button_array code deliberately ignores EPROBE_DEFER causing it to fail its probe() which causes the volume and power buttons to now work.
The ignoring of EPROBE_DEFER is there to deal with a problem specific to older Bay Trail (BYT) and Cherry Trail (CHT) tablets which often use this driver. Modify the error handling to only ignore EPROBE_DEFER on BYT and CHT platforms and propagate EPROBE_DEFER normally on other platforms.
--- drivers/input/misc/soc_button_array.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
drivers/input/misc/soc_button_array.c +11 -3
@@ -16,6 +16,7 @@#include <linux/gpio/consumer.h> #include <linux/gpio_keys.h> #include <linux/gpio.h> +#include <linux/platform_data/x86/soc.h> #include <linux/platform_device.h> static bool use_low_level_irq;
@@ -160,7 +161,7 @@ soc_button_device_create(struct platformstruct gpio_keys_platform_data *gpio_keys_pdata;const struct dmi_system_id *dmi_id;int invalid_acpi_index =-1 ; -int error, gpio, irq; +int error, gpio, irq =0 ;int n_buttons =0 ;for (info = button_info; info->name; info++)
@@ -191,8 +192,9 @@ soc_button_device_create(struct platform error =soc_button_lookup_gpio (&pdev->dev, info->acpi_index, &gpio, &irq);if (error || irq <0 ) {/* -* Skip GPIO if not present. Note we deliberately -* ignore -EPROBE_DEFER errors here. On some devices +* Propagate -EPROBE_DEFER, skip button on other errors. +* +* -EPROBE_DEFER is ignored on Bay & Cherry Trail. Here * Intel is using so called virtual GPIOs which are not * GPIOs at all but some way for AML code to check some * random status bits without need a custom opregion.
@@ -201,6 +203,12 @@ soc_button_device_create(struct platform* we do not have a driver for these so they will never * show up, therefore we ignore -EPROBE_DEFER. */ +if ((error == -EPROBE_DEFER || irq == -EPROBE_DEFER ) && + !(soc_intel_is_byt () ||soc_intel_is_cht ())) { + error = -EPROBE_DEFER ; + goto err_free_mem; + } +continue ; }
Greg Kroah-Hartman
maintainerPATCH 857/1193 dmaengine: sun6i: fix undefined behaviour in sun6i_dma_tx_status
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Lugnberg <[email protected]>
commit 9096bdc8d930147f7c39a493a859acbd3a8485d8 upstream.
sun6i_dma_tx_status() calls vchan_find_desc() to look up the virtual descriptor for a given cookie, before checking whether the pointer vd is NULL:
vd = vchan_find_desc(&vchan->vc, cookie);
txd = to_sun6i_desc(&vd->tx); /* vd may be NULL here */
if (vd) {
for (lli = txd->v_lli; ...)vchan_find_desc() returns NULL when the descriptor has already been completed or is in-flight on a physical channel and no longer present in the virtual channel's descriptor list. When vd is NULL, to_sun6i_desc() is called unconditionally on &vd->tx before the NULL check, which is undefined behaviour. Move the call inside the if (vd) guard to ensure it is only reached with a valid pointer.
vd = vchan_find_desc(&vchan->vc, cookie);
if (vd) {
struct sun6i_desc *txd = to_sun6i_desc(&vd->tx);
for (lli = txd->v_lli; ...)--- drivers/dma/sun6i-dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/dma/sun6i-dma.c +1 -2
@@ -970,7 +970,6 @@ static enum dma_status sun6i_dma_tx_statstruct sun6i_pchan *pchan = vchan->phy;struct sun6i_dma_lli *lli;struct virt_dma_desc *vd; -struct sun6i_desc *txd;enum dma_status ret;unsigned long flags;size_t bytes =0 ;
@@ -982,9 +981,9 @@ static enum dma_status sun6i_dma_tx_statspin_lock_irqsave (&vchan->vc.lock, flags); vd =vchan_find_desc (&vchan->vc, cookie); - txd =to_sun6i_desc (&vd->tx);if (vd) { +struct sun6i_desc *txd =to_sun6i_desc (&vd->tx);for (lli = txd->v_lli; lli !=NULL ; lli = lli->v_lli_next) bytes += lli->len; }else if (!pchan || !pchan->desc) {
Greg Kroah-Hartman
maintainerPATCH 858/1193 dmaengine: ti: k3-udma-glue: fix NULL dereference in k3_udma_glue_release_rx_chn()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Chesnokov <[email protected]>
commit 0294b6dd515256c03ea2dbf508ddd3826d788579 upstream.
If devm_kcalloc() for rx_chn->flows fails in a channel request function, the error path calls k3_udma_glue_release_rx_chn(), which dereferences the NULL rx_chn->flows pointer in k3_udma_glue_release_rx_flow().
Skip the flow release loop in k3_udma_glue_release_rx_chn() when rx_chn->flows is not allocated.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/dma/ti/k3-udma-glue.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/dma/ti/k3-udma-glue.c +3 -2
@@ -1107,8 +1107,9 @@ void k3_udma_glue_release_rx_chn(struct rx_chn->psil_paired = false; } -for (i =0 ; i < rx_chn->flow_num; i++) -k3_udma_glue_release_rx_flow (rx_chn, i); +if (rx_chn->flows) +for (i =0 ; i < rx_chn->flow_num; i++) +k3_udma_glue_release_rx_flow (rx_chn, i);if (xudma_rflow_is_gp (rx_chn->common.udmax, rx_chn->flow_id_base)) xudma_free_gp_rflow_range(rx_chn->common.udmax,
Greg Kroah-Hartman
maintainerPATCH 859/1193 ipv6: xfrm: use full sockets in local error paths
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
commit 6973a21ee73c5567f883813c8ef414774b45892f upstream.
xfrm6_local_rxpmtu() and xfrm6_local_error() dereference skb->sk as if it always pointed at a full IPv6 socket.
That is not guaranteed. TCP SYN-ACK skbs can be owned by a TCP_NEW_SYN_RECV request_sock while the output path itself is driven by the full listener. If rerouting selects an IPv6 XFRM tunnel route with a lower MTU, the local PMTU/error handling path can reach these callbacks with that mini-socket still attached to the skb.
The callbacks then miscast the request socket as a full inet/IPv6 socket and can read beyond the request_sock allocation when they access inet_sock or ipv6_pinfo state.
Resolve the owner with skb_to_full_sk() in both callbacks and bail out when no full socket is attached. This matches the surrounding XFRM IPv6 PMTU/error logic, which already reasons about full sockets with skb_to_full_sk().
--- net/ipv6/xfrm6_output.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
net/ipv6/xfrm6_output.c +8 -2
@@ -19,7 +19,10 @@void xfrm6_local_rxpmtu (struct sk_buff *skb,u32 mtu) {struct flowi6 fl6; -struct sock *sk = skb->sk; +struct sock *sk =skb_to_full_sk (skb); + +if (!sk) +return ; fl6.flowi6_oif = sk->sk_bound_dev_if; fl6.daddr =ipv6_hdr (skb)->daddr;
@@ -31,7 +34,10 @@ void xfrm6_local_error(struct sk_buff *s {struct flowi6 fl6;const struct ipv6hdr *hdr; -struct sock *sk = skb->sk; +struct sock *sk =skb_to_full_sk (skb); + +if (!sk) +return ; hdr = skb->encapsulation ?inner_ipv6_hdr (skb) :ipv6_hdr (skb); fl6.fl6_dport =inet_sk (sk)->inet_dport;
Greg Kroah-Hartman
maintainerPATCH 860/1193 net: lan743x: fix RX checksum use-after-free
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Amirkan <[email protected]>
commit a9ce4053dc945c5372dedba5017ee675b30dc0c5 upstream.
lan743x_rx_process_buffer() adds each non-first receive buffer to the head skb's frag_list. On the last descriptor, lan743x_rx_trim_skb() linearizes the head and frees the fragment skb metadata.
The checksum-success path then writes ip_summed through the local skb pointer, which still points to the final fragment. This causes a use-after-free write when a packet spans more than one receive buffer.
Set ip_summed on the surviving head skb instead. Multi-buffer receive can occur after a live MTU increase because existing ring entries keep their old buffer size until they are replenished.
A KUnit test invoking lan743x_rx_process_buffer() with a two-buffer packet produced a one-byte KASAN use-after-free write before this change. The same test passed after the change. The driver object also builds with W=1. This was not tested on physical LAN743x hardware.
--- drivers/net/ethernet/microchip/lan743x_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/microchip/lan743x_main.c +1 -1
@@ -2726,7 +2726,7 @@ process_extension: rx->adapter->netdev);if (rx->adapter->netdev->features &NETIF_F_RXCSUM ) {if (!is_ice && !is_tce && !is_icsm) - skb->ip_summed =CHECKSUM_UNNECESSARY ; + rx->skb_head->ip_summed =CHECKSUM_UNNECESSARY ; }netdev_dbg (netdev,"sending %d byte frame to OS" , rx->skb_head->len);
Greg Kroah-Hartman
maintainerPATCH 861/1193 net: wwan: t7xx: validate the netif index in t7xx_ccmni_recv_skb()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanglei Zhu <[email protected]>
commit c7ead9704249d57d4693a04697e3bbd285138fa9 upstream.
The netif index carried in the DPMAIF PIT header is five bits wide, but ccmni_inst[] only has room for NIC_DEV_MAX (21) entries. t7xx_ccmni_recv_skb() indexes the array without a bounds check, so indexes 21 to 31 read past it. The out-of-bounds value lands in the callback table that follows the array, which is never NULL, so the existing !ccmni check does not catch it and the driver dereferences whatever sits there as a struct t7xx_ccmni.
Drop the skb when the index is out of range.
Verified in a QEMU guest with a fault injector setting the netif index to 25: the unpatched driver reads a value past ccmni_inst[], which lands in the callback table, and dereferences it far enough to queue the skb. With this check the packet is dropped. Well-formed traffic on index 0 is unaffected.
Changes in v2: none.
--- drivers/net/wwan/t7xx/t7xx_netdev.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wwan/t7xx/t7xx_netdev.c +4 -0
@@ -414,6 +414,10 @@ static void t7xx_ccmni_recv_skb(struct t skb_cb =T7XX_SKB_CB (skb); netif_id = skb_cb->netif_idx; +if (netif_id >=NIC_DEV_MAX ) { +dev_kfree_skb (skb); +return ; + } ccmni =READ_ONCE (ccmni_ctlb->ccmni_inst[netif_id]);if (!ccmni) {dev_kfree_skb (skb);
Greg Kroah-Hartman
maintainerPATCH 852/1193 Bluetooth: btusb: fix NXP IW610 composite device handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Thibert <[email protected]>
commit 2b50adefed9808a56d84d1de803cad882cc787fa upstream.
The NXP IW610 module exposes itself as a composite USB device (0471:0215) with three interfaces: two real Bluetooth HCI interfaces (class 0xe0) and one vendor-specific WiFi interface (class 0xff) used by mwifiex-nxp.
The composite device's whole USB descriptor reports class 0xe0/01/01 (Bluetooth), so btusb_table's generic USB_DEVICE_INFO(0xe0, 0x01, 0x01) entry matches every interface, not just the two real HCI ones -- btusb ends up binding the WiFi interface too, and mwifiex-nxp never gets it.
Fix:
1. In btusb_table (the table the USB core actually matches against), explicitly ignore the WiFi interface via BTUSB_IGNORE, ahead of the generic entry.
2. In quirks_table, scope the existing BTUSB_MARVELL entry to the BT interface class instead of matching the whole device by VID/PID (harmless either way since quirks_table isn't consulted for initial binding, but keep it correct).
Not upstream anywhere: checked NXP's own i.MX kernel fork (nxp-imx/linux-imx), no IW610 references in btusb.c on any branch -- their reference designs wire this chip differently (WiFi over SDIO per their release notes), so they never hit this.
--- drivers/bluetooth/btusb.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/bluetooth/btusb.c +17 -0
@@ -68,6 +68,15 @@ static struct usb_driver btusb_driver;#define BTUSB_BARROT BIT(28)static const struct usb_device_id btusb_table[] = { +/* +* NXP IW610 (0471:0215): the composite device reports Bluetooth +* class at the whole-device level, so the generic entry below +* would also match this WiFi vendor interface. Ignore it here +* first so mwifiex-nxp can bind it instead. +*/ + {USB_DEVICE_AND_INTERFACE_INFO (0x0471 ,0x0215 ,0xff ,0xff ,0xff ), + .driver_info =BTUSB_IGNORE }, +/* Generic Bluetooth USB device */ {USB_DEVICE_INFO (0xe0 ,0x01 ,0x01 ) },
@@ -470,6 +479,14 @@ static const struct usb_device_id quirks { USB_DEVICE(0x1286, 0x2046), .driver_info = BTUSB_MARVELL }, { USB_DEVICE(0x1286, 0x204e), .driver_info = BTUSB_MARVELL }, +/* +* NXP IW610 BT interfaces (Marvell-lineage silicon, same quirk as +* the 0x1286 entries above). Scoped to the BT interface class, +* not just VID/PID -- see the btusb_table entry above. +*/ + { USB_DEVICE_AND_INTERFACE_INFO(0x0471, 0x0215, 0xe0, 0x01, 0x01), + .driver_info = BTUSB_MARVELL }, +/* Intel Bluetooth devices */ { USB_DEVICE(0x8087, 0x0025), .driver_info = BTUSB_INTEL_COMBINED }, { USB_DEVICE(0x8087, 0x0026), .driver_info = BTUSB_INTEL_COMBINED },
Greg Kroah-Hartman
maintainerPATCH 901/1193 Input: synaptics - disable InterTouch on ThinkPad T440p (board id 2722)
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Raphaël Larocque <[email protected]>
commit 26eb3d92c7a4d7adb1ae1740ca6e8e100b11d1ec upstream.
The Lenovo ThinkPad T440p (PNP ID LEN0036, board id 2722) has a Synaptics touchpad whose SMBus companion is not ready at boot and takes roughly 200 seconds to appear. During this window the touchpad and TrackPoint are completely unresponsive on approximately 50% of boots, making the machine unusable until the companion finally registers.
The device is in the topbuttonpad_pnp_ids[] SMBus allowlist, so the kernel attempts to use SMBus/RMI4 mode by default. When the companion is not ready, psmouse_smbus_init() leaves breadcrumbs and returns -EAGAIN, the PS/2 fallback path is taken, but the device does not function properly until the companion appears and RMI4 takes over.
Disable SMBus InterTouch for board id 2722 so the touchpad and TrackPoint work immediately via PS/2 from boot. Users can still force SMBus with psmouse.synaptics_intertouch=1 if needed.
--- drivers/input/mouse/synaptics.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/input/mouse/synaptics.c +8 -0
@@ -1837,6 +1837,14 @@ static int synaptics_setup_intertouch(streturn -ENXIO ; } + +/* Disable intertouch on known-broken board revisions */ +if (info->board_id ==2722 ) { +psmouse_info (psmouse, +"Disabling intertouch for board id %u\n" , + info->board_id); +return -ENXIO ; + } }psmouse_info (psmouse,"Trying to set up SMBus access\n" );
Greg Kroah-Hartman
maintainerPATCH 910/1193 watchdog: da9063: fix suspend/resume handling of HW_RUNNING watchdog
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Jun <[email protected]>
commit 7cb575b71ab98194d2e040bded3a7281e089c5ed upstream.
da9063_wdt_suspend() and da9063_wdt_resume() only check watchdog_active(), when the watchdog is left running by the driver sets WDOG_HW_RUNNING in da9063_wdt_probe() but userspace never opens the device, so WDOG_ACTIVE remains cleared, the wdt_disable() will not be executed in da9063_wdt_suspend. In this case, the suspend callback is a no-op and the watchdog keeps counting during system suspend, leading to an unexpected system reset.
Check WDOG_HW_RUNNING and wdd,can fix this issue.
--- drivers/watchdog/da9063_wdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/watchdog/da9063_wdt.c +2 -2
@@ -271,7 +271,7 @@ static int __maybe_unused da9063_wdt_susif (!use_sw_pm)return 0 ; -if (watchdog_active (wdd)) +if (watchdog_active (wdd) ||watchdog_hw_running (wdd))return da9063_wdt_stop (wdd);return 0 ;
@@ -284,7 +284,7 @@ static int __maybe_unused da9063_wdt_resif (!use_sw_pm)return 0 ; -if (watchdog_active (wdd)) +if (watchdog_active (wdd) ||watchdog_hw_running (wdd))return da9063_wdt_start (wdd);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 911/1193 watchdog: digicolor: Avoid division by zero
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 400cb663ca019bae6eb878f06f1094ddf7c0b0df upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
Since get_timeleft() cannot propagate errors, check the clock rate early in probe() and cache the rate in the driver data as it is unlikely to change at runtime.
--- drivers/watchdog/digicolor_wdt.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/watchdog/digicolor_wdt.c +9 -4
@@ -25,6 +25,7 @@ struct dc_wdt {void __iomem *base;struct clk *clk;spinlock_t lock; +unsigned long rate; };static unsigned timeout;
@@ -61,7 +62,7 @@ static int dc_wdt_start(struct watchdog_ {struct dc_wdt *wdt =watchdog_get_drvdata (wdog); -dc_wdt_set (wdt, wdog->timeout *clk_get_rate (wdt->clk)); +dc_wdt_set (wdt, wdog->timeout * wdt->rate);return 0 ; }
@@ -79,7 +80,7 @@ static int dc_wdt_set_timeout(struct wat {struct dc_wdt *wdt =watchdog_get_drvdata (wdog); -dc_wdt_set (wdt, t *clk_get_rate (wdt->clk)); +dc_wdt_set (wdt, t * wdt->rate); wdog->timeout = t;return 0 ;
@@ -90,7 +91,7 @@ static unsigned int dc_wdt_get_timeleft(struct dc_wdt *wdt =watchdog_get_drvdata (wdog);uint32_t count =readl_relaxed (wdt->base +TIMER_A_COUNT ); -return count /clk_get_rate (wdt->clk); +return count / wdt->rate; }static const struct watchdog_ops dc_wdt_ops = {
@@ -130,7 +131,11 @@ static int dc_wdt_probe(struct platform_ wdt->clk =devm_clk_get (dev,NULL );if (IS_ERR (wdt->clk))return PTR_ERR (wdt->clk); - dc_wdt_wdd.max_timeout =U32_MAX /clk_get_rate (wdt->clk); + + wdt->rate =clk_get_rate (wdt->clk); +if (!wdt->rate) +return -EINVAL ; + dc_wdt_wdd.max_timeout =U32_MAX / wdt->rate; dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout; dc_wdt_wdd.parent = dev;
Greg Kroah-Hartman
maintainerPATCH 912/1193 watchdog: msc313e: Fix premature reset during timeout update
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 22737cfced627ffcb4b5c36d63bb3d4476f63213 upstream.
Updating the 32-bit hardware timeout requires writing to two 16-bit registers sequentially. If the watchdog is actively running, this non-atomic update might trigger a premature system reset.
Clear the watchdog counter before updating the registers to prevent the timer from timing out prematurely against an intermediate threshold.
--- drivers/watchdog/msc313e_wdt.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/watchdog/msc313e_wdt.c +6 -0
@@ -47,6 +47,9 @@ static void msc313e_wdt_set_hw_timeout(s {u32 t = timeout *clk_get_rate (priv->clk); +/* Clear before to prevent premature reset during non-atomic updates. */ +writew (1 , priv->base +REG_WDT_CLR ); +writew (t &0xffff , priv->base +REG_WDT_MAX_PRD_L );writew ((t >>16 ) &0xffff , priv->base +REG_WDT_MAX_PRD_H );writew (1 , priv->base +REG_WDT_CLR );
@@ -77,6 +80,9 @@ static int msc313e_wdt_stop(struct watch {struct msc313e_wdt_priv *priv =watchdog_get_drvdata (wdev); +/* Clear before to prevent premature reset during non-atomic updates. */ +writew (1 , priv->base +REG_WDT_CLR ); +writew (0 , priv->base +REG_WDT_MAX_PRD_L );writew (0 , priv->base +REG_WDT_MAX_PRD_H );writew (0 , priv->base +REG_WDT_CLR );
Greg Kroah-Hartman
maintainerPATCH 913/1193 watchdog: msc313e: Propagate error code in resume()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 1d9763f34a85680db1e8233d654fdb85e5f897cc upstream.
If msc313e_wdt_start() fails during system resume, the error is currently ignored. Consequently, the watchdog isn't running without the user's knowledge.
Propagate the error code and print a message if msc313e_wdt_start() fails.
--- drivers/watchdog/msc313e_wdt.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/watchdog/msc313e_wdt.c +7 -3
@@ -198,11 +198,15 @@ static int __maybe_unused msc313e_wdt_sustatic int __maybe_unused msc313e_wdt_resume (struct device *dev) {struct msc313e_wdt_priv *priv =dev_get_drvdata (dev); +int ret =0 ; -if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev)) -msc313e_wdt_start (&priv->wdev); +if (watchdog_active (&priv->wdev) ||watchdog_hw_running (&priv->wdev)) { + ret =msc313e_wdt_start (&priv->wdev); +if (ret) +dev_err (dev,"Failed to restart watchdog (err=%d)\n" , ret); + } -return 0 ; +return ret; } static SIMPLE_DEV_PM_OPS(msc313e_wdt_pm_ops, msc313e_wdt_suspend, msc313e_wdt_resume);
Greg Kroah-Hartman
maintainerPATCH 914/1193 watchdog: rtd119x: Avoid division by zero
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 5af7d2cbd20f893def03c8310a460ade66a5d822 upstream.
clk_get_rate() could return 0. Avoid a division by zero panic.
--- drivers/watchdog/rtd119x_wdt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/watchdog/rtd119x_wdt.c +6 -1
@@ -98,6 +98,7 @@ static int rtd119x_wdt_probe(struct plat {struct device *dev = &pdev->dev;struct rtd119x_watchdog_device *data; +unsigned long rate; data =devm_kzalloc (dev,sizeof (*data),GFP_KERNEL );if (!data)
@@ -111,10 +112,14 @@ static int rtd119x_wdt_probe(struct platif (IS_ERR (data->clk))return PTR_ERR (data->clk); + rate =clk_get_rate (data->clk); +if (!rate) +return -EINVAL ; + data->wdt_dev.info = &rtd119x_wdt_info; data->wdt_dev.ops = &rtd119x_wdt_ops; data->wdt_dev.timeout =120 ; - data->wdt_dev.max_timeout =0xffffffff /clk_get_rate (data->clk); + data->wdt_dev.max_timeout =0xffffffff / rate; data->wdt_dev.min_timeout =1 ; data->wdt_dev.parent = dev;
Greg Kroah-Hartman
maintainerPATCH 915/1193 watchdog: sp5100_tco: Fix pci_dev reference leak in sp5100_tco_init()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 88f113634028ca90a857031837d8061d1a9e1a7b upstream.
sp5100_tco_init() stores the PCI device matched by for_each_pci_dev() in the global sp5100_tco_pci and keeps its reference for the lifetime of the driver, but neither sp5100_tco_exit() nor the error paths of sp5100_tco_init() call pci_dev_put(), leaking the reference on driver registration failure and on every module load/unload cycle.
Drop the reference when the platform driver or device registration fails and when the module is unloaded.
--- drivers/watchdog/sp5100_tco.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/watchdog/sp5100_tco.c +5 -1
@@ -605,8 +605,10 @@ static int __init sp5100_tco_init(void)pr_info ("SP5100/SB800 TCO WatchDog Timer Driver\n" ); err =platform_driver_register (&sp5100_tco_driver); -if (err) +if (err) { +pci_dev_put (sp5100_tco_pci);return err; + } sp5100_tco_platform_device =platform_device_register_simple (TCO_DRIVER_NAME ,-1 ,NULL ,0 );
@@ -619,6 +621,7 @@ static int __init sp5100_tco_init(void) unreg_platform_driver:platform_driver_unregister (&sp5100_tco_driver); +pci_dev_put (sp5100_tco_pci);return err; }
@@ -626,6 +629,7 @@ static void __exit sp5100_tco_exit(void) {platform_device_unregister (sp5100_tco_platform_device);platform_driver_unregister (&sp5100_tco_driver); +pci_dev_put (sp5100_tco_pci); }module_init (sp5100_tco_init);
Greg Kroah-Hartman
maintainerPATCH 916/1193 watchdog: starfive-wdt: Fix runtime PM leak in starfive_wdt_pm_start()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wentao Liang <[email protected]>
commit 8f0ca55016a7647109ae2bc91bcb346fc8b13785 upstream.
starfive_wdt_pm_start() takes a runtime PM reference with pm_runtime_get_sync(), which increments the usage counter even when it fails, and returns the error without dropping it again. The watchdog core does not invoke the stop callback when start fails, so the reference taken on the error path is leaked.
Use pm_runtime_resume_and_get() instead, which keeps the usage counter balanced when the resume fails.
--- drivers/watchdog/starfive-wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/starfive-wdt.c +1 -1
@@ -369,7 +369,7 @@ static void starfive_wdt_stop(struct stastatic int starfive_wdt_pm_start (struct watchdog_device *wdd) {struct starfive_wdt *wdt =watchdog_get_drvdata (wdd); -int ret =pm_runtime_get_sync (wdd->parent); +int ret =pm_runtime_resume_and_get (wdd->parent);if (ret <0 )return ret;
Greg Kroah-Hartman
maintainerPATCH 917/1193 wifi: brcmsmac: fix UAF in brcms_free_timer()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit 1eeca1d5e0920fbdad6449768fd2d4364e714180 upstream.
brcms_free_timer() calls brcms_del_timer() which uses the non-synchronous cancel_delayed_work() to cancel the timer's underlying delayed work. If the work callback (_brcms_timer) is already running, cancel_delayed_work() returns false without waiting, and brcms_free_timer() proceeds to kfree(t) while the callback still accesses t through container_of().
Add an explicit cancel_delayed_work_sync() after brcms_del_timer() to guarantee that any in-flight callback has completed before the timer structure is freed.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c +4 -0
@@ -1565,6 +1565,10 @@ void brcms_free_timer(struct brcms_timer/* delete the timer in case it is active */ brcms_del_timer (t); +/* Ensure the callback has finished before freeing the timer +* structure, since brcms_del_timer() uses non-synchronous cancel. +*/ +cancel_delayed_work_sync (&t->dly_wrk);if (wl->timers == t) { wl->timers = wl->timers->next;
Greg Kroah-Hartman
maintainerPATCH 918/1193 wifi: iwlegacy: fix broadcast stations deallocation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislaw Gruszka <[email protected]>
commit b5526b780f8b297a76030410b96ba29153afb98f upstream.
On the error path of __il4965_up(), il_dealloc_bcast_stations() clears only IL_STA_UCODE_ACTIVE, leaving IL_STA_BCAST set. This causes the same broadcast stations to be deallocated again by __il4965_down().
This can occur when RF_KILL is toggled during driver startup.
To fix clear the entire 'used' field, since we will not do any other operations on the station.
--- drivers/net/wireless/intel/iwlegacy/common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/intel/iwlegacy/common.c +1 -1
@@ -2324,7 +2324,7 @@ il_dealloc_bcast_stations(struct il_privif (!(il->stations[i].used &IL_STA_BCAST ))continue ; - il->stations[i].used &= ~IL_STA_UCODE_ACTIVE ; + il->stations[i].used =0 ; il->num_stations--;BUG_ON (il->num_stations <0 );kfree (il->stations[i].lq);
Greg Kroah-Hartman
maintainerPATCH 919/1193 wifi: libertas_tf: fix UAF in lbtf_free_adapter()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
commit bbb9a0ab96d44a64529aafc7a16de460a1712f6a upstream.
lbtf_free_adapter() calls lbtf_free_cmd_buffer() to free the command buffers before calling timer_delete_sync() to wait for the command timer callback. If the timer callback (command_timer_fn) is already running when lbtf_free_cmd_buffer() frees the command array, the callback dereferences priv->cur_cmd->cmdbuf which points to freed memory.
Swap the order so that timer_delete_sync() runs first, ensuring any in-flight callback has completed before the command buffers are freed.
--- drivers/net/wireless/marvell/libertas_tf/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/marvell/libertas_tf/main.c +1 -1
@@ -173,8 +173,8 @@ static int lbtf_init_adapter(struct lbtfstatic void lbtf_free_adapter (struct lbtf_private *priv) {lbtf_deb_enter (LBTF_DEB_MAIN ); -lbtf_free_cmd_buffer (priv);timer_delete_sync (&priv->command_timer); +lbtf_free_cmd_buffer (priv);lbtf_deb_leave (LBTF_DEB_MAIN ); }
Greg Kroah-Hartman
maintainerPATCH 902/1193 Input: synaptics-rmi4 - fix GPF in suspend and resume when unbound
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Torokhov <[email protected]>
commit fe10579b6dc3f0dac61e51e1797cacbba5039ac2 upstream.
Transport drivers (such as rmi_i2c and rmi_spi) invoke rmi_driver_suspend() and rmi_driver_resume() on their child rmi_dev device during system power management events. However, transport drivers are fully registered and operational even if the physical RMI driver failed to bind or probe the rmi_dev device.
When rmi_driver_suspend() or rmi_driver_resume() is called on an unbound rmi_dev, dev_get_drvdata() returns NULL. Calling rmi_disable_irq() or rmi_enable_irq() without driver data attached causes a NULL pointer dereference and General Protection Fault when attempting to lock data->enabled_mutex.
Fix this by checking if driver data is attached to rmi_dev in rmi_driver_suspend() and rmi_driver_resume(), exiting early if no driver data is present.
--- drivers/input/rmi4/rmi_driver.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/input/rmi4/rmi_driver.c +13 -0
@@ -946,6 +946,15 @@ int rmi_driver_suspend(struct rmi_device {int retval; +/* +* Transport driver will try to suspend RMI device even if physical +* driver did not bind to the RMI device, because transport device +* (I2C, SPI) is fully registered and operational. Exit early if +* there is no driver data attached to the RMI device. +*/ +if (!dev_get_drvdata (&rmi_dev->dev)) +return 0 ; + retval =rmi_suspend_functions (rmi_dev);if (retval) dev_warn(&rmi_dev->dev, "Failed to suspend functions: %d\n",
@@ -960,6 +969,10 @@ int rmi_driver_resume(struct rmi_device {int retval; +/* Skip if not fully bound to RMI driver */ +if (!dev_get_drvdata (&rmi_dev->dev)) +return 0 ; +rmi_enable_irq (rmi_dev, clear_wake); retval =rmi_resume_functions (rmi_dev);
Greg Kroah-Hartman
maintainerPATCH 920/1193 wifi: rsi: fix heap OOB write on key removal
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit e6c5ed7a98d7bc8b0f7918246f1c90ddb3f79dfa upstream.
When a key is removed (data == NULL), rsi_hal_load_key() runs:
memset(&set_key[FRAME_DESC_SZ], 0, frame_len - FRAME_DESC_SZ);
set_key is a struct rsi_set_key *, so the subscript is scaled by sizeof(struct rsi_set_key) (160 bytes): &set_key[FRAME_DESC_SZ] is skb->data + 2560, and the memset writes 144 zero bytes starting 2.4KB past the end of the 160-byte skb data buffer, corrupting unrelated heap objects. The intended byte offset would have been (u8 *)set_key + FRAME_DESC_SZ.
The write fires on every DISABLE_KEY callback, so plain disconnects, roams and interface teardowns trigger it on real networks.
The memset is redundant: the whole buffer is zeroed right after allocation, so the frame sent to the device is byte-identical without it. Drop the else branch; normal operation is unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/rsi/rsi_91x_mgmt.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/wireless/rsi/rsi_91x_mgmt.c +0 -2
@@ -852,8 +852,6 @@ int rsi_hal_load_key(struct rsi_common *memcpy (set_key->tx_mic_key, &data[16 ],8 );memcpy (set_key->rx_mic_key, &data[24 ],8 ); } - }else { -memset (&set_key[FRAME_DESC_SZ ],0 , frame_len -FRAME_DESC_SZ ); }skb_put (skb, frame_len);
Greg Kroah-Hartman
maintainerPATCH 921/1193 wifi: wlcore: release runtime PM ref on regdomain config failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 8a1f3cf89ddcc700e25afe42cfad333059adcc94 upstream.
wlcore_regdomain_config() gets a runtime PM reference before sending the regulatory-domain command. When wlcore_cmd_regdomain_config_locked() fails, the function queues recovery and returns without dropping that reference.
Release the reference after handling the command result so both success and failure paths balance the preceding pm_runtime_resume_and_get(). The recovery worker takes a separate runtime PM reference and cannot release the reference held here.
--- drivers/net/wireless/ti/wlcore/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/wireless/ti/wlcore/main.c +1 -3
@@ -3635,10 +3635,8 @@ void wlcore_regdomain_config(struct wl12 goto out; ret =wlcore_cmd_regdomain_config_locked (wl); -if (ret <0 ) { +if (ret <0 )wl12xx_queue_recovery_work (wl); - goto out; - }pm_runtime_mark_last_busy (wl->dev);pm_runtime_put_autosuspend (wl->dev);
Greg Kroah-Hartman
maintainerPATCH 922/1193 wifi: wilc1000: fix out-of-bounds read in P2P public action frames
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memis <[email protected]>
commit ba6cb7c0868a412c2eb68e8efd5aa38bfb258a14 upstream.
wilc_wfi_p2p_rx() and mgmt_tx() start parsing a frame once ieee80211_is_public_action() returns true. That helper only verifies the frame is long enough for the action category field, that is offsetofend(struct ieee80211_mgmt, u.action.category), 25 bytes. Both functions then read the P2P public action header up to oui_subtype at offset 30 and pass "size - ie_offset" to cfg80211_find_vendor_ie(), where ie_offset is offsetof(struct ieee80211_mgmt, u) + sizeof(*d), i.e. 32.
A public action frame of 25 to 31 bytes passes the check but is shorter than that 32 byte header, so oui_subtype can be read out of bounds, and because the length is unsigned, "size - ie_offset" underflows to a value close to 4 GiB. cfg80211_find_vendor_ie() takes an unsigned int length, so even the size_t subtraction in mgmt_tx() is truncated to the same value. It then walks far past the buffer searching for a vendor element until it reaches unmapped memory.
In the receive path the frame arrives over the air and needs no association, so a nearby unauthenticated device can crash the host while it is in P2P listen. Reject frames shorter than the P2P public action header in both paths before dereferencing it.
--- drivers/net/wireless/microchip/wilc1000/cfg80211.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/net/wireless/microchip/wilc1000/cfg80211.c +14 -0
@@ -1069,6 +1069,13 @@ void wilc_wfi_p2p_rx(struct wilc_vif *viif (!ieee80211_is_public_action ((struct ieee80211_hdr *)buff, size)) goto out_rx_mgmt; +/* ieee80211_is_public_action() only validates up to the category +* byte, so reject frames too short for the P2P public action header +* before dereferencing it or computing size - ie_offset. +*/ +if (size < ie_offset) + goto out_rx_mgmt; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);if (d->oui_subtype !=GO_NEG_REQ && d->oui_subtype !=GO_NEG_RSP && d->oui_subtype !=P2P_INV_REQ && d->oui_subtype !=P2P_INV_RSP )
@@ -1219,6 +1226,13 @@ static int mgmt_tx(struct wiphy *wiphy, goto out_set_timeout; } +/* ieee80211_is_public_action() only validates up to the category +* byte, so reject frames too short for the P2P public action header +* before dereferencing it or computing len - ie_offset. +*/ +if (len < ie_offset) + goto out_set_timeout; + d = (struct wilc_p2p_pub_act_frame *)(&mgmt->u.action);if (d->oui_type !=WLAN_OUI_TYPE_WFA_P2P || d->oui_subtype !=GO_NEG_CONF ) {
Greg Kroah-Hartman
maintainerPATCH 923/1193 wifi: wilc1000: fix RX buffer OOB-write in wilc_wlan_handle_isr_ext()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tianchu Chen <[email protected]>
commit c1ba7f7f18465e259cf1b4d9c73fc73853d7f790 upstream.
wilc_wlan_handle_isr_ext() takes the RX transfer size from the device-reported interrupt status register (a 15-bit field shifted left by 2, up to 131068 bytes) and reads that many bytes from the device into rx_buffer, which is only WILC_RX_BUFF_SIZE (96K) large. The wrap check only handles the current offset; the size itself is never compared against the buffer, so a bogus SDIO device can make the driver OOB-write rx_buffer by up to ~32K with data it controls.
The oversized transfer also leaves rx_buffer_offset past the end of the buffer, after which the unsigned wrap check stops working and the overflow can repeat.
Drop any transfer whose size exceeds the RX buffer, acknowledging the data interrupt and re-arming the RX engine so the bogus frame is discarded and reception can continue. This also restores the rx_buffer_offset <= WILC_RX_BUFF_SIZE invariant the wrap check relies on.
This is not expected to change driver behavior in most cases:
without this check, an oversized transfer would most likely corrupt neighboring kernel memory instead of completing anyway, and the drop path performs the same interrupt acknowledgment and RX engine re-arming as the normal path, so subsequent transfers are received unaffected.
Discovered by Atuin - Automated Vulnerability Discovery Engine.
--- drivers/net/wireless/microchip/wilc1000/wlan.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/net/wireless/microchip/wilc1000/wlan.c +9 -0
@@ -1040,6 +1040,15 @@ static void wilc_wlan_handle_isr_ext(strif (size <=0 )return ; +/* A size exceeding the RX buffer is bogus; drop the transfer +* instead of overflowing the buffer. +*/ +if (size >WILC_RX_BUFF_SIZE ) { + wilc->hif_func->hif_clear_int_ext (wilc, +DATA_INT_CLR |ENABLE_RX_VMM ); +return ; + } +if (WILC_RX_BUFF_SIZE - offset < size) offset =0 ;
Greg Kroah-Hartman
maintainerPATCH 924/1193 wifi: p54: validate curve data length in the calibration curve converters
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit ce858fa6b8a214dee5adb82358885fa024cdd887 upstream.
p54_convert_rev0() and p54_convert_rev1() read calibration curve data from the device-supplied EEPROM entry using channel and points-per-channel counts taken verbatim from that same entry, so an entry that declares more data than it carries drives an out-of-bounds read past the EEPROM buffer (verified with a KASAN reproducer of the conversion loop). The sibling converters p54_convert_output_limits() and p54_convert_db() already validate their counts against the entry length; this path was missed.
Reject the entry when the counts do not fit in the entry data.
--- drivers/net/wireless/intersil/p54/eeprom.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/net/wireless/intersil/p54/eeprom.c +15 -4
@@ -418,17 +418,22 @@ free: }static int p54_convert_rev0 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev0 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +2 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kmalloc (sizeof (*priv->curve_data) + cd_len,GFP_KERNEL );if (!priv->curve_data)
@@ -470,17 +475,22 @@ static int p54_convert_rev0(struct ieee8 }static int p54_convert_rev1 (struct ieee80211_hw *dev, -struct pda_pa_curve_data *curve_data) +struct pda_pa_curve_data *curve_data,size_t len) {struct p54_common *priv = dev->priv;struct p54_pa_curve_data_sample *dst;struct pda_pa_curve_data_sample_rev1 *src; +size_t needed = curve_data->channels * + (sizeof (*src) * curve_data->points_per_channel +3 );size_t cd_len =sizeof (*curve_data) + (curve_data->points_per_channel*sizeof (*dst) +2 ) * curve_data->channels;unsigned int i, j;void *source, *target; +if (len <sizeof (*curve_data) + needed) +return -EINVAL ; + priv->curve_data =kzalloc (cd_len +sizeof (*priv->curve_data),GFP_KERNEL );if (!priv->curve_data)
@@ -767,6 +777,7 @@ int p54_parse_eeprom(struct ieee80211_hwcase PDR_PRISM_PA_CAL_CURVE_DATA : {struct pda_pa_curve_data *curve_data = (struct pda_pa_curve_data *)entry->data; +if (data_len <sizeof (*curve_data)) { err = -EINVAL ; goto err;
@@ -774,10 +785,10 @@ int p54_parse_eeprom(struct ieee80211_hwswitch (curve_data->cal_method_rev) {case 0 : - err =p54_convert_rev0 (dev, curve_data); + err =p54_convert_rev0 (dev, curve_data, data_len);break ;case 1 : - err =p54_convert_rev1 (dev, curve_data); + err =p54_convert_rev1 (dev, curve_data, data_len);break ;default : wiphy_err(dev->wiphy,
Greg Kroah-Hartman
maintainerPATCH 925/1193 wifi: p54: require a full exp_if record in PDR_INTERFACE_LIST
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengzhuo Wei <[email protected]>
commit d8efd84f49379ed28624098821f80e992657d935 upstream.
The PDR_INTERFACE_LIST loop only checks that the record start is within the entry before reading an entire struct exp_if from it. A truncated trailing record makes the if_id/variant reads cross the entry boundary into the heap beyond the EEPROM buffer (verified with a KASAN reproducer of the loop). The variant also feeds the synth front-end selection, so this is not only a leak.
Advance only while a full record still fits in the entry.
--- drivers/net/wireless/intersil/p54/eeprom.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/intersil/p54/eeprom.c +2 -1
@@ -816,7 +816,8 @@ int p54_parse_eeprom(struct ieee80211_hwbreak ;case PDR_INTERFACE_LIST : tmp = entry->data; -while ((u8 *)tmp < entry->data + data_len) { +while ((u8 *)tmp +sizeof (struct exp_if ) <= + entry->data + data_len) {struct exp_if *exp_if = tmp;if (exp_if->if_id ==cpu_to_le16 (IF_ID_ISL39000 )) synth =le16_to_cpu (exp_if->variant);
Greg Kroah-Hartman
maintainerPATCH 926/1193 wifi: mwifiex: bound the pairwise-cipher OUI walk to the IE length
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Doruk Tan Ozturk <[email protected]>
commit e667aee1c192d67d27c803007bfa9c6e0873e959 upstream.
mwifiex_search_oui_in_ie() reads a pairwise-cipher (PTK) count from a beacon/probe-response RSN or WPA information element and then walks that many 4-byte OUIs, comparing each with memcmp(). The count comes straight from the (attacker-supplied) IE and is never checked against the element's own length, and the callers admit the element on element_id alone (has_ieee_hdr() / has_vendor_hdr(), no length check). A crafted RSN/WPA IE with a large pairwise count therefore makes the walk read up to 255 * 4 bytes past the element -- an out-of-bounds read of the kmemdup()'d beacon buffer, reachable from any AP whose beacon/probe response is processed during scan-result parsing.
Pass the number of IE bytes available at the OUI list and bound the walk to the element. Keep the length signed and reject a negative value before any unsigned arithmetic, so a small or zero IE length cannot underflow to a large size_t and defeat the bound.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/net/wireless/marvell/mwifiex/scan.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +22 -3
@@ -104,12 +104,24 @@ has_vendor_hdr(struct ieee_types_vendor_* a given oui in PTK. */ static u8 -mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui) +mwifiex_search_oui_in_ie (struct ie_body *iebody,u8 *oui,int ie_len) { +const size_t ptk_body_offset = offsetof(struct ie_body , ptk_body);u8 count; +/* ie_len is the number of bytes available at iebody. Keep it signed +* and reject a negative (underflowed) length before the unsigned +* comparisons below, so a small or zero IE length cannot wrap. +*/ +if (ie_len <0 || (size_t )ie_len < ptk_body_offset) +return MWIFIEX_OUI_NOT_PRESENT ; + count = iebody->ptk_cnt[0 ]; +/* Reject an OUI count whose list would run past the element. */ +if (ptk_body_offset + count *sizeof (iebody->ptk_body) > (size_t )ie_len) +return MWIFIEX_OUI_NOT_PRESENT ; +/* There could be multiple OUIs for PTK hence 1) Take the length. 2) Check all the OUIs for AES.
@@ -143,11 +155,14 @@ mwifiex_is_rsn_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_ieee_hdr (bss_desc->bcn_rsn_ie,WLAN_EID_RSN )) { +int ie_len = (int )bss_desc->bcn_rsn_ie->ieee_hdr.len - +RSN_GTK_OUI_OFFSET ; + iebody = (struct ie_body *) (((u8 *) bss_desc->bcn_rsn_ie->data) +RSN_GTK_OUI_OFFSET ); oui = &mwifiex_rsn_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
@@ -169,10 +184,14 @@ mwifiex_is_wpa_oui_present(struct mwifieu8 ret =MWIFIEX_OUI_NOT_PRESENT ;if (has_vendor_hdr (bss_desc->bcn_wpa_ie,WLAN_EID_VENDOR_SPECIFIC )) { +int ie_len = (int )bss_desc->bcn_wpa_ie->vend_hdr.len - + (int )sizeof (bss_desc->bcn_wpa_ie->vend_hdr.oui) - +WPA_GTK_OUI_OFFSET ; + iebody = (struct ie_body *)((u8 *)bss_desc->bcn_wpa_ie->data +WPA_GTK_OUI_OFFSET ); oui = &mwifiex_wpa_oui[cipher][0 ]; - ret =mwifiex_search_oui_in_ie (iebody, oui); + ret =mwifiex_search_oui_in_ie (iebody, oui, ie_len);if (ret)return ret; }
Greg Kroah-Hartman
maintainerPATCH 927/1193 wifi: mwifiex: validate scan response extents
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit 3687d7d48070838cc2953431b3a27717cab0aaf6 upstream.
mwifiex_ret_802_11_scan() subtracts the fixed response fields and the firmware-provided BSS length from resp->size without first proving that either extent fits. A short response or oversized BSS length can therefore underflow tlv_buf_size and make the TLV parser walk beyond the command response.
Compute the fixed extent from the selected normal or background scan response. Validate that the fixed fields and BSS data fit before deriving the TLV extent and entering the parser.
--- drivers/net/wireless/marvell/mwifiex/scan.c | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-)
drivers/net/wireless/marvell/mwifiex/scan.c +19 -10
@@ -2125,6 +2125,7 @@ int mwifiex_ret_802_11_scan(struct mwifiu32 bytes_left;u32 idx;u32 tlv_buf_size; +size_t fixed_size;struct mwifiex_ie_types_chan_band_list_param_set *chan_band_tlv;struct chan_band_param_set *chan_band;u8 is_bgscan_resp;
@@ -2140,6 +2141,14 @@ int mwifiex_ret_802_11_scan(struct mwifielse scan_rsp = &resp->params.scan_resp; + scan_resp_size =le16_to_cpu (resp->size); + fixed_size = scan_rsp->bss_desc_and_tlv_buffer - (u8 *)resp; +if (scan_resp_size < fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: response is too short\n" ); + ret =-1 ; + goto check_next_scan; + }if (scan_rsp->number_of_sets >MWIFIEX_MAX_AP ) { mwifiex_dbg(adapter, ERROR,
@@ -2157,8 +2166,6 @@ int mwifiex_ret_802_11_scan(struct mwifi"info: SCAN_RESP: bss_descript_size %d\n" , bytes_left); - scan_resp_size =le16_to_cpu (resp->size); -mwifiex_dbg (adapter,INFO ,"info: SCAN_RESP: returned %d APs before parsing\n" , scan_rsp->number_of_sets);
@@ -2166,15 +2173,17 @@ int mwifiex_ret_802_11_scan(struct mwifi bss_info = scan_rsp->bss_desc_and_tlv_buffer;/* -* The size of the TLV buffer is equal to the entire command response -* size (scan_resp_size) minus the fixed fields (sizeof()'s), the -* BSS Descriptions (bss_descript_size as bytesLef) and the command -* response header (S_DS_GEN) +* The TLV buffer follows the command-specific fixed fields and the BSS +* descriptions. Background-scan responses have an additional fixed +* field before scan_rsp, which is included in fixed_size. */ - tlv_buf_size = scan_resp_size - (bytes_left - +sizeof (scan_rsp->bss_descript_size) - +sizeof (scan_rsp->number_of_sets) - +S_DS_GEN ); +if (bytes_left > scan_resp_size - fixed_size) { +mwifiex_dbg (adapter,ERROR , +"SCAN_RESP: BSS data exceeds response\n" ); + ret =-1 ; + goto check_next_scan; + } + tlv_buf_size = scan_resp_size - fixed_size - bytes_left; tlv_data = (struct mwifiex_ie_types_data *) (scan_rsp-> bss_desc_and_tlv_buffer +
Greg Kroah-Hartman
maintainerPATCH 928/1193 wifi: mwifiex: validate action frame fixed fields
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhao Li <[email protected]>
commit 1c25bfad93e69ce13f744a2fb919f02ea396a985 upstream.
mwifiex_process_mgmt_packet() accepts an rx_pkt_length as small as a four-address struct ieee80211_hdr plus the two-byte firmware length prefix. After stripping the prefix, mwifiex_parse_mgmt_packet() can receive a frame equal to sizeof(struct ieee80211_hdr).
For action frames, the parser reads the category byte immediately after that header and, for a public action frame, reads the following action code byte without verifying that either field is present. A truncated frame can therefore make the parser consume up to two bytes past the firmware-declared frame length. If those bytes look like a TDLS discovery response, the malformed frame can spuriously update peer signal state.
Require the category and public action-code fields before reading them. Use sizeof(*ieee_hdr) so the checks and field accesses directly match the firmware four-address layout being parsed before address4 is removed.
--- drivers/net/wireless/marvell/mwifiex/util.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/wireless/marvell/mwifiex/util.c +8 -2
@@ -335,10 +335,16 @@ mwifiex_parse_mgmt_packet(struct mwifiexswitch (stype) {case IEEE80211_STYPE_ACTION : - category = *(payload +sizeof (struct ieee80211_hdr )); +if (len <sizeof (*ieee_hdr) +1 ) +return -1 ; + + category = *(payload +sizeof (*ieee_hdr));switch (category) {case WLAN_CATEGORY_PUBLIC : - action_code = *(payload +sizeof (struct ieee80211_hdr ) +if (len <sizeof (*ieee_hdr) +2 ) +return -1 ; + + action_code = *(payload +sizeof (*ieee_hdr) +1 );if (action_code ==WLAN_PUB_ACTION_TDLS_DISCOVER_RES ) { addr2 = ieee_hdr->addr2;
Greg Kroah-Hartman
maintainerPATCH 929/1193 wifi: mac80211: avoid WARN in set_bitrate_mask when sdata not in driver
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rik van Riel <[email protected]>
commit da2ca406f45a6e21760243152ed8d2e8e72915c2 upstream.
ieee80211_set_bitrate_mask() checks if the interface is running via ieee80211_sdata_running(), but it does not check if the interface is still present in the driver.
When sdata is running but IEEE80211_SDATA_IN_DRIVER is not set, the call reaches drv_set_bitrate_mask() in driver-ops.h which hits
wlan1: Failed check-sdata-in-driver check, flags: 0x0
WARNING: net/mac80211/driver-ops.h:884 at drv_set_bitrate_mask
Syzkaller triggers this via wext SIOCSIWRATE ioctl. The Call Trace shows wext_ioctl_dispatch() in wext-core.c dispatching the ioctl, calling ioctl_standard_call() for SIOCSIWRATE, which calls cfg80211_wext_siwrate() in wext-compat.c. That builds a bitrate mask and calls rdev_set_bitrate_mask() which ends up in ieee80211_set_bitrate_mask() in cfg.c. The interface is marked running via SDATA_STATE_RUNNING but flags is 0, so check_sdata_in_driver() fails.
When the interface is being torn down, or when wext ioctl is issued during interface bringup before drv_add_interface() sets IN_DRIVER, the running check passes while IN_DRIVER is clear.
Check IEEE80211_SDATA_IN_DRIVER in ieee80211_set_bitrate_mask() before calling the driver, returning -ENETDOWN. This avoids the WARN_ONCE in driver-ops.h and matches other cfg.c operations that bail early when not in driver.
This change should be safe because wiphy mutex is held in cfg80211_wext_siwrate() via guard(wiphy), and IN_DRIVER is set/cleared under RTNL and wiphy paths in drv_add_interface() and drv_remove_interface() in driver-ops.c, so the check is race-free against driver add/remove. Returning -ENETDOWN is the same error other not-running paths use and does not introduce new locking.
--- net/mac80211/cfg.c | 3 +++ 1 file changed, 3 insertions(+)
net/mac80211/cfg.c +3 -0
@@ -3345,6 +3345,9 @@ static int ieee80211_set_bitrate_mask(stif (!ieee80211_sdata_running (sdata))return -ENETDOWN ; +if (!(sdata->flags &IEEE80211_SDATA_IN_DRIVER )) +return -ENETDOWN ; +/* * If active validate the setting and reject it if it doesn't leave * at least one basic rate usable, since we really have to be able
Greg Kroah-Hartman
maintainerPATCH 903/1193 Input: zero ff_effect before compat copy in input_ff_effect_from_user
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Iván Ezequiel Rodriguez <[email protected]>
commit f84819ef8d66931ee3998fee3c4f03230f4cb6cc upstream.
In the compat path input_ff_effect_from_user() aliases the caller's native struct ff_effect with the smaller struct ff_effect_compat and copies only the compat sized prefix:
compat_effect = (struct ff_effect_compat *)effect; if (copy_from_user(compat_effect, buffer, sizeof(struct ff_effect_compat)))
The tail of the native structure is never written. Callers pass an uninitialized on-stack object, for example evdev_do_ioctl() for EVIOCSFF, so those bytes keep their previous stack contents. input_ff_upload() then stores the full native structure in ff->effects[id], from where a uinput based force feedback daemon can read it back via UI_BEGIN_FF_UPLOAD, disclosing kernel stack memory to userspace.
Zero the effect before the compat copy.
--- drivers/input/input-compat.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/input/input-compat.c +2 -0
@@ -75,6 +75,8 @@ int input_ff_effect_from_user(const char*/ compat_effect = (struct ff_effect_compat *)effect; +memset (effect,0 ,sizeof (*effect)); +if (copy_from_user (compat_effect, buffer,sizeof (struct ff_effect_compat )))return -EFAULT ;
Greg Kroah-Hartman
maintainerPATCH 930/1193 drm/gud: fix out-of-bounds write in gud_plane_atomic_check()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sajal Gupta <[email protected]>
commit 59ced288fcba9e91bd38e61a972ad782c4edb7d0 upstream.
The plane property loop uses req->properties[num_properties + i] as write index while simultaneously incrementing num_properties inside the loop. At iteration i, num_properties has also incremented by i, so the write is done at initial_num_properties + 2*i, skipping every other index and advancing by 2 per iteration.
With just 2 connector and 32 plane properties the last write happens at index 64, one slot past the end of the 64-slot (indices 0–63) allocation. A USB device can trigger OOB by advertising the maximum number of properties.
Fix by dropping the redundant + i; num_properties is already the correct running index, as gud_connector_fill_properties() fills the preceding slots.
--- drivers/gpu/drm/gud/gud_pipe.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +2 -2
@@ -538,8 +538,8 @@ int gud_pipe_check(struct drm_simple_dis goto out; } - req->properties[num_properties + i].prop =cpu_to_le16 (prop); - req->properties[num_properties + i].val =cpu_to_le64 (val); + req->properties[num_properties].prop =cpu_to_le16 (prop); + req->properties[num_properties].val =cpu_to_le64 (val); num_properties++; }
Greg Kroah-Hartman
maintainerPATCH 931/1193 drm/msm/adreno: fix autosuspend cleanup during teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 6fbbf1e152f34ad3913e4a6476680aba672c5068 upstream.
adreno_gpu_init() calls pm_runtime_use_autosuspend(), but adreno_gpu_cleanup() does not call the matching pm_runtime_dont_use_autosuspend() during teardown.
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 adreno_gpu_cleanup().
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/745110/
--- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/adreno/adreno_gpu.c +2 -0
@@ -1125,6 +1125,8 @@ void adreno_gpu_cleanup(struct adreno_gpfor (i =0 ; i <ARRAY_SIZE (adreno_gpu->info->fw); i++)release_firmware (adreno_gpu->fw[i]); +pm_runtime_dont_use_autosuspend (&gpu->pdev->dev); +if (priv &&pm_runtime_enabled (&priv->gpu_pdev->dev))pm_runtime_disable (&priv->gpu_pdev->dev);
Greg Kroah-Hartman
maintainerPATCH 932/1193 drm/msm/hdmi_phy: fix runtime PM cleanup on probe failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit f4fae975db08a9aeec0b15e145c7d4d0fe02a0ec upstream.
msm_hdmi_phy_probe() enables runtime PM before enabling the PHY resources and initializing the PLL, but failures from either operation return without calling the matching pm_runtime_disable().
The remove path disables runtime PM, but it is not called when probe fails. As a result, runtime PM remains enabled after an unsuccessful probe.
Route failures after pm_runtime_enable() through a common error path and disable runtime PM before returning.
This issue was found by manual code inspection.
Patchwork: https://patchwork.freedesktop.org/patch/753043/
--- drivers/gpu/drm/msm/hdmi/hdmi_phy.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/hdmi/hdmi_phy.c +6 -2
@@ -161,13 +161,13 @@ static int msm_hdmi_phy_probe(struct pla ret =msm_hdmi_phy_resource_enable (phy);if (ret) -return ret; + goto err_pm_disable; ret =msm_hdmi_phy_pll_init (pdev, phy->cfg->type);if (ret) {DRM_DEV_ERROR (dev,"couldn't init PLL\n" );msm_hdmi_phy_resource_disable (phy); -return ret; + goto err_pm_disable; }msm_hdmi_phy_resource_disable (phy);
@@ -175,6 +175,10 @@ static int msm_hdmi_phy_probe(struct plaplatform_set_drvdata (pdev, phy);return 0 ; + +err_pm_disable: +pm_runtime_disable (dev); +return ret; }static int msm_hdmi_phy_remove (struct platform_device *pdev)
Greg Kroah-Hartman
maintainerPATCH 933/1193 smb: client: cancel reconnect work in clean_demultiplex_info()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit c65eae6f61d1778ff7a82e4aae4080e26f486af1 upstream.
clean_demultiplex_info() cancels server->echo delayed work but not server->reconnect, which can cause a use-after-free when the demultiplex thread exits while a reconnect work is still queued:
cifs_demultiplex_thread()
cifs_readv_from_socket()
cifs_reconnect()
__cifs_reconnect()
cifs_queue_server_reconn()
mod_delayed_work(cifsiod_wq, &server->reconnect, 0)
clean_demultiplex_info()
cancel_delayed_work_sync(&server->echo) // echo canceled
// reconnect NOT canceled
kfree_sensitive(server) // server freed ...later, on cifsiod_wq:
smb2_reconnect_server()
server->srv_count // UAF read of freed server
Fix this by canceling server->reconnect delayed work in clean_demultiplex_info() before the server is freed, the same way cifs_put_tcp_session() already does.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -998,6 +998,7 @@ clean_demultiplex_info(struct TCP_Serverspin_unlock (&server->srv_lock);cancel_delayed_work_sync (&server->echo); +cancel_delayed_work_sync (&server->reconnect);spin_lock (&server->srv_lock); server->tcpStatus = CifsExiting;
Greg Kroah-Hartman
maintainerPATCH 934/1193 smb: client: fix rlist race and missing initialization
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit 5f270f091256da1338c3631083e15d7f83cc05e1 upstream.
TCP_Server_Info.rlist is allocated via kzalloc which zeros both ->next and ->prev to NULL instead of pointing to itself, making list_empty() always return false and list_add() dereference a NULL ->prev pointer.
Also, cifs_signal_cifsd_for_reconnect() can be called concurrently from multiple cifsd threads, allowing the same server's rlist node to be added twice into the local list, corrupting it.
--- fs/smb/client/connect.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/smb/client/connect.c +7 -0
@@ -187,6 +187,8 @@ cifs_signal_cifsd_for_reconnect(struct T nserver = ses->chans[i].server;if (!nserver)continue ; +if (!list_empty (&nserver->rlist)) +continue ; nserver->srv_count++;list_add (&nserver->rlist, &reco); }
@@ -195,11 +197,15 @@ cifs_signal_cifsd_for_reconnect(struct T } } +spin_lock (&cifs_tcp_ses_lock);list_for_each_entry_safe (server, nserver, &reco, rlist) {list_del_init (&server->rlist);set_need_reco (server); +spin_unlock (&cifs_tcp_ses_lock);cifs_put_tcp_session (server,0 ); +spin_lock (&cifs_tcp_ses_lock); } +spin_unlock (&cifs_tcp_ses_lock); }/*
@@ -1784,6 +1790,7 @@ cifs_get_tcp_session(struct smb3_fs_contspin_lock_init (&tcp_ses->mid_lock);INIT_LIST_HEAD (&tcp_ses->tcp_ses_list);INIT_LIST_HEAD (&tcp_ses->smb_ses_list); +INIT_LIST_HEAD (&tcp_ses->rlist);INIT_DELAYED_WORK (&tcp_ses->echo, cifs_echo_request);INIT_DELAYED_WORK (&tcp_ses->reconnect, smb2_reconnect_server);mutex_init (&tcp_ses->reconnect_mutex);
Greg Kroah-Hartman
maintainerPATCH 935/1193 smb: client: reject short Next offsets in parse_server_interfaces()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 1b3221bb121079ad79a1f3c3aa360ba649832e7a upstream.
In parse_server_interfaces(), the server-supplied Next offset is validated against bytes_left, but not against the size of the interface structure itself.
A small, non-zero Next value can pass the bounds check but advance the pointer by less than sizeof(*p). This causes the next iteration of the loop to read misaligned, overlapping structure fields.
Fix this by ensuring the Next offset is at least sizeof(*p).
--- fs/smb/client/smb2ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/smb/client/smb2ops.c +3 -3
@@ -744,9 +744,9 @@ next_iface:break ; }/* Validate that Next doesn't point beyond the buffer */ -if (next > bytes_left) { -cifs_dbg (VFS ,"%s: invalid Next pointer %zu > %zd\n" , - __func__, next, bytes_left); +if (next <sizeof (*p) || next > bytes_left) { +cifs_dbg (VFS ,"%s: invalid Next pointer %zu out of range [%zu, %zd]\n" , + __func__, next,sizeof (*p), bytes_left); rc = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 936/1193 smb: client: fix smbd_connection leak on cifs_get_tcp_session() error
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
commit e75c96157d45e498970158c8f7373d90102e33b9 upstream.
When an RDMA connection is successfully established via smbd_get_connection() but cifs_get_tcp_session() later fails (e.g. kthread_create() returns an error), the error path frees tcp_ses without first destroying the smbd_connection.
Fix this by calling smbd_destroy() in the out_err cleanup path before kfree(tcp_ses). smbd_destroy() safely handles the case where smbd_conn is NULL, so it can be called unconditionally.
--- fs/smb/client/connect.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/connect.c +1 -0
@@ -1901,6 +1901,7 @@ out_err:kfree (tcp_ses->leaf_fullpath);if (tcp_ses->ssocket)sock_release (tcp_ses->ssocket); +smbd_destroy (tcp_ses);kfree (tcp_ses); }return ERR_PTR (rc);
Greg Kroah-Hartman
maintainerPATCH 937/1193 smb: client: fix next_buffer UAF and NextCommand bounds in compound PDUs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 05762c5bc1cfdcac36747994fde2c04387a457f1 upstream.
Fix several related bounds checking and pointer lifecycle issues in receive_encrypted_standard()'s handling of compound encrypted frames:
- Clear next_buffer after assigning it to server->bigbuf. A stale next_buffer pointer can lead to a use-after-free on subsequent error paths.
- Update pdu_length to the decrypted plaintext size (buf_size). Using the pre-decryption length allows NextCommand to point into stale ciphertext residue.
- Reject next_cmd values smaller than MID_HEADER_SIZE(server).
- Fix an integer overflow in the upper bound check by verifying pdu_length - next_cmd < MID_HEADER_SIZE(server), ensuring the trailing slice is large enough for a header.
--- fs/smb/client/smb2ops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +10 -1
@@ -4963,6 +4963,7 @@ receive_encrypted_standard(struct TCP_Se length =decrypt_raw_data (server, buf, buf_size,NULL , false);if (length)return length; + pdu_length = buf_size; next_is_large = server->large_buf; one_more:
@@ -4975,8 +4976,15 @@ one_more: }if (next_cmd) { -if (WARN_ON_ONCE (next_cmd > pdu_length)) +if (next_cmd <MID_HEADER_SIZE (server) || + next_cmd > pdu_length || + pdu_length - next_cmd <MID_HEADER_SIZE (server)) { +unsigned int max_next = pdu_length > (unsigned int )MID_HEADER_SIZE (server) ? + pdu_length - (unsigned int )MID_HEADER_SIZE (server) :0 ; +cifs_server_dbg (VFS ,"invalid NextCommand offset %u out of range [%zu, %u]\n" , + next_cmd,MID_HEADER_SIZE (server), max_next);return -1 ; + }if (next_is_large) next_buffer = (char *)cifs_buf_get ();else
@@ -5012,6 +5020,7 @@ one_more: server->bigbuf = buf = next_buffer; else server->smallbuf = buf = next_buffer; + next_buffer =NULL ; goto one_more; }else if (ret !=0 ) {/*
Greg Kroah-Hartman
maintainerPATCH 938/1193 smb: client: fix potential OOB read in smb3_enum_snapshots()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit 4775c3b7a597907e0b97556c7986fda238a377ae upstream.
If snapshot_array_size is smaller than GMT_TOKEN_SIZE, smb3_enum_snapshots() sets ret_data_len tosizeof(struct smb_snapshot_array) without verifying the actual length of the server's reply.
Because SMB2_ioctl() places no lower bound on the server-supplied OutputCount and allocates retbuf to exactly that length, a short reply results in ret_data_len exceeding the size of retbuf. The subsequent copy_to_user() then reads past the end of retbuf, leaking adjacent slab memory to userspace. The subsequent clamp check is ineffective as it only reduces ret_data_len.
Fix this by rejecting replies shorter thansizeof(struct smb_snapshot_array) with -EIO. Note that the bound is set to the 12-byte struct size rather than the 16-byte MIN_SNAPSHOT_ARRAY_SIZE defined in MS-SMB2 3.3.5.15.1, because 12 bytes is exactly what copy_to_user() attempts to read.
--- fs/smb/client/smb2ops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/client/smb2ops.c +7 -1
@@ -2190,8 +2190,14 @@ smb3_enum_snapshots(const unsigned int x* and retry the ioctl again with larger array size sufficient * to hold all of the snapshot GMT tokens on the second try. */ -if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) +if (snapshot_in.snapshot_array_size <GMT_TOKEN_SIZE ) { +if (ret_data_len <sizeof (struct smb_snapshot_array )) { + rc = -EIO ; +kfree (retbuf); +return rc; + } ret_data_len =sizeof (struct smb_snapshot_array ); + }/* * We return struct SRV_SNAPSHOT_ARRAY, followed by
Greg Kroah-Hartman
maintainerPATCH 939/1193 smb: client: fix server->total_read for compound encrypted PDUs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit f73726b83e4756fdaa099e1bc1143293bd57ad79 upstream.
In receive_encrypted_standard(), server->total_read is left at the full decrypted frame size when walking sub-PDUs of a compound encrypted frame. As a result, cifs_handle_standard() passes this full size to smb2_check_message(), causing the PDU length guards to incorrectly validate the entire compound frame instead of the current sub-PDU.
This allows truncated non-last sub-PDUs to bypass length validation, leading to out-of-bounds reads in smb2_get_data_area_len().
Fix this by setting server->total_read to the true length of the current sub-PDU: next_cmd for non-last sub-PDUs, and the remaining pdu_length for the last one.
--- fs/smb/client/smb2ops.c | 1 + 1 file changed, 1 insertion(+)
fs/smb/client/smb2ops.c +1 -0
@@ -4975,6 +4975,7 @@ receive_encrypted_standard(struct TCP_Se one_more: shdr = (struct smb2_hdr *)buf; next_cmd =le32_to_cpu (shdr->NextCommand); + server->total_read = next_cmd ? next_cmd : pdu_length;if (*num_mids >=MAX_COMPOUND ) {cifs_server_dbg (VFS ,"too many PDUs in compound\n" );
Greg Kroah-Hartman
maintainerPATCH 904/1193 hwmon: (hp-wmi-sensors) Fix use-after-free in fungible_show()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit e6cb0b4d4ecb8e71fd2200d907ab2e9663356f69 upstream.
nsensor->current_state is dynamically replaced as the sensor's state changes. update_numeric_sensor_from_wobj() does this by freeing the old string and installing a new one:
if (strcmp(trimmed, nsensor->current_state)) {
new_string = hp_wmi_strdup(dev, trimmed);
if (new_string) {
devm_kfree(dev, nsensor->current_state);
nsensor->current_state = new_string;
}
}This function is only ever called from hp_wmi_update_info() while state->lock is held, so the free-and-replace itself is properly serialized against concurrent updates.
fungible_show(), however, reads the same pointer after the lock has already been dropped:
err = hp_wmi_update_info(state, info);
if (err)
return err;
switch (prop) {
...
case HP_WMI_PROPERTY_CURRENT_STATE:
seq_printf(seqf, "%s\n", nsensor->current_state);
break;hp_wmi_update_info() takes state->lock internally and releases it before returning, so by the time fungible_show() dereferences nsensor->current_state in seq_printf(), no lock is held. Two processes reading a sensor's current_state debugfs entry at overlapping times (or one reading it while another read of the same sensor triggers a refresh) can race: one thread's seq_printf() can be part-way through printing the string at the moment another thread's call into update_numeric_sensor_from_wobj() frees it with devm_kfree() and installs a new pointer, causing a use-after-free read.
Take state->lock around the read in fungible_show() as well, so it can never run concurrently with the free-and-replace in update_numeric_sensor_from_wobj().
--- drivers/hwmon/hp-wmi-sensors.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/hp-wmi-sensors.c +2 -0
@@ -1247,7 +1247,9 @@ static int fungible_show(struct seq_filebreak ;case HP_WMI_PROPERTY_CURRENT_STATE : +mutex_lock (&state->lock);seq_printf (seqf,"%s\n" , nsensor->current_state); +mutex_unlock (&state->lock);break ;case HP_WMI_PROPERTY_UNIT_MODIFIER :
Greg Kroah-Hartman
maintainerPATCH 940/1193 smb: client: fix missing lower-bound check on DFS referral string offsets
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit e83330c55edc0c3ac08aa6c95e49e4694c65523b upstream.
parse_dfs_referrals() checks that DfsPathOffset and NetworkAddressOffset do not exceed the buffer end, but fails to check that they don't point inside the referral header itself.
If a server provides an offset smaller thansizeof(struct dfs_referral_level_3), the derived string pointer overlaps with the struct fields, causing cifs_strndup_from_utf16() to interpret header data as UTF-16 strings.
Fix this by enforcing that string offsets are at least sizeof(*ref).
--- fs/smb/client/misc.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
fs/smb/client/misc.c +10 -2
@@ -1056,7 +1056,11 @@ parse_dfs_referrals(struct get_dfs_refer node->ref_flag =le16_to_cpu (ref->ReferralEntryFlags);/* copy DfsPath */ -if (le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->DfsPathOffset) <sizeof (*ref) || +le16_to_cpu (ref->DfsPathOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: DfsPathOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->DfsPathOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
@@ -1070,7 +1074,11 @@ parse_dfs_referrals(struct get_dfs_refer }/* copy link target UNC */ -if (le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +if (le16_to_cpu (ref->NetworkAddressOffset) <sizeof (*ref) || +le16_to_cpu (ref->NetworkAddressOffset) > data_end - (char *)ref) { +cifs_dbg (VFS ,"%s: NetworkAddressOffset %u out of range [%zu, %td]\n" , + __func__,le16_to_cpu (ref->NetworkAddressOffset), +sizeof (*ref), data_end - (char *)ref); rc = -EINVAL ; goto parse_DFS_referrals_exit; }
Greg Kroah-Hartman
maintainerPATCH 941/1193 smb: client: fix missing iov bounds check in parse_posix_sids()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frank Sorenson <[email protected]>
commit b09d092eb24ad0110f16a9b7c1ed5d2a0c1733dc upstream.
In parse_posix_sids(), sidsbuf_end is calculated using the server-supplied out_len without being validated against the actual length of the received iov (iov_len).
If a server provides an inflated out_len, sidsbuf_end will point past the end of the iov. This defeats the bounds guards in posix_info_sid_size(), allowing out-of-bounds reads into adjacent kernel memory.
Fix this by rejecting responses where the calculated sidsbuf_end would exceed the received iov boundaries or cause pointer wraparound.
--- fs/smb/client/smb2inode.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
fs/smb/client/smb2inode.c +11 -0
@@ -71,6 +71,17 @@ static int parse_posix_sids(struct cifs_ sidsbuf = (u8 *)qi +le16_to_cpu (qi->OutputBufferOffset) + qi_len; sidsbuf_end = sidsbuf + out_len - qi_len; +if (sidsbuf_end < sidsbuf) { +cifs_dbg (VFS ,"%s: server-supplied out_len %u caused pointer wraparound\n" , + __func__, out_len); +return -EINVAL ; + } +if (sidsbuf_end > (u8 *)rsp_iov->iov_base + rsp_iov->iov_len) { +cifs_dbg (VFS ,"%s: server-supplied out_len %u overruns iov by %td bytes\n" , + __func__, out_len, + sidsbuf_end - ((u8 *)rsp_iov->iov_base + rsp_iov->iov_len)); +return -EINVAL ; + } owner_len =posix_info_sid_size (sidsbuf, sidsbuf_end);if (owner_len ==-1 )
Greg Kroah-Hartman
maintainerPATCH 942/1193 ipv6: mcast: Use in6_dev_get() in ipv6_dev_mc_dec().
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit e01b193e0b50ae849bf60067e111446f19ee2f20 ]
As well as __ipv6_dev_mc_inc(), all code in __ipv6_dev_mc_dec() are protected by inet6_dev->mc_lock, and RTNL is not needed.
Let's use in6_dev_get() in ipv6_dev_mc_dec() and remove ASSERT_RTNL() in __ipv6_dev_mc_dec().
Now, we can remove the RTNL comment above addrconf_leave_solict() too.
--- net/ipv6/addrconf.c | 3 +-- net/ipv6/mcast.c | 14 ++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-)
net/ipv6/addrconf.c +1 -2
@@ -2226,12 +2226,11 @@ void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr)ipv6_dev_mc_inc (dev, &maddr); } -/* caller must hold RTNL */ void addrconf_leave_solict (struct inet6_dev *idev,const struct in6_addr *addr) {struct in6_addr maddr; -if (idev->dev->flags&(IFF_LOOPBACK |IFF_NOARP )) +if (READ_ONCE (idev->dev->flags) & (IFF_LOOPBACK |IFF_NOARP ))return ;addrconf_addr_solict_mult (addr, &maddr);
net/ipv6/mcast.c +6 -8
@@ -971,9 +971,8 @@ int __ipv6_dev_mc_dec(struct inet6_dev *idev, const struct in6_addr *addr) {struct ifmcaddr6 *ma,__rcu **map; -ASSERT_RTNL (); -mutex_lock (&idev->mc_lock); +for (map = &idev->mc_list; (ma =mc_dereference (*map, idev)); map = &ma->next) {
@@ -1002,13 +1001,12 @@ int ipv6_dev_mc_dec(struct net_device *dev, const struct in6_addr *addr)struct inet6_dev *idev;int err; -ASSERT_RTNL (); - - idev =__in6_dev_get (dev); + idev =in6_dev_get (dev);if (!idev) - err = -ENODEV ; -else - err =__ipv6_dev_mc_dec (idev, addr); +return -ENODEV ; + + err =__ipv6_dev_mc_dec (idev, addr); +in6_dev_put (idev);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 943/1193 ipv6: mcast: Dont hold RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 1767bb2d47b715a106287a8f963d9ec6cbab4e69 ]
In __ipv6_sock_mc_join(), per-socket mld data is protected by lock_sock(), and only __dev_get_by_index() requires RTNL.
Let's use dev_get_by_index() and drop RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.
Note that we must call rt6_lookup() and dev_hold() under RCU.
If rt6_lookup() returns an entry from the exception table, dst_dev_put() could change rt->dev.dst to loopback concurrently, and the original device could lose the refcount before dev_hold() and unblock device registration.
dst_dev_put() is called from NETDEV_UNREGISTER and synchronize_net() follows it, so as long as rt6_lookup() and dev_hold() are called within the same RCU critical section, the dev is alive.
Even if the race happens, they are synchronised by idev->dead and mcast addresses are cleaned up.
For the racy access to rt->dst.dev, we use dst_dev().
--- net/ipv6/ipv6_sockglue.c | 2 -- net/ipv6/mcast.c | 24 +++++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-)
net/ipv6/ipv6_sockglue.c +0 -2
@@ -121,11 +121,9 @@ static bool setsockopt_needs_rtnl(int optname) {switch (optname) {case IPV6_ADDRFORM : -case IPV6_ADD_MEMBERSHIP :case IPV6_DROP_MEMBERSHIP :case IPV6_JOIN_ANYCAST :case IPV6_LEAVE_ANYCAST : -case MCAST_JOIN_GROUP :case MCAST_LEAVE_GROUP :case MCAST_JOIN_SOURCE_GROUP :case MCAST_LEAVE_SOURCE_GROUP :
net/ipv6/mcast.c +13 -11
@@ -172,14 +172,12 @@ static int unsolicited_report_interval(struct inet6_dev *idev)static int __ipv6_sock_mc_join (struct sock *sk,int ifindex,const struct in6_addr *addr,unsigned int mode) { -struct net_device *dev =NULL ; -struct ipv6_mc_socklist *mc_lst;struct ipv6_pinfo *np =inet6_sk (sk); +struct ipv6_mc_socklist *mc_lst;struct net *net =sock_net (sk); +struct net_device *dev =NULL ;int err; -ASSERT_RTNL (); -if (!ipv6_addr_is_multicast (addr))return -EINVAL ;
@@ -199,13 +197,18 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,if (ifindex ==0 ) {struct rt6_info *rt; + +rcu_read_lock (); rt =rt6_lookup (net, addr,NULL ,0 ,NULL ,0 );if (rt) { - dev = rt->dst.dev; + dev =dst_dev (&rt->dst); +dev_hold (dev);ip6_rt_put (rt); } - }else - dev =__dev_get_by_index (net, ifindex); +rcu_read_unlock (); + }else { + dev =dev_get_by_index (net, ifindex); + }if (!dev) {sock_kfree_s (sk, mc_lst,sizeof (*mc_lst));
@@ -216,12 +219,11 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex, mc_lst->sfmode = mode;RCU_INIT_POINTER (mc_lst->sflist,NULL ); -/* -* now add/increase the group membership on the device -*/ - +/* now add/increase the group membership on the device */ err =__ipv6_dev_mc_inc (dev, addr, mode); +dev_put (dev); +if (err) {sock_kfree_s (sk, mc_lst,sizeof (*mc_lst));return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 944/1193 ipv6: mcast: Dont hold RTNL for IPV6_DROP_MEMBERSHIP and MCAST_LEAVE_GROUP.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit 2ceb71ce7d34e751f91bbca9da3513a2bc29089c ]
In __ipv6_sock_mc_drop(), per-socket mld data is protected by lock_sock(), and only __dev_get_by_index() and __in6_dev_get() require RTNL.
Let's use dev_get_by_index() and in6_dev_get() and drop RTNL for IPV6_ADD_MEMBERSHIP and MCAST_JOIN_GROUP.
Note that __ipv6_sock_mc_drop() is factorised to reuse in the next patch.
--- net/ipv6/ipv6_sockglue.c | 2 -- net/ipv6/mcast.c | 47 +++++++++++++++++++++++----------------- 2 files changed, 27 insertions(+), 22 deletions(-)
net/ipv6/ipv6_sockglue.c +0 -2
@@ -121,10 +121,8 @@ static bool setsockopt_needs_rtnl(int optname) {switch (optname) {case IPV6_ADDRFORM : -case IPV6_DROP_MEMBERSHIP :case IPV6_JOIN_ANYCAST :case IPV6_LEAVE_ANYCAST : -case MCAST_LEAVE_GROUP :case MCAST_JOIN_SOURCE_GROUP :case MCAST_LEAVE_SOURCE_GROUP :case MCAST_BLOCK_SOURCE :
net/ipv6/mcast.c +27 -20
64 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 945/1193 ipv6: mcast: Dont hold RTNL for MCAST_ socket options.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit e6e14d582dd2cbee362c48a1865f8d03ca0a5611 ]
In ip6_mc_source() and ip6_mc_msfilter(), per-socket mld data is protected by lock_sock() and inet6_dev->mc_lock is also held for some per-interface functions.
ip6_mc_find_dev_rtnl() only depends on RTNL. If we want to remove it, we need to check inet6_dev->dead under mc_lock to close the race with addrconf_ifdown(), as mentioned earlier.
Let's do that and drop RTNL for the rest of MCAST_ socket options.
Note that ip6_mc_msfilter() has unnecessary lock dances and they are integrated into one to avoid the last-minute error and simplify the error handling.
--- net/ipv6/ipv6_sockglue.c | 5 --- net/ipv6/mcast.c | 74 ++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 34 deletions(-)
net/ipv6/ipv6_sockglue.c +0 -5
@@ -123,11 +123,6 @@ static bool setsockopt_needs_rtnl(int optname)case IPV6_ADDRFORM :case IPV6_JOIN_ANYCAST :case IPV6_LEAVE_ANYCAST : -case MCAST_JOIN_SOURCE_GROUP : -case MCAST_LEAVE_SOURCE_GROUP : -case MCAST_BLOCK_SOURCE : -case MCAST_UNBLOCK_SOURCE : -case MCAST_MSFILTER :return true; }return false;
net/ipv6/mcast.c +45 -29
169 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 946/1193 ipv6: mcast: use copy-on-write RCU updates in ip6_mc_source()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c073d1b070f171d206b19c98d71739a97f15b3f1 ]
pmc->sflist is read locklessly under rcu_read_lock() by inet6_mc_check() during packet reception in the UDP and RAW multicast receive paths.
ip6_mc_source() mutated psl->sl_addr and psl->sl_count in-place when adding or removing a source filter. Additionally, when expanding the filter buffer, newpsl was published via rcu_assign_pointer() before writing the new source into the array.
Because 16-byte struct in6_addr writes are not atomic and array shifting is not synchronized with RCU readers, concurrent readers in inet6_mc_check() could read torn IPv6 addresses or observe duplicated/missed source entries.
Fix this by switching ip6_mc_source() to copy-on-write RCU updates:
allocate and fully populate newpsl before publishing it via rcu_assign_pointer(), and reclaim the old filter via kfree_rcu(), matching ip6_mc_msfilter().
Also remove the now unused IP6_SFBLOCK macro.
--- include/net/if_inet6.h | 2 - net/ipv6/mcast.c | 98 ++++++++++++++++++++++++------------------ 2 files changed, 56 insertions(+), 44 deletions(-)
include/net/if_inet6.h +0 -2
@@ -88,8 +88,6 @@ struct ip6_sf_socklist {struct in6_addr sl_addr[]; }; -#define IP6_SFBLOCK 10/* allocate this many at once */ -struct ipv6_mc_socklist {struct in6_addr addr;int ifindex;
net/ipv6/mcast.c +56 -42
139 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 947/1193 ipv6: mcast: fix RCU list diversion in ip6_mc_del1_src()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 93b49239840b91313adbd77b8b52993eff2d08c1 ]
When removing a source filter whose count reaches zero, ip6_mc_del1_src() unlinks psf from pmc->mca_sources. If the filter was previously active, the code moved psf directly into pmc->mca_tomb by updating psf->sf_next.
Because pmc->mca_sources is traversed locklessly under RCU (e.g. by ipv6_chk_mcast_addr()), mutating psf->sf_next before a grace period elapses diverts concurrent readers to the tombstone list. Consequently, readers miss remaining active sources in pmc->mca_sources and improperly examine deleted tombstone entries.
Fix this by allocating a new tombstone node for pmc->mca_tomb (as done in sf_setstate()) and retiring the original psf via kfree_rcu().
--- net/ipv6/mcast.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
net/ipv6/mcast.c +11 -7
@@ -2367,14 +2367,18 @@ static int ip6_mc_del1_src(struct ifmcaddr6 *pmc, int sfmode,if (psf->sf_oldin && !(pmc->mca_flags &MAF_NOREPORT ) && !mld_in_v1_mode (idev)) { - psf->sf_crcount = idev->mc_qrv; -rcu_assign_pointer (psf->sf_next, -mc_dereference (pmc->mca_tomb, idev)); -rcu_assign_pointer (pmc->mca_tomb, psf); - rv =1 ; - }else { -kfree_rcu (psf, rcu); +struct ip6_sf_list *dpsf =kmalloc (sizeof (*dpsf),GFP_KERNEL ); + +if (dpsf) { + *dpsf = *psf; + dpsf->sf_crcount = idev->mc_qrv; +rcu_assign_pointer (dpsf->sf_next, +mc_dereference (pmc->mca_tomb, idev)); +rcu_assign_pointer (pmc->mca_tomb, dpsf); + rv =1 ; + } } +kfree_rcu (psf, rcu); }return rv; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 905/1193 hwmon: (pmbus/core) increase number of phases and add new mask
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nuno Sá <[email protected]>
commit 06bd6794b5fd2163880ac3bfe973d4cc61f359f3 upstream.
Increase the number of phases to 16 as a new upcoming device supports such a number.
While at it, add a new mask for controlling the source of the output voltage.
Note (groeck):
This patch was meant to prepare for support of MAX20826 and compatible devices, which support more than 10 phases per page. However, Sashiko reports that the mp2975 driver already supports up to 14 phases, and the mp2856 driver supports up to 12 phases. This already has the potential for out-of-bounds writes when probing the affected chips, making this patch a bug fix.
--- drivers/hwmon/pmbus/pmbus.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/pmbus/pmbus.h +2 -1
@@ -241,6 +241,7 @@ enum pmbus_regs {/* * OPERATION */ +#define PB_OPERATION_CONTROL_V_SRC GENMASK(5, 4)#define PB_OPERATION_CONTROL_ON BIT(7)/*
@@ -376,7 +377,7 @@ enum pmbus_sensor_classes { };#define PMBUS_PAGES 32/* Per PMBus specification */ -#define PMBUS_PHASES 10/* Maximum number of phases per page */ +#define PMBUS_PHASES 16/* Maximum number of phases per page */ /* Functionality bit mask */ #define PMBUS_HAVE_VIN BIT(0)
Greg Kroah-Hartman
maintainerPATCH 906/1193 hwmon: (pmbus/tps53679) Fix TPS53676 phase page decoding
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 1d12fb94ac0975566545871dda100df34df5f845 upstream.
tps53676_identify() reads the USER_DATA_03 phase configuration to count the phases assigned to each channel and derive the number of PMBus pages. In each 16-bit phase descriptor the channel (PAGE) is encoded in bit 4 and the firing order in bits 3:0, but the code tested bit 3 (0x08), which is part of the firing-order field.
TPS53676 supports up to seven phases, so firing-order bit 3 is never set. As a result the existing test classifies every enabled phase as channel A. On a dual-channel configuration the phases assigned to channel B are therefore miscounted as channel A and page 1 is not exposed.
Test the PAGE field (bit 4) instead.
--- drivers/hwmon/pmbus/tps53679.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/tps53679.c +1 -1
@@ -168,7 +168,7 @@ static int tps53676_identify(struct i2c_return -EIO ;for (i =0 ; i <2 *TPS53676_MAX_PHASES ; i +=2 ) {if (buf[i +1 ] &0x80 ) { -if (buf[i] &0x08 ) +if (buf[i] &BIT (4 )) phases_b++;else phases_a++;
Greg Kroah-Hartman
maintainerPATCH 907/1193 hwmon: (pmbus/tps53679) Select page 0 for single-page TPS53676
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanman Pradhan <[email protected]>
commit 089070b51ccbac411462a30a454690274c6e4270 upstream.
tps53676_identify() derives the number of PMBus pages but does not ensure that page 0 is selected for single-page configurations. pmbus_set_page() does not update the PAGE register when info->pages is 1, so if boot firmware leaves PAGE set to another value subsequent register accesses may target the wrong page.
For single-page devices, select page 0 explicitly.
--- drivers/hwmon/pmbus/tps53679.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/hwmon/pmbus/tps53679.c +9 -0
@@ -181,6 +181,15 @@ static int tps53676_identify(struct i2c_if (phases_b >0 ) { info->pages =2 ; info->phases[1 ] = phases_b; + }else { +/* +* pmbus_set_page() does not update the PAGE register on +* single-page devices, so select page 0 explicitly in case +* the boot firmware left the device on another page. +*/ + ret =i2c_smbus_write_byte_data (client,PMBUS_PAGE ,0 ); +if (ret <0 ) +return ret; }return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 908/1193 hwmon: (w83791d) remove fan/pwm 4-5 sysfs group on remove
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit 0ff9c7775e51ac6d47b1bb5c46f06b1434fe58a8 upstream.
When the fan/pwm 4-5 pins are not used as GPIO, w83791d_probe() creates the w83791d_group_fanpwm45 sysfs group on the I2C client device.
The probe error path removes this group when a later initialization step fails, but the normal remove path only removes w83791d_group. As a result, the optional fan/pwm 4-5 sysfs files can remain after the driver is unbound.
The callbacks associated with these files access the driver data, which is devm allocated and released after driver unbind. Leaving the sysfs files behind can therefore result in accesses to stale driver data.
Remove w83791d_group_fanpwm45 during normal teardown as well.
This issue was found by manual code inspection.
--- drivers/hwmon/w83791d.c | 1 + 1 file changed, 1 insertion(+)
drivers/hwmon/w83791d.c +1 -0
@@ -1415,6 +1415,7 @@ static void w83791d_remove(struct i2c_clstruct w83791d_data *data =i2c_get_clientdata (client);hwmon_device_unregister (data->hwmon_dev); +sysfs_remove_group (&client->dev.kobj, &w83791d_group_fanpwm45);sysfs_remove_group (&client->dev.kobj, &w83791d_group); }
Greg Kroah-Hartman
maintainerPATCH 909/1193 hwmon: (w83793) release probe data through kref
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit c702a5f18b780e477eccbbab558e590e9673e4cb upstream.
w83793_probe() initializes data->kref to manage the lifetime of the driver data. The normal remove path drops the driver-owned reference with kref_put(), while watchdog users take and release additional references through the same kref.
However, the probe error path still frees data directly with kfree(). This bypasses the kref-managed lifetime and discards the initial reference without a matching kref_put(), leaving the reference accounting unbalanced.
Drop the probe-owned reference with kref_put() instead and let w83793_release_resources() perform the final free, matching the normal remove path.
This issue was found by manual code inspection.
--- drivers/hwmon/w83793.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwmon/w83793.c +3 -1
@@ -1929,7 +1929,9 @@ exit_remove:for (i =0 ; i <ARRAY_SIZE (w83793_temp); i++)device_remove_file (dev, &w83793_temp[i].dev_attr); free_mem: -kfree (data); +mutex_lock (&watchdog_data_mutex); +kref_put (&data->kref, w83793_release_resources); +mutex_unlock (&watchdog_data_mutex); exit:return err; }
Greg Kroah-Hartman
maintainerPATCH 900/1193 Input: soc_button_array - check btns_desc->package.count
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit fb5022278b6ea7f1838e3ef78028d5d5e3375f65 upstream.
Check that btns_desc->package.count is not 0 before accessing btns_desc->package.elements[0].
--- drivers/input/misc/soc_button_array.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/misc/soc_button_array.c +1 -1
@@ -377,7 +377,7 @@ static struct soc_button_info *soc_butto } } -if (!btns_desc) { +if (!btns_desc || !btns_desc->package.count) {dev_err (dev,"ACPI Button Descriptors not found\n" ); button_info =ERR_PTR (-ENODEV ); goto out;
Greg Kroah-Hartman
maintainerPATCH 949/1193 spi: spi-zynqmp-gqspi: stop the controller on shutdown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Itai Handler <[email protected]>
commit e922bad8b2d5028c51a096d083fea41cd0987154 upstream.
The driver has no ->shutdown, and platform_drv_shutdown() has no fallback of its own. Unlike pci_device_shutdown(), which clears bus mastering when kexec_in_progress, nothing on the platform bus disarms a device that can still write to memory. The normal kexec path never calls ->suspend either, so the quiesce in zynqmp_qspi_suspend() is not reached.
A controller that is still executing a DMA read may therefore keep writing to memory across a kexec. QSPIDMA_DST_ADDR still points at memory owned by the kernel that called kexec, DST_SIZE is non-zero and the flash is still clocked, so data can keep landing in RAM while the new kernel is being relocated, and after it has started executing.
That destination is a physical address which means nothing to the new kernel, so the writes can corrupt whatever now occupies it: kernel text or data, page tables, or the initrd. Nothing reports an error and the resulting behaviour is undefined.
This can be observed by reading GQSPI_EN (offset 0x114) and QSPIDMA_DST_ADDR/SIZE/STS/CTRL (offsets 0x800 to 0x80c) early in the new kernel, before the driver probes: without this patch GQSPI_EN reads 1 and QSPIDMA_DST_ADDR still points into the previous kernel's memory.
Add a ->shutdown that stops the controller the way zynqmp_qspi_suspend() already does. spi_controller_suspend() stops the queue, waits for a message that is already executing and makes any later transfer fail with -ESHUTDOWN, so nothing can be cut short by the register write that follows. It may sleep, which is fine here: device_shutdown() runs in process context. Unlike ->suspend this cannot abort on error, because a controller left mastering the bus is worse than a truncated transfer, so a failure to drain is only logged.
GQSPI_EN_OFST is then cleared, as zynqmp_qspi_remove() and zynqmp_qspi_suspend() already do. Skip that write only when pm_runtime_get_if_in_use() returns 0, i.e. runtime suspended: the clocks are gated, so the registers are unreachable and the controller cannot be mastering the bus. A negative return is not the same thing - it is what the CONFIG_PM=n stub always returns, and there probe() has enabled pclk and refclk for good, so the controller is running and must be stopped.
[ itai: context only - the platform_driver callback is still spelled
.remove_new in this tree, renamed back to .remove upstream by commit 494c3dc46776 ("spi: Switch back to struct platform_driver::remove()") ]
--- drivers/spi/spi-zynqmp-gqspi.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
drivers/spi/spi-zynqmp-gqspi.c +34 -0
@@ -1377,11 +1377,45 @@ static void zynqmp_qspi_remove(struct platform_device *pdev)clk_disable_unprepare (xqspi->pclk); } +static void zynqmp_qspi_shutdown (struct platform_device *pdev) +{ +struct zynqmp_qspi *xqspi =platform_get_drvdata (pdev); +int ret; + +/* +* Stop the queue and reject any later transfer first, so the write +* below cannot cut into a message that is still being executed. +* Unlike ->suspend this cannot abort on error: a controller left +* mastering the bus is worse than a truncated transfer. +*/ + ret =spi_controller_suspend (xqspi->ctlr); +if (ret) +dev_warn (&pdev->dev,"could not stop the queue: %d\n" , ret); + +/* +* Only a runtime suspended controller can be left alone: its clocks +* are gated, so it cannot be mastering the bus, and its registers +* must not be accessed either. Any other answer means it may be +* running and has to be stopped. In particular, on a kernel built +* without runtime PM this returns -EINVAL, and there the clocks +* enabled in probe() are never gated at all. +*/ + ret =pm_runtime_get_if_in_use (&pdev->dev); +if (!ret) +return ; + +zynqmp_gqspi_write (xqspi,GQSPI_EN_OFST ,0x0 ); + +if (ret >0 ) +pm_runtime_put_noidle (&pdev->dev); +} +MODULE_DEVICE_TABLE (of, zynqmp_qspi_of_match);static struct platform_driver zynqmp_qspi_driver = { .probe = zynqmp_qspi_probe, .remove_new = zynqmp_qspi_remove, + .shutdown = zynqmp_qspi_shutdown, .driver = { .name ="zynqmp-qspi" , .of_match_table = zynqmp_qspi_of_match,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 958/1193 remoteproc: qcom_q6v5_adsp: Fix iommu_unmap() usage
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mostafa Saleh <[email protected]>
[ Upstream commit 0d8e2195bce6f08c1c53c5ef4d7347fe46418101 ]
During adsp_map_carveout, the IOVA is computed by combining the physical address and the SID:
iova = adsp->mem_phys | (sid << 32);
However, adsp_unmap_carveout() uses the physical address and not the IOVA in iommu_unmap(), causing the unmap to fail or leak mappings because the address doesn't match the original IOVA.
Cache the constructed IOVA within the qcom_adsp device struct during mapping and use it during unmapping.
--- drivers/remoteproc/qcom_q6v5_adsp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/remoteproc/qcom_q6v5_adsp.c +4 -4
@@ -105,6 +105,7 @@ struct qcom_adsp {struct completion stop_done;phys_addr_t mem_phys; +unsigned long iova;phys_addr_t mem_reloc;void *mem_region;size_t mem_size;
@@ -340,7 +341,7 @@ static void adsp_unmap_carveout(struct rproc *rproc)struct qcom_adsp *adsp = rproc->priv;if (adsp->has_iommu) -iommu_unmap (rproc->domain, adsp->mem_phys, adsp->mem_size); +iommu_unmap (rproc->domain, adsp->iova, adsp->mem_size); }static int adsp_map_carveout (struct rproc *rproc)
@@ -348,7 +349,6 @@ static int adsp_map_carveout(struct rproc *rproc)struct qcom_adsp *adsp = rproc->priv;struct of_phandle_args args;long long sid; -unsigned long iova;int ret;if (!adsp->has_iommu)
@@ -365,9 +365,9 @@ static int adsp_map_carveout(struct rproc *rproc)of_node_put (args.np);/* Add SID configuration for ADSP Firmware to SMMU */ - iova = adsp->mem_phys | (sid <<32 ); + adsp->iova = adsp->mem_phys | (sid <<32 ); - ret =iommu_map (rproc->domain, iova, adsp->mem_phys, + ret =iommu_map (rproc->domain, adsp->iova, adsp->mem_phys, adsp->mem_size,IOMMU_READ |IOMMU_WRITE ,GFP_KERNEL );if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 959/1193 KVM: s390: Fix IRQ injection with SIGP Stop and Store Status
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudio Imbrenda <[email protected]>
[ Upstream commit d343407b728a80b74be3c24b59f15e60289ea527 ]
When __inject_sigp_stop() is called for a Stop and Store Status operation, if the vCPU is running, the interrupt is marked as pending and the status is stored by the thread performing the KVM_RUN IOCTL.
If the vCPU is already stopped, the status is stored immediately.
Storing the status means writing into userspace, which might fault, and __inject_sigp_stop() is called from do_inject_vcpu() which in turn is always called holding a spinlock, which is obviously an issue.
Fix this by returning -EWOULDBLOCK from __inject_sigp_stop(), and adding a bool flag to indicate whether a store status is needed. The callers of do_inject_vcpu() are modified to pass the pointer to the bool flag; whenever a Store Status operation is needed, the callers can now perform it outside the spinlock.
Opportunistically refactor kvm_s390_set_irq_state() to use scoped_guard() and __free().
Message-ID: <[email protected]>
--- arch/s390/kvm/interrupt.c | 70 +++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 32 deletions(-)
arch/s390/kvm/interrupt.c +38 -32
@@ -1586,23 +1586,21 @@ static int __inject_set_prefix(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) }#define KVM_S390_STOP_SUPP_FLAGS (KVM_S390_STOP_FLAG_STORE_STATUS) -static int __inject_sigp_stop (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) +static int __inject_sigp_stop (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq,bool *storestatus) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int;struct kvm_s390_stop_info *stop = &li->irq.stop; -int rc =0 ; vcpu->stat.inject_stop_signal++;trace_kvm_s390_inject_vcpu (vcpu->vcpu_id,KVM_S390_SIGP_STOP ,0 ,0 );if (irq->u.stop.flags & ~KVM_S390_STOP_SUPP_FLAGS )return -EINVAL ; -if (is_vcpu_stopped (vcpu)) { -if (irq->u.stop.flags &KVM_S390_STOP_FLAG_STORE_STATUS ) - rc =kvm_s390_store_status_unloaded (vcpu, -KVM_S390_STORE_STATUS_NOADDR ); -return rc; +if (!(irq->u.stop.flags &KVM_S390_STOP_FLAG_STORE_STATUS )) +return 0 ; + *storestatus = true; +return -EWOULDBLOCK ; }if (test_and_set_bit (IRQ_PEND_SIGP_STOP , &li->pending_irqs))
@@ -2142,7 +2140,7 @@ void kvm_s390_clear_stop_irq(struct kvm_vcpu *vcpu)spin_unlock (&li->lock); } -static int do_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) +static int do_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq,bool *storestatus) {int rc;
@@ -2154,7 +2152,7 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq) rc =__inject_set_prefix (vcpu, irq);break ;case KVM_S390_SIGP_STOP : - rc =__inject_sigp_stop (vcpu, irq); + rc =__inject_sigp_stop (vcpu, irq, storestatus);break ;case KVM_S390_RESTART : rc =__inject_sigp_restart (vcpu);
@@ -2190,11 +2188,16 @@ static int do_inject_vcpu(struct kvm_vcpu *vcpu, struct kvm_s390_irq *irq)int kvm_s390_inject_vcpu (struct kvm_vcpu *vcpu,struct kvm_s390_irq *irq) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; +bool storestatus = false;int rc;spin_lock (&li->lock); - rc =do_inject_vcpu (vcpu, irq); + rc =do_inject_vcpu (vcpu, irq, &storestatus);spin_unlock (&li->lock); + +if (rc == -EWOULDBLOCK && storestatus) + rc =kvm_s390_store_status_unloaded (vcpu,KVM_S390_STORE_STATUS_NOADDR ); +if (!rc)kvm_s390_vcpu_wakeup (vcpu);return rc;
@@ -2930,7 +2933,8 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm,int kvm_s390_set_irq_state (struct kvm_vcpu *vcpu,void __user *irqstate,int len) {struct kvm_s390_local_interrupt *li = &vcpu->arch.local_int; -struct kvm_s390_irq *buf; + struct kvm_s390_irq *buf __free(kvfree) = NULL; +bool tmp, storestatus = false;int r =0 ;int n;
@@ -2938,31 +2942,33 @@ int kvm_s390_set_irq_state(struct kvm_vcpu *vcpu, void __user *irqstate, int lenif (!buf)return -ENOMEM ; -if (copy_from_user ((void *) buf, irqstate, len)) { - r = -EFAULT ; - goto out_free; - } +if (copy_from_user ((void *)buf, irqstate, len)) +return -EFAULT ; -/* -* Don't allow setting the interrupt state -* when there are already interrupts pending -*/ -spin_lock (&li->lock); -if (li->pending_irqs) { - r = -EBUSY ; - goto out_unlock; - } + scoped_guard(spinlock, &li->lock) { +/* +* Don't allow setting the interrupt state +* when there are already interrupts pending +*/ +if (li->pending_irqs) +return -EBUSY ; -for (n =0 ; n < len /sizeof (*buf); n++) { - r =do_inject_vcpu (vcpu, &buf[n]); -if (r) -break ; +for (n =0 ; n < len /sizeof (*buf); n++) { + tmp = false; + r =do_inject_vcpu (vcpu, &buf[n], &tmp); +if (r == -EWOULDBLOCK && tmp) { + storestatus = true; + r =0 ; + } +if (r) +break ; + } } -out_unlock: -spin_unlock (&li->lock); -out_free: -vfree (buf); +if (storestatus) { + n =kvm_s390_store_status_unloaded (vcpu,KVM_S390_STORE_STATUS_NOADDR ); +return r ? r : n; + }return r; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 960/1193 bpf: Fix bpf_skb_change_tail wrt csum partial skbs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daniel Borkmann <[email protected]>
[ Upstream commit 3b55f350c68a0aceff108f47f9d31f47ebffaf7b ]
Cilium generates ICMP "frag needed" replies from BPF when a LB DSR packet exceeds the egress MTU. The reply is built by first trimming the packet down to target size via bpf_skb_change_tail(), and then pushing the ICMP error headers in front of it.
The trim is rejected for skbs which carry a checksum offload, e.g. TCP packets aggregated by GRO on ingress where tcp_gro_complete() leaves the skb as CHECKSUM_PARTIAL. __bpf_skb_min_len() raises the minimum length to the end of the L4 checksum field, so a trim to 42 bytes bails out with -EINVAL given a min_len of 52 in this case, and due to that the ICMP generator fails. This is not the case if GRO is turned off.
Fix this bpf_skb_change_tail() restriction and drop the checksum offload when the new length no longer covers the checksum field. The BPF program rewrites the skb into an ICMP error and computes the checksum itself anyway.
--- net/core/filter.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
net/core/filter.c +5 -6
@@ -3808,12 +3808,6 @@ static u32 __bpf_skb_min_len(const struct sk_buff *skb)if (offset >0 ) min_len = offset; } -if (skb->ip_summed ==CHECKSUM_PARTIAL ) { - offset =skb_checksum_start_offset (skb) + - skb->csum_offset +sizeof (__sum16); -if (offset >0 ) - min_len = offset; - }return min_len; }
@@ -3830,6 +3824,11 @@ static int bpf_skb_grow_rcsum(struct sk_buff *skb, unsigned int new_len)static int bpf_skb_trim_rcsum (struct sk_buff *skb,unsigned int new_len) { +if (skb->ip_summed ==CHECKSUM_PARTIAL && + new_len <skb_checksum_start_offset (skb) + skb->csum_offset + +sizeof (__sum16)) + skb->ip_summed =CHECKSUM_NONE ; +return __skb_trim_rcsum (skb, new_len); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 961/1193 bpf: Disallow bpf_skb_pull_data() for LWT_SEG6LOCAL
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit e4a62833adff6ef0fe7c0b90393204fe3c26b5c5 ]
An LWT_SEG6LOCAL program can invalidate its cached SRH with bpf_lwt_seg6_adjust_srh() and then call bpf_skb_pull_data(). The latter may reallocate skb->head, leaving the per-CPU SRH pointer dangling. Post-program SRH validation then writes through that pointer.
Disallow bpf_skb_pull_data() for LWT_SEG6LOCAL programs so the verifier rejects this unsafe helper combination. Other LWT program types continue to expose the helper through lwt_out_func_proto().
--- net/core/filter.c | 2 ++ 1 file changed, 2 insertions(+)
net/core/filter.c +2 -0
@@ -8599,6 +8599,8 @@ static const struct bpf_func_proto * lwt_seg6local_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) { switch (func_id) { + case BPF_FUNC_skb_pull_data: + return NULL;#if IS_ENABLED (CONFIG_IPV6_SEG6_BPF )case BPF_FUNC_lwt_seg6_store_bytes:return &bpf_lwt_seg6_store_bytes_proto;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 962/1193 selftests/ftrace: Fix unique symbol check in kprobe_non_uniq_symbol.tc
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Schnelle <[email protected]>
[ Upstream commit d22c3e0088e85be8131f7a9283f759cdbb20726d ]
The current regex also matches symbols in modules, which makes the test fail on s390 where name_show is present only once in the kernel, but also multiple times in modules:
000001b1401cdc20 t name_show000001b0c05e6c40 t name_show [mdev]000001b0c0495f30 t name_show [i2c_core]
Fix this by changing the regular expression to only match the function name.
--- .../selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/test.d/kprobe/kprobe_non_uniq_symbol.tc +1 -1
@@ -6,7 +6,7 @@ SYMBOL='name_show' # We skip this test on kernel where SYMBOL is unique or does not exist. -if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}" /proc/kallsyms)" -le '1' ]; then +if [ "$(grep -c -E "[[:alnum:]]+ t ${SYMBOL}$" /proc/kallsyms)" -le '1' ]; then exit_unsupported fi
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 963/1193 bpf: Fix divide-by-zero in btf_struct_walk()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit b0b3dc66529676228cb938cbcad66920f735c223 ]
When an access goes past the struct and the last member is a flexible array, btf_struct_walk() folds the offset back into a single element with (off - moff) % t->size, but never checks that the element type has a size.
BTF takes an empty struct, so this in program BTF
/* event could be empty */
struct event {
#ifdef HAVE_TIMESTAMP
__u64 ts;
#endif
};
struct batch {
int nr;
struct event events[];
};divides by zero at prog load time. Getting there needs a PTR_TO_BTF_ID that is not MEM_ALLOC, e.g. a plain read of a local kptr stashed in a map from a sleepable program.
Oops: divide error: 0000 [#1] SMP KASAN PTI RIP: 0010:btf_struct_walk+0x53f/0x1570 Call Trace: <TASK> btf_struct_access+0x42a/0xcd0 check_ptr_to_btf_access+0x4dc/0x1160 check_mem_access+0x3a45/0x8740 check_load_mem+0x36a/0xd10 do_check_common+0x3ef0/0xb210 bpf_check+0x6d3b/0x8580 bpf_prog_load+0xf7c/0x2720 __sys_bpf+0xa83/0x3690 __x64_sys_bpf+0xc7/0x150 x64_sys_call+0x1f3f/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
Reject a zero-sized element type. The fixed array path in the same function already bails out on the same thing:
btf_struct_walk() ... /* skip empty array */ if (moff == mtrue_end) continue; msize /= total_nelems;
--- kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
@@ -6212,7 +6212,7 @@ static int btf_struct_walk(struct bpf_verifier_log *log, const struct btf *btf,if (btf_type_is_int (t))return WALK_SCALAR ; -if (!btf_type_is_struct (t)) +if (!btf_type_is_struct (t) || !t->size) goto error; off = (off - moff) % t->size;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 964/1193 bpf: Fix out-of-bounds read of sk_protocol in bpf_sock_destroy()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 01b245ba016d44861690594e10f67e026ce8552f ]
sk_protocol lives in struct sock, not in struct sock_common. A timewait or request sock handed to bpf_sock_destroy() by the tcp iterator is neither, so reading sk->sk_protocol runs past the object:
==================================================================
BUG: KASAN: slab-out-of-bounds in bpf_sock_destroy+0xc7/0xe0 Read of size 2 at addr ffff8881047d11b4 by task test_progs/428 Tainted: [W]=WARN Call Trace: <TASK> dump_stack_lvl+0x91/0xf0 print_report+0xd1/0x630 kasan_report+0xf3/0x130 __asan_report_load2_noabort+0x14/0x30 bpf_sock_destroy+0xc7/0xe0 bpf_prog_c3dd61f9d9cd9f37_iter_tcp6_timewait+0x9f/0xb7 bpf_iter_run_prog+0x538/0xde0 bpf_iter_tcp_seq_show+0x26b/0x4b0 bpf_seq_read+0x424/0x1210 vfs_read+0x197/0xe40 ksys_read+0x119/0x240 __x64_sys_read+0x72/0xc0 x64_sys_call+0x647/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e
Only check sk_protocol on full socks. tcp_abort() already knows how to deal with TIME_WAIT and NEW_SYN_RECV socks. Also fix the comment, it never matched the code.
--- net/core/filter.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
net/core/filter.c +9 -4
@@ -12071,8 +12071,9 @@ __diag_ignore_all("-Wmissing-prototypes",* @sock: Pointer to socket to be destroyed * * Return: -* On error, may return EPROTONOSUPPORT, EINVAL. -* EPROTONOSUPPORT if protocol specific destroy handler is not supported. +* On error, may return EOPNOTSUPP, or whatever the protocol specific +* destroy handler returns. +* EOPNOTSUPP if protocol specific destroy handler is not supported. * 0 otherwise */ __bpf_kfunc int bpf_sock_destroy(struct sock_common *sock)
@@ -12084,8 +12085,12 @@ __bpf_kfunc int bpf_sock_destroy(struct sock_common *sock)* Supporting protocols will need to acquire sock lock in the BPF context * prior to invoking this kfunc. */ -if (!sk->sk_prot->diag_destroy || (sk->sk_protocol !=IPPROTO_TCP && - sk->sk_protocol !=IPPROTO_UDP )) +if (!sk->sk_prot->diag_destroy) +return -EOPNOTSUPP ; + +if (sk_fullsock (sk) && + sk->sk_protocol !=IPPROTO_TCP && + sk->sk_protocol !=IPPROTO_UDP )return -EOPNOTSUPP ;return sk->sk_prot->diag_destroy (sk,ECONNABORTED );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 965/1193 tcp: Skip cond_resched() in inet_csk_listen_stop() under BPF context
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit eaab8cab451b9502ce224cd202550375b894a467 ]
bpf_sock_destroy() runs from the tcp iterator, under rcu_read_lock(). If the sock is a listener that still has children in its accept queue, tcp_abort() ends up in inet_csk_listen_stop() and the cond_resched() there trips the debug check:
BUG: sleeping function called from invalid context at net/ipv4/inet_connection_sock.c:1523
in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 628, name: test_progspreempt_count: 0, expected: 0
RCU nest depth: 1, expected: 0
locks held by test_progs/628: 3, last CPU#3:
#0: ffff8881158cee18 (&p->lock){+.+.}-{4:4}, at: bpf_seq_read+0x56/0x1210 #1: ffff8881106bb858 (sk_lock-AF_INET6){+.+.}-{0:0}, at: bpf_iter_tcp_seq_show+0x32b/0x4b0 #2: ffffffffb435af20 (rcu_read_lock){....}-{1:3}, at: bpf_iter_run_prog+0x46b/0xde0
CPU: 3 UID: 0 PID: 628 Comm: test_progs Tainted: G W 7.2.0+ #65 PREEMPT Tainted: [W]=WARN Call Trace: <TASK> dump_stack_lvl+0xc1/0xf0 dump_stack+0x10/0x20 __might_resched+0x3d2/0x610 inet_csk_listen_stop+0x7b/0xbf0 tcp_abort+0x23b/0x3b0 bpf_sock_destroy+0xfc/0x140 bpf_prog_448133d24601754f_iter_tcp6_server+0x81/0x8a bpf_iter_run_prog+0x538/0xde0 bpf_iter_tcp_seq_show+0x26b/0x4b0 bpf_seq_read+0x424/0x1210 vfs_read+0x197/0xe40 ksys_read+0x119/0x240 __x64_sys_read+0x72/0xc0 x64_sys_call+0x647/0x27e0 do_syscall_64+0xe5/0x610 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7fad39b28aca RSP: 002b:00007ffc381c61c0 EFLAGS: 00000246 ORIG_RAX: 0000000000000000 RAX: ffffffffffffffda RBX: 00007ffc381c6a88 RCX: 00007fad39b28aca RDX: 0000000000000032 RSI: 00007ffc381c6250 RDI: 0000000000000014 RBP: 00007ffc381c61e0 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003 R13: 0000000000000000 R14: 000055f077c1bbb0 R15: 00007fad3a0f3000 </TASK>
The commit that added the kfunc already guards lock_sock() in tcp_abort() and udp_abort() with has_current_bpf_ctx(), but missed the listener path. Do the same for the cond_resched(). The loop runs inside the iterator's rcu_read_lock(), it must not reschedule or report a quiescent state there.
--- net/ipv4/inet_connection_sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv4/inet_connection_sock.c +2 -1
@@ -1478,7 +1478,8 @@ void inet_csk_listen_stop(struct sock *sk)local_bh_enable ();sock_put (child); -cond_resched (); +if (!has_current_bpf_ctx ()) +cond_resched (); }if (queue->fastopenq.rskq_rst_head) {/* Free all the reqs queued in rskq_rst_head. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 966/1193 HID: elecom: fix bus type for M-XGL20DLBK
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oscar Priego Verdugo <[email protected]>
[ Upstream commit 8e2a4b458ad25e13422bb059758c30a6562aa9cf ]
The M-XGL20DLBK is matched as a USB device by hid-elecom, but its entry in hid_have_special_driver[] uses HID_BLUETOOTH_DEVICE.
This prevents the special-driver quirk entry from matching the USB device handled by hid-elecom. Use HID_USB_DEVICE there as well.
--- drivers/hid/hid-quirks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hid/hid-quirks.c +1 -1
@@ -416,7 +416,7 @@ static const struct hid_device_id hid_have_special_driver[] = {#endif #if IS_ENABLED(CONFIG_HID_ELECOM) { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_BM084) }, - { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XGL20DLBK) }, { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_HT1MRBK_01AC) }, { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_00FB) }, { HID_USB_DEVICE(USB_VENDOR_ID_ELECOM, USB_DEVICE_ID_ELECOM_M_XT3URBK_018F) },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 967/1193 bpf: Avoid soft lockup in __htab_map_lookup_and_delete_batch()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Fernandez (Anthropic) <[email protected]>
[ Upstream commit 85136bf22404474a815fc0ed26ec0d1cbc1bc3f9 ]
__htab_map_lookup_and_delete_batch() has no rescheduling point. The batch count bounds how many entries are copied out, not how many buckets are visited, so one BPF_MAP_LOOKUP_BATCH call can walk the map end to end. The empty-bucket fast path is worse: it stays inside a single rcu_read_lock() / bpf_disable_instrumentation() section for any run of consecutive empty buckets.
That holds up on small maps, but it falls apart at scale. On a 144-CPU arm64 host running a CONFIG_PREEMPT_NONE kernel, periodic BPF_MAP_LOOKUP_BATCH calls against an LRU hash map with 16,777,216 buckets held a CPU inside the batch op for 77+ seconds and triggered the soft lockup watchdog.
Commit 75134f16e7dd ("bpf: Add schedule points in batch ops") fixed this same problem in the generic batch ops, but not in this htab-native path, which every htab-based hash map variant uses for its lookup[_and_delete] batch ops.
Complete that fix here. Leave the critical section after 64 consecutive empty buckets, call cond_resched_tasks_rcu_qs(), and resume at the saved bucket cursor. No locks are held at that point, and resuming from the cursor is already the function's behavior for non-empty buckets. Add the same call to the per-bucket loop after copy_to_user(), where every lock has been dropped. cond_resched_rcu() is not enough here: sleeping with bpf_prog_active elevated makes tracing programs on that CPU silently skip their invocations.
Plain cond_resched() is not enough either. It is a no-op under PREEMPT and PREEMPT_LAZY, the only models arm64 and x86 have offered since commit 7dadeaa6e851 ("sched: Further restrict the preemption modes"). It is also never a Tasks RCU quiescent state, in any model: the reschedule counts as a preemption. The walking task stays a holdout and stalls every synchronize_rcu_tasks() caller, ftrace and BPF trampoline teardown included, until the syscall returns [1]. cond_resched_tasks_rcu_qs() is the usual tool for that [2]. It reports the quiescent state at each yield and still reschedules as cond_resched() does on PREEMPT_NONE and PREEMPT_VOLUNTARY kernels.
--- kernel/bpf/hashtab.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-)
kernel/bpf/hashtab.c +21 -3
@@ -1695,6 +1695,12 @@ static int htab_lru_percpu_map_lookup_and_delete_elem(struct bpf_map *map, flags); } +/* +* Max consecutive empty buckets to walk in one RCU + +* instrumentation-disabled section before rescheduling. +*/ +#define HTAB_BATCH_EMPTY_RESCHED 64 + static int __htab_map_lookup_and_delete_batch(struct bpf_map *map, const union bpf_attr *attr,
@@ -1716,6 +1722,7 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map,unsigned long flags =0 ;bool locked = false;struct htab_elem *l; +u32 empty_cnt =0 ;struct bucket *b;int ret =0 ;
@@ -1885,12 +1892,21 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, } next_batch: -/* If we are not copying data, we can go to next bucket and avoid -* unlocking the rcu. +/* +* If we are not copying data, we can go to next bucket and avoid +* unlocking the rcu. Bound the walk though: after +* HTAB_BATCH_EMPTY_RESCHED consecutive empty buckets, fully exit +* the critical section (no locks are held here) and reschedule. */ if (!bucket_cnt && (batch +1 < htab->n_buckets)) { batch++; - goto again_nocopy; +if (++empty_cnt <HTAB_BATCH_EMPTY_RESCHED ) + goto again_nocopy; + empty_cnt =0 ; +rcu_read_unlock (); +bpf_enable_instrumentation (); +cond_resched_tasks_rcu_qs (); + goto again; }rcu_read_unlock ();
@@ -1904,11 +1920,13 @@ __htab_map_lookup_and_delete_batch(struct bpf_map *map, } total += bucket_cnt; + empty_cnt =0 ; batch++;if (batch >= htab->n_buckets) { ret = -ENOENT ; goto after_loop; } +cond_resched_tasks_rcu_qs (); goto again; after_loop:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 950/1193 selftests/landlock: Add layout1.refer_mount_root
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mickaël Salaün <[email protected]>
[ Upstream commit 0055f53aac80fd938bf7cdfad7ad414ca6c0e198 ]
Add tests to check error codes when linking or renaming a mount root directory. This previously triggered a kernel warning, but it is fixed with the previous commit.
--- tools/testing/selftests/landlock/fs_test.c | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
tools/testing/selftests/landlock/fs_test.c +50 -0
@@ -23,6 +23,12 @@#include <sys/vfs.h> #include <unistd.h> +/* +* Intentionally included last to work around header conflict. +* See https://sourceware.org/glibc/wiki/Synchronizing_Headers. +*/ +#include <linux/mount.h> +#include "common.h" #ifndef renameat2
@@ -34,6 +40,13 @@ int renameat2(int olddirfd, const char * }#endif +#ifndef open_tree +int open_tree (int dfd,const char *filename,unsigned int flags) +{ +return syscall (__NR_open_tree, dfd, filename, flags); +} +#endif +#ifndef RENAME_EXCHANGE #define RENAME_EXCHANGE (1 << 1)#endif
@@ -2486,6 +2499,43 @@ TEST_F_FORK(layout1, refer_denied_by_def layer_dir_s1d1_refer); } +/* +* Tests walking through a denied root mount. +*/ +TEST_F_FORK(layout1, refer_mount_root_deny) +{ +const struct landlock_ruleset_attr ruleset_attr = { + .handled_access_fs =LANDLOCK_ACCESS_FS_MAKE_DIR , + }; +int root_fd, ruleset_fd; + +/* Creates a mount object from a non-mount point. */ +set_cap (_metadata,CAP_SYS_ADMIN ); + root_fd = +open_tree (AT_FDCWD , dir_s1d1, +AT_EMPTY_PATH |OPEN_TREE_CLONE |OPEN_TREE_CLOEXEC ); +clear_cap (_metadata,CAP_SYS_ADMIN ); +ASSERT_LE (0 , root_fd); + + ruleset_fd = +landlock_create_ruleset (&ruleset_attr,sizeof (ruleset_attr),0 ); +ASSERT_LE (0 , ruleset_fd); + +ASSERT_EQ (0 ,prctl (PR_SET_NO_NEW_PRIVS ,1 ,0 ,0 ,0 )); +ASSERT_EQ (0 ,landlock_restrict_self (ruleset_fd,0 )); +EXPECT_EQ (0 ,close (ruleset_fd)); + +/* Link denied by Landlock: EACCES. */ +EXPECT_EQ (-1 ,linkat (root_fd,"." , root_fd,"does_not_exist" ,0 )); +EXPECT_EQ (EACCES , errno); + +/* renameat2() always returns EBUSY. */ +EXPECT_EQ (-1 ,renameat2 (root_fd,"." , root_fd,"does_not_exist" ,0 )); +EXPECT_EQ (EBUSY , errno); + +EXPECT_EQ (0 ,close (root_fd)); +} + TEST_F_FORK(layout1, reparent_link) {const struct rule layer1[] = {
Greg Kroah-Hartman
maintainerPATCH 968/1193 bpf: Fix out-of-bounds read of rtt_min in sock_ops
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 75f8cf22463d82bb1fb0239a3d485fc8f4c8ef03 ]
A sockops prog reading skops->rtt_min never checks the sk type: on the tcp_conn_request() path sock_ops->sk is a request_sock (non-full), and the ctx rewrite casts it to a tcp_sock (full) and reads rtt_min past the end of the request_sock, returning dirty adjacent memory.
SEC("sockops")
int prog(struct bpf_sock_ops *skops)
{
switch (skops->op) {
case BPF_SOCK_OPS_RWND_INIT:
leak = skops->rtt_min; /* reads the request_sock OOB */
...
}
}For instance one such read returned rtt_min=0xffff8881, the high half of a leaked kernel pointer.
Guarding that cast is exactly what SOCK_OPS_GET_FIELD() does -- it checks is_locked_tcp_sock and returns 0 when sock_ops->sk is not a locked full socket. Every other tcp_sock field in sock_ops goes through it; rtt_min is the only one open-coded, so it skips the check.
Read rtt_min through SOCK_OPS_GET_FIELD() too. rtt_min is a bit special:
it is a struct minmax and we only want the current min, so pass rtt_min.s[0].v. That is equivalent to the old hand-computed offset
offsetof(struct tcp_sock, rtt_min) + sizeof_field(struct minmax_sample, t)
(s[0] sits at rtt_min + 0 and .v at + sizeof(.t), i.e. what minmax_get() returns), so the loaded field is unchanged and only the full-sock guard is added. The two BUILD_BUG_ON()s that protected the hand-computed offset are no longer needed.
Before patch:
0: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk 1: r1 = *(u32 *)(r1 +2324) ; ((tcp_sock *)sk)->rtt_min.s[0].v
After patch:
0: *(u64 *)(r1 +56) = r9 1: r9 = *(u8 *)(r1 +50) ; is_locked_tcp_sock 2: if r9 == 0 goto pc+4 ; not a locked full sock -> 0 3: r9 = *(u64 *)(r1 +56) 4: r1 = *(u64 *)(r1 +0) ; r1 = skops->sk 5: r1 = *(u32 *)(r1 +2324) ; rtt_min.s[0].v 6: goto pc+2 7: r9 = *(u64 *)(r1 +56) 8: r1 = 0
--- net/core/filter.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
net/core/filter.c +1 -12
@@ -10651,18 +10651,7 @@ static u32 sock_ops_convert_ctx_access(enum bpf_access_type type,break ;case offsetof(struct bpf_sock_ops , rtt_min): - BUILD_BUG_ON(sizeof_field(struct tcp_sock, rtt_min) != - sizeof(struct minmax)); -BUILD_BUG_ON (sizeof (struct minmax ) < -sizeof (struct minmax_sample )); - - *insn++ =BPF_LDX_MEM (BPF_FIELD_SIZEOF ( - struct bpf_sock_ops_kern, sk), - si->dst_reg, si->src_reg, - offsetof(struct bpf_sock_ops_kern , sk)); - *insn++ =BPF_LDX_MEM (BPF_W , si->dst_reg, si->dst_reg, - offsetof(struct tcp_sock , rtt_min) + - sizeof_field(struct minmax_sample, t)); + SOCK_OPS_GET_FIELD(rtt_min, rtt_min.s[0].v, struct tcp_sock);break ;case offsetof(struct bpf_sock_ops , bpf_sock_ops_cb_flags):
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 969/1193 bpf, sockmap: Fix self-redirect copied_seq double-counting
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Geliang Tang <[email protected]>
[ Upstream commit 490a83d6386eec1d29f470c8d7331677fb46c3b7 ]
When a BPF stream_verdict program redirects an skb back to the same socket (self-redirect with BPF_F_INGRESS), sk_psock_verdict_apply() calls tcp_eat_skb() which advances tcp_sk->copied_seq. However, the skb is then delivered to the socket's psock ingress queue and later read by tcp_bpf_recvmsg_parser(), which also advances copied_seq via the copied_from_self accounting path. This double-counting causes copied_seq to advance by 2x the actual data length, triggering:
TCP recvmsg seq # bug 2: copied BF2E806, seq BF2E7FD, \ rcvnxt BF2E806, fl 0 WARNING: net/ipv4/tcp.c:2745 at tcp_recvmsg_locked+0x72b/0x2640 Call Trace: tcp_recvmsg+0x10a/0x500 sock_recvmsg+0x168/0x1d0 __sys_recvfrom+0x19a/0x2a0 __x64_sys_recvfrom+0xe4/0x1f0 do_syscall_64+0xf7/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f
cleanup rbuf bug: copied BF2E806 seq BF2E806 rcvnxt BF2E806
WARNING: net/ipv4/tcp.c:1609 at tcp_cleanup_rbuf+0xf2/0x1c0 Call Trace: tcp_recvmsg_locked+0x8d1/0x2640 tcp_recvmsg+0x10a/0x500 sock_recvmsg+0x168/0x1d0 __sys_recvfrom+0x19a/0x2a0 __x64_sys_recvfrom+0xe4/0x1f0 do_syscall_64+0xf7/0x530 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Fix this by converting self-redirect verdict to __SK_PASS at the beginning of sk_psock_verdict_apply(). This bypasses the __SK_REDIRECT case entirely (which calls sk_psock_eat_skb), letting the __SK_PASS path queue the skb to the psock ingress queue. The data is then read via tcp_bpf_recvmsg_parser(), which advances copied_seq exactly once through copied_from_self. Cross-socket redirects continue through __SK_REDIRECT with sk_psock_eat_skb() unchanged.
--- net/core/skmsg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/core/skmsg.c +4 -0
@@ -1035,6 +1035,10 @@ static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb,int err =0 ;u32 len, off; +if (verdict == __SK_REDIRECT &&skb_bpf_ingress (skb) && +skb_bpf_redirect_fetch (skb) == psock->sk) + verdict = __SK_PASS; +switch (verdict) {case __SK_PASS: err = -EIO ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 970/1193 pinctrl: meson: Fix typo in s4 group name
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Anderson <[email protected]>
[ Upstream commit 692f32609a30f75ca3401e25b504bfd06bd5662a ]
One of the i2c pin groups has some junk at the end. The name should be i2c2_scl_h1, and indeed that's the name used by i2c2_pins3 in meson-s4.dtsi.
--- drivers/pinctrl/meson/pinctrl-meson-s4.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/meson/pinctrl-meson-s4.c +1 -1
@@ -854,7 +854,7 @@ static const char * const i2c1_groups[] = {static const char *const i2c2_groups[] = {"i2c2_sda_d" ,"i2c2_scl_d" ,"i2c2_sda_h8" ,"i2c2_scl_h9" , -"i2c2_sda_h0" ,"i2c2_scl_h1l," +"i2c2_sda_h0" ,"i2c2_scl_h1" , };static const char *const i2c3_groups[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 971/1193 HID: amd_sfh: Validate PCI BAR size before mapping
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Slawomir Stepien <[email protected]>
[ Upstream commit 65bcc5f89704efe5b9d69d4ea2c1002d90c31382 ]
The amd_sfh driver maps PCI BAR 2 using pcim_iomap_regions() and subsequently accesses MMIO registers at offsets up to 0x10958 (e.g., AMD_P2C_MSG3 at 0x1068C). However, the driver never validates that the BAR size is large enough to cover these accesses. If the driver is bound to a device with a smaller BAR 2, this leads to an out-of-bounds memory access and a page fault during the probe function.
For example, a page fault can occur when reading from privdata->mmio + AMD_P2C_MSG3 in mp2_select_ops():
BUG: unable to handle page fault for address: ffffc9000390368c PGD 100000067 P4D 100000067 PUD 1012c1067 PMD 105b64067 PTE 0 Oops: Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:readl arch/x86/include/asm/io.h:59 [inline] RIP: 0010:mp2_select_ops drivers/hid/amd-sfh-hid/amd_sfh_pcie.c:282 [inline] RIP: 0010:amd_mp2_pci_probe+0x337/0x5f0 drivers/hid/amd-sfh-hid/amd_sfh_pcie.c:487 Call Trace: <TASK> local_pci_probe drivers/pci/pci-driver.c:332 [inline] pci_call_probe drivers/pci/pci-driver.c:394 [inline] __pci_device_probe drivers/pci/pci-driver.c:455 [inline] pci_device_probe+0x431/0xc90 drivers/pci/pci-driver.c:489
Fix this by verifying that the length of BAR 2 is at least 128KB before attempting to map it. Since the maximum accessed offset is 0x10958, and PCI BAR sizes are powers of 2, any legitimate hardware will have a BAR size of at least 128KB.
--- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 4 ++++ drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
drivers/hid/amd-sfh-hid/amd_sfh_common.h +4 -0
@@ -11,11 +11,15 @@#define AMD_SFH_COMMON_H #include <linux/pci.h> +#include <linux/sizes.h> #include "amd_sfh_hid.h" #define PCI_DEVICE_ID_AMD_MP2 0x15E4#define PCI_DEVICE_ID_AMD_MP2_1_1 0x164A +/* The BAR 2 size must cover the highest register offset (0x10958) */ +#define AMD_SFH_MIN_BAR_SIZE SZ_128K +#define AMD_C2P_MSG (regno) (0x10500 + ((regno) * 4))#define AMD_P2C_MSG (regno) (0x10680 + ((regno) * 4))
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +10 -0
@@ -349,6 +349,16 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *iif (rc)return rc; +if (!(pci_resource_flags (pdev,2 ) &IORESOURCE_MEM )) { +dev_err (&pdev->dev,"BAR 2 is not IORESOURCE_MEM\n" ); +return -ENODEV ; + } + +if (pci_resource_len (pdev,2 ) <AMD_SFH_MIN_BAR_SIZE ) { +dev_err (&pdev->dev,"BAR 2 is too small\n" ); +return -EINVAL ; + } + rc =pcim_iomap_regions (pdev,BIT (2 ),DRIVER_NAME );if (rc)return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 972/1193 KVM: arm64: vgic-its: Add stronger type-checking to the ITS entry sizes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marc Zyngier <[email protected]>
[ Upstream commit 3b2c81d5feb250dfdcb0ef5825319f36c29f8336 ]
The ITS ABI infrastructure allows for some pretty lax code, where the size of the data doesn't have to match the size of the entry, potentially leading to a collection of interesting bugs.
Commit 7fe28d7e68f9 ("KVM: arm64: vgic-its: Add a data length check in vgic_its_save_*") added some checks, but starts by implicitly casting all writes to a 64bit value, hiding some of the issues.
Instead, introduce macros that will check the data type actually used for dealing with the table entries. The macros are taking a symbolic entry type that is used to fetch the size of the entry type for the current ABI. This immediately catches a couple of low-impact gotchas (zero values that are implicitly 32bit), easy enough to fix.
Given that we currently only have a single ABI, hardcode a couple of BUILD_BUG_ON()s that will fire if we use anything but a 64bit quantity, and some (currently unreachable) fallback code that may become useful one day.
Stable-dep-of: cc5d96036e01 ("KVM: arm64: vgic-its: Skip unreachable devices instead of failing the save")
--- arch/arm64/kvm/vgic/vgic-its.c | 68 +++++++++++++++++++++++++--------- arch/arm64/kvm/vgic/vgic.h | 23 ------------ 2 files changed, 50 insertions(+), 41 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +50 -18
@@ -29,6 +29,41 @@ static int vgic_its_commit_v0(struct vgic_its *its);static int update_lpi_config (struct kvm *kvm,struct vgic_irq *irq,struct kvm_vcpu *filter_vcpu,bool needs_inv); +#define vgic_its_read_entry_lock (i, g, valp, t) \ + ({ \ + int __sz = vgic_its_get_abi(i)->t##_esz; \ + struct kvm *__k = (i)->dev->kvm; \ + int __ret; \ + \ + BUILD_BUG_ON(NR_ITS_ABIS == 1 && \ + sizeof(*(valp)) != ABI_0_ESZ); \ + if (NR_ITS_ABIS > 1 && \ + KVM_BUG_ON(__sz != sizeof(*(valp)), __k)) \ + __ret = -EINVAL; \ + else \ + __ret = kvm_read_guest_lock(__k, (g), \ + valp, __sz); \ + __ret; \ + }) + +#define vgic_its_write_entry_lock (i, g, val, t) \ + ({ \ + int __sz = vgic_its_get_abi(i)->t##_esz; \ + struct kvm *__k = (i)->dev->kvm; \ + typeof(val) __v = (val); \ + int __ret; \ + \ + BUILD_BUG_ON(NR_ITS_ABIS == 1 && \ + sizeof(__v) != ABI_0_ESZ); \ + if (NR_ITS_ABIS > 1 && \ + KVM_BUG_ON(__sz != sizeof(__v), __k)) \ + __ret = -EINVAL; \ + else \ + __ret = vgic_write_guest_lock(__k, (g), \ + &__v, __sz); \ + __ret; \ + }) +/* * Creates a new (reference to a) struct vgic_irq for a given LPI. * If this LPI is already mapped on another ITS, we increase its refcount
@@ -869,7 +904,7 @@ static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its,its_free_ite (kvm, ite); -return vgic_its_write_entry_lock (its, gpa,0 , ite_esz); +return vgic_its_write_entry_lock (its, gpa,0ULL , ite); }return E_ITS_DISCARD_UNMAPPED_INTERRUPT ;
@@ -1217,7 +1252,6 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,bool valid =its_cmd_get_validbit (its_cmd);u8 num_eventid_bits =its_cmd_get_size (its_cmd);gpa_t itt_addr =its_cmd_get_ittaddr (its_cmd); -int dte_esz =vgic_its_get_abi (its)->dte_esz;struct its_device *device;gpa_t gpa;
@@ -1242,7 +1276,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its,* is an error, so we are done in any case. */ if (!valid) -return vgic_its_write_entry_lock (its, gpa,0 , dte_esz); +return vgic_its_write_entry_lock (its, gpa,0ULL , dte); device =vgic_its_alloc_device (its, device_id, itt_addr, num_eventid_bits);
@@ -2213,7 +2247,7 @@ static int scan_its_table(struct vgic_its *its, gpa_t base, int size, u32 esz,* vgic_its_save_ite - Save an interrupt translation entry at @gpa */ static int vgic_its_save_ite (struct vgic_its *its,struct its_device *dev, -struct its_ite *ite,gpa_t gpa,int ite_esz) +struct its_ite *ite,gpa_t gpa) {u32 next_offset;u64 val;
@@ -2224,7 +2258,7 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev, ite->collection->collection_id; val =cpu_to_le64 (val); -return vgic_its_write_entry_lock (its, gpa, val, ite_esz); +return vgic_its_write_entry_lock (its, gpa, val, ite); }/**
@@ -2322,7 +2356,7 @@ static int vgic_its_save_itt(struct vgic_its *its, struct its_device *device)if (ite->irq->hw && !kvm_vgic_global_state.has_gicv4_1)return -EACCES ; - ret =vgic_its_save_ite (its, device, ite, gpa, ite_esz); + ret =vgic_its_save_ite (its, device, ite, gpa);if (ret)return ret; }
@@ -2363,7 +2397,7 @@ static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)* @ptr: GPA */ static int vgic_its_save_dte (struct vgic_its *its,struct its_device *dev, -gpa_t ptr,int dte_esz) +gpa_t ptr) {u64 val, itt_addr_field;u32 next_offset;
@@ -2376,7 +2410,7 @@ static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev, (dev->num_eventid_bits - 1)); val =cpu_to_le64 (val); -return vgic_its_write_entry_lock (its, ptr, val, dte_esz); +return vgic_its_write_entry_lock (its, ptr, val, dte); }/**
@@ -2456,10 +2490,8 @@ static int vgic_its_device_cmp(void *priv, const struct list_head *a,*/ static int vgic_its_save_device_tables (struct vgic_its *its) { -const struct vgic_its_abi *abi =vgic_its_get_abi (its);u64 baser = its->baser_device_table;struct its_device *dev; -int dte_esz = abi->dte_esz;if (!(baser &GITS_BASER_VALID ))return 0 ;
@@ -2478,7 +2510,7 @@ static int vgic_its_save_device_tables(struct vgic_its *its)if (ret)return ret; - ret =vgic_its_save_dte (its, dev, eaddr, dte_esz); + ret =vgic_its_save_dte (its, dev, eaddr);if (ret)return ret; }
@@ -2559,7 +2591,7 @@ static int vgic_its_restore_device_tables(struct vgic_its *its)static int vgic_its_save_cte (struct vgic_its *its,struct its_collection *collection, -gpa_t gpa,int esz) +gpa_t gpa) {u64 val;
@@ -2568,7 +2600,7 @@ static int vgic_its_save_cte(struct vgic_its *its, collection->collection_id); val =cpu_to_le64 (val); -return vgic_its_write_entry_lock (its, gpa, val, esz); +return vgic_its_write_entry_lock (its, gpa, val, cte); }/*
@@ -2576,7 +2608,7 @@ static int vgic_its_save_cte(struct vgic_its *its,* Return +1 on success, 0 if the entry was invalid (which should be * interpreted as end-of-table), and a negative error value for generic errors. */ -static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa,int esz) +static int vgic_its_restore_cte (struct vgic_its *its,gpa_t gpa) {struct its_collection *collection;struct kvm *kvm = its->dev->kvm;
@@ -2584,7 +2616,7 @@ static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, int esz)u64 val;int ret; - ret =vgic_its_read_entry_lock (its, gpa, &val, esz); + ret =vgic_its_read_entry_lock (its, gpa, &val, cte);if (ret)return ret; val =le64_to_cpu (val);
@@ -2631,7 +2663,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its) max_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ;list_for_each_entry (collection, &its->collection_list, coll_list) { - ret =vgic_its_save_cte (its, collection, gpa, cte_esz); + ret =vgic_its_save_cte (its, collection, gpa);if (ret)return ret; gpa += cte_esz;
@@ -2645,7 +2677,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its)* table is not fully filled, add a last dummy element * with valid bit unset */ -return vgic_its_write_entry_lock (its, gpa,0 , cte_esz); +return vgic_its_write_entry_lock (its, gpa,0ULL , cte); }/**
@@ -2670,7 +2702,7 @@ static int vgic_its_restore_collection_table(struct vgic_its *its) max_size =GITS_BASER_NR_PAGES (baser) *SZ_64K ;while (read < max_size) { - ret =vgic_its_restore_cte (its, gpa, cte_esz); + ret =vgic_its_restore_cte (its, gpa);if (ret <=0 )break ; gpa += cte_esz;
arch/arm64/kvm/vgic/vgic.h +0 -23
@@ -145,29 +145,6 @@ static inline int vgic_write_guest_lock(struct kvm *kvm, gpa_t gpa,return ret; } -static inline int vgic_its_read_entry_lock (struct vgic_its *its,gpa_t eaddr, -u64 *eval,unsigned long esize) -{ -struct kvm *kvm = its->dev->kvm; - -if (KVM_BUG_ON (esize !=sizeof (*eval), kvm)) -return -EINVAL ; - -return kvm_read_guest_lock (kvm, eaddr, eval, esize); - -} - -static inline int vgic_its_write_entry_lock (struct vgic_its *its,gpa_t eaddr, -u64 eval,unsigned long esize) -{ -struct kvm *kvm = its->dev->kvm; - -if (KVM_BUG_ON (esize !=sizeof (eval), kvm)) -return -EINVAL ; - -return vgic_write_guest_lock (kvm, eaddr, &eval, esize); -} -/* * This struct provides an intermediate representation of the fields contained * in the GICH_VMCR and ICH_VMCR registers, such that code exporting the GIC
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 973/1193 KVM: arm64: vgic-its: Skip unreachable devices instead of failing the save
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit cc5d96036e01ac330d24b2f0c336d60f82ab4930 ]
vgic_its_save_device_tables() aborts with -EINVAL when a device's entry falls outside the device table, which a guest can arrange on its own: an indirect table lets it clear an L1 entry's valid bit without touching GITS_BASER. That fails a save userspace should be able to issue reliably.
Skip the device instead, and point the saved DTE chain past it, as commit ad1e686e2378d ("KVM: arm64: vgic-its: Point saved ITEs at the next valid entry") does for ITEs. compute_next_devid_offset() takes the next device off the list whether or not it was saved, so the predecessor would otherwise point at an entry the save never wrote. Restore follows that offset while it stays inside the table being scanned: within an L2 block, or anywhere in a flat table. Both need userspace to remove a memslot under the table, since dropping an L1 entry takes the whole block with it and scan_its_table() stops at the block boundary.
--- arch/arm64/kvm/vgic/vgic-its.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
arch/arm64/kvm/vgic/vgic-its.c +19 -13
@@ -2153,18 +2153,22 @@ static int vgic_its_attr_regs_access(struct kvm_device *dev,return ret; } -static u32 compute_next_devid_offset (struct list_head *h, +static u32 compute_next_devid_offset (struct vgic_its *its,u64 baser,struct its_device *dev) { -struct its_device *next; -u32 next_offset; +struct its_device *next = dev; -if (list_is_last (&dev->dev_list, h)) -return 0 ; - next =list_next_entry (dev, dev_list); - next_offset = next->device_id - dev->device_id; +/* +* Point at the next device vgic_its_save_device_tables() saves. It +* sorts device_list first, so the subtraction cannot underflow. +*/ +list_for_each_entry_continue (next, &its->device_list, dev_list) { +if (vgic_its_check_id (its, baser, next->device_id,NULL )) +return min_t (u32, next->device_id - dev->device_id, +VITS_DTE_MAX_DEVID_OFFSET ); + } -return min_t (u32, next_offset,VITS_DTE_MAX_DEVID_OFFSET ); +return 0 ; }static u32 compute_next_eventid_offset (struct list_head *h,struct its_ite *ite)
@@ -2393,17 +2397,18 @@ static int vgic_its_restore_itt(struct vgic_its *its, struct its_device *dev)* vgic_its_save_dte - Save a device table entry at a given GPA * * @its: ITS handle +* @baser: GITS_BASER<dev> the caller is saving against * @dev: ITS device * @ptr: GPA */ -static int vgic_its_save_dte (struct vgic_its *its,struct its_device *dev, -gpa_t ptr) +static int vgic_its_save_dte (struct vgic_its *its,u64 baser, +struct its_device *dev,gpa_t ptr) {u64 val, itt_addr_field;u32 next_offset; itt_addr_field = dev->itt_addr >>8 ; - next_offset =compute_next_devid_offset (&its->device_list, dev); + next_offset =compute_next_devid_offset (its, baser, dev); val = (1ULL << KVM_ITS_DTE_VALID_SHIFT | ((u64)next_offset << KVM_ITS_DTE_NEXT_SHIFT) | (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) |
@@ -2502,15 +2507,16 @@ static int vgic_its_save_device_tables(struct vgic_its *its)int ret;gpa_t eaddr; +/* Don't fail a save that userspace must be able to issue. */ if (!vgic_its_check_id (its, baser, dev->device_id, &eaddr)) -return -EINVAL ; +continue ; ret =vgic_its_save_itt (its, dev);if (ret)return ret; - ret =vgic_its_save_dte (its, dev, eaddr); + ret =vgic_its_save_dte (its, baser, dev, eaddr);if (ret)return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 974/1193 KVM: arm64: Return -EINVAL for an empty SMCCC filter range at base 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 64dc6f1db7e620f2e9337bb181f305fb0561da79 ]
kvm_smccc_set_filter() only rejects a range if its inclusive end, base + nr_functions - 1, is below base. That catches an empty range (nr_functions == 0) at every nonzero base, but at base 0 the end wraps to U32_MAX and KVM tries to insert [0, U32_MAX], which overlaps the reserved Arm Architecture Calls ranges. KVM_ARM_VM_SMCCC_FILTER then returns -EEXIST instead of the -EINVAL that the smccc_filter selftest expects for an empty range.
Reject a zero function count explicitly.
Tested with a userspace reproducer on an arm64 VHE host under QEMU TCG:
EEXIST before, EINVAL after.
--- arch/arm64/kvm/hypercalls.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/kvm/hypercalls.c +2 -1
@@ -174,7 +174,8 @@ static int kvm_smccc_set_filter(struct kvm *kvm, struct kvm_smccc_filter __user start = filter.base; end = start + filter.nr_functions -1 ; -if (end < start || filter.action >=NR_SMCCC_FILTER_ACTIONS ) +if (!filter.nr_functions || end < start || + filter.action >=NR_SMCCC_FILTER_ACTIONS )return -EINVAL ;mutex_lock (&kvm->arch.config_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 975/1193 squashfs: Add dictionary size range check to prevent shift-out-of-bounds
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ran Hongyun <[email protected]>
[ Upstream commit 1f7745fb3580152ca902ef181b605f33cabfb1d0 ]
When an abnormal SquashFS image (COMP_OPTS flag is 1 but dictionary size is 0) is mounted, and performs shift operations using dictionarysize, the shift exponent is -1, causing a shift-out-of-bounds.
Detail as below:squashfs_comp_opts(msblk, buffer, length)
squashfs_xz_comp_opts()
if (comp_opts)
n = ffs(opts->dict_size) - 1;<----opts->dict_size=0, n=-1
if (opts->dict_size != (1 << n) && opts->dict_size !=
(1 << n) + (1 << (n + 1))) <----shift-out-of-boundsFix it by adding a dictionary size range check before the shift operation.
--- fs/squashfs/xz_wrapper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/squashfs/xz_wrapper.c +3 -3
@@ -57,10 +57,10 @@ static void *squashfs_xz_comp_opts(struct squashfs_sb_info *msblk, opts->dict_size =le32_to_cpu (comp_opts->dictionary_size); -/* the dictionary size should be 2^n or 2^n+2^(n+1) */ +/* the dictionary size should be positive and 2^n or 2^n+2^(n+1) */ n =ffs (opts->dict_size) -1 ; -if (opts->dict_size != (1 << n) && opts->dict_size != (1 << n) + - (1 << (n +1 ))) { +if (opts->dict_size <=0 || (opts->dict_size != (1 << n) && + opts->dict_size != (1 << n) + (1 << (n +1 )))) { err = -EIO ; goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 976/1193 Bluetooth: SMP: reject Security Request over BR/EDR
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christiano Amora <[email protected]>
[ Upstream commit f033482d76a9f18080c7a40c5f9c678bd7adc8f3 ]
Bose QC Ultra Headphones (dual-mode, same public address on both transports) occasionally send an SMP Security Request on the BR/EDR SMP fixed channel right after the ACL link is encrypted. The kernel handles it as if it were an LE link: smp_cmd_security_req() has no transport check, smp_ltk_encrypt() looks up an LTK with the ACL connection's dst_type, and hci_find_ltk() matches the peer's LE LTK because the LE public address type is stored as ADDR_LE_DEV_PUBLIC (0), the same value as BDADDR_BREDR. HCI_OP_LE_START_ENC is then issued on the ACL handle, the controller rejects it with Invalid HCI Command Parameters, and hci_cs_le_start_enc() disconnects the link with HCI_ERROR_AUTH_FAILURE. The headphones drop within a second of connecting, before any profile is up; a manual reconnect works.
btmon (MediaTek MT7922, kernel 7.0.12):
Quoted 1 line
HCI Event: Encryption Change (
0x08) plen 4
Status: Success (0x00)
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)
Encryption: Enabled with AES-CCM (0x02)Quoted 1 line
ACL Data RX: Handle 50 flags
0x02dlen 6
BR/EDR SMP: Security Request (0x0b) len 1
Authentication requirement: No bonding, No MITM, SC (0x08)
< HCI Command: LE Start Encryption (0x08|0x0019) plen 28
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)Quoted 1 line
HCI Event: Command Status (
0x0f) plen 4
LE Start Encryption (0x08|0x0019) ncmd 1
Status: Invalid HCI Command Parameters (0x12)
< HCI Command: Disconnect (0x01|0x0006) plen 3
Handle: 50 Address: BC:87:FA:47:73:5E (Bose Corporation)
Reason: Authentication Failure (0x05)SMP over BR/EDR is limited to cross-transport key derivation; the Security Request procedure (Core Specification Vol 3, Part H, Section 2.4.6, PDU in Section 3.6.7) has no BR/EDR counterpart. Reply with Pairing Failed / Command Not Supported on a non-LE link, before the PDU is parsed, and keep the connection. The reply is sent directly rather than through smp_failure(): rejecting a command on the wrong transport is not an authentication failure, and MGMT_EV_AUTH_FAILED would make bluetoothd disconnect the device.
Tested on the affected host (kernel 7.0.12, MediaTek MT7922, Bose QC Ultra) with the patched module built out of tree: 7 days and 49 reconnects without a drop, against 2 drops in the 3 days before the patch. Every disconnect in that week had a userspace or remote reason.
--- net/bluetooth/smp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/bluetooth/smp.c +17 -0
@@ -2302,6 +2302,23 @@ static u8 smp_cmd_security_req(struct l2cap_conn *conn, struct sk_buff *skb)bt_dev_dbg (hdev,"conn %p" , conn); +/* SMP over BR/EDR only covers cross-transport key derivation; the +* Security Request procedure has no BR/EDR counterpart. Reject it +* here, otherwise smp_ltk_encrypt() finds the peer's LE LTK +* (ADDR_LE_DEV_PUBLIC and BDADDR_BREDR are both 0) and issues +* HCI_OP_LE_START_ENC on the ACL handle, which the controller +* rejects and hci_cs_le_start_enc() turns into a disconnect. Reply +* without smp_failure(): this is not an authentication failure, and +* MGMT_EV_AUTH_FAILED would make bluetoothd drop the device. +*/ +if (hcon->type !=LE_LINK ) { +u8 reason =SMP_CMD_NOTSUPP ; + +smp_send_cmd (conn,SMP_CMD_PAIRING_FAIL ,sizeof (reason), + &reason); +return 0 ; + } +if (skb->len <sizeof (*rp))return SMP_INVALID_PARAMS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 977/1193 Bluetooth: mgmt: Dequeue pending mesh_send_sync entries on cancel
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lee Jones <[email protected]>
[ Upstream commit 71af682ba4692c2ed9ace4c3d4ca462ae368c029 ]
In send_cancel(), pending mesh_tx objects are removed from the hdev->mesh_pending list and freed via mesh_send_complete(). However, if a mesh transmission was already queued onto hdev->cmd_sync_work_list via mesh_next(), the queued entry retains a raw pointer to mesh_tx.
When hci_cmd_sync_work later processes the entry, it attempts to execute mesh_send_sync and its destroy callback mesh_send_start_complete using the already freed mesh_tx pointer, leading to a use-after-free.
Fix this by invoking hci_cmd_sync_dequeue() for mesh_send_sync on the target mesh_tx before completing it. If the entry is found and dequeued, its destroy callback will complete and free the object; otherwise, mesh_send_complete() is called directly.
Additionally, ensure the transmission queue advances after cancellation or errors. In mesh_send_start_complete(), call mesh_next() on error unless err is -ECANCELED, because hci_cmd_sync_dequeue() holds hdev->cmd_sync_work_lock and calling mesh_next() synchronously would deadlock. Instead, advance the queue in send_cancel() once the lock is released and if no transmission is in progress.
--- net/bluetooth/mgmt.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
net/bluetooth/mgmt.c +15 -4
@@ -2283,6 +2283,8 @@ static void mesh_send_start_complete(struct hci_dev *hdev, void *data, int err)hci_dev_clear_flag (hdev,HCI_MESH_SENDING );/* Send Complete Error Code for handle */ mesh_send_complete (hdev, mesh_tx, false); +if (err != -ECANCELED ) +mesh_next (hdev,NULL ,0 );return ; }
@@ -2392,19 +2394,28 @@ static int send_cancel(struct hci_dev *hdev, void *data)do { mesh_tx =mgmt_mesh_next (hdev, cmd->sk); -if (mesh_tx) -mesh_send_complete (hdev, mesh_tx, false); +if (mesh_tx) { +if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, + mesh_tx,NULL )) +mesh_send_complete (hdev, mesh_tx, false); + } }while (mesh_tx); }else { mesh_tx =mgmt_mesh_find (hdev, cancel->handle); -if (mesh_tx && mesh_tx->sk == cmd->sk) -mesh_send_complete (hdev, mesh_tx, false); +if (mesh_tx && mesh_tx->sk == cmd->sk) { +if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, + mesh_tx,NULL )) +mesh_send_complete (hdev, mesh_tx, false); + } }mgmt_cmd_complete (cmd->sk, hdev->id,MGMT_OP_MESH_SEND_CANCEL ,0 ,NULL ,0 ); +if (!hci_dev_test_flag (hdev,HCI_MESH_SENDING )) +mesh_next (hdev,NULL ,0 ); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 951/1193 spi: zynqmp-gqspi: Use devm_spi_alloc_host()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
[ Upstream commit 64640f6c972e80f52196416a8d4dc3c0ffcbc82d ]
Use devm_spi_alloc_host() so that there's no need to call spi_controller_put() in the error path.
--- drivers/spi/spi-zynqmp-gqspi.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/spi/spi-zynqmp-gqspi.c +6 -12
@@ -1220,7 +1220,7 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)u32 num_cs;const struct qspi_platform_data *p_data; - ctlr =spi_alloc_master (&pdev->dev,sizeof (*xqspi)); + ctlr =devm_spi_alloc_master (&pdev->dev,sizeof (*xqspi));if (!ctlr)return -ENOMEM ;
@@ -1234,29 +1234,25 @@ static int zynqmp_qspi_probe(struct platform_device *pdev) xqspi->has_tapdelay = true; xqspi->regs =devm_platform_ioremap_resource (pdev,0 ); -if (IS_ERR (xqspi->regs)) { - ret =PTR_ERR (xqspi->regs); - goto remove_master; - } +if (IS_ERR (xqspi->regs)) +return PTR_ERR (xqspi->regs); xqspi->pclk =devm_clk_get (&pdev->dev,"pclk" );if (IS_ERR (xqspi->pclk)) {dev_err (dev,"pclk clock not found.\n" ); - ret =PTR_ERR (xqspi->pclk); - goto remove_master; +return PTR_ERR (xqspi->pclk); } xqspi->refclk =devm_clk_get (&pdev->dev,"ref_clk" );if (IS_ERR (xqspi->refclk)) {dev_err (dev,"ref_clk clock not found.\n" ); - ret =PTR_ERR (xqspi->refclk); - goto remove_master; +return PTR_ERR (xqspi->refclk); } ret =clk_prepare_enable (xqspi->pclk);if (ret) {dev_err (dev,"Unable to enable APB clock.\n" ); - goto remove_master; +return ret; } ret =clk_prepare_enable (xqspi->refclk);
@@ -1343,8 +1339,6 @@ static int zynqmp_qspi_probe(struct platform_device *pdev)clk_disable_unprepare (xqspi->refclk); clk_dis_pclk:clk_disable_unprepare (xqspi->pclk); -remove_master: -spi_controller_put (ctlr);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 978/1193 cgroup: selftests: Move memcontrol specific helpers out of common cgroup_util.c
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 3a7f9e518c6a83d54c84c101e23ffc8aa12df139 ]
Move a handful of helpers out of cgroup_util.c and into test_memcontrol.c that have nothing to with cgroups in general, in anticipation of making cgroup_util.c a generic library that can be used by other selftests.
Make read_text() and write_text() non-static so test_memcontrol.c can use them.
Stable-dep-of: c774ec8f0a5d ("selftests: cgroup: give the O_TMPFILE open in get_temp_fd() a mode")
--- tools/testing/selftests/cgroup/cgroup_util.c | 82 +------------------ tools/testing/selftests/cgroup/cgroup_util.h | 8 +- .../selftests/cgroup/test_memcontrol.c | 78 ++++++++++++++++++ 3 files changed, 83 insertions(+), 85 deletions(-)
tools/testing/selftests/cgroup/cgroup_util.c +2 -80
@@ -20,7 +20,7 @@#include "../clone3/clone3_selftests.h" /* Returns read len on success, or -errno on failure. */ -static ssize_t read_text (const char *path,char *buf,size_t max_len) +ssize_t read_text (const char *path,char *buf,size_t max_len) {ssize_t len;int fd;
@@ -39,7 +39,7 @@ static ssize_t read_text(const char *path, char *buf, size_t max_len) }/* Returns written len on success, or -errno on failure. */ -static ssize_t write_text (const char *path,char *buf,ssize_t len) +ssize_t write_text (const char *path,char *buf,ssize_t len) {int fd;
@@ -466,84 +466,6 @@ int cg_run_nowait(const char *cgroup,return pid; } -int get_temp_fd (void ) -{ -return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ); -} - -int alloc_pagecache (int fd,size_t size) -{ -char buf[PAGE_SIZE ]; -struct stat st; -int i; - -if (fstat (fd, &st)) - goto cleanup; - - size += st.st_size; - -if (ftruncate (fd, size)) - goto cleanup; - -for (i =0 ; i < size; i +=sizeof (buf)) -read (fd, buf,sizeof (buf)); - -return 0 ; - -cleanup: -return -1 ; -} - -int alloc_anon (const char *cgroup,void *arg) -{ -size_t size = (unsigned long )arg; -char *buf, *ptr; - - buf =malloc (size); -for (ptr = buf; ptr < buf + size; ptr +=PAGE_SIZE ) - *ptr =0 ; - -free (buf); -return 0 ; -} - -int is_swap_enabled (void ) -{ -char buf[PAGE_SIZE ]; -const char delim[] ="\n" ; -int cnt =0 ; -char *line; - -if (read_text ("/proc/swaps" , buf,sizeof (buf)) <=0 ) -return -1 ; - -for (line =strtok (buf, delim); line; line =strtok (NULL , delim)) - cnt++; - -return cnt >1 ; -} - -int set_oom_adj_score (int pid,int score) -{ -char path[PATH_MAX ]; -int fd, len; - -sprintf (path,"/proc/%d/oom_score_adj" , pid); - - fd =open (path,O_WRONLY |O_APPEND ); -if (fd <0 ) -return fd; - - len =dprintf (fd,"%d" , score); -if (len <0 ) { -close (fd); -return len; - } - -close (fd); -return 0 ; -} -int proc_mount_contains (const char *option) {char buf[4 *PAGE_SIZE ];
tools/testing/selftests/cgroup/cgroup_util.h +3 -5
@@ -21,6 +21,9 @@ static inline int values_close(long a, long b, int err)return abs (a - b) <= (a + b) /100 * err; } +extern ssize_t read_text (const char *path,char *buf,size_t max_len); +extern ssize_t write_text (const char *path,char *buf,ssize_t len); +extern int cg_find_unified_root (char *root,size_t len,bool *nsdelegate);extern char *cg_name (const char *root,const char *name);extern char *cg_name_indexed (const char *root,const char *name,int index);
@@ -47,11 +50,6 @@ extern int cg_enter_current_thread(const char *cgroup);extern int cg_run_nowait (const char *cgroup,int (*fn)(const char *cgroup,void *arg),void *arg); -extern int get_temp_fd (void ); -extern int alloc_pagecache (int fd,size_t size); -extern int alloc_anon (const char *cgroup,void *arg); -extern int is_swap_enabled (void ); -extern int set_oom_adj_score (int pid,int score);extern int cg_wait_for_proc_count (const char *cgroup,int count);extern int cg_killall (const char *cgroup);int proc_mount_contains (const char *option);
tools/testing/selftests/cgroup/test_memcontrol.c +78 -0
84 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 979/1193 selftests: cgroup: give the O_TMPFILE open in get_temp_fd() a mode
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eva Kurchatova <[email protected]>
[ Upstream commit c774ec8f0a5d02a06d34c27f5a7de7e333b91265 ]
O_TMPFILE, like O_CREAT, needs the third argument. Without it glibc refuses the call at compile time as soon as fortification is on:
In function 'open',
inlined from 'get_temp_fd' at test_memcontrol.c:33:9:
/usr/include/bits/fcntl2.h:52:11: error: call to '__open_missing_mode'
declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
The fortify checks take effect only once the compiler optimises, and cgroup/Makefile builds with "-Wall -pthread" alone, so this goes unnoticed in a plain build. Building the tests with the flags distributions commonly use, -O2 -D_FORTIFY_SOURCE=3, loses test_memcontrol entirely.
--- tools/testing/selftests/cgroup/test_memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/cgroup/test_memcontrol.c +1 -1
@@ -26,7 +26,7 @@ static bool has_recursiveprot;int get_temp_fd (void ) { -return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ); +return open ("." ,O_TMPFILE |O_RDWR |O_EXCL ,0600 ); }int alloc_pagecache (int fd,size_t size)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 980/1193 scsi: megaraid_sas: Protect megasas_get_ctrl_info() in megasas_resume()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bart Van Assche <[email protected]>
[ Upstream commit 42d1221d321e55afc7bba9109a77aaf5a817c8a3 ]
Protect the megasas_get_ctrl_info() call in megasas_resume() with instance->reset_mutex using scoped_guard().
megasas_get_ctrl_info() may release and reacquire instance->reset_mutex. Hence, calling this function without holding instance->reset_mutex is not safe.
--- drivers/scsi/megaraid/megaraid_sas_base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/scsi/megaraid/megaraid_sas_base.c +3 -1
@@ -7871,7 +7871,9 @@ megasas_resume(struct device *dev) goto fail_init_mfi; } -if (megasas_get_ctrl_info (instance) !=DCMD_SUCCESS ) +scoped_guard (mutex, &instance->reset_mutex) + rval = megasas_get_ctrl_info(instance); +if (rval !=DCMD_SUCCESS ) goto fail_init_mfi; tasklet_init(&instance->isr_tasklet, instance->instancet->tasklet,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 981/1193 docs: s390/pci: Improve and update PCI documentation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Schnelle <[email protected]>
[ Upstream commit 737c4f4a241ca85c597ca2ef1a6f8446bf681ab5 ]
Update the s390 specific PCI documentation to better reflect current behavior and terms such as the handling of Isolated VFs via commit 25f39d3dcb48 ("s390/pci: Ignore RID for isolated VFs").
Add a descriptions for /sys/firmware/clp/uid_checking which was added in commit b043a81ce3ee ("s390/pci: Expose firmware provided UID Checking state in sysfs") but missed documentation.
Similarly add documentation for the fidparm attribute added by commit 99ad39306a62 ("s390/pci: Expose FIDPARM attribute in sysfs") and add a list of pft values and their names.
Finally improve formatting of the different attribute descriptions by adding a separating colon.
Stable-dep-of: 4525a9110495 ("s390/pci/docs: Fix sriov_numvfs attribute name")
--- Documentation/arch/s390/pci.rst | 152 +++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 51 deletions(-)
Documentation/arch/s390/pci.rst +101 -51
@@ -6,6 +6,7 @@ S/390 PCI Authors: - Pierre Morel + - Niklas Schnelle Copyright, IBM Corp. 2020
@@ -27,14 +28,16 @@ Command line parameters debugfs entries --------------- -The S/390 debug feature (s390dbf) generates views to hold various debug results in sysfs directories of the form: +The S/390 debug feature (s390dbf) generates views to hold various debug results +in sysfs directories of the form: * /sys/kernel/debug/s390dbf/pci_*/ For example: - /sys/kernel/debug/s390dbf/pci_msg/sprintf - Holds messages from the processing of PCI events, like machine check handling + + holds messages from the processing of PCI events, like machine check handling and setting of global functionality, like UID checking. Change the level of logging to be more or less verbose by piping
@@ -47,87 +50,134 @@ Sysfs entries Entries specific to zPCI functions and entries that hold zPCI information. -* /sys/bus/pci/slots/XXXXXXXX +* /sys/bus/pci/slots/XXXXXXXX: - The slot entries are set up using the function identifier (FID) of the - PCI function. The format depicted as XXXXXXXX above is 8 hexadecimal digits - with 0 padding and lower case hexadecimal digits. + The slot entries are set up using the function identifier (FID) of the PCI + function as slot name. The format depicted as XXXXXXXX above is 8 hexadecimal + digits with 0 padding and lower case hexadecimal digits. - /sys/bus/pci/slots/XXXXXXXX/power A physical function that currently supports a virtual function cannot be powered off until all virtual functions are removed with: - echo 0 > /sys/bus/pci/devices/XXXX:XX:XX.X/sriov_numvf + echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvf -* /sys/bus/pci/devices/XXXX:XX:XX.X/ +* /sys/bus/pci/devices/DDDD:BB:dd.f/: - - function_id - A zPCI function identifier that uniquely identifies the function in the Z server. + - function_id: + The zPCI function identifier (FID) is a 32-bit hexadecimal value that + uniquely identifies the PCI function. Unless the hypervisor provides + a virtual FID e.g. on KVM this identifier is unique across the machine even + between different partitions. - - function_handle - Low-level identifier used for a configured PCI function. - It might be useful for debugging. + - function_handle: + This 32-bit hexadecimal value is a low-level identifier used for a PCI + function. Note that the function handle may be changed and become invalid + on PCI events and when enabling/disabling the PCI function. - - pchid - Model-dependent location of the I/O adapter. + - pchid: + This 16-bit hexadecimal value encodes a model-dependent location for + the PCI function. - - pfgid - PCI function group ID, functions that share identical functionality + - pfgid: + PCI function group ID; functions that share identical functionality use a common identifier. A PCI group defines interrupts, IOMMU, IOTLB, and DMA specifics. - - vfn + - vfn: The virtual function number, from 1 to N for virtual functions, 0 for physical functions. - - pft - The PCI function type - - - port - The port corresponds to the physical port the function is attached to. - It also gives an indication of the physical function a virtual function - is attached to. - - - uid - The user identifier (UID) may be defined as part of the machine - configuration or the z/VM or KVM guest configuration. If the accompanying - uid_is_unique attribute is 1 the platform guarantees that the UID is unique - within that instance and no devices with the same UID can be attached - during the lifetime of the system. - - - uid_is_unique - Indicates whether the user identifier (UID) is guaranteed to be and remain - unique within this Linux instance. - - - pfip/segmentX + - pft: + The PCI function type is an s390-specific type attribute. It indicates + a more general, usage oriented, type than PCI Specification + class/vendor/device identifiers. That is PCI functions with the same pft + value may be backed by different hardware implementations. At the same time + apart from unclassified functions (pft is 0x00) the same pft value + generally implies a similar usage model. At the same time the same + PCI hardware device may appear with different pft values when in a + different usage model. For example NETD and NETH VFs may be implemented + by the same PCI hardware device but in NETD the parent Physical Function + is user managed while with NETH it is platform managed. + + Currently the following PFT values are defined: + + - 0x00 (UNC): Unclassified + - 0x02 (ROCE): RoCE Express + - 0x05 (ISM): Internal Shared Memory + - 0x0a (ROC2): RoCE Express 2 + - 0x0b (NVMe): NVMe + - 0x0c (NETH): Network Express hybrid + - 0x0d (CNW): Cloud Network Adapter + - 0x0f (NETD): Network Express direct + + - port: + The port is a decimal value corresponding to the physical port the function + is attached to. Virtual Functions (VFs) share the port with their parent + Physical Function (PF). A value of 0 indicates that the port attribute is + not applicable for that PCI function type. + + - uid: + The user-defined identifier (UID) for a PCI function is a 32-bit + hexadecimal value. It is defined on a per instance basis as part of the + partition, KVM guest, or z/VM guest configuration. If UID Checking is + enabled the platform ensures that the UID is unique within that instance + and no two PCI functions with the same UID will be visible to the instance. + + Independent of this guarantee and unlike the function ID (FID) the UID may + be the same in different partitions within the same machine. This allows to + create PCI configurations in multiple partitions to be identical in the + UID-namespace. + + - uid_is_unique: + A 0 or 1 flag indicating whether the user-defined identifier (UID) is + guaranteed to be and remain unique within this Linux instance. This + platform feature is called UID Checking. + + - pfip/segmentX: The segments determine the isolation of a function. They correspond to the physical path to the function. The more the segments are different, the more the functions are isolated. + - fidparm: + Contains an 8-bit-per-PCI function parameter field in hexadecimal provided + by the platform. The meaning of this field is PCI function type specific. + For NETH VFs a value of 0x01 indicates that the function supports + promiscuous mode. + +* /sys/firmware/clp/uid_checking: + + In addition to the per-device uid_is_unique attribute this presents a + global indication of whether UID Checking is enabled. This allows users + to check for UID Checking even when no PCI functions are configured. + Enumeration and hotplug ======================= The PCI address consists of four parts: domain, bus, device and function, -and is of this form: DDDD:BB:dd.f +and is of this form: DDDD:BB:dd.f. -* When not using multi-functions (norid is set, or the firmware does not - support multi-functions): +* For a PCI function for which the platform does not expose the RID, the + pci=norid kernel parameter is used, or a so-called isolated Virtual Function + which does have RID information but is used without its parent Physical + Function being part of the same PCI configuration: - There is only one function per domain. - - The domain is set from the zPCI function's UID as defined during the - LPAR creation. + - The domain is set from the zPCI function's UID if UID Checking is on; + otherwise the domain ID is generated dynamically and is not stable + across reboots or hot plug. -* When using multi-functions (norid parameter is not set), - zPCI functions are addressed differently: +* For a PCI function for which the platform exposes the RID and which + is not an Isolated Virtual Function: - There is still only one bus per domain. - - There can be up to 256 functions per bus. + - There can be up to 256 PCI functions per bus. - - The domain part of the address of all functions for - a multi-Function device is set from the zPCI function's UID as defined - in the LPAR creation for the function zero. + - The domain part of the address of all functions within the same topology is + that of the configured PCI function with the lowest devfn within that + topology. - - New functions will only be ready for use after the function zero - (the function with devfn 0) has been enumerated. + - Virtual Functions generated by an SR-IOV capable Physical Function only + become visible once SR-IOV is enabled.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 982/1193 s390/pci/docs: Fix sriov_numvfs attribute name
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
[ Upstream commit 4525a911049543c23885a540a788d13be318a486 ]
The attribute is sriov_numvfs (drivers/pci/iov.c); the document names it sriov_numvf, which does not exist.
Use sriov_numvfs.
--- Documentation/arch/s390/pci.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/arch/s390/pci.rst +1 -1
@@ -60,7 +60,7 @@ Entries specific to zPCI functions and entries that hold zPCI information. A physical function that currently supports a virtual function cannot be powered off until all virtual functions are removed with: - echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvf + echo 0 > /sys/bus/pci/devices/DDDD:BB:dd.f/sriov_numvfs * /sys/bus/pci/devices/DDDD:BB:dd.f/:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 983/1193 s390/cio: Fix cio_update_schib() to not cache invalid schib
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit 29d9e5835d89223aa913dcf7b942cc1c148bdd25 ]
When pmcw.dnv is 0, the contents of all SCHIB fields are unpredictable. Zero sch->schib in that case to prevent subsequent code from making decisions based on unpredictable data.
--- drivers/s390/cio/cio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/s390/cio/cio.c +7 -4
@@ -453,7 +453,8 @@ EXPORT_SYMBOL_GPL(cio_commit_config);/** * cio_update_schib - Perform stsch and update schib if subchannel is valid. * @sch: subchannel on which to perform stsch -* Return zero on success, -ENODEV otherwise. +* Return zero on success, -ENODEV if the subchannel is not operational, +* -EACCES if the subchannel has no valid device. */ int cio_update_schib (struct subchannel *sch) {
@@ -462,10 +463,12 @@ int cio_update_schib(struct subchannel *sch)if (stsch (sch->schid, &schib))return -ENODEV ; -memcpy (&sch->schib, &schib,sizeof (schib)); - -if (!css_sch_is_valid (&schib)) +if (!css_sch_is_valid (&schib)) { +memset (&sch->schib,0 ,sizeof (sch->schib));return -EACCES ; + } + +memcpy (&sch->schib, &schib,sizeof (schib));return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 984/1193 s390/cio: Check pmcw.dnv before pmcw.ena in I/O entry points
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit f6f2985eabdb2bfdc82ce90a1ea3ec53ba795f34 ]
The device number valid (dnv) bit in the PMCW must be checked before acting on any other PMCW fields for IO-type subchannels. A subchannel with dnv=0 has no valid device number associated, making it meaningless to evaluate the enabled (ena) state or issue any I/O instruction against it.
--- drivers/s390/cio/device_ops.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/s390/cio/device_ops.c +12 -0
@@ -142,6 +142,8 @@ int ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -198,6 +200,8 @@ int ccw_device_start_timeout_key(struct ccw_device *cdev, struct ccw1 *cpa,if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -375,6 +379,8 @@ int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -409,6 +415,8 @@ int ccw_device_resume(struct ccw_device *cdev)if (!cdev || !cdev->dev.parent)return -ENODEV ; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_NOT_OPER )
@@ -544,6 +552,8 @@ int ccw_device_tm_start_timeout_key(struct ccw_device *cdev, struct tcw *tcw,int rc; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state ==DEV_STATE_VERIFY ) {
@@ -686,6 +696,8 @@ int ccw_device_tm_intrg(struct ccw_device *cdev) {struct subchannel *sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return -ENODEV ;if (!sch->schib.pmcw.ena)return -EINVAL ;if (cdev->private->state !=DEV_STATE_ONLINE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 985/1193 s390/cio: Guard PMCW field accesses with dnv check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vineeth Vijayan <[email protected]>
[ Upstream commit 9590f4d83880dfb5a81906e48e72779248fbe8f0 ]
When PMCW.DNV is 0, no I/O device is associated with the subchannel. However, several code paths access PMCW fields directly from the cached sch->schib without first invoking the update helper. Add explicit DNV validation before accessing PMCW fields from the cached SCHIB to avoid using invalid data.
--- drivers/s390/cio/chp.c | 3 +++ drivers/s390/cio/device.c | 9 +++++---- drivers/s390/cio/device_fsm.c | 3 +++ drivers/s390/cio/device_ops.c | 9 +++++++++ drivers/s390/cio/vfio_ccw_fsm.c | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-)
drivers/s390/cio/chp.c +3 -0
@@ -78,6 +78,9 @@ u8 chp_get_sch_opm(struct subchannel *sch)int opm;int i; +if (!sch->schib.pmcw.dnv) +return 0 ; + opm =0 ;chp_id_init (&chpid);for (i =0 ; i <8 ; i++) {
drivers/s390/cio/device.c +5 -4
@@ -925,7 +925,7 @@ static int ccw_device_move_to_sch(struct ccw_device *cdev,if (!sch_is_pseudo_sch (old_sch)) {spin_lock_irq (&old_sch->lock); - old_enabled = old_sch->schib.pmcw.ena; + old_enabled = old_sch->schib.pmcw.dnv && old_sch->schib.pmcw.ena; rc =0 ;if (old_enabled) rc =cio_disable_subchannel (old_sch);
@@ -944,7 +944,7 @@ static int ccw_device_move_to_sch(struct ccw_device *cdev,CIO_MSG_EVENT (0 ,"device_move(0.%x.%04x,0.%x.%04x)=%d\n" , cdev->private->dev_id.ssid, cdev->private->dev_id.devno, sch->schid.ssid, - sch->schib.pmcw.dev, rc); + sch->schid.sch_no, rc);if (old_enabled) {/* Try to re-enable the old subchannel. */ spin_lock_irq (&old_sch->lock);
@@ -1210,7 +1210,7 @@ static void io_subchannel_quiesce(struct subchannel *sch) cdev =sch_get_cdev (sch);if (cio_is_console (sch->schid)) goto out_unlock; -if (!sch->schib.pmcw.ena) +if (!sch->schib.pmcw.dnv || !sch->schib.pmcw.ena) goto out_unlock; ret =cio_disable_subchannel (sch);if (ret != -EBUSY )
@@ -1257,7 +1257,8 @@ static int recovery_check(struct device *dev, void *data)switch (cdev->private->state) {case DEV_STATE_ONLINE : sch =to_subchannel (cdev->dev.parent); -if ((sch->schib.pmcw.pam & sch->opm) == sch->vpm) +if (sch->schib.pmcw.dnv && + (sch->schib.pmcw.pam & sch->opm) == sch->vpm)break ; fallthrough;case DEV_STATE_DISCONNECTED :
drivers/s390/cio/device_fsm.c +3 -0
@@ -169,6 +169,9 @@ __recover_lost_chpids(struct subchannel *sch, int old_lpm)int mask, i;struct chp_id chpid; +if (!sch->schib.pmcw.dnv) +return ; +chp_id_init (&chpid);for (i =0 ; i<8 ; i++) { mask =0x80 >> i;
drivers/s390/cio/device_ops.c +9 -0
@@ -486,6 +486,8 @@ struct channel_path_desc_fmt0 *ccw_device_get_chp_desc(struct ccw_device *cdev,struct chp_id chpid; sch =to_subchannel (cdev->dev.parent); +if (!sch->schib.pmcw.dnv) +return NULL ;chp_id_init (&chpid); chpid.id = sch->schib.pmcw.chpid[chp_idx];return chp_get_chp_desc (chpid);
@@ -506,6 +508,8 @@ u8 *ccw_device_get_util_str(struct ccw_device *cdev, int chp_idx)struct chp_id chpid;u8 *util_str; +if (!sch->schib.pmcw.dnv) +return NULL ;chp_id_init (&chpid); chpid.id = sch->schib.pmcw.chpid[chp_idx]; chp =chpid_to_chp (chpid);
@@ -654,6 +658,9 @@ int ccw_device_get_mdc(struct ccw_device *cdev, u8 mask)struct chp_id chpid;int mdc =0 , i; +if (!sch->schib.pmcw.dnv) +return 0 ; +/* Adjust requested path mask to excluded varied off paths. */ if (mask) mask &= sch->lpm;
@@ -790,6 +797,8 @@ int ccw_device_get_chpid(struct ccw_device *cdev, int chp_idx, u8 *chpid)if ((chp_idx <0 ) || (chp_idx >7 ))return -EINVAL ; +if (!sch->schib.pmcw.dnv) +return -ENODEV ; mask =0x80 >> chp_idx;if (!(sch->schib.pmcw.pim & mask))return -ENODEV ;
drivers/s390/cio/vfio_ccw_fsm.c +1 -1
@@ -399,7 +399,7 @@ static void fsm_close(struct vfio_ccw_private *private,spin_lock_irq (&sch->lock); -if (!sch->schib.pmcw.ena) +if (!sch->schib.pmcw.dnv || !sch->schib.pmcw.ena) goto err_unlock; ret =cio_disable_subchannel (sch);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 986/1193 fs: avoid repeated scans in evict_inodes()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Sun <[email protected]>
[ Upstream commit 7459c021874246c196f397686e100702f059b9e7 ]
We observed hung tasks when users attempted to unmount a filesystem after its disk had been removed while still in use. During device removal, fs_bdev_mark_dead() calls evict_inodes() while holding s_umount.
Each time evict_inodes() drops s_inode_list_lock to reschedule, it restarts the walk from the head of s_inodes. With many referenced inodes at the head of the list, these restarts repeatedly scan the same inodes without reclaiming them. This can keep s_umount held for a long time, blocking concurrent umount attempts and triggering hung-task reports.
Keep the current inode, already marked I_FREEING, out of the disposal batch until s_inode_list_lock is reacquired. Resume the walk from this inode and dispose of it in a later batch or at the end of the walk.
The zero-refcount and state checks under i_lock allow this walker to claim the inode by setting I_FREEING and removing it from the LRU. Other reclaimers skip the inode, leaving this walker responsible for eviction. Only evict() removes it from s_inodes, so keeping it out of the disposal batch ensures that it remains on the list while the lock is dropped. After reacquiring the lock, reading its current next pointer accounts for concurrent removal of following inodes.
The existing inode lifetime rules prohibit acquiring a reference to an inode marked I_FREEING or I_WILL_FREE. __iget() requires its caller to hold i_lock and establish that taking a reference is valid. Inode lookup and igrab() check these flags under i_lock when acquiring a reference from zero. ihold() requires an existing reference, which would keep i_count nonzero and prevent this walker from claiming the inode. These rules already allow iput_final() and the inode shrinker to release i_lock after setting I_FREEING and before eviction completes.
A temporary __iget() reference would also keep the inode on the list, but its release must preserve last-reference handling. Another user can acquire a reference, update lazy timestamps and drop its reference while the pin is held. If the pin becomes the last reference, dropping it with atomic_dec_and_test() and evicting directly bypasses iput()'s lazytime handling and can lose those timestamp updates.
Releasing the pin with iput() preserves that handling, but does not guarantee eviction. fs_bdev_mark_dead() runs with SB_ACTIVE set, so iput() may retain the inode in cache, whereas evict_inodes() must evict eligible zero-reference inodes. The inode may also have been freed when iput() returns, so the walker cannot then use it to force eviction. Using I_FREEING preserves the existing eviction behavior without introducing an additional last-reference transition.
The xfstests auto group passed on ext4 and XFS with known unrelated failures excluded. No new issues were observed, and the previously reproducible hung task no longer occurs with this patch.
--- fs/inode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
fs/inode.c +5 -6
@@ -754,7 +754,6 @@ void evict_inodes(struct super_block *sb)struct inode *inode, *next;LIST_HEAD (dispose); -again:spin_lock (&sb->s_inode_list_lock);list_for_each_entry_safe (inode, next, &sb->s_inodes, i_sb_list) {if (atomic_read (&inode->i_count))
@@ -773,19 +772,19 @@ void evict_inodes(struct super_block *sb) inode->i_state |=I_FREEING ;inode_lru_list_del (inode);spin_unlock (&inode->i_lock); -list_add (&inode->i_lru, &dispose);/* -* We can have a ton of inodes to evict at unmount time given -* enough memory, check to see if we need to go to sleep for a -* bit so we don't livelock. +* Keep this inode out of dispose so it stays on s_inodes while +* the list lock is dropped. I_FREEING prevents new references +* and leaves eviction to us, so we can resume the walk from it. */ if (need_resched ()) {spin_unlock (&sb->s_inode_list_lock);cond_resched ();dispose_list (&dispose); - goto again; +spin_lock (&sb->s_inode_list_lock); } +list_add (&inode->i_lru, &dispose); }spin_unlock (&sb->s_inode_list_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 987/1193 xsk: Use a 32-bit compare in xsk_map_gen_lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 70504de0bb627848667207bec7ccfd647deb8814 ]
xsk_map_gen_lookup() loads a u32 key and compares it with max_entries using BPF_JMP_IMM. BPF immediates are sign-extended to 64 bits, so a max_entries value of 0x80000000 or higher becomes a threshold larger than every zero-extended 32-bit key. An out-of-range index then skips the bounds check and the generated lookup reads past xsk_map[].
Compare with BPF_JMP32_IMM so the check stays in 32-bit unsigned range.
--- net/xdp/xskmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/xdp/xskmap.c +1 -1
@@ -124,7 +124,7 @@ static int xsk_map_gen_lookup(struct bpf_map *map, struct bpf_insn *insn_buf)struct bpf_insn *insn = insn_buf; *insn++ =BPF_LDX_MEM (BPF_W , ret, index,0 ); - *insn++ =BPF_JMP_IMM (BPF_JGE , ret, map->max_entries,5 ); + *insn++ =BPF_JMP32_IMM (BPF_JGE , ret, map->max_entries,5 ); *insn++ =BPF_ALU64_IMM (BPF_LSH , ret,ilog2 (sizeof (struct xsk_sock *))); *insn++ =BPF_ALU64_IMM (BPF_ADD , mp, offsetof(struct xsk_map , xsk_map)); *insn++ =BPF_ALU64_REG (BPF_ADD , ret, mp);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 952/1193 erofs: fix large folio race in erofs_fscache_req_complete
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wenwu Hou <[email protected]>
This patch is for stable only. Commit c37460cd9b2fc ("erofs: remove fscache backend entirely") upstream removed this code.
xas_for_each() iteration can race with reclamation of an unlocked large folio and splitting of its replacement shadow entry. Fix this by advancing past the entire folio before unlocking it.
For example:
CPU A: EROFS completion Other CPUs
---------------------------------- -----------------------------------
Find F at index 0.
Mark F uptodate.
Unlock F.
Reclaim F.
Replace indices 0–3 with a multi-index workingset shadow.
Another reader inserts a smaller folio, e.g. order-0 at index 0. Split the large shadow entry:
index 0: new folio index 1: shadow index 2: shadow index 3: shadow
Find a shadow at index 1.folio_mark_uptodate(folio).
This can cause a kernel panic such as:
[1030374.432778] [ C31] BUG: unable to handle page fault for address: 00001846af017b01 [1030374.432971] [ C31] #PF: supervisor write access in kernel mode [1030374.432973] [ C31] #PF: error_code(0x0002) - not-present page [1030374.433543] [ C31] PGD 5a44f75067 P4D 5a44f75067 PUD 0 [1030374.433546] [ C31] Oops: 0002 [#1] PREEMPT SMP NOPTI [1030374.433549] [ C31] CPU: 31 PID: 2425624 Comm: node Kdump: loaded Tainted: G OE K 6.6.88-**** [1030374.434154] [ C31] Hardware name: Alibaba Cloud Alibaba Cloud ECS, BIOS ?-20260421_110423-CN.l65g09119.cloud.sqa.na131 04/01/2014 [1030374.434156] [ C31] RIP: 0010:erofs_fscache_req_complete+0xc1/0x1a0 [erofs] [1030374.434764] [ C31] Code: 17 c5 c3 48 89 c7 48 85 c0 0f 84 af 00 00 00 48 81 ff 06 04 00 00 74 1b 48 81 ff 02 04 00 00 0f 84 b9 00 00 00 66 85 ed 75 04 <f0> 80 0f 08 e8 96 04 24 c3 48 8b 54 24 18 f6 c2 03 0f 95 c0 48 85 [1030374.435044] [ C31] RSP: 0000:ffffb8f2fc973cc0 EFLAGS: 00010046 [1030374.435641] [ C31] [1030374.435642] [ C31] RAX: 00001846af017b01 RBX: 000000000000000f RCX: 0000000000000001 [1030374.436885] [ C31] RDX: 000000000000000c RSI: ffffa02ab337d468 RDI: 00001846af017b01 [1030374.437127] [ C31] RBP: 0000000000000000 R08: ffffffffffffffc0 R09: 0000000000000002 [1030374.437672] [ C31] R10: 0000000000000005 R11: 0000000000000191 R12: ffffa0060ec72300 [1030374.437673] [ C31] R13: 0000000008000000 R14: ffffffffc11b1990 R15: 0000000000007000 [1030374.437677] [ C31] FS: 00007f4928cdec80(0000) GS:ffffa07dc5f80000(0000) knlGS:0000000000000000 [1030374.437678] [ C31] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [1030374.437680] [ C31] CR2: 00001846af017b01 CR3: 00000063d5356006 CR4: 0000000000770ee0 [1030374.437681] [ C31] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [1030374.437682] [ C31] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400 [1030374.437684] [ C31] PKRU: 55555558 [1030374.437684] [ C31] Call Trace: [1030374.437687] [ C31] <TASK> [1030374.437692] [ C31] erofs_fscache_req_put+0x27/0x40 [erofs] [1030374.438900] [ C31] cachefiles_read_complete+0x48/0x110 [cachefiles] [1030374.440448] [ C31] iomap_dio_bio_end_io+0x128/0x160 [1030374.440456] [ C31] ? __pfx_stripe_end_io+0x10/0x10 [dm_mod] [1030374.440950] [ C31] clone_endio+0x123/0x1f0 [dm_mod] [1030374.441550] [ C31] blk_mq_end_request_batch+0xf4/0x440 [1030374.441556] [ C31] ? nohz_balancer_kick+0x31/0x270 [1030374.441561] [ C31] ? dma_direct_unmap_sg+0x48/0x1d0 [1030374.441565] [ C31] ? dma_pool_free+0x22/0x60 [1030374.441569] [ C31] ? nvme_pci_complete_batch+0xaf/0xc0 [nvme] [1030374.442070] [ C31] nvme_irq+0x6e/0x80 [nvme] [1030374.442422] [ C31] ? __pfx_nvme_pci_complete_batch+0x10/0x10 [nvme] [1030374.442428] [ C31] __handle_irq_event_percpu+0x46/0x1a0 [1030374.442431] [ C31] handle_irq_event+0x37/0x80 [1030374.442433] [ C31] handle_edge_irq+0x93/0x240 [1030374.442436] [ C31] __common_interrupt+0x3b/0xa0 [1030374.442441] [ C31] common_interrupt+0x3f/0xa0 [1030374.442446] [ C31] asm_common_interrupt+0x22/0x40
--- fs/erofs/fscache.c | 2 ++ 1 file changed, 2 insertions(+)
fs/erofs/fscache.c +2 -0
@@ -88,6 +88,8 @@ static void erofs_fscache_req_complete(struct erofs_fscache_request *req)continue ;if (!failed)folio_mark_uptodate (folio); +/* Skip the entire folio before unlocking allows it to be split. */ +xas_advance (&xas,folio_next_index (folio) -1 );folio_unlock (folio); }rcu_read_unlock ();
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 988/1193 bpf: Skip unsettled links in link iterator
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 50e80e2bb5e2be8515205b9c496b9640ddefa434 ]
bpf_link_prime() inserts a link into link_idr before anon_inode_getfile() succeeds and before bpf_link_settle() publishes the ID in link->id. bpf_link_by_id() treats such an ID-zero link as unsettled, but the link iterator takes a reference without this check.
If anon_inode_getfile() then fails, the creator removes the ID and frees its still-private link directly. The iterator is left with a dangling reference and its next bpf_link_put() accesses freed memory.
Treat ID-zero entries as transient in bpf_link_get_curr_or_next(), just as bpf_link_by_id() does.
BUG: KASAN: slab-use-after-free in bpf_link_put Write of size 8 by task exp/384 Call Trace: bpf_link_put kernel/bpf/syscall.c:3372 bpf_link_seq_next kernel/bpf/link_iter.c:33 bpf_seq_read kernel/bpf/bpf_iter.c:158 vfs_read fs/read_write.c:572 ksys_read fs/read_write.c:716 do_syscall_64 arch/x86/entry/syscall_64.c:84 entry_SYSCALL_64_after_hwframe arch/x86/entry/entry_64.S:121 Kernel panic - not syncing: KASAN: panic_on_warn set ...
--- kernel/bpf/syscall.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +4 -1
@@ -5269,7 +5269,10 @@ struct bpf_link *bpf_link_get_curr_or_next(u32 *id) again: link =idr_get_next (&link_idr, id);if (link) { - link =bpf_link_inc_not_zero (link); +if (link->id) + link =bpf_link_inc_not_zero (link); +else + link =ERR_PTR (-EAGAIN );if (IS_ERR (link)) { (*id)++; goto again;
Signature · 1 line
2.53.0