6.1.188-rc1 review
Subsystems (3)
Greg Kroah-Hartman
maintainerPATCH 241/1191 wifi: mt76: mt7615: avoid waiting for mac work under the mt76 mutex
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit bda8324270b1ac91bfba1df8928e0570e29759e8 upstream.
mt7615_suspend() acquired the mt76 mutex and then called cancel_delayed_work_sync() on mac_work. mt7615_mac_work() acquires the same mutex via mt7615_mutex_acquire() at the top of the worker, so if mac_work is already running and blocked on the mutex, the suspend path deadlocks waiting for the work it holds the mutex against.
Flush scan_work and mac_work before taking the mutex, matching the suspend paths in mt7921 and mt7925. scan_work only takes the mt76 spinlock, but moving it keeps the sequence consistent. This also keeps mac_work from running over an already suspended HIF, which the previous split (async cancel under the lock, sync cancel after release) would have allowed.
--- drivers/net/wireless/mediatek/mt76/mt7615/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/main.c +3 -2
@@ -1217,11 +1217,12 @@ static int mt7615_suspend(struct ieee802cancel_delayed_work_sync (&dev->pm.ps_work);mt76_connac_free_pending_tx_skbs (&dev->pm,NULL ); +cancel_delayed_work_sync (&phy->scan_work); +cancel_delayed_work_sync (&phy->mt76->mac_work); +mt7615_mutex_acquire (dev);clear_bit (MT76_STATE_RUNNING , &phy->mt76->state); -cancel_delayed_work_sync (&phy->scan_work); -cancel_delayed_work_sync (&phy->mt76->mac_work);set_bit (MT76_STATE_SUSPEND , &phy->mt76->state); ieee80211_iterate_active_interfaces(hw,
Greg Kroah-Hartman
maintainerPATCH 242/1191 vsock/virtio: flush works in dependency order
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chengfeng Ye <[email protected]>
commit 728836ebca239810f164262b10211ef59182f811 upstream.
virtio_vsock_remove() stops the virtqueues and then flushes each work item before freeing the enclosing virtio_vsock. The current order does not account for dependencies between those items: tx_work may queue send_pkt_work, and send_pkt_work may queue rx_work.
In particular, send_pkt_work can set restart_rx and release tx_lock. The remove path can then stop the queues and flush rx_work before send_pkt_work queues it. Although the later send_pkt_work flush waits for that producer to finish, nothing waits for the newly queued rx_work, so kfree(vsock) can race with it.
KASAN reported:
BUG: KASAN: slab-use-after-free in virtio_transport_rx_work+0x487/0x4b0 Read of size 8 at addr ffff888114c2b008 by task kworker/1:1/47 Workqueue: virtio_vsock virtio_transport_rx_work Call Trace: virtio_transport_rx_work+0x487/0x4b0 process_one_work+0x688/0x1120 worker_thread+0x45b/0xd10 Allocated by task 1: virtio_vsock_probe+0xef/0x6b0 Freed by task 84: kfree+0x131/0x3c0 virtio_vsock_remove+0xd1/0x100
Flush the works in producer-to-consumer order. virtio_vsock_vqs_del() has already disabled the queue callbacks and cleared the run flags, so after tx_work and send_pkt_work are drained, no source remains that can queue rx_work after its flush.
--- net/vmw_vsock/virtio_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/vmw_vsock/virtio_transport.c +1 -1
@@ -714,10 +714,10 @@ static void virtio_vsock_remove(struct v/* Other works can be queued before 'config->del_vqs()', so we flush * all works before to free the vsock object to avoid use after free. */ -flush_work (&vsock->rx_work);flush_work (&vsock->tx_work);flush_work (&vsock->event_work);flush_work (&vsock->send_pkt_work); +flush_work (&vsock->rx_work);mutex_unlock (&the_virtio_vsock_mutex);
Greg Kroah-Hartman
maintainerPATCH 243/1191 w1: ds28e17: reject an oversize length on an I2C block read
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maoyi Xie <[email protected]>
commit 169ae5e65e5aaf213b6a578f6478a9fd2e523606 upstream.
w1_f19_i2c_master_transfer() is the master_xfer for the DS28E17 1-Wire to I2C bridge. On an I2C_M_RECV_LEN read, it takes the length from the device. The downstream slave puts a length byte in buf[0]. The driver then reads that many bytes into buf[1] with w1_f19_i2c_read().
buf[0] is controlled by the device and can be 0 to 255. w1_f19_i2c_read() only rejects a zero count. The caller buffer is I2C_SMBUS_BLOCK_MAX + 2, so 34 bytes. A length above 32 makes the read run past it, up to about 222 bytes out of bounds.
The SMBus core does check buf[0] against I2C_SMBUS_BLOCK_MAX. That check runs after master_xfer returns. By then the write is already done. i2c-algo-bit rejects an oversize length before it copies, and returns -EPROTO.
Reject a length above I2C_SMBUS_BLOCK_MAX at both RECV_LEN sites, the same way i2c-algo-bit does.
--- drivers/w1/slaves/w1_ds28e17.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/w1/slaves/w1_ds28e17.c +8 -0
@@ -389,6 +389,10 @@ static int w1_f19_i2c_master_transfer(st* another simple read in that case. */ if (msgs[i+1 ].flags &I2C_M_RECV_LEN ) { +if (msgs[i+1 ].buf[0 ] >I2C_SMBUS_BLOCK_MAX ) { + i = -EPROTO ; + goto error; + } result =w1_f19_i2c_read (sl, msgs[i+1 ].addr, &(msgs[i+1 ].buf[1 ]), msgs[i+1 ].buf[0 ]);if (result <0 ) {
@@ -415,6 +419,10 @@ static int w1_f19_i2c_master_transfer(st* another simple read in that case. */ if (msgs[i].flags &I2C_M_RECV_LEN ) { +if (msgs[i].buf[0 ] >I2C_SMBUS_BLOCK_MAX ) { + i = -EPROTO ; + goto error; + } result = w1_f19_i2c_read(sl, msgs[i].addr, &(msgs[i].buf[1]),
Greg Kroah-Hartman
maintainerPATCH 244/1191 xarray: honor XA_FLAGS_ACCOUNT in xas_split_alloc()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zi Yan <[email protected]>
commit 789763523fb43cdc328de5cb5dcd19240ccf90d8 upstream.
XArray operations that allocate xa_nodes, such as xas_nomem() and xas_alloc(), add __GFP_ACCOUNT when the array has XA_FLAGS_ACCOUNT set. This charges the allocated memory and avoids the workingset convergence issue described by commit 7b785645e8f13 ("mm: fix page cache convergence regression").
xas_split_alloc() does not add _GFP_ACCOUNT when XA_FLAGS_ACCOUNT is present. Fix it.
--- lib/xarray.c | 3 +++ 1 file changed, 3 insertions(+)
lib/xarray.c +3 -0
@@ -1014,6 +1014,9 @@ void xas_split_alloc(struct xa_state *xaif (xas->xa_shift +XA_CHUNK_SHIFT > order)return ; +if (xas->xa->xa_flags &XA_FLAGS_ACCOUNT ) + gfp |= __GFP_ACCOUNT; + do { unsigned int i; void *sibling = NULL;
Greg Kroah-Hartman
maintainerPATCH 245/1191 tpm: tpm_i2c_nuvoton: disable IRQ on wait timeout
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
commit 705c4ed0643366963547b2616d53165f2519c81f upstream.
i2c_nuvoton_wait_for_stat() enables the IRQ before waiting for the interrupt handler to report a status change. If the wait times out, or is interrupted before the handler runs, the function returns without balancing the enable_irq() call.
Disable the IRQ before leaving the failed wait path. Also preserve an interrupted wait's original error code instead of converting it to -ETIMEDOUT inside the helper.
--- drivers/char/tpm/tpm_i2c_nuvoton.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_i2c_nuvoton.c +4 -2
@@ -181,8 +181,10 @@ static int i2c_nuvoton_wait_for_stat(str timeout);if (rc >0 )return 0 ; -/* At this point we know that the SINT pin is asserted, so we -* do not need to do i2c_nuvoton_check_status */ + +disable_irq (priv->irq); +if (rc <0 ) +return rc; }else {unsigned long ten_msec, stop;bool status_valid;
Greg Kroah-Hartman
maintainerPATCH 246/1191 signal: avoid shared siginfo namespace rewrites
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit d19cdc167e696714509e87d3f7ae765b6e164589 upstream.
send_signal_locked() rewrites sender ids for the target namespace. Group sends reuse the same siginfo, so one recipient can affect the next.
Copy the siginfo before changing it.
--- kernel/signal.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/signal.c +4 -0
@@ -1225,6 +1225,7 @@ static inline bool has_si_pid_and_uid(stint send_signal_locked (int sig,struct kernel_siginfo *info,struct task_struct *t,enum pid_type type) { +struct kernel_siginfo rewritten;/* Should SIGKILL or SIGSTOP be received by a pid namespace init? */ bool force = false;
@@ -1238,6 +1239,9 @@ int send_signal_locked(int sig, struct k/* SIGKILL and SIGSTOP is special or has ids */ struct user_namespace *t_user_ns; + rewritten = *info; + info = &rewritten; +rcu_read_lock (); t_user_ns =task_cred_xxx (t, user_ns);if (current_user_ns () != t_user_ns) {
Greg Kroah-Hartman
maintainerPATCH 247/1191 smack: fix cred UAF in smack_file_send_sigiotask()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jann Horn <[email protected]>
commit fedc88e38ce979a720cd2de042578cb5df3dc8de upstream.
When inspecting the credentials of another task, objective credentials (->real_cred, accessed with __task_cred()) must always be used.
Accessing ->cred on a non-current task is forbidden unless that task is being created or destroyed; a task is allowed to change its own ->cred pointer with no synchronization, and changing ->cred should only affect the current syscall.
smack_file_send_sigiotask() was accessing both sets of credentials: First tsk->cred, then __task_cred(tsk).
Fix it, always access the objective credentials here.
I have tested that this bug can lead to a KASAN-reported UAF of struct cred in smack_file_send_sigiotask(), and that this fix prevents the race.
--- security/smack/smack_lsm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
security/smack/smack_lsm.c +1 -1
@@ -1836,7 +1836,7 @@ static int smack_file_send_sigiotask(str {struct smack_known **blob;struct smack_known *skp; -struct smack_known *tkp =smk_of_task (smack_cred (tsk->cred)); +struct smack_known *tkp =smk_of_task_struct_obj (tsk);const struct cred *tcred;struct file *file;int rc;
Greg Kroah-Hartman
maintainerPATCH 248/1191 taskstats: fix cpumask parsing cutting off the last character
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit 1f58a5335cdd14b3fb5f2a5d3763dee1f5cba1d3 upstream.
parse() hands nla_strscpy() len as dstsize, and nla_strscpy() copies at most dstsize - 1 bytes. When the attr payload comes in without a trailing NUL, srclen == len >= dstsize and the last character of the cpumask string gets cut off. Register "0-15" and you are silently listening on "0-1", exit data for the rest never shows up.
The bug only bites when the sender doesn't NUL terminate the payload; senders that include the NUL were always fine (srclen gets decremented for the trailing NUL, so srclen < dstsize). Thats probably why this survived 20 years. And the policy is NLA_STRING, not NLA_NUL_STRING, so a payload without the trailing NUL is legit input here.
Skip the kmalloc/nla_strscpy dance entirely and use nla_strdup(), which already allocates srclen + 1 and terminates. The nla_len() bounds checks stay as they were.
--- kernel/taskstats.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/taskstats.c +1 -2
@@ -368,10 +368,9 @@ static int parse(struct nlattr *na, strureturn -E2BIG ;if (len <1 )return -EINVAL ; - data =kmalloc (len,GFP_KERNEL ); + data =nla_strdup (na,GFP_KERNEL );if (!data)return -ENOMEM ; -nla_strscpy (data, na, len); ret =cpulist_parse (data, mask);kfree (data);return ret;
Greg Kroah-Hartman
maintainerPATCH 249/1191 timer: Keep debugobjects state consistent in migrate_timer_list()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
commit c793bbfc4a0a9f5a66978fc91559e9681748dbeb upstream.
When timers are migrated away from an offline CPU the debugobjects state gets corrupted. The timer is accounted as inactive on deletion, but the enqueue on the alive CPU lacks the activation call.
That used to work, but got broken when the trace point and the debug objects call got separated. That change missed to fixup migrate_timer_list().
Add the missing debug_timer_activate() invocation to fix it.
--- kernel/time/timer.c | 1 + 1 file changed, 1 insertion(+)
kernel/time/timer.c +1 -0
@@ -2224,6 +2224,7 @@ static void migrate_timer_list(struct ti timer = hlist_entry(head->first, struct timer_list, entry);detach_timer (timer, false); timer->flags = (timer->flags & ~TIMER_BASEMASK ) | cpu; +debug_timer_activate (timer);internal_add_timer (new_base, timer); } }
Greg Kroah-Hartman
maintainerPATCH 250/1191 udf: Fix i_lenExtents truncation on 32-bit kernels
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhan Xusheng <[email protected]>
commit a5a5ed23b1340ff0f32a14a7ca8585f7c4e9b2e2 upstream.
In udf_do_extend_file() the total extent length is rounded up to a block boundary with:
iinfo->i_lenExtents = (iinfo->i_lenExtents + sb->s_blocksize - 1) & ~(sb->s_blocksize - 1);
i_lenExtents is a __u64, but sb->s_blocksize is unsigned long. On 32-bit kernels unsigned long is 32-bit, so ~(sb->s_blocksize - 1) is a 32-bit value (e.g. 0xfffff800 for a 2 KiB block) that is zero-extended in the AND, clearing the upper 32 bits of i_lenExtents. For UDF files whose total extent length exceeds 4 GiB this truncates i_lenExtents when the file is extended, corrupting the tracked extent length.
Cast the block size to 64-bit before forming the mask. 64-bit kernels are unaffected.
--- fs/udf/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/udf/inode.c +1 -1
@@ -398,7 +398,7 @@ static int udf_do_extend_file(struct ino sb->s_blocksize - 1) & ~(sb->s_blocksize - 1)); iinfo->i_lenExtents = (iinfo->i_lenExtents + sb->s_blocksize -1 ) & - ~(sb->s_blocksize -1 ); + ~((u64 )sb->s_blocksize -1 ); }/* Can we merge with the previous extent? */
Greg Kroah-Hartman
maintainerPATCH 251/1191 platform/chrome: sensorhub: Fix dropped timestamp events and log spam
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit 9a3f43b30373c61477d0d3ab52946c05f9492bf9 upstream.
Commit 833740a2333c ("platform/chrome: sensorhub: Bound the EC-reported sensor number") evaluated the sensor_num against the bounds limit even for timestamp events. A timestamp event typically has a sensor_num of 0xff [1], causing the driver to flag it as invalid and skip to the next event.
As a result, we'd see a flooding of "Invalid sensor number 255 from EC" warning logs and these timestamp events were being dropped.
Move the bounds-check into cros_ec_sensor_ring_process_event() and evaluate it only after standalone timestamp events have already been processed and returned early.
[1] https://crrev.com/219ca6ef82ba266da788b673ee4ad50bd3ea1285/common/motion_sense_fifo.c#427
--- drivers/platform/chrome/cros_ec_sensorhub_ring.c | 27 ++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-)
drivers/platform/chrome/cros_ec_sensorhub_ring.c +15 -12
@@ -436,6 +436,21 @@ cros_ec_sensor_ring_process_event(struct fifo_timestamp, *current_timestamp, now); + +/* +* A standalone timestamp event typically has a sensor_num of +* 0xff. Return early here to prevent it from hitting the +* bounds check below and spamming the logs. +*/ +return false; + } + +/* Skip event if sensor_num from EC is out of bounds. */ +if (in->sensor_num >= sensorhub->sensor_num) { +dev_warn_ratelimited (sensorhub->dev, +"Invalid sensor number %u from EC\n" , + in->sensor_num); +return false; }if (in->flags &MOTIONSENSE_SENSOR_FLAG_ODR ) {
@@ -463,10 +478,6 @@ cros_ec_sensor_ring_process_event(structreturn true; } -if (in->flags &MOTIONSENSE_SENSOR_FLAG_TIMESTAMP ) -/* If we just have a timestamp, skip this entry. */ -return false; -/* Regular sample */ out->sensor_id = in->sensor_num; trace_cros_ec_sensorhub_data(in->sensor_num,
@@ -851,14 +862,6 @@ static void cros_ec_sensorhub_ring_handlfor (in = sensorhub->resp->fifo_read.data, j =0 ; j < number_data; j++, in++) { -/* Skip event if sensor_num from EC is out of bounds. */ -if (in->sensor_num >= sensorhub->sensor_num) { -dev_warn_ratelimited (sensorhub->dev, -"Invalid sensor number %u from EC\n" , - in->sensor_num); -continue ; - } - if (cros_ec_sensor_ring_process_event( sensorhub, fifo_info, fifo_timestamp,
Greg Kroah-Hartman
maintainerPATCH 252/1191 net: skbuff: dont skb_tx_error() the source skb in skb_zerocopy()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Norbert Szetei <[email protected]>
[ Upstream commit 8ece906150128d5ec2462aabcc978c568433eca4 ]
skb_zerocopy() copies frags from @from into @to. On an skb_orphan_frags() failure it calls skb_tx_error(@from), a destructive operation on the source skb the copy helper does not own. That completes @from's zerocopy uarg and clears SKBFL_ALL_ZEROCOPY, including the SKBFL_SHARED_FRAG page-ownership marker.
Both callers already report the failure on their own drop path. nfnetlink_queue does it at nla_put_failure, and Open vSwitch does it in the flow-miss drop arm of ovs_dp_process_packet(), so nothing is lost by dropping it here.
On Open vSwitch's OVS_ACTION_ATTR_USERSPACE path the skb is not freed on this error: do_execute_actions() ignores output_userspace()'s return value and, unless the upcall was the last action, keeps forwarding the same skb through the flow's remaining actions. The uarg is completed while that skb is still in flight, telling the producer its buffers are free, and SKBFL_SHARED_FRAG is cleared on an skb the rest of the stack still handles. That flag is what makes esp_input() call skb_cow_data() instead of decrypting in place, so a later local ESP delivery can decrypt over frags the skb does not own privately.
Leave error reporting to the callers.
--- net/core/skbuff.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/core/skbuff.c +2 -3
@@ -3356,10 +3356,9 @@ skb_zerocopy(struct sk_buff *to, struct sk_buff *from, int len, int hlen)skb_len_add (to, len + plen); -if (unlikely (skb_orphan_frags (from,GFP_ATOMIC ))) { -skb_tx_error (from); +if (unlikely (skb_orphan_frags (from,GFP_ATOMIC )))return -ENOMEM ; - } +skb_zerocopy_clone (to, from,GFP_ATOMIC );for (i =0 ; i <skb_shinfo (from)->nr_frags; i++) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 253/1191 net: openvswitch: fix kernel-doc warnings in internal headers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ilya Maximets <[email protected]>
[ Upstream commit 6bb0dcb3d321c14be7ca33b71a149034d6a2cde8 ]
Some field descriptions were missing, some were not very accurate. Not touching the uAPI header or .c files for now.
Formatting of those comments isn't great in general, but at least they are not missing anything now.
Before:
$ ./scripts/kernel-doc -none -Wall net/openvswitch/*.h 2>&1 | wc -l 16
After:
$ ./scripts/kernel-doc -none -Wall net/openvswitch/*.h 2>&1 | wc -l 0
--- net/openvswitch/datapath.h | 20 ++++++++++++++------ net/openvswitch/vport.h | 8 ++++++++ 2 files changed, 22 insertions(+), 6 deletions(-)
net/openvswitch/datapath.h +14 -6
@@ -29,8 +29,8 @@* datapath. * @n_hit: Number of received packets for which a matching flow was found in * the flow table. -* @n_miss: Number of received packets that had no matching flow in the flow -* table. The sum of @n_hit and @n_miss is the number of packets that have +* @n_missed: Number of received packets that had no matching flow in the flow +* table. The sum of @n_hit and @n_missed is the number of packets that have * been received by the datapath. * @n_lost: Number of received packets that had no matching flow in the flow * table that could not be sent to userspace (normally due to an overflow in
@@ -40,6 +40,7 @@* up per packet. * @n_cache_hit: The number of received packets that had their mask found using * the mask cache. +* @syncp: Synchronization point for 64bit counters. */ struct dp_stats_percpu {u64 n_hit;
@@ -74,8 +75,10 @@ struct dp_nlsk_pids {* ovs_mutex and RCU. * @stats_percpu: Per-CPU datapath statistics. * @net: Reference to net namespace. -* @max_headroom: the maximum headroom of all vports in this datapath; it will +* @user_features: Bitmap of enabled %OVS_DP_F_* features. +* @max_headroom: The maximum headroom of all vports in this datapath; it will * be used by all the internal vports in this dp. +* @meter_tbl: Meter table. * @upcall_portids: RCU protected 'struct dp_nlsk_pids'. * * Context: See the comment on locking at the top of datapath.c for additional
@@ -125,10 +128,13 @@ struct ovs_skb_cb {#define OVS_CB (skb) ((struct ovs_skb_cb *)(skb)->cb)/** -* struct dp_upcall - metadata to include with a packet to send to userspace +* struct dp_upcall_info - metadata to include with a packet sent to userspace * @cmd: One of %OVS_PACKET_CMD_*. * @userdata: If nonnull, its variable-length value is passed to userspace as * %OVS_PACKET_ATTR_USERDATA. +* @actions: If nonnull, its variable-length value is passed to userspace as +* %OVS_PACKET_ATTR_ACTIONS. +* @actions_len: The length of the @actions. * @portid: Netlink portid to which packet should be sent. If @portid is 0 * then no packet is sent and the packet is accounted in the datapath's @n_lost * counter.
@@ -149,6 +155,10 @@ struct dp_upcall_info {* struct ovs_net - Per net-namespace data for ovs. * @dps: List of datapaths to enable dumping them all out. * Protected by genl_mutex. +* @dp_notify_work: A work notifier to handle port unregistering. +* @masks_rebalance: A work to periodically optimize flow table caches. +* @ct_limit_info: A hash table of conntrack zone connection limits. +* @xt_label: Whether connlables are configured for the network or not. */ struct ovs_net {struct list_head dps;
@@ -157,8 +167,6 @@ struct ovs_net {#if IS_ENABLED (CONFIG_NETFILTER_CONNCOUNT )struct ovs_ct_limit_info *ct_limit_info;#endif - -/* Module reference for configuring conntrack. */ bool xt_label; };
net/openvswitch/vport.h +8 -0
@@ -93,6 +93,8 @@ struct vport {* @desired_ifindex: New vport's ifindex. * @dp: New vport's datapath. * @port_no: New vport's port number. +* @upcall_portids: %OVS_VPORT_ATTR_UPCALL_PID attribute from Netlink message, +* %NULL if none was supplied. */ struct vport_parms {const char *name;
@@ -121,6 +123,8 @@ struct vport_parms {* have any configuration. * @send: Send a packet on the device. * zero for dropped packets or negative for error. +* @owner: Module that implements this vport type. +* @list: List entry in the global list of vport types. */ struct vport_ops {enum ovs_vport_type type;
@@ -148,6 +152,8 @@ void ovs_vport_free(struct vport *);* * @vport: vport to access * +* Returns: A void pointer to a private data allocated in the @vport. +* * If a nonzero size was passed in priv_size of vport_alloc() a private data * area was allocated on creation. This allows that area to be accessed and * used for any purpose needed by the vport implementer.
@@ -162,6 +168,8 @@ static inline void *vport_priv(const struct vport *vport)* * @priv: Start of private data area. * +* Returns: A reference to a vport structure that contains @priv. +* * It is sometimes useful to translate from a pointer to the private data * area to the vport, such as in the case where the private data pointer is * the result of a hash table lookup. @priv must point to the start of the
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 254/1191 openvswitch: Fix CT limit teardown use-after-free
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuqi Xu <[email protected]>
[ Upstream commit 403f96c32c9e24600093d7d0c61c17daeedca957 ]
Packet processing uses CT limit state under RCU, while netns teardown frees that state under ovs_mutex. The CT limit pointer was neither removed from readers nor protected by a grace period, allowing packet processing to dereference the freed state.
An unprivileged user can trigger this bug from a user and network namespace, causing a slab-use-after-free in ovs_ct_execute() when the netns is torn down.
Publish the CT limit pointer through RCU, remove it before teardown, and wait for readers before freeing its contents. Keep ovs_mutex around individual CT limit updates, and use the RCU read-side lock while GET traverses the RCU-protected limit lists.
Netns teardown detaches the RCU-protected CT limit state in the pernet .pre_exit callback while holding ovs_mutex. The pernet core guarantees an RCU grace period between the .pre_exit and .exit callbacks, so the .exit callback completes the teardown without adding any extra synchronization.
The netlink command handlers do not need NULL checks because the userspace netlink socket holds an active reference to its network namespace while a request is processed. The per-netns exit path therefore cannot run concurrently with SET, DEL, or GET for that socket's namespace.
6.12+ doesn't have a 'family' argument in nf_conncount_init/destroy ]
--- net/openvswitch/conntrack.c | 122 +++++++++++++++++++++++------------- net/openvswitch/conntrack.h | 6 +- net/openvswitch/datapath.c | 10 ++- net/openvswitch/datapath.h | 8 ++- 4 files changed, 98 insertions(+), 48 deletions(-)
net/openvswitch/conntrack.c +79 -43
@@ -1182,10 +1182,14 @@ static int ovs_ct_check_limit(struct net *net, const struct ovs_conntrack_info *info) {struct ovs_net *ovs_net =net_generic (net, ovs_net_id); -const struct ovs_ct_limit_info *ct_limit_info = ovs_net->ct_limit_info; +const struct ovs_ct_limit_info *ct_limit_info;u32 per_zone_limit, connections;u32 conncount_key; + ct_limit_info =rcu_dereference (ovs_net->ct_limit_info); +if (!ct_limit_info) +return 0 ; + conncount_key = info->zone.id; per_zone_limit =ct_limit_get (ct_limit_info, info->zone.id);
@@ -1892,43 +1896,56 @@ static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info)#if IS_ENABLED (CONFIG_NETFILTER_CONNCOUNT )static int ovs_ct_limit_init (struct net *net,struct ovs_net *ovs_net) { +struct ovs_ct_limit_info *info;int i, err; - ovs_net->ct_limit_info =kmalloc (sizeof (*ovs_net->ct_limit_info), -GFP_KERNEL ); -if (!ovs_net->ct_limit_info) + info =kmalloc (sizeof (*info),GFP_KERNEL ); +if (!info)return -ENOMEM ; - ovs_net->ct_limit_info->default_limit =OVS_CT_LIMIT_DEFAULT ; - ovs_net->ct_limit_info->limits = + info->default_limit =OVS_CT_LIMIT_DEFAULT ; + info->limits =kmalloc_array (CT_LIMIT_HASH_BUCKETS ,sizeof (struct hlist_head ),GFP_KERNEL ); -if (!ovs_net->ct_limit_info->limits) { -kfree (ovs_net->ct_limit_info); +if (!info->limits) { +kfree (info);return -ENOMEM ; }for (i =0 ; i <CT_LIMIT_HASH_BUCKETS ; i++) -INIT_HLIST_HEAD (&ovs_net->ct_limit_info->limits[i]); +INIT_HLIST_HEAD (&info->limits[i]); - ovs_net->ct_limit_info->data = -nf_conncount_init (net,NFPROTO_INET ,sizeof (u32)); + info->data =nf_conncount_init (net,NFPROTO_INET ,sizeof (u32)); -if (IS_ERR (ovs_net->ct_limit_info->data)) { - err =PTR_ERR (ovs_net->ct_limit_info->data); -kfree (ovs_net->ct_limit_info->limits); -kfree (ovs_net->ct_limit_info); +if (IS_ERR (info->data)) { + err =PTR_ERR (info->data); +kfree (info->limits); +kfree (info);pr_err ("openvswitch: failed to init nf_conncount %d\n" , err);return err; } +rcu_assign_pointer (ovs_net->ct_limit_info, info);return 0 ; } -static void ovs_ct_limit_exit (struct net *net,struct ovs_net *ovs_net) +static void *ovs_ct_limit_exit_start (struct ovs_net *ovs_net) +{ +return rcu_replace_pointer (ovs_net->ct_limit_info,NULL , +lockdep_ovsl_is_held ()); +} + +/* The CT limit state must be detached by ovs_ct_limit_exit_start() and an +* RCU grace period must elapse before this function runs. The pernet core +* guarantees the grace period between the .pre_exit and .exit callbacks. +*/ +static void ovs_ct_limit_exit_finish (struct net *net,void *data) { -const struct ovs_ct_limit_info *info = ovs_net->ct_limit_info; +const struct ovs_ct_limit_info *info = data;int i; +if (!info) +return ; +nf_conncount_destroy (net,NFPROTO_INET , info->data);for (i =0 ; i <CT_LIMIT_HASH_BUCKETS ; ++i) {struct hlist_head *head = &info->limits[i];
@@ -1936,7 +1953,7 @@ static void ovs_ct_limit_exit(struct net *net, struct ovs_net *ovs_net)struct hlist_node *next;hlist_for_each_entry_safe (ct_limit, next, head, hlist_node) -kfree_rcu (ct_limit, rcu); +kfree (ct_limit); }kfree (info->limits);kfree (info);
@@ -1975,12 +1992,13 @@ static bool check_zone_id(int zone_id, u16 *pzone)return false; } -static int ovs_ct_limit_set_zone_limit (struct nlattr *nla_zone_limit, -struct ovs_ct_limit_info *info) +static int ovs_ct_limit_set_zone_limit (struct ovs_net *ovs_net, +struct nlattr *nla_zone_limit) {struct ovs_zone_limit *zone_limit; -int rem; +struct ovs_ct_limit_info *info;u16 zone; +int rem; rem =NLA_ALIGN (nla_len (nla_zone_limit)); zone_limit = (struct ovs_zone_limit *)nla_data (nla_zone_limit);
@@ -1989,6 +2007,7 @@ static int ovs_ct_limit_set_zone_limit(struct nlattr *nla_zone_limit,if (unlikely (zone_limit->zone_id ==OVS_ZONE_LIMIT_DEFAULT_ZONE )) {ovs_lock (); + info =ovsl_dereference (ovs_net->ct_limit_info); info->default_limit = zone_limit->limit;ovs_unlock (); } else if (unlikely(!check_zone_id(
@@ -2006,6 +2025,7 @@ static int ovs_ct_limit_set_zone_limit(struct nlattr *nla_zone_limit, ct_limit->limit = zone_limit->limit;ovs_lock (); + info =ovsl_dereference (ovs_net->ct_limit_info);ct_limit_set (info, ct_limit);ovs_unlock (); }
@@ -2020,12 +2040,13 @@ static int ovs_ct_limit_set_zone_limit(struct nlattr *nla_zone_limit,return 0 ; } -static int ovs_ct_limit_del_zone_limit (struct nlattr *nla_zone_limit, -struct ovs_ct_limit_info *info) +static int ovs_ct_limit_del_zone_limit (struct ovs_net *ovs_net, +struct nlattr *nla_zone_limit) {struct ovs_zone_limit *zone_limit; -int rem; +struct ovs_ct_limit_info *info;u16 zone; +int rem; rem =NLA_ALIGN (nla_len (nla_zone_limit)); zone_limit = (struct ovs_zone_limit *)nla_data (nla_zone_limit);
@@ -2034,6 +2055,7 @@ static int ovs_ct_limit_del_zone_limit(struct nlattr *nla_zone_limit,if (unlikely (zone_limit->zone_id ==OVS_ZONE_LIMIT_DEFAULT_ZONE )) {ovs_lock (); + info =ovsl_dereference (ovs_net->ct_limit_info); info->default_limit =OVS_CT_LIMIT_DEFAULT ;ovs_unlock (); } else if (unlikely(!check_zone_id(
@@ -2041,6 +2063,7 @@ static int ovs_ct_limit_del_zone_limit(struct nlattr *nla_zone_limit,OVS_NLERR (true,"zone id is out of range" ); }else {ovs_lock (); + info =ovsl_dereference (ovs_net->ct_limit_info);ct_limit_del (info, zone);ovs_unlock (); }
@@ -2084,6 +2107,7 @@ static int __ovs_ct_limit_get_zone_limit(struct net *net,return nla_put_nohdr (reply,sizeof (zone_limit), &zone_limit); } +/* Called with RCU read lock held. */ static int ovs_ct_limit_get_zone_limit(struct net *net, struct nlattr *nla_zone_limit, struct ovs_ct_limit_info *info,
@@ -2107,12 +2131,10 @@ static int ovs_ct_limit_get_zone_limit(struct net *net, &zone))) { OVS_NLERR(true, "zone id is out of range"); } else { -rcu_read_lock (); limit =ct_limit_get (info, zone); err =__ovs_ct_limit_get_zone_limit ( net, info->data, zone, limit, reply); -rcu_read_unlock ();if (err)return err; }
@@ -2127,6 +2149,7 @@ static int ovs_ct_limit_get_zone_limit(struct net *net,return 0 ; } +/* Called with RCU read lock held. */ static int ovs_ct_limit_get_all_zone_limit (struct net *net,struct ovs_ct_limit_info *info,struct sk_buff *reply)
@@ -2139,19 +2162,16 @@ static int ovs_ct_limit_get_all_zone_limit(struct net *net,if (err)return err; -rcu_read_lock ();for (i =0 ; i <CT_LIMIT_HASH_BUCKETS ; ++i) { head = &info->limits[i];hlist_for_each_entry_rcu (ct_limit, head, hlist_node) { err =__ovs_ct_limit_get_zone_limit (net, info->data, ct_limit->zone, ct_limit->limit, reply);if (err) - goto exit_err; +return err; } } -exit_err: -rcu_read_unlock ();return err; }
@@ -2161,7 +2181,6 @@ static int ovs_ct_limit_cmd_set(struct sk_buff *skb, struct genl_info *info)struct sk_buff *reply;struct ovs_header *ovs_reply_header;struct ovs_net *ovs_net =net_generic (sock_net (skb->sk), ovs_net_id); -struct ovs_ct_limit_info *ct_limit_info = ovs_net->ct_limit_info;int err; reply = ovs_ct_limit_cmd_reply_start(info, OVS_CT_LIMIT_CMD_SET,
@@ -2174,8 +2193,8 @@ static int ovs_ct_limit_cmd_set(struct sk_buff *skb, struct genl_info *info) goto exit_err; } - err =ovs_ct_limit_set_zone_limit (a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT ], - ct_limit_info); + err =ovs_ct_limit_set_zone_limit (ovs_net, + a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT ]);if (err) goto exit_err;
@@ -2195,7 +2214,6 @@ static int ovs_ct_limit_cmd_del(struct sk_buff *skb, struct genl_info *info)struct sk_buff *reply;struct ovs_header *ovs_reply_header;struct ovs_net *ovs_net =net_generic (sock_net (skb->sk), ovs_net_id); -struct ovs_ct_limit_info *ct_limit_info = ovs_net->ct_limit_info;int err; reply = ovs_ct_limit_cmd_reply_start(info, OVS_CT_LIMIT_CMD_DEL,
@@ -2208,8 +2226,8 @@ static int ovs_ct_limit_cmd_del(struct sk_buff *skb, struct genl_info *info) goto exit_err; } - err =ovs_ct_limit_del_zone_limit (a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT ], - ct_limit_info); + err =ovs_ct_limit_del_zone_limit (ovs_net, + a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT ]);if (err) goto exit_err;
@@ -2229,7 +2247,7 @@ static int ovs_ct_limit_cmd_get(struct sk_buff *skb, struct genl_info *info)struct ovs_header *ovs_reply_header;struct net *net =sock_net (skb->sk);struct ovs_net *ovs_net =net_generic (net, ovs_net_id); -struct ovs_ct_limit_info *ct_limit_info = ovs_net->ct_limit_info; +struct ovs_ct_limit_info *ct_limit_info;int err; reply = ovs_ct_limit_cmd_reply_start(info, OVS_CT_LIMIT_CMD_GET,
@@ -2243,18 +2261,19 @@ static int ovs_ct_limit_cmd_get(struct sk_buff *skb, struct genl_info *info) goto exit_err; } +rcu_read_lock (); + ct_limit_info =rcu_dereference (ovs_net->ct_limit_info);if (a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT ]) { err =ovs_ct_limit_get_zone_limit ( net, a[OVS_CT_LIMIT_ATTR_ZONE_LIMIT ], ct_limit_info, reply); -if (err) - goto exit_err; }else { err =ovs_ct_limit_get_all_zone_limit (net, ct_limit_info, reply); -if (err) - goto exit_err; } +rcu_read_unlock (); +if (err) + goto exit_err;nla_nest_end (reply, nla_reply);genlmsg_end (reply, ovs_reply_header);
@@ -2329,12 +2348,29 @@ int ovs_ct_init(struct net *net)return err; } -void ovs_ct_exit (struct net *net) +/* Must be called with ovs_mutex held. Detaches the RCU-protected +* ct_limit_info and stores it in ovs_net->ct_limit_exit_data for +* ovs_ct_exit_finish() to complete the teardown after an RCU grace period. +*/ +void ovs_ct_exit_start (struct net *net__maybe_unused ) +{ +#if IS_ENABLED (CONFIG_NETFILTER_CONNCOUNT ) +struct ovs_net *ovs_net =net_generic (net, ovs_net_id); + + ovs_net->ct_limit_exit_data =ovs_ct_limit_exit_start (ovs_net); +#endif +} + +/* Completes the CT limit teardown. The pernet core guarantees an RCU +* grace period between detaching the state in ovs_ct_exit_start() and +* this call, so no RCU readers remain. +*/ +void ovs_ct_exit_finish (struct net *net) {struct ovs_net *ovs_net =net_generic (net, ovs_net_id);#if IS_ENABLED (CONFIG_NETFILTER_CONNCOUNT ) -ovs_ct_limit_exit (net, ovs_net); +ovs_ct_limit_exit_finish (net, ovs_net->ct_limit_exit_data);#endif if (ovs_net->xt_label)
net/openvswitch/conntrack.h +4 -2
@@ -14,7 +14,8 @@ enum ovs_key_attr;#if IS_ENABLED (CONFIG_NF_CONNTRACK )int ovs_ct_init (struct net *); -void ovs_ct_exit (struct net *); +void ovs_ct_exit_start (struct net *net); +void ovs_ct_exit_finish (struct net *net);bool ovs_ct_verify (struct net *,enum ovs_key_attr attr); int ovs_ct_copy_action(struct net *, const struct nlattr *, const struct sw_flow_key *, struct sw_flow_actions **,
@@ -40,7 +41,8 @@ void ovs_ct_free_action(const struct nlattr *a);static inline int ovs_ct_init (struct net *net) {return 0 ; } -static inline void ovs_ct_exit (struct net *net) { } +static inline void ovs_ct_exit_start (struct net *net) { } +static inline void ovs_ct_exit_finish (struct net *net) { }static inline bool ovs_ct_verify (struct net *net,int attr) {
net/openvswitch/datapath.c +9 -1
@@ -2700,6 +2700,13 @@ static void __net_exit list_vports_from_net(struct net *net, struct net *dnet, } } +static void __net_exit ovs_pre_exit_net(struct net *dnet) +{ +ovs_lock (); +ovs_ct_exit_start (dnet); +ovs_unlock (); +} + static void __net_exit ovs_exit_net(struct net *dnet) {struct datapath *dp, *dp_next;
@@ -2710,7 +2717,7 @@ static void __net_exit ovs_exit_net(struct net *dnet)ovs_lock (); -ovs_ct_exit (dnet); +ovs_ct_exit_finish (dnet);list_for_each_entry_safe (dp, dp_next, &ovs_net->dps, list_node)__dp_destroy (dp);
@@ -2734,6 +2741,7 @@ static void __net_exit ovs_exit_net(struct net *dnet)static struct pernet_operations ovs_net_ops = { .init = ovs_init_net, + .pre_exit = ovs_pre_exit_net, .exit = ovs_exit_net, .id = &ovs_net_id, .size =sizeof (struct ovs_net ),
net/openvswitch/datapath.h +6 -2
@@ -157,7 +157,10 @@ struct dp_upcall_info {* Protected by genl_mutex. * @dp_notify_work: A work notifier to handle port unregistering. * @masks_rebalance: A work to periodically optimize flow table caches. -* @ct_limit_info: A hash table of conntrack zone connection limits. +* @ct_limit_info: Hash table of conntrack zone connection limits. Protected +* by RCU; updates and teardown are serialized by ovs_mutex. May be NULL during +* netns teardown. +* @ct_limit_exit_data: CT limit state detached at .pre_exit, freed at .exit. * @xt_label: Whether connlables are configured for the network or not. */ struct ovs_net {
@@ -165,7 +168,8 @@ struct ovs_net {struct work_struct dp_notify_work;struct delayed_work masks_rebalance;#if IS_ENABLED (CONFIG_NETFILTER_CONNCOUNT ) -struct ovs_ct_limit_info *ct_limit_info; +struct ovs_ct_limit_info __rcu *ct_limit_info; +struct ovs_ct_limit_info *ct_limit_exit_data;#endif bool xt_label; };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 255/1191 landlock: Require LANDLOCK_ACCESS_FS_MAKE_REG for whiteout creation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Günther Noack <[email protected]>
[ Upstream commit 672fa082d48b21e1fb62cdb184fee41513e53421 ]
Whiteout objects are used in the upper layer of an OverlayFS to indicate that the file with this name does not exist in the unified view, even if it is present in one of the lower layer file systems.
For the userspace implementations of OverlayFS (fuse-overlayfs), whiteout objects can be created from userspace as well:
* mknod(2) with S_IFCHR and makedev(0, 0)
* renameat2(2) with RENAME_WHITEOUT,
creating the whiteout in the old place of the moved file.
This commit guards whiteout creation in both of these cases with LANDLOCK_ACCESS_FS_MAKE_REG. Whiteout objects are *not* considered character devices and are not bound to a driver.
LANDLOCK_ACCESS_FS_MAKE_REG describes the same permission class as a whiteout object: creating one is the only S_IFCHR creation that the VFS exempts from CAP_MKNOD, so it is as unprivileged as creating a regular file, while LANDLOCK_ACCESS_FS_MAKE_CHAR and LANDLOCK_ACCESS_FS_MAKE_BLOCK keep meaning the creation of devices that expose a kernel interface [1].
For the mknod(2) case, introduce a Landlock erratum. The creation of whiteout objects through mknod(2) was previously guarded using LANDLOCK_ACCESS_FS_MAKE_CHAR, and it is now guarded using LANDLOCK_ACCESS_FS_MAKE_REG.
For the renameat2(2) case, fix a bug: Before this commit, renameat2(2) with RENAME_WHITEOUT would create a directory entry even when all LANDLOCK_ACCESS_FS_MAKE_* rights were denied.
This does not affect normal renames within layered OverlayFS mounts:
When doing a regular rename() on a mounted fuse-overlayfs, it is the fuse-overlayfs daemon that exercises renameat2() with RENAME_WHITEOUT, and only the Landlock domain of that daemon is checked there.
Depends-on: 49c9e09d9610 ("landlock: Fix handling of disconnected directories")
Depends-on: fe72ce6710cb ("landlock: Add errata documentation section")
[mic: Record why LANDLOCK_ACCESS_FS_MAKE_REG is the matching right, and add link(2) to the user doc]
--- include/uapi/linux/landlock.h | 1 + security/landlock/errata/abi-1.h | 24 +++++++++++++++++++ security/landlock/fs.c | 40 +++++++++++++++++++++++++------- 3 files changed, 56 insertions(+), 9 deletions(-) create mode 100644 security/landlock/errata/abi-1.h
include/uapi/linux/landlock.h +1 -0
@@ -115,6 +115,7 @@ struct landlock_path_beneath_attr {* device. * - %LANDLOCK_ACCESS_FS_MAKE_DIR: Create (or rename) a directory. * - %LANDLOCK_ACCESS_FS_MAKE_REG: Create (or rename or link) a regular file. +* This also guards the creation of whiteout objects as used in OverlayFS. * - %LANDLOCK_ACCESS_FS_MAKE_SOCK: Create (or rename or link) a UNIX domain * socket. * - %LANDLOCK_ACCESS_FS_MAKE_FIFO: Create (or rename or link) a named pipe.
security/landlock/errata/abi-1.h new file +24 -0
@@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/** +* DOC: erratum_4 +* +* Erratum 4: Creation of whiteout objects +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This fix changes the access rights required for the creation of whiteout +* objects through :manpage:`mknod(2)`, :manpage:`renameat2(2)`, or +* :manpage:`link(2)`. Creating whiteout objects is now guarded by +* ``LANDLOCK_ACCESS_FS_MAKE_REG`` instead of ``LANDLOCK_ACCESS_FS_MAKE_CHAR``. +* +* Whiteout objects are used in OverlayFS to mark the absence of a file in an +* upper file system. Despite being created with ``S_IFCHR``, whiteout objects +* do not count as character devices. +* +* Impact: +* +* Sandboxed programs that create OverlayFS whiteouts (such as fuse-overlayfs) +* now require ``LANDLOCK_ACCESS_FS_MAKE_REG`` instead of +* ``LANDLOCK_ACCESS_FS_MAKE_CHAR``. +*/ +LANDLOCK_ERRATUM (4 )
security/landlock/fs.c +31 -9
@@ -15,6 +15,7 @@#include <linux/err.h> #include <linux/fs.h> #include <linux/init.h> +#include <linux/kdev_t.h> #include <linux/kernel.h> #include <linux/limits.h> #include <linux/list.h>
@@ -664,7 +665,7 @@ static inline int current_check_access_path(const struct path *const path,return check_access_path (dom, path, access_request); } -static inline access_mask_t get_mode_access (const umode_t mode) +static inline access_mask_t get_mode_access (const umode_t mode,const dev_t dev) {switch (mode &S_IFMT ) {case S_IFLNK :
@@ -672,6 +673,9 @@ static inline access_mask_t get_mode_access(const umode_t mode)case S_IFDIR :return LANDLOCK_ACCESS_FS_MAKE_DIR ;case S_IFCHR : +/* Whiteout objects are guarded with MAKE_REG. */ +if (dev ==WHITEOUT_DEV ) +return LANDLOCK_ACCESS_FS_MAKE_REG ;return LANDLOCK_ACCESS_FS_MAKE_CHAR ;case S_IFBLK :return LANDLOCK_ACCESS_FS_MAKE_BLOCK ;
@@ -688,6 +692,13 @@ static inline access_mask_t get_mode_access(const umode_t mode) } } +static inline access_mask_t get_dentry_access (const struct dentry *const dentry) +{ +const struct inode *const inode =d_backing_inode (dentry); + +return get_mode_access (inode->i_mode, inode->i_rdev); +} +static inline access_mask_t maybe_remove (const struct dentry *const dentry) {if (d_is_negative (dentry))
@@ -768,6 +779,7 @@ static bool collect_domain_accesses(* @new_dentry: Destination file or directory. * @removable: Sets to true if it is a rename operation. * @exchange: Sets to true if it is a rename operation with RENAME_EXCHANGE. +* @whiteout: Sets to true if it is a rename operation with RENAME_WHITEOUT. * * Because of its unprivileged constraints, Landlock relies on file hierarchies * (and not only inodes) to tie access rights to files. Being able to link or
@@ -816,7 +828,8 @@ static bool collect_domain_accesses(static int current_check_refer_path (struct dentry *const old_dentry,const struct path *const new_dir,struct dentry *const new_dentry, -const bool removable,const bool exchange) +const bool removable,const bool exchange, +const bool whiteout) {const struct landlock_ruleset *const dom =landlock_get_current_domain ();
@@ -836,18 +849,25 @@ static int current_check_refer_path(struct dentry *const old_dentry,if (exchange) {if (unlikely (d_is_negative (new_dentry)))return -ENOENT ; - access_request_parent1 = -get_mode_access (d_backing_inode (new_dentry)->i_mode); + access_request_parent1 =get_dentry_access (new_dentry); }else { access_request_parent1 =0 ; } - access_request_parent2 = -get_mode_access (d_backing_inode (old_dentry)->i_mode); + access_request_parent2 =get_dentry_access (old_dentry);if (removable) { access_request_parent1 |=maybe_remove (old_dentry); access_request_parent2 |=maybe_remove (new_dentry); } +/* +* In case of renameat2(2) with RENAME_WHITEOUT, a whiteout object is +* created in the source location, so we require an additional access +* right there. +*/ +if (whiteout) + access_request_parent1 |= +get_mode_access (S_IFCHR |WHITEOUT_MODE ,WHITEOUT_DEV ); +/* The mount points are the same for old and new paths, cf. EXDEV. */ if (old_dentry->d_parent == new_dir->dentry) {/*
@@ -1099,7 +1119,7 @@ static int hook_path_link(struct dentry *const old_dentry, struct dentry *const new_dentry) {return current_check_refer_path (old_dentry, new_dir, new_dentry, false, - false); + false, false); } static int hook_path_rename(const struct path *const old_dir,
@@ -1110,7 +1130,8 @@ static int hook_path_rename(const struct path *const old_dir, {/* old_dir refers to old_dentry->d_parent and new_dir->mnt */ return current_check_refer_path (old_dentry, new_dir, new_dentry, true, - !!(flags &RENAME_EXCHANGE )); + !!(flags &RENAME_EXCHANGE ), + !!(flags &RENAME_WHITEOUT )); } static int hook_path_mkdir(const struct path *const dir,
@@ -1128,7 +1149,8 @@ static int hook_path_mknod(const struct path *const dir,if (!dom)return 0 ; -return check_access_path (dom, dir,get_mode_access (mode)); +return check_access_path (dom, dir, +get_mode_access (mode,new_decode_dev (dev))); } static int hook_path_symlink(const struct path *const dir,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 256/1191 netfilter: nf_tables: make nft_object rhltable per table
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
commit f4f699790590bd0896c48a71e9232a65198f92f0 upstream.
The nft_object rhltable is global, this allows for accessing objects that are being dismangled from lookup path by other existing netns. Given the nft_obj_destroy() releases the object inmediately, this might lead to use-after-free of these objects that are being released. Make the existing rhltable per table to address this issue to deal with with the nft_rcv_nl_event() path too.
Update nft_obj_lookup() to take the table as non-const, otherwise, compiler complains when passing the objname_ht to rhltable_lookup().
[ 6.1: Conflicts in nf_tables_api.c because 6.1 lacks three mainline
refactors: 0be908750162 ("netfilter: nf_tables: pass nft_table to destroy function", v6.11), e169285f8c56 ("netfilter: nf_tables: do not store nft_ctx in transaction objects", v6.11) and f80a612dd77c ("netfilter: nf_tables: add support to destroy operation", v6.3). As a result 6.1's nf_tables_table_destroy() still takes an nft_ctx; struct nft_trans still embeds an nft_ctx (so the owning table is trans->ctx.table, not a per-transaction table local); and the commit path has no NFT_MSG_DESTROYOBJ case. Resolved by destroying the per-table objname_ht via ctx->table in nf_tables_table_destroy(), and by passing the owning table trans->ctx.table to nft_obj_del() in the commit and abort paths; 6.1's single NFT_MSG_DELOBJ case is retained. The header and all other hunks applied cleanly. ]
--- include/net/netfilter/nf_tables.h | 4 +++- net/netfilter/nf_tables_api.c | 34 +++++++++++++++---------------- 2 files changed, 19 insertions(+), 19 deletions(-)
include/net/netfilter/nf_tables.h +3 -1
@@ -1212,6 +1212,7 @@ static inline void nft_use_inc_restore(u32 *use)* @sets: sets in the table * @objects: stateful objects in the table * @flowtables: flow tables in the table +* @objname_ht: hashtable for objects lookup by name * @hgenerator: handle generator state * @handle: table handle * @use: number of chain references to this table
@@ -1227,6 +1228,7 @@ struct nft_table {struct list_head sets;struct list_head objects;struct list_head flowtables; +struct rhltable objname_ht;u64 hgenerator;u64 handle;u32 use;
@@ -1305,7 +1307,7 @@ static inline void *nft_obj_data(const struct nft_object *obj)#define nft_expr_obj (expr) *((struct nft_object **)nft_expr_priv(expr))struct nft_object *nft_obj_lookup (const struct net *net, -const struct nft_table *table, +struct nft_table *table,const struct nlattr *nla,u32 objtype,u8 genmask);
net/netfilter/nf_tables_api.c +16 -18
@@ -42,8 +42,6 @@ enum { NFT_VALIDATE_DO, }; -static struct rhltable nft_objname_ht; -static u32 nft_chain_hash (const void *data,u32 len,u32 seed);static u32 nft_chain_hash_obj (const void *data,u32 len,u32 seed);static int nft_chain_hash_cmp (struct rhashtable_compare_arg *,const void *);
@@ -1415,6 +1413,10 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,if (err) goto err_chain_ht; + err =rhltable_init (&table->objname_ht, &nft_objname_ht_params); +if (err <0 ) + goto err_obj_ht; +INIT_LIST_HEAD (&table->chains);INIT_LIST_HEAD (&table->sets);INIT_LIST_HEAD (&table->objects);
@@ -1433,6 +1435,8 @@ static int nf_tables_newtable(struct sk_buff *skb, const struct nfnl_info *info,list_add_tail_rcu (&table->list, &nft_net->tables);return 0 ; err_trans: +rhltable_destroy (&table->objname_ht); +err_obj_ht:rhltable_destroy (&table->chains_ht); err_chain_ht:kfree (table->udata);
@@ -1595,6 +1599,7 @@ static void nf_tables_table_destroy(struct nft_ctx *ctx)return ;rhltable_destroy (&ctx->table->chains_ht); +rhltable_destroy (&ctx->table->objname_ht);kfree (ctx->table->name);kfree (ctx->table->udata);kfree (ctx->table);
@@ -7149,7 +7154,7 @@ void nft_unregister_obj(struct nft_object_type *obj_type)EXPORT_SYMBOL_GPL (nft_unregister_obj);struct nft_object *nft_obj_lookup (const struct net *net, -const struct nft_table *table, +struct nft_table *table,const struct nlattr *nla,u32 objtype,u8 genmask) {
@@ -7165,7 +7170,7 @@ struct nft_object *nft_obj_lookup(const struct net *net, !lockdep_commit_lock_is_held(net));rcu_read_lock (); - list =rhltable_lookup (&nft_objname_ht, &k, nft_objname_ht_params); + list =rhltable_lookup (&table->objname_ht, &k, nft_objname_ht_params);if (!list) goto out;
@@ -7444,7 +7449,7 @@ static int nf_tables_newobj(struct sk_buff *skb, const struct nfnl_info *info,if (err <0 ) goto err_trans; - err =rhltable_insert (&nft_objname_ht, &obj->rhlhead, + err =rhltable_insert (&table->objname_ht, &obj->rhlhead, nft_objname_ht_params);if (err <0 ) goto err_obj_ht;
@@ -7640,8 +7645,8 @@ nf_tables_getobj_single(u32 portid, const struct nfnl_info *info,struct netlink_ext_ack *extack = info->extack;u8 genmask =nft_genmask_cur (info->net);u8 family = info->nfmsg->nfgen_family; -const struct nft_table *table;struct net *net = info->net; +struct nft_table *table;struct nft_object *obj;struct sk_buff *skb2;u32 objtype;
@@ -9319,9 +9324,9 @@ static void nf_tables_commit_chain(struct net *net, struct nft_chain *chain)nf_tables_commit_chain_free_rules_old (g0); } -static void nft_obj_del (struct nft_object *obj) +static void nft_obj_del (struct nft_table *table,struct nft_object *obj) { -rhltable_remove (&nft_objname_ht, &obj->rhlhead, nft_objname_ht_params); +rhltable_remove (&table->objname_ht, &obj->rhlhead, nft_objname_ht_params);list_del_rcu (&obj->list); }
@@ -9972,7 +9977,7 @@ static int nf_tables_commit(struct net *net, struct sk_buff *skb) }break ;case NFT_MSG_DELOBJ : -nft_obj_del (nft_trans_obj (trans)); +nft_obj_del (trans->ctx.table,nft_trans_obj (trans));nf_tables_obj_notify (&trans->ctx,nft_trans_obj (trans),NFT_MSG_DELOBJ );break ;
@@ -10231,7 +10236,7 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action)nft_trans_destroy (trans); }else {nft_use_dec_restore (&trans->ctx.table->use); -nft_obj_del (nft_trans_obj (trans)); +nft_obj_del (trans->ctx.table,nft_trans_obj (trans)); }break ;case NFT_MSG_DELOBJ :
@@ -10870,7 +10875,7 @@ static void __nft_release_table(struct net *net, struct nft_table *table)nft_set_destroy (&ctx, set); }list_for_each_entry_safe (obj, ne, &table->objects, list) { -nft_obj_del (obj); +nft_obj_del (table, obj);nft_use_dec (&table->use);nft_obj_destroy (&ctx, obj); }
@@ -11033,10 +11038,6 @@ static int __init nf_tables_module_init(void)if (err <0 ) goto err_netdev_notifier; - err =rhltable_init (&nft_objname_ht, &nft_objname_ht_params); -if (err <0 ) - goto err_rht_objname; - err =nft_offload_init ();if (err <0 ) goto err_offload;
@@ -11059,8 +11060,6 @@ static int __init nf_tables_module_init(void) err_netlink_notifier:nft_offload_exit (); err_offload: -rhltable_destroy (&nft_objname_ht); -err_rht_objname:unregister_netdevice_notifier (&nf_tables_flowtable_notifier); err_netdev_notifier:nf_tables_core_module_exit ();
@@ -11084,7 +11083,6 @@ static void __exit nf_tables_module_exit(void)cancel_work_sync (&trans_gc_work);cancel_work_sync (&trans_destroy_work);rcu_barrier (); -rhltable_destroy (&nft_objname_ht);nf_tables_core_module_exit (); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 257/1191 fsnotify: Fix stale object mask after concurrent mark updates
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngjae Kwon <[email protected]>
[ Upstream commit e422777fdd4746de1109575c51e65038d4c5c1be ]
When a mark gets a new event bit, fanotify and inotify may avoid recalculating the object mask if the cached aggregate already contains that bit. This is racy with a recalculation triggered by a concurrent update to another mark on the same connector.
The concurrent scan can read the mark before the new bit is added, while the updater reads the old aggregate before that scan publishes its result. The updater then skips recalculation and the scan publishes a mask without the bit, leaving the object mask stale after both updates complete.
This can be reproduced with two fanotify groups watching the same inode:
one thread removes FAN_MODIFY from one existing mark while another thread adds FAN_MODIFY to the other mark. After both fanotify_mark() calls return, writes can fail to produce FAN_MODIFY for the group whose mark now contains the bit. This was reproduced on an unmodified v6.12.95 kernel. The equivalent inotify interleaving loses IN_MODIFY events.
For normal fanotify additions, recalculate whenever the raw mark mask changes. The normal mask is not cleared asynchronously, so an unchanged addition cannot introduce missing interest. Always recalculate ignore-mask updates because FS_MODIFY handling may clear the ignore mask without taking mark->lock, making snapshot comparisons unreliable.
Always recalculate after updating an existing inotify watch. Its replace path temporarily sets mark->mask to zero, so a concurrent scan can observe zero even when the old and final masks are equal. Assigning the replacement mask directly would avoid the transient zero, but existing-watch updates are infrequent, so unconditional recalculation is simpler.
[yjkwon0026: Resolve the inotify conflict by retaining the branch-native inode->i_fsnotify_marks argument to fsnotify_recalc_mask(). This tree lacks 35ceae44742e ("fsnotify: Avoid data race between fsnotify_recalc_mask() and fsnotify_object_watched()") and 4520b96b8136 ("fsnotify: inotify: pass mark connector to fsnotify_recalc_mask()"). The differing READ_ONCE() line and connector call are in the conditional deleted by this patch, so neither commit is a prerequisite for this fix.]
--- fs/notify/fanotify/fanotify_user.c | 12 +++++++----- fs/notify/inotify/inotify_user.c | 15 +-------------- 2 files changed, 8 insertions(+), 19 deletions(-)
fs/notify/fanotify/fanotify_user.c +7 -5
@@ -1126,16 +1126,18 @@ static bool fanotify_mark_update_flags(struct fsnotify_mark *fsn_mark,static bool fanotify_mark_add_to_mask (struct fsnotify_mark *fsn_mark,__u32 mask,unsigned int fan_flags) { +__u32 old_mask;bool recalc;spin_lock (&fsn_mark->lock); -if (!(fan_flags &FANOTIFY_MARK_IGNORE_BITS )) +if (!(fan_flags &FANOTIFY_MARK_IGNORE_BITS )) { + old_mask = fsn_mark->mask; fsn_mark->mask |= mask; -else + recalc = old_mask != fsn_mark->mask; + }else { fsn_mark->ignore_mask |= mask; - - recalc =fsnotify_calc_mask (fsn_mark) & - ~fsnotify_conn_mask (fsn_mark->connector); + recalc = true; + } recalc |=fanotify_mark_update_flags (fsn_mark, fan_flags);spin_unlock (&fsn_mark->lock);
fs/notify/inotify/inotify_user.c +1 -14
@@ -540,7 +540,6 @@ static int inotify_update_existing_watch(struct fsnotify_group *group, {struct fsnotify_mark *fsn_mark;struct inotify_inode_mark *i_mark; -__u32 old_mask, new_mask;int replace = !(arg &IN_MASK_ADD );int create = (arg &IN_MASK_CREATE );int ret;
@@ -556,27 +555,15 @@ static int inotify_update_existing_watch(struct fsnotify_group *group, i_mark = container_of(fsn_mark, struct inotify_inode_mark, fsn_mark);spin_lock (&fsn_mark->lock); - old_mask = fsn_mark->mask;if (replace) { fsn_mark->mask =0 ; fsn_mark->flags &= ~INOTIFY_MARK_FLAGS ; } fsn_mark->mask |=inotify_arg_to_mask (inode, arg); fsn_mark->flags |=inotify_arg_to_flags (arg); - new_mask = fsn_mark->mask;spin_unlock (&fsn_mark->lock); -if (old_mask != new_mask) { -/* more bits in old than in new? */ -int dropped = (old_mask & ~new_mask); -/* more bits in this fsn_mark than the inode's mask? */ -int do_inode = (new_mask & ~inode->i_fsnotify_mask); - -/* update the inode with this new fsn_mark */ -if (dropped || do_inode) -fsnotify_recalc_mask (inode->i_fsnotify_marks); - - } +fsnotify_recalc_mask (inode->i_fsnotify_marks);/* return the wd */ ret = i_mark->wd;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 258/1191 tcp: fix potential race in tcp_v6_syn_recv_sock()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 858d2a4f67ff69e645a43487ef7ea7f28f06deae ]
Code in tcp_v6_syn_recv_sock() after the call to tcp_v4_syn_recv_sock() is done too late.
After tcp_v4_syn_recv_sock(), the child socket is already visible from TCP ehash table and other cpus might use it.
Since newinet->pinet6 is still pointing to the listener ipv6_pinfo bad things can happen as syzbot found.
Move the problematic code in tcp_v6_mapped_child_init() and call this new helper from tcp_v4_syn_recv_sock() before the ehash insertion.
This allows the removal of one tcp_sync_mss(), since tcp_v4_syn_recv_sock() will call it with the correct context.
[florian:
- net/ipv6/tcp_ipv6.c:
- Set newnp->ipv6_fl_list = NULL instead of newinet->ipv6_fl_list = NULL, as ipv6_fl_list is in struct ipv6_pinfo.
- Guarded af_specific assignment with #ifdef CONFIG_TCP_MD5SIG instead of checking CONFIG_TCP_AO.
- Used if (tcp_inet6_sk(sk)->repflow) instead of inet6_test_bit(REPFLOW, sk).
- net/dccp/:
- Updated syn_recv_sock implementations and call sites for DCCP, which was removed in upstream kernels prior to this commit.]
--- include/net/inet_connection_sock.h | 4 +- include/net/tcp.h | 4 +- net/dccp/dccp.h | 4 +- net/dccp/ipv4.c | 4 +- net/dccp/ipv6.c | 7 ++- net/dccp/minisocks.c | 2 +- net/ipv4/syncookies.c | 2 +- net/ipv4/tcp_fastopen.c | 2 +- net/ipv4/tcp_ipv4.c | 8 ++- net/ipv4/tcp_minisocks.c | 2 +- net/ipv6/tcp_ipv6.c | 97 +++++++++++++----------------- net/mptcp/subflow.c | 6 +- net/smc/af_smc.c | 6 +- 13 files changed, 78 insertions(+), 70 deletions(-)
include/net/inet_connection_sock.h +3 -1
@@ -42,7 +42,9 @@ struct inet_connection_sock_af_ops {struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req); + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk));u16 net_header_len;u16 net_frag_header_len;u16 sockaddr_len;
include/net/tcp.h +3 -1
@@ -468,7 +468,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req); + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk));int tcp_v4_do_rcv (struct sock *sk,struct sk_buff *skb);int tcp_v4_connect (struct sock *sk,struct sockaddr *uaddr,int addr_len);int tcp_connect (struct sock *sk);
net/dccp/dccp.h +3 -1
@@ -267,7 +267,9 @@ struct sock *dccp_v4_request_recv_sock(const struct sock *sk, struct sk_buff *skstruct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req); + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk));struct sock *dccp_check_req (struct sock *sk,struct sk_buff *skb,struct request_sock *req);
net/dccp/ipv4.c +3 -1
@@ -409,7 +409,9 @@ struct sock *dccp_v4_request_recv_sock(const struct sock *sk,struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct inet_request_sock *ireq;struct inet_sock *newinet;
net/dccp/ipv6.c +5 -2
@@ -416,7 +416,9 @@ static struct sock *dccp_v6_request_recv_sock(const struct sock *sk,struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct inet_request_sock *ireq = inet_rsk(req);struct ipv6_pinfo *newnp;
@@ -431,7 +433,8 @@ static struct sock *dccp_v6_request_recv_sock(const struct sock *sk,* v6 mapped */ newsk =dccp_v4_request_recv_sock (sk, skb, req, dst, - req_unhash, own_req); + req_unhash, own_req, + opt_child_init);if (newsk ==NULL )return NULL ;
net/dccp/minisocks.c +1 -1
@@ -193,7 +193,7 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, goto drop; child =inet_csk (sk)->icsk_af_ops->syn_recv_sock (sk, skb, req,NULL , - req, &own_req); + req, &own_req,NULL );if (child) { child =inet_csk_complete_hashdance (sk, child, req, own_req); goto out;
net/ipv4/syncookies.c +1 -1
@@ -199,7 +199,7 @@ struct sock *tcp_get_cookie_sock(struct sock *sk, struct sk_buff *skb,bool own_req; child = icsk->icsk_af_ops->syn_recv_sock (sk, skb, req, dst, -NULL , &own_req); +NULL , &own_req,NULL );if (child) {refcount_set (&req->rsk_refcnt,1 );tcp_sk (child)->tsoffset = tsoff;
net/ipv4/tcp_fastopen.c +1 -1
@@ -247,7 +247,7 @@ static struct sock *tcp_fastopen_create_child(struct sock *sk,bool own_req; child =inet_csk (sk)->icsk_af_ops->syn_recv_sock (sk, skb, req,NULL , -NULL , &own_req); +NULL , &own_req,NULL );if (!child)return NULL ;
net/ipv4/tcp_ipv4.c +7 -1
@@ -1509,7 +1509,9 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb,struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct inet_request_sock *ireq;bool found_dup_sk = false;
@@ -1565,6 +1567,10 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, }sk_setup_caps (newsk, dst); +#if IS_ENABLED (CONFIG_IPV6 ) +if (opt_child_init) +opt_child_init (newsk, sk); +#endif tcp_ca_openreq_child (newsk, dst);tcp_sync_mss (newsk,dst_mtu (dst));
net/ipv4/tcp_minisocks.c +1 -1
@@ -780,7 +780,7 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,* socket is created, wait for troubles. */ child =inet_csk (sk)->icsk_af_ops->syn_recv_sock (sk, skb, req,NULL , - req, &own_req); + req, &own_req,NULL );if (!child) goto listen_overflow;
net/ipv6/tcp_ipv6.c +42 -55
113 lines not on this page · raw message
net/mptcp/subflow.c +4 -2
@@ -699,7 +699,9 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct mptcp_subflow_context *listener = mptcp_subflow_ctx(sk);struct mptcp_subflow_request_sock *subflow_req;
@@ -745,7 +747,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, create_child: child = listener->icsk_af_ops->syn_recv_sock (sk, skb, req, dst, - req_unhash, own_req); + req_unhash, own_req, opt_child_init);if (child && *own_req) {struct mptcp_subflow_context *ctx =mptcp_subflow_ctx (child);
net/smc/af_smc.c +4 -2
@@ -118,7 +118,9 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,struct request_sock *req, struct dst_entry *dst, struct request_sock *req_unhash, - bool *own_req) + bool *own_req, + void (*opt_child_init)(struct sock *newsk, + const struct sock *sk)) { struct smc_sock *smc;struct sock *child;
@@ -143,7 +145,7 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,/* passthrough to original syn recv sock fct */ child = smc->ori_af_ops->syn_recv_sock (sk, skb, req, dst, req_unhash, - own_req); + own_req, opt_child_init);/* child must not inherit smc or its ops */ if (child) {rcu_assign_sk_user_data (child,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 259/1191 entry: Fix seccomp bypass after ptrace with TSYNC
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
commit 4a3591287fb7f808e209b4974ed337f609a2006b upstream.
Sashiko review pointed out the following issue.
If a thread is stopped in syscall_trace_enter() for ptrace, another thread can install a seccomp filter with SECCOMP_FILTER_FLAG_TSYNC (e.g., via seccomp_attach_filter()). This will successfully set SYSCALL_WORK_SECCOMP on the stopped thread, but syscall_trace_enter() evaluates a cached 'work' variable sampled on entry. Consequently, the subsequent check for SYSCALL_WORK_SECCOMP misses the newly assigned flag, and the filter is silently bypassed.
This race condition could allow an unprivileged process to execute a prohibited system call (e.g., execve) that the newly installed filter was intended to block, especially since the tracer might have modified the system call number during the ptrace stop.
Fix this by re-reading the syscall_work flags after ptrace handling, so that any new SYSCALL_WORK_SECCOMP flag set by another thread via TSYNC during the ptrace stop is observed before the subsequent seccomp check.
--- kernel/entry/common.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/entry/common.c +3 -0
@@ -65,6 +65,9 @@ static long syscall_trace_enter(struct pt_regs *regs, long syscall, ret =ptrace_report_syscall_entry (regs);if (ret || (work &SYSCALL_WORK_SYSCALL_EMU ))return -1L ; + +/* ptrace might have changed work flags */ + work =READ_ONCE (current_thread_info ()->syscall_work); }/* Do seccomp after ptrace, to catch any tracer changes. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 260/1191 selinux: avoid implicit conversions in services code
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Göttsche <[email protected]>
commit c50e125d057152bc68dfd5669b73611343653eb7 upstream.
Use u32 as the output parameter type in security_get_classes() and security_get_permissions(), based on the type of the symtab nprim member.
Declare the read-only class string parameter ofsecurity_get_permissions() const.
Avoid several implicit conversions by using the identical type for the destination.
Use the type identical to the source for local variables.
--- security/selinux/include/security.h | 4 ++-- security/selinux/selinuxfs.c | 7 ++++--- security/selinux/ss/services.c | 23 ++++++++++++----------- 3 files changed, 18 insertions(+), 16 deletions(-)
security/selinux/include/security.h +2 -2
@@ -379,9 +379,9 @@ int security_net_peersid_resolve(struct selinux_state *state, u32 *peer_sid);int security_get_classes (struct selinux_policy *policy, -char ***classes,int *nclasses); +char ***classes,u32 *nclasses);int security_get_permissions (struct selinux_policy *policy, -char *class,char ***perms,int *nperms); +char *class,char ***perms,u32 *nperms);int security_get_reject_unknown (struct selinux_state *state);int security_get_allow_unknown (struct selinux_state *state);
security/selinux/selinuxfs.c +4 -3
@@ -1874,7 +1874,8 @@ static int sel_make_perm_files(struct selinux_policy *newpolicy, char *objclass, int classvalue, struct dentry *dir) { - int i, rc, nperms; + u32 i, nperms; +int rc;char **perms; rc =security_get_permissions (newpolicy, objclass, &perms, &nperms);
@@ -1944,8 +1945,8 @@ static int sel_make_classes(struct selinux_policy *newpolicy,struct dentry *class_dir, unsigned long *last_class_ino) { - - int rc, nclasses, i; + u32 i, nclasses; +int rc;char **classes; rc =security_get_classes (newpolicy, &classes, &nclasses);
security/selinux/ss/services.c +12 -11
@@ -869,7 +869,7 @@ int security_bounded_transition(struct selinux_state *state,struct sidtab *sidtab;struct sidtab_entry *old_entry, *new_entry;struct type_datum *type; -int index; +u32 index;int rc;if (!selinux_initialized (state))
@@ -1537,7 +1537,7 @@ static int security_context_to_sid_core(struct selinux_state *state,return -ENOMEM ;if (!selinux_initialized (state)) { -int i; +u32 i;for (i =1 ; i <SECINITSID_NUM ; i++) {const char *s = initial_sid_to_string[i];
@@ -2886,7 +2886,6 @@ static inline int __security_genfs_sid(struct selinux_policy *policy, {struct policydb *policydb = &policy->policydb;struct sidtab *sidtab = policy->sidtab; -int len;u16 sclass;struct genfs *genfs;struct ocontext *c;
@@ -2908,7 +2907,7 @@ static inline int __security_genfs_sid(struct selinux_policy *policy,return -ENOENT ;for (c = genfs->head; c; c = c->next) { - len =strlen (c->u.name); +size_t len =strlen (c->u.name);if ((!c->v.sclass || sclass == c->v.sclass) && (strncmp (c->u.name, path, len) ==0 ))break ;
@@ -3402,7 +3401,7 @@ static int get_classes_callback(void *k, void *d, void *args) {struct class_datum *datum = d;char *name = k, **classes = args; -int value = datum->value -1 ; +u32 value = datum->value -1 ; classes[value] =kstrdup (name,GFP_ATOMIC );if (!classes[value])
@@ -3412,7 +3411,7 @@ static int get_classes_callback(void *k, void *d, void *args) }int security_get_classes (struct selinux_policy *policy, -char ***classes,int *nclasses) +char ***classes,u32 *nclasses) {struct policydb *policydb;int rc;
@@ -3428,7 +3427,8 @@ int security_get_classes(struct selinux_policy *policy, rc =hashtab_map (&policydb->p_classes.table, get_classes_callback, *classes);if (rc) { -int i; +u32 i; +for (i =0 ; i < *nclasses; i++)kfree ((*classes)[i]);kfree (*classes);
@@ -3442,7 +3442,7 @@ static int get_permissions_callback(void *k, void *d, void *args) {struct perm_datum *datum = d;char *name = k, **perms = args; -int value = datum->value -1 ; +u32 value = datum->value -1 ; perms[value] =kstrdup (name,GFP_ATOMIC );if (!perms[value])
@@ -3452,10 +3452,11 @@ static int get_permissions_callback(void *k, void *d, void *args) }int security_get_permissions (struct selinux_policy *policy, -char *class,char ***perms,int *nperms) +char *class,char ***perms,u32 *nperms) {struct policydb *policydb; -int rc, i; +u32 i; +int rc;struct class_datum *match; policydb = &policy->policydb;
@@ -3675,7 +3676,7 @@ int selinux_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule,/* Check to see if the rule contains any selinux fields */ int selinux_audit_rule_known (struct audit_krule *rule) { -int i; +u32 i;for (i =0 ; i < rule->field_count; i++) {struct audit_field *f = &rule->fields[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 261/1191 selinux: reject an unclaimed class value in security_get_classes()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 22b05fec62c0fe9864cfceb52f7d0f3a34d9b1dd upstream.
security_get_classes() sizes an array by p_classes.nprim and fills it at value - 1, so a class value the policy never defines leaves a NULL. sel_make_classes() passes every entry to sel_make_dir(), reaching the same d_alloc_name() dereference as the permission array. The class symbol table is allowed to be sparse (policydb_class_isvalid() exists to absorb that), but this getter builds its own array straight from the hash table and has no such predicate.
Fail the lookup when a value went unclaimed instead of handing out the NULL. Conforming policies define every class they declare and are unaffected.
--- security/selinux/ss/services.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
security/selinux/ss/services.c +19 -5
@@ -3414,6 +3414,7 @@ int security_get_classes(struct selinux_policy *policy, char ***classes, u32 *nclasses) { struct policydb *policydb; +u32 i;int rc; policydb = &policy->policydb;
@@ -3426,16 +3427,29 @@ int security_get_classes(struct selinux_policy *policy, rc =hashtab_map (&policydb->p_classes.table, get_classes_callback, *classes); -if (rc) { -u32 i; +if (rc) + goto err; -for (i =0 ; i < *nclasses; i++) -kfree ((*classes)[i]); -kfree (*classes); +/* +* The class symtab may be sparse, which policydb_class_isvalid() exists +* to absorb; the callback fills this array by value, so an unclaimed +* one leaves a NULL that sel_make_classes() hands to sel_make_dir(). +*/ +for (i =0 ; i < *nclasses; i++) { +if (!(*classes)[i]) { + rc = -EINVAL ; + goto err; + } } out:return rc; + +err: +for (i =0 ; i < *nclasses; i++) +kfree ((*classes)[i]); +kfree (*classes); +return rc; }static int get_permissions_callback (void *k,void *d,void *args)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 262/1191 ALSA: seq: Fix port lock leak in deliver_to_subscribers()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
Commit 46397622a3fa ("ALSA: seq: Add UMP support") mistakenly removed the snd_seq_port_unlock(src_port) call in deliver_to_subscribers(). As a result, every time an event is delivered to a subscriber, the source port's use_lock atomic counter is increased but never decreased.
The leak prevents ALSA sequencer ports from closing cleanly. When the client process exits or destroys the port, port_delete() hangs forever at snd_use_lock_sync(). The process becomes stuck in an unkillable D state, triggering the following warning:
ALSA: seq_lock: waiting [1 left] in sound/core/seq/seq_ports.c:250
Restore the missing snd_seq_port_unlock(src_port).
Note that commit 177ccf811df4 ("ALSA: seq: Support MIDI 2.0 UMP Endpoint port") incidentally resolved this issue upstream when it refactored the locking logic into a wrapper function. However, since the commit introduces a new feature and might not be suitable for stable release branches, this targeted fix is necessary.
--- sound/core/seq/seq_clientmgr.c | 1 + 1 file changed, 1 insertion(+)
sound/core/seq/seq_clientmgr.c +1 -0
@@ -733,6 +733,7 @@ static int deliver_to_subscribers(struct snd_seq_client *client,read_unlock (&grp->list_lock); else up_read(&grp->list_mutex); +snd_seq_port_unlock (src_port);memcpy (event, &event_saved, saved_size);return (result <0 ) ? result : num_ev; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 263/1191 net: ntb_netdev: Fix TX busy and drop handling
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
[ Upstream commit 8aaa47351db0f93a5c5297fbafdfa8bc75e8ae49 ]
Currently, ntb_netdev returns NETDEV_TX_BUSY for every enqueue error. It also increments the drop and error counters while leaving the skb owned by the qdisc, and may return BUSY with the subqueue still awake. Retrying a permanent error cannot succeed either.
The unconditional BUSY return and premature accounting date back to the initial driver. The error-path queue stop was later removed without changing that return value. The current flow-control code includes a resource check, but ntb_netdev does not honor its result before enqueue.
Honor the resource check before enqueue. For -EAGAIN and -EBUSY, stop the subqueue, arm the existing reaper timer, and return BUSY without touching the skb. For other errors, free the skb, increment tx_dropped, and return NETDEV_TX_OK.
[den: adapt to the single-queue implementation, as 6.1.y lacks commit:
ee970634c777 ("net: ntb_netdev: Introduce per-queue context")]
Stable-dep-of: 873ce713fef5 ("NTB: ntb_transport: Fail TX enqueue when the QP link is down")
Stable-dep-of: a4f2387db6f1 ("NTB: ntb_transport: Reject oversized TX buffers")
--- drivers/net/ntb_netdev.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/net/ntb_netdev.c +19 -8
@@ -164,8 +164,10 @@ static int __ntb_netdev_maybe_stop_tx(struct net_device *netdev,static int ntb_netdev_maybe_stop_tx (struct net_device *ndev,struct ntb_transport_qp *qp,int size) { -if (netif_queue_stopped (ndev) || - (ntb_transport_tx_free_entry (qp) >= size)) +if (netif_queue_stopped (ndev)) +return -EBUSY ; + +if (ntb_transport_tx_free_entry (qp) >= size)return 0 ;return __ntb_netdev_maybe_stop_tx (ndev, qp, size);
@@ -208,21 +210,30 @@ static netdev_tx_t ntb_netdev_start_xmit(struct sk_buff *skb,struct ntb_netdev *dev =netdev_priv (ndev);int rc; -ntb_netdev_maybe_stop_tx (ndev, dev->qp, tx_stop); +if (unlikely (ntb_netdev_maybe_stop_tx (ndev, dev->qp, tx_stop))) +return NETDEV_TX_BUSY ; rc =ntb_transport_tx_enqueue (dev->qp, skb, skb->data, skb->len); -if (rc) - goto err; +if (rc) { +if (rc == -EAGAIN || rc == -EBUSY ) { +netif_stop_queue (ndev); +mod_timer (&dev->tx_timer, + jiffies +usecs_to_jiffies (tx_time)); +return NETDEV_TX_BUSY ; + } + + goto drop; + }/* check for next submit */ ntb_netdev_maybe_stop_tx (ndev, dev->qp, tx_stop);return NETDEV_TX_OK ; -err: +drop: +dev_kfree_skb_any (skb); ndev->stats.tx_dropped++; - ndev->stats.tx_errors++; -return NETDEV_TX_BUSY ; +return NETDEV_TX_OK ; }static void ntb_netdev_tx_timer (struct timer_list *t)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 264/1191 vxlan: use pskb_network_may_pull() for transmit path header pulls
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit b9553558b48db54ac9273e6b98d7263ef5c1a329 ]
In vxlan_xmit(), arp_reduce(), and vxlan_mdb_entry_skb_get(), pskb_may_pull() was being called to verify the availability of network layer headers (ARP, IPv6/ND, IP/IPv6 MDB keys).
However, during transmit skb->data points to the MAC header, so skb_network_offset(skb) is ETH_HLEN (14 bytes). Using pskb_may_pull(skb, len) only checks len bytes from skb->data rather than skb_network_offset(skb) + len, which can leave part of the network header in non-linear frags.
Replace these remaining pskb_may_pull() calls with pskb_network_may_pull() to properly account for the MAC header offset.
--- drivers/net/vxlan/vxlan_core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_core.c +3 -3
@@ -1904,7 +1904,7 @@ static int arp_reduce(struct net_device *dev, struct sk_buff *skb, __be32 vni)if (dev->flags &IFF_NOARP ) goto out; -if (!pskb_may_pull (skb,arp_hdr_len (dev))) { +if (!pskb_network_may_pull (skb,arp_hdr_len (dev))) { dev->stats.tx_dropped++; goto out; }
@@ -2865,8 +2865,8 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)return arp_reduce (dev, skb, vni); #if IS_ENABLED(CONFIG_IPV6) else if (ntohs(eth->h_proto) == ETH_P_IPV6 && - pskb_may_pull(skb, sizeof(struct ipv6hdr) + - sizeof(struct nd_msg)) && + pskb_network_may_pull(skb, sizeof(struct ipv6hdr) + + sizeof(struct nd_msg)) && ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {struct nd_msg *m = (struct nd_msg *)(ipv6_hdr (skb) +1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 265/1191 tracing/mmiotrace: Remove reference to unused per CPU data pointer
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
commit 6936298393d8d8bc3cec6b704f6a774162cf9bd3 upstream.
The mmiotracer referenced the per CPU array_buffer->data descriptor but never actually used it. Remove the references to it.
--- kernel/trace/trace_mmiotrace.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
kernel/trace/trace_mmiotrace.c +2 -10
@@ -292,7 +292,6 @@ __init static int init_mmio_trace(void)device_initcall (init_mmio_trace);static void __trace_mmiotrace_rw (struct trace_array *tr, -struct trace_array_cpu *data,struct mmiotrace_rw *rw) {struct trace_event_call *call = &event_mmiotrace_rw;
@@ -318,12 +317,10 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,void mmio_trace_rw (struct mmiotrace_rw *rw) {struct trace_array *tr = mmio_trace_array; -struct trace_array_cpu *data =per_cpu_ptr (tr->array_buffer.data,smp_processor_id ()); -__trace_mmiotrace_rw (tr, data, rw); +__trace_mmiotrace_rw (tr, rw); }static void __trace_mmiotrace_map (struct trace_array *tr, -struct trace_array_cpu *data,struct mmiotrace_map *map) {struct trace_event_call *call = &event_mmiotrace_map;
@@ -349,12 +346,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,void mmio_trace_mapping (struct mmiotrace_map *map) {struct trace_array *tr = mmio_trace_array; -struct trace_array_cpu *data; - -preempt_disable (); - data =per_cpu_ptr (tr->array_buffer.data,smp_processor_id ()); -__trace_mmiotrace_map (tr, data, map); -preempt_enable (); +__trace_mmiotrace_map (tr, map); }int mmio_trace_printk (const char *fmt,va_list args)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 266/1191 tracing/mmiotrace: Add NULL check for mmio_trace_array in logging functions
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit 12b80cdbc54cf615b4717a4e8180063408091ea2 upstream.
mmio_trace_rw() and mmio_trace_mapping() retrieve mmio_trace_array into tr and pass it to __trace_mmiotrace_rw() and __trace_mmiotrace_map(). If these functions are invoked while mmio_trace_array is NULL (e.g. before initialization or after disabled), accessing tr->array_buffer.buffer will result in a NULL pointer dereference crash.
Fix this by adding an explicit NULL check for tr at the beginning of __trace_mmiotrace_rw() and __trace_mmiotrace_map().
--- kernel/trace/trace_mmiotrace.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/trace/trace_mmiotrace.c +10 -2
@@ -295,11 +295,15 @@ static void __trace_mmiotrace_rw(struct trace_array *tr, struct mmiotrace_rw *rw) {struct trace_event_call *call = &event_mmiotrace_rw; -struct trace_buffer *buffer = tr->array_buffer.buffer; +struct trace_buffer *buffer;struct ring_buffer_event *event;struct trace_mmiotrace_rw *entry;unsigned int trace_ctx; +if (!tr) +return ; + + buffer = tr->array_buffer.buffer; trace_ctx =tracing_gen_ctx_flags (0 ); event =trace_buffer_lock_reserve (buffer,TRACE_MMIO_RW ,sizeof (*entry), trace_ctx);
@@ -324,11 +328,15 @@ static void __trace_mmiotrace_map(struct trace_array *tr, struct mmiotrace_map *map) {struct trace_event_call *call = &event_mmiotrace_map; -struct trace_buffer *buffer = tr->array_buffer.buffer; +struct trace_buffer *buffer;struct ring_buffer_event *event;struct trace_mmiotrace_map *entry;unsigned int trace_ctx; +if (!tr) +return ; + + buffer = tr->array_buffer.buffer; trace_ctx =tracing_gen_ctx_flags (0 ); event =trace_buffer_lock_reserve (buffer,TRACE_MMIO_MAP ,sizeof (*entry), trace_ctx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 267/1191 mm/huge_memory: use folios memcg inside __folio_split()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zi Yan <[email protected]>
commit c299a2285d9d8bda4da024455de65e3d00de6f17 upstream.
Patch series "Honor XA_FLAGS_ACCOUNT in xas_split_alloc() and charge to folio's memcg", v3.
__GFP_ACCOUNT is needed for xarray node allocation accounting when XA_FLAGS_ACCOUNT is set. Commit 7b785645e8f13 ("mm: fix page cache convergence regression") fixed a workingset regression with it. xas_split_alloc() does not have it and needs to be fixed.
In addition, based on Sashiko's review[1] and Johannes' confirmation[2], to charge the right memcg, folio's memcg needs to be active during folio split. Add that before adding __GFP_ACCOUNT.
There is no workingset convergence regression related to missing __GFP_ACCOUNT in xas_split_alloc() and the impact to userspace should be minor.
This patch (of 2):
During a pagecache folio split, an xarray node allocation can happen and needs to charge at folio's memcg instead of folio split invoker's memcg, because for example folio split can happen during reclaim and reclaim's active memcg might not be folio's memcg. Switch to folio's memcg at the beginning and switch back afterwards.
--- mm/huge_memory.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
mm/huge_memory.c +10 -0
@@ -2676,6 +2676,7 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)struct folio *folio =page_folio (page);struct deferred_split *ds_queue =get_deferred_split_queue (&folio->page);XA_STATE (xas, &folio->mapping->i_pages, folio->index); +struct mem_cgroup *memcg, *old_memcg;struct anon_vma *anon_vma =NULL ;struct address_space *mapping =NULL ;int extra_pins, ret;
@@ -2694,6 +2695,13 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)if (folio_test_writeback (folio))return -EBUSY ; +/* +* switch to folio's memcg as xarray node allocation can happen and +* needs to charge to it. +*/ + memcg =folio_memcg (folio); + old_memcg =set_active_memcg (memcg); +if (folio_test_anon (folio)) {/* * The caller does not necessarily hold an mmap_lock that would
@@ -2821,6 +2829,8 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)if (mapping)i_mmap_unlock_read (mapping); out: +/* restore to caller's old_memcg */ +set_active_memcg (old_memcg);xas_destroy (&xas);count_vm_event (!ret ?THP_SPLIT_PAGE :THP_SPLIT_PAGE_FAILED );return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 268/1191 scsi: core: Fill in DMA padding bytes in scsi_alloc_sgtables()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Petr Vaganov <[email protected]>
commit 626147717bea776b61ed3631d2c26283760c4cc4 upstream.
During fuzz testing, the following issue was discovered:
BUG: KMSAN: uninit-value in __dma_map_sg_attrs+0x217/0x310 __dma_map_sg_attrs+0x217/0x310 dma_map_sg_attrs+0x4a/0x70 ata_qc_issue+0x9f8/0x1420 __ata_scsi_queuecmd+0x1657/0x1740 ata_scsi_queuecmd+0x79a/0x920 scsi_queue_rq+0x4472/0x4f40 blk_mq_dispatch_rq_list+0x1cca/0x3ee0 __blk_mq_sched_dispatch_requests+0x458/0x630 blk_mq_sched_dispatch_requests+0x15b/0x340 __blk_mq_run_hw_queue+0xe5/0x250 __blk_mq_delay_run_hw_queue+0x138/0x780 blk_mq_run_hw_queue+0x4bb/0x7e0 blk_mq_sched_insert_request+0x2a7/0x4c0 blk_execute_rq+0x497/0x8a0 sg_io+0xbe0/0xe20 scsi_ioctl+0x2b36/0x3c60 sr_block_ioctl+0x319/0x440 blkdev_ioctl+0x80f/0xd70 __se_sys_ioctl+0x219/0x420 __x64_sys_ioctl+0x93/0xe0 x64_sys_call+0x1d6c/0x3ad0 do_syscall_64+0x4c/0xa0 entry_SYSCALL_64_after_hwframe+0x6e/0xd8
Uninit was created at:
__alloc_pages+0x5c0/0xc80 alloc_pages+0xe0e/0x1050 blk_rq_map_user_iov+0x2b77/0x6100 blk_rq_map_user_io+0x2fa/0x4d0 sg_io+0xad6/0xe20 scsi_ioctl+0x2b36/0x3c60 sr_block_ioctl+0x319/0x440 blkdev_ioctl+0x80f/0xd70 __se_sys_ioctl+0x219/0x420 __x64_sys_ioctl+0x93/0xe0 x64_sys_call+0x1d6c/0x3ad0 do_syscall_64+0x4c/0xa0 entry_SYSCALL_64_after_hwframe+0x6e/0xd8
Bytes 14-15 of 16 are uninitialized
Memory access of size 16 starts at ffff88800cbdb000
When processing the last unaligned element of the scatterlist, it is supplemented with missing bytes in the amount of pad_len. These bytes remain uninitialized, which leads to a problem.
Extend last_sg->length by pad_len first, then use sg_zero_buffer() to zero those pad_len bytes. sg_zero_buffer() uses sg_miter internally, which correctly handles sg entries spanning multiple pages and padding that crosses a page boundary.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
--- drivers/scsi/scsi_lib.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/scsi_lib.c +2 -0
@@ -1070,8 +1070,10 @@ blk_status_t scsi_alloc_sgtables(struct scsi_cmnd *cmd)if (blk_rq_bytes (rq) & rq->q->dma_pad_mask) {unsigned int pad_len = (rq->q->dma_pad_mask & ~blk_rq_bytes (rq)) +1 ; +unsigned int data_len = last_sg->length; last_sg->length += pad_len; +sg_zero_buffer (last_sg,1 , pad_len, data_len); cmd->extra_len += pad_len; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 269/1191 usb: image: mdc800: change kmalloc() to kzalloc()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Griffin Kroah-Hartman <[email protected]>
commit 2430eb81e44111b30eeb5273bbcf8b24ca517ef9 upstream.
Change the kmalloc() calls in usb_mdc800_init() for irq_urb_buffer and download_urb_buffer to kzalloc(), avoiding potential stack leaks if a shorter message is received in mdc800_usb_irq() and mdc800_usb_download_notify()
--- drivers/usb/image/mdc800.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/image/mdc800.c +2 -2
@@ -1001,13 +1001,13 @@ static int __init usb_mdc800_init (void) mdc800->downloaded =0 ; mdc800->written =0 ; - mdc800->irq_urb_buffer=kmalloc (8 ,GFP_KERNEL ); + mdc800->irq_urb_buffer=kzalloc (8 ,GFP_KERNEL );if (!mdc800->irq_urb_buffer) goto cleanup_on_fail; mdc800->write_urb_buffer=kmalloc (8 ,GFP_KERNEL );if (!mdc800->write_urb_buffer) goto cleanup_on_fail; - mdc800->download_urb_buffer=kmalloc (64 ,GFP_KERNEL ); + mdc800->download_urb_buffer=kzalloc (64 ,GFP_KERNEL );if (!mdc800->download_urb_buffer) goto cleanup_on_fail;
Greg Kroah-Hartman
maintainerPATCH 270/1191 ALSA: usb-audio: fix OOB write in snd_usbmidi_us122l_output()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
commit e4637ce34607f1733a34a57294966d26b263e626 upstream.
The snd_usbmidi_us122l_output() picks a count of 2 on anything slower than high speed and never relates it to ep->max_transfer. The URB buffer holds exactly max_transfer bytes, so a device declaring a one byte bulk endpoint takes two bytes from snd_rawmidi_transmit(), and the memset that pads the rest computes 1 - 2 in int and wraps to SIZE_MAX.
Only 0x800e and 0x800f are pinned to nine bytes. The US-122MKII at 0x0644:0x8021 falls to the default and takes usb_maxpacket(), which the USB core only clamps downward.
The akai and novation output ops in this file were given the same guard recently. Do the same here.
--- sound/usb/midi.c | 2 ++ 1 file changed, 2 insertions(+)
sound/usb/midi.c +2 -0
@@ -974,6 +974,8 @@ static void snd_usbmidi_us122l_output(stdefault : count =2 ; } +if (ep->max_transfer < count) +return ; count =snd_rawmidi_transmit (ep->ports[0 ].substream, urb->transfer_buffer, count);
Greg Kroah-Hartman
maintainerPATCH 271/1191 clk: qcom: gcc-mdm9607: Increase delay for USB PHY reset
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit c99bc8e83848358bd4a0436e4bdae5b7919babb2 upstream.
To conform to the specifications of the USB PHY, the reset signal should be asserted for at least 10us. Guarantee that by increasing the delay for the USB2_HS_PHY_ONLY_BCR reset control similar to commit dcc6c9fb7128 ("clk:
qcom: gcc-msm8909: Increase delay for USB PHY reset").
--- drivers/clk/qcom/gcc-mdm9607.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/gcc-mdm9607.c +1 -1
@@ -1568,7 +1568,7 @@ static const struct qcom_reset_map gcc_m [USB_HS_HSIC_BCR] = { 0x3d05c }, [GCC_MSS_RESTART] = { 0x3e000 }, [USB_HS_BCR] = { 0x41000 }, - [USB2_HS_PHY_ONLY_BCR] = { 0x41034 }, + [USB2_HS_PHY_ONLY_BCR] = { .reg = 0x41034, .udelay = 15 }, [QUSB2_PHY_BCR] = { 0x4103c }, };
Greg Kroah-Hartman
maintainerPATCH 272/1191 media: usbtv: keep device alive while ALSA card exists
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
commit fc530fe168bb2b745a93f553ad21fc25fd9cba3d upstream.
The ALSA PCM callbacks store the driver state in pcm->private_data. An open PCM file can outlive USB disconnect because usbtv_audio_free() uses snd_card_free_when_closed(). The disconnect path can then drop the V4L2 device reference and free struct usbtv before ALSA releases the substream, so a later close dereferences freed memory in snd_usbtv_pcm_close().
Take a V4L2 device reference for the ALSA card and drop it from the card private_free callback. This keeps struct usbtv valid until ALSA has closed the remaining files and freed the card.
--- drivers/media/usb/usbtv/usbtv-audio.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/media/usb/usbtv/usbtv-audio.c +11 -0
@@ -317,6 +317,13 @@ static const struct snd_pcm_ops snd_usbt .pointer = snd_usbtv_pointer, }; +static void usbtv_audio_card_free (struct snd_card *card) +{ +struct usbtv *usbtv = card->private_data; + +v4l2_device_put (&usbtv->v4l2_dev); +} +int usbtv_audio_init (struct usbtv *usbtv) {int rv;
@@ -331,6 +338,10 @@ int usbtv_audio_init(struct usbtv *usbtvif (rv <0 )return rv; +v4l2_device_get (&usbtv->v4l2_dev); + card->private_data = usbtv; + card->private_free = usbtv_audio_card_free; +strscpy (card->driver, usbtv->dev->driver->name,sizeof (card->driver));strscpy (card->shortname,"usbtv" ,sizeof (card->shortname)); snprintf(card->longname, sizeof(card->longname),
Greg Kroah-Hartman
maintainerPATCH 273/1191 usb-storage: ene_ub6250: fix race between scan work and probe
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liu Qi <[email protected]>
commit 445fc368c6bc73eff0aeb3818cf5f355facfbb16 upstream.
ene_ub6250_probe() calls usb_stor_probe2(), which starts the usb-storage infrastructure and schedules the delayed scan work. The driver then calls ene_get_card_type(), which sends an ENE command through ene_send_scsi_cmd() and the usb-storage bulk transfer helpers.
Both the delayed scan work, through usb_stor_Bulk_max_lun(), and ene_get_card_type() use us->current_urb. The scan work serializes this access with us->dev_mutex, but the ENE card-type probe does not. If the scan work runs while ene_get_card_type() is still using us->current_urb, usb_submit_urb() warns that the URB is already active.
Serialize ene_get_card_type() with us->dev_mutex, matching the locking used by the scan path.
--- drivers/usb/storage/ene_ub6250.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/storage/ene_ub6250.c +2 -0
@@ -2358,7 +2358,9 @@ static int ene_ub6250_probe(struct usb_ireturn result;/* probe card type */ +mutex_lock (&us->dev_mutex); result =ene_get_card_type (us,REG_CARD_STATUS , info->bbuf); +mutex_unlock (&us->dev_mutex);if (result !=USB_STOR_XFER_GOOD ) {usb_stor_disconnect (intf);return USB_STOR_TRANSPORT_ERROR ;
Greg Kroah-Hartman
maintainerPATCH 274/1191 usb: f_mass_storage: Bump local buffer size in fsg_common_create_luns()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
commit 9f6f095beec82a80daa666a3b2186a5b95841e9a upstream.
GCC (Debian 14.2.0-19) is not happy about the buffer size:
drivers/usb/gadget/function/f_mass_storage.c:2970:48: error: ‘%d’ directive output may be truncated writing between 1 and 9 bytes into a region of size 5 [-Werror=format-truncation=]
Bump the size to get it enough for all possible values.
Note, although cfg->nluns is limited to FSG_MAX_LUNS (16), the compiler doesn't realize this and complains about the buffer size.
Also note, the existing comment is wrong as size 8 for the whole buffer doesn't cover 100 mil numbers, hence drop it altogether.
--- drivers/usb/gadget/function/f_mass_storage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/function/f_mass_storage.c +1 -1
@@ -2964,7 +2964,7 @@ EXPORT_SYMBOL_GPL(fsg_common_create_lun)int fsg_common_create_luns (struct fsg_common *common,struct fsg_config *cfg) { -char buf[8 ];/* enough for 100000000 different numbers, decimal */ +char buf[14 ];int i, rc;fsg_common_remove_luns (common);
Greg Kroah-Hartman
maintainerPATCH 275/1191 usb: typec: ucsi: displayport: Fix OOB altmode array index
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jameson Thies <[email protected]>
commit 04cec690b1fd9d1c4c314b91a10d8c68a3acfe18 upstream.
The UCSI displayport driver indexes the connector's port altmode array with the GET_CURRENT_CAM response after checking it is not 0xff. The port altmode array is UCSI_MAX_ALTMODES elements long. If the PPM returns an invalid GET_CURRENT_CAM response above UCSI_MAX_ALTMODES and not equal to 0xff, the kernel may crash with an array index OOB error.
Update the UCSI displayport driver to verify the current cam is less than UCSI_MAX_ALTMODES before accessing the port altmode array.
--- drivers/usb/typec/ucsi/displayport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/typec/ucsi/displayport.c +1 -1
@@ -74,7 +74,7 @@ static int ucsi_displayport_enter(struct cur =0xff ; } -if (cur !=0xff ) { +if (cur <UCSI_MAX_ALTMODES ) { ret = dp->con->port_altmode[cur] == alt ?0 : -EBUSY ; goto err_unlock; }
Greg Kroah-Hartman
maintainerPATCH 276/1191 USB: gadget: fix NULL pointer dereference in gadget_dev_ioctl()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lovekesh Solanki <[email protected]>
commit dd0eed9e165b1a6292f49e622e3dd0b7d99b106d upstream.
gadget_dev_ioctl() reads dev->gadget before acquiring dev->lock, but dev->state is checked after acquiring the lock. Therefore a concurrent bind can change the device state between these operations, which can leave ioctl with a stale NULL gadget pointer and causing a NULL pointer dereference at gadget->ops->ioctl.
Read dev->gadget while holding dev->lock so that the gadget pointer and device state are sampled consistently.
--- drivers/usb/gadget/legacy/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/gadget/legacy/inode.c +2 -1
@@ -1247,10 +1247,11 @@ out:static long gadget_dev_ioctl (struct file *fd,unsigned code,unsigned long value) {struct dev_data *dev = fd->private_data; -struct usb_gadget *gadget = dev->gadget; +struct usb_gadget *gadget;long ret = -ENOTTY ;spin_lock_irq (&dev->lock); + gadget = dev->gadget;if (dev->state ==STATE_DEV_OPENED || dev->state ==STATE_DEV_UNBOUND ) {/* Not bound to a UDC */
Greg Kroah-Hartman
maintainerPATCH 277/1191 usb: gadget: fix null pointer dereference in usb_put_function_instance()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeffin Philip <[email protected]>
commit 6e74ac5c596fd246e37eadfc354567179ccbe9aa upstream.
usb_put_function_instance() attempts to dereference fd inside fi struct to get mod in uvc_alloc_inst() error path. However, fd is not allocated until later in try_get_usb_function_instance() after allocating fi in uvc_alloc_inst() and thus guranteed to be null in error path. Fix this by adding a null check for fi->fd that returns if fd is null.
--- drivers/usb/gadget/functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/functions.c +1 -1
@@ -70,7 +70,7 @@ void usb_put_function_instance(struct us {struct module *mod; -if (!fi) +if (!fi || !fi->fd)return ; mod = fi->fd->mod;
Greg Kroah-Hartman
maintainerPATCH 278/1191 staging: rtl8723bs: fix OOB read / stack overflow in rtw_get_wps_attr()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit 99aa998dec83ba180822f70e6d48a514fc81c20d upstream.
rtw_get_wps_attr() walks WPS attributes inside a WPS IE taken from a wireless management frame. For each candidate attribute it only checks that the fixed 4-byte attribute header (2-byte ID + 2-byte length) fits inside the IE:
if (attr_ptr + 4 > wps_ie + wps_ielen) break; u16 attr_id = get_unaligned_be16(attr_ptr); u16 attr_data_len = get_unaligned_be16(attr_ptr + 2); u16 attr_len = attr_data_len + 4;
attr_data_len (and therefore attr_len) is read directly from the wire and is never checked against the remaining bytes in the IE before being used as the size of:
memcpy(buf_attr, attr_ptr, attr_len);
Since attr_len is fully attacker controlled (0 to 65535+4), this is both a heap OOB read of wps_ie, and, more seriously, a stack buffer overflow at several call sites where buf_attr is a single-byte stack variable, e.g. rtw_get_wps_attr_content()'s callers passing WPS_ATTR_SELECTED_REGISTRAR into a stack "u8 sr"/"u8 selected_registrar" (drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c, drivers/staging/rtl8723bs/core/rtw_mlme_ext.c). A crafted WPS IE in a beacon or probe response processed during scanning can therefore smash the stack of the parsing thread.
rtw_get_wps_attr_content() itself has no independent length check and simply trusts the attr_len it gets back from rtw_get_wps_attr(), so fixing the bound here also fixes that caller.
The "attr_ptr + 4 > wps_ie + wps_ielen" header check above was added by commit 1463ca3ec6601 ("staging: rtl8723bs: fix OOB reads in rtw_get_sec_ie(), rtw_get_wapi_ie(), and rtw_get_wps_attr()"), which bounded the fixed header but never extended the check to cover the variable-length attribute data that follows it. Add that missing check before attr_len is used as a memcpy() length or accepted as a match.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +4 -0
@@ -745,6 +745,10 @@ u8 *rtw_get_wps_attr(u8 *wps_ie, uint wpu16 attr_data_len =get_unaligned_be16 (attr_ptr +2 );u16 attr_len = attr_data_len +4 ; +/* Reject attributes whose claimed length runs past the IE */ +if (attr_ptr + attr_len > wps_ie + wps_ielen) +break ; +if (attr_id == target_attr_id) { target_attr_ptr = attr_ptr;
Greg Kroah-Hartman
maintainerPATCH 279/1191 staging: rtl8723bs: fix OOB read in rtw_action_frame_parse()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muhammad Bilal <[email protected]>
commit ff917923f4fb9c83717ba135ee47d7e4c1567bb7 upstream.
rtw_action_frame_parse() takes a frame_len parameter but never actually checks it before indexing into the frame body:
const u8 *frame_body = frame + sizeof(struct ieee80211_hdr_3addr); ... c = frame_body[0]; ... a = frame_body[1];
frame_body already points 24 bytes (sizeof(struct ieee80211_hdr_3addr)) into frame, so reading frame_body[0] and frame_body[1] requires frame_len >= 26. A management action frame shorter than that (e.g. exactly 24 bytes, the minimum a malicious peer can send) causes a 1-2 byte out-of-bounds read.
This is reachable from rtw_cfg80211_monitor_if_xmit_entry() and cfg80211_rtw_mgmt_tx() in ioctl_cfg80211.c, both of which pass attacker/user-influenced frame buffers and lengths straight through.
Add the missing length check before frame_body is dereferenced.
--- drivers/staging/rtl8723bs/core/rtw_ieee80211.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/rtl8723bs/core/rtw_ieee80211.c +3 -0
@@ -1152,6 +1152,9 @@ int rtw_action_frame_parse(const u8 *frau8 c;u8 a =ACT_PUBLIC_MAX ; +if (frame_len <sizeof (struct ieee80211_hdr_3addr ) +2 ) +return false; + fc =le16_to_cpu (((struct ieee80211_hdr_3addr *)frame)->frame_control); if ((fc & (IEEE80211_FCTL_FTYPE|IEEE80211_FCTL_STYPE))
Greg Kroah-Hartman
maintainerPATCH 280/1191 thermal/drivers/imx: Disable clock on runtime resume failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit bcc6d886e5006a4656901d2d7fb6a215c96068a0 upstream.
imx_thermal_runtime_resume() enables the thermal clock before powering up the sensor and enabling measurements.
If either regmap_write() fails, the function returns with the clock still enabled. This leaves the clock enable count unbalanced after a failed runtime resume.
Disable the clock on those failure paths before returning the error.
--- drivers/thermal/imx_thermal.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/thermal/imx_thermal.c +7 -2
@@ -897,12 +897,12 @@ static int __maybe_unused imx_thermal_ru ret =regmap_write (map, socdata->sensor_ctrl +REG_CLR , socdata->power_down_mask);if (ret) -return ret; + goto disable_clk; ret =regmap_write (map, socdata->sensor_ctrl +REG_SET , socdata->measure_temp_mask);if (ret) -return ret; + goto disable_clk;/* * According to the temp sensor designers, it may require up to ~17us
@@ -911,6 +911,11 @@ static int __maybe_unused imx_thermal_ruusleep_range (20 ,50 );return 0 ; + +disable_clk: +clk_disable_unprepare (data->thermal_clk); + +return ret; }static const struct dev_pm_ops imx_thermal_pm_ops = {
Greg Kroah-Hartman
maintainerPATCH 281/1191 thermal/drivers/qoriq: Disable clock on resume failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Can Peng <[email protected]>
commit fcbf9964b67a6d6704c50ed28daa24c3b164f01c upstream.
qoriq_tmu_resume() enables the TMU clock before clearing the power-down bit and enabling monitoring.
If either register update fails, the function returns with the clock still enabled. This leaves the clock enable count unbalanced after a failed resume.
Disable the clock on those failure paths before returning the error.
--- drivers/thermal/qoriq_thermal.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/thermal/qoriq_thermal.c +11 -2
@@ -369,11 +369,20 @@ static int __maybe_unused qoriq_tmu_resuif (data->ver >TMU_VER1 ) { ret =regmap_clear_bits (data->regmap,REGS_TMR ,TMR_CMD );if (ret) -return ret; + goto disable_clk; }/* Enable monitoring */ -return regmap_update_bits (data->regmap,REGS_TMR ,TMR_ME ,TMR_ME ); + ret =regmap_update_bits (data->regmap,REGS_TMR ,TMR_ME ,TMR_ME ); +if (ret) + goto disable_clk; + +return 0 ; + +disable_clk: +clk_disable_unprepare (data->clk); + +return ret; } static SIMPLE_DEV_PM_OPS(qoriq_tmu_pm_ops,
Greg Kroah-Hartman
maintainerPATCH 282/1191 scsi: target: iscsi: Reserve a terminator byte for the login payload
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sujal Tuladhar <[email protected]>
commit f4825922d2fb371e2b969697d792077f1b62b62c upstream.
iscsi_target_check_login_request() rejects a login PDU whose DataSegmentLength exceeds MAX_KEY_VALUE_PAIRS, but the test is '>' and login->req_buf is allocated with exactly MAX_KEY_VALUE_PAIRS bytes. Since iscsit_get_login_rx() receives payload_length + padding bytes, where
padding = ((-payload_length) & 3);
any payload_length from 8189 to 8192 fills the whole 8192 byte buffer. The write stays in bounds, but no byte is left for a NUL terminator.
The buffer is subsequently consumed as a C string. In the CHAP path chap_check_algorithm() calls kstrdup(a_str), and extract_param() calls strstr(in_buf, pattern) followed by strlen_semi(), none of which take a length. convert_null_to_semi() additionally rewrites every embedded NUL to ';', so even a payload made of well formed NUL separated key=value records is left without a terminator. These walk past the end of the object into adjacent slab memory. It is reachable by an unauthenticated initiator against a portal configured for CHAP; when authentication is not required iscsi_login_zero_tsih_s2() rewrites AuthMethod to None and the CHAP path is never entered.
Allocate one extra byte. kzalloc() zeroes it and nothing ever writes to it, as every writer copies to offset 0 for at most MAX_KEY_VALUE_PAIRS bytes, so the buffer is always terminated.
--- drivers/target/iscsi/iscsi_target_login.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/target/iscsi/iscsi_target_login.c +1 -1
@@ -48,7 +48,7 @@ static struct iscsi_login *iscsi_login_i login->conn = conn; login->first_request =1 ; - login->req_buf =kzalloc (MAX_KEY_VALUE_PAIRS ,GFP_KERNEL ); + login->req_buf =kzalloc (MAX_KEY_VALUE_PAIRS +1 ,GFP_KERNEL );if (!login->req_buf) {pr_err ("Unable to allocate memory for response buffer.\n" ); goto out_login;
Greg Kroah-Hartman
maintainerPATCH 283/1191 scsi: pm8001: Use rollback index when freeing MSI-X vectors
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 3f92a64545165bdbb36dee8fa35626b295463313 upstream.
pm8001_request_msix() unwinds previously registered handlers with free_irq() when request_irq() fails. The rollback loop uses the failing index i for every iteration instead of the already registered vector index j.
That passes the wrong IRQ/dev_id pair to free_irq() and leaves the earlier handlers installed. Use j for both pci_irq_vector() and the matching irq_vector entry in the rollback loop.
--- drivers/scsi/pm8001/pm8001_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/pm8001/pm8001_init.c +2 -2
@@ -1004,8 +1004,8 @@ static u32 pm8001_request_msix(struct pm &(pm8001_ha->irq_vector[i]));if (rc) {for (j =0 ; j < i; j++) { -free_irq (pci_irq_vector (pm8001_ha->pdev, i), - &(pm8001_ha->irq_vector[i])); +free_irq (pci_irq_vector (pm8001_ha->pdev, j), + &pm8001_ha->irq_vector[j]); }pci_free_irq_vectors (pm8001_ha->pdev);break ;
Greg Kroah-Hartman
maintainerPATCH 284/1191 mm/damon/sysfs: kobject_del() region and target (error) dirs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 2603ef6f6ec3d3f7de2d6a07e7c9a683cebac419 upstream.
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for the normal creation path of region directories and the error path of target directories, by adding kobject_del() calls.
--- mm/damon/sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +6 -2
@@ -1162,8 +1162,10 @@ static void damon_sysfs_regions_rm_dirs(struct damon_sysfs_region **regions_arr = regions->regions_arr;int i; -for (i =0 ; i < regions->nr; i++) +for (i =0 ; i < regions->nr; i++) { +kobject_del (®ions_arr[i]->kobj);kobject_put (®ions_arr[i]->kobj); + } regions->nr =0 ;kfree (regions_arr); regions->regions_arr =NULL ;
@@ -1398,13 +1400,15 @@ static int damon_sysfs_targets_add_dirs( err =damon_sysfs_target_add_dirs (target);if (err) - goto out; + goto del_out; targets_arr[i] = target; targets->nr++; }return 0 ; +del_out: +kobject_del (&target->kobj); out:damon_sysfs_targets_rm_dirs (targets);kobject_put (&target->kobj);
Greg Kroah-Hartman
maintainerPATCH 285/1191 mm/damon/sysfs: kobject_del() target (normal), context and kdamond dirs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: SJ Park <[email protected]>
commit 263af33a72d1995ae6cdc22b08d527e2bda17259 upstream.
Patch series "mm/damon/sysfs: kobject_del() directories that users can create/remove".
DAMON sysfs interface allows users to create and remove arbitrary number of directories on sysfs, using a few files having 'nr_' prefix. For example, 'nr_kdamonds'. When the user writes a number 'N' to the files, directories having name starting from '0' to 'N - 1' are created in the same directory. The pre-existing number-named directories are removed before creating the new directories.
For the removal of the existing directories, DAMON sysfs interface use only kobject_put(). Because DAMON sysfs interface is the only kernel component that manages the directories, there is no problem in normal situations. However, if CONFIG_DEBUG_KOBJECT_RELEASE is enabled, the removal of dirs are delayed. Let's suppose a user writes a non-zero number to the 'nr_*' files while there are pre-existing number-named directories, on the config enabled kernel. DAMON sysfs interface decreases the reference counts of the existing directories and immediately creates new directories. Because the removal of the sysfs directories is delayed, it shows some pre-existing directories of the same names when it tries to create the new directories, and fails.
For example, the issue can be triggered like below:
# grep DEBUG_KOBJECT_RELEASE /boot/config-$(uname -r)
CONFIG_DEBUG_KOBJECT_RELEASE=y
# ls
nr_kdamonds
# echo 1 > nr_kdamonds
# echo 1 > nr_kdamonds
bash: echo: write error: File exists
# dmesg
[...]
[ 300.880458] kobject: kobject_add_internal failed for 0 with -EEXIST, don't try to register things with the same name in the same directory.
[...]Some of the error handling paths of the directories also lack the kobject_del() call. If the user uses nr_* file right after the errors, similar issues can happen.
This doesn't cause catastrophic issues like kernel panics or memory corruptions. Users can work around by removing all directories first (write 0 to the nr_* files) and then create new directories after confirming the old directories are gone. But, this is definitely a bug that causes a bad user experience.
Fix the issues by calling kobject_del() before creating new directories.
This patch (of 11)
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for normal creation paths of target, context and kdamond directories, and error paths of context and kdamond directories by adding kobject_del() calls.
Note that this fix for target directories is not complete since it has a similar issue in the damon_sysfs_targets_add_dirs() error path. Because the normal path issue and the error path issue are introduced by different commits, this commit is fixing only the normal path issue. A commit for the error path will be added next.
--- mm/damon/sysfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +9 -2
@@ -1362,6 +1362,7 @@ static void damon_sysfs_targets_rm_dirs(for (i =0 ; i < targets->nr; i++) {damon_sysfs_target_rm_dirs (targets_arr[i]); +kobject_del (&targets_arr[i]->kobj);kobject_put (&targets_arr[i]->kobj); } targets->nr =0 ;
@@ -1888,6 +1889,7 @@ static void damon_sysfs_contexts_rm_dirsfor (i =0 ; i < contexts->nr; i++) {damon_sysfs_context_rm_dirs (contexts_arr[i]); +kobject_del (&contexts_arr[i]->kobj);kobject_put (&contexts_arr[i]->kobj); } contexts->nr =0 ;
@@ -1926,13 +1928,15 @@ static int damon_sysfs_contexts_add_dirs err =damon_sysfs_context_add_dirs (context);if (err) - goto out; + goto del_out; contexts_arr[i] = context; contexts->nr++; }return 0 ; +del_out: +kobject_del (&context->kobj); out:damon_sysfs_contexts_rm_dirs (contexts);kobject_put (&context->kobj);
@@ -2717,6 +2721,7 @@ static void damon_sysfs_kdamonds_rm_dirsfor (i =0 ; i < kdamonds->nr; i++) {damon_sysfs_kdamond_rm_dirs (kdamonds_arr[i]); +kobject_del (&kdamonds_arr[i]->kobj);kobject_put (&kdamonds_arr[i]->kobj); } kdamonds->nr =0 ;
@@ -2772,13 +2777,15 @@ static int damon_sysfs_kdamonds_add_dirs err =damon_sysfs_kdamond_add_dirs (kdamond);if (err) - goto out; + goto del_out; kdamonds_arr[i] = kdamond; kdamonds->nr++; }return 0 ; +del_out: +kobject_del (&kdamond->kobj); out:damon_sysfs_kdamonds_rm_dirs (kdamonds);kobject_put (&kdamond->kobj);
Greg Kroah-Hartman
maintainerPATCH 286/1191 futex: Prevent rcuwait use-after-free during requeue PI
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yao Kai <[email protected]>
commit a3b8d46fe401cba3a5c46dea610e6eb3dc15370e upstream.
On PREEMPT_RT, FUTEX_CMP_REQUEUE_PI can trigger a KASAN report (slab-out-of-bounds) in futex_requeue_pi_complete() invocation of rcuwait_wake_up().
The futex_q used by futex_wait_requeue_pi() is allocated on the waiter's stack. An early wakeup can race with a PI requeue as follows:
waiter requeue task
------ ------------futex_wait_requeue_pi()
futex_do_wait()
schedule()
futex_requeue
futex_proxy_trylock_atomic()
futex_requeue_pi_prepare()
Q_REQUEUE_PI_NONE -> Q_REQUEUE_PI_IN_PROGRESS
* timeout/ signal wakes waiter *
futex_requeue_pi_wakeup_sync()
Q_REQUEUE_PI_IN_PROGRESS -> Q_REQUEUE_PI_WAIT
requeue_pi_wake_futex
futex_requeue_pi_complete()
cmpxchg Q_REQUEUE_PI_WAIT -> Q_REQUEUE_PI_LOCKED
rcuwait_wait_event()
if (atomic_read(&q->requeue_state) != Q_REQUEUE_PI_WAIT)
break /* no schedule() */ /* q.pi_state->owner == current */
futex_private_hash_put()
/* return from syscall */
rcuwait_wake_up(&q->requeue_wait)
/* q is gone */futex_requeue_pi_complete() publishes Q_REQUEUE_PI_LOCKED before calling rcuwait_wake_up(). The waiter observes this state in rcuwait_wait_event() before invoking schedule() in rcuwait_wait_event(). Here, the waiter is free leave the syscall before requeue task can complete the wake.
To address this race skip rcuwait_wake_up() in the Q_REQUEUE_PI_LOCKED case.
This state is only published by requeue_pi_wake_futex(), which saves q->task before futex_requeue_pi_complete() and wakes the waiter via wake_up_state().
This wake is intended to wake the waiter from its futex_do_wait() sleep. If the waiter is still sleeping there, it can not get into the Q_REQUEUE_PI_WAIT state (and require this removed wake). Should the waiter be woken up from futex_do_wait() by other means (as in this example) and sleep in futex_requeue_pi_wakeup_sync() then the wake_up_state() from requeue_pi_wake_futex() will wake it, too. Should the waiter task terminate before wake_up_state() had a chance to wake the task then the task pointer does not become invalid because the futex_hash_bucket::lock is held and the task pointer is RCU protected.
[bigeasy: Updated comment and commit message]
--- kernel/futex/requeue.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
kernel/futex/requeue.c +10 -2
@@ -147,8 +147,16 @@ static inline void futex_requeue_pi_comp }while (!atomic_try_cmpxchg (&q->requeue_state, &old, new));#ifdef CONFIG_PREEMPT_RT -/* If the waiter interleaved with the requeue let it know */ -if (unlikely (old ==Q_REQUEUE_PI_WAIT )) +/* +* The waiter in futex_requeue_pi_wakeup_sync() can interleave with the +* wake below: It will assign Q_REQUEUE_PI_IN_PROGRESS and here it will +* be updated to Q_REQUEUE_PI_LOCKED (locked = 1). The rcuwait_wait_event() +* will already read Q_REQUEUE_PI_LOCKED and skip the schedule() invocation, +* leading to an access of futex_q::requeue_wait after the waiter returned. +* In this case only we skip the wake here and rely on following wake in +* requeue_pi_wake_futex() to perform the wake if needed. +*/ +if (unlikely (old ==Q_REQUEUE_PI_WAIT ) && new !=Q_REQUEUE_PI_LOCKED )rcuwait_wake_up (&q->requeue_wait);#endif }
Greg Kroah-Hartman
maintainerPATCH 287/1191 HID: rmi: fix OOB access with undersized RMI reports
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Jie Law <[email protected]>
commit 4956993bb3befdf791d71a4952d8d13bcfd44c7b upstream.
The hid-rmi driver sizes its writeReport/readReport buffer purely from the report descriptor supplied by the device, with no minimum bound:
data->input_report_size = hid_report_len(input_report); data->output_report_size = hid_report_len(output_report); alloc_size = data->output_report_size + data->input_report_size; data->writeReport = devm_kzalloc(&hdev->dev, alloc_size, GFP_KERNEL); data->readReport = data->writeReport + data->output_report_size;
but then reads and writes fixed offsets into it. A device declaring a 1-byte output and a 1-byte input report makes hid_report_len() return 2 for each, so alloc_size is 4, while rmi_set_page() -- reached unconditionally at probe time through rmi_input_configured() -- stores writeReport[4] and rmi_hid_read_block() stores writeReport[0..5]. Since readReport lives at writeReport + output_report_size, those stores also corrupt the window the next reply is parsed out of.
The read path is worse: the copy length comes from readReport[1], which the device fills in and can be up to 255, and the copy starts at &readReport[2] with no regard for input_report_size, so it runs past the end of the allocation into adjacent slab objects. This does not even need a lying device -- rmi_f01_probe() issues a fixed 21-byte register read, so any device declaring an input report smaller than 23 bytes reads out of bounds even when it answers truthfully. Those bytes become the register values the RMI core acts on: rmi_f01_probe() prints them to the kernel log as the product id and exports them through the mode 0444 sysfs attribute of the same name, and rmi_driver_set_irq_bits() sends them back to the device as the interrupt mask, so an undersized report descriptor leaks heap contents both to unprivileged userspace and to the device itself.
The write path has no bound either: rmi_hid_write_block() copies an unbounded len to &writeReport[4], and the largest caller a device can drive at probe time is rmi_driver_set_irq_bits(), whose length is derived from the interrupt source counts the device declares in its Page Description Table.
Finally, the read loop cannot terminate on a zero-length reply: such a reply copies nothing and advances neither bytes_read nor bytes_needed, and because a reply did arrive the one second wait_event_timeout() does not fire either, so a device answering 0 forever keeps the loop running inside the probe worker with page_mutex held. khungtaskd does not notice, because every reply wakes the task.
Reject reports too small for what the driver builds -- 6 output bytes for the write reports and 3 input bytes for the read handshake -- at probe time, clamp the write and the read copy to the report sizes the device declared, and treat a zero-length reply as an error. A device refused this way is started as an ordinary HID device, like one that does not carry the RMI report ids at all.
RMI_DEVICE must not be left set in device_flags on that path, because rmi_input_configured() would then run the RMI setup and reach rmi_set_page(), which writes the writeReport buffer the refusal just skipped allocating. The bit can arrive set: rmi_probe() copies id->driver_data into device_flags before the report checks, and a bind through the new_id sysfs attribute can supply driver_data with RMI_DEVICE (BIT(0)) set. Strip the bit where driver_data is copied, so RMI_DEVICE keeps meaning exactly "this probe validated the reports"; the three jumps to start that predate this patch are covered as well.
The error path also clears RMI_READ_DATA_PENDING on its way out, because that flag is what the wait at the top of the loop tests: leaving it set would make every later wait_event_timeout() return immediately on the stale reply and kill the read path for the rest of the device's life.
Clamping does not regress working hardware: the read loop already handles a reply carrying fewer bytes than requested, and a write longer than the output report was overrunning the buffer already.
Verified on v6.12.69 and on v6.12.105 built with CONFIG_KASAN=y and booted kasan_multi_shot, whose hid-rmi.c is identical to mainline here. An emulated RMI4 device driven over /dev/uhid, and the same device again over dummy_hcd plus raw-gadget, give identical results:
BUG: KASAN: slab-out-of-bounds in rmi_hid_read_block+0x409/0x750 [hid_rmi] Read of size 21 at addr ffff88800bf33bba by task kworker/0:3/285 __asan_memcpy+0x23/0x60 rmi_hid_read_block+0x409/0x750 [hid_rmi] rmi_f01_probe+0x5dd/0x1dc0 [rmi_core] BUG: KASAN: slab-out-of-bounds in rmi_hid_write_block+0x1a9/0x350 [hid_rmi] Write of size 35 at addr ffff88810a2b24ac by task kworker/1:10/666 __asan_memcpy+0x3c/0x60 rmi_hid_write_block+0x1a9/0x350 [hid_rmi] rmi_driver_set_irq_bits+0x1f6/0x4d0 [rmi_core] rmi_driver_probe+0x636/0xbf0 [rmi_core] rmi_input_configured+0x184/0x2e0 [hid_rmi] rmi_probe+0x952/0xcf0 [hid_rmi]
and, for the zero-length reply, a probe worker left in D state in rmi_hid_read_block() after 225 replies at 200 ms intervals.
After this change the undersized descriptor is refused at probe with "rmi reports too small (out=2 in=2)", the oversized read and write are both rejected, the zero-length reply fails the read with -EIO while later reads on the same device keep working, and a device declaring reports large enough for a 21-byte register read still probes normally and reports its real product id. A device bound through new_id with RMI_DEVICE in its driver_data no longer reaches rmi_set_page() with an unallocated writeReport either.
--- drivers/hid/hid-rmi.c | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-)
drivers/hid/hid-rmi.c +43 -3
@@ -235,7 +235,23 @@ static int rmi_hid_read_block(struct rmibreak ; } - read_input_count = data->readReport[1 ]; + read_input_count =min_t (int, data->readReport[1 ], + data->input_report_size -2 ); +if (!read_input_count) { +/* +* A zero length reply advances neither +* bytes_read nor bytes_needed, and because a +* reply did arrive the wait above does not +* time out either, so a device answering 0 +* forever would spin here indefinitely with +* page_mutex held. +*/ +hid_warn (hdev,"%s: zero-length read reply\n" , + __func__); +clear_bit (RMI_READ_DATA_PENDING , &data->flags); + ret = -EIO ; +break ; + }memcpy (buf + bytes_read, &data->readReport[2 ],min (read_input_count, bytes_needed));
@@ -271,6 +287,11 @@ static int rmi_hid_write_block(struct rm goto exit; } +if (len +4 > data->output_report_size) { + ret = -EINVAL ; + goto exit; + } + data->writeReport[0 ] =RMI_WRITE_REPORT_ID ; data->writeReport[1 ] = len; data->writeReport[2 ] = addr &0xFF ;
@@ -668,8 +689,16 @@ static int rmi_probe(struct hid_device *return ret; } -if (id->driver_data) - data->device_flags = id->driver_data; +/* +* RMI_DEVICE can only mean "this probe validated the RMI reports and +* allocated writeReport": every bail-out to start below skips that +* allocation, and device_flags left carrying RMI_DEVICE from +* driver_data would send rmi_input_configured() into rmi_set_page() +* with writeReport still NULL. A bind through the new_id sysfs +* attribute can supply driver_data with the bit set, so do not let +* driver_data grant it. +*/ + data->device_flags = id->driver_data & ~RMI_DEVICE ;/* * Check for the RMI specific report ids. If they are misisng
@@ -698,6 +727,17 @@ static int rmi_probe(struct hid_device * data->output_report_size =hid_report_len (output_report); +/* +* The write reports built by this driver occupy 6 bytes and the read +* handshake looks at the first 3 bytes of an input report, so refuse +* to drive a device whose reports cannot hold them. +*/ +if (data->output_report_size <6 || data->input_report_size <3 ) { +hid_err (hdev,"rmi reports too small (out=%u in=%u)\n" , + data->output_report_size, data->input_report_size); + goto start; + } + data->device_flags |=RMI_DEVICE ; alloc_size = data->output_report_size + data->input_report_size;
Greg Kroah-Hartman
maintainerPATCH 288/1191 HID: wacom: validate report length in wacom_intuos_pro2_bt_irq
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ibrahim Hashimov <[email protected]>
commit a8e04f3f894ccb52cfcd7e60125a9f35da4a616d upstream.
wacom_intuos_pro2_bt_irq() receives the wire report length in len but never consults it before parsing. After the report-id gate it unconditionally calls wacom_intuos_pro2_bt_pen() and then, selected by features.type, a fixed chain of sub-parsers, none of which receive len:
wacom_intuos_pro2_bt_pen(wacom);
if (type == INTUOSP2_BT || type == INTUOSP2S_BT) {
wacom_intuos_pro2_bt_touch(wacom);
wacom_intuos_pro2_bt_pad(wacom);
wacom_intuos_pro2_bt_battery(wacom);
} else {
wacom_intuos_gen3_bt_pad(wacom);
wacom_intuos_gen3_bt_battery(wacom);
}Each sub-parser dereferences wacom->data at fixed offsets. The furthest byte touched on each branch is:
INTUOSP2_BT / INTUOSP2S_BT: wacom_intuos_pro2_bt_pad() reads data[285]
(the touchring byte), so the report must be at least 286 bytes;
INTUOSHT3_BT ("gen3"): wacom_intuos_gen3_bt_battery() reads data[45],
so the report must be at least 46 bytes.
features.type is selected from the VID/PID id_table entry and wacom_setup_device_quirks() force-registers the pen/pad/touch inputs for that type independent of the report descriptor, so a malicious or malfunctioning paired/spoofed Bluetooth peripheral can advertise that VID/PID and send an undersized report that still satisfies the data[0] == 0x80/0x81 gate. The driver then reads past the received report and forwards the bytes to userspace via evdev (MSC_SERIAL / ABS_MISC / ABS_WHEEL on the pen and pad input nodes), an out-of-bounds read with a concrete userspace read-back channel, and a true out-of-bounds read on transports whose backing buffer is sized to the (small) report descriptor rather than a fixed-size staging buffer.
This is the same class of bug commit 2f1763f62909 ("HID: wacom: fix out-of-bounds read in wacom_intuos_bt_irq") already hardened in the sibling wacom_intuos_bt_irq(), which guards each report id against its minimum length before parsing.
Guard wacom_intuos_pro2_bt_irq() the same way: before parsing, reject reports shorter than the furthest offset the selected branch actually dereferences, warn, and bail out. Because the whole pen/touch/pad/ battery chain runs unconditionally per branch, a single up-front check against the maximum offset (286 bytes for INTUOSP2_BT/INTUOSP2S_BT, 46 bytes for the gen3 branch) bounds every sub-parser. Returning 0 on a short report also skips those calls for the same malformed report, which is the safe, conservative behavior.
--- drivers/hid/wacom_wac.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/hid/wacom_wac.c +13 -0
@@ -1591,6 +1591,19 @@ static int wacom_intuos_pro2_bt_irq(strureturn 0 ; } +if (wacom->features.type ==INTUOSP2_BT || + wacom->features.type ==INTUOSP2S_BT ) { +if (len <286 ) { +dev_warn (wacom->pen_input->dev.parent, +"Pro2 BT report too short: %zu bytes\n" , len); +return 0 ; + } + }else if (len <46 ) { +dev_warn (wacom->pen_input->dev.parent, +"Pro2 BT report too short: %zu bytes\n" , len); +return 0 ; + } +wacom_intuos_pro2_bt_pen (wacom);if (wacom->features.type ==INTUOSP2_BT || wacom->features.type ==INTUOSP2S_BT ) {
Greg Kroah-Hartman
maintainerPATCH 289/1191 dm: fix race when loading and unloading a table
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 5380c7f6335cc6d77eb77d065105e81155c4d9d3 upstream.
If the userspace calls two concurrent table load ioctls and one of them succeeds and the other fails, there is a race condition because dm_setup_md_queue walks &md->table_devices without any lock. If the walk races with dm_table_destroy -> free_devices -> dm_put_table_device, there is access to invalid memory.
Fix this race by extending the lock over the list walk.
--- drivers/md/dm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
drivers/md/dm.c +8 -4
@@ -2349,9 +2349,10 @@ int dm_setup_md_queue(struct mapped_devi*/ mutex_lock (&md->table_devices_lock); r =add_disk (md->disk); -mutex_unlock (&md->table_devices_lock); -if (r) +if (r) { +mutex_unlock (&md->table_devices_lock);return r; + }/* * Register the holder relationship for devices added before the disk
@@ -2362,18 +2363,21 @@ int dm_setup_md_queue(struct mapped_deviif (r) goto out_undo_holders; } +mutex_unlock (&md->table_devices_lock); r =dm_sysfs_init (md);if (r) - goto out_undo_holders; + goto lock_out_undo_holders; md->type = type; +return 0 ; +lock_out_undo_holders: +mutex_lock (&md->table_devices_lock); out_undo_holders:list_for_each_entry_continue_reverse (td, &md->table_devices, list)bd_unlink_disk_holder (td->dm_dev.bdev, md->disk); -mutex_lock (&md->table_devices_lock);del_gendisk (md->disk);mutex_unlock (&md->table_devices_lock);return r;
Greg Kroah-Hartman
maintainerPATCH 290/1191 dm: fix resume-vs-remove race
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
commit 44b43ec132f1cf3275ecc182d0c82f50c3c4c3d5 upstream.
If the user issues the resume ioctl and the remove ioctl at the same time, it may be possible that the device is resumed after it is suspended in __dm_destroy. The result is that the table is destroyed without calling the postsuspend method.
Dm targets expect that they may be removed only after the postsuspend method method was called. If we break this expectation, it can cause misbehavior in various targets. For example - in the dm-integrity target, the reboot notifier is not unregistered, leading to use-after-free.
Fix this bug by refusing to resume if the device is being destroyed.
--- drivers/md/dm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/md/dm.c +1 -1
@@ -2852,7 +2852,7 @@ retry: r = -EINVAL ;mutex_lock_nested (&md->suspend_lock,SINGLE_DEPTH_NESTING ); -if (!dm_suspended_md (md)) +if (!dm_suspended_md (md) ||test_bit (DMF_FREEING , &md->flags)) goto out;if (dm_suspended_internally_md (md)) {
Greg Kroah-Hartman
maintainerPATCH 291/1191 dmaengine: dw-edma: Complete descriptors before pausing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit c154060016a9db2ac889bfdb0a3c1322f9be8ded upstream.
If PAUSE is requested while the final burst of a descriptor is in flight, the DONE interrupt takes the PAUSE path without checking whether the descriptor has been depleted. The depleted descriptor remains on the issued list and the channel enters EDMA_ST_PAUSE.
On resume, dw_edma_start_transfer() can select that depleted descriptor again even though no burst remains, leaving the channel in an invalid busy state.
Check for descriptor completion before acknowledging PAUSE. If there is no work to start on resume, leave the channel idle. Also ignore DONE interrupts while the channel is paused so a stale or repeated interrupt cannot change its state or start queued work.
--- drivers/dma/dw-edma/dw-edma-core.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/dma/dw-edma/dw-edma-core.c +14 -6
@@ -240,7 +240,8 @@ static int dw_edma_device_resume(struct err = -EPERM ; }else { chan->status =EDMA_ST_BUSY ; -dw_edma_start_transfer (chan); +if (!dw_edma_start_transfer (chan)) + chan->status =EDMA_ST_IDLE ; }return err;
@@ -591,10 +592,16 @@ static void dw_edma_done_interrupt(strucdw_edma_v0_core_clear_done_int (chan);spin_lock_irqsave (&chan->vc.lock, flags); +if (chan->status ==EDMA_ST_PAUSE ) { +spin_unlock_irqrestore (&chan->vc.lock, flags); +return ; + } + vd =vchan_next_desc (&chan->vc);if (vd) {switch (chan->request) {case EDMA_REQ_NONE : +case EDMA_REQ_PAUSE : desc =vd2dw_edma_desc (vd);if (!desc->chunks_alloc) { dw_hdma_set_callback_result(vd,
@@ -603,6 +610,12 @@ static void dw_edma_done_interrupt(strucvchan_cookie_complete (vd); } +if (chan->request ==EDMA_REQ_PAUSE ) { + chan->request =EDMA_REQ_NONE ; + chan->status =EDMA_ST_PAUSE ; +break ; + } +/* Continue transferring if there are remaining chunks or issued requests. */ chan->status =dw_edma_start_transfer (chan) ?EDMA_ST_BUSY :EDMA_ST_IDLE ;
@@ -615,11 +628,6 @@ static void dw_edma_done_interrupt(struc chan->status =EDMA_ST_IDLE ;break ; -case EDMA_REQ_PAUSE : - chan->request =EDMA_REQ_NONE ; - chan->status =EDMA_ST_PAUSE ; -break ; -default :break ; }
Greg Kroah-Hartman
maintainerPATCH 292/1191 dmaengine: dw-edma: Initialize IRQ data before requesting IRQs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Koichiro Den <[email protected]>
commit 647217abea849d3d45f8cb0b8ee5b78d50f26985 upstream.
dw_edma_irq_request() passes struct dw_edma_irq to request_irq() before dw_edma_channel_setup() fills the back pointer. A shared interrupt can therefore enter the handler with dw_irq->dw still NULL, leading to a NULL pointer dereference.
Set the back pointer before installing each handler.
--- drivers/dma/dw-edma/dw-edma-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/dma/dw-edma/dw-edma-core.c +2 -1
@@ -806,7 +806,6 @@ static int dw_edma_channel_setup(structelse irq->rd_mask |=BIT (j); - irq->dw = dw;memcpy (&chan->msi, &irq->msi,sizeof (chan->msi)); dev_vdbg(dev, "MSI:\t\tChannel %s[%u] addr=0x%.8x%.8x, data=0x%.8x\n",
@@ -901,6 +900,7 @@ static int dw_edma_irq_request(struct dwif (chip->nr_irqs ==1 ) {/* Common IRQ shared among all channels */ irq = chip->ops->irq_vector (dev,0 ); + dw->irq[0 ].dw = dw; err =request_irq (irq, dw_edma_interrupt_common,IRQF_SHARED , dw->name, &dw->irq[0 ]);if (err) {
@@ -926,6 +926,7 @@ static int dw_edma_irq_request(struct dwfor (i =0 ; i < (*wr_alloc + *rd_alloc); i++) { irq = chip->ops->irq_vector (dev, i); + dw->irq[i].dw = dw; err = request_irq(irq, i < *wr_alloc ? dw_edma_interrupt_write :
Greg Kroah-Hartman
maintainerPATCH 293/1191 cpuidle: dt_idle_genpd: kfree() the original name allocation
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 2b0ac85512b7f67479127b2713254490662eb13d upstream.
dt_idle_pd_alloc() kasprintf()s the full node path, then points pd->name at kbasename() of that string. dt_idle_pd_free() kfree()s pd->name, which is no longer the start of the allocation.
Copy the basename instead.
--- drivers/cpuidle/dt_idle_genpd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/cpuidle/dt_idle_genpd.c +1 -2
@@ -99,7 +99,7 @@ struct generic_pm_domain *dt_idle_pd_allif (!pd) goto out; - pd->name =kasprintf (GFP_KERNEL ,"%pOF" , np); + pd->name =kstrdup (kbasename (of_node_full_name (np)),GFP_KERNEL );if (!pd->name) goto free_pd;
@@ -112,7 +112,6 @@ struct generic_pm_domain *dt_idle_pd_all goto free_name; pd->free_states = pd_free_states; - pd->name =kbasename (pd->name); pd->states = states; pd->state_count = state_count;
Greg Kroah-Hartman
maintainerPATCH 294/1191 block: flag zoned disks with GENHD_FL_NO_PART
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
commit 3f9c7a108c0e8f14425384912017071b71341e3b upstream.
Zoned block devices do not support partitions. However, the partition table is nevertheless still inspected, and any partition found ignored with a warning in add_partition(). While this is generally not a problem, and in fact beneficial to the user as it indicates an invalid use of a zoned block device, scanning for a partition table on the device may result in issuing read operations to offline zones (e.g. after a disk head is depopulated for disks that support head management operations).
Since partitions are ignored anyway, completely disable partition scanning for zoned gendisks by setting the flag GENHD_FL_NO_PART in __add_disk(). The existing check in add_partition() is left as-is to ensure that we still get a warning if for whatever reason, despite GENHD_FL_NO_PART, we still endup trying to add partitions.
Flagging zoned disks with GENHD_FL_NO_PART also has the benefit to expose through sysfs the ext_range attribute with the value of 1 instead of the default DISK_MAX_PARTS, thus correctly advertizing the fact that zoned disks do not support partitions.
--- block/genhd.c | 7 +++++++ 1 file changed, 7 insertions(+)
block/genhd.c +7 -0
@@ -428,6 +428,13 @@ int __must_check device_add_disk(structelevator_init_mq (disk->queue);/* +* We do not support partitions with zoned block devices, so do not try +* to scan the partitions table. +*/ +if (blk_queue_is_zoned (disk->queue)) + disk->flags |=GENHD_FL_NO_PART ; + +/* * If the driver provides an explicit major number it also must provide * the number of minors numbers supported, and those will be used to * setup the gendisk.
Greg Kroah-Hartman
maintainerPATCH 295/1191 ata: ahci: work around lost interrupts on Marvell 88SE61xx
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hajo Noerenberg <[email protected]>
commit dc3565a4ae538e584e5e63b3b3cd1eaf502593c1 upstream.
ahci_single_level_irq_intr() services the ports first and clears the global HOST_IRQ_STAT afterwards, as recommended by AHCI 1.1 section 10.6.2. The Marvell 88SE6111/6121/6145 family stops reporting interrupts for a port when HOST_IRQ_STAT is cleared while PxIS still holds bits:
PxIS keeps its content, HOST_IRQ_STAT reads back as 0, the port is never looked at again, and the command in flight only ends in a timeout.
Measured on a Seagate Blackarmor NAS440 (Marvell 88F6281 Kirkwood, 88SE6121 rev B2 behind PCIe) by polling the AHCI registers from userspace while an IDENTIFY was outstanding:
t=303.046 irqs 127 PxIS 0x00000000 PxCI 0x00000001
IDENTIFY issued
t=303.057 irqs 128 PxIS 0x00000020 PxCI 0x00000000
CI cleared, DPS set, one interrupt taken ... PxIS stays 0x00000020, HOST_IRQ_STAT stays 0 ...
t~308.05 qc timeout after 5000 msecs
The command had completed - PxCI was clear and PxIS had DPS set - so ahci_qc_complete() would have completed it. It never got the chance because the handler read HOST_IRQ_STAT as 0 and returned IRQ_NONE.
Marvell's own driver for these chips clears the two registers in the opposite order and says so ("clear global before channel"), and ahci_xgene handles its broken edge latch the same way. Since the reordering costs at most one spurious interrupt per valid one on conforming controllers, do it in a private interrupt handler selected for board_ahci_mv instead of changing libahci for everyone.
With this applied, SATA-2 and SATA-3 disks work at 3.0 Gbps on the 88SE6121 without the drive-side 1.5 Gbps jumper that was needed before. Time from link up to a successful IDENTIFY:
WDC WD5000AADS-00S9B0 port 0 7 ms (never identified before) WDC WD3202ABYS-01B7A0 port 1 28 ms WDC WD30EFRX-68EUZN0 port 1 200 ms (3 TB, HPA detection ok)
Only the 88SE6121 was tested; board_ahci_mv also covers the 88SE6145, which Marvell's driver treats identically.
--- drivers/ata/ahci.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/ata/ahci.c +49 -0
@@ -1563,6 +1563,51 @@ static irqreturn_t ahci_thunderx_irq_han }#endif +/* +* The Marvell 88SE6111/6121/6145 ("Thor") family stops reporting interrupts +* for a port when HOST_IRQ_STAT is cleared while PxIS still holds bits: PxIS +* keeps its content, HOST_IRQ_STAT reads back as 0, the port is never looked +* at again and the command in flight only ends in a timeout. On a 88SE6121 +* this makes every SATA-2 or SATA-3 disk fail to IDENTIFY, while SATA-1 disks +* happen to win the race often enough to work. +* +* Clearing the host status before servicing the ports avoids it. Marvell's +* own driver for these chips does the same and says so ("clear global before +* channel"), and ahci_xgene handles its broken edge latch the same way. The +* price is at most one spurious interrupt per valid one, which is why this is +* not the generic behaviour - see AHCI 1.1 section 10.6.2. +* +* Link: https://bugzilla.kernel.org/show_bug.cgi?id=216094 +*/ +static irqreturn_t ahci_mv_irq_handler (int irq,void *dev_instance) +{ +struct ata_host *host = dev_instance; +struct ahci_host_priv *hpriv = host->private_data; +void __iomem *mmio = hpriv->mmio; +unsigned int rc; +u32 irq_stat, irq_masked; + + irq_stat =readl (mmio +HOST_IRQ_STAT ); +if (!irq_stat) +return IRQ_NONE ; + + irq_masked = irq_stat & hpriv->port_map; + +spin_lock (&host->lock); + +/* +* Use the unmasked value to clear the interrupt, as a spurious pending +* event on a dummy port might cause a screaming IRQ. +*/ +writel (irq_stat, mmio +HOST_IRQ_STAT ); + + rc =ahci_handle_port_intr (host, irq_masked); + +spin_unlock (&host->lock); + +return IRQ_RETVAL (rc); +} +static void ahci_remap_check (struct pci_dev *pdev,int bar,struct ahci_host_priv *hpriv) {
@@ -1806,6 +1851,10 @@ static int ahci_init_one(struct pci_devreturn -ENOMEM ; hpriv->flags |= (unsigned long )pi.private_data; +/* the Marvell "Thor" family needs HOST_IRQ_STAT cleared first */ +if (board_id == board_ahci_mv) + hpriv->irq_handler = ahci_mv_irq_handler; +/* MCP65 revision A1 and A2 can't do MSI */ if (board_id == board_ahci_mcp65 && (pdev->revision ==0xa1 || pdev->revision ==0xa2 ))
Greg Kroah-Hartman
maintainerPATCH 296/1191 ima: Check for ERR_PTR from dentry_path() in validate_hash_algo()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bradley Morgan <[email protected]>
commit 8861f6d5c0678a7c5089c7b272509fc5931b8437 upstream.
dentry_path() returns ERR_PTR(-ENAMETOOLONG) when the path exceeds the buffer. validate_hash_algo() passes the result straight to integrity_audit_msg() without checking. ERR_PTR is not NULL, so integrity_audit_message() sees a valid pointer and calls strlen() on it, which faults:
BUG: unable to handle page fault for address: ffffffffffffffdc
RIP: 0010:strlen+0x30/0xa0
Call Trace:
audit_log_untrustedstring+0x19/0x30
integrity_audit_message+0x366/0x4f0
ima_inode_setxattr+0x512/0x5f0Check for IS_ERR() and use NULL instead, which makes the audit message skip the name= field instead of crashing.
--- security/integrity/ima/ima_appraise.c | 2 ++ 1 file changed, 2 insertions(+)
security/integrity/ima/ima_appraise.c +2 -0
@@ -740,6 +740,8 @@ static int validate_hash_algo(struct denreturn -EACCES ; path =dentry_path (dentry, pathbuf,PATH_MAX ); +if (IS_ERR (path)) + path =NULL ;integrity_audit_msg (AUDIT_INTEGRITY_DATA ,d_inode (dentry), path,"set_data" , errmsg, -EACCES ,0 );
Greg Kroah-Hartman
maintainerPATCH 297/1191 kprobes: Protect kprobe_blacklist with RCU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit 0c4256196b3a105307e2235fbfd85e768bbcdd0f upstream.
__within_kprobe_blacklist() traverses kprobe_blacklist without holding kprobe_mutex. When a module is unloaded, kprobe_remove_area_blacklist() removes blacklist entries and immediately frees them with kfree(). A concurrent call to within_kprobe_blacklist() can therefore dereference freed memory.
Furthermore, within_kprobe_blacklist() can be called in atomic or non-preemptible contexts where the sleeping kprobe_mutex cannot be taken.
Protect kprobe_blacklist with RCU. Use guard(rcu)() and list_for_each_entry_rcu() for traversal, list_add_tail_rcu() for insertions, list_del_rcu() for deletions, and kfree_rcu() to reclaim entries safely after a grace period.
--- include/linux/kprobes.h | 1 + kernel/kprobes.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)
include/linux/kprobes.h +1 -0
@@ -186,6 +186,7 @@ struct kprobe_blacklist_entry {struct list_head list;unsigned long start_addr;unsigned long end_addr; +struct rcu_head rcu; };#ifdef CONFIG_KPROBES
kernel/kprobes.c +10 -4
@@ -1384,8 +1384,14 @@ static bool __within_kprobe_blacklist(un/* * If 'kprobe_blacklist' is defined, check the address and * reject any probe registration in the prohibited area. +* Note: this can return true during transition period where +* (start_addr, end_addr) in the black list is shrinking +* but old entry has not been removed yet. This is acceptable +* because the worst case is that we reject more probes than +* we should. */ -list_for_each_entry (ent, &kprobe_blacklist, list) { +guard (rcu)(); +list_for_each_entry_rcu (ent, &kprobe_blacklist, list) {if (addr >= ent->start_addr && addr < ent->end_addr)return true; }
@@ -2478,7 +2484,7 @@ int kprobe_add_ksym_blacklist(unsigned l ent->start_addr = entry; ent->end_addr = entry + size;INIT_LIST_HEAD (&ent->list); -list_add_tail (&ent->list, &kprobe_blacklist); +list_add_tail_rcu (&ent->list, &kprobe_blacklist);return (int )size; }
@@ -2507,8 +2513,8 @@ static void kprobe_remove_area_blacklistlist_for_each_entry_safe (ent, n, &kprobe_blacklist, list) {if (ent->start_addr < start || ent->start_addr >= end)continue ; -list_del (&ent->list); -kfree (ent); +list_del_rcu (&ent->list); +kfree_rcu (ent, rcu); } }
Greg Kroah-Hartman
maintainerPATCH 298/1191 Input: aiptek - validate raw macro indices before updating state
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
[ Upstream commit 95dffe32a66cbed07fbfa7afed39d56d5014e04f ]
aiptek_irq() derives macro key indices directly from tablet reports and then uses them to index macroKeyEvents[]. Report types 4 and 5 also save the derived value in aiptek->lastMacro and later use that state to release the previous key.
Validate the raw macro index once before it enters that state machine, so lastMacro only ever stores an in-range macro key. Keep direct bounds checks for report type 6, which reads the macro number from the packet body and uses it immediately.
--- drivers/input/tablet/aiptek.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/input/tablet/aiptek.c +9 -4
@@ -658,6 +658,8 @@ static void aiptek_irq(struct urb *urb) pck = (data[1 ] & aiptek->curSetting.stylusButtonUpper) !=0 ?1 :0 ; macro = dv && p && tip && !(data[3 ] &1 ) ? (data[3 ] >>1 ) :-1 ; +if (macro >=ARRAY_SIZE (macroKeyEvents)) + macro =-1 ; z =get_unaligned_le16 (data +4 );if (dv) {
@@ -699,7 +701,9 @@ static void aiptek_irq(struct urb *urb) left = (data[1 ]& aiptek->curSetting.mouseButtonLeft) !=0 ?1 :0 ; right = (data[1 ] & aiptek->curSetting.mouseButtonRight) !=0 ?1 :0 ; middle = (data[1 ] & aiptek->curSetting.mouseButtonMiddle) !=0 ?1 :0 ; - macro = dv && p && left && !(data[3 ] &1 ) ? (data[3 ] >>1 ) :0 ; + macro = dv && p && left && !(data[3 ] &1 ) ? (data[3 ] >>1 ) :-1 ; +if (macro >=ARRAY_SIZE (macroKeyEvents)) + macro =-1 ;if (dv) {/* If the selected tool changed, reset the old
@@ -737,11 +741,11 @@ static void aiptek_irq(struct urb *urb)*/ else if (data[0] == 6) { macro =get_unaligned_le16 (data +1 ); -if (macro >0 ) { +if (macro >0 && macro -1 <ARRAY_SIZE (macroKeyEvents)) {input_report_key (inputdev, macroKeyEvents[macro -1 ],0 ); } -if (macro <25 ) { +if (macro +1 <ARRAY_SIZE (macroKeyEvents)) {input_report_key (inputdev, macroKeyEvents[macro +1 ],0 ); }
@@ -760,7 +764,8 @@ static void aiptek_irq(struct urb *urb) aiptek->curSetting.toolMode; } -input_report_key (inputdev, macroKeyEvents[macro],1 ); +if (macro <ARRAY_SIZE (macroKeyEvents)) +input_report_key (inputdev, macroKeyEvents[macro],1 );input_report_abs (inputdev,ABS_MISC ,1 |AIPTEK_REPORT_TOOL_UNKNOWN );input_sync (inputdev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 299/1191 rtc: rzn1: Fix weekday underflow when alarm crosses month boundary
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
commit 022a2839a52006531804a8db55d3228084400b48 upstream.
rzn1_rtc_set_alarm() calculates the alarm weekday from the difference between the alarm day and the current day of the month. When the alarm crosses a month boundary, this difference can become negative. Since days_ahead is unsigned, it underflows and results in an incorrect weekday being programmed into RZN1_RTC_ALW.
The RTC core already provides a fully populated struct rtc_time for the alarm, including the correct tm_wday. Use tm->tm_wday directly instead of recalculating the weekday from the day-of-month.
This avoids the underflow and ensures alarms scheduled across a month boundary use the correct weekday.
--- drivers/rtc/rtc-rzn1.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/rtc/rtc-rzn1.c +1 -6
@@ -219,7 +219,6 @@ static int rzn1_rtc_set_alarm(struct devstruct rzn1_rtc *rtc =dev_get_drvdata (dev);struct rtc_time *tm = &alrm->time, tm_now;unsigned long alarm, farest; -unsigned int days_ahead, wday;int ret; ret =rzn1_rtc_read_time (dev, &tm_now);
@@ -232,13 +231,9 @@ static int rzn1_rtc_set_alarm(struct devif (time_after (alarm, farest))return -ERANGE ; -/* Convert alarm day into week day */ - days_ahead = tm->tm_mday - tm_now.tm_mday; - wday = (tm_now.tm_wday + days_ahead) %7 ; -writel (bin2bcd (tm->tm_min), rtc->base +RZN1_RTC_ALM );writel (bin2bcd (tm->tm_hour), rtc->base +RZN1_RTC_ALH ); -writel (BIT (wday), rtc->base +RZN1_RTC_ALW ); +writel (BIT (tm->tm_wday), rtc->base +RZN1_RTC_ALW );rzn1_rtc_alarm_irq_enable (dev, alrm->enabled);
Greg Kroah-Hartman
maintainerPATCH 300/1191 rtc: rzn1: Disable alarm interrupt before reprogramming alarm registers
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
commit 51458d5b0a1cfb1b6013400abc95aadf16ed2a57 upstream.
rzn1_rtc_set_alarm() updates RZN1_RTC_ALM, RZN1_RTC_ALH and RZN1_RTC_ALW using separate MMIO writes without first disabling the alarm interrupt. If a previous alarm is still enabled, the interrupt can fire while the alarm registers contain a mixture of old and newly written values.
Fix this by disabling the alarm interrupt before reprogramming ALM, ALH and ALW with a call to rzn1_rtc_alarm_irq_enable().
--- drivers/rtc/rtc-rzn1.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/rtc/rtc-rzn1.c +5 -0
@@ -231,6 +231,11 @@ static int rzn1_rtc_set_alarm(struct devif (time_after (alarm, farest))return -ERANGE ; +/* Disable alarm interrupts before reprogramming the alarm. */ + ret =rzn1_rtc_alarm_irq_enable (dev,0 ); +if (ret) +return ret; +writel (bin2bcd (tm->tm_min), rtc->base +RZN1_RTC_ALM );writel (bin2bcd (tm->tm_hour), rtc->base +RZN1_RTC_ALH );writel (BIT (tm->tm_wday), rtc->base +RZN1_RTC_ALW );
Greg Kroah-Hartman
maintainerPATCH 301/1191 perf/x86/intel: Fix kernel address leakages in LBR stack
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
commit e2b0575900ff72aa82748af96e7bd564ade5157a upstream.
Before Arch LBR gained CPL filtering support, a user-only branch stack could still contain kernel addresses. As a result, kernel branch records may be exposed to user space even when PERF_SAMPLE_BRANCH_USER is requested.
For example, on Intel Tiger Lake, the following command can still report SYSRET/ERET entries with kernel-space from addresses:
$ ./perf record -e cycles:p -o - --branch-filter any,save_type,u -- \
./perf bench syscall basic --loop 1000 | \
./perf script -i - --fields brstack|tr ' ' '\n'| \
grep -E '0x[89a-f][0-9a-f]{15}' Total time: 0.000 [sec]
0.219000 usecs/op
4,566,210 ops/sec[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.551 MB - ] 0xffffffff93c001c8/0x7f12a2b1d647/P/-/-/16959/SYSRET/- 0xffffffff93c001c8/0x7f12a2b1d5c2/P/-/-/17535/SYSRET/- 0xffffffff93c01928/0x7f12a2861000/P/-/-/6719/ERET/- 0xffffffff93c01928/0x7f12a297a000/P/-/-/8575/ERET/-
The problem is that intel_pmu_lbr_filter() does not fully validate the privilege level of sampled entries. It filters some mismatches based on the branch type and the to address, but it does not reject entries whose from address violates the requested branch privilege filter.
Fix this by extending software filtering to validate both from and to addresses against br_sel. Any LBR entry contains kernel address does not match the requested user filter is dropped. This prevents kernel addresses from appearing in user-only branch stacks.
--- arch/x86/events/intel/lbr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/x86/events/intel/lbr.c +9 -3
@@ -1124,7 +1124,7 @@ intel_pmu_lbr_filter(struct cpu_hw_event {u64 from, to;int br_sel = cpuc->br_sel; -int i, j, type, to_plm; +int i, j, type, from_plm, to_plm;bool compress = false;/* if sampling all branches, then nothing to filter */
@@ -1156,8 +1156,14 @@ intel_pmu_lbr_filter(struct cpu_hw_event type |=X86_BR_NO_TX ; } -/* if type does not correspond, then discard */ -if (type ==X86_BR_NONE || (br_sel & type) != type) { + from_plm =kernel_ip (from) ?X86_BR_KERNEL :X86_BR_USER ; +/* +* If type does not correspond, then discard. +* Specifically reject entries whose from address is in +* kernel space when only X86_BR_USER is requested. +*/ +if (type ==X86_BR_NONE || (br_sel & type) != type || + (!(br_sel &X86_BR_KERNEL ) && (from_plm &X86_BR_KERNEL ))) { cpuc->lbr_entries[i].from =0 ; compress = true; }
Greg Kroah-Hartman
maintainerPATCH 302/1191 perf hisi-ptt: Fix PTT trace TLP header parsing
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sizhe Liu <[email protected]>
commit 2b8a2e5d424f0b3369054305d0bf6a5b9faee6c1 upstream.
TLP Headers traced by HiSilicon PCIe tune and trace device (PTT) in 4DW format are shown in the document as below:
bits [31:30] [ 29:25 ][24][23][22][21][ 20:11 ][ 10:0 ]
|-----|---------|---|---|---|---|-------------|-------------|
DW0 [ Fmt ][ Type ][T9][T8][TH][SO][ Length ][ Time ]
DW1 [ Header DW1 ]
DW2 [ Header DW2 ]
DW3 [ Header DW3 ]Problem:
The DW0 bit field layout of the hisi_ptt_4dw union does not match the actual bit ordering in little-endian memory, causing incorrect field decoding.
Test on Kunpeng 930 SOC, generating data flow with iperf commands:
- server side:
iperf -s
- client side:
iperf -c $ip_addr -t 30
Trace the TLP headers with hisi_ptt on server side at the same time:
perf record -e hisi_ptt12_0/type=4,filter=0x05101,direction=2,format=0/ \
--max-size 50M -o perf.data &
The trace aims to capture completion TLPs, learn more in the document:
https://docs.kernel.org/trace/hisi-ptt.html
Decode perf.data with hisi_ptt decoder:
perf report -D
The hisi_ptt decoder produces the following result:
[...perf headers and other information]
. ... HISI PTT data: size 8388608 bytes
. 00000000: 68 87 20 94 Format 3 Type 1a T9 0 T8 1 TH 1 SO 1 Length 10 Time 4a1 . 00000004: 40 00 00 00 Header DW1 . 00000008: 40 00 01 51 Header DW2 . 0000000c: 00 00 00 00 Header DW3
[...other hisi_ptt TLP headers]
According to PCIe r5.0 sec 2.2.1, the Fmt & Type of Cpl/CplD is supposed to be 8b'00001010' / 8b'01001010'
However, the Format & Type decoder analyzing result is 8b'01111010'. It does not match field encodings of any TLP.
Correct decoder result should be:
[...perf headers and other information]
. ... HISI PTT data: size 8388608 bytes
. 00000000: 94 20 87 68 Format 2 Type a T9 0 T8 0 TH 0 SO 1 Length 10 Time 768 . 00000004: 00 00 00 40 Header DW1 . 00000008: 51 01 00 40 Header DW2 . 0000000c: 00 00 00 00 Header DW3
[...other hisi_ptt TLP headers]
To solve the problem:
1. Drop the union and C bitfield struct, store the raw DW value in a plain uint32_t, and extract the fields with FIELD_GET() against GENMASK/BIT masks declared in the header so they can be reused by other translation units. The masks are portable across endianness and compilers.
2. Print all DW hex values in big-endian byte order for readability, matching the bit field layout shown in the 4DW format diagram.
3. Read the DW value with get_unaligned_le32() instead of an unaligned pointer cast, avoiding both strict-aliasing violations and alignment hazards on hosts that do not support unaligned access.
--- Documentation/trace/hisi-ptt.rst | 28 ++++----- tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 47 ++++++++-------- tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 12 ++++ 3 files changed, 50 insertions(+), 37 deletions(-)
Documentation/trace/hisi-ptt.rst +14 -14
@@ -279,20 +279,20 @@ according to the format described previo [...perf headers and other information] . ... HISI PTT data: size 4194304 bytes . 00000000: 00 00 00 00 Prefix - . 00000004: 01 00 00 60 Header DW0 - . 00000008: 0f 1e 00 01 Header DW1 - . 0000000c: 04 00 00 00 Header DW2 - . 00000010: 40 00 81 02 Header DW3 - . 00000014: 33 c0 04 00 Time + . 00000004: 60 00 00 01 Header DW0 + . 00000008: 01 00 1e 0f Header DW1 + . 0000000c: 00 00 00 04 Header DW2 + . 00000010: 02 81 00 40 Header DW3 + . 00000014: 00 04 c0 33 Time . 00000020: 00 00 00 00 Prefix - . 00000024: 01 00 00 60 Header DW0 - . 00000028: 0f 1e 00 01 Header DW1 - . 0000002c: 04 00 00 00 Header DW2 - . 00000030: 40 00 81 02 Header DW3 - . 00000034: 02 00 00 00 Time + . 00000024: 60 00 00 01 Header DW0 + . 00000028: 01 00 1e 0f Header DW1 + . 0000002c: 00 00 00 04 Header DW2 + . 00000030: 02 81 00 40 Header DW3 + . 00000034: 00 00 00 02 Time . 00000040: 00 00 00 00 Prefix - . 00000044: 01 00 00 60 Header DW0 - . 00000048: 0f 1e 00 01 Header DW1 - . 0000004c: 04 00 00 00 Header DW2 - . 00000050: 40 00 81 02 Header DW3 + . 00000044: 60 00 00 01 Header DW0 + . 00000048: 01 00 1e 0f Header DW1 + . 0000004c: 00 00 00 04 Header DW2 + . 00000050: 02 81 00 40 Header DW3 [...]
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +24 -23
81 lines not on this page · raw message
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h +12 -0
@@ -9,12 +9,24 @@#include <stddef.h> #include <stdint.h> +#include <linux/bits.h> +#include <linux/bitfield.h> #define HISI_PTT_8DW_CHECK_MASK GENMASK(31, 11)#define HISI_PTT_IS_8DW_PKT GENMASK(31, 11)#define HISI_PTT_MAX_SPACE_LEN 10#define HISI_PTT_FIELD_LENTH 4 +/* Header DW0 fields for 4DW format */ +#define HISI_PTT_HEAD0_4DW_TIME GENMASK_U32(10, 0) +#define HISI_PTT_HEAD0_4DW_LEN GENMASK_U32(20, 11) +#define HISI_PTT_HEAD0_4DW_SO BIT_U32(21) +#define HISI_PTT_HEAD0_4DW_TH BIT_U32(22) +#define HISI_PTT_HEAD0_4DW_T8 BIT_U32(23) +#define HISI_PTT_HEAD0_4DW_T9 BIT_U32(24) +#define HISI_PTT_HEAD0_4DW_TYPE GENMASK_U32(29, 25) +#define HISI_PTT_HEAD0_4DW_FORMAT GENMASK_U32(31, 30) +enum hisi_ptt_pkt_type {HISI_PTT_4DW_PKT ,HISI_PTT_8DW_PKT ,
Greg Kroah-Hartman
maintainerPATCH 303/1191 i2c: core: fix debugfs UAF on adapter removal
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasileios Almpanis <[email protected]>
commit b15b548d52b43ba8ac4652bc2c7244a8dd1e9622 upstream.
i2c_del_adapter() frees the adapter's debugfs directory before it unregisters the adapter device, but the new_device sysfs attribute stays writable until device_del(). A write racing with removal still reaches i2c_device_probe(), which passes the freed adap->debugfs to debugfs_create_dir() as the new client's parent:
BUG: KASAN: slab-use-after-free in lookup_noperm_common+0x407/0x430 Read of size 4 at addr ffff88803ef87810 by task syz.0.61/6090 lookup_noperm_common+0x407/0x430 simple_start_creating+0x9c/0x110 debugfs_start_creating+0xdb/0x1a0 debugfs_create_dir+0x24/0x350 i2c_device_probe+0x814/0xbf0
It's technically possible to create a client after i2c_deregister_clients has run. That client will never be unregistered and make wait_for_completion hang.
Close the window by removing the new_device attribute at the start of i2c_del_adapter(). device_remove_file() will drain any clients left.
--- drivers/i2c/i2c-core-base.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i2c/i2c-core-base.c +6 -0
@@ -1813,6 +1813,12 @@ void i2c_del_adapter(struct i2c_adapterreturn ; } +/* +* This drains any in-flight writers, so all +* clients will be caught by i2c_deregister_clients(). +*/ +device_remove_file (&adap->dev, &dev_attr_new_device); +i2c_acpi_remove_space_handler (adap);i2c_deregister_clients (adap);
Greg Kroah-Hartman
maintainerPATCH 304/1191 i2c: mux: Fix channel node leak on adapter add failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmad Byagowi <[email protected]>
commit 385c7af4e3b95d0769fd211831674e83b16a2ebf upstream.
i2c_mux_add_adapter() takes a reference to the Device Tree channel node before registering the new adapter. If adapter registration fails, the error path frees the private data without dropping that reference.
Release the channel node before freeing the private data.
--- drivers/i2c/i2c-mux.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/i2c-mux.c +1 -0
@@ -433,6 +433,7 @@ int i2c_mux_add_adapter(struct i2c_mux_creturn 0 ; err_free_priv: +of_node_put (priv->adap.dev.of_node);kfree (priv);return ret; }
Greg Kroah-Hartman
maintainerPATCH 305/1191 ALSA: harmony: initialize locks before requesting IRQ
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 33abb7491e89285a41565670945293dda841afc4 upstream.
snd_harmony_create() registers the IRQ before initializing h->lock and h->mixer_lock. A pending interrupt can invoke the handler while these locks are uninitialized.
Initialize both locks before requesting the IRQ so the handler always sees valid lock state.
--- sound/parisc/harmony.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/parisc/harmony.c +3 -3
@@ -889,6 +889,9 @@ snd_harmony_create(struct snd_card *card goto free_and_ret; } +spin_lock_init (&h->mixer_lock); +spin_lock_init (&h->lock); + err =request_irq (padev->irq, snd_harmony_interrupt,0 ,"harmony" , h);if (err) {
@@ -898,9 +901,6 @@ snd_harmony_create(struct snd_card *card } h->irq = padev->irq; -spin_lock_init (&h->mixer_lock); -spin_lock_init (&h->lock); - err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , h, &ops);if (err <0 ) goto free_and_ret;
Greg Kroah-Hartman
maintainerPATCH 306/1191 ALSA: pcm: Fix race between non-atomic ops and trigger-start
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit acac7b5e07349a9d10d78873afb4b93cd1dc721f upstream.
We protect the races of the concurrent state transitions between atomic PCM ops, but the checks between the non-atomic ops (hw_params, hw_free and prepare) and the atomic ops aren't perfect; there is a check of the conflicting PCM state at the beginning of hw_params & co, but the atomic PCM ops can be still issued during the non-atomic PCM operations. An example such scenario is that a thread A re-issues the PREPARE or HW_PARAMS for the already prepared stream, while another thread B triggers the PCM start in the middle of the prepare operation. Although this usually doesn't lead to much serious issues, it can give some inconsistency as reported by syzkaller (such as ODEBUG warning).
There are various atomic PCM ops, and basically the only problem is the PCM start as it operates from the PREPARED state. Other trigger commands (stop, etc) are for the running or the other special state, hence they are filtered as pre-condition.
This patch is for preventing the PCM trigger-start during the non- atomic operations in order to address the problems above. Fortunately, the hw_params, hw_free and prepare operations call snd_pcm_buffer_access_lock(), and this can be used for checking the concurrent operations at the PCM trigger -- which sets the runtime->buffer_accessing to a negative (if possible), so the PCM trigger just needs to check the runtime->buffer_accessing value; if it's negative, it means the concurrent non-atomic PCM ops is running.
--- sound/core/pcm_native.c | 2 ++ 1 file changed, 2 insertions(+)
sound/core/pcm_native.c +2 -0
@@ -1430,6 +1430,8 @@ static int snd_pcm_pre_start(struct snd_struct snd_pcm_runtime *runtime = substream->runtime;if (runtime->state !=SNDRV_PCM_STATE_PREPARED )return -EBADFD ; +if (atomic_read (&runtime->buffer_accessing) <0 ) +return -EBADFD ;/* during hw_params, hw_free or prepare */ if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && !snd_pcm_playback_data (substream))return -EPIPE ;
Greg Kroah-Hartman
maintainerPATCH 307/1191 nvme-tcp: check the data direction of a C2HData PDU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
commit f83af377c148f6ad94b41c0e8313f12adf45e1c1 upstream.
nvme_tcp_handle_c2h_data() finds the request by command id and checks that it has a payload, but it does not check that the command asked for data to be read. A controller that answers a write command with C2HData therefore reaches nvme_tcp_recv_data(), where _copy_to_iter() hits WARN_ON_ONCE(i->data_source) and returns 0. The receive path turns that into -EFAULT and resets the controller.
No data is copied, so this is not memory corruption. What a controller gets is a kernel warning it can raise at will, which is fatal on a host booted with panic_on_warn.
The send path already knows the direction - it consults rq_data_dir() when it builds a command - and nvme_tcp_handle_r2t() checks the length and the offset of the request it names. The C2HData path does not check the direction at all.
Reject a C2HData PDU whose command is not a read. Rejecting it fails the command and resets the controller, as the neighbouring check in this function does; what goes away is the warning.
[ 6.885580] ------------[ cut here ]------------ [ 6.886457] WARNING: lib/iov_iter.c:193 at _copy_to_iter+0x289/0x1330, CPU#0: kworker/0:1H/71 [ 6.888137] CPU: 0 UID: 0 PID: 71 Comm: kworker/0:1H Not tainted 7.2.0-rc5-NVMETCP-gf5098b6bae76 #1 PREEMPT(lazy) [ 6.891165] Workqueue: nvme_tcp_wq nvme_tcp_io_work [ 6.891875] RIP: 0010:_copy_to_iter+0x289/0x1330 [ 6.903739] Call Trace: [ 6.904085] <TASK> [ 6.909254] __skb_datagram_iter+0x433/0x820 [ 6.911026] skb_copy_datagram_iter+0x37/0x120 [ 6.911622] nvme_tcp_recv_skb+0xa07/0x4320 [ 6.913378] __tcp_read_sock+0x1ab/0x810 [ 6.915788] nvme_tcp_try_recv+0x152/0x1e0 [ 6.918222] nvme_tcp_io_work+0x1e4/0x6c0 [ 6.926906] </TASK> [ 6.927226] ---[ end trace 0000000000000000 ]--- [ 6.927878] nvme nvme0: queue 1 failed to copy request 0x71 data [ 6.928709] nvme nvme0: receive failed: -14
--- drivers/nvme/host/tcp.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/nvme/host/tcp.c +7 -0
@@ -596,6 +596,13 @@ static int nvme_tcp_handle_c2h_data(strureturn -ENOENT ; } +if (rq_data_dir (rq) !=READ ) { +dev_err (queue->ctrl->ctrl.device, +"queue %d tag %#x unexpected data for a write\n" , +nvme_tcp_queue_id (queue), rq->tag); +return -EIO ; + } + req =blk_mq_rq_to_pdu (rq);if (!blk_rq_payload_bytes (rq) || !req->curr_bio || !req->data_len) { dev_err(queue->ctrl->ctrl.device,
Greg Kroah-Hartman
maintainerPATCH 308/1191 nvmet-tcp: fix out-of-bounds write when receiving an over-long PDU
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivam Kumar <[email protected]>
commit 14cc5a7e77731497d5bea70f3bb05df7eda982e4 upstream.
nvmet_tcp_try_recv_pdu() reads a PDU header into the fixed 128-byte queue->pdu union, then computes the remaining payload length as
queue->left = hdr->hlen - queue->offset + hdgst;
and reads that many more bytes into &queue->pdu + queue->offset, without ever bounding the result against sizeof(queue->pdu).
A struct nvme_tcp_icreq_pdu is itself 128 bytes, exactly the size of the union. Once a header digest has been negotiated (hdgst = 4), a second ICReq passes the hlen == nvmet_tcp_pdu_size() check but yields queue->left = 128 - 8 + 4 = 124, so bytes 8..132 are written into the 128-byte buffer -- 4 bytes past its end, over queue->hdr_digest and queue->data_digest. Those bytes are attacker-controlled (an ICReq carries no digest), and the duplicate ICReq is only rejected later, after the overflow. A remote unauthenticated host can thus corrupt kernel memory adjacent to the receive buffer.
Reject any PDU whose declared length would read past the end of queue->pdu before the second recv.
--- drivers/nvme/target/tcp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/target/tcp.c +2 -0
@@ -1192,6 +1192,8 @@ recv: } queue->left = hdr->hlen - queue->offset + hdgst; +if (queue->left >sizeof (queue->pdu) - queue->offset) +return -EPROTO ; goto recv; }
Greg Kroah-Hartman
maintainerPATCH 309/1191 nvmet-tcp: reject unsolicited H2CData PDUs
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivam Kumar <[email protected]>
commit db62b35cbca052860c519cbcabe7650708528738 upstream.
nvmet_tcp_handle_h2c_data_pdu() accepts an H2CData PDU after only checking that its TTAG is a valid in-range command index and that the command's data buffers are mapped. It never checks that the target has actually solicited that data by sending an R2T for the command.
A remote host can abuse this. It submits a write command that takes the R2T path and, before the target transmits the R2T, sends an H2CData PDU for that command's tag. The data completes the command early, and when the command then fails synchronously (e.g. a length mismatch caught by nvmet_check_transfer_len()), it is completed a second time. Each completion calls nvmet_tcp_queue_response(), so the same command is added to queue->resp_list twice while it is still linked; the second llist_add() makes the node point to itself (lentry->next == lentry).
nvmet_tcp_process_resp_list() then walks that self-referential node and adds the command to resp_send_list twice. With CONFIG_DEBUG_LIST this trips the "list_add double add" check (kernel BUG); without it the loop never terminates and the nvmet_tcp workqueue wedges (soft-lockup). It is remotely triggerable and needs no authentication on an allow_any_host subsystem.
Track whether an R2T has been transmitted for a command and reject an H2CData PDU that arrives before it. The flag is cleared on command reuse (nvmet_tcp_get_cmd() zeroes cmd->flags) and stays set across the multiple H2CData PDUs of a single solicited transfer.
--- drivers/nvme/target/tcp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/nvme/target/tcp.c +8 -0
@@ -61,6 +61,7 @@ enum nvmet_tcp_recv_state {enum {NVMET_TCP_F_INIT_FAILED = (1 <<0 ), +NVMET_TCP_F_R2T_SENT = (1 <<1 ), };struct nvmet_tcp_cmd {
@@ -722,6 +723,7 @@ static int nvmet_try_send_r2t(struct nvmreturn -EAGAIN ; cmd->queue->snd_cmd =NULL ; + cmd->flags |=NVMET_TCP_F_R2T_SENT ;return 1 ; }
@@ -997,6 +999,12 @@ static int nvmet_tcp_handle_h2c_data_pdu cmd = &queue->connect; } +if (unlikely (!(cmd->flags &NVMET_TCP_F_R2T_SENT ))) { +pr_err ("queue %d: unsolicited H2CData (ttag %u)\n" , + queue->idx, data->ttag); + goto err_proto; + } +if (le32_to_cpu (data->data_offset) != cmd->rbytes_done) { pr_err("ttag %u unexpected data offset %u (expected %u)\n", data->ttag, le32_to_cpu(data->data_offset),
Greg Kroah-Hartman
maintainerPATCH 310/1191 Revert "irqchip/mbigen: Fix mbigen node address layout"
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: caina <[email protected]>
commit e67091609cf85962f64391c1b0f93d4cbfcd4e22 upstream.
This reverts commit 6be6cba9c4371d27f78d900ccfe34bb880d9ee20.
Commit 6be6cba9c437 ("irqchip/mbigen: Fix mbigen node address layout") appears to cause a regression on Hi1616.
On-board hns NIC has two ports, enahisic2i0 and enahisic2i1, both behind mbigen-v2. Port 0 works; port 1 cannot pass any traffic.
Their interrupt pins fall on different mbigen nodes:
enahisic2i0: pins 1152-1198 -> all in node 9
enahisic2i1: pins 1200-1246 -> node 9 (1200-1215) + node 10 (1216-1246)
(nid = (hwirq - 64) / 128 + 1; pin 1215 = node 9, pin 1216 = node 10)
/proc/interrupts shows the break happens exactly at the node boundary:
enahisic2i1-rx0 pin 1200 count 102 <- node 9 enahisic2i1-rx5 pin 1215 count 1 <- node 9, last pin enahisic2i1-tx5 pin 1216 count 0 <- node 10, first pin enahisic2i1-rx6 pin 1218 count 0 <- node 10
...all node 10 pins stay at zero.
Port 0 (entirely node 9) is unaffected. Reverting the commit restores normal operation.
The commit assumes CLEAR occupies a full 4 KB page at [0xa000, 0xb000) and collides with node 10, so node 10+ gets shifted by 0x1000.
But get_mbigen_clear_reg() uses flat, chip-wide addressing -- it never multiplies by the node ID:
*addr = (hwirq / 32) * 4 + REG_MBIGEN_CLEAR_OFFSET; /* 0xa000 */
Over the valid hwirq range [64, 1407], CLEAR only spans 0xa008-0xa0af (168 bytes). Node 10's registers are:
TYPE: 0xa000-0xa00f (16 B) overlaps CLEAR by 8 B (0xa008-0xa00f)
VEC: 0xa200-0xa3ff (512 B) no overlap with CLEARShifting the whole page moves VEC from 0xa200 to 0xb200. The hardware reads the event ID from the fixed silicon address 0xa200 on interrupt firing, but software wrote it to 0xb200 -- so the hardware gets an uninitialised value and the interrupt is lost.
The only real overlap is 8 bytes of TYPE. It can only trigger when a single mbigen instance has devices on both node 1 (CLEAR 0xa008) and node 10 (TYPE 0xa008). On Hi1616 those nodes are on separate mbigen instances, so it never triggers.
--- drivers/irqchip/irq-mbigen.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/irqchip/irq-mbigen.c +4 -16
@@ -64,20 +64,6 @@ struct mbigen_device {void __iomem *base; }; -static inline unsigned int get_mbigen_node_offset (unsigned int nid) -{ -unsigned int offset = nid *MBIGEN_NODE_OFFSET ; - -/* -* To avoid touched clear register in unexpected way, we need to directly -* skip clear register when access to more than 10 mbigen nodes. -*/ -if (nid >= (REG_MBIGEN_CLEAR_OFFSET /MBIGEN_NODE_OFFSET )) - offset +=MBIGEN_NODE_OFFSET ; - -return offset; -} -static inline unsigned int get_mbigen_vec_reg (irq_hw_number_t hwirq) {unsigned int nid, pin;
@@ -86,7 +72,8 @@ static inline unsigned int get_mbigen_ve nid = hwirq /IRQS_PER_MBIGEN_NODE +1 ; pin = hwirq %IRQS_PER_MBIGEN_NODE ; -return pin *4 +get_mbigen_node_offset (nid) +REG_MBIGEN_VEC_OFFSET ; +return pin *4 + nid *MBIGEN_NODE_OFFSET + +REG_MBIGEN_VEC_OFFSET ; } static inline void get_mbigen_type_reg(irq_hw_number_t hwirq,
@@ -101,7 +88,8 @@ static inline void get_mbigen_type_reg(i *mask =1 << (irq_ofst %32 ); ofst = irq_ofst /32 *4 ; - *addr = ofst +get_mbigen_node_offset (nid) +REG_MBIGEN_TYPE_OFFSET ; + *addr = ofst + nid *MBIGEN_NODE_OFFSET + +REG_MBIGEN_TYPE_OFFSET ; } static inline void get_mbigen_clear_reg(irq_hw_number_t hwirq,
Greg Kroah-Hartman
maintainerPATCH 311/1191 mm/hugetlb: fix missing migratable flag on same-node hugetlb migration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wupeng Ma <[email protected]>
commit 8ee1ef0f2f8ce29338f4ab00a3d344c010208058 upstream.
Commit ba23f58de896 ("mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio") moved setting of the migratable flag and active-list placement from folio_putback_active_hugetlb(dst) into move_hugetlb_state(), so that the freshly allocated destination folio is handled where allocation is known to have succeeded.
Unfortunately, the new code was appended after the existing temporary-folio block in move_hugetlb_state(), which contains an early return added earlier by commit 5af1ab1d24e08 ("mm/hugetlb: optimize the surplus state transfer code in move_hugetlb_state()"):
if (folio_test_hugetlb_temporary(new_folio)) {
...
if (new_nid == old_nid)
return; <-- skips the new code
...
}
/* added by ba23f58 */
folio_set_hugetlb_migratable(new_folio);
list_move_tail(&new_folio->lru, ...&h->hugepage_activelist);When the destination folio is temporary (i.e. the hugetlb pool was exhausted and the migration callback fell back to alloc_migrate_hugetlb_folio()) and the migration does not cross a node -- the common case, and always true on a single-NUMA system -- move_hugetlb_state() returns before setting the migratable flag or adding the new folio to the active list. The destination folio is then installed in the page table but cannot be isolated afterwards, since folio_isolate_hugetlb() rejects folios without the migratable flag; a subsequent soft-offline, hard-offline or memory-hotplug offline of that folio fails with -EBUSY.
This was reproduced on a single-NUMA arm64 VM: a second MADV_SOFT_OFFLINE on an already-migrated hugetlb page returned EBUSY and logged "hugepage isolation failed".
Keep the surplus adjustment, which is the only part that depends on the node crossing, guarded by `if (new_nid != old_nid)', while making the migratable flag and active-list placement unconditional. This preserves the cleanup intent of ba23f58 and closes the early-return hole.
--- mm/hugetlb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
mm/hugetlb.c +7 -7
@@ -7549,14 +7549,14 @@ void move_hugetlb_state(struct page *old* There is no need to transfer the per-node surplus state * when we do not cross the node. */ -if (new_nid == old_nid) -return ; -spin_lock_irq (&hugetlb_lock); -if (h->surplus_huge_pages_node[old_nid]) { - h->surplus_huge_pages_node[old_nid]--; - h->surplus_huge_pages_node[new_nid]++; +if (new_nid != old_nid) { +spin_lock_irq (&hugetlb_lock); +if (h->surplus_huge_pages_node[old_nid]) { + h->surplus_huge_pages_node[old_nid]--; + h->surplus_huge_pages_node[new_nid]++; + } +spin_unlock_irq (&hugetlb_lock); } -spin_unlock_irq (&hugetlb_lock); }/*
Greg Kroah-Hartman
maintainerPATCH 312/1191 nvdimm/btt: reject an arena whose nfree is below the lane count
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 6a1f2e5ed9267ca19187038ac635393c165213ac upstream.
The BTT info block's nfree field, the number of reserve free blocks, is read from the medium without validation. btt_freelist_init() and btt_rtt_init() size the per-lane freelist[] and rtt[] arrays by nfree, but the I/O path indexes them by the lane from nd_region_acquire_lane(), which is bounded by nd_region->num_lanes (ND_MAX_LANES), not by nfree. A crafted or foreign arena whose nfree is below the lane count makes freelist[lane]/rtt[lane] run past the allocation: an out-of-bounds write.
btt.rst documents the nlanes = min(nfree, num_cpus) invariant, which the code does not currently honor: num_lanes is ND_MAX_LANES regardless of nfree. Reject an arena whose nfree is below num_lanes at discovery, before the per-lane arrays are allocated, enforcing that invariant.
--- drivers/nvdimm/btt.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/nvdimm/btt.c +8 -0
@@ -886,6 +886,14 @@ static int discover_arenas(struct btt *b arena->external_lba_start = cur_nlba;parse_arena_meta (arena, super, cur_off); +if (arena->nfree < btt->nd_region->num_lanes) { +dev_err (to_dev (arena), +"nfree %u smaller than lane count %d\n" , + arena->nfree, btt->nd_region->num_lanes); + ret = -ENODEV ; + goto out; + } + ret =log_set_indices (arena);if (ret) { dev_err(to_dev(arena),
Greg Kroah-Hartman
maintainerPATCH 313/1191 parisc: eisa: Fix infinite loop when parsing invalid IRQ value
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
commit 8b585431a16cfb9d8f2955a9fa0787ce3dceb3c2 upstream.
When an invalid value is passed via the "eisa_irq_edge=" kernel command line parameter (e.g. "eisa_irq_edge=16,5"), eisa_irq_setup() prints an error message and continues without advancing the current position. As a result the same invalid value is parsed again and again, causing an infinite loop while the kernel boots.
Advance to the next comma-separated entry, or stop parsing when there is no next entry, before continuing so that the remaining entries are processed normally.
--- drivers/parisc/eisa.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/parisc/eisa.c +5 -0
@@ -441,6 +441,11 @@ static int __init eisa_irq_setup(char *s val = (int )simple_strtoul (cur, &pe,0 );if (val >15 || val <0 ) {printk (KERN_ERR "eisa: EISA irq value are 0-15\n" ); + cur =strchr (cur,',' ); +if (cur) + cur++; +else +break ;continue ; }if (val ==2 ) {
Greg Kroah-Hartman
maintainerPATCH 314/1191 parisc: Fix alignment of asm statements in head.S
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
commit 04cf68c9a76e3c6b67ad056a66a14923abf85925 upstream.
All assembler statements need to be 4-byte aligned. Prevent a possible misalignment if someone changes the preceeding string and it's length is then suddenly not a multiple of 4 any longer.
--- arch/parisc/kernel/head.S | 1 + 1 file changed, 1 insertion(+)
arch/parisc/kernel/head.S +1 -0
@@ -105,6 +105,7 @@ $iodc_panic: or %r10,%r10,%r10 /* qemu idle sleep */ msg1: .ascii "Can't boot kernel which was built for PA8x00 CPUs on this machine.\r\n" msg1_end: + .align 4 $cpu_ok: #endif
Greg Kroah-Hartman
maintainerPATCH 315/1191 powerpc/pseries: Handle and log pseries-wdt registration failures
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourabh Jain <[email protected]>
commit e65b526affa621b50646cafdf6b06505af07032e upstream.
The pseries watchdog initialization registers the pseries-wdt platform device using platform_device_register_simple(), but currently ignores its return value.
Check the returned pointer for errors, log a descriptive error message when registration fails, and propagate the failure code to the caller. This avoids silently ignoring platform device registration failures.
--- arch/powerpc/platforms/pseries/setup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/powerpc/platforms/pseries/setup.c +12 -2
@@ -192,8 +192,18 @@ static void __init fwnmi_init(void)*/ static __init int pseries_wdt_init (void ) { -if (firmware_has_feature (FW_FEATURE_WATCHDOG )) -platform_device_register_simple ("pseries-wdt" ,0 ,NULL ,0 ); +struct platform_device *pdev; + +if (!firmware_has_feature (FW_FEATURE_WATCHDOG )) +return 0 ; + + pdev =platform_device_register_simple ("pseries-wdt" ,0 ,NULL ,0 ); + +if (IS_ERR (pdev)) { +pr_err ("Failed to register pseries-wdt platform device\n" ); +return PTR_ERR (pdev); + } +return 0 ; }machine_subsys_initcall (pseries, pseries_wdt_init);
Greg Kroah-Hartman
maintainerPATCH 316/1191 powerpc/pseries: Move H_WATCHDOG definitions to a common header
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourabh Jain <[email protected]>
commit 516a254918453ec99660201263d01189c082332c upstream.
The H_WATCHDOG input and output definitions are currently local to the pseries watchdog driver. The next patch in this series also needs these definitions to issue H_WATCHDOG hypercalls outside the watchdog driver.
Move the H_WATCHDOG definitions to a new common header, asm/papr-watchdog.h, so they can be shared without duplicating the PAPR watchdog definitions.
No functional changes.
--- arch/powerpc/include/asm/papr-watchdog.h | 58 +++++++++++++++++++++++++++++++ drivers/watchdog/pseries-wdt.c | 53 ---------------------------- 2 files changed, 59 insertions(+), 52 deletions(-) create mode 100644 arch/powerpc/include/asm/papr-watchdog.h
arch/powerpc/include/asm/papr-watchdog.h new file +58 -0
@@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_POWERPC_PAPR_WATCHDOG_H +#define _ASM_POWERPC_PAPR_WATCHDOG_H + +/* +* H_WATCHDOG Input +* +* R4: "flags": +* +* Bits 48-55: "operation" +*/ +#define PSERIES_WDTF_OP_START 0x100UL/* start timer */ +#define PSERIES_WDTF_OP_STOP 0x200UL/* stop timer */ +#define PSERIES_WDTF_OP_QUERY 0x300UL/* query timer capabilities */ + +/* +* Bits 56-63: "timeoutAction" (for "Start Watchdog" only) +*/ +#define PSERIES_WDTF_ACTION_HARD_POWEROFF 0x1UL/* poweroff */ +#define PSERIES_WDTF_ACTION_HARD_RESTART 0x2UL/* restart */ +#define PSERIES_WDTF_ACTION_DUMP_RESTART 0x3UL/* dump + restart */ + +/* +* H_WATCHDOG Output +* +* R3: Return code +* +* H_SUCCESS The operation completed. +* +* H_BUSY The hypervisor is too busy; retry the operation. +* +* H_PARAMETER The given "flags" are somehow invalid. Either the +* "operation" or "timeoutAction" is invalid, or a +* reserved bit is set. +* +* H_P2 The given "watchdogNumber" is zero or exceeds the +* supported maximum value. +* +* H_P3 The given "timeoutInMs" is below the supported +* minimum value. +* +* H_NOOP The given "watchdogNumber" is already stopped. +* +* H_HARDWARE The operation failed for ineffable reasons. +* +* H_FUNCTION The H_WATCHDOG hypercall is not supported by this +* hypervisor. +* +* R4: +* +* - For the "Query Watchdog Capabilities" operation, a 64-bit +* structure: +*/ +#define PSERIES_WDTQ_MIN_TIMEOUT (cap) (((cap) >> 48) & 0xffff) +#define PSERIES_WDTQ_MAX_NUMBER (cap) (((cap) >> 32) & 0xffff) + +#endif /* _ASM_POWERPC_PAPR_WATCHDOG_H */
drivers/watchdog/pseries-wdt.c +1 -52
62 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 317/1191 powerpc/crash: stop watchdogs before booting kdump kernel
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourabh Jain <[email protected]>
commit fb43ba4256543ce18ca0540fc37022bda438a293 upstream.
On pseries LPAR systems, watchdog timers configured from userspace can remain active after a kernel panic. When a panic triggers kdump, the crashing kernel jumps directly to the kdump kernel without stopping active watchdogs. As a result, the watchdogs remain active after the kdump kernel starts.
If dump capture takes longer than the watchdog timeout, PHYP resets the LPAR before the dump is fully captured, causing dump capture to fail.
Fix this by issuing the H_WATCHDOG hcall during the crash shutdown sequence to stop all active watchdogs before booting the kdump kernel.
--- arch/powerpc/include/asm/papr-watchdog.h | 6 ++++++ arch/powerpc/platforms/pseries/setup.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+)
arch/powerpc/include/asm/papr-watchdog.h +6 -0
@@ -22,6 +22,12 @@#define PSERIES_WDTF_ACTION_DUMP_RESTART 0x3UL/* dump + restart */ /* +* R5: "watchdogNumber": +* PAPR says use -1 (all ones) to stop all watchdogs. +*/ +#define PSERIES_WDT_NUM_ALL ((unsigned long)-1) + +/* * H_WATCHDOG Output * * R3: Return code
arch/powerpc/platforms/pseries/setup.c +14 -0
@@ -75,6 +75,7 @@#include <asm/dtl.h> #include <asm/hvconsole.h> #include <asm/setup.h> +#include <asm/papr-watchdog.h> #include "pseries.h"
@@ -186,6 +187,16 @@ static void __init fwnmi_init(void)#endif } +static void pseries_crash_stop_watchdogs (void ) +{ +long rc; + + rc =plpar_hcall_norets_notrace (H_WATCHDOG ,PSERIES_WDTF_OP_STOP , +PSERIES_WDT_NUM_ALL ); +if (rc !=H_SUCCESS && rc !=H_NOOP ) +pr_warn ("Could not stop watchdogs before kdump rc=%ld\n" , rc); +} +/* * Affix a device for the first timer to the platform bus if * we have firmware support for the H_WATCHDOG hypercall.
@@ -204,6 +215,9 @@ static __init int pseries_wdt_init(void)return PTR_ERR (pdev); } +if (crash_shutdown_register (pseries_crash_stop_watchdogs)) +pr_warn ("Could not register watchdog crash shutdown handler\n" ); +return 0 ; }machine_subsys_initcall (pseries, pseries_wdt_init);
Greg Kroah-Hartman
maintainerPATCH 318/1191 s390/vfio-ap: Fix stale do_remove flag across iterations in vfio_ap_mdev_cfg_remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit b1f092d94f621307927f145e3cc31893da51fc08 upstream.
The do_remove flag in vfio_ap_mdev_cfg_remove() is initialised to zero before the loop that iterates over the list of matrix mdevs, but is never reset at the start of each iteration. Since do_remove is OR-accumulated across iterations, a positive result from one mdev carries over to subsequent mdevs.
The fix is to set the do_remove flag with the first call to bitmap_and; for example: do_remove = bitmap_an rather than do_remove |= bitmap_and.
--- drivers/s390/crypto/vfio_ap_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +4 -4
@@ -2032,15 +2032,15 @@ static void vfio_ap_mdev_cfg_remove(unsiDECLARE_BITMAP (aprem,AP_DEVICES );DECLARE_BITMAP (aqrem,AP_DOMAINS );DECLARE_BITMAP (cdrem,AP_DOMAINS ); -int do_remove =0 ; +int do_remove;list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) {mutex_lock (&matrix_mdev->kvm->lock);mutex_lock (&matrix_dev->mdevs_lock); - do_remove |=bitmap_and (aprem, ap_remove, - matrix_mdev->matrix.apm, -AP_DEVICES ); + do_remove =bitmap_and (aprem, ap_remove, + matrix_mdev->matrix.apm, +AP_DEVICES ); do_remove |=bitmap_and (aqrem, aq_remove, matrix_mdev->matrix.aqm,AP_DOMAINS );
Greg Kroah-Hartman
maintainerPATCH 319/1191 s390/vfio-ap: Fix control domain removal in vfio_ap_mdev_cfg_remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 6b8a02e216f6b520cc029e43ddc83956605135d5 upstream.
The vfio_ap_config_remove function uses the bitmap_andnot function to clear bits from the matrix_mdev->matrix.adm bitmap (specifies the control domains assigned to the mdev). This prevents the explicitly unplugged control domains from being removed the KVM guest. The bitmap_and function is used instead.
--- drivers/s390/crypto/vfio_ap_ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +3 -3
@@ -2044,9 +2044,9 @@ static void vfio_ap_mdev_cfg_remove(unsi do_remove |=bitmap_and (aqrem, aq_remove, matrix_mdev->matrix.aqm,AP_DOMAINS ); - do_remove |=bitmap_andnot (cdrem, cd_remove, - matrix_mdev->matrix.adm, -AP_DOMAINS ); + do_remove |=bitmap_and (cdrem, cd_remove, + matrix_mdev->matrix.adm, +AP_DOMAINS );if (do_remove) vfio_ap_mdev_hot_unplug_cfg(matrix_mdev, aprem, aqrem,
Greg Kroah-Hartman
maintainerPATCH 320/1191 s390/vfio-ap: Fix hot-unplug skipped when last AP adapter or domain removed
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 917f509bfb88048094dbb85c4e9dbc4d6fe4a886 upstream.
The vfio_ap_mdev_hot_unplug_cfg() function uses the return value of bitmap_andnot() to determine whether the guest APCB needs to be updated. However, bitmap_andnot() returns false when the resulting destination bitmap is empty. This means that if the only adapter, domain or control domain assigned to an mdev is removed from the host's AP configuration, the bit is correctly cleared from the shadow APCB, but bitmap_andnot() returns false because the result is an empty bitmap. Consequently, do_hotplug remains 0 and vfio_ap_mdev_update_guest_apcb() is never called, leaving the KVM guest with stale hardware access to the unplugged AP devices.
Fix this by replacing the bitmap_andnot() return value check with bitmap_intersects() to determine whether the shadow APCB actually overlaps with the removal mask. If there is an intersection, call bitmap_andnot() solely for its side effect of clearing the bits, then unconditionally set do_hotplug to trigger the guest APCB update.
--- drivers/s390/crypto/vfio_ap_ops.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +17 -13
@@ -1988,24 +1988,28 @@ static void vfio_ap_mdev_hot_unplug_cfg(unsigned long *aqrem, unsigned long *cdrem) { - int do_hotplug = 0; + bool do_hotplug = false; -if (!bitmap_empty (aprem,AP_DEVICES )) { - do_hotplug |=bitmap_andnot (matrix_mdev->shadow_apcb.apm, - matrix_mdev->shadow_apcb.apm, - aprem,AP_DEVICES ); +if (bitmap_intersects (matrix_mdev->shadow_apcb.apm, aprem,AP_DEVICES )) { +bitmap_andnot (matrix_mdev->shadow_apcb.apm, + matrix_mdev->shadow_apcb.apm, + aprem,AP_DEVICES ); + do_hotplug = true; } -if (!bitmap_empty (aqrem,AP_DOMAINS )) { - do_hotplug |=bitmap_andnot (matrix_mdev->shadow_apcb.aqm, - matrix_mdev->shadow_apcb.aqm, - aqrem,AP_DEVICES ); +if (bitmap_intersects (matrix_mdev->shadow_apcb.aqm, aqrem,AP_DOMAINS )) { +bitmap_andnot (matrix_mdev->shadow_apcb.aqm, + matrix_mdev->shadow_apcb.aqm, + aqrem,AP_DOMAINS ); + do_hotplug = true; } -if (!bitmap_empty (cdrem,AP_DOMAINS )) - do_hotplug |=bitmap_andnot (matrix_mdev->shadow_apcb.adm, - matrix_mdev->shadow_apcb.adm, - cdrem,AP_DOMAINS ); +if (bitmap_intersects (matrix_mdev->shadow_apcb.adm, cdrem,AP_DOMAINS )) { +bitmap_andnot (matrix_mdev->shadow_apcb.adm, + matrix_mdev->shadow_apcb.adm, + cdrem,AP_DOMAINS ); + do_hotplug = true; + }if (do_hotplug)vfio_ap_mdev_update_guest_apcb (matrix_mdev);
Greg Kroah-Hartman
maintainerPATCH 321/1191 s390/vfio-ap: Fix required lock not held during update of ap_matrix_mdev object
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 5883528250be57fa92270459b33603ff52de0a91 upstream.
In the vfio_ap_mdev_cfg_add function, the apm_add, aqm_add and adm_add fields of an ap_matrix_mdev object fields are modified while not holding the matrix_dev->mdevs_lock. This lock must be held while making these to guard against a race condition with another caller that may be concurrently modifying these fields or any of the fields in the matrix_mdev->matrix.
--- drivers/s390/crypto/vfio_ap_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +8 -0
@@ -2184,12 +2184,20 @@ static void vfio_ap_mdev_cfg_add(unsignevfio_ap_filter_apid_by_qtype (apm_add, aqm_add);list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) { +/* +* The mdevs_lock must be held in order to access fields +* within matrix_mdev +*/ +mutex_lock (&matrix_dev->mdevs_lock); +bitmap_and (matrix_mdev->apm_add, matrix_mdev->matrix.apm, apm_add,AP_DEVICES );bitmap_and (matrix_mdev->aqm_add, matrix_mdev->matrix.aqm, aqm_add,AP_DOMAINS );bitmap_and (matrix_mdev->adm_add, matrix_mdev->matrix.adm, adm_add,AP_DEVICES ); + +mutex_unlock (&matrix_dev->mdevs_lock); } }
Greg Kroah-Hartman
maintainerPATCH 322/1191 mtd: afs: validate v2 image info bounds
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit e9290031f736e99ad17c25c00311c92c266843b7 upstream.
The AFS v2 parser uses footer[8] to locate the image information block inside the current erase block, then uses the image information region_count to walk entries from a fixed local array. The footer offset and region count come from flash contents and are not checked against the erase block or the local image-info array before use.
Reject v2 entries whose image information offset would underflow the erase block calculation, and reject region counts that cannot fit in the local image-info array before walking region entries.
--- drivers/mtd/parsers/afs.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mtd/parsers/afs.c +7 -0
@@ -235,6 +235,9 @@ static int afs_parse_v2_partition(structpr_debug ("Parsing v2 partition @%08x-%08x\n" , off, off + mtd->erasesize); +if (mtd->erasesize <sizeof (footer)) +return -EINVAL ; +/* First read the footer */ ptr = off + mtd->erasesize -sizeof (footer); ret =mtd_read (mtd, ptr,sizeof (footer), &sz, (u_char *)footer);
@@ -245,6 +248,8 @@ static int afs_parse_v2_partition(struct } name = (char *) &footer[0 ]; version = footer[9 ]; +if (footer[8 ] > mtd->erasesize -sizeof (footer)) +return -EINVAL ; ptr = off + mtd->erasesize -sizeof (footer) - footer[8 ]; pr_debug("found image \"%s\", version %08x, info @%08x\n",
@@ -278,6 +283,8 @@ static int afs_parse_v2_partition(struct entrypoint = imginfo[pad]; attributes = imginfo[pad+1 ]; region_count = imginfo[pad+2 ]; +if (region_count > (ARRAY_SIZE (imginfo) - pad -3 ) /4 ) +return -EINVAL ; block_start = imginfo[20 ]; block_end = imginfo[21 ];
Greg Kroah-Hartman
maintainerPATCH 323/1191 mtd: mtdoops: free page bitmap when the backing MTD is removed
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 956e7da12c114f13c63d126ab1d79c3b6a819060 upstream.
mtdoops_notify_add() allocates oops_page_used when the configured MTD device is registered. mtdoops_notify_remove() detaches from that device but leaves the bitmap allocated. If the same MTD device is later registered again, the add path allocates a new bitmap and overwrites the old pointer, leaking one vmalloc allocation per remove/add cycle.
This is only visible when the backing MTD device can disappear and be registered again while mtdoops remains loaded, so the usual static MTD case does not expose it.
Free the bitmap after unregistering the dumper and flushing the pending workers, then clear the pointer and page count before a later attach can allocate fresh state. Clearing the pointer also keeps the module exit path from freeing the same bitmap a second time after a remove event.
--- drivers/mtd/mtdoops.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/mtdoops.c +3 -0
@@ -378,6 +378,9 @@ static void mtdoops_notify_remove(struct cxt->mtd =NULL ;flush_work (&cxt->work_erase);flush_work (&cxt->work_write); +vfree (cxt->oops_page_used); + cxt->oops_page_used =NULL ; + cxt->oops_pages =0 ; }
Greg Kroah-Hartman
maintainerPATCH 324/1191 mtd: rawnand: validate ONFI extended parameter page sections
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit e5e415262330bd70f983e091d8919d9dcd99e475 upstream.
nand_flash_detect_ext_param_page() allocates the length declared by the ONFI parameter page, then treats the data as a fixed header followed by variable-length sections. It reads that header and advances over sections without first proving that the fixed page and each current section fit in the allocation.
Reject pages shorter than the fixed header, track the remaining variable area while walking sections, and require the ECC section to contain every field read from struct onfi_ext_ecc_info. Use device-scoped diagnostics that identify the malformed ONFI section.
--- drivers/mtd/nand/raw/nand_onfi.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/nand_onfi.c +25 -2
@@ -35,16 +35,21 @@ static int nand_flash_detect_ext_param_p struct nand_onfi_params *p) {struct nand_device *base = &chip->base; +struct mtd_info *mtd =nand_to_mtd (chip);struct nand_ecc_props requirements;struct onfi_ext_param_page *ep;struct onfi_ext_section *s;struct onfi_ext_ecc_info *ecc; +size_t remaining, section_len;uint8_t *cursor;int ret;int len;int i; len =le16_to_cpu (p->ext_param_page_length) *16 ; +if (len <sizeof (*ep)) +return -EINVAL ; + ep =kmalloc (len,GFP_KERNEL );if (!ep)return -ENOMEM ;
@@ -77,11 +82,29 @@ static int nand_flash_detect_ext_param_p/* find the ECC section. */ cursor = (uint8_t *)(ep +1 ); + remaining = len -sizeof (*ep);for (i =0 ; i <ONFI_EXT_SECTION_MAX ; i++) { s = ep->sections + i; -if (s->type ==ONFI_SECTION_TYPE_2 ) + section_len = s->length *16 ; +if (section_len > remaining) { +dev_dbg (&mtd->dev, +"ONFI extended parameter section %d exceeds page\n" , + i); + goto ext_out; + } + +if (s->type ==ONFI_SECTION_TYPE_2 ) { +if (section_len <sizeof (*ecc)) { +dev_dbg (&mtd->dev, +"ONFI extended parameter ECC section %d is too short\n" , + i); + goto ext_out; + }break ; - cursor += s->length *16 ; + } + + cursor += section_len; + remaining -= section_len; }if (i ==ONFI_EXT_SECTION_MAX ) {pr_debug ("We can not find the ECC section.\n" );
Greg Kroah-Hartman
maintainerPATCH 325/1191 batman-adv: fix stale receive device on merged fragments
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
commit ad46c907d7d9975a285c1e89a4adde652eaa93f5 upstream.
Fragment reassembly reuses the skb from the highest-numbered buffered fragment as the merged packet. When that fragment was received on a hard interface which is deleted before the chain completes, the merged skb can re-enter the receive path with a stale skb->dev and skb_iif.
batadv_batman_skb_recv() passes such merged packets through the normal receive handlers again. DAT and bridge loop avoidance both derive the ARP header length from skb->dev, so they can dereference the freed net_device before the packet reaches the local mesh interface.
Refresh the receive device metadata from the current receive device before running the packet handlers. This keeps internally reinjected merged fragments consistent with the normal receive path after hard interface teardown.
--- net/batman-adv/main.c | 4 ++++ 1 file changed, 4 insertions(+)
net/batman-adv/main.c +4 -0
@@ -457,6 +457,10 @@ int batadv_batman_skb_recv(struct sk_bufif (!skb) goto err_put; +/* Merged fragments re-enter here with reused skb metadata. */ + skb->dev = dev; + skb->skb_iif = dev->ifindex; +/* packet should hold at least type and version */ if (unlikely (!pskb_may_pull (skb,2 ))) goto err_free;
Greg Kroah-Hartman
maintainerPATCH 326/1191 batman-adv: dat: avoid unaligned fault in IP extraction
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 0121afa52cdb88cfb4d5d7bd126a23a9100121d8 upstream.
Independent of the alignment of the ARP packet in the SKB, either the batadv_arp_ip_src or the batadv_arp_ip_dst will have an unaligned access (on HW without native unaligned read support).
Use get_unaligned() to handle this properly on all architectures.
--- net/batman-adv/distributed-arp-table.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/batman-adv/distributed-arp-table.c +6 -2
@@ -250,7 +250,10 @@ static u8 *batadv_arp_hw_src(struct sk_b*/ static __be32 batadv_arp_ip_src (struct sk_buff *skb,int hdr_size) { -return *(__force __be32 *)(batadv_arp_hw_src (skb, hdr_size) +ETH_ALEN ); +u8 *src =batadv_arp_hw_src (skb, hdr_size) +ETH_ALEN ; +__be32 *ip = (__force __be32 *)src; + +return get_unaligned (ip); }/**
@@ -275,8 +278,9 @@ static u8 *batadv_arp_hw_dst(struct sk_bstatic __be32 batadv_arp_ip_dst (struct sk_buff *skb,int hdr_size) {u8 *dst =batadv_arp_hw_src (skb, hdr_size) +ETH_ALEN *2 +4 ; +__be32 *ip = (__force __be32 *)dst; -return *(__force __be32 *)dst; +return get_unaligned (ip); }/**
Greg Kroah-Hartman
maintainerPATCH 327/1191 batman-adv: bla: fix freeing of claims on meshif deletion
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 8d128c932bced74e3b1625ba3d7c78ef122a88a7 upstream.
When the mesh interface is getting deleted, then batadv_bla_del_backbone_claims() (via batadv_bla_purge_backbone_gw()) could make sure that all claims gets removed. But this function is only executed when bat_priv->bla.claim_hash is not NULL. And since batadv_bla_free() is always setting it to NULL before it is (indirectly) called, it was never actually executed.
But the batadv_bla_purge_claims() -> batadv_handle_unclaim() is at the moment too fragile because the BLA code is not handling the rehashing in batadv_bla_update_orig_address(). The stored backbone address doesn't have to be the one actually used for the hash bucket selection during the initial adding of the backbone. The batadv_handle_unclaim() can therefore fail to find the respective backbone for the unclaim and then stop the deletion.
But the actual backbone_gw object is not needed for the unclaim because all relevant information is always provided by the caller. And the check for the existence of the backbone_gw doesn't provide any additional security check for the deletion of a claim.
--- net/batman-adv/bridge_loop_avoidance.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +1 -9
@@ -941,26 +941,18 @@ static bool batadv_handle_unclaim(struct const u8 *backbone_addr, const u8 *claim_addr, unsigned short vid) { - struct batadv_bla_backbone_gw *backbone_gw; - /* unclaim in any case if it is our own */ if (primary_if && batadv_compare_eth(backbone_addr, primary_if->net_dev->dev_addr)) batadv_bla_send_claim(bat_priv, claim_addr, vid, BATADV_CLAIM_TYPE_UNCLAIM); - backbone_gw =batadv_backbone_hash_find (bat_priv, backbone_addr, vid); - -if (!backbone_gw) -return true; -/* this must be an UNCLAIM frame */ batadv_dbg (BATADV_DBG_BLA , bat_priv,"%s(): UNCLAIM %pM on vid %d (sent by %pM)...\n" , __func__, - claim_addr,batadv_print_vid (vid), backbone_gw->orig); + claim_addr,batadv_print_vid (vid), backbone_addr);batadv_bla_del_claim (bat_priv, claim_addr, vid); -batadv_backbone_gw_put (backbone_gw);return true; }
Greg Kroah-Hartman
maintainerPATCH 328/1191 batman-adv: bla: prevent CRC corruptions after claim flush
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 89f3502ff6878798be96461b2eebd64ba3c3874c upstream.
When batadv_bla_del_backbone_claims() tried to remove all claims of a backbone, it sets the CRC to 0. It assumes that the it had the last reference of the claims because batadv_claim_release() (which runs after the last reference was released), is XORing the crc16 of the claim address with the backbone CRC.
If there would be a parallel holder of any of these references, it could happen that the backbone CRC is (0 ^ crc16(delayed_released_claim)). Which is the wrong starting point for the new claims it may receive when the remote answers the claim request from batadv_bla_send_request().
This reinitializations can be completely dropped to avoid this problem. batadv_claim_release() will take care of fixing the backbone CRC.
--- net/batman-adv/bridge_loop_avoidance.c | 5 ----- 1 file changed, 5 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +0 -5
@@ -323,11 +323,6 @@ batadv_bla_del_backbone_claims(struct ba }spin_unlock_bh (list_lock); } - -/* all claims gone, initialize CRC */ -spin_lock_bh (&backbone_gw->crc_lock); - backbone_gw->crc =BATADV_BLA_CRC_INIT ; -spin_unlock_bh (&backbone_gw->crc_lock); }/**
Greg Kroah-Hartman
maintainerPATCH 329/1191 clk: qcom: gcc-msm8916: Fix enable_reg for gcc_blsp1_sleep_clk
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit c5339edc6abb601ea10df910ea0b1592fa1016f3 upstream.
According to the APQ8016E TRM, the GCC_BLSP1_SLEEP_CBCR register is read-only and only has the CLK_OFF bit to check if the clock is running. This is a shared vote clock, the correct way to enable it is to vote for BLSP1_SLEEP_CLK_ENA (BIT(9)) in GCC_APCS_CLOCK_BRANCH_ENA_VOTE (0x45004).
--- drivers/clk/qcom/gcc-msm8916.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-msm8916.c +3 -2
@@ -1590,9 +1590,10 @@ static struct clk_branch gcc_blsp1_ahb_cstatic struct clk_branch gcc_blsp1_sleep_clk = { .halt_reg =0x01004 , + .halt_check =BRANCH_HALT_VOTED , .clkr = { - .enable_reg =0x01004 , - .enable_mask =BIT (0 ), + .enable_reg =0x45004 , + .enable_mask =BIT (9 ), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_sleep_clk" , .parent_data = &(const struct clk_parent_data ){
Greg Kroah-Hartman
maintainerPATCH 330/1191 clk: qcom: gcc-msm8939: Fix enable_reg for gcc_blsp1_sleep_clk
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit fc611445b021262b0d4ace6f716a360663816287 upstream.
MSM8939 is similar to MSM8916, where the GCC_BLSP1_SLEEP_CBCR register is read-only and only has the CLK_OFF bit to check if the clock is running. This is a shared vote clock, the correct way to enable it is to vote for BLSP1_SLEEP_CLK_ENA (BIT(9)) in GCC_APCS_CLOCK_BRANCH_ENA_VOTE (0x45004).
--- drivers/clk/qcom/gcc-msm8939.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-msm8939.c +3 -2
@@ -1882,9 +1882,10 @@ static struct clk_branch gcc_blsp1_ahb_cstatic struct clk_branch gcc_blsp1_sleep_clk = { .halt_reg =0x01004 , + .halt_check =BRANCH_HALT_VOTED , .clkr = { - .enable_reg =0x01004 , - .enable_mask =BIT (0 ), + .enable_reg =0x45004 , + .enable_mask =BIT (9 ), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_sleep_clk" , .ops = &clk_branch2_ops,
Greg Kroah-Hartman
maintainerPATCH 331/1191 clk: qcom: gcc-mdm9607: Drop incorrect apss_tcu_clk_src
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit 38d06956f60675f906dc3f5b70b3b52103b86a7d upstream.
This clock does not exist on the specified address on MDM9607. Reading/writing the registers always results in 0 or crashes. The math in the frequency table is also broken. GPLL2 on MDM9607 runs at 480 MHz, so:
- F(155000000, P_GPLL2, 6, 0, 0), // 480 MHz/6 = 80 MHz, not 155 MHz
- F(310000000, P_GPLL2, 3, 0, 0), // 480 MHz/3 = 160 MHz, not 310 MHz
Presumably, this definition was mistakenly copied as-is from gcc-msm8916 (which uses 930 MHz for GPLL2). There are no branch consumers of this root clock inside gcc-mdm9607 (notably, gcc_apss_tcu_clk has bimc_ddr_clk_src as parent instead of this clock), so we can just drop it.
It seems like this clock does exist on this SoC on a different address, but since there is no user and reference code for it, it is still better to drop it.
--- drivers/clk/qcom/gcc-mdm9607.c | 35 ----------------------------------- 1 file changed, 35 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +0 -35
@@ -159,20 +159,6 @@ static const struct clk_parent_data gcc_ { .hw = &gpll2.clkr.hw }, }; -static const struct parent_map gcc_xo_gpll0_gpll1_gpll2_map[] = { - {P_XO ,0 }, - {P_GPLL0 ,1 }, - {P_GPLL1 ,2 }, - {P_GPLL2 ,3 }, -}; - -static const struct clk_parent_data gcc_xo_gpll0_gpll1_gpll2[] = { - { .fw_name ="xo" }, - { .hw = &gpll0.clkr.hw }, - { .hw = &gpll1_vote.hw }, - { .hw = &gpll2.clkr.hw }, -}; -static const struct freq_tbl ftbl_apss_ahb_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (50000000 ,P_GPLL0 ,16 ,0 ,0 ),
@@ -675,26 +661,6 @@ static struct clk_rcg2 sdcc2_apps_clk_sr }, }; -static const struct freq_tbl ftbl_gcc_apss_tcu_clk[] = { -F (155000000 ,P_GPLL2 ,6 ,0 ,0 ), -F (310000000 ,P_GPLL2 ,3 ,0 ,0 ), -F (400000000 ,P_GPLL0 ,2 ,0 ,0 ), - { } -}; - -static struct clk_rcg2 apss_tcu_clk_src = { - .cmd_rcgr =0x1207c , - .hid_width =5 , - .parent_map = gcc_xo_gpll0_gpll1_gpll2_map, - .freq_tbl = ftbl_gcc_apss_tcu_clk, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="apss_tcu_clk_src" , - .parent_data = gcc_xo_gpll0_gpll1_gpll2, - .num_parents =4 , - .ops = &clk_rcg2_ops, - }, -}; -static const struct freq_tbl ftbl_gcc_usb_hs_system_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (57140000 ,P_GPLL0 ,14 ,0 ,0 ),
@@ -1512,7 +1478,6 @@ static struct clk_regmap *gcc_mdm9607_cl [PDM2_CLK_SRC] = &pdm2_clk_src.clkr, [SDCC1_APPS_CLK_SRC] = &sdcc1_apps_clk_src.clkr, [SDCC2_APPS_CLK_SRC] = &sdcc2_apps_clk_src.clkr, - [APSS_TCU_CLK_SRC] = &apss_tcu_clk_src.clkr, [USB_HS_SYSTEM_CLK_SRC] = &usb_hs_system_clk_src.clkr, [GCC_BLSP1_AHB_CLK] = &gcc_blsp1_ahb_clk.clkr, [GCC_BLSP1_SLEEP_CLK] = &gcc_blsp1_sleep_clk.clkr,
Greg Kroah-Hartman
maintainerPATCH 332/1191 clk: qcom: gcc-mdm9607: Drop incorrect system_noc_bfdcd_clk_src
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit 17784427df923a0573a7ea83f9198456ff1ec1a5 upstream.
This clock does not exist on MDM9607. Reading/writing the registers always results in 0.
Presumably, this definition was mistakenly copied from gcc-msm8916. On MSM8916, this root clock is used for multimedia subsystems (camera, display, video). MDM9607 has none of that, so this clock was probably omitted in the hardware.
There are no users inside gcc-mdm9607, so we can just drop it.
--- drivers/clk/qcom/gcc-mdm9607.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +0 -13
@@ -241,18 +241,6 @@ static struct clk_rcg2 pcnoc_bfdcd_clk_s }, }; -static struct clk_rcg2 system_noc_bfdcd_clk_src = { - .cmd_rcgr =0x26004 , - .hid_width =5 , - .parent_map = gcc_xo_gpll0_bimc_map, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="system_noc_bfdcd_clk_src" , - .parent_data = gcc_xo_gpll0_bimc, - .num_parents =ARRAY_SIZE (gcc_xo_gpll0_bimc), - .ops = &clk_rcg2_ops, - }, -}; -static const struct freq_tbl ftbl_gcc_blsp1_qup1_6_i2c_apps_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (50000000 ,P_GPLL0 ,16 ,0 ,0 ),
@@ -1451,7 +1439,6 @@ static struct clk_regmap *gcc_mdm9607_cl [BIMC_PLL_VOTE] = &bimc_pll_vote, [BIMC_DDR_CLK_SRC] = &bimc_ddr_clk_src.clkr, [PCNOC_BFDCD_CLK_SRC] = &pcnoc_bfdcd_clk_src.clkr, - [SYSTEM_NOC_BFDCD_CLK_SRC] = &system_noc_bfdcd_clk_src.clkr, [APSS_AHB_CLK_SRC] = &apss_ahb_clk_src.clkr, [BLSP1_QUP1_I2C_APPS_CLK_SRC] = &blsp1_qup1_i2c_apps_clk_src.clkr, [BLSP1_QUP1_SPI_APPS_CLK_SRC] = &blsp1_qup1_spi_apps_clk_src.clkr,
Greg Kroah-Hartman
maintainerPATCH 333/1191 clk: qcom: gcc-mdm9607: Fix enable_reg for gcc_blsp1_sleep_clk
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit 944d0fb38cffe57a1d1ebf82c5c077bad82dcdbb upstream.
MDM9607 is similar to MSM8909, where the GCC_BLSP1_SLEEP_CBCR register is read-only and only has the CLK_OFF bit to check if the clock is running. This is a shared vote clock, the correct way to enable it is to vote for BLSP1_SLEEP_CLK_ENA (BIT(9)) in GCC_APCS_CLOCK_BRANCH_ENA_VOTE (0x45004).
--- drivers/clk/qcom/gcc-mdm9607.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +3 -2
@@ -745,9 +745,10 @@ static struct clk_branch gcc_blsp1_ahb_cstatic struct clk_branch gcc_blsp1_sleep_clk = { .halt_reg =0x1004 , + .halt_check =BRANCH_HALT_VOTED , .clkr = { - .enable_reg =0x1004 , - .enable_mask =BIT (0 ), + .enable_reg =0x45004 , + .enable_mask =BIT (9 ), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_sleep_clk" , .parent_data = &(const struct clk_parent_data ){
Greg Kroah-Hartman
maintainerPATCH 334/1191 clk: qcom: gcc-mdm9607: Fix halt_reg for gcc_apss_axi_clk
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit ca7e6cc30cde4f0cbeff2e205a84bedf431e9156 upstream.
gcc_apss_axi_clk specifies a halt_reg of 0x4601c, but this is already used by gcc_apss_ahb_clk. The correct value according to the downstream driver is 0x46020.
--- drivers/clk/qcom/gcc-mdm9607.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/gcc-mdm9607.c +1 -1
@@ -1415,7 +1415,7 @@ static struct clk_branch gcc_apss_ahb_cl };static struct clk_branch gcc_apss_axi_clk = { - .halt_reg =0x4601c , + .halt_reg =0x46020 , .halt_check =BRANCH_HALT_VOTED , .clkr = { .enable_reg =0x45004 ,
Greg Kroah-Hartman
maintainerPATCH 335/1191 clk: qcom: gcc-mdm9607: Drop incorrect BIMC PLL and related clocks
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit e111ddda092ad961870a634e4c9263c10a3e8485 upstream.
The gcc-mdm9607 driver was originally based on gcc-msm8916, but a closer match nowadays is gcc-msm8909. Looking at the differences between gcc-mdm9607 and gcc-msm8909, there is quite some confusion around the definitions for the BIMC PLL.
It turns out the BIMC PLL on MDM9607 is actually an Alpha PLL just like on MSM8909. We can vote for it using BIT(2), which explains why BIT(3) was used for GPLL2.
In practice, the BIMC PLL is exclusively controlled by the RPM firmware and Linux should not touch it. So far, it was defined to model the full clock hierarchy, but even in read-only mode with CLK_GET_RATE_NOCACHE this is problematic since the RPM will silently change the clock parents without notifying Linux about it. The clock framework reads the clock parent only once during boot, so the resulting rates will still be often wrong.
Follow the example of more recent SoCs and drop the BIMC PLL and all remaining related clocks to avoid reporting stale status data. This means we cannot determine the rate of these clocks anymore. This is not a big problem in practice, since these are NoC-related clocks that are independently managed through the interconnect subsystem.
--- drivers/clk/qcom/gcc-mdm9607.c | 125 ----------------------------------------- 1 file changed, 1 insertion(+), 124 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +1 -124
@@ -27,7 +27,6 @@enum {P_XO , -P_BIMC ,P_GPLL0 ,P_GPLL1 ,P_GPLL2 ,
@@ -122,7 +121,7 @@ static struct clk_alpha_pll gpll2_early .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT], .clkr = { .enable_reg = 0x45000, - .enable_mask = BIT(3), /* Yeah, apparently it's not 2 */ + .enable_mask = BIT(3), /* BIT(2) is used for BIMC PLL */ .hw.init = &(struct clk_init_data) { .name = "gpll2_early",
@@ -179,68 +178,6 @@ static struct clk_rcg2 apss_ahb_clk_src }, }; -static struct clk_pll bimc_pll = { - .l_reg =0x23004 , - .m_reg =0x23008 , - .n_reg =0x2300c , - .config_reg =0x23010 , - .mode_reg =0x23000 , - .status_reg =0x2301c , - .status_bit =17 , - .clkr.hw.init = &(struct clk_init_data ){ - .name ="bimc_pll" , - .parent_data = &(const struct clk_parent_data ){ - .fw_name ="xo" , - }, - .num_parents =1 , - .ops = &clk_pll_ops, - }, -}; - -static struct clk_regmap bimc_pll_vote = { - .enable_reg =0x45000 , - .enable_mask =BIT (3 ), - .hw.init = &(struct clk_init_data ){ - .name ="bimc_pll_vote" , - .parent_hws = (const struct clk_hw *[]){ &bimc_pll.clkr.hw }, - .num_parents =1 , - .ops = &clk_pll_vote_ops, - }, -}; - -static const struct parent_map gcc_xo_gpll0_bimc_map[] = { - {P_XO ,0 }, - {P_GPLL0 ,1 }, - {P_BIMC ,2 }, -}; - -static const struct clk_parent_data gcc_xo_gpll0_bimc[] = { - { .fw_name ="xo" }, - { .hw = &gpll0.clkr.hw }, - { .hw = &bimc_pll_vote.hw }, -}; - -static const struct freq_tbl ftbl_pcnoc_bfdcd_clk_src[] = { -F (19200000 ,P_XO ,1 ,0 ,0 ), -F (50000000 ,P_GPLL0 ,16 ,0 ,0 ), -F (100000000 ,P_GPLL0 ,8 ,0 ,0 ), - { } -}; - -static struct clk_rcg2 pcnoc_bfdcd_clk_src = { - .cmd_rcgr =0x27000 , - .freq_tbl = ftbl_pcnoc_bfdcd_clk_src, - .hid_width =5 , - .parent_map = gcc_xo_gpll0_bimc_map, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="pcnoc_bfdcd_clk_src" , - .parent_data = gcc_xo_gpll0_bimc, - .num_parents =ARRAY_SIZE (gcc_xo_gpll0_bimc), - .ops = &clk_rcg2_ops, - .flags =CLK_IS_CRITICAL , - }, -}; -static const struct freq_tbl ftbl_gcc_blsp1_qup1_6_i2c_apps_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (50000000 ,P_GPLL0 ,16 ,0 ,0 ),
@@ -736,8 +673,6 @@ static struct clk_branch gcc_blsp1_ahb_c .enable_mask = BIT(10), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1039,8 +974,6 @@ static struct clk_branch gcc_boot_rom_ah .enable_mask = BIT(7), .hw.init = &(struct clk_init_data ){ .name ="gcc_boot_rom_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1054,9 +987,6 @@ static struct clk_branch gcc_crypto_ahb_ .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_crypto_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1070,9 +1000,6 @@ static struct clk_branch gcc_crypto_axi_ .enable_mask = BIT(1), .hw.init = &(struct clk_init_data ){ .name ="gcc_crypto_axi_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1146,9 +1073,6 @@ static struct clk_branch gcc_mss_cfg_ahb .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_mss_cfg_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1176,9 +1100,6 @@ static struct clk_branch gcc_pdm_ahb_clk .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_pdm_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1192,9 +1113,6 @@ static struct clk_branch gcc_prng_ahb_cl .enable_mask = BIT(8), .hw.init = &(struct clk_init_data ){ .name ="gcc_prng_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1207,9 +1125,6 @@ static struct clk_branch gcc_sdcc1_ahb_c .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_sdcc1_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1237,9 +1152,6 @@ static struct clk_branch gcc_sdcc2_ahb_c .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_sdcc2_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1260,19 +1172,6 @@ static struct clk_branch gcc_sdcc2_apps_ }, }; -static struct clk_rcg2 bimc_ddr_clk_src = { - .cmd_rcgr =0x32004 , - .hid_width =5 , - .parent_map = gcc_xo_gpll0_bimc_map, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="bimc_ddr_clk_src" , - .parent_data = gcc_xo_gpll0_bimc, - .num_parents =3 , - .ops = &clk_rcg2_ops, - .flags =CLK_GET_RATE_NOCACHE , - }, -}; -static struct clk_branch gcc_mss_q6_bimc_axi_clk = { .halt_reg =0x49004 , .clkr = {
@@ -1280,9 +1179,6 @@ static struct clk_branch gcc_mss_q6_bimc .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_mss_q6_bimc_axi_clk" , - .parent_hws = (const struct clk_hw *[]){ &bimc_ddr_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1296,8 +1192,6 @@ static struct clk_branch gcc_apss_tcu_cl .enable_mask = BIT(1), .hw.init = &(struct clk_init_data ){ .name ="gcc_apss_tcu_clk" , - .parent_hws = (const struct clk_hw *[]){ &bimc_ddr_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1311,9 +1205,6 @@ static struct clk_branch gcc_smmu_cfg_cl .enable_mask = BIT(12), .hw.init = &(struct clk_init_data ){ .name ="gcc_smmu_cfg_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1361,9 +1252,6 @@ static struct clk_branch gcc_usb_hs_phy_ .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_usb_hs_phy_cfg_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1376,9 +1264,6 @@ static struct clk_branch gcc_usb_hs_ahb_ .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_usb_hs_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1407,8 +1292,6 @@ static struct clk_branch gcc_apss_ahb_cl .enable_mask = BIT(14), .hw.init = &(struct clk_init_data ){ .name ="gcc_apss_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1422,8 +1305,6 @@ static struct clk_branch gcc_apss_axi_cl .enable_mask = BIT(13), .hw.init = &(struct clk_init_data ){ .name ="gcc_apss_axi_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1436,10 +1317,6 @@ static struct clk_regmap *gcc_mdm9607_cl [GPLL1_VOTE] = &gpll1_vote, [GPLL2] = &gpll2.clkr, [GPLL2_EARLY] = &gpll2_early.clkr, - [BIMC_PLL] = &bimc_pll.clkr, - [BIMC_PLL_VOTE] = &bimc_pll_vote, - [BIMC_DDR_CLK_SRC] = &bimc_ddr_clk_src.clkr, - [PCNOC_BFDCD_CLK_SRC] = &pcnoc_bfdcd_clk_src.clkr, [APSS_AHB_CLK_SRC] = &apss_ahb_clk_src.clkr, [BLSP1_QUP1_I2C_APPS_CLK_SRC] = &blsp1_qup1_i2c_apps_clk_src.clkr, [BLSP1_QUP1_SPI_APPS_CLK_SRC] = &blsp1_qup1_spi_apps_clk_src.clkr,
Greg Kroah-Hartman
maintainerPATCH 336/1191 i2c: mux: demux-pinctrl: fix OF node leak on kstrdup failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 62edb8ca0aa44517cc23cfa26cd8a51f15ea92fe upstream.
of_parse_phandle() takes a reference on the parent node. If a later devm_kstrdup() fails, err_rollback only releases nodes for indices 0..i-1, so the current node is leaked.
of_node_put() the current parent before rolling back.
--- drivers/i2c/muxes/i2c-demux-pinctrl.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/muxes/i2c-demux-pinctrl.c +1 -0
@@ -245,6 +245,7 @@ static int i2c_demux_pinctrl_probe(struc props[i].value =devm_kstrdup (&pdev->dev,"ok" ,GFP_KERNEL );if (!props[i].name || !props[i].value) { err = -ENOMEM ; +of_node_put (adap_np); goto err_rollback; } props[i].length =3 ;
Greg Kroah-Hartman
maintainerPATCH 337/1191 ASoC: cs35l33: drain threaded IRQ before runtime suspend
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit e074c12c428c633e079154301207a6079a208583 upstream.
cs35l33_runtime_suspend() currently switches the codec into regcache_cache_only(true) and powers it down without first quiescing the threaded IRQ registered by devm_request_threaded_irq(). That leaves a window where cs35l33_irq_thread() can still run after suspend has closed off live register access.
A running system can reach this during runtime PM while the driver still has critical fault IRQs unmasked. If the threaded handler runs in that window, it reads volatile INT_STATUS_1/2 after cache_only has been enabled, ignores the regmap_read() failures, and can still drive the AMP_SHORT_RLS, CAL_ERR_RLS, OTE_RLS, and OTW_RLS release paths.
Use disable_irq() before entering cache_only/power-off so any in-flight threaded handler is drained and no new IRQ thread can run during the suspended state. Re-enable the IRQ only after runtime_resume() has restored live register access with regcache_sync(). Since probe only warns if devm_request_threaded_irq() fails, track whether the IRQ was actually installed before disabling or re-enabling it.
--- sound/soc/codecs/cs35l33.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
sound/soc/codecs/cs35l33.c +12 -2
@@ -42,6 +42,7 @@ struct cs35l33_private {struct regmap *regmap;struct gpio_desc *reset_gpio;bool amp_cal; +bool irq_requested;int mclk_int;struct regulator_bulk_data core_supplies[2 ];int num_core_supplies;
@@ -883,6 +884,9 @@ static int __maybe_unused cs35l33_runtim goto err; } +if (cs35l33->irq_requested) +enable_irq (to_i2c_client (dev)->irq); +return 0 ; err:
@@ -902,6 +906,10 @@ static int __maybe_unused cs35l33_runtim/* redo the calibration in next power up */ cs35l33->amp_cal = false; +/* Drain and block the threaded IRQ before cache_only/power-off. */ +if (cs35l33->irq_requested) +disable_irq (to_i2c_client (dev)->irq); +regcache_cache_only (cs35l33->regmap, true);regcache_mark_dirty (cs35l33->regmap); regulator_bulk_disable(cs35l33->num_core_supplies,
@@ -1158,10 +1166,12 @@ static int cs35l33_i2c_probe(struct i2c_ } ret =devm_request_threaded_irq (&i2c_client->dev, i2c_client->irq,NULL , - cs35l33_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -"cs35l33" , cs35l33); + cs35l33_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , +"cs35l33" , cs35l33);if (ret !=0 )dev_warn (&i2c_client->dev,"Failed to request IRQ: %d\n" , ret); +else + cs35l33->irq_requested = true;/* We could issue !RST or skip it based on AMP topology */ cs35l33->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
Greg Kroah-Hartman
maintainerPATCH 338/1191 ASoC: cs35l34: drain threaded IRQ before runtime suspend
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 4105a4c0678b2808fc8046b60321b4f1cc7dae75 upstream.
cs35l34_runtime_suspend() currently switches the codec into regcache_cache_only(true), asserts reset low, and powers the device off without first quiescing the threaded IRQ registered by devm_request_threaded_irq(). That leaves a window where cs35l34_irq_thread() can still run after suspend has removed live hardware access.
A running system can reach this during runtime PM while the driver still has critical fault IRQs unmasked. If the threaded handler runs in that window, it reads volatile INT_STATUS_1..4 after cache_only has been enabled, ignores the regmap_read() failures, and can still execute the PROT_RELEASE_CTL release sequence or the BST fault power-down writes.
Use disable_irq() before entering cache_only/reset-low/power-off so any in-flight threaded handler is drained and no new IRQ thread can run while the device is suspended. Re-enable the IRQ only after runtime_resume() has restored live register access with regcache_sync(). Since probe only logs request_threaded_irq() failures and keeps going, track whether the IRQ was actually installed before disabling or re-enabling it.
--- sound/soc/codecs/cs35l34.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
sound/soc/codecs/cs35l34.c +12 -2
@@ -45,6 +45,7 @@ struct cs35l34_private {int num_core_supplies;int mclk_int;bool tdm_mode; +bool irq_requested;struct gpio_desc *reset_gpio;/* Active-low reset GPIO */ };
@@ -1053,10 +1054,12 @@ static int cs35l34_i2c_probe(struct i2c_ } ret =devm_request_threaded_irq (&i2c_client->dev, i2c_client->irq,NULL , - cs35l34_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -"cs35l34" , cs35l34); + cs35l34_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , +"cs35l34" , cs35l34);if (ret !=0 )dev_err (&i2c_client->dev,"Failed to request IRQ: %d\n" , ret); +else + cs35l34->irq_requested = true; cs35l34->reset_gpio =devm_gpiod_get_optional (&i2c_client->dev,"reset" ,GPIOD_OUT_LOW );
@@ -1161,6 +1164,9 @@ static int __maybe_unused cs35l34_runtimdev_err (dev,"Failed to restore register cache\n" ); goto err; } + +if (cs35l34->irq_requested) +enable_irq (to_i2c_client (dev)->irq);return 0 ; err:regcache_cache_only (cs35l34->regmap, true);
@@ -1174,6 +1180,10 @@ static int __maybe_unused cs35l34_runtim {struct cs35l34_private *cs35l34 =dev_get_drvdata (dev); +/* Drain and block the threaded IRQ before cache_only/power-off. */ +if (cs35l34->irq_requested) +disable_irq (to_i2c_client (dev)->irq); +regcache_cache_only (cs35l34->regmap, true);regcache_mark_dirty (cs35l34->regmap);
Greg Kroah-Hartman
maintainerPATCH 339/1191 ASoC: fsl: mpc5200-i2s: Free DMA resources on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 3a89ddcf0c3d9a068631e8c24d5c9e81d1e6512a upstream.
mpc5200_audio_dma_create() creates the DMA resources before registering the component. If snd_soc_register_component() fails, the function returns directly and leaves the DMA resources allocated.
Call mpc5200_audio_dma_destroy() before returning from this error path.
--- sound/soc/fsl/mpc5200_psc_i2s.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/fsl/mpc5200_psc_i2s.c +1 -0
@@ -171,6 +171,7 @@ static int psc_i2s_of_probe(struct platf psc_i2s_dai, ARRAY_SIZE(psc_i2s_dai));if (rc !=0 ) {pr_err ("Failed to register DAI\n" ); +mpc5200_audio_dma_destroy (op);return rc; }
Greg Kroah-Hartman
maintainerPATCH 340/1191 AsoC: intel: sst: fix PCI device reference leak on probe failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 016f29997ebd29d6ab59c8162ce0e7f73bd1e517 upstream.
intel_sst_probe() takes a reference to the PCI device with pci_dev_get(). If sst_platform_get_resources() fails afterwards, the probe error path cleans up the driver context but does not drop the PCI device reference.
Add a pci_dev_put() error path for failures after pci_dev_get().
--- sound/soc/intel/atom/sst/sst_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/atom/sst/sst_pci.c +3 -1
@@ -141,13 +141,15 @@ static int intel_sst_probe(struct pci_de sst_drv_ctx->pci =pci_dev_get (pci); ret =sst_platform_get_resources (sst_drv_ctx);if (ret <0 ) - goto do_free_drv_ctx; + goto do_put_pci;pci_set_drvdata (pci, sst_drv_ctx);sst_configure_runtime_pm (sst_drv_ctx);return ret; +do_put_pci: +pci_dev_put (sst_drv_ctx->pci); do_free_drv_ctx:sst_context_cleanup (sst_drv_ctx);dev_err (sst_drv_ctx->dev,"Probe failed with %d\n" , ret);
Greg Kroah-Hartman
maintainerPATCH 341/1191 ASoC: samsung: aries_audio_probe: double of_node_put due to direct assignment without of_node_get
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit fb5d1b1c5f8a920ee697545fa6dee16825085717 upstream.
In aries_audio_probe(), aries_dai[0].platforms->of_node is assigned the same pointer as aries_dai[0].cpus->of_node (from of_parse_phandle) without calling of_node_get(). When the sound card is deregistered, the ASoC framework calls of_node_put() on both cpus->of_node and platforms->of_node, causing a double put on the same node and a refcount underflow.
Add of_node_get(aries_dai[0].cpus->of_node) before the assignment.
--- sound/soc/samsung/aries_wm8994.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/samsung/aries_wm8994.c +1 -0
@@ -653,6 +653,7 @@ static int aries_audio_probe(struct plat goto out; } +of_node_get (aries_dai[0 ].cpus->of_node); aries_dai[0 ].platforms->of_node = aries_dai[0 ].cpus->of_node;/* Set CPU of_node for BT DAI */
Greg Kroah-Hartman
maintainerPATCH 342/1191 iio: chemical: atlas-sensor: fix PM reference leak in buffer postenable
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Moksh Panicker <[email protected]>
commit bcd3f72e26314edfce7eaf8d7160b3119c7b7fed upstream.
atlas_buffer_postenable() acquires a runtime PM reference with pm_runtime_resume_and_get() but returns the result of atlas_set_interrupt() directly. If atlas_set_interrupt() fails, the runtime PM reference is leaked and the device can never autosuspend.
Add pm_runtime_put_autosuspend() on the error path to balance the reference.
--- drivers/iio/chemical/atlas-sensor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iio/chemical/atlas-sensor.c +5 -1
@@ -414,7 +414,11 @@ static int atlas_buffer_postenable(strucif (ret)return ret; -return atlas_set_interrupt (data, true); + ret =atlas_set_interrupt (data, true); +if (ret) +pm_runtime_put_autosuspend (&data->client->dev); + +return ret; }static int atlas_buffer_predisable (struct iio_dev *indio_dev)
Greg Kroah-Hartman
maintainerPATCH 343/1191 iio: chemical: sgp30: Handle IAQ thread creation failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linmao Li <[email protected]>
commit 1135d6875d2dbda3f6ec718f3421a6ce4378bd63 upstream.
kthread_run() can fail and return an error pointer, but sgp_probe() stores it and returns success, so the device is registered without its IAQ thread and sgp_remove() later passes the error pointer to kthread_stop(). Return the error from probe instead.
--- drivers/iio/chemical/sgp30.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/iio/chemical/sgp30.c +3 -0
@@ -548,6 +548,9 @@ static int sgp_probe(struct i2c_client * data->iaq_thread =kthread_run (sgp_iaq_threadfn, data,"%s-iaq" , data->client->name); +if (IS_ERR (data->iaq_thread)) +return dev_err_probe (dev,PTR_ERR (data->iaq_thread), +"failed to start IAQ thread\n" );return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 344/1191 iio: dac: m62332: Fix regulator reference count imbalance
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Erick Henrique <[email protected]>
commit a130404ce0b69ca1438126bd81c1985d3b4d2e6f upstream.
m62332_set_value() enables the Vcc regulator on every write of a non-zero value and disables it on every write of zero, without tracking the channel's current state. Because the regulator is reference counted, changing a channel directly from one non-zero value to another enables it more than once, while a later write of zero disables it only once. The reference count never returns to zero and the regulator is left enabled indefinitely.
Only enable the regulator on the transition from zero to non-zero, and only disable it on the transition from non-zero to zero, using the previously stored channel value to detect the edge. Balance the regulator on the I2C error path so the reference count stays consistent if the write fails.
--- drivers/iio/dac/m62332.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/iio/dac/m62332.c +12 -5
@@ -32,6 +32,7 @@ static int m62332_set_value(struct iio_d {struct m62332_data *data =iio_priv (indio_dev);struct i2c_client *client = data->client; +bool enabling, disabling;u8 outbuf[2 ];int res;
@@ -43,7 +44,10 @@ static int m62332_set_value(struct iio_dmutex_lock (&data->mutex); -if (val) { + enabling = val && !data->raw[channel]; + disabling = !val && data->raw[channel]; + +if (enabling) { res =regulator_enable (data->vcc);if (res) goto out;
@@ -52,14 +56,17 @@ static int m62332_set_value(struct iio_d res =i2c_master_send (client, outbuf,ARRAY_SIZE (outbuf));if (res >=0 && res !=ARRAY_SIZE (outbuf)) res = -EIO ; -if (res <0 ) +if (res <0 ) { +if (enabling) +regulator_disable (data->vcc); goto out; + } - data->raw[channel] = val; - -if (!val) +if (disabling)regulator_disable (data->vcc); + data->raw[channel] = val; +mutex_unlock (&data->mutex);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 345/1191 iio: gyro: mpu3050: fix sign of raw angular velocity readings
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
commit 06fab97602fe400bea843176f485bbac07a668e2 upstream.
The MPU-3050 gyroscope output registers hold 16-bit two's complement values; the angular velocity channels are declared with .sign = 's'. When mpu3050_read_raw() handles IIO_CHAN_INFO_RAW it reads the register via a big-endian regmap_bulk_read() and assigns it with:
*val = be16_to_cpu(raw_val);
be16_to_cpu() yields an unsigned 16-bit quantity, so negative rates (bit 15 set) are reported to userspace as large positive integers (e.g. -1 becomes 65535) instead of the correct negative value.
Cast to s16 before the assignment, matching the temperature channel a few lines above which already handles the sign correctly.
--- drivers/iio/gyro/mpu3050-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/gyro/mpu3050-core.c +1 -1
@@ -356,7 +356,7 @@ static int mpu3050_read_raw(struct iio_d goto out_read_raw_unlock; } - *val =be16_to_cpu (raw_val); + *val = (s16 )be16_to_cpu (raw_val); ret =IIO_VAL_INT ; goto out_read_raw_unlock;
Greg Kroah-Hartman
maintainerPATCH 346/1191 iio: light: cm32181: return zero after writing calibscale
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giorgi Tchankvetadze <[email protected]>
commit 8756acd30919a3e9f547ea4a1d4b7f7895f4d340 upstream.
The write_raw callback is documented to return 0 on success or a negative error code. However, the IIO_CHAN_INFO_CALIBSCALE case returns 'val' (the user-supplied value) instead of 0.
Fix it by returning 0 on success, matching the behavior of other calibscale implementations in the subsystem.
--- drivers/iio/light/cm32181.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/cm32181.c +1 -1
@@ -370,7 +370,7 @@ static int cm32181_write_raw(struct iio_switch (mask) {case IIO_CHAN_INFO_CALIBSCALE : cm32181->calibscale = val; -return val; +return 0 ;case IIO_CHAN_INFO_INT_TIME : ret =cm32181_write_als_it (cm32181, val2);return ret;
Greg Kroah-Hartman
maintainerPATCH 347/1191 iio: light: gp2ap002: Disable regulators on resume failure
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
commit a41000ba3a230bed1e422f283486ff8f77fe0d30 upstream.
If enabling VIO fails after VDD has been enabled, runtime resume returns without disabling VDD. Likewise, if device reinitialization fails, both supplies remain enabled. The runtime PM core keeps the device suspended when its resume callback fails, so the supplies must be restored to the suspended state.
Disable the supplies enabled by the callback before returning an error.
--- drivers/iio/light/gp2ap002.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/light/gp2ap002.c +8 -2
@@ -672,7 +672,7 @@ static int gp2ap002_runtime_resume(struc ret =regulator_enable (gp2ap002->vio);if (ret) {dev_err (dev,"failed to enable VIO regulator in resume path\n" ); -return ret; + goto out_disable_vdd; }msleep (20 );
@@ -680,13 +680,19 @@ static int gp2ap002_runtime_resume(struc ret =gp2ap002_init (gp2ap002);if (ret) {dev_err (dev,"re-initialization failed\n" ); -return ret; + goto out_disable_vio; }/* Re-activate the IRQ */ enable_irq (gp2ap002->irq);return 0 ; + +out_disable_vio: +regulator_disable (gp2ap002->vio); +out_disable_vdd: +regulator_disable (gp2ap002->vdd); +return ret; } static DEFINE_RUNTIME_DEV_PM_OPS(gp2ap002_dev_pm_ops, gp2ap002_runtime_suspend,
Greg Kroah-Hartman
maintainerPATCH 348/1191 iio: srf04: fix pm_runtime handling on probe error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
commit a40b2e7a17f26e38ab054363c9c7cde149588357 upstream.
When pm_runtime_set_active() fails during probe, the driver logs the error and unregisters the IIO device, but then falls through and still calls pm_runtime_enable() before returning the error.
Since probe returns an error, srf04_remove() is never called, so runtime PM is left enabled without a matching pm_runtime_disable(). This leaks the enable and triggers an "Unbalanced pm_runtime_enable!" warning on a subsequent bind of the device.
Return the error right after unregistering the IIO device so that runtime PM is not enabled on the failure path.
--- drivers/iio/proximity/srf04.c | 1 + 1 file changed, 1 insertion(+)
drivers/iio/proximity/srf04.c +1 -0
@@ -335,6 +335,7 @@ static int srf04_probe(struct platform_dif (ret) {dev_err (data->dev,"pm_runtime_set_active: %d\n" , ret);iio_device_unregister (indio_dev); +return ret; }pm_runtime_enable (data->dev);
Greg Kroah-Hartman
maintainerPATCH 349/1191 iio: temperature: hid-sensor-temperature: switch to non-devm iio_device_register()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sanjay Chitroda <[email protected]>
commit 967d066f5334740f656577bc51c381a1bb707b61 upstream.
Avoid using devm_iio_device_register(), as this driver requires explicit error handling and teardown ordering.
With devm_iio_device_register(), IIO device remains registered until the devres cleanup phase. However, driver's remove() callback removes the sensor hub callback and trigger support. This can create a race window where IIO device is still visible and read_raw() requests are issued. These requests might call sensor_hub_input_attr_get_raw_value(), which waits up to 5 seconds for a response from the sensor hub callback that has already been removed.
Add an explicit iio_device_unregister() call in the teardown path to ensure deterministic cleanup, so that userspace can no longer access the device once backend resources begin to be dismantled.
--- drivers/iio/temperature/hid-sensor-temperature.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/temperature/hid-sensor-temperature.c +2 -1
@@ -243,7 +243,7 @@ static int hid_temperature_probe(structif (ret) goto error_remove_trigger; - ret =devm_iio_device_register (indio_dev->dev.parent, indio_dev); + ret =iio_device_register (indio_dev);if (ret) goto error_remove_callback;
@@ -263,6 +263,7 @@ static int hid_temperature_remove(structstruct iio_dev *indio_dev =platform_get_drvdata (pdev);struct temperature_state *temp_st =iio_priv (indio_dev); +iio_device_unregister (indio_dev);sensor_hub_remove_callback (hsdev,HID_USAGE_SENSOR_TEMPERATURE );hid_sensor_remove_trigger (indio_dev, &temp_st->common_attributes);
Greg Kroah-Hartman
maintainerPATCH 350/1191 KVM: nVMX: Always flush vpid02 on first use
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yosry Ahmed <[email protected]>
commit f0772389413dce9657c7d6950abf3edbbd511356 upstream.
Make sure vpid02 is always flushed on first use by setting last_vpid=0 when allocating vpid02. nested_vmx_transition_tlb_flush() will always detect a VPID change on first VM-Enter after VMXON, because VPID=0 in vmcs12 is not allowed if L1 enables VPID.
This avoids using stale TLB entries from a previous lifetime of the VPID, that might have been associated with a different vCPU (or a completely different VM).
Note that last_vpid is already being initialized as 0 when the vCPU is created, but it is not reset when vpid02 is freed on VMXOFF. Hence, the problem can only occur if L1 does VMXOFF -> VMXON, runs an L2, and KVM happens to reuse a VPID that has TLB entries on the physical CPU.
--- arch/x86/kvm/vmx/nested.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/kvm/vmx/nested.c +10 -0
@@ -1164,6 +1164,9 @@ static void nested_vmx_transition_tlb_fl* is the VPID incorporated into the MMU context. I.e. KVM must assume * that the new vpid12 has never been used and thus represents a new * guest ASID that cannot have entries in the TLB. +* +* Note, last_vpid is initialized as 0, so the first nested VM-Enter +* after VMXON will always flush the TLB to avoid using stale entries. */ if (is_vmenter && vmcs12->virtual_processor_id != vmx->nested.last_vpid) { vmx->nested.last_vpid = vmcs12->virtual_processor_id;
@@ -5162,6 +5165,13 @@ static int enter_vmx_operation(struct kv vmx->nested.vpid02 =allocate_vpid (); +/* +* Clear last_vpid to ensure that the VPID is flushed on the first +* nested VM-Enter. Otherwise, stale TLB entries from a previous life of +* the VPID (e.g. different vCPU or even different VM) could be used. +*/ + vmx->nested.last_vpid =0 ; + vmx->nested.vmcs02_initialized = false; vmx->nested.vmxon = true;
Greg Kroah-Hartman
maintainerPATCH 351/1191 KVM: nVMX: Service local TLB flushes on failed nested VM-Enter
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yosry Ahmed <[email protected]>
commit 05a0b701d1089fb57beeb8982f23c3bbafe0fa8b upstream.
KVM services local TLB flushes on "full" nested VM-Exits (through __nested_vmx_vmexit()), but not if a nested VM-Enter fails (e.g. due to failed VMCS checks in nested_vmx_enter_non_root_mode()).
However, it is possible that KVM had queued TLB flushes that need to be performed, even if the nested VM-Enter was not successful. For example, if VPID is disabled for L2 (via nested_vmx_transition_tlb_flush(), or if via the MSR load lists, as the SDM says:
If any MSR is being loaded in such a way that would architecturally require a TLB flush, the TLBs are updated so that, after VM entry, the logical processor will not use any translations that were cached before the transition.
The SDM is unclear about when the TLB flush should occur, and whether or not a failed VM entry would flush the TLB, so it is safer to always do the TLB flush in this case.
More concretely, KVM also updates the last VPID L1 used for L2 in nested_vmx_transition_tlb_flush() (i.e. last_vpid), even if the VM entry ultimately fails. With the current code, KVM could miss a TLB flush if L1 changes L2's VPID, then does a failed VM entry followed by a successful one, as the failed VM entry would update last_vpid but not actually flush the TLB. Servicing local TLB flushes on failed VM entries makes sure that the TLB is always flushed when last_vpid is updated.
--- arch/x86/kvm/vmx/nested.c | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/x86/kvm/vmx/nested.c +8 -0
@@ -3527,6 +3527,14 @@ enum nvmx_vmentry_status nested_vmx_ente vmentry_fail_vmexit_guest_mode:if (vmcs12->cpu_based_vm_exec_control &CPU_BASED_USE_TSC_OFFSETTING ) vcpu->arch.tsc_offset -= vmcs12->tsc_offset; + +/* +* Handle any TLB flush requests that were queued for L2 if KVM made it +* far enough along to switch to L2 context. Note, loading host state +* will generate any flushes for L1 required by VM-Exit. +*/ +kvm_service_local_tlb_flush_requests (vcpu); +leave_guest_mode (vcpu); vmentry_fail_vmexit:
Greg Kroah-Hartman
maintainerPATCH 352/1191 KVM: x86: hyper-v: Clamp stimer deadline to avoid livelock
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carlos López <[email protected]>
commit 0ca49fbd2883cd53d32d85b50feef17fa04d0fbf upstream.
Fix an issue where userspace or the guest can program an Hyper-V synthetic timer to have a deadline in the past via integer overflow, preventing the CPU from making progress and triggering an RCU stall.
Hyper-V's SynIC exposes 4 per-vCPU synthetic timers to the guest, which are emulated by KVM. Each is programmed through the HV_X64_MSR_STIMERi_CONFIG and HV_X64_MSR_STIMERi_COUNT MSRs. Depending on CONFIG, COUNT represents either the absolute expiration time or the period of a periodic timer, both expressed in 100ns ticks. These timers may be set both by the guest (WRMSR) and the host (KVM_SET_MSRS).
When the timer is enabled, stimer_start() translates COUNT to an absolute monotonic deadline and arms an hrtimer. If COUNT is set to a value close to U64_MAX, the deadline calculation can overflow.
ktime_add_ns(ktime_now, 100 * (stimer->exp_time - time_now))
This can result in a CPU livelock. stimer_start() arms the timer via hrtimer_start() with a deadline in the past, which causes it to immediately fire. The stimer callback then raises KVM_RQ_HV_STIMER, with the intention of causing KVM to deliver a synthetic interrupt on the next vCPU guest enter.
Then, once userspace issues KVM_RUN, vcpu_enter_guest() consumes the request, calling kvm_hv_process_stimers(). This would normally disable the timer via stimer_expiration() once the deadline is in the past. However, the deadline comparison is done between the KVM reference counter and stime->exp_time, which is a big value close to U64_MAX, so this never happens for a few thousand years.
kvm_hv_process_timers() then re-arms the timer via stimer_start(), since it was not disabled, which again fires immediately. Before entering the guest, kvm_vcpu_exit_request() checks kvm_request_pending(), which returns true due to the newly raised KVM_REQ_HV_STIMER. Then vcpu_enter_guest() aborts the guest entry, returning early into vcpu_run(), which loops back again into vcpu_enter_guest(), restarting the cycle.
Since there are no manual yields in this loop, a task with SCHED_FIFO may starve RCU grace-period kthreads, which exposes the stalls found by syzcaller:
rcu: INFO: rcu_preempt detected stalls on CPUs/tasks:
rcu: (detected by 1, t=10502 jiffies, g=14269, q=1142 ncpus=2)
rcu: All QSes seen, last rcu_preempt kthread activity 10500 (4294965239-4294954739), jiffies_till_next_fqs=1, root ->qsmask 0x0
rcu: rcu_preempt kthread starved for 10500 jiffies! g14269 f0x2 RCU_GP_WAIT_FQS(5) ->state=0x0 ->cpu=0
rcu: Unless rcu_preempt kthread gets sufficient CPU time, OOM is now expected behavior.
( ... )
Call Trace:
<IRQ>
__run_hrtimer kernel/time/hrtimer.c:1773 [inline]
__hrtimer_run_queues+0x408/0xc30 kernel/time/hrtimer.c:1841
hrtimer_interrupt+0x45b/0xaa0 kernel/time/hrtimer.c:1903
local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1045 [inline]
__sysvec_apic_timer_interrupt+0x102/0x3e0 arch/x86/kernel/apic/apic.c:1062
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1056 [inline]
sysvec_apic_timer_interrupt+0xa1/0xc0 arch/x86/kernel/apic/apic.c:1056
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697
RIP: 0010:__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:152 [inline]
RIP: 0010:_raw_spin_unlock_irqrestore+0xa8/0x110 kernel/locking/spinlock.c:194
Code: 74 05 e8 0b f4 5f f6 48 c7 44 24 20 00 00 00 00 9c 8f 44 24 20 f6 44 24 21 02 75 4f f7 c3 00 02 00 00 74 01 fb bf 01 00 00 00 <e8> 23 6b 27 f6 65 8b 05 7c 60 5a 07 85 c0 74 40 48 c7 04 24 0e 36
RSP: 0018:ffffc900040a7320 EFLAGS: 00000206
RAX: 5de15cb931505900 RBX: 0000000000000a06 RCX: 5de15cb931505900
RDX: 0000000000000007 RSI: ffffffff8daa9dc3 RDI: 0000000000000001
RBP: ffffc900040a73b0 R08: ffffffff8fc3d077 R09: 1ffffffff1f87a0e
R10: dffffc0000000000 R11: fffffbfff1f87a0f R12: dffffc0000000000
R13: 0000000000000000 R14: ffff8880b8628240 R15: 1ffff92000814e64
hrtimer_start include/linux/hrtimer.h:259 [inline]
stimer_start arch/x86/kvm/hyperv.c:682 [inline]
kvm_hv_process_stimers+0xd0a/0x16a0 arch/x86/kvm/hyperv.c:893
vcpu_enter_guest arch/x86/kvm/x86.c:11193 [inline]
vcpu_run+0x2240/0x76b0 arch/x86/kvm/x86.c:11639
kvm_arch_vcpu_ioctl_run+0x1148/0x1c90 arch/x86/kvm/x86.c:11984
kvm_vcpu_ioctl+0x99a/0xed0 virt/kvm/kvm_main.c:4492
vfs_ioctl fs/ioctl.c:51 [inline]
__do_sys_ioctl fs/ioctl.c:597 [inline]
__se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f635278f749
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f635365c038 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 00007f63529e5fa0 RCX: 00007f635278f749
RDX: 0000000000000000 RSI: 000000000000ae80 RDI: 0000000000000005
RBP: 00007f6352813f91 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f63529e6038 R14: 00007f63529e5fa0 R15: 00007ffd5b219358
</TASK>Fix this by clamping the deadline computation to KTIME_MAX, which preserves the intent of arming a timer very far in the future. ktime_add_safe() already does this type of clamping, so use it after checking that that multiplying by the 100ns time tick also does not overflow.
--- arch/x86/kvm/hyperv.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-)
arch/x86/kvm/hyperv.c +18 -7
@@ -601,6 +601,18 @@ static enum hrtimer_restart stimer_timer }/* +* Translate a stimer expiry given in 100ns reference ticks into an +* an absolute deadline. Saturates on overflow. +*/ +static ktime_t stimer_add_delta (ktime_t now,u64 delta_100ns) +{ +if (delta_100ns >=KTIME_MAX /100 ) +return KTIME_MAX ; + +return ktime_add_safe (now,100 * delta_100ns); +} + +/* * stimer_start() assumptions: * a) stimer->count is not equal to 0 * b) stimer->config has HV_STIMER_ENABLE flag
@@ -609,6 +621,7 @@ static int stimer_start(struct kvm_vcpu_ {u64 time_now;ktime_t ktime_now; +ktime_t deadline; time_now =get_time_ref_counter (hv_stimer_to_vcpu (stimer)->kvm); ktime_now =ktime_get ();
@@ -631,10 +644,8 @@ static int stimer_start(struct kvm_vcpu_ stimer->index, time_now, stimer->exp_time); -hrtimer_start (&stimer->timer, -ktime_add_ns (ktime_now, -100 * (stimer->exp_time - time_now)), -HRTIMER_MODE_ABS ); + deadline =stimer_add_delta (ktime_now, stimer->exp_time - time_now); +hrtimer_start (&stimer->timer, deadline,HRTIMER_MODE_ABS );return 0 ; } stimer->exp_time = stimer->count;
@@ -653,9 +664,9 @@ static int stimer_start(struct kvm_vcpu_ stimer->index, time_now, stimer->count); -hrtimer_start (&stimer->timer, -ktime_add_ns (ktime_now,100 * (stimer->count - time_now)), -HRTIMER_MODE_ABS ); + deadline =stimer_add_delta (ktime_now, stimer->count - time_now); +hrtimer_start (&stimer->timer, deadline,HRTIMER_MODE_ABS ); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 353/1191 KVM: s390: Fix length check __import_wp_info()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit 4c07680a467e2f7697245bcd11691bffb2a6f0ed upstream.
struct kvm_hw_breakpoint::len is a __u64 that is fully controlled by user space. This is then assigned to wp_info->len, which is an int. The bounds check is done on the truncated value while the allocation uses the untruncated one:
wp_info->len = bp_data->len; [...] if (wp_info->len < 0 || wp_info->len > MAX_WP_SIZE) return -EINVAL; wp_info->old_data = kmalloc(bp_data->len, GFP_KERNEL_ACCOUNT);
Use the validated value for the allocation as intended. Without this fix userspace can trigger >4GB allocations which will fail and result in a WARN due to MAX_PAGE_ORDER.
Message-ID: <[email protected]>
--- arch/s390/kvm/guestdbg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/guestdbg.c +1 -1
@@ -184,7 +184,7 @@ static int __import_wp_info(struct kvm_vif (wp_info->len <0 || wp_info->len >MAX_WP_SIZE )return -EINVAL ; - wp_info->old_data =kmalloc (bp_data->len,GFP_KERNEL_ACCOUNT ); + wp_info->old_data =kmalloc (wp_info->len,GFP_KERNEL_ACCOUNT );if (!wp_info->old_data)return -ENOMEM ;/* try to backup the original value */
Greg Kroah-Hartman
maintainerPATCH 354/1191 KVM: s390: Fix memory leak in guest debug handling
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit 121ea1de927c8b9bfdf53c31cad27b86d5de0293 upstream.
bp_data is freed only for the error case by kfree(bp_data). Every successful KVM_SET_GUEST_DEBUG will leak bp_data.
Message-ID: <[email protected]>
--- arch/s390/kvm/guestdbg.c | 1 + 1 file changed, 1 insertion(+)
arch/s390/kvm/guestdbg.c +1 -0
@@ -271,6 +271,7 @@ int kvm_s390_import_bp_data(struct kvm_v vcpu->arch.guestdbg.hw_bp_info = bp_info; vcpu->arch.guestdbg.nr_hw_wp = nr_wp; vcpu->arch.guestdbg.hw_wp_info = wp_info; +kfree (bp_data);return 0 ; error:kfree (bp_data);
Greg Kroah-Hartman
maintainerPATCH 355/1191 KVM: s390: Fix old_data leak in guest debug error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit aa9c8e8baf1e765fa65b93212522c636f25d846f upstream.
__import_wp_info() allocates a per-watchpoint old_data buffer to back up the original guest memory contents. If a later watchpoint of the same KVM_SET_GUEST_DEBUG request fails to import, kvm_s390_import_bp_data() jumps to the error label, which frees the wp_info array but not the old_data buffers of the entries that were imported successfully. Up to MAX_BP_COUNT - 1 buffers of up to MAX_WP_SIZE bytes are leaked per failed request, and the request can be repeated.
Create error handling for cleaning up all created old_data memory areas.
Message-ID: <[email protected]>
--- arch/s390/kvm/guestdbg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/s390/kvm/guestdbg.c +5 -1
@@ -256,7 +256,7 @@ int kvm_s390_import_bp_data(struct kvm_v ret =__import_wp_info (vcpu, &bp_data[i], &wp_info[nr_wp]);if (ret) - goto error; + goto error_wp; nr_wp++;break ;case KVM_HW_BP :
@@ -273,6 +273,10 @@ int kvm_s390_import_bp_data(struct kvm_v vcpu->arch.guestdbg.hw_wp_info = wp_info;kfree (bp_data);return 0 ; + +error_wp: +while (nr_wp--) +kfree (wp_info[nr_wp].old_data); error:kfree (bp_data);kfree (wp_info);
Greg Kroah-Hartman
maintainerPATCH 356/1191 KVM: s390: Free guest debug data on vcpu destroy
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit e7f698b09d4a7c36b299acf680fc50fe868e2bcd upstream.
kvm_s390_clear_bp_data() is only called from kvm_arch_vcpu_ioctl_set_guest_debug(), i.e. when user space changes or disables debugging. A vCPU that is destroyed while hardware breakpoints are still armed - the normal case when the VMM just exits or crashes - leaks hw_bp_info, hw_wp_info and all old_data buffers, since generic KVM frees the vCPU right after kvm_arch_vcpu_destroy().
That is bounded by MAX_BP_COUNT entries, so roughly 8 KiB per vCPU, but it is unbounded over VM lifetimes. The allocations are GFP_KERNEL_ACCOUNT, so the charge also outlives the exiting process and pins dying memcgs.
Fix by clearing the debug data on vCPU destruction. Calling it unconditionally is fine: struct kvm_vcpu is zero allocated, so for a vCPU that never enabled debugging the counters are 0 and the pointers NULL.
Message-ID: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 1 + 1 file changed, 1 insertion(+)
arch/s390/kvm/kvm-s390.c +1 -0
@@ -3274,6 +3274,7 @@ void kvm_arch_vcpu_destroy(struct kvm_vctrace_kvm_s390_destroy_vcpu (vcpu->vcpu_id);kvm_s390_clear_local_irqs (vcpu);kvm_clear_async_pf_completion_queue (vcpu); +kvm_s390_clear_bp_data (vcpu);if (!kvm_is_ucontrol (vcpu->kvm))sca_del_vcpu (vcpu);kvm_s390_update_topology_change_report (vcpu->kvm,1 );
Greg Kroah-Hartman
maintainerPATCH 357/1191 KVM: s390: Take srcu when importing watchpoint data
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit a4e482def8533ebace517d9f67f1465841b1f982 upstream.
__import_wp_info() backs up the original guest memory contents of a watchpoint with read_guest_abs(), which is kvm_read_guest() and therefore resolves the memslot via __kvm_memslots(). That requires kvm->srcu (or kvm->slots_lock) to be held, otherwise a concurrent memslot update can free the memslots array under us once its SRCU grace period has elapsed.
As this is not fast path, following lock ordering (mutex first, then srcu) take the big hammer and hold the srcu for the full import.
Message-ID: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +4 -2
@@ -4222,8 +4222,10 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(/* enforce guest PER */ kvm_s390_set_cpuflags (vcpu,CPUSTAT_P ); -if (dbg->control &KVM_GUESTDBG_USE_HW_BP ) - rc =kvm_s390_import_bp_data (vcpu, dbg); +if (dbg->control &KVM_GUESTDBG_USE_HW_BP ) { +scoped_guard (srcu, &vcpu->kvm->srcu) + rc = kvm_s390_import_bp_data(vcpu, dbg); + } }else {kvm_s390_clear_cpuflags (vcpu,CPUSTAT_P ); vcpu->arch.guestdbg.last_bp =0 ;
Greg Kroah-Hartman
maintainerPATCH 358/1191 KVM: s390: Zero initialize irq in reinject_machine_check
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit b239410c7653ff6781d4cf1d63cfc52a1bb71788 upstream.
kvm_s390_reinject_machine_check() fills cr14, mcic, ext_damage_code and failing_storage_address of the on-stack struct kvm_s390_irq, but struct kvm_s390_mchk_info also has a pad word and a 16 byte fixed_logout array. struct mcck_volatile_info carries no logout data, so there is nothing to copy there and both stay whatever was on the stack.
__inject_mchk() then memcpy()s fixed_logout into the vcpu local interrupt state unconditionally. This will reach the guest during deliver and userspace during migration.
Reflecting zeroes is the correct behaviour here, as KVM has no logout data for a reinjected machine check.
This needs a host machine check while the cpu is in SIE so not trivial to trigger.
Message-ID: <[email protected]>
--- arch/s390/kvm/interrupt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/interrupt.c +1 -1
@@ -2859,7 +2859,7 @@ void kvm_s390_reinject_machine_check(str struct mcck_volatile_info *mcck_info) {struct kvm_s390_interrupt_info inti; -struct kvm_s390_irq irq; +struct kvm_s390_irq irq = {};struct kvm_s390_mchk_info *mchk;union mci mci;__u64 cr14 =0 ;/* upper bits are not used */
Greg Kroah-Hartman
maintainerPATCH 359/1191 KVM: s390: pv: Fix rc/rrc offset for PVM_DUMP
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit 1e3c8e7b3465fb8a49d3623d2d0f449c0b5b48f3 upstream.
The rc/rrc value is copied to the cmd location of the cmd in the kvm_pv_cmd structure. Fix the offset.
Message-ID: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kvm/kvm-s390.c +1 -1
@@ -5551,7 +5551,7 @@ long kvm_arch_vcpu_ioctl(struct file *fi r =kvm_s390_handle_pv_vcpu_dump (vcpu, &cmd);/* Always copy over UV rc / rrc data */ -if (copy_to_user ((__u8 __user *)argp, &cmd.rc, +if (copy_to_user (argp + offsetof(struct kvm_pv_cmd , rc), &cmd.rc,sizeof (cmd.rc) +sizeof (cmd.rrc))) r = -EFAULT ;break ;
Greg Kroah-Hartman
maintainerPATCH 360/1191 KVM: s390: Restore sigset on error path
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Borntraeger <[email protected]>
commit c44d36d8e6501c4934412d9014e5e02da9efdb8f upstream.
kvm_sigset_activate() installs vcpu->sigset via sigprocmask() and stashes the caller's mask in current->real_blocked; only kvm_sigset_deactivate() restores it.
For KVM_RUN on a STOPPED vcpu the error path will not restore the userspace mask. Re-arrange the error handling to also restore the signal mask.
Message-ID: <[email protected]>
--- arch/s390/kvm/kvm-s390.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
arch/s390/kvm/kvm-s390.c +4 -2
@@ -4911,7 +4911,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vpr_err_ratelimited ("can't run stopped vcpu %d\n" , vcpu->vcpu_id); rc = -EINVAL ; - goto out; + goto out_sigset; }sync_regs (vcpu);
@@ -4938,9 +4938,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vdisable_cpu_timer_accounting (vcpu);store_regs (vcpu); + vcpu->stat.exit_userspace++; + +out_sigset:kvm_sigset_deactivate (vcpu); - vcpu->stat.exit_userspace++; out:vcpu_put (vcpu);return rc;
Greg Kroah-Hartman
maintainerPATCH 361/1191 media: airspy: use vb2_video_unregister_device() on disconnect to fix NULL deref
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Valery Borovsky <[email protected]>
commit 2f378dc45e685fc825d2dd08e7864666d6fcc009 upstream.
airspy_disconnect() clears s->udev under v4l2_lock, but airspy_stop_streaming() unconditionally calls airspy_ctrl_msg() and airspy_free_stream_bufs() afterwards. If a streaming user closes the device after disconnect, stop_streaming() runs and dereferences the NULL s->udev:
airspy_stop_streaming()
airspy_ctrl_msg(s, CMD_RECEIVER_MODE, 0, 0, NULL, 0)
usb_sndctrlpipe(s->udev, 0) /* NULL deref */
airspy_free_stream_bufs(s)
usb_free_coherent(s->udev, ...) /* NULL deref */The airspy driver uses vb2_fop_release() in its file_operations, so replace video_unregister_device(&s->vdev) with vb2_video_unregister_device(&s->vdev) and move it before clearing s->udev. vb2_video_unregister_device() releases the vb2 queue, which synchronously runs airspy_stop_streaming() if streaming is active, so the URBs, coherent DMA stream buffers and the hardware stop control message all execute while s->udev is still valid.
vb2_video_unregister_device() locks vdev->queue->lock (vb_queue_lock) internally, and stop_streaming() locks v4l2_lock, so the previous outer mutex_lock(&s->vb_queue_lock) / mutex_lock(&s->v4l2_lock) pair around the unregister sequence would self-deadlock and has been removed. A short v4l2_lock critical section around s->udev = NULL remains so any ioctl path that still holds the file descriptor sees coherent state.
Issue identified by automated review of the INV-003 series at
https://sashiko.dev/
--- drivers/media/usb/airspy/airspy.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/media/usb/airspy/airspy.c +12 -5
@@ -464,14 +464,21 @@ static void airspy_disconnect(struct usbdev_dbg (s->dev,"\n" ); -mutex_lock (&s->vb_queue_lock); +/* +* vb2_video_unregister_device() releases the vb2 queue, which +* triggers airspy_stop_streaming() if streaming is active. +* stop_streaming() dereferences s->udev via airspy_ctrl_msg() and +* airspy_free_stream_bufs(), so it must run before s->udev is +* cleared. vb2_video_unregister_device() locks vb_queue_lock +* internally and stop_streaming() locks v4l2_lock, so neither may +* be held by the caller. +*/ +v4l2_device_disconnect (&s->v4l2_dev); +vb2_video_unregister_device (&s->vdev); +mutex_lock (&s->v4l2_lock); -/* No need to keep the urbs around after disconnection */ s->udev =NULL ; -v4l2_device_disconnect (&s->v4l2_dev); -video_unregister_device (&s->vdev);mutex_unlock (&s->v4l2_lock); -mutex_unlock (&s->vb_queue_lock);v4l2_device_put (&s->v4l2_dev); }
Greg Kroah-Hartman
maintainerPATCH 362/1191 media: cec: meson: ao-cec-g12a: name the CEC core regmap to avoid debugfs clash
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yi Ding <[email protected]>
commit 172c5a7d81deb922ddedd1bc920751c7fed6c43c upstream.
The driver registers two regmaps on the same platform device: an MMIO regmap for the AO CEC registers, and an indirect regmap (using reg_read()/reg_write() callbacks) for the CEC controller core registers. Neither regmap_config sets a .name, so both default their debugfs directory to the device name and collide:
debugfs: 'ff800280.cec' already exists in 'regmap'
Because of the clash the second regmap's debugfs directory fails to register, so its registers can no longer be inspected via debugfs.
Give the indirect CEC core regmap a distinct name. The two debugfs directories then become "<dev>.cec" and "<dev>.cec-core". This only affects debugfs naming; register access is unchanged.
Tested on an ODROID-N2 (Amlogic S922X): the warning is gone and both /sys/kernel/debug/regmap/ff800280.cec and ff800280.cec-core are present.
--- drivers/media/cec/platform/meson/ao-cec-g12a.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/cec/platform/meson/ao-cec-g12a.c +1 -0
@@ -405,6 +405,7 @@ static int meson_ao_cec_g12a_write(void }static const struct regmap_config meson_ao_cec_g12a_cec_regmap_conf = { + .name ="core" , .reg_bits =8 , .val_bits =8 , .reg_read = meson_ao_cec_g12a_read,
Greg Kroah-Hartman
maintainerPATCH 363/1191 media: cec: Serialize exclusive follower delivery
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
commit 1924d0788caa6c66fd320dd4704fae99487fd2c7 upstream.
cec_receive_notify() reads the exclusive follower pointer without the adapter lock. Serialize the no-follower check and message delivery against mode changes and release.
--- drivers/media/cec/core/cec-adap.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/cec/core/cec-adap.c +7 -1
@@ -2152,9 +2152,13 @@ static int cec_receive_notify(struct cec* Unprocessed messages are aborted if userspace isn't doing * any processing either. */ +mutex_lock (&adap->lock);if (!is_broadcast && !is_reply && !adap->follower_cnt && - !adap->cec_follower && msg->msg[1 ] !=CEC_MSG_FEATURE_ABORT ) + !adap->cec_follower && msg->msg[1 ] !=CEC_MSG_FEATURE_ABORT ) { +mutex_unlock (&adap->lock);return cec_feature_abort (adap, msg); + } +mutex_unlock (&adap->lock);break ; }
@@ -2167,10 +2171,12 @@ skip_processing:* Send to the exclusive follower if there is one, otherwise send * to all followers. */ +mutex_lock (&adap->lock);if (adap->cec_follower)cec_queue_msg_fh (adap->cec_follower, msg);else cec_queue_msg_followers (adap, msg); +mutex_unlock (&adap->lock);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 364/1191 media: cedrus: fix memory leak in cedrus_init_ctrls()
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawei Feng <[email protected]>
commit 9df2fbe563194da1967a5db083442186c1323efe upstream.
In cedrus_init_ctrls(), the V4L2 control handler is initialized before allocating memory for ctx->ctrls. If this allocation fails, the function returns -ENOMEM without freeing the previously allocated handler resources, leading to a memory leak.
Fix this by calling v4l2_ctrl_handler_free() on the ctx->ctrls allocation failure path.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1.1.
An x86_64 allyesconfig build showed no new warnings. As we do not have an Allwinner SoC or board with a Cedrus VPU available to test with, no runtime testing was able to be performed.
--- drivers/staging/media/sunxi/cedrus/cedrus.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/staging/media/sunxi/cedrus/cedrus.c +3 -1
@@ -271,8 +271,10 @@ static int cedrus_init_ctrls(struct cedr ctrl_size =sizeof (ctrl) *CEDRUS_CONTROLS_COUNT +1 ; ctx->ctrls =kzalloc (ctrl_size,GFP_KERNEL ); -if (!ctx->ctrls) +if (!ctx->ctrls) { +v4l2_ctrl_handler_free (hdl);return -ENOMEM ; + }for (i =0 ; i <CEDRUS_CONTROLS_COUNT ; i++) { ctrl = v4l2_ctrl_new_custom(hdl, &cedrus_controls[i].cfg,
Greg Kroah-Hartman
maintainerPATCH 365/1191 media: cobalt: Avoid freeing ALSA private data twice
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ruoyu Wang <[email protected]>
commit 3a7d6b9c4cb5ac18cbd3f1c7f8c7b159c42ba0b1 upstream.
snd_cobalt_card_create() stores cobsc in sc->private_data and installs snd_cobalt_card_private_free() as sc->private_free. From that point, snd_card_free(sc) releases cobsc through the ALSA card cleanup path.
If cobalt_alsa_init() fails after snd_cobalt_card_create(), the err_exit_free path calls snd_card_free(sc) and then kfree(cobsc). That second free releases the same object again.
Remove the explicit kfree(cobsc) and leave ownership with the ALSA card.
This issue was found by a static analysis checker and confirmed by manual source review.
--- drivers/media/pci/cobalt/cobalt-alsa-main.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/pci/cobalt/cobalt-alsa-main.c +0 -1
@@ -135,7 +135,6 @@ int cobalt_alsa_init(struct cobalt_strea err_exit_free:if (sc !=NULL )snd_card_free (sc); -kfree (cobsc); err_exit:return ret; }
Greg Kroah-Hartman
maintainerPATCH 366/1191 media: cx231xx: reject geometry changes while the VBI queue is busy
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 627a121c15fe05a541f44d86016294b80bada75d upstream.
vidioc_s_fmt_vid_cap() and vidioc_s_std() change the device-wide dev->width / dev->norm but only refuse the change when the *video* queue (dev->vidq) is busy. The VBI queue (dev->vbiq) shares that same geometry:cx231xx_init_vbi_isoc() latches dma_q->lines_per_field from dev->norm, the VBI videobuf2 plane is sized from dev->width / dev->norm in vbi_queue_setup() and vbi_buf_prepare(), and cx231xx_do_vbi_copy() then recomputes the destination offset from the *live* dev->width and the latched lines_per_field on every URB completion:
offset = lines_completed * (dev->width << 1) + ...; if (dma_q->current_field == 2) offset += dev->width * 2 * dma_q->lines_per_field; memcpy(plane + offset, p_buffer, lencopy);
Because the VBI node shares video_ioctl_ops with the video node, an application can size a small VBI plane (REQBUFS/QBUF with a small width, or with the NTSC standard), then enlarge dev->width (or switch dev->norm to PAL) through the video node while the VBI stream is running -- the change is allowed because only dev->vidq is checked -- and let the device deliver a field-2 VBI payload. cx231xx_do_vbi_copy() now computes the offset with the larger geometry and memcpy()s past the end of the smaller plane that was already allocated, a heap out-of-bounds write whose offset is attacker-chosen and whose contents come from the device. The per-field guard in cx231xx_copy_vbi_line() does not help: it bounds the copy against the latched lines_per_field, not the plane's real capacity, and vb2 does not re-run buf_prepare() for an already prepared buffer.
Refuse the format/standard change when the VBI queue is busy as well, so the geometry cannot change underneath an allocated VBI buffer.
--- drivers/media/usb/cx231xx/cx231xx-video.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/cx231xx/cx231xx-video.c +2 -2
@@ -899,7 +899,7 @@ static int vidioc_s_fmt_vid_cap(struct fif (rc)return rc; -if (vb2_is_busy (&dev->vidq)) { +if (vb2_is_busy (&dev->vidq) ||vb2_is_busy (&dev->vbiq)) {dev_err (dev->dev,"%s: queue busy\n" , __func__);return -EBUSY ; }
@@ -934,7 +934,7 @@ static int vidioc_s_std(struct file *filif (dev->norm == norm)return 0 ; -if (vb2_is_busy (&dev->vidq)) +if (vb2_is_busy (&dev->vidq) ||vb2_is_busy (&dev->vbiq))return -EBUSY ; dev->norm = norm;
Greg Kroah-Hartman
maintainerPATCH 367/1191 media: cx23885: cancel NetUP CI work before teardown
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fan Wu <[email protected]>
commit 4e143d662ca94888b494b2427fc9e34494eb933a upstream.
netup_ci_exit() frees a netup_ci_state while its work item, netup_read_ci_status(), may still be pending or running on the system workqueue. The worker obtains the state with container_of() and dereferences it, so it must not outlive the state.
netup_ci_init() queues the initial status read, and CI GPIO interrupts subsequently queue the same work from netup_ci_slot_status(). During remove, cx23885_finidev() calls free_irq() before the CI device is unregistered. free_irq() prevents further IRQ handlers from running, but does not drain work queued previously, so the worker can run after netup_ci_exit() frees the state.
Call cancel_work_sync() before dvb_ca_en50221_release() and kfree().
This issue was found by an in-house static analysis tool.
--- drivers/media/pci/cx23885/cimax2.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/pci/cx23885/cimax2.c +1 -0
@@ -528,6 +528,7 @@ void netup_ci_exit(struct cx23885_tsportif (NULL == state->ca.data)return ; +cancel_work_sync (&state->work);dvb_ca_en50221_release (&state->ca);kfree (state); }
Greg Kroah-Hartman
maintainerPATCH 368/1191 media: em28xx: defer audio-only extension registration
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Diego Fernando Mancera Gomez <[email protected]>
commit 95f76f51937fdfb0fc1e14cae606b1ef574a56f3 upstream.
The audio-only path registers extensions while probing the primary device. For a dual-TS board, this happens before dev_next is created. The duplicate device inherits is_audio_only and is then independently inserted into em28xx_devlist.
The list is intended to contain only primary devices: extension operations reach the secondary device through dev_next. The independently linked secondary can be freed during disconnect while its list node remains reachable, resulting in a use-after-free.
Defer audio-only extension registration to the module-request work item. It runs only after probing has completed construction of the optional secondary device, so only the primary is registered and extension callbacks reach the secondary through dev_next.
--- drivers/media/usb/em28xx/em28xx-cards.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/usb/em28xx/em28xx-cards.c +1 -2
@@ -3396,6 +3396,7 @@ static void request_module_async(struct* intf. Don't register extensions twice on those devices. */ if (dev->is_audio_only) { +em28xx_init_extension (dev);#if defined(CONFIG_MODULES ) && defined(MODULE )request_module ("em28xx-alsa" );#endif
@@ -3624,8 +3625,6 @@ static int em28xx_init_dev(struct em28xx retval = -ENODEV ; goto err_deinit_media; } -em28xx_init_extension (dev); -return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 369/1191 media: em28xx: fix use-after-free of dev_next->devlist on disconnect
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangong.Han <[email protected]>
commit 826915b6b65e2d3251e7248ea54289a22d748c84 upstream.
When a device with has_dual_ts=1 is probed and the is_audio_only path is taken, both dev and dev->dev_next are added to the global em28xx_devlist via em28xx_init_extension(). However, during disconnect, em28xx_close_extension(dev) only calls list_del(&dev->devlist), leaving dev->dev_next->devlist still linked in the global list. When dev_next is subsequently freed via kref_put(), its devlist entry becomes a dangling pointer in em28xx_devlist. The next device probe that calls em28xx_init_extension() triggers a list corruption BUG when list_add_tail detects the freed node.
This bug was exposed by commit a368ecde8a50 ("USB: core: Fix duplicate endpoint bug by clearing reserved bits in the descriptor") which clears reserved bits in bEndpointAddress during endpoint parsing. This causes fuzzed endpoint addresses like 0xf3 to be normalized to 0x83, which em28xx interprets as a vendor audio endpoint, enabling the is_audio_only + has_dual_ts code path that was previously unreachable with such descriptors.
Fix this by removing dev->dev_next->devlist from the global list in em28xx_close_extension() before the device is freed.
--- drivers/media/usb/em28xx/em28xx-core.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/usb/em28xx/em28xx-core.c +2 -0
@@ -1133,6 +1133,8 @@ void em28xx_close_extension(struct em28x ops->fini (dev); } } +if (dev->dev_next) +list_del (&dev->dev_next->devlist);list_del (&dev->devlist);mutex_unlock (&em28xx_devlist_mutex); }
Greg Kroah-Hartman
maintainerPATCH 370/1191 media: go7007: defer the ALSA v4l2 put until card release
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shuangpeng Bai <[email protected]>
commit 1bd456afeb8a515137e567967069fce6f8fcd23e upstream.
go7007_snd_init() already takes a v4l2_device reference for the ALSA side, but go7007_snd_remove() drops it immediately after calling snd_card_free_when_closed().
That is too early when a userspace process still has the capture PCM open. The ALSA card and its PCM callbacks remain alive until the last file is closed, so the release path can still reach struct go7007 through pcm->private_data and call go7007_snd_hw_free() after the V4L2 release path has freed the object.
Move the matching v4l2_device_put() to the ALSA card private_free callback so the existing ALSA reference covers the whole deferred card lifetime.
--- drivers/media/usb/go7007/snd-go7007.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/media/usb/go7007/snd-go7007.c +9 -1
@@ -195,6 +195,13 @@ static const struct snd_device_ops go700 .dev_free = go7007_snd_free, }; +static void go7007_snd_card_free (struct snd_card *card) +{ +struct go7007 *go = card->private_data; + +v4l2_device_put (&go->v4l2_dev); +} +int go7007_snd_init (struct go7007 *go) {static int dev;
@@ -245,6 +252,8 @@ int go7007_snd_init(struct go7007 *go) gosnd->substream =NULL ; go->snd_context = gosnd;v4l2_device_get (&go->v4l2_dev); + gosnd->card->private_data = go; + gosnd->card->private_free = go7007_snd_card_free; ++dev;return 0 ;
@@ -263,7 +272,6 @@ int go7007_snd_remove(struct go7007 *go)snd_card_disconnect (gosnd->card);snd_card_free_when_closed (gosnd->card); -v4l2_device_put (&go->v4l2_dev);return 0 ; }EXPORT_SYMBOL (go7007_snd_remove);
Greg Kroah-Hartman
maintainerPATCH 371/1191 media: i2c: ov02a10: fix endpoint parsing use-after-free
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Biren Pandya <[email protected]>
commit 94971ba0592ca77ec99b292226a4b398763315b8 upstream.
The ov02a10_check_hwcfg() function calls fwnode_handle_put(ep) immediately after allocating and parsing the endpoint. However, it subsequently calls fwnode_property_read_u32() using the same 'ep' handle, leading to a potential use-after-free.
Additionally, reading the optional 'ovti,mipi-clock-voltage' property used to overwrite the 'ret' variable. If the property was missing, 'ret' would become negative, and this failure code would be incorrectly returned at the end of the function, causing probe to fail entirely.
Fix the use-after-free by moving fwnode_property_read_u32() before the endpoint is parsed and freed. Avoid the error leak by not assigning the result of fwnode_property_read_u32() to 'ret'.
--- drivers/media/i2c/ov02a10.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/media/i2c/ov02a10.c +5 -7
@@ -821,18 +821,16 @@ static int ov02a10_check_hwcfg(struct deif (!ep)return -ENXIO ; +/* Optional indication of MIPI clock voltage unit */ +if (!fwnode_property_read_u32 (ep,"ovti,mipi-clock-voltage" , + &clk_volt)) + ov02a10->mipi_clock_voltage = clk_volt; + ret =v4l2_fwnode_endpoint_alloc_parse (ep, &bus_cfg);fwnode_handle_put (ep);if (ret)return ret; -/* Optional indication of MIPI clock voltage unit */ - ret =fwnode_property_read_u32 (ep,"ovti,mipi-clock-voltage" , - &clk_volt); - -if (!ret) - ov02a10->mipi_clock_voltage = clk_volt; -for (i =0 ; i <ARRAY_SIZE (link_freq_menu_items); i++) {for (j =0 ; j < bus_cfg.nr_of_link_frequencies; j++) { if (link_freq_menu_items[i] ==
Greg Kroah-Hartman
maintainerPATCH 372/1191 media: i2c: ov7740: fix use-after-destroy in remove
In reply to Greg Kroah-Hartman6.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: Biren Pandya <[email protected]>
commit 5d1b3dea5a44124bab6c14a2d71b977dabed54e7 upstream.
The ov7740_remove() function had a severe teardown order bug where it destroyed the driver's mutex before freeing the V4L2 control handler which relies on that mutex, leading to a use-after-destroy kernel panic. Furthermore, the driver explicitly called v4l2_ctrl_handler_free() and mutex_destroy() sequentially, but then called ov7740_free_controls() which invokes both of them a second time, resulting in a double-free.
This patch fixes the issue by unregistering the subdevice first, and relying exclusively on ov7740_free_controls() to safely tear down the mutex and control handler in the correct order.
--- drivers/media/i2c/ov7740.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/i2c/ov7740.c +1 -3
@@ -1158,10 +1158,8 @@ static void ov7740_remove(struct i2c_clistruct v4l2_subdev *sd =i2c_get_clientdata (client); struct ov7740 *ov7740 = container_of(sd, struct ov7740, subdev); -mutex_destroy (&ov7740->mutex); -v4l2_ctrl_handler_free (ov7740->subdev.ctrl_handler); -media_entity_cleanup (&ov7740->subdev.entity);v4l2_async_unregister_subdev (sd); +media_entity_cleanup (&ov7740->subdev.entity);ov7740_free_controls (ov7740);pm_runtime_get_sync (&client->dev);