6.6.163-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 362/3318 media: go7007: only set audio_enabled if go7007_snd_init() succeeded
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xiang Mei <[email protected]>
commit 2eacf058d2dbb0ae3aaf576459da9e5f2b6bbfbd upstream.
go7007_register_encoder() sets go->audio_enabled before calling go7007_snd_init() and discards its return value. go7007_snd_init() assigns go->snd_context only on success, so a failed ALSA setup leaves audio_enabled set with snd_context still NULL. The disconnect path tests audio_enabled and calls go7007_snd_remove(), which dereferences snd_context unconditionally.
go7007_snd_init() returns -ENODEV once its never-decremented static card counter reaches SNDRV_CARDS, so SNDRV_CARDS attach/detach cycles arm the next attach; no memory pressure is needed.
Set go->audio_enabled only once go7007_snd_init() has succeeded.
Oops: general protection fault, probably for non-canonical address ... KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] Workqueue: usb_hub_wq hub_event RIP: 0010:go7007_snd_remove (drivers/media/usb/go7007/snd-go7007.c:273) Call Trace: go7007_usb_disconnect (drivers/media/usb/go7007/go7007-usb.c:1336) usb_unbind_interface (drivers/usb/core/driver.c:461) device_remove (drivers/base/dd.c:618) device_release_driver_internal (drivers/base/dd.c:1349) bus_remove_device (drivers/base/bus.c:664) device_del (drivers/base/core.c:3965) usb_disable_device (drivers/usb/core/message.c:1478) usb_disconnect hub_event (drivers/usb/core/hub.c:5966) process_one_work (kernel/workqueue.c:3396) worker_thread (kernel/workqueue.c:3560) kthread (kernel/kthread.c:436) ret_from_fork (arch/x86/kernel/process.c:158) ret_from_fork_asm (arch/x86/entry/entry_64.S:245) Kernel panic - not syncing: Fatal exception
--- drivers/media/usb/go7007/go7007-driver.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/usb/go7007/go7007-driver.c +2 -3
@@ -306,10 +306,9 @@ int go7007_register_encoder(struct go700if (ret <0 )return ret; -if (go->board_info->flags &GO7007_BOARD_HAS_AUDIO ) { +if ((go->board_info->flags &GO7007_BOARD_HAS_AUDIO ) && +go7007_snd_init (go) ==0 ) go->audio_enabled =1 ; -go7007_snd_init (go); - }return 0 ; }EXPORT_SYMBOL (go7007_register_encoder);
Greg Kroah-Hartman
maintainerPATCH 363/3318 net: ipv4: add zero check for snd_cwnd_clamp
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kaho Jiang <[email protected]>
commit 363c8c79220d0db4d65dcd570529ddda15067cb5 upstream.
When RTAX_CWND is locked, user is able to pass 0 into it. This could lead to writing 0 to tp->snd_cwnd, leading to a division by zero error.
Oops: divide error: 0000 [#1] SMP KASAN NOPTI Call Trace: <IRQ> tcp_reno_cong_avoid (net/ipv4/tcp_cong.c:510 (discriminator 1)) tcp_ack (net/ipv4/tcp_input.c:3517 net/ipv4/tcp_input.c:3873 net/ipv4/tcp_input.c:4440) tcp_rcv_established (net/ipv4/tcp_input.c:6685) tcp_v4_do_rcv (net/ipv4/tcp_ipv4.c:1854) tcp_v4_rcv (net/ipv4/tcp_ipv4.c:2248) ip_protocol_deliver_rcu (net/ipv4/ip_input.c:207 (discriminator 1)) ip_local_deliver_finish (net/ipv4/ip_input.c:241 (discriminator 1)) ip_local_deliver (./include/linux/netfilter.h:325 ./include/linux/netfilter.h:319 net/ipv4/ip_input.c:262) ip_rcv (./include/net/dst.h:481 (discriminator 6) net/ipv4/ip_input.c:492 (discriminator 6) ./include/linux/netfilter.h:325 (discriminator 6) ./include/li) __netif_receive_skb_one_core (net/core/dev.c:6297 (discriminator 4)) __netif_receive_skb (net/core/dev.c:6410) process_backlog (net/core/dev.c:6761) __napi_poll.constprop.0 (net/core/dev.c:7830) net_rx_action (net/core/dev.c:7893 net/core/dev.c:8050) handle_softirqs (kernel/softirq.c:645) __irq_exit_rcu (kernel/softirq.c:679 kernel/softirq.c:519 kernel/softirq.c:758) irq_exit_rcu (kernel/softirq.c:775) sysvec_apic_timer_interrupt (arch/x86/kernel/apic/apic.c:1062 (discriminator 35) arch/x86/kernel/apic/apic.c:1062 (discriminator 35)) RIP: 0010:tcp_cong_avoid_ai (net/ipv4/tcp_cong.c:482)
Fix by checking if user pass in zero as parameter and if lock is present.
--- net/ipv4/metrics.c | 5 +++++ 1 file changed, 5 insertions(+)
net/ipv4/metrics.c +5 -0
@@ -60,6 +60,11 @@ static int ip_metrics_convert(struct nlaif (ecn_ca) metrics[RTAX_FEATURES -1 ] |=DST_FEATURE_ECN_CA ; +if ((metrics[RTAX_LOCK -1 ] & (1 <<RTAX_CWND )) && !metrics[RTAX_CWND -1 ]) { +NL_SET_ERR_MSG (extack,"Locked cwnd metric must be non zero" ); +return -EINVAL ; + } +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 364/3318 net: usb: pegasus: do not advance rx_skb->data on dropped frames
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wei Jie Law <[email protected]>
commit bfa09dccf98cf78dd9282259b2140bd1472f5ae9 upstream.
For the 0x8513 chip, read_bulk_callback() skips the 2-byte receive header by advancing pegasus->rx_skb->data in place. This is done before the pkt_len > PEGASUS_MTU check, and when that check drops the frame the good path resubmits the same skb with the advanced rx_skb->data as the transfer buffer, still PEGASUS_MTU bytes long.
Every frame with an oversized length field therefore moves the receive buffer two more bytes towards the end of the skb data area. A device that keeps sending such frames makes the host controller write received data over skb_shared_info and past the end of the allocation, and the corrupted skb_shared_info is used when the skb is eventually freed. With an emulated device sending frames filled with 0x5a on a KASAN kernel:
BUG: KASAN: slab-out-of-bounds in dummy_timer+0xade/0x3f00 [dummy_hcd] Write of size 1536 at addr ffff888105821202 by task swapper/1/0 ... Oops: general protection fault, probably for non-canonical address 0xeb4b474b4b4b4b4c: 0000 [#1] PREEMPT SMP KASAN NOPTI KASAN: maybe wild-memory-access in range [0x5a5a5a5a5a5a5a60-0x5a5a5a5a5a5a5a67] RIP: 0010:skb_release_data+0x36f/0x800
Only skip the header with skb_reserve() once the frame is going to be passed up, so the receive buffer always starts at the beginning of the skb data area. Unlike the old pointer adjustment, skb_reserve() also moves skb->tail, so the two header bytes now count against the buffer
size: lower the length limit for the 0x8513 accordingly, otherwise a pkt_len of PEGASUS_MTU - 1 or PEGASUS_MTU would trip skb_over_panic().
Found by code review with LLM assistance and reproduced with an emulated USB device (raw-gadget + dummy_hcd).
--- drivers/net/usb/pegasus.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/usb/pegasus.c +4 -2
@@ -464,6 +464,7 @@ static void read_bulk_callback(struct uru8 *buf = urb->transfer_buffer;int rx_status, count = urb->actual_length;int status = urb->status; +int rx_offset =0 ;__u16 pkt_len;if (!pegasus)
@@ -513,7 +514,7 @@ static void read_bulk_callback(struct urif (pegasus->chip ==0x8513 ) { pkt_len =le32_to_cpu (*(__le32 *)urb->transfer_buffer); pkt_len &=0x0fff ; - pegasus->rx_skb->data +=2 ; + rx_offset =2 ; }else { pkt_len = buf[count -3 ] <<8 ; pkt_len += buf[count -4 ];
@@ -525,13 +526,14 @@ static void read_bulk_callback(struct ur* If the packet is unreasonably long, quietly drop it rather than * kernel panicing by calling skb_put. */ -if (pkt_len >PEGASUS_MTU ) +if (pkt_len >PEGASUS_MTU - rx_offset) goto goon;/* * at this point we are sure pegasus->rx_skb != NULL * so we go ahead and pass up the packet. */ +skb_reserve (pegasus->rx_skb, rx_offset);skb_put (pegasus->rx_skb, pkt_len); pegasus->rx_skb->protocol =eth_type_trans (pegasus->rx_skb, net);netif_rx (pegasus->rx_skb);
Greg Kroah-Hartman
maintainerPATCH 365/3318 ocfs2/dlm: drain join handlers before releasing module text
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
commit 28f366d84023651e50e32e29931401ba0df3e679 upstream.
The code for a registered DLM handler must remain resident until its last invocation finishes. dlm_unregister_net_handlers() only removes dlm_join_handlers from the o2net registry. o2net_handler_get() takes a kref on the wrapper, but that reference does not pin ocfs2_dlm text. o2net_process_message() calls nh_func after dropping o2net_handler_lock.
With CONFIG_OCFS2_FS_O2CB=m, ocfs2_dlm can be loaded independently of ocfs2_stack_o2cb while nodemanager continues handling messages from a configured, heartbeating peer. If no dependent module or module reference prevents normal unload, the following ordering is possible:
Receive worker Module unload
-------------- -------------
o2net_handler_get()
take wrapper kref
drop handler lock
<preempted>
dlm_exit()
unregister handlers
release DLM module text
call saved nh_func
in released module text
Use o2net_unregister_and_flush_handler_list() in the shared DLM unregister helper. It first prevents new lookups, then waits for the ordered o2net workqueue to drain, including a concurrent destruction of that queue. The acquired invocation therefore finishes before dlm_exit() returns and the loader releases the callback code. The same helper covers partial registration and dlm_init() error unwind before module memory is released.
Skip the drain when the private join-handler list is empty. Early dlm_init() failures can reach this helper before any handler has been published. Partial-registration failure also reaches it a second time after the first call has already unregistered and drained the list. Neither case needs to take o2net_wq_mutex or drain unrelated work. The list is changed only by serialized module init/exit paths; a nonempty list still uses the full unregister-and-flush helper.
Oops report as below:
Oops: int3: 0000 [#1] SMP KASAN NOPTI
CPU: 2 UID: 0 PID: 54 Comm: kworker/u16:3 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy)Hardware identification omitted.
Workqueue: o2net o2net_rx_until_empty [ocfs2_nodemanager]
RIP: 0010:0xffffffffc0423871
[Instruction byte dump omitted.]Register dump omitted.
Call Trace:
<TASK>
? o2net_rx_until_empty+0x19b1/0x3300 [ocfs2_nodemanager]
? __pfx_o2net_rx_until_empty+0x10/0x10 [ocfs2_nodemanager]
? lock_acquire+0x190/0x300
? process_one_work+0x935/0x1b40
? process_one_work+0x834/0x1b40
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x290
? srso_alias_return_thunk+0x5/0xfbef5
? process_one_work+0x9a8/0x1b40
? __pfx_process_one_work+0x10/0x10
? lock_acquire+0x190/0x300
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
? worker_thread+0x65c/0xe40
? srso_alias_return_thunk+0x5/0xfbef5
? __kthread_parkme+0x177/0x220
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_worker_thread+0x10/0x10
? kthread+0x351/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
? ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf70
? __pfx_kthread+0x10/0x10
? ret_from_fork_asm+0x1a/0x30
</TASK>
Modules linked in: ocfs2_nodemanager [last unloaded: ocfs2_dlm]
---[ end trace 0000000000000000 ]------ fs/ocfs2/dlm/dlmdomain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ocfs2/dlm/dlmdomain.c +2 -1
@@ -2214,7 +2214,8 @@ static LIST_HEAD(dlm_join_handlers);static void dlm_unregister_net_handlers (void ) { -o2net_unregister_handler_list (&dlm_join_handlers); +if (!list_empty (&dlm_join_handlers)) +o2net_unregister_and_flush_handler_list (&dlm_join_handlers); }static int dlm_register_net_handlers (void )
Greg Kroah-Hartman
maintainerPATCH 366/3318 ocfs2: drain quorum work before removing the cluster
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
commit b584c45b6066fd9799c44ffb9badcb5db351c8a6 upstream.
The configured cluster must remain available until an in-flight quorum decision has finished using its fencing method. o2quo_make_decision() drops qs_lock before calling o2quo_fence_self(), which marks heartbeat regions for unclean stop and then reads o2nm_single_cluster->cl_fence_method. Cluster removal clears the singleton without waiting for this independent system-workqueue item.
When a failed-quorum decision overlaps removal of the heartbeat regions, nodes and cluster through configfs, the worker can be preempted after marking the regions and resume after the singleton has been cleared:
Quorum worker Configfs removal
select fence; drop qs_lock
o2hb_stop_all_regions()
remove regions; join heartbeat threads remove nodes; stop o2net clear singleton; release cluster
read cl_fence_method
The resumed read dereferences NULL instead of applying the configured fencing method. The heartbeat thread's dependency protects the local node only until the thread exits, and draining o2net does not wait for qs_work.
Add o2quo_flush_work() to drain pending or running quorum decisions before clearing the singleton in o2nm_cluster_group_drop_item(). By this point the heartbeat regions and nodes have been removed, so their work publishers are stopped. The worker can finish while the cluster and its configured fencing method remain available. It does not acquire the configfs mutex held by the removal path.
Keep o2quo_exit() as the counterpart of o2quo_init() for module teardown and initialization failure, and have it call the same drain helper. Cluster removal uses only the explicitly named drain operation.
KASAN report as below:
Oops: general protection fault, probably for non-canonical address 0xdffffc000000011b: 0000 [#1] SMP KASAN NOPTI
KASAN: null-ptr-deref in range [0x00000000000008d8-0x00000000000008df]
CPU: 0 UID: 0 PID: 72 Comm: kworker/0:2 Not tainted 7.3.0-rc4-next-20260921-pmb-ocfs2-functional-v1+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Workqueue: events o2quo_make_decision
RIP: 0010:o2quo_fence_self+0x65/0x200Register dump omitted.
Call Trace:
<TASK>
o2quo_make_decision+0x345/0x3a0
? __pfx_o2quo_make_decision+0x10/0x10
? process_one_work+0x834/0x1b40
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x290
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x9a8/0x1b40
? __pfx_process_one_work+0x10/0x10
? lock_acquire+0x190/0x300
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? srso_alias_return_thunk+0x5/0xfbef5
? __kthread_parkme+0x177/0x220
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_worker_thread+0x10/0x10
kthread+0x351/0x460
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_kthread+0x10/0x10
ret_from_fork+0x659/0x940
? __pfx_ret_from_fork+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __switch_to+0x74f/0xf70
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]------ fs/ocfs2/cluster/nodemanager.c | 3 +++ fs/ocfs2/cluster/quorum.c | 7 ++++++- fs/ocfs2/cluster/quorum.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-)
fs/ocfs2/cluster/nodemanager.c +3 -0
@@ -11,6 +11,7 @@#include "tcp.h" #include "nodemanager.h" #include "heartbeat.h" +#include "quorum.h" #include "masklog.h" #include "sys.h"
@@ -739,6 +740,8 @@ static void o2nm_cluster_group_drop_itemstruct o2nm_cluster *cluster =to_o2nm_cluster (item);BUG_ON (o2nm_single_cluster != cluster); +/* Drain quorum work before it loses access to the cluster. */ +o2quo_flush_work (); o2nm_single_cluster =NULL ;configfs_remove_default_groups (&cluster->cl_group);
fs/ocfs2/cluster/quorum.c +6 -1
@@ -318,9 +318,14 @@ void o2quo_init(void)INIT_WORK (&qs->qs_work, o2quo_make_decision); } -void o2quo_exit (void ) +void o2quo_flush_work (void ) {struct o2quo_state *qs = &o2quo_state;flush_work (&qs->qs_work); } + +void o2quo_exit (void ) +{ +o2quo_flush_work (); +}
fs/ocfs2/cluster/quorum.h +1 -0
@@ -8,6 +8,7 @@void o2quo_init (void );void o2quo_exit (void ); +void o2quo_flush_work (void );void o2quo_hb_up (u8 node);void o2quo_hb_down (u8 node);
Greg Kroah-Hartman
maintainerPATCH 367/3318 ocfs2: pin owning modules for open debugfs files
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
commit 26d7e34b4226709084461a07bf28d9066fa96d8c upstream.
The OCFS2 debugfs file operation tables do not set owner. The full debugfs proxy obtains real_fops with fops_get() at open and keeps it until final release. Without an owner, this does not acquire a reference to the module containing the table and its callbacks. Removing the debugfs entries does not drain retained open files.
An open connected_nodes file can therefore outlive ocfs2_nodemanager and make full_proxy_release() read real_fops->release from freed module memory. Heming also reproduced the issue with fs_state and asked for the other OCFS2 debugfs operation tables to be checked.
Set owner to THIS_MODULE in all eleven explicit debugfs operation
tables: five in ocfs2_nodemanager, four in ocfs2_dlm, and two in ocfs2. The existing debugfs get/put pair then holds the appropriate module until final release. Leave the open, read and release callbacks unchanged. The blockcheck table already sets owner through DEFINE_DEBUGFS_ATTRIBUTE(), so it needs no change.
The original controlled test used an unloadable OCFS2 module and case-local probe filters without changing the candidate open, unload or release logic. Closing a retained connected_nodes file after normal unload produced:
BUG: unable to handle page fault for address: fffffbfff804cfef Oops: Oops: 0000 [#1] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0xbf/0x190 Call Trace: <TASK> __fput+0x39a/0xa60 fput_close_sync+0xff/0x200 __x64_sys_close+0x8c/0xf0 do_syscall_64+0x114/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Modules linked in: [last unloaded: ocfs2_nodemanager]
--- fs/ocfs2/cluster/heartbeat.c | 1 + fs/ocfs2/cluster/netdebug.c | 4 ++++ fs/ocfs2/dlm/dlmdebug.c | 5 +++++ fs/ocfs2/dlmglue.c | 2 ++ fs/ocfs2/super.c | 1 + 5 files changed, 13 insertions(+)
fs/ocfs2/cluster/heartbeat.c +1 -0
@@ -1420,6 +1420,7 @@ static ssize_t o2hb_debug_read(struct fi#endif /* CONFIG_DEBUG_FS */ static const struct file_operations o2hb_debug_fops = { + .owner =THIS_MODULE , .open = o2hb_debug_open, .release = o2hb_debug_release, .read = o2hb_debug_read,
fs/ocfs2/cluster/netdebug.c +4 -0
@@ -183,6 +183,7 @@ static int nst_fop_release(struct inode }static const struct file_operations nst_seq_fops = { + .owner =THIS_MODULE , .open = nst_fop_open, .read = seq_read, .llseek = seq_lseek,
@@ -415,6 +416,7 @@ static int stats_fop_open(struct inode * }static const struct file_operations stats_seq_fops = { + .owner =THIS_MODULE , .open = stats_fop_open, .read = seq_read, .llseek = seq_lseek,
@@ -427,6 +429,7 @@ static int sc_fop_open(struct inode *ino }static const struct file_operations sc_seq_fops = { + .owner =THIS_MODULE , .open = sc_fop_open, .read = seq_read, .llseek = seq_lseek,
@@ -476,6 +479,7 @@ static ssize_t o2net_debug_read(struct f }static const struct file_operations nodes_fops = { + .owner =THIS_MODULE , .open = nodes_fop_open, .release = o2net_debug_release, .read = o2net_debug_read,
fs/ocfs2/dlm/dlmdebug.c +5 -0
@@ -7,6 +7,7 @@* Copyright (C) 2004, 2008 Oracle. All rights reserved. */ +#include <linux/module.h> #include <linux/types.h> #include <linux/slab.h> #include <linux/highmem.h>
@@ -393,6 +394,7 @@ bail: }static const struct file_operations debug_purgelist_fops = { + .owner =THIS_MODULE , .open = debug_purgelist_open, .release = debug_release, .read = debug_read,
@@ -450,6 +452,7 @@ bail: }static const struct file_operations debug_mle_fops = { + .owner =THIS_MODULE , .open = debug_mle_open, .release = debug_release, .read = debug_read,
@@ -657,6 +660,7 @@ static int debug_lockres_release(struct }static const struct file_operations debug_lockres_fops = { + .owner =THIS_MODULE , .open = debug_lockres_open, .release = debug_lockres_release, .read = seq_read,
@@ -852,6 +856,7 @@ bail: }static const struct file_operations debug_state_fops = { + .owner =THIS_MODULE , .open = debug_state_open, .release = debug_release, .read = debug_read,
fs/ocfs2/dlmglue.c +2 -0
@@ -7,6 +7,7 @@* Copyright (C) 2003, 2004 Oracle. All rights reserved. */ +#include <linux/module.h> #include <linux/types.h> #include <linux/slab.h> #include <linux/highmem.h>
@@ -3315,6 +3316,7 @@ static int ocfs2_dlm_debug_open(struct i }static const struct file_operations ocfs2_dlm_debug_fops = { + .owner =THIS_MODULE , .open = ocfs2_dlm_debug_open, .release = ocfs2_dlm_debug_release, .read = seq_read,
fs/ocfs2/super.c +1 -0
@@ -383,6 +383,7 @@ static ssize_t ocfs2_debug_read(struct f#endif /* CONFIG_DEBUG_FS */ static const struct file_operations ocfs2_osb_debug_fops = { + .owner =THIS_MODULE , .open = ocfs2_osb_debug_open, .release = ocfs2_debug_release, .read = ocfs2_debug_read,
Greg Kroah-Hartman
maintainerPATCH 368/3318 ocfs2: publish the filecheck owner before adding sysfs attributes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
commit e062baf5680845705d21df415c8f0751c96b0792 upstream.
ocfs2_filecheck_create_sysfs() initializes the filecheck allocation before calling kobject_init_and_add(), but assigns entry->fs_fcheck only after that call returns. The default attribute group can already be visible while registration is in progress. A concurrent read can therefore enter ocfs2_filecheck_attr_show() with a NULL fs_fcheck and try to lock its fc_lock.
Assign the initialized owner before adding the kobject, so every activated attribute has valid state. Clear the pointer when addition fails, preserving the existing teardown guard and error cleanup.
A controlled probe-instrumented test kernel with the original OCFS2 registration ordering produced this Oops during a concurrent sysfs read:
KASAN: null-ptr-deref in range [0x0000000000000028-0x000000000000002f] RIP: 0010:kasan_byte_accessible+0x15/0x30 Call Trace: <TASK> __kasan_check_byte+0x13/0x50 lock_acquire+0x113/0x300 _raw_spin_lock+0x31/0x40 ocfs2_filecheck_attr_show+0x138/0x5f0 ocfs2_filecheck_show+0x5d/0x90 sysfs_kf_seq_show+0x1d3/0x360 seq_read_iter+0x480/0x1110 kernfs_fop_read_iter+0x419/0x5a0 vfs_read+0x7d2/0xc20 ksys_read+0x111/0x200 do_syscall_64+0x114/0x620 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK> Modules linked in:
--- fs/ocfs2/filecheck.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/ocfs2/filecheck.c +4 -1
@@ -179,17 +179,20 @@ int ocfs2_filecheck_create_sysfs(struct fcheck->fc_size =0 ; fcheck->fc_done =0 ; +/* Publish the initialized owner before activating its sysfs callbacks. */ + entry->fs_fcheck = fcheck; entry->fs_kobj.kset = osb->osb_dev_kset;init_completion (&entry->fs_kobj_unregister); ret =kobject_init_and_add (&entry->fs_kobj, &ocfs2_ktype_filecheck,NULL ,"filecheck" );if (ret) { +/* Mount failure still calls ocfs2_filecheck_remove_sysfs(). */ + entry->fs_fcheck =NULL ;kobject_put (&entry->fs_kobj);kfree (fcheck);return ret; } - entry->fs_fcheck = fcheck;return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 369/3318 thunderbolt: Do not RPM complete unrelated subtrees on unplug
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonathan Gopel <[email protected]>
commit 96a8479804e3f7af43e639e9df39f562f1a75fd5 upstream.
When a Thunderbolt device is unplugged, that switch and every switch subsequent to it on the bus device list is complete()d, not just its child devices. In the case of multiple domains, it may cause, eg, an attempt to complete() the uninitialized domain 1 root switch RPM completion on unplug of a switch from domain 0 (though ordering is not guaranteed numerically sorted).
I initially noticed this issue on a Dell XPS9720 when the system would seem to sporadically not wake after unplugging a Thunderbolt dock. I tried multiple kernel versions including v7.2.7 and v7.3-rc4 to see if that resolved the issue, but the issue persisted. Eventually I found that I could consistently generate a kernel Oops reporting a page fault at 0xffff_ffff_ffff_fff8 on unplug from one side of the laptop and went bug hunting. I became suspicious of the bus_for_each_dev() walk that I ultimately ended up changing. To confirm this issue, I did an eBPF trace of bus_for_each_dev(), complete_rpm(), and complete() while unplugging in a variety of situations and found that an unplug from domain 0 tries to complete_rpm() domain 1's switch, whose RPM completion is not initialized and thus is holding a null wait-list pointer, triggering the page fault.
Here are the key sections of that eBPF trace. Note that HEAD denotes the completion's own wait-list HEAD:
```
RESCAN_ENTER domain=0
COMPLETE rescan_domain=0 target=0-1 target_domain=0
route=0x1 parent=0-0 unplugged=1
COMPLETION done=0 head=HEAD next=HEAD prev=HEAD
BUS_WALK domain=0 start=0-1 callback=complete_rpm
CALLBACK_ENTER rescan_domain=0 dev=1-0 parent=domain1 is_switch=1
COMPLETE rescan_domain=0 target=1-0 target_domain=1
route=0x0 parent=domain1 unplugged=0
COMPLETION done=0 head=HEAD next=0 prev=0
complete+5
complete_rpm+43
bus_for_each_dev+133
icm_free_unplugged_children+250
icm_rescan_work+42
```This patch gates the complete() on an additional condition - that the Thunderbolt domain matches the domain of the device that was unplugged.
I only have a single system with multiple Thunderbolt domains - the Dell XPS9720. I am consistently able to reproduce the Oops on that system. Since running with this patch, I have not seen the Oops reoccur. I have also tested it on a Thinkpad X1-Gen12, and that system boots and runs well with it, but it only has a single Thunderbolt domain, so it does not exercise the multi-domain failure case.
--- drivers/thunderbolt/icm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/thunderbolt/icm.c +3 -3
@@ -2034,7 +2034,7 @@ static int complete_rpm(struct device *d {struct tb_switch *sw =tb_to_switch (dev); -if (sw) +if (sw && sw->tb == data)complete (&sw->rpm_complete);return 0 ; }
@@ -2050,8 +2050,8 @@ static void remove_unplugged_switch(stru* tb_switch_remove() calls pm_runtime_get_sync() that then waits * for it. */ -complete_rpm (&sw->dev,NULL ); -bus_for_each_dev (&tb_bus_type, &sw->dev,NULL , complete_rpm); +complete_rpm (&sw->dev, sw->tb); +bus_for_each_dev (&tb_bus_type, &sw->dev, sw->tb, complete_rpm);tb_switch_remove (sw);pm_runtime_mark_last_busy (parent);
Greg Kroah-Hartman
maintainerPATCH 370/3318 udf: fix return value for non-recorded-allocated extents in udf_map_block()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giorgi Kobakhia <[email protected]>
commit 0f242ca0878896df30292f4922700a32e8fdd039 upstream.
When someone creates a corrupted UDF filesystem where symlink contains other extent type than EXT_RECORDED_ALLOCATED, it can leads to a crash like:
Oops: general protection fault KASAN: maybe wild-memory-access RIP: 0010:page_get_link (fs/namei.c:6503) Call Trace: vfs_readlink (fs/namei.c:6419) do_readlinkat (fs/stat.c:583) __x64_sys_readlink (fs/stat.c:605 fs/stat.c:602 fs/stat.c:602)
This is because in this case udf_map_block() fails to convert return value of inode_bmap() from 1 to 0. Returned '1' propagates through udf_bread() all the way up to __page_get_link() where it ends up being treated as a folio pointer with obvious results.
Move the reset to 0 line outside the if, so udf_map_block() returns either 0 or -errno, even if the extent type is not EXT_RECORDED_ALLOCATED.
--- fs/udf/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/udf/inode.c +1 -1
@@ -441,8 +441,8 @@ static int udf_map_block(struct inode *i map->pblk =udf_get_lb_pblock (inode->i_sb, &eloc, offset); map->oflags |=UDF_BLK_MAPPED ; - ret =0 ; } + ret =0 ; out_read:up_read (&iinfo->i_data_sem);brelse (epos.bh);
Greg Kroah-Hartman
maintainerPATCH 371/3318 wwan: wwan_hwsim: Pin module for debugfs file operations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bui Viet Dung <[email protected]>
commit a388f17e23b7e305cb306aafd73bb10d6b8ca452 upstream.
An open debugfs file retains its file_operations pointer in the debugfs proxy state. However, wwan_hwsim_debugfs_portdestroy_fops, wwan_hwsim_debugfs_portcreate_fops, wwan_hwsim_debugfs_devdestroy_fops, and wwan_hwsim_debugfs_devcreate_fops in wwan_hwsim.c have no .owner set to THIS_MODULE.
As a result, full_proxy_open_regular() calls fops_get() which succeeds without taking a reference to the wwan_hwsim module. When a userspace process opens any of these debugfs files, a subsequent module unload (rmmod wwan_hwsim) can succeed while the file descriptor remains open.
When the userspace process subsequently closes the descriptor, full_proxy_release() accesses the already unmapped file_operations structure, triggering a kernel oops in full_proxy_release():
BUG: unable to handle page fault for address: fffffbfff84f90ef Oops: 0000 [#2] SMP KASAN NOPTI RIP: 0010:full_proxy_release+0x8e/0x140 Call Trace: <TASK> __fput+0x357/0xaa0 fput_close_sync+0xe6/0x1a0 file_close_fd_locked+0x17e/0x2f0 do_close+0x33/0x70 __x64_sys_close+0x44/0x80 do_syscall_64+0xc3/0x590 entry_SYSCALL_64_after_hwframe+0x76/0x7e </TASK>
The issue was discovered via manual code audit of wwan_hwsim.c and reproduced on a Linux 7.3-rc6 test VM with CONFIG_WWAN_HWSIM=m.
Set .owner = THIS_MODULE on all four debugfs file_operations structures in wwan_hwsim.c so that debugfs pins the module until close has completed.
--- drivers/net/wwan/wwan_hwsim.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/wwan/wwan_hwsim.c +4 -0
@@ -378,6 +378,7 @@ static ssize_t wwan_hwsim_debugfs_portde }static const struct file_operations wwan_hwsim_debugfs_portdestroy_fops = { + .owner =THIS_MODULE , .write = wwan_hwsim_debugfs_portdestroy_write, .open = simple_open, .llseek = noop_llseek,
@@ -402,6 +403,7 @@ static ssize_t wwan_hwsim_debugfs_portcr }static const struct file_operations wwan_hwsim_debugfs_portcreate_fops = { + .owner =THIS_MODULE , .write = wwan_hwsim_debugfs_portcreate_write, .open = simple_open, .llseek = noop_llseek,
@@ -423,6 +425,7 @@ static ssize_t wwan_hwsim_debugfs_devdes }static const struct file_operations wwan_hwsim_debugfs_devdestroy_fops = { + .owner =THIS_MODULE , .write = wwan_hwsim_debugfs_devdestroy_write, .open = simple_open, .llseek = noop_llseek,
@@ -446,6 +449,7 @@ static ssize_t wwan_hwsim_debugfs_devcre }static const struct file_operations wwan_hwsim_debugfs_devcreate_fops = { + .owner =THIS_MODULE , .write = wwan_hwsim_debugfs_devcreate_write, .open = simple_open, .llseek = noop_llseek,
Greg Kroah-Hartman
maintainerPATCH 372/3318 netfilter: nf_conntrack_expect: add and use nf_ct_expect_related_pair()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
commit 4aa63842fc92de1bce59d4709a0d32e718890bb2 upstream.
Add a new function to insert a pair of expectations, this is required by the SIP and H323 NAT helpers. The spinlock is held to check if there is a slot for both expectations, in such case, insert them.
This removes the need for nf_ct_unexpect_related() inside the loop to find a pair of consecutive ports, otherwise inserting expectations whose dead flag is already set on can happen.
Bump master_help->expecting for the expectation class after checking if the expectation fits in the master expectation list, which is needed for this new _pair() function variant to run the eviction routine including the preallocated slot for the first expectation in the pair.
[ Joas: nf_ct_expect_insert() and __nf_ct_expect_check() do not take
a master_help argument in this tree, so keep their existing signatures; nf_ct_expect_related_report() gets master_help from nfct_help(expect->master) for the moved expecting[] increment. ]
--- include/net/netfilter/nf_conntrack_expect.h | 3 ++ net/ipv4/netfilter/nf_nat_h323.c | 22 +++++-------- net/netfilter/nf_conntrack_expect.c | 35 ++++++++++++++++++++- net/netfilter/nf_nat_sip.c | 20 ++++-------- 4 files changed, 50 insertions(+), 30 deletions(-)
include/net/netfilter/nf_conntrack_expect.h +3 -0
@@ -160,6 +160,9 @@ static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect,return nf_ct_expect_related_report (expect,0 ,0 , flags); } +int nf_ct_expect_related_pair (struct nf_conntrack_expect *expect[], +unsigned int flag); +struct nf_conn_help ;void nf_ct_expectation_gc (struct nf_conn_help *master_help);
net/ipv4/netfilter/nf_nat_h323.c +7 -15
@@ -179,6 +179,7 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,struct nf_conntrack_expect *rtp_exp, struct nf_conntrack_expect *rtcp_exp) { + struct nf_conntrack_expect *rtp_pair[2] = { rtp_exp, rtcp_exp };struct nf_ct_h323_master *info =nfct_help_data (ct);int dir =CTINFO2DIR (ctinfo);int i;
@@ -221,22 +222,13 @@ static int nat_rtp_rtcp(struct sk_buff *skb, struct nf_conn *ct,int ret; rtp_exp->tuple.dst.u.udp.port =htons (nated_port); - ret =nf_ct_expect_related (rtp_exp,0 ); + rtcp_exp->tuple.dst.u.udp.port =htons (nated_port +1 ); + ret =nf_ct_expect_related_pair (rtp_pair,0 );if (ret ==0 ) { - rtcp_exp->tuple.dst.u.udp.port = -htons (nated_port +1 ); - ret =nf_ct_expect_related (rtcp_exp,0 ); -if (ret ==0 ) -break ; -else if (ret == -EBUSY ) { -nf_ct_unexpect_related (rtp_exp); -continue ; - }else if (ret <0 ) { -nf_ct_unexpect_related (rtp_exp); - nated_port =0 ; -break ; - } - }else if (ret != -EBUSY ) { +break ; + }else if (ret == -EBUSY ) { +continue ; + }else if (ret <0 ) { nated_port =0 ;break ; }
net/netfilter/nf_conntrack_expect.c +34 -1
@@ -425,7 +425,6 @@ static void nf_ct_expect_insert(struct nf_conntrack_expect *exp) exp->timeout += helper->expect_policy[exp->class].timeout *HZ ;hlist_add_head_rcu (&exp->lnode, &master_help->expectations); - master_help->expecting[exp->class]++;hlist_add_head_rcu (&exp->hnode, &nf_ct_expect_hash[h]); cnet =nf_ct_pernet (net);
@@ -525,6 +524,7 @@ int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,if (ret <0 ) goto out; +nfct_help (expect->master)->expecting[expect->class]++;nf_ct_expect_insert (expect);nf_ct_expect_event_report (IPEXP_NEW , expect, portid, report);
@@ -537,6 +537,39 @@ int nf_ct_expect_related_report(struct nf_conntrack_expect *expect, }EXPORT_SYMBOL_GPL (nf_ct_expect_related_report); +int nf_ct_expect_related_pair (struct nf_conntrack_expect *expect[], +unsigned int flags) +{ +struct nf_conn_help *master_help; +int i, ret; + +spin_lock_bh (&nf_conntrack_expect_lock); + master_help =nfct_help (expect[0 ]->master); +if (!master_help || master_help !=nfct_help (expect[1 ]->master)) { + ret = -EINVAL ; + goto out; + } + +for (i =0 ; i <2 ; i++) { + ret =__nf_ct_expect_check (expect[i], flags); +if (ret <0 ) { +if (i ==1 ) + master_help->expecting[expect[0 ]->class]--; + goto out; + } + master_help->expecting[expect[i]->class]++; + } + +for (i =0 ; i <2 ; i++) { +nf_ct_expect_insert (expect[i]); +nf_ct_expect_event_report (IPEXP_NEW , expect[i],0 ,0 ); + } +out: +spin_unlock_bh (&nf_conntrack_expect_lock); +return ret; +} +EXPORT_SYMBOL_GPL (nf_ct_expect_related_pair); +void nf_ct_expect_iterate_destroy (bool (*iter)(struct nf_conntrack_expect *e,void *data),void *data) {
net/netfilter/nf_nat_sip.c +6 -14
@@ -585,6 +585,7 @@ static unsigned int nf_nat_sdp_media(struct sk_buff *skb, unsigned int protoff,unsigned int medialen, union nf_inet_addr *rtp_addr) { + struct nf_conntrack_expect *rtp_pair[2] = { rtp_exp, rtcp_exp };enum ip_conntrack_info ctinfo;struct nf_conn *ct =nf_ct_get (skb, &ctinfo);enum ip_conntrack_dir dir =CTINFO2DIR (ctinfo);
@@ -615,24 +616,15 @@ static unsigned int nf_nat_sdp_media(struct sk_buff *skb, unsigned int protoff,int ret; rtp_exp->tuple.dst.u.udp.port =htons (port); - ret =nf_ct_expect_related (rtp_exp, -NF_CT_EXP_F_SKIP_MASTER ); -if (ret == -EBUSY ) -continue ; -else if (ret <0 ) { - port =0 ; -break ; - } rtcp_exp->tuple.dst.u.udp.port =htons (port +1 ); - ret =nf_ct_expect_related (rtcp_exp, -NF_CT_EXP_F_SKIP_MASTER ); + + ret =nf_ct_expect_related_pair (rtp_pair, +NF_CT_EXP_F_SKIP_MASTER );if (ret ==0 )break ; -else if (ret == -EBUSY ) { -nf_ct_unexpect_related (rtp_exp); +else if (ret == -EBUSY )continue ; - }else if (ret <0 ) { -nf_ct_unexpect_related (rtp_exp); +else if (ret <0 ) { port =0 ;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 373/3318 netfilter: ctnetlink: do not expose expectation DEAD flag
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pablo Neira Ayuso <[email protected]>
[ Upstream commit 322371b09058ad10d0282a0e7ec8eaa764e6aaac ]
Expose expectation flags included in the NF_CT_EXPECT_MASK bitmask only. The DEAD flag is internal, do not expose it.
--- net/netfilter/nf_conntrack_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -3039,7 +3039,7 @@ ctnetlink_exp_dump_expect(struct sk_buff *skb,#endif if (nla_put_be32 (skb,CTA_EXPECT_TIMEOUT ,htonl (timeout)) ||nla_put_be32 (skb,CTA_EXPECT_ID ,nf_expect_get_id (exp)) || -nla_put_be32 (skb,CTA_EXPECT_FLAGS ,htonl (exp->flags)) || +nla_put_be32 (skb,CTA_EXPECT_FLAGS ,htonl (exp->flags &NF_CT_EXPECT_MASK )) ||nla_put_be32 (skb,CTA_EXPECT_CLASS ,htonl (exp->class))) goto nla_put_failure;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 374/3318 sctp: auth: discard auth_chunk when skb_clone fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qing Luo <[email protected]>
[ Upstream commit 9ae7ed101cf28613071ebfbc42668c8917a670cf ]
When processing AUTH + COOKIE-ECHO packets, if skb_clone() fails due to memory pressure, chunk->auth_chunk is NULL. The original code still sets chunk->auth = 1 and continues, leaving the COOKIE-ECHO to be processed without a valid auth_chunk for deferred verification.
Discard the AUTH chunk early via pdiscard when skb_clone() fails, so that the receive loop can continue processing remaining chunks in the inqueue instead of stalling the entire packet.
--- net/sctp/associola.c | 4 ++++ net/sctp/endpointola.c | 4 ++++ 2 files changed, 8 insertions(+)
net/sctp/associola.c +4 -0
@@ -1027,6 +1027,10 @@ static void sctp_assoc_bh_rcv(struct work_struct *work)if (next_hdr->type ==SCTP_CID_COOKIE_ECHO ) { chunk->auth_chunk =skb_clone (chunk->skb,GFP_ATOMIC ); +if (!chunk->auth_chunk) { + chunk->pdiscard =1 ; +continue ; + } chunk->auth =1 ;continue ; }
net/sctp/endpointola.c +4 -0
@@ -367,6 +367,10 @@ static void sctp_endpoint_bh_rcv(struct work_struct *work)if (next_hdr->type ==SCTP_CID_COOKIE_ECHO ) { chunk->auth_chunk =skb_clone (chunk->skb,GFP_ATOMIC ); +if (!chunk->auth_chunk) { + chunk->pdiscard =1 ; +continue ; + } chunk->auth =1 ;continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 375/3318 mtd: rawnand: pl353: Add message about ECC mode
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andrea Scian <[email protected]>
[ Upstream commit 1e06dbfdfb851170b243d6498e442b449324c664 ]
This just add some information on kernel log about the selected ECC
Stable-dep-of: 80ecacd054ff ("mtd: rawnand: pl353: Make sure we use the monolithic helpers for raw accesses")
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/nand/raw/pl35x-nand-controller.c +3 -0
@@ -973,15 +973,18 @@ static int pl35x_nand_attach_chip(struct nand_chip *chip)switch (chip->ecc.engine_type) {case NAND_ECC_ENGINE_TYPE_ON_DIE : +dev_dbg (nfc->dev,"Using on-die ECC\n" );/* Keep these legacy BBT descriptors for ON_DIE situations */ chip->bbt_td = &bbt_main_descr; chip->bbt_md = &bbt_mirror_descr; fallthrough;case NAND_ECC_ENGINE_TYPE_NONE :case NAND_ECC_ENGINE_TYPE_SOFT : +dev_dbg (nfc->dev,"Using software ECC (Hamming 1-bit/512B)\n" ); chip->ecc.write_page_raw = nand_monolithic_write_page_raw;break ;case NAND_ECC_ENGINE_TYPE_ON_HOST : +dev_dbg (nfc->dev,"Using hardware ECC\n" ); ret =pl35x_nand_init_hw_ecc_controller (nfc, chip);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 376/3318 mtd: rawnand: pl353: Make sure we use the monolithic helpers for raw accesses
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal (DAVE) <[email protected]>
[ Upstream commit 80ecacd054ffeb60cd28e46ed5cd6bd0d2de318b ]
Any access not using the hardware ECC engine should be monolithic because the controller has its very own way of handling the end of a transaction during operation configuration, so we cannot easily make repeated reads.
This has the side effect of fixing support for software ECC engines.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/pl35x-nand-controller.c +3 -2
@@ -914,7 +914,6 @@ static int pl35x_nand_init_hw_ecc_controller(struct pl35x_nandc *nfc, chip->ecc.steps = mtd->writesize / chip->ecc.size; chip->ecc.read_page = pl35x_nand_read_page_hwecc; chip->ecc.write_page = pl35x_nand_write_page_hwecc; - chip->ecc.write_page_raw = nand_monolithic_write_page_raw;pl35x_smc_set_ecc_pg_size (nfc, chip, mtd->writesize); nfc->ecc_buf = devm_kmalloc(nfc->dev, chip->ecc.bytes * chip->ecc.steps,
@@ -981,7 +980,6 @@ static int pl35x_nand_attach_chip(struct nand_chip *chip)case NAND_ECC_ENGINE_TYPE_NONE :case NAND_ECC_ENGINE_TYPE_SOFT :dev_dbg (nfc->dev,"Using software ECC (Hamming 1-bit/512B)\n" ); - chip->ecc.write_page_raw = nand_monolithic_write_page_raw;break ;case NAND_ECC_ENGINE_TYPE_ON_HOST :dev_dbg (nfc->dev,"Using hardware ECC\n" );
@@ -995,6 +993,9 @@ static int pl35x_nand_attach_chip(struct nand_chip *chip)return -EINVAL ; } + chip->ecc.read_page_raw = nand_monolithic_read_page_raw; + chip->ecc.write_page_raw = nand_monolithic_write_page_raw; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 377/3318 drm/sysfb: simpledrm: Improve framebuffer-size validation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Zimmermann <[email protected]>
[ Upstream commit 03f1a3545b721fa7fdadd00080e237519a286a97 ]
Validate the framebuffer size from the firmware against the limitations of struct drm_display_mode. The type only stores sizes in 16-bit fields. Fail probing on errors.
v2:
- remove unused function simplefb_get_validated_int0() (Sashiko)
--- drivers/gpu/drm/tiny/simpledrm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/tiny/simpledrm.c +2 -2
@@ -52,12 +52,12 @@ static int simplefb_get_validated_int0(struct drm_device *dev, const char *name, uint32_t value) { - if (!value) { + if (!value || value > U16_MAX) { drm_err(dev, "simplefb: invalid framebuffer %s of %u\n", name, value);return -EINVAL ; } -return simplefb_get_validated_int (dev, name, value); +return (int )value; } static const struct drm_format_info *
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 378/3318 KVM: nVMX: Decouple INVVPID operand checks from flushing of vpid02
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sean Christopherson <[email protected]>
[ Upstream commit 32912404b4b1ee98400744941c78f019a63d6e8f ]
Separate the INVVPID operand checks from the actual flushing of vpid02 so the flushing can be adjusted to do the right thing when vmcs02 was last loaded on a different pCPU, without having to duplicate the logic across multiple case-statements.
Opportunistically let the VM-Fail paths poke out past 80 chars.
No functional change intended.
--- arch/x86/kvm/vmx/nested.c | 57 +++++++++++---------------------------- 1 file changed, 16 insertions(+), 41 deletions(-)
arch/x86/kvm/vmx/nested.c +16 -41
@@ -5855,7 +5855,6 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)u64 vpid;u64 gla; } operand; -u16 vpid02;int r, gpr_index;int cpu;
@@ -5891,8 +5890,14 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)return kvm_handle_memory_failure (vcpu, r, &e);if (operand.vpid >>16 ) -return nested_vmx_fail (vcpu, -VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); +return nested_vmx_fail (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); + +if (type !=VMX_VPID_EXTENT_ALL_CONTEXT && !operand.vpid) +return nested_vmx_fail (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); + +if (type ==VMX_VPID_EXTENT_INDIVIDUAL_ADDR && +is_noncanonical_address (operand.gla, vcpu)) +return nested_vmx_fail (vcpu,VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID );/* * Always flush the effective vpid02, i.e. never flush the current VPID
@@ -5904,44 +5909,14 @@ static int handle_invvpid(struct kvm_vcpu *vcpu)* by invalidating the nested VPID tracking to ensure that KVM performs * the invalidation on the correct pCPU. */ - vpid02 =nested_get_vpid02 (vcpu); -switch (type) { -case VMX_VPID_EXTENT_INDIVIDUAL_ADDR : -if (!operand.vpid || -is_noncanonical_address (operand.gla, vcpu)) -return nested_vmx_fail (vcpu, -VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); - cpu =get_cpu (); -if (cpu != vmx->nested.vmcs02.cpu) - vmx->nested.last_vpid =0 ; -else -vpid_sync_vcpu_addr (vpid02, operand.gla); -put_cpu (); -break ; -case VMX_VPID_EXTENT_SINGLE_CONTEXT : -case VMX_VPID_EXTENT_SINGLE_NON_GLOBAL : -if (!operand.vpid) -return nested_vmx_fail (vcpu, -VMXERR_INVALID_OPERAND_TO_INVEPT_INVVPID ); - cpu =get_cpu (); -if (cpu != vmx->nested.vmcs02.cpu) - vmx->nested.last_vpid =0 ; -else -vpid_sync_context (vpid02); -put_cpu (); -break ; -case VMX_VPID_EXTENT_ALL_CONTEXT : - cpu =get_cpu (); -if (cpu != vmx->nested.vmcs02.cpu) - vmx->nested.last_vpid =0 ; -else -vpid_sync_context (vpid02); -put_cpu (); -break ; -default : -WARN_ON_ONCE (1 ); -return kvm_skip_emulated_instruction (vcpu); - } + cpu =get_cpu (); +if (cpu != vmx->nested.vmcs02.cpu) + vmx->nested.last_vpid =0 ; +else if (type ==VMX_VPID_EXTENT_INDIVIDUAL_ADDR ) +vpid_sync_vcpu_addr (nested_get_vpid02 (vcpu), operand.gla); +else +vpid_sync_context (nested_get_vpid02 (vcpu)); +put_cpu ();/* * Sync the shadow page tables if EPT is disabled, L1 is invalidating
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 379/3318 platform/x86: lenovo/ymc: Only match lower byte in WMI lid switch query response
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Julian Haarmann <[email protected]>
[ Upstream commit bbc497b5231829d32c3a53b6e66be1add76c0064 ]
On newer Lenovo Yoga devices like the "Yoga 9 2-in-1 14IPH11 - Type 83SE", the hinge switch WMI query returns extra data in the upper bits (e.g. 0x50001 laptop mode, 0x50002 tablet mode, ect.).
The driver previously checked for exact matches (0x01 laptop, 0x02 tablet, ect.) causing newer switches to not work.
Mask the WMI query result to only match the lower byte and ignore upper bits.
--- drivers/platform/x86/lenovo-ymc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/platform/x86/lenovo-ymc.c +7 -1
@@ -8,6 +8,8 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt#include <linux/acpi.h> +#include <linux/bitfield.h> +#include <linux/bits.h> #include <linux/dmi.h> #include <linux/input.h> #include <linux/input/sparse-keymap.h>
@@ -20,6 +22,8 @@#define LENOVO_YMC_QUERY_INSTANCE 0#define LENOVO_YMC_QUERY_METHOD 0x01 +#define LENOVO_YMC_STATE_MASK GENMASK(7, 0) +static bool force;module_param (force, bool,0444 );MODULE_PARM_DESC (force,"Force loading on boards without a convertible DMI chassis-type" );
@@ -85,7 +89,9 @@ static void lenovo_ymc_notify(struct wmi_device *wdev, union acpi_object *data) "WMI event data is not an integer\n"); goto free_obj; } - code = obj->integer.value; + +/* strip upper bits (e.g. 0x50000) on newer devices */ + code =FIELD_GET (LENOVO_YMC_STATE_MASK , obj->integer.value);if (!sparse_keymap_report_event (priv->input_dev, code,1 , true))dev_warn (&wdev->dev,"Unknown key %d pressed\n" , code);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 380/3318 KVM: x86: Always initialize EFER reserved bits on vendor initialization
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yosry Ahmed <[email protected]>
[ Upstream commit a4b8acd428ba3f03952ef309d7f438dbc357557b ]
EFER reserved bits are statically initialized, and do not reset if a vendor module is re-loaded. For example, loading kvm_amd with nested=1 removes EFER.SVME (and potentially EFER.LMSLE) from the reserved bits. Reloading kvm_amd with nested=0 does not add them back, allowing userspace to set EFER.SVME with nested=0.
Re-initializing EFER reserved bits before configuring them on vendor initialization.
--- arch/x86/kvm/x86.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
arch/x86/kvm/x86.c +10 -10
@@ -102,16 +102,7 @@ EXPORT_SYMBOL_GPL(kvm_caps);#define emul_to_vcpu (ctxt) \ ((struct kvm_vcpu *)(ctxt)->vcpu) -/* EFER defaults: -* - enable syscall per default because its emulated by KVM -* - enable LME and LMA per default on 64 bit KVM -*/ -#ifdef CONFIG_X86_64 -static -u64 __read_mostly efer_reserved_bits = ~((u64)(EFER_SCE |EFER_LME |EFER_LMA )); -#else -static u64 __read_mostly efer_reserved_bits = ~((u64 )EFER_SCE ); -#endif +static u64 __read_mostly efer_reserved_bits;static u64 __read_mostly cr4_reserved_bits =CR4_RESERVED_BITS ;
@@ -9606,6 +9597,15 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops)if (boot_cpu_has (X86_FEATURE_ARCH_CAPABILITIES ))rdmsrl (MSR_IA32_ARCH_CAPABILITIES , host_arch_capabilities); +/* +* EFER defaults, re-initialized on every vendor load: +* - enable syscall per default because its emulated by KVM +* - enable LME and LMA per default on 64 bit KVM +*/ + efer_reserved_bits = ~((u64 )EFER_SCE ); +if (IS_ENABLED (CONFIG_X86_64 )) + efer_reserved_bits &= ~((u64)(EFER_LME |EFER_LMA )); + r = ops->hardware_setup ();if (r !=0 ) goto out_mmu_exit;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 381/3318 KVM: x86: Check EFER validity on KVM_SET_SREGS*
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yosry Ahmed <[email protected]>
[ Upstream commit 184bd464bdb66daa9173670904f24c29c7b7f7d4 ]
When handling userspace SREGS writes, check the validity of EFER (i.e. allowed bits) before writing the new value of EFER through the per-vendor set_efer callbacks. This prevents userspace from writing bogus values (e.g. EFER.SVME=1 with nested=0).
Note: on KVM_SET_MSRS, KVM only checks EFER validity in terms of KVM caps, not guest caps, so it is possible to set EFER bits that are supported by KVM but not by the guest CPUID. Potentially allowing userspace to set msrs before CPUID.
However, for KVM_SET_SREGS*, check the validity of the set bits against both KVM and guest caps. This is consistent with other validity checks (e.g. for CR4) that check validity against guest caps, which already imposes the need to set CPUID before SREGS.
--- arch/x86/kvm/x86.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/x86.c +2 -1
@@ -11624,7 +11624,8 @@ static bool kvm_is_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) }return kvm_is_valid_cr4 (vcpu, sregs->cr4) && -kvm_is_valid_cr0 (vcpu, sregs->cr0); +kvm_is_valid_cr0 (vcpu, sregs->cr0) && +kvm_valid_efer (vcpu, sregs->efer); } static int __set_sregs_common(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 382/3318 KVM: SEV: Drop FOLL_WRITE for encrypted region registration
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pankaj Gupta <[email protected]>
[ Upstream commit ee1a586dd1fa2f245b3b753a3e44d9263a49240b ]
When pinning SEV guest memory, drop FOLL_WRITE and rely on FOLL_LONGTERM to break CoW, as *KVM* doesn't actually to the memory using the GUP'd pages. Omitting FOLL_WRITE fixes a regression when using file-backed guest memory that was introduced when KVM (correctly) added FOLL_LONG (e.g. to ensure anonymous memory is migrated out of MIGRATE_CMA/ZONE_MOVABLE before a long term pin).
Unfortunately, as of commits:
8ac268436e6d ("mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings") a6e79df92e4a ("mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings")
GUP uses FOLL_LONGTERM as a canary of sorts to detect pins that are likely to be problematic, and disallows WRITE+LONGTERM pins for file-backed memory. As a result, backing SEV+ guests with file-backed memory, e.g. virtio-pmem, fails due to the disallowed FOLL_LONGTERM+FOLL_WRITE combination.
Note, in the past, FOLL_WRITE was required to trigger CoW unsharing, to prevent replacing the page in the (primary MMU's) page tables during a later write fault after already having pinned a (shared) page in MAP_PRIVATE mappings. FOLL_LONGTERM does that nowadays, even without FOLL_WRITE (see gup_must_unshare()).
--- arch/x86/kvm/svm/sev.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +5 -1
@@ -2000,8 +2000,12 @@ int sev_mem_enc_register_region(struct kvm *kvm,if (!region)return -ENOMEM ; +/* +* Do NOT specify FOLL_WRITE, as KVM isn't using the pinned pages to +* write memory, and FOLL_LONGTERM itself triggers CoW unshare. +*/ region->pages =sev_pin_memory (kvm, range->addr, range->size, ®ion->npages, -FOLL_WRITE |FOLL_LONGTERM ); +FOLL_LONGTERM );if (IS_ERR (region->pages)) { ret =PTR_ERR (region->pages); goto e_free;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 383/3318 PCI/AER: Fix mapping of errors to agent & layer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
[ Upstream commit 1017599755b8b578a671f8fac175bce56189d01c ]
PCIe r7.0 sec 6.2.7 documents the agent and layer of each Correctable and Uncorrectable Error. Based on this spec section, the AER driver maps detected errors to an agent and layer using a set of macros and logs them.
Most errors listed in sec 6.2.7 map to the "Receiver" agent and "Transaction Layer", so the macros use these as defaults unless an error maps to something else.
However the macros have not been amended since their introduction in 2006 with commit 6c2b374d7485 ("PCI-Express AER implemetation: AER core and aerdriver"). They are still based on PCIe r1.0 sec 7.2.5 (renumbered to 6.2.7 in PCIe r1.1 and newer).
Amend the macros to map errors introduced since then to the appropriate agent and layer.
PCIe r2.1 introduced a new "Component" agent and "General" layer for Internal Errors and Header Log Overflow. Add them to the macros.
Unsupported Request is currently mapped to the "Requester" agent, even though it is reported by the "Receiver". Fix the incorrect mapping.
Sec 6.2.7 neglects to list an agent for Data Link Protocol Error and Surprise Down Error. Map the latter to "Component" because PCIe r7.0 sec 3.2.1 states that the error is "associated with the detecting Port". Map the former to "Receiver" because every occurrence of Data Link Protocol Error in the spec refers to it being logged in the Receiving Port. I have had these errata reported to the PCI-SIG Protocol Working Group. (There's also a layout erratum in the REPLAY_NUM Rollover row wherein columns are shifted to the left, but that's already corrected in the PCIe r7.1 draft as of 2026-04-07.)
--- drivers/pci/pcie/aer.c | 24 +++++++++++++++++++----- include/uapi/linux/pci_regs.h | 3 +++ 2 files changed, 22 insertions(+), 5 deletions(-)
drivers/pci/pcie/aer.c +19 -5
@@ -398,23 +398,32 @@ void pci_aer_exit(struct pci_dev *dev)#define AER_AGENT_REQUESTER 1#define AER_AGENT_COMPLETER 2#define AER_AGENT_TRANSMITTER 3 +#define AER_AGENT_COMPONENT 4#define AER_AGENT_REQUESTER_MASK (t) ((t == AER_CORRECTABLE) ? \ - 0 : (PCI_ERR_UNC_COMP_TIME|PCI_ERR_UNC_UNSUP)) + 0 : PCI_ERR_UNC_COMP_TIME)#define AER_AGENT_COMPLETER_MASK (t) ((t == AER_CORRECTABLE) ? \ 0 : PCI_ERR_UNC_COMP_ABORT)#define AER_AGENT_TRANSMITTER_MASK (t) ((t == AER_CORRECTABLE) ? \ - (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : 0) + (PCI_ERR_COR_REP_ROLL|PCI_ERR_COR_REP_TIMER) : \ + (PCI_ERR_UNC_POISON_BLK|PCI_ERR_UNC_ATOMEG| \ + PCI_ERR_UNC_DMWR_BLK|PCI_ERR_UNC_XLAT_BLK| \ + PCI_ERR_UNC_TLPPRE)) +#define AER_AGENT_COMPONENT_MASK (t) ((t == AER_CORRECTABLE) ? \ + (PCI_ERR_COR_INTERNAL|PCI_ERR_COR_LOG_OVER) : \ + (PCI_ERR_UNC_INTN|PCI_ERR_UNC_SURPDN))#define AER_GET_AGENT (t, e) \ ((e & AER_AGENT_COMPLETER_MASK(t)) ? AER_AGENT_COMPLETER : \ (e & AER_AGENT_REQUESTER_MASK(t)) ? AER_AGENT_REQUESTER : \ (e & AER_AGENT_TRANSMITTER_MASK(t)) ? AER_AGENT_TRANSMITTER : \ + (e & AER_AGENT_COMPONENT_MASK(t)) ? AER_AGENT_COMPONENT : \ AER_AGENT_RECEIVER)#define AER_PHYSICAL_LAYER_ERROR 0#define AER_DATA_LINK_LAYER_ERROR 1#define AER_TRANSACTION_LAYER_ERROR 2 +#define AER_GENERAL_ERROR 3#define AER_PHYSICAL_LAYER_ERROR_MASK (t) ((t == AER_CORRECTABLE) ? \ PCI_ERR_COR_RCVR : 0)
@@ -422,11 +431,14 @@ void pci_aer_exit(struct pci_dev *dev) (PCI_ERR_COR_BAD_TLP| \ PCI_ERR_COR_BAD_DLLP| \ PCI_ERR_COR_REP_ROLL| \ - PCI_ERR_COR_REP_TIMER) : PCI_ERR_UNC_DLP) + PCI_ERR_COR_REP_TIMER) : (PCI_ERR_UNC_DLP|PCI_ERR_UNC_SURPDN)) +#define AER_GENERAL_ERROR_MASK (t) ((t == AER_CORRECTABLE) ? \ + (PCI_ERR_COR_INTERNAL|PCI_ERR_COR_LOG_OVER) : PCI_ERR_UNC_INTN)#define AER_GET_LAYER_ERROR (t, e) \ ((e & AER_PHYSICAL_LAYER_ERROR_MASK(t)) ? AER_PHYSICAL_LAYER_ERROR : \ (e & AER_DATA_LINK_LAYER_ERROR_MASK(t)) ? AER_DATA_LINK_LAYER_ERROR : \ + (e & AER_GENERAL_ERROR_MASK(t)) ? AER_GENERAL_ERROR : \ AER_TRANSACTION_LAYER_ERROR)/*
@@ -441,7 +453,8 @@ static const char *aer_error_severity_string[] = {static const char *aer_error_layer[] = {"Physical Layer" ,"Data Link Layer" , -"Transaction Layer" +"Transaction Layer" , +"General" , };static const char *aer_correctable_error_string[] = {
@@ -518,7 +531,8 @@ static const char *aer_agent_string[] = {"Receiver ID" ,"Requester ID" ,"Completer ID" , -"Transmitter ID" +"Transmitter ID" , + "Component ID", }; #define aer_stats_dev_attr(name, stats_array, strings_array, \
include/uapi/linux/pci_regs.h +3 -0
@@ -764,6 +764,9 @@#define PCI_ERR_UNC_MCBTLP 0x00800000/* MC blocked TLP */ #define PCI_ERR_UNC_ATOMEG 0x01000000/* Atomic egress blocked */ #define PCI_ERR_UNC_TLPPRE 0x02000000/* TLP prefix blocked */ +#define PCI_ERR_UNC_POISON_BLK 0x04000000/* Poisoned TLP Egress Blocked */ +#define PCI_ERR_UNC_DMWR_BLK 0x08000000/* DMWr Request Egress Blocked */ +#define PCI_ERR_UNC_XLAT_BLK 0x80000000/* Translation Egress Blocked */ #define PCI_ERR_UNCOR_MASK 0x08/* Uncorrectable Error Mask */ /* Same bits as above */ #define PCI_ERR_UNCOR_SEVER 0x0c/* Uncorrectable Error Severity */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 384/3318 PCI/AER: Emit TLP Log only for unmasked errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
[ Upstream commit a8bf2dd750de7d682fdaa2127f4e3217ce9c4a82 ]
Per PCIe r7.0 sec 6.2.5, the prefix and header of an offending TLP is only recorded for unmasked Uncorrectable Errors. Yet when the AER driver determines whether a prefix and header has been logged, it does not take the Uncorrectable Error Mask Register into account. Fix it.
--- drivers/pci/pcie/aer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pcie/aer.c +2 -2
@@ -785,7 +785,7 @@ void cper_print_aer(struct pci_dev *dev, int aer_severity, }else { status = aer->uncor_status; mask = aer->uncor_mask; - tlp_header_valid = status &AER_LOG_TLP_MASKS ; + tlp_header_valid = (status & ~mask) &AER_LOG_TLP_MASKS ; } layer =AER_GET_LAYER_ERROR (aer_severity, status);
@@ -1107,7 +1107,7 @@ int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info)pci_read_config_dword (dev, aer +PCI_ERR_CAP , &temp); info->first_error =PCI_ERR_CAP_FEP (temp); -if (info->status &AER_LOG_TLP_MASKS ) { +if ((info->status & ~info->mask) &AER_LOG_TLP_MASKS ) { info->tlp_header_valid =1 ;pci_read_config_dword (dev, aer +PCI_ERR_HEADER_LOG , &info->tlp.dw0);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 385/3318 mm/slub: fix missing debugfs entries for caches created before sysfs init
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Xiasong <[email protected]>
[ Upstream commit 7e98f856395618011c517f767fb80ac3fe90de2b ]
slab_debugfs_init() creates the slab debugfs root at device initcall time, while slab_sysfs_init() moves slab_state to FULL at late initcall time. SLAB_STORE_USER caches created in this window miss their debugfs entries because do_kmem_cache_create() skips debugfs_slab_add() when slab_state <= UP. This was observed with MPTCP's request_sock_subflow_v6 cache, whose slab debugfs directory was missing.
The affected window is:
slab_debugfs_init()
slab_debugfs_root = debugfs_create_dir(...)
list_for_each_entry(s, &slab_caches, list)
debugfs_slab_add(s)
kmem_cache_create(..., SLAB_STORE_USER, ...)
do_kmem_cache_create()
if (slab_state <= UP)
return without debugfs entries
slab_sysfs_init()
slab_state = FULL
Initialize the debugfs root and add debugfs entries while holding slab_mutex, walking slab_caches exactly once and handling both sysfs and debugfs entries in the same pass. This gives the sysfs and debugfs initialization an explicit order and prevents caches from being created between the debugfs scan and slab_state reaching FULL.
Gate the new slab_late_init() on either sysfs or debugfs being enabled, with the slab_kset creation and alias_list processing factored into helpers that have empty no-sysfs variants, as suggested by Vlastimil Babka. On slab_kset_init() failure, slab_state stays below FULL so kmem_cache_create() keeps taking the early-boot path, matching prior behavior.
Guard debugfs_slab_release() against an uninitialized debugfs root, since the root is now created later and a cache may be released before it exists.
--- mm/slub.c | 76 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 28 deletions(-)
mm/slub.c +48 -28
@@ -318,16 +318,22 @@ enum track_item { TRACK_ALLOC, TRACK_FREE };#ifdef SLAB_SUPPORTS_SYSFS static int sysfs_slab_add (struct kmem_cache *);static int sysfs_slab_alias (struct kmem_cache *,const char *); +static int __init slab_kset_init (void ); +static void __init slab_sysfs_process_aliases (void );#else static inline int sysfs_slab_add (struct kmem_cache *s) {return 0 ; }static inline int sysfs_slab_alias (struct kmem_cache *s,const char *p) {return 0 ; } +static inline int slab_kset_init (void ) {return 0 ; } +static inline void slab_sysfs_process_aliases (void ) { }#endif #if defined(CONFIG_DEBUG_FS ) && defined(CONFIG_SLUB_DEBUG )static void debugfs_slab_add (struct kmem_cache *); +static void __init slab_debugfs_root_init (void );#else static inline void debugfs_slab_add (struct kmem_cache *s) { } +static inline void slab_debugfs_root_init (void ) { }#endif static inline void stat (const struct kmem_cache *s,enum stat_item si)
@@ -6279,28 +6285,20 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)return 0 ; } -static int __init slab_sysfs_init (void ) +static int __init slab_kset_init (void ) { -struct kmem_cache *s; -int err; - -mutex_lock (&slab_mutex); - slab_kset =kset_create_and_add ("slab" ,NULL , kernel_kobj);if (!slab_kset) { -mutex_unlock (&slab_mutex);pr_err ("Cannot register slab subsystem.\n" );return -ENOMEM ; } - slab_state =FULL ; +return 0 ; +} -list_for_each_entry (s, &slab_caches, list) { - err =sysfs_slab_add (s); -if (err) -pr_err ("SLUB: Unable to add boot slab %s to sysfs\n" , - s->name); - } +static void __init slab_sysfs_process_aliases (void ) +{ +int err;while (alias_list) {struct saved_alias *al = alias_list;
@@ -6312,12 +6310,41 @@ static int __init slab_sysfs_init(void) al->name); kfree(al); } +} +#endif /* SLAB_SUPPORTS_SYSFS */ + +#if defined(SLAB_SUPPORTS_SYSFS ) || \ + (defined(CONFIG_SLUB_DEBUG ) && defined(CONFIG_DEBUG_FS )) +static int __init slab_late_init (void ) +{ +struct kmem_cache *s; +int err; +mutex_lock (&slab_mutex); + + err =slab_kset_init (); +if (err) + goto out; + +slab_debugfs_root_init (); + slab_state =FULL ; + +list_for_each_entry (s, &slab_caches, list) { +if (sysfs_slab_add (s)) +pr_err ("SLUB: Unable to add boot slab %s to sysfs\n" , + s->name); + +if (s->flags &SLAB_STORE_USER ) +debugfs_slab_add (s); + } + +slab_sysfs_process_aliases (); +out:mutex_unlock (&slab_mutex); -return 0 ; +return err; } -late_initcall (slab_sysfs_init); -#endif /* SLAB_SUPPORTS_SYSFS */ +late_initcall (slab_late_init); +#endif #if defined(CONFIG_SLUB_DEBUG ) && defined(CONFIG_DEBUG_FS )static int slab_debugfs_show (struct seq_file *seq,void *v)
@@ -6515,23 +6542,16 @@ static void debugfs_slab_add(struct kmem_cache *s)void debugfs_slab_release (struct kmem_cache *s) { +if (unlikely (!slab_debugfs_root)) +return ; +debugfs_lookup_and_remove (s->name, slab_debugfs_root); } -static int __init slab_debugfs_init (void ) +static void __init slab_debugfs_root_init (void ) { -struct kmem_cache *s; - slab_debugfs_root =debugfs_create_dir ("slab" ,NULL ); - -list_for_each_entry (s, &slab_caches, list) -if (s->flags &SLAB_STORE_USER ) -debugfs_slab_add (s); - -return 0 ; - } -__initcall (slab_debugfs_init);#endif /* * The /proc/slabinfo ABI
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 386/3318 mm/rmap: use huge_ptep_get() in try_to_unmap_one()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dev Jain <[email protected]>
[ Upstream commit f5407e9b697c940e78b27ff63c6e14d8d171adc3 ]
Patch series "Fix incorrect access of hugetlb pte entries", v3.
There are various places which use ptep_get() to get the pte entry corresponding to a hugetlb folio. Some arches (like s390) have special handling to compute the pteval, so they provide huge_ptep_get(). Use this helper consistently.
Additionally, some code paths may provide huge_ptep_get with an unaligned address. This is a problem on arm64 (I checked other arches and it looks fine for them), which is fixed in patch 1. The fix is made to be
backport-friendly: the cleaner fix would be to perhaps pass the hstate to huge_ptep_get() - that is wider churn and we can do that later.
This patch (of 5):
try_to_unmap_one() handles hugetlb folios when memory failure needs to replace a poisoned hugetlb mapping with a hwpoison entry. In that case page_vma_mapped_walk() returns the pte pointer to the hugetlb folio in pvmw.pte, but the code reads it with ptep_get().
On arches which provide their own huge_ptep_get() to dereference a huge pte pointer, accessing via ptep_get() would cause pte_pfn(), pte_present() etc to misbehave.
It is not clear whether this has a trivially visible effect to userspace.
Just use huge_ptep_get() for dereferencing a huge pte pointer.
--- include/linux/hugetlb.h | 2 ++ mm/rmap.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-)
include/linux/hugetlb.h +2 -0
@@ -1199,6 +1199,8 @@ static inline void hugetlb_count_sub(long l, struct mm_struct *mm) { } +pte_t huge_ptep_get (pte_t *ptep); +static inline pte_t huge_ptep_clear_flush (struct vm_area_struct *vma,unsigned long addr,pte_t *ptep) {
mm/rmap.c +5 -1
@@ -1538,7 +1538,11 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,break ; } - pfn =pte_pfn (ptep_get (pvmw.pte)); +if (folio_test_hugetlb (folio)) + pteval =huge_ptep_get (pvmw.pte); +else + pteval =ptep_get (pvmw.pte); + pfn =pte_pfn (pteval); subpage =folio_page (folio, pfn -folio_pfn (folio)); address = pvmw.address; anon_exclusive = folio_test_anon(folio) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 387/3318 mm/rmap: use huge_ptep_get() in try_to_migrate_one()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dev Jain <[email protected]>
[ Upstream commit 9be12ffa78cd087d41086f937a156435d4e588e9 ]
try_to_migrate_one() is used by folio migration to replace a present mapping with a migration entry. For hugetlb folios, page_vma_mapped_walk() returns the pte pointer to the hugetlb folio in pvmw.pte, but the code reads the huge pte entry with ptep_get().
On arches which provide their own huge_ptep_get() to dereference a huge pte pointer, accessing via ptep_get() would cause pte_pfn(), pte_present() etc to misbehave.
It is not clear whether this has a trivially visible effect to userspace.
Use huge_ptep_get() to dereference a huge pte pointer.
Commit a98a2f0c8ce1 copied the bug from try_to_unmap_one into try_to_migrate_one.
--- mm/rmap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/rmap.c +5 -1
@@ -1895,7 +1895,11 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,/* Unexpected PMD-mapped THP? */ VM_BUG_ON_FOLIO (!pvmw.pte, folio); - pfn =pte_pfn (ptep_get (pvmw.pte)); +if (folio_test_hugetlb (folio)) + pteval =huge_ptep_get (pvmw.pte); +else + pteval =ptep_get (pvmw.pte); + pfn =pte_pfn (pteval);if (folio_is_zone_device (folio)) {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 388/3318 mm/migrate: use huge_ptep_get() in remove_migration_pte()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dev Jain <[email protected]>
[ Upstream commit ac1ec50d71b953524100ddc09057ee61a3dfaff3 ]
remove_migration_pte() converts migration entries back to present PTEs after folio migration completes. For hugetlb folios, page_vma_mapped_walk() returns the pte pointer to the hugetlb folio in pvmw.pte, but the code reads it with ptep_get().
On arches which provide their own huge_ptep_get() to dereference a huge pte pointer, accessing via ptep_get() would cause pte_pfn(), pte_present() etc to misbehave.
It is not clear whether this has a trivially visible effect to userspace.
Use huge_ptep_get() to dereference a huge pte pointer.
--- mm/migrate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/migrate.c +4 -1
@@ -210,7 +210,10 @@ static bool remove_migration_pte(struct folio *folio,folio_get (folio); pte =mk_pte (new,READ_ONCE (vma->vm_page_prot)); - old_pte =ptep_get (pvmw.pte); +if (folio_test_hugetlb (folio)) + old_pte =huge_ptep_get (pvmw.pte); +else + old_pte =ptep_get (pvmw.pte);if (pte_swp_soft_dirty (old_pte)) pte =pte_mksoft_dirty (pte);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 389/3318 mm/page_vma_mapped: use huge_ptep_get() for hugetlb
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dev Jain <[email protected]>
[ Upstream commit e87df0d5d6962bde50f55f6d02b779daa394f894 ]
check_pte() is the final validation step in page_vma_mapped_walk(). It reads pvmw->pte with ptep_get() to decide whether the entry maps the PFN range being walked. For hugetlb VMAs, that pointer refers to a hugetlb entry.
On arches which provide their own huge_ptep_get() to dereference a huge pte pointer, accessing via ptep_get() would cause pte_pfn(), pte_present() etc to misbehave.
It is not clear whether this has a trivially visible effect to userspace.
Use huge_ptep_get() to dereference a huge pte pointer.
--- mm/page_vma_mapped.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
mm/page_vma_mapped.c +6 -1
@@ -97,7 +97,12 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, spinlock_t **ptlp)static bool check_pte (struct page_vma_mapped_walk *pvmw,unsigned long pte_nr) {unsigned long pfn; -pte_t ptent =ptep_get (pvmw->pte); +pte_t ptent; + +if (is_vm_hugetlb_page (pvmw->vma)) + ptent =huge_ptep_get (pvmw->pte); +else + ptent =ptep_get (pvmw->pte);if (pvmw->flags &PVMW_MIGRATION ) {swp_entry_t entry;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 390/3318 HID: nintendo: register input device after capabilities are set
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiangshan Yi <[email protected]>
[ Upstream commit d723bc1fe2e72b9252234e94c11af644ec477bf7 ]
input_register_device() exposes the device to userspace immediately. In joycon_input_create() it was called before joycon_config_rumble() configures the FF_RUMBLE capability and the memless force-feedback device, so a concurrent EVIOCSFF could dereference a NULL dev->ff.
Registering early also means the initial udev event lacks button and axis information, which can make input managers ignore the device.
Move input_register_device() to the end of joycon_input_create(), after all capabilities, the IMU input device and the force-feedback callbacks have been configured.
--- drivers/hid/hid-nintendo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/hid/hid-nintendo.c +4 -4
@@ -1796,10 +1796,6 @@ static int joycon_input_create(struct joycon_ctlr *ctlr) ctlr->rumble_msecs =jiffies_to_msecs (jiffies);#endif - ret =input_register_device (ctlr->input); -if (ret) -return ret; -/* configure the imu input device */ ctlr->imu_input =devm_input_allocate_device (&hdev->dev);if (!ctlr->imu_input)
@@ -1850,6 +1846,10 @@ static int joycon_input_create(struct joycon_ctlr *ctlr)if (ret)return ret; + ret =input_register_device (ctlr->input); +if (ret) +return ret; +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 391/3318 HID: input: read battery capacity from its actual report offset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jose Villaseñor Montfort <[email protected]>
[ Upstream commit d07644524b6511b622ee7b0e2e68c9ee43d522a4 ]
hidinput_query_battery_capacity() assumes the state-of-charge value is the first byte following the report ID (buf[1]) and ignores where the battery field actually sits within the report.
An Apple Magic Trackpad 2 precedes the AbsoluteStateOfCharge byte with a byte of status flags in its battery reports, so this query returns the flags byte instead of the charge level.
The device happens to make that easy to observe, because it exposes the same cell twice: its report descriptor declares AbsoluteStateOfCharge in two reports (0x90 and 0x9b), so hidinput_setup_battery() registers two power supplies. Only the first one is refreshed by hid-magicmouse -- it uses hid_get_battery(), which returns the first battery of the list -- and that refresh goes through the report event path, which parses the field correctly. Nothing ever reports the second one, so every read of its capacity takes the query path above. On a USB-C Magic Trackpad over USB, on an unpatched 7.1.5:
hid-<serial>-battery-144 = 100% (Charging) <- report event path hid-<serial>-battery-155 = 3% (Discharging) <- query path
Both are the same physical battery. A raw HIDIOCGINPUT of the two reports at that same moment:
report 0x90 -> [90 03 64]
report 0x9b -> [9b 03 64 64 00 00 10 00 00 00 00 00 00 00]
^flags ^SoC = 0x64 = 100%
The device answers correctly in both cases; only the offset the kernel reads the capacity from is wrong. 0x03 is the flags byte (present, charging), reported as "3%".
Bluetooth takes the same query path for its capacity, where the trackpad reported a bogus near-constant ~4% -- 0b100, the FullyCharged flag -- regardless of the real charge.
Store the battery field's offset within the report at setup time and use it when querying, so the capacity is read from its real position. The report event path already parses the field correctly through the HID core; only the explicit GET_REPORT query was wrong.
Devices whose capacity field is the first field in the report have a report_offset of 0 and are unaffected (buf[1 + 0] == buf[1]).
--- drivers/hid/hid-input.c | 17 +++++++++++++---- include/linux/hid.h | 1 + 2 files changed, 14 insertions(+), 4 deletions(-)
drivers/hid/hid-input.c +13 -4
@@ -424,19 +424,27 @@ static int hidinput_query_battery_capacity(struct hid_device *dev) {u8 *buf;int ret; +/* +* The capacity field may not be the first field in the report: some +* devices (e.g. the Apple Magic Trackpad 2 over Bluetooth) precede it +* with status flags. Read it from its actual byte offset in the report +* (report_offset is in bits; the leading byte is the report id). +*/ +int offset =1 + dev->battery_report_offset /8 ; +int len = offset +1 ; - buf =kmalloc (4 ,GFP_KERNEL ); + buf =kmalloc (max (len,4 ),GFP_KERNEL );if (!buf)return -ENOMEM ; - ret =hid_hw_raw_request (dev, dev->battery_report_id, buf,4 , + ret =hid_hw_raw_request (dev, dev->battery_report_id, buf,max (len,4 ), dev->battery_report_type,HID_REQ_GET_REPORT ); -if (ret <2 ) { +if (ret < len) {kfree (buf);return -ENODATA ; } - ret =hidinput_scale_battery_capacity (dev, buf[1 ]); + ret =hidinput_scale_battery_capacity (dev, buf[offset]);kfree (buf);return ret; }
@@ -554,6 +562,7 @@ static int hidinput_setup_battery(struct hid_device *dev, unsigned report_type, dev->battery_max = max; dev->battery_report_type = report_type; dev->battery_report_id = field->report->id; + dev->battery_report_offset = field->report_offset; dev->battery_charge_status =POWER_SUPPLY_STATUS_DISCHARGING ;/*
include/linux/hid.h +1 -0
@@ -673,6 +673,7 @@ struct hid_device { /* device report descriptor */__s32 battery_max;__s32 battery_report_type;__s32 battery_report_id; +__s32 battery_report_offset;__s32 battery_charge_status;enum hid_battery_status battery_status;bool battery_avoid_query;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 392/3318 f2fs: dirty directory inodes on mtime/ctime update
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joanne Chang <[email protected]>
[ Upstream commit 9ec09d5f4b317a417c8655c14056f70cbe71eb6c ]
Xfstests generic/547 sometimes fail with mismatched directory metadata before and after a power failure. This happens because when a directory entry is added, renamed, or deleted, its mtime and ctime are updated and the inode is marked dirty via f2fs_mark_inode_dirty_sync(dir, sync=false). The sync=false flag means the dirty inode is not added to the global DIRTY_META list. Therefore, subsequent checkpoints skip flushing these updated directory blocks, causing directory timestamps to revert to stale values after a sudden power failure.
Address this by changing the dirtying parameter to sync=true during directory entry mutations and renames. This forces F2FS to immediately queue the updated directory blocks on the global DIRTY_META list, ensuring timestamps are committed to checkpoints.
--- fs/f2fs/dir.c | 6 +++--- fs/f2fs/inline.c | 2 +- fs/f2fs/namei.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-)
fs/f2fs/dir.c +3 -3
@@ -481,7 +481,7 @@ void f2fs_set_link(struct inode *dir, struct f2fs_dir_entry *de,set_page_dirty (page); dir->i_mtime =inode_set_ctime_current (dir); -f2fs_mark_inode_dirty_sync (dir, false); +f2fs_mark_inode_dirty_sync (dir, true);f2fs_put_page (page,1 ); }
@@ -635,7 +635,7 @@ void f2fs_update_parent_metadata(struct inode *dir, struct inode *inode,clear_inode_flag (inode,FI_NEW_INODE ); } dir->i_mtime =inode_set_ctime_current (dir); -f2fs_mark_inode_dirty_sync (dir, false); +f2fs_mark_inode_dirty_sync (dir, true);if (F2FS_I (dir)->i_current_depth != current_depth)f2fs_i_depth_write (dir, current_depth);
@@ -946,7 +946,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,f2fs_put_page (page,1 ); dir->i_mtime =inode_set_ctime_current (dir); -f2fs_mark_inode_dirty_sync (dir, false); +f2fs_mark_inode_dirty_sync (dir, true);if (inode)f2fs_drop_nlink (dir, inode);
fs/f2fs/inline.c +1 -1
@@ -728,7 +728,7 @@ void f2fs_delete_inline_entry(struct f2fs_dir_entry *dentry, struct page *page,f2fs_put_page (page,1 ); dir->i_mtime =inode_set_ctime_current (dir); -f2fs_mark_inode_dirty_sync (dir, false); +f2fs_mark_inode_dirty_sync (dir, true);if (inode)f2fs_drop_nlink (dir, inode);
fs/f2fs/namei.c +3 -3
@@ -1038,7 +1038,7 @@ static int f2fs_rename(struct mnt_idmap *idmap, struct inode *old_dir,f2fs_up_write (&F2FS_I (old_inode)->i_sem);inode_set_ctime_current (old_inode); -f2fs_mark_inode_dirty_sync (old_inode, false); +f2fs_mark_inode_dirty_sync (old_inode, true);f2fs_delete_entry (old_entry, old_page, old_dir,NULL ); old_page =NULL ;
@@ -1210,7 +1210,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_i_links_write (old_dir, old_nlink >0 );f2fs_up_write (&F2FS_I (old_dir)->i_sem); } -f2fs_mark_inode_dirty_sync (old_dir, false); +f2fs_mark_inode_dirty_sync (old_dir, true);/* update directory entry info of new dir inode */ f2fs_set_link (new_dir, new_entry, new_page, old_inode);
@@ -1229,7 +1229,7 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,f2fs_i_links_write (new_dir, new_nlink >0 );f2fs_up_write (&F2FS_I (new_dir)->i_sem); } -f2fs_mark_inode_dirty_sync (new_dir, false); +f2fs_mark_inode_dirty_sync (new_dir, true);if (F2FS_OPTION (sbi).fsync_mode ==FSYNC_MODE_STRICT ) {f2fs_add_ino_entry (sbi, old_dir->i_ino,TRANS_DIR_INO );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 393/3318 module: Use RCU in find_kallsyms_symbol().
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit f01369239293e4900af7be673e0fd26fe54f85e1 ]
The modules list and module::kallsyms can be accessed under RCU assumption.
Use rcu_dereference() to reference the kallsyms pointer in find_kallsyms_symbol(). Use a RCU section instead of preempt_disable in callers of find_kallsyms_symbol(). Keep the preempt-disable in module_address_lookup() due to __module_address().
Stable-dep-of: 0e9f090a4e9b ("module/kallsyms: fix nextval for data symbol lookup")
--- kernel/module/kallsyms.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/module/kallsyms.c +3 -4
@@ -260,7 +260,7 @@ static const char *find_kallsyms_symbol(struct module *mod, {unsigned int i, best =0 ;unsigned long nextval, bestval; -struct mod_kallsyms *kallsyms =rcu_dereference_sched (mod->kallsyms); +struct mod_kallsyms *kallsyms =rcu_dereference (mod->kallsyms);struct module_memory *mod_mem;/* At worse, next value is at end of module */
@@ -331,6 +331,7 @@ const char *module_address_lookup(unsigned long addr,const char *ret =NULL ;struct module *mod; +guard (rcu)();preempt_disable (); mod =__module_address (addr);if (mod) {
@@ -355,7 +356,7 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) {struct module *mod; -preempt_disable (); +guard (rcu)();list_for_each_entry_rcu (mod, &modules, list) {if (mod->state ==MODULE_STATE_UNFORMED )continue ;
@@ -367,12 +368,10 @@ int lookup_module_symbol_name(unsigned long addr, char *symname) goto out;strscpy (symname, sym,KSYM_NAME_LEN ); -preempt_enable ();return 0 ; } } out: -preempt_enable ();return -ERANGE ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 394/3318 module/kallsyms: fix nextval for data symbol lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislaw Gruszka <[email protected]>
[ Upstream commit 0e9f090a4e9bfae5a190ccf89eab3bf14f6b0f96 ]
The symbol lookup code assumes the queried address resides in either MOD_TEXT or MOD_INIT_TEXT. This breaks for addresses in other module memory regions (e.g. rodata or data), resulting in incorrect upper bounds and wrong symbol size.
Select the module memory region the address belongs to instead of hardcoding text sections. Also initialize the lower bound to the start of that region, as searching from address 0 is unnecessary.
--- kernel/module/kallsyms.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
kernel/module/kallsyms.c +16 -8
@@ -261,17 +261,25 @@ static const char *find_kallsyms_symbol(struct module *mod,unsigned int i, best =0 ;unsigned long nextval, bestval;struct mod_kallsyms *kallsyms =rcu_dereference (mod->kallsyms); -struct module_memory *mod_mem; +struct module_memory *mod_mem =NULL ; -/* At worse, next value is at end of module */ -if (within_module_init (addr, mod)) - mod_mem = &mod->mem[MOD_INIT_TEXT ]; -else - mod_mem = &mod->mem[MOD_TEXT ]; +for_each_mod_mem_type (type) { +#ifndef CONFIG_KALLSYMS_ALL +if (!mod_mem_type_is_text (type)) +continue ; +#endif +if (within_module_mem_type (addr, mod, type)) { + mod_mem = &mod->mem[type]; +break ; + } + } - nextval = (unsigned long )mod_mem->base + mod_mem->size; +if (!mod_mem) +return NULL ; - bestval =kallsyms_symbol_value (&kallsyms->symtab[best]); +/* Initialize bounds within memory region the address belongs to. */ + nextval = (unsigned long )mod_mem->base + mod_mem->size; + bestval = (unsigned long )mod_mem->base -1 ;/* * Scan for closest preceding symbol, and next symbol. (ELF
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 395/3318 module: Factor out elf_validity_ehdr
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit 90f8f312db720dbabec7c6258ef580b50129cc21 ]
Factor out verification of the ELF header and document what is checked.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 70 +++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 23 deletions(-)
kernel/module/main.c +47 -23
@@ -1655,6 +1655,50 @@ static int validate_section_offset(struct load_info *info, Elf_Shdr *shdr)return 0 ; } +/** +* elf_validity_ehdr() - Checks an ELF header for module validity +* @info: Load info containing the ELF header to check +* +* Checks whether an ELF header could belong to a valid module. Checks: +* +* * ELF header is within the data the user provided +* * ELF magic is present +* * It is relocatable (not final linked, not core file, etc.) +* * The header's machine type matches what the architecture expects. +* * Optional arch-specific hook for other properties +* - module_elf_check_arch() is currently only used by PPC to check +* ELF ABI version, but may be used by others in the future. +* +* Return: %0 if valid, %-ENOEXEC on failure. +*/ +static int elf_validity_ehdr (const struct load_info *info) +{ +if (info->len <sizeof (*(info->hdr))) { +pr_err ("Invalid ELF header len %lu\n" , info->len); +return -ENOEXEC ; + } +if (memcmp (info->hdr->e_ident,ELFMAG ,SELFMAG ) !=0 ) { +pr_err ("Invalid ELF header magic: != %s\n" ,ELFMAG ); +return -ENOEXEC ; + } +if (info->hdr->e_type !=ET_REL ) { +pr_err ("Invalid ELF header type: %u != %u\n" , + info->hdr->e_type,ET_REL ); +return -ENOEXEC ; + } +if (!elf_check_arch (info->hdr)) { +pr_err ("Invalid architecture in ELF header: %u\n" , + info->hdr->e_machine); +return -ENOEXEC ; + } +if (!module_elf_check_arch (info->hdr)) { +pr_err ("Invalid module architecture in ELF header: %u\n" , + info->hdr->e_machine); +return -ENOEXEC ; + } +return 0 ; +} +/* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go.
@@ -1684,30 +1728,10 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)unsigned int num_info_secs =0 , info_idx;unsigned int num_sym_secs =0 , sym_idx; -if (info->len <sizeof (*(info->hdr))) { -pr_err ("Invalid ELF header len %lu\n" , info->len); - goto no_exec; - } + err =elf_validity_ehdr (info); +if (err <0 ) +return err; -if (memcmp (info->hdr->e_ident,ELFMAG ,SELFMAG ) !=0 ) { -pr_err ("Invalid ELF header magic: != %s\n" ,ELFMAG ); - goto no_exec; - } -if (info->hdr->e_type !=ET_REL ) { -pr_err ("Invalid ELF header type: %u != %u\n" , - info->hdr->e_type,ET_REL ); - goto no_exec; - } -if (!elf_check_arch (info->hdr)) { -pr_err ("Invalid architecture in ELF header: %u\n" , - info->hdr->e_machine); - goto no_exec; - } -if (!module_elf_check_arch (info->hdr)) { -pr_err ("Invalid module architecture in ELF header: %u\n" , - info->hdr->e_machine); - goto no_exec; - }if (info->hdr->e_shentsize !=sizeof (Elf_Shdr)) {pr_err ("Invalid ELF section header size\n" ); goto no_exec;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 396/3318 module: Factor out elf_validity_cache_sechdrs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit c92aab819d56d51631f0484ed7af11d9d8ff4cb0 ]
Factor out and document the validation of section headers.
Because we now validate all section offsets and lengths before accessing them, we can remove the ad-hoc checks.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 125 ++++++++++++++++++++++++++++--------------- 1 file changed, 82 insertions(+), 43 deletions(-)
kernel/module/main.c +82 -43
@@ -1699,6 +1699,87 @@ static int elf_validity_ehdr(const struct load_info *info)return 0 ; } +/** +* elf_validity_cache_sechdrs() - Cache section headers if valid +* @info: Load info to compute section headers from +* +* Checks: +* +* * ELF header is valid (see elf_validity_ehdr()) +* * Section headers are the size we expect +* * Section array fits in the user provided data +* * Section index 0 is NULL +* * Section contents are inbounds +* +* Then updates @info with a &load_info->sechdrs pointer if valid. +* +* Return: %0 if valid, negative error code if validation failed. +*/ +static int elf_validity_cache_sechdrs (struct load_info *info) +{ +Elf_Shdr *sechdrs; +Elf_Shdr *shdr; +int i; +int err; + + err =elf_validity_ehdr (info); +if (err <0 ) +return err; + +if (info->hdr->e_shentsize !=sizeof (Elf_Shdr)) { +pr_err ("Invalid ELF section header size\n" ); +return -ENOEXEC ; + } + +/* +* e_shnum is 16 bits, and sizeof(Elf_Shdr) is +* known and small. So e_shnum * sizeof(Elf_Shdr) +* will not overflow unsigned long on any platform. +*/ +if (info->hdr->e_shoff >= info->len + || (info->hdr->e_shnum *sizeof (Elf_Shdr) > + info->len - info->hdr->e_shoff)) { +pr_err ("Invalid ELF section header overflow\n" ); +return -ENOEXEC ; + } + + sechdrs = (void *)info->hdr + info->hdr->e_shoff; + +/* +* The code assumes that section 0 has a length of zero and +* an addr of zero, so check for it. +*/ +if (sechdrs[0 ].sh_type !=SHT_NULL + || sechdrs[0 ].sh_size !=0 + || sechdrs[0 ].sh_addr !=0 ) { +pr_err ("ELF Spec violation: section 0 type(%d)!=SH_NULL or non-zero len or addr\n" , + sechdrs[0 ].sh_type); +return -ENOEXEC ; + } + +/* Validate contents are inbounds */ +for (i =1 ; i < info->hdr->e_shnum; i++) { + shdr = &sechdrs[i]; +switch (shdr->sh_type) { +case SHT_NULL : +case SHT_NOBITS : +/* No contents, offset/size don't mean anything */ +continue ; +default : + err =validate_section_offset (info, shdr); +if (err <0 ) { +pr_err ("Invalid ELF section in module (section %u type %u)\n" , + i, shdr->sh_type); +return err; + } + } + } + + info->sechdrs = sechdrs; + +return 0 ; +} +/* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go.
@@ -1728,29 +1809,10 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)unsigned int num_info_secs =0 , info_idx;unsigned int num_sym_secs =0 , sym_idx; - err =elf_validity_ehdr (info); + err =elf_validity_cache_sechdrs (info);if (err <0 )return err; -if (info->hdr->e_shentsize !=sizeof (Elf_Shdr)) { -pr_err ("Invalid ELF section header size\n" ); - goto no_exec; - } - -/* -* e_shnum is 16 bits, and sizeof(Elf_Shdr) is -* known and small. So e_shnum * sizeof(Elf_Shdr) -* will not overflow unsigned long on any platform. -*/ -if (info->hdr->e_shoff >= info->len - || (info->hdr->e_shnum *sizeof (Elf_Shdr) > - info->len - info->hdr->e_shoff)) { -pr_err ("Invalid ELF section header overflow\n" ); - goto no_exec; - } - - info->sechdrs = (void *)info->hdr + info->hdr->e_shoff; -/* * Verify if the section name table index is valid. */
@@ -1763,11 +1825,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) } strhdr = &info->sechdrs[info->hdr->e_shstrndx]; - err =validate_section_offset (info, strhdr); -if (err <0 ) { -pr_err ("Invalid ELF section hdr(type %u)\n" , strhdr->sh_type); -return err; - }/* * The section name table must be NUL-terminated, as required
@@ -1784,18 +1841,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) goto no_exec; } -/* -* The code assumes that section 0 has a length of zero and -* an addr of zero, so check for it. -*/ -if (info->sechdrs[0 ].sh_type !=SHT_NULL - || info->sechdrs[0 ].sh_size !=0 - || info->sechdrs[0 ].sh_addr !=0 ) { -pr_err ("ELF Spec violation: section 0 type(%d)!=SH_NULL or non-zero len or addr\n" , - info->sechdrs[0 ].sh_type); - goto no_exec; - } -for (i =1 ; i < info->hdr->e_shnum; i++) { shdr = &info->sechdrs[i];switch (shdr->sh_type) {
@@ -1814,12 +1859,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) sym_idx = i; fallthrough;default : - err =validate_section_offset (info, shdr); -if (err <0 ) { -pr_err ("Invalid ELF section in module (section %u type %u)\n" , - i, shdr->sh_type); -return err; - }if (strcmp (info->secstrings + shdr->sh_name,".gnu.linkonce.this_module" ) ==0 ) { num_mod_secs++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 397/3318 module: Factor out elf_validity_cache_secstrings
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit 3c5700aeabd87e81d9153a7666b28d0e405c6c88 ]
Factor out the validation of section names.
There are two behavioral changes:
1. Previously, we did not validate non-SHF_ALLOC sections. This may have once been safe, as find_sec skips non-SHF_ALLOC sections, but find_any_sec, which will be used to load BTF if that is enabled, ignores the SHF_ALLOC flag. Since there's no need to support invalid section names, validate all of them, not just SHF_ALLOC sections.
2. Section names were validated *after* accessing them for the purposes of detecting ".modinfo" and ".gnu.linkonce.this_module". They are now checked prior to the access, which could avoid bad accesses with malformed modules.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 106 ++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 37 deletions(-)
kernel/module/main.c +69 -37
@@ -1780,6 +1780,71 @@ static int elf_validity_cache_sechdrs(struct load_info *info)return 0 ; } +/** +* elf_validity_cache_secstrings() - Caches section names if valid +* @info: Load info to cache section names from. Must have valid sechdrs. +* +* Specifically checks: +* +* * Section name table index is inbounds of section headers +* * Section name table is not empty +* * Section name table is NUL terminated +* * All section name offsets are inbounds of the section +* +* Then updates @info with a &load_info->secstrings pointer if valid. +* +* Return: %0 if valid, negative error code if validation failed. +*/ +static int elf_validity_cache_secstrings (struct load_info *info) +{ +Elf_Shdr *strhdr, *shdr; +char *secstrings; +int i; + +/* +* Verify if the section name table index is valid. +*/ +if (info->hdr->e_shstrndx ==SHN_UNDEF + || info->hdr->e_shstrndx >= info->hdr->e_shnum) { +pr_err ("Invalid ELF section name index: %d || e_shstrndx (%d) >= e_shnum (%d)\n" , + info->hdr->e_shstrndx, info->hdr->e_shstrndx, + info->hdr->e_shnum); +return -ENOEXEC ; + } + + strhdr = &info->sechdrs[info->hdr->e_shstrndx]; + +/* +* The section name table must be NUL-terminated, as required +* by the spec. This makes strcmp and pr_* calls that access +* strings in the section safe. +*/ + secstrings = (void *)info->hdr + strhdr->sh_offset; +if (strhdr->sh_size ==0 ) { +pr_err ("empty section name table\n" ); +return -ENOEXEC ; + } +if (secstrings[strhdr->sh_size -1 ] !='\0' ) { +pr_err ("ELF Spec violation: section name table isn't null terminated\n" ); +return -ENOEXEC ; + } + +for (i =0 ; i < info->hdr->e_shnum; i++) { + shdr = &info->sechdrs[i]; +/* SHT_NULL means sh_name has an undefined value */ +if (shdr->sh_type ==SHT_NULL ) +continue ; +if (shdr->sh_name >= strhdr->sh_size) { +pr_err ("Invalid ELF section name in module (section %u type %u)\n" , + i, shdr->sh_type); +return -ENOEXEC ; + } + } + + info->secstrings = secstrings; +return 0 ; +} +/* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go.
@@ -1803,7 +1868,7 @@ static int elf_validity_cache_sechdrs(struct load_info *info)static int elf_validity_cache_copy (struct load_info *info,int flags) {unsigned int i; -Elf_Shdr *shdr, *strhdr; +Elf_Shdr *shdr;int err;unsigned int num_mod_secs =0 , mod_idx;unsigned int num_info_secs =0 , info_idx;
@@ -1812,34 +1877,9 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) err =elf_validity_cache_sechdrs (info);if (err <0 )return err; - -/* -* Verify if the section name table index is valid. -*/ -if (info->hdr->e_shstrndx ==SHN_UNDEF - || info->hdr->e_shstrndx >= info->hdr->e_shnum) { -pr_err ("Invalid ELF section name index: %d || e_shstrndx (%d) >= e_shnum (%d)\n" , - info->hdr->e_shstrndx, info->hdr->e_shstrndx, - info->hdr->e_shnum); - goto no_exec; - } - - strhdr = &info->sechdrs[info->hdr->e_shstrndx]; - -/* -* The section name table must be NUL-terminated, as required -* by the spec. This makes strcmp and pr_* calls that access -* strings in the section safe. -*/ - info->secstrings = (void *)info->hdr + strhdr->sh_offset; -if (strhdr->sh_size ==0 ) { -pr_err ("empty section name table\n" ); - goto no_exec; - } -if (info->secstrings[strhdr->sh_size -1 ] !='\0' ) { -pr_err ("ELF Spec violation: section name table isn't null terminated\n" ); - goto no_exec; - } + err =elf_validity_cache_secstrings (info); +if (err <0 ) +return err;for (i =1 ; i < info->hdr->e_shnum; i++) { shdr = &info->sechdrs[i];
@@ -1868,14 +1908,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) num_info_secs++; info_idx = i; } - -if (shdr->sh_flags &SHF_ALLOC ) { -if (shdr->sh_name >= strhdr->sh_size) { -pr_err ("Invalid ELF section name in module (section %u type %u)\n" , - i, shdr->sh_type); -return -ENOEXEC ; - } - }break ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 398/3318 module: Factor out elf_validity_cache_index_info
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit fbc0e4e482aac7f2b0d20f0a11f6d5eeda346fda ]
Centralize .modinfo detection and property validation.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 82 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 14 deletions(-)
kernel/module/main.c +68 -14
@@ -193,6 +193,38 @@ static unsigned int find_sec(const struct load_info *info, const char *name)return 0 ; } +/** +* find_any_unique_sec() - Find a unique section index by name +* @info: Load info for the module to scan +* @name: Name of the section we're looking for +* +* Locates a unique section by name. Ignores SHF_ALLOC. +* +* Return: Section index if found uniquely, zero if absent, negative count +* of total instances if multiple were found. +*/ +static int find_any_unique_sec (const struct load_info *info,const char *name) +{ +unsigned int idx; +unsigned int count =0 ; +int i; + +for (i =1 ; i < info->hdr->e_shnum; i++) { +if (strcmp (info->secstrings + info->sechdrs[i].sh_name, + name) ==0 ) { + count++; + idx = i; + } + } +if (count ==1 ) { +return idx; + }else if (count ==0 ) { +return 0 ; + }else { +return -count; + } +} +/* Find a module section, or NULL. */ static void *section_addr (const struct load_info *info,const char *name) {
@@ -1845,6 +1877,39 @@ static int elf_validity_cache_secstrings(struct load_info *info)return 0 ; } +/** +* elf_validity_cache_index_info() - Validate and cache modinfo section +* @info: Load info to populate the modinfo index on. +* Must have &load_info->sechdrs and &load_info->secstrings populated +* +* Checks that if there is a .modinfo section, it is unique. +* Then, it caches its index in &load_info->index.info. +* Finally, it tries to populate the name to improve error messages. +* +* Return: %0 if valid, %-ENOEXEC if multiple modinfo sections were found. +*/ +static int elf_validity_cache_index_info (struct load_info *info) +{ +int info_idx; + + info_idx =find_any_unique_sec (info,".modinfo" ); + +if (info_idx ==0 ) +/* Early return, no .modinfo */ +return 0 ; + +if (info_idx <0 ) { +pr_err ("Only one .modinfo section must exist.\n" ); +return -ENOEXEC ; + } + + info->index.info = info_idx; +/* Try to find a name early so we can log errors with a module name */ + info->name =get_modinfo (info,"name" ); + +return 0 ; +} +/* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go.
@@ -1871,13 +1936,15 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)Elf_Shdr *shdr;int err;unsigned int num_mod_secs =0 , mod_idx; -unsigned int num_info_secs =0 , info_idx;unsigned int num_sym_secs =0 , sym_idx; err =elf_validity_cache_sechdrs (info);if (err <0 )return err; err =elf_validity_cache_secstrings (info); +if (err <0 ) +return err; + err =elf_validity_cache_index_info (info);if (err <0 )return err;
@@ -1903,24 +1970,11 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) ".gnu.linkonce.this_module") == 0) { num_mod_secs++; mod_idx = i; - } else if (strcmp(info->secstrings + shdr->sh_name, - ".modinfo") == 0) { - num_info_secs++; - info_idx = i; }break ; } } -if (num_info_secs >1 ) { -pr_err ("Only one .modinfo section must exist.\n" ); - goto no_exec; - }else if (num_info_secs ==1 ) { -/* Try to find a name early so we can log errors with a module name */ - info->index.info = info_idx; - info->name =get_modinfo (info,"name" ); - } -if (num_sym_secs !=1 ) {pr_warn ("%s: module has no symbols (stripped?)\n" , info->name ?:"(missing .modinfo section or name field)" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 399/3318 module: Factor out elf_validity_cache_index_mod
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit 0be41a9367d1fbb16b4b57d81082341af114bad7 ]
Centralize .gnu.linkonce.this_module detection and property validation.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 129 ++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 62 deletions(-)
kernel/module/main.c +67 -62
@@ -1910,6 +1910,68 @@ static int elf_validity_cache_index_info(struct load_info *info)return 0 ; } +/** +* elf_validity_cache_index_mod() - Validates and caches this_module section +* @info: Load info to cache this_module on. +* Must have &load_info->sechdrs and &load_info->secstrings populated +* +* The ".gnu.linkonce.this_module" ELF section is special. It is what modpost +* uses to refer to __this_module and let's use rely on THIS_MODULE to point +* to &__this_module properly. The kernel's modpost declares it on each +* modules's *.mod.c file. If the struct module of the kernel changes a full +* kernel rebuild is required. +* +* We have a few expectations for this special section, this function +* validates all this for us: +* +* * The section has contents +* * The section is unique +* * We expect the kernel to always have to allocate it: SHF_ALLOC +* * The section size must match the kernel's run time's struct module +* size +* +* If all checks pass, the index will be cached in &load_info->index.mod +* +* Return: %0 on validation success, %-ENOEXEC on failure +*/ +static int elf_validity_cache_index_mod (struct load_info *info) +{ +Elf_Shdr *shdr; +int mod_idx; + + mod_idx =find_any_unique_sec (info,".gnu.linkonce.this_module" ); +if (mod_idx <=0 ) { +pr_err ("module %s: Exactly one .gnu.linkonce.this_module section must exist.\n" , + info->name ?:"(missing .modinfo section or name field)" ); +return -ENOEXEC ; + } + + shdr = &info->sechdrs[mod_idx]; + +if (shdr->sh_type ==SHT_NOBITS ) { +pr_err ("module %s: .gnu.linkonce.this_module section must have a size set\n" , + info->name ?:"(missing .modinfo section or name field)" ); +return -ENOEXEC ; + } + +if (!(shdr->sh_flags &SHF_ALLOC )) { +pr_err ("module %s: .gnu.linkonce.this_module must occupy memory during process execution\n" , + info->name ?:"(missing .modinfo section or name field)" ); +return -ENOEXEC ; + } + +if (shdr->sh_size !=sizeof (struct module )) { +pr_err ("module %s: .gnu.linkonce.this_module section size must match the kernel's built struct module size at run time\n" , + info->name ?:"(missing .modinfo section or name field)" ); +return -ENOEXEC ; + } + + info->index.mod = mod_idx; + +return 0 ; +} + +/* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go.
@@ -1935,7 +1997,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)unsigned int i;Elf_Shdr *shdr;int err; -unsigned int num_mod_secs =0 , mod_idx;unsigned int num_sym_secs =0 , sym_idx; err =elf_validity_cache_sechdrs (info);
@@ -1945,16 +2006,15 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)if (err <0 )return err; err =elf_validity_cache_index_info (info); +if (err <0 ) +return err; + err =elf_validity_cache_index_mod (info);if (err <0 )return err;for (i =1 ; i < info->hdr->e_shnum; i++) { shdr = &info->sechdrs[i]; -switch (shdr->sh_type) { -case SHT_NULL : -case SHT_NOBITS : -continue ; -case SHT_SYMTAB : +if (shdr->sh_type ==SHT_SYMTAB ) {if (shdr->sh_link ==SHN_UNDEF || shdr->sh_link >= info->hdr->e_shnum) { pr_err("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n",
@@ -1964,14 +2024,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) } num_sym_secs++; sym_idx = i; - fallthrough; -default : -if (strcmp (info->secstrings + shdr->sh_name, -".gnu.linkonce.this_module" ) ==0 ) { - num_mod_secs++; - mod_idx = i; - } -break ; } }
@@ -1987,55 +2039,8 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) info->index.str = shdr->sh_link; info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset; -/* -* The ".gnu.linkonce.this_module" ELF section is special. It is -* what modpost uses to refer to __this_module and let's use rely -* on THIS_MODULE to point to &__this_module properly. The kernel's -* modpost declares it on each modules's *.mod.c file. If the struct -* module of the kernel changes a full kernel rebuild is required. -* -* We have a few expectaions for this special section, the following -* code validates all this for us: -* -* o Only one section must exist -* o We expect the kernel to always have to allocate it: SHF_ALLOC -* o The section size must match the kernel's run time's struct module -* size -*/ -if (num_mod_secs !=1 ) { -pr_err ("module %s: Only one .gnu.linkonce.this_module section must exist.\n" , - info->name ?:"(missing .modinfo section or name field)" ); - goto no_exec; - } - - shdr = &info->sechdrs[mod_idx]; - -/* -* This is already implied on the switch above, however let's be -* pedantic about it. -*/ -if (shdr->sh_type ==SHT_NOBITS ) { -pr_err ("module %s: .gnu.linkonce.this_module section must have a size set\n" , - info->name ?:"(missing .modinfo section or name field)" ); - goto no_exec; - } - -if (!(shdr->sh_flags &SHF_ALLOC )) { -pr_err ("module %s: .gnu.linkonce.this_module must occupy memory during process execution\n" , - info->name ?:"(missing .modinfo section or name field)" ); - goto no_exec; - } - -if (shdr->sh_size !=sizeof (struct module )) { -pr_err ("module %s: .gnu.linkonce.this_module section size must match the kernel's built struct module size at run time\n" , - info->name ?:"(missing .modinfo section or name field)" ); - goto no_exec; - } - - info->index.mod = mod_idx; -/* This is temporary: point mod into copy of data. */ - info->mod = (void *)info->hdr + shdr->sh_offset; + info->mod = (void *)info->hdr + info->sechdrs[info->index.mod].sh_offset;/* * If we didn't load the .modinfo 'name' field earlier, fall back to
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 400/3318 module: Factor out elf_validity_cache_index_sym
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit 9bd4982cf7d65f4c9e0793d5a8fda6ad838e8554 ]
Centralize symbol table detection and property validation.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 73 ++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 29 deletions(-)
kernel/module/main.c +44 -29
@@ -1971,6 +1971,39 @@ static int elf_validity_cache_index_mod(struct load_info *info)return 0 ; } +/** +* elf_validity_cache_index_sym() - Validate and cache symtab index +* @info: Load info to cache symtab index in. +* Must have &load_info->sechdrs and &load_info->secstrings populated. +* +* Checks that there is exactly one symbol table, then caches its index in +* &load_info->index.sym. +* +* Return: %0 if valid, %-ENOEXEC on failure. +*/ +static int elf_validity_cache_index_sym (struct load_info *info) +{ +unsigned int sym_idx; +unsigned int num_sym_secs =0 ; +int i; + +for (i =1 ; i < info->hdr->e_shnum; i++) { +if (info->sechdrs[i].sh_type ==SHT_SYMTAB ) { + num_sym_secs++; + sym_idx = i; + } + } + +if (num_sym_secs !=1 ) { +pr_warn ("%s: module has no symbols (stripped?)\n" , + info->name ?:"(missing .modinfo section or name field)" ); +return -ENOEXEC ; + } + + info->index.sym = sym_idx; + +return 0 ; +}/* * Check userspace passed ELF module against our expectations, and cache
@@ -1994,10 +2027,8 @@ static int elf_validity_cache_index_mod(struct load_info *info)*/ static int elf_validity_cache_copy (struct load_info *info,int flags) { -unsigned int i; -Elf_Shdr *shdr;int err; -unsigned int num_sym_secs =0 , sym_idx; +int str_idx; err =elf_validity_cache_sechdrs (info);if (err <0 )
@@ -2009,34 +2040,21 @@ static int elf_validity_cache_copy(struct load_info *info, int flags)if (err <0 )return err; err =elf_validity_cache_index_mod (info); +if (err <0 ) +return err; + err =elf_validity_cache_index_sym (info);if (err <0 )return err; -for (i =1 ; i < info->hdr->e_shnum; i++) { - shdr = &info->sechdrs[i]; -if (shdr->sh_type ==SHT_SYMTAB ) { -if (shdr->sh_link ==SHN_UNDEF - || shdr->sh_link >= info->hdr->e_shnum) { -pr_err ("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n" , - shdr->sh_link, shdr->sh_link, - info->hdr->e_shnum); - goto no_exec; - } - num_sym_secs++; - sym_idx = i; - } - } - -if (num_sym_secs !=1 ) { -pr_warn ("%s: module has no symbols (stripped?)\n" , - info->name ?:"(missing .modinfo section or name field)" ); - goto no_exec; + str_idx = info->sechdrs[info->index.sym].sh_link; +if (str_idx ==SHN_UNDEF || str_idx >= info->hdr->e_shnum) { +pr_err ("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n" , + str_idx, str_idx, info->hdr->e_shnum); +return -ENOEXEC ; } -/* Sets internal symbols and strings. */ - info->index.sym = sym_idx; - shdr = &info->sechdrs[sym_idx]; - info->index.str = shdr->sh_link; +/* Sets internal strings. */ + info->index.str = str_idx; info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;/* This is temporary: point mod into copy of data. */
@@ -2057,9 +2075,6 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) info->index.pcpu =find_pcpusec (info);return 0 ; - -no_exec: -return -ENOEXEC ; }#define COPY_CHUNK_SIZE (16*PAGE_SIZE)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 401/3318 module: Factor out elf_validity_cache_index_str
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthew Maurer <[email protected]>
[ Upstream commit 0a9395334496d3be8bde491e46087540cb8f141d ]
Pull out index validation for the symbol string section.
Note that this does not validate the *contents* of the string table, only shape and presence of the section.
Stable-dep-of: 9a5ff4568932 ("module: validate string table section types")
--- kernel/module/main.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-)
kernel/module/main.c +28 -9
@@ -2005,6 +2005,31 @@ static int elf_validity_cache_index_sym(struct load_info *info)return 0 ; } +/** +* elf_validity_cache_index_str() - Validate and cache strtab index +* @info: Load info to cache strtab index in. +* Must have &load_info->sechdrs and &load_info->secstrings populated. +* Must have &load_info->index.sym populated. +* +* Looks at the symbol table's associated string table, makes sure it is +* in-bounds, and caches it. +* +* Return: %0 if valid, %-ENOEXEC on failure. +*/ +static int elf_validity_cache_index_str (struct load_info *info) +{ +unsigned int str_idx = info->sechdrs[info->index.sym].sh_link; + +if (str_idx ==SHN_UNDEF || str_idx >= info->hdr->e_shnum) { +pr_err ("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n" , + str_idx, str_idx, info->hdr->e_shnum); +return -ENOEXEC ; + } + + info->index.str = str_idx; +return 0 ; +} +/* * Check userspace passed ELF module against our expectations, and cache * useful variables for further processing as we go.
@@ -2028,7 +2053,6 @@ static int elf_validity_cache_index_sym(struct load_info *info)static int elf_validity_cache_copy (struct load_info *info,int flags) {int err; -int str_idx; err =elf_validity_cache_sechdrs (info);if (err <0 )
@@ -2045,16 +2069,11 @@ static int elf_validity_cache_copy(struct load_info *info, int flags) err =elf_validity_cache_index_sym (info);if (err <0 )return err; - - str_idx = info->sechdrs[info->index.sym].sh_link; -if (str_idx ==SHN_UNDEF || str_idx >= info->hdr->e_shnum) { -pr_err ("Invalid ELF sh_link!=SHN_UNDEF(%d) or (sh_link(%d) >= hdr->e_shnum(%d)\n" , - str_idx, str_idx, info->hdr->e_shnum); -return -ENOEXEC ; - } + err =elf_validity_cache_index_str (info); +if (err <0 ) +return err;/* Sets internal strings. */ - info->index.str = str_idx; info->strtab = (char *)info->hdr + info->sechdrs[info->index.str].sh_offset;/* This is temporary: point mod into copy of data. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 402/3318 module: validate string table section types
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thiébaud Weksteen <[email protected]>
[ Upstream commit 9a5ff45689329835f874cefe5174e577d141d423 ]
In elf_validity_cache_sechdrs, section sizes and offsets are validated, unless the section type is SHT_NULL or SHT_NOBITS.
Later, elf_validity_cache_secstrings and elf_validity_cache_index_str access the section name table (.shstrtab) and symbol string table (.strtab) headers without first ensuring that their types are SHT_STRTAB. If a section type is SHT_NULL or SHT_NOBITS, sh_offset has not been validated and may reference out-of-bounds memory when dereferenced in elf_validity_cache_secstrings or elf_validity_cache_strtab.
Validate that both string section headers are of type SHT_STRTAB before caching them.
--- kernel/module/main.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/module/main.c +13 -1
@@ -1819,6 +1819,7 @@ static int elf_validity_cache_sechdrs(struct load_info *info)* Specifically checks: * * * Section name table index is inbounds of section headers +* * Section name table type is SHT_STRTAB * * Section name table is not empty * * Section name table is NUL terminated * * All section name offsets are inbounds of the section
@@ -1846,6 +1847,11 @@ static int elf_validity_cache_secstrings(struct load_info *info) strhdr = &info->sechdrs[info->hdr->e_shstrndx]; +if (strhdr->sh_type !=SHT_STRTAB ) { +pr_err ("Invalid ELF section name table type: %u\n" , strhdr->sh_type); +return -ENOEXEC ; + } +/* * The section name table must be NUL-terminated, as required * by the spec. This makes strcmp and pr_* calls that access
@@ -2012,7 +2018,7 @@ static int elf_validity_cache_index_sym(struct load_info *info)* Must have &load_info->index.sym populated. * * Looks at the symbol table's associated string table, makes sure it is -* in-bounds, and caches it. +* in-bounds and of type SHT_STRTAB, and caches it. * * Return: %0 if valid, %-ENOEXEC on failure. */
@@ -2026,6 +2032,12 @@ static int elf_validity_cache_index_str(struct load_info *info)return -ENOEXEC ; } +if (info->sechdrs[str_idx].sh_type !=SHT_STRTAB ) { +pr_err ("Invalid ELF symbol string table type: %u\n" , + info->sechdrs[str_idx].sh_type); +return -ENOEXEC ; + } + info->index.str = str_idx;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 403/3318 scsi: qla2xxx: Clamp max_npiv_vports to VP_CTRL bitmap capacity
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nilesh Javali <[email protected]>
[ Upstream commit 2ac6a829843cf3df522d19e091276109b94c4c7a ]
ha->max_npiv_vports is taken from firmware (mcp->mb[11]) and only constrained so that (max_npiv_vports + 1) is a multiple of MIN_MULTI_ID_FABRIC, which permits values of 63, 127, 191 and 255. NPIV vports are then allocated up to that count.
VP enable uses the VP_CONFIG IOCB, which addresses a vport through a plain vp_index byte, so a vp_index beyond 128 is enabled without issue. VP disable, however, uses the VP_CTRL IOCB, which selects target vports through the fixed 128-bit vp_idx_map bitmap. qla24xx_control_vp() rejects a vp_index past that bitmap and the IOCB builder cannot set a bit beyond 127, yet qla24xx_vport_delete() frees the local state regardless. A vport with vp_index > 128 can therefore be created and enabled but never disabled, leaving it permanently active in firmware: a resource leak.
Cap ha->max_npiv_vports at init to the vp_idx_map capacity so such vports are never created. This collapses 191/255 to 127 (still modulo-valid) and leaves the real-world 63/127 cases unaffected.
--- drivers/scsi/qla2xxx/qla_fw.h | 4 ++++ drivers/scsi/qla2xxx/qla_init.c | 13 +++++++++++++ drivers/scsi/qla2xxx/qla_mid.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-)
drivers/scsi/qla2xxx/qla_fw.h +4 -0
@@ -1442,6 +1442,10 @@ struct vp_ctrl_entry_24xx {uint8_t reserved_5[24 ]; }; +/* vp_idx_map is a 128-bit (16-byte) bitmap selecting target VPs. */ +#define VP_CTRL_IDX_MAP_BITS \ + (sizeof_field(struct vp_ctrl_entry_24xx, vp_idx_map) * 8) +/* * Modify Virtual Port Configuration IOCB */
drivers/scsi/qla2xxx/qla_init.c +13 -0
@@ -4408,6 +4408,19 @@ qla2x00_setup_chip(scsi_qla_host_t *vha) MIN_MULTI_ID_FABRIC)) ha->max_npiv_vports =MIN_MULTI_ID_FABRIC -1 ; + +/* +* The VP_CTRL IOCB selects target VPs +* through the fixed vp_idx_map bitmap, +* so a vp_index beyond it can be enabled +* via VP_CONFIG but never disabled via +* VP_CTRL, leaking the VP. Cap the count +* to the bitmap capacity. +*/ +if (ha->max_npiv_vports >= +VP_CTRL_IDX_MAP_BITS ) + ha->max_npiv_vports = +VP_CTRL_IDX_MAP_BITS -1 ; }qla2x00_get_resource_cnts (vha);qla_init_iocb_limit (vha);
drivers/scsi/qla2xxx/qla_mid.c +1 -1
@@ -967,7 +967,7 @@ int qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)* (16-byte) vp_idx_map bitmap, so vp_index must fit within it even * if firmware advertises more NPIV vports. */ - if (vp_index > sizeof_field(struct vp_ctrl_entry_24xx, vp_idx_map) * 8) +if (vp_index >VP_CTRL_IDX_MAP_BITS )return QLA_PARAMETER_ERROR ;/* ref: INIT */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 404/3318 btrfs: do not overwrite NODATASUM flag when removing NODATACOW flag
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 15f7c86215e8d5f14b24127fa88af6c79363d50e ]
[TEST FAILURE]
The test case generic/628 will fail if MOUNT_OPTIONS is set to "-o nodatasum":
FSTYP -- btrfs PLATFORM -- Linux/x86_64 btrfs-vm 7.1.0-rc4-custom+ #383 SMP PREEMPT_DYNAMIC Sat May 30 07:35:42 ACST 2026 MKFS_OPTIONS -- -O bgt -K /dev/mapper/test-scratch1
MOUNT_OPTIONS -- -o nodatasum /dev/mapper/test-scratch1 /mnt/scratch
# generic/628 1s ... - output mismatch (see /home/adam/xfstests/results//generic/628.out.bad)
# --- tests/generic/628.out 2022-05-11 11:25:30.816666664 +0930 # +++ /home/adam/xfstests/results//generic/628.out.bad 2026-06-08 18:56:49.878542927 +0930 # @@ -8,8 +8,9 @@ # 310f146ce52077fcd3308dcbe7632bb2 SCRATCH_MNT/a # 310f146ce52077fcd3308dcbe7632bb2 SCRATCH_MNT/d # test reflink flag not set iflag # +XFS_IOC_CLONE: Invalid argument # 310f146ce52077fcd3308dcbe7632bb2 SCRATCH_MNT/a # -310f146ce52077fcd3308dcbe7632bb2 SCRATCH_MNT/b # +d41d8cd98f00b204e9800998ecf8427e SCRATCH_MNT/b
# ...
[CAUSE]
The direct cause is that after "chattr +S", the btrfs inode will lose its NODATASUM flag inherited from the mount option. E.g.:
# mkfs.btrfs -f $dev
# mount $dev $mnt -o nodatasum
# touch $mnt/foobar
# sync
# btrfs ins dump-tree -t 5 $dev | grep "(257 INODE_ITEM 0) itemoff" -A 3
item 4 key (257 INODE_ITEM 0) itemoff 15879 itemsize 160
generation 9 transid 9 size 0 nbytes 0
block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
sequence 1 flags 0x1(NODATASUM)
^^^^^^^^^ Proper NODATASUM flag # chattr +S $mnt/foobar
# sync
# btrfs ins dump-tree -t 5 $dev | grep "(257 INODE_ITEM 0) itemoff" -A 3
item 4 key (257 INODE_ITEM 0) itemoff 15879 itemsize 160
generation 9 transid 10 size 0 nbytes 0
block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0
sequence 2 flags 0x20(SYNC)
^^^^ Only the new SYNC flagThis makes the inode drop the old NODATASUM flag, while the new reflink destination will still inherit the NODATASUM flag. The mismatching NODATASUM flags will cause the reflink to fail.
The root cause is that, inside btrfs_fileattr_set() if no FS_NOCOW_FL is set, we remove both NODATASUM and NODATACOW flag.
However we should not touch NODATASUM flag, as data COW doesn't require checksum. Only NODATACOW implies NODATASUM, but DATACOW doesn't imply DATASUM.
The deeper problems are:
- Fileattr API is too binary
It either clears or sets a flag, there is no "do not change" option. So that why "chattr +S" implies "chattr -C", and is forcing us to change NODATACOW along with NODATASUM flag.
- No way to change NODATASUM through fileattr API
In fact NODATASUM can only be modified through mount option.
The deeper problems are much harder to attack.
[FIX]
Remove NODATACOW flag when FS_NOCOW_FL is not set, but only remove NODATASUM if "nodatasum" mount option is not set.
This allows the existing "chattr +C" then "chattr -C" to remove both NODATACOW and NODATASUM flags on a default mount.
But for a mount with "nodatasum" option, the NODATASUM inode flag will persist through either "chattr +C" and "chattr -C".
--- fs/btrfs/ioctl.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
fs/btrfs/ioctl.c +15 -8
@@ -321,14 +321,21 @@ int btrfs_fileattr_set(struct mnt_idmap *idmap, binode_flags |=BTRFS_INODE_NODATACOW ; } }else { -/* -* Revert back under same assumptions as above -*/ -if (S_ISREG (inode->i_mode)) { -if (inode->i_size ==0 ) - binode_flags &= ~(BTRFS_INODE_NODATACOW | -BTRFS_INODE_NODATASUM ); - }else { +/* We can only change NODATACOW for zero-sized regular file. */ +if (S_ISREG (inode->i_mode) && (inode->i_size ==0 )) { + binode_flags &= ~BTRFS_INODE_NODATACOW ; +/* +* There is currently no way to change NODATASUM flag +* through fileattr API. If we unconditionally keep the +* current NODATASUM flag, chattr +C then chattr -C will +* keep the NODATASUM flag, and no way to remove that +* flag. +* +* So respect the current mount option for NODATASUM flag. +*/ +if (!btrfs_test_opt (fs_info,NODATASUM )) + binode_flags &= ~BTRFS_INODE_NODATASUM ; + }else if (!S_ISREG (inode->i_mode)) { binode_flags &= ~BTRFS_INODE_NODATACOW ; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 405/3318 i3c: master: Fix potential UAF in i3c_device_uevent()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
[ Upstream commit e5e8dd2e959f470524c16ca444d001c90d6bb3ad ]
i3c_device_uevent() dereferences i3cdev->desc without holding the bus normal-use lock. Since the descriptor pointer can be replaced concurrently, including when a uevent is generated from sysfs, this can result in dereferencing a stale descriptor and lead to a use-after-free.
Use i3c_device_get_info() instead, which protects access to the descriptor with the normal-use lock.
Commit 6cf7b65f7029 ("i3c: Use i3cdev->desc->info instead of calling i3c_device_get_info() to avoid deadlock") replaced the accessor with a direct descriptor dereference because i3c_device_get_info() would recursively acquire bus->lock during device registration.
This change depends on "i3c: master: Fix recursive locking during device registration", which moves device registration out from under bus->lock and removes the possibility of that deadlock. Without that change, restoring the i3c_device_get_info() call would reintroduce the deadlock.
--- drivers/i3c/master.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/i3c/master.c +1 -2
@@ -280,8 +280,7 @@ static int i3c_device_uevent(const struct device *dev, struct kobj_uevent_env *estruct i3c_device_info devinfo;u16 manuf, part, ext; -if (i3cdev->desc) - devinfo = i3cdev->desc->info; +i3c_device_get_info (i3cdev, &devinfo); manuf =I3C_PID_MANUF_ID (devinfo.pid); part =I3C_PID_PART_ID (devinfo.pid); ext =I3C_PID_EXTRA_INFO (devinfo.pid);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 406/3318 futex: Sanitize and document task_struct::futex::state transitions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Gleixner <[email protected]>
[ Upstream commit f9ece060cc43eae8a1f148737d193ba0d07b8f88 ]
The futex state is used to prevent a waiter from attaching to the lock owner while the owner runs the futex cleanup in exit() or exec().
Only the state transition from FUTEX_STATE_OK to FUTEX_STATE_EXITING must be done with the task's pi_lock held, the transition away from FUTEX_STATE_EXITING has no serialization requirements on the writer side, but it's completely non obvious why. It's magically protected by exit_pi_state(), which operates under tsk::pi_lock, as that's the state which has to be correct when the waiter observes the new state.
OTOH, taking the pi_lock in futex_cleanup_end() is not a performance issue because at that point the lock should be uncontended in the vast majority of cases.
Aside of that the handling of FUTEX_STATE_EXITING in attach_to_pi_owner() and handle_exit_race() is confusing at best.
Protect the store in futex_cleanup_end() with tsk::pi_lock, handle FUTEX_STATE_EXITING in attach_to_pi_owner() explicitly and document how this is supposed to work.
--- kernel/futex/core.c | 8 ++-- kernel/futex/pi.c | 102 +++++++++++++++++++++++++++++++------------- 2 files changed, 75 insertions(+), 35 deletions(-)
kernel/futex/core.c +3 -5
@@ -1126,11 +1126,9 @@ static void futex_cleanup_begin(struct task_struct *tsk)static void futex_cleanup_end (struct task_struct *tsk,int state) { -/* -* Lockless store. The only side effect is that an observer might -* take another loop until it becomes visible. -*/ - tsk->futex_state = state; +scoped_guard (raw_spinlock_irq, &tsk->pi_lock) + tsk->futex_state = state; +/* * Drop the exit protection. This unblocks waiters which observed * FUTEX_STATE_EXITING to reevaluate the state.
kernel/futex/pi.c +72 -30
136 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 407/3318 svcrdma: Clear sc_cm_id when ADDR_CHANGE replacement fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chuck Lever <[email protected]>
[ Upstream commit 01500306e1d50de7ca7a2cdcdfa28ac0523eb747 ]
When svc_rdma_listen_handler() handles RDMA_CM_EVENT_ADDR_CHANGE, it creates a replacement listener cm_id and returns 1, telling the CM core to destroy the old one. If the replacement allocation fails, sc_cm_id still points at the old cm_id that the CM core is about to destroy. Any subsequent dereference of sc_cm_id -- such as svc_rdma_detach()'s rdma_disconnect() call -- is a use-after-free.
NULL sc_cm_id on the failure path and guard svc_rdma_detach()'s rdma_disconnect() call against NULL so that the listener can be torn down safely when the server shuts down.
--- net/sunrpc/xprtrdma/svc_rdma_transport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/sunrpc/xprtrdma/svc_rdma_transport.c +5 -2
@@ -303,6 +303,7 @@ static int svc_rdma_listen_handler(struct rdma_cm_id *cma_id,if (IS_ERR (listen_id)) {pr_err ("Listener dead, address change failed for device %s\n" , cma_id->device->name); + cma_xprt->sc_cm_id =NULL ; }else cma_xprt->sc_cm_id = listen_id;return 1 ;
@@ -582,7 +583,8 @@ static void svc_rdma_detach(struct svc_xprt *xprt)struct svcxprt_rdma *rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt); -rdma_disconnect (rdma->sc_cm_id); +if (rdma->sc_cm_id) +rdma_disconnect (rdma->sc_cm_id); }static void __svc_rdma_free (struct work_struct *work)
@@ -614,7 +616,8 @@ static void __svc_rdma_free(struct work_struct *work)ib_dealloc_pd (rdma->sc_pd);/* Destroy the CM ID */ -rdma_destroy_id (rdma->sc_cm_id); +if (rdma->sc_cm_id) +rdma_destroy_id (rdma->sc_cm_id);kfree (rdma); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 408/3318 nfsd: dedup nfs4_client_to_reclaim inserts
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 9b57793863f69c608691c98e57c2f9be2db9dfed ]
nfs4_client_to_reclaim() unconditionally allocates a new nfs4_client_reclaim, prepends it to reclaim_str_hashtbl[], and bumps reclaim_str_hashtbl_size with no check for an existing entry for the same client name. After a reboot with a populated recovery directory that inflates the counter by one for every client that reclaims:
boot: load_recdir()
nfs4_client_to_reclaim(name) /* entry #1, size++ */
grace: RECLAIM_COMPLETE
__nfsd4_create_reclaim_record_grace()
nfs4_client_to_reclaim(name) /* entry #2, size++ */inc_reclaim_complete() ends the grace period early only when
atomic_inc_return(&nn->nr_reclaim_complete) ==
nn->reclaim_str_hashtbl_sizeWith reclaim_str_hashtbl_size at 2N and nr_reclaim_complete capped at N, the equality never holds and the fast end-of-grace path is dead. The grace period always runs out the full 90-second laundromat timer, and the shadow entry left in the hash table carries a dangling cr_clp for any reader that walks it.
Fix nfs4_client_to_reclaim() to look the name up with nfsd4_find_reclaim_client() first and, on a hit, fold the new princhash into the existing record (if it lacks one) and return that record without allocating or touching reclaim_str_hashtbl_size. On kmemdup() failure during the fold-in, return NULL so __cld_pipe_inprogress_downcall() surfaces -EFAULT to nfsdcld, matching the miss-path contract.
Add an rw_semaphore (reclaim_str_hashtbl_lock) to struct nfsd_net that serialises all access to reclaim_str_hashtbl[] and reclaim_str_hashtbl_size. Writers (nfs4_client_to_reclaim, nfs4_remove_reclaim_record callers) hold the write side; readers (nfsd4_cld_check*, inc_reclaim_complete, clients_still_reclaiming, nfs4_has_reclaimed_state, nfsd4_check_legacy_client) hold the read side. All call sites are in sleepable context, and none is a hot path, so the rwsem cost is negligible.
--- fs/nfsd/netns.h | 6 ++++- fs/nfsd/nfs4recover.c | 46 +++++++++++++++++++++++++------- fs/nfsd/nfs4state.c | 61 ++++++++++++++++++++++++++++++++++++++----- 3 files changed, 96 insertions(+), 17 deletions(-)
fs/nfsd/netns.h +5 -1
@@ -93,6 +93,7 @@ struct nfsd_net {*/ struct list_head *reclaim_str_hashtbl;int reclaim_str_hashtbl_size; +struct rw_semaphore reclaim_str_hashtbl_lock;struct list_head *conf_id_hashtbl;struct rb_root conf_name_tree;struct list_head *unconf_id_hashtbl;
@@ -105,7 +106,10 @@ struct nfsd_net {* close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time * for last close replay. * -* All of the above fields are protected by the client_mutex. +* reclaim_str_hashtbl[], reclaim_str_hashtbl_size are protected by +* reclaim_str_hashtbl_lock. +* +* All of the remaining fields are protected by the client_lock. */ struct list_head client_lru;struct list_head close_lru;
fs/nfsd/nfs4recover.c +36 -10
157 lines not on this page · raw message
fs/nfsd/nfs4state.c +55 -6
122 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 409/3318 nfsd: use test_and_clear_bit for somebody_reclaimed to prevent lost update
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 0a5a548861ab09e79a6b3062ac17e410323af3cd ]
clients_still_reclaiming() uses separate test_bit() and clear_bit() calls on NFSD_NET_SOMEBODY_RECLAIMED. A concurrent set_bit() from the OPEN or LOCK reclaim path arriving between the test and clear is silently lost, causing the next laundromat tick to end grace prematurely.
Replace with test_and_clear_bit() to make the read-and-clear atomic.
--- fs/nfsd/nfs4state.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/nfsd/nfs4state.c +1 -2
@@ -6103,9 +6103,8 @@ static bool clients_still_reclaiming(struct nfsd_net *nn)if (atomic_read (&nn->nr_reclaim_complete) == size)return false; } -if (!test_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags)) +if (!test_and_clear_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags))return false; -clear_bit (NFSD_NET_SOMEBODY_RECLAIMED , &nn->flags);/* * If we've given them *two* lease times to reclaim, and they're * still not done, give up:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 410/3318 ALSA: hda/realtek: Enable micmute LED on HP EliteBook 6 G1a p/n: AD3Q9ET#UUG
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Denis Batishchev <[email protected]>
[ Upstream commit e7da28b820d12927de30abf554c727a319f80359 ]
The HP EliteBook 6 G1a (SSID 103c:8e0d) uses a Realtek ALC236 codec. Without a quirk no fixup is selected and the mic-mute LED stays off. It needs the same ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF quirk as the already-supported 14" variant (SSID 103c:8dfb), so add it.
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10329,6 +10329,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x103c ,0x8d84 ,"HP EliteBook X G1i" ,ALC285_FIXUP_HP_GPIO_LED ),SND_PCI_QUIRK (0x103c ,0x8d91 ,"HP ZBook Firefly 14 G12" ,ALC285_FIXUP_HP_GPIO_LED ),SND_PCI_QUIRK (0x103c ,0x8d92 ,"HP ZBook Firefly 16 G12" ,ALC285_FIXUP_HP_GPIO_LED ), +SND_PCI_QUIRK (0x103c ,0x8e0d ,"HP EliteBook 6 G1a 14 (AD3Q9ET#UUG)" ,ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF ),SND_PCI_QUIRK (0x103c ,0x8e18 ,"HP ZBook Firefly 14 G12A" ,ALC285_FIXUP_HP_GPIO_LED ),SND_PCI_QUIRK (0x103c ,0x8e19 ,"HP ZBook Firefly 14 G12A" ,ALC285_FIXUP_HP_GPIO_LED ), SND_PCI_QUIRK(0x103c, 0x8e1a, "HP ZBook Firefly 14 G12A", ALC285_FIXUP_HP_GPIO_LED),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 411/3318 ALSA: hda/ext: preserve PPLCCTL bits when clearing reset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
[ Upstream commit 36aa66de481d29edd63cbad9b5c4dc18c340fdf6 ]
snd_hdac_ext_stream_reset() polls PPLCCTL for STRST by masking the register value with AZX_PPLCCTL_STRST:
val = readl(...) & AZX_PPLCCTL_STRST;
The same masked value is then used when clearing STRST. Since val contains no bits other than STRST, clearing STRST from it always produces zero. The subsequent writel() therefore writes zero to the entire PPLCCTL register instead of clearing only the reset bit.
PPLCCTL contains other stream control fields, including the stream tag in AZX_PPLCCTL_STRM_MASK. Those fields must not be modified as a side effect of clearing stream reset.
Use snd_hdac_updatel() to clear STRST, matching the existing set-reset path and preserving all unrelated PPLCCTL bits.
--- sound/hda/ext/hdac_ext_stream.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/hda/ext/hdac_ext_stream.c +2 -2
@@ -169,8 +169,8 @@ void snd_hdac_ext_stream_reset(struct hdac_ext_stream *hext_stream)break ;udelay (3 ); }while (--timeout); - val &= ~AZX_PPLCCTL_STRST ; -writel (val, hext_stream->pplc_addr +AZX_REG_PPLCCTL ); +snd_hdac_updatel (hext_stream->pplc_addr,AZX_REG_PPLCCTL , +AZX_PPLCCTL_STRST ,0 );udelay (3 ); timeout =50 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 412/3318 usb: dwc3: gadget: Fix use-after-free in dwc3_gadget_free_endpoints due to race condition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
[ Upstream commit 9c855832790cd488d87de1885974f4c37cfe7358 ]
In dwc3_gadget_init_endpoint, &dep->nostream_work is bound with dwc3_nostream_work, and dwc3_gadget_endpoint_stream_event can queue this delayed work on system_percpu_wq when a DEPEVT_STREAM_NOSTREAM event is received.
If we remove the gadget, dwc3_gadget_free_endpoints makes cleanup and the memory allocated for dep with kzalloc() is released by kfree(dep), while the delayed work mentioned above may still be pending or running. The sequence of operations that may lead to a UAF bug is as follows:
CPU0 CPU1
| dwc3_thread_interrupt
| dwc3_endpoint_interrupt
| dwc3_gadget_endpoint_stream_event
| queue_delayed_work(system_percpu_wq,
| &dep->nostream_work)
dwc3_gadget_free_endpoints |
dwc3_free_trb_pool(dep) |
list_del(&dep->endpoint.ep_list) |
dwc3_debugfs_remove_endpoint_dir(dep) |
kfree(dep) |
// dep is freed |
| dwc3_nostream_work
| // use dep (use-after-free)Fix it by canceling the delayed work before kfree(dep) in dwc3_gadget_free_endpoints.
--- drivers/usb/dwc3/gadget.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/dwc3/gadget.c +1 -0
@@ -3505,6 +3505,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc) }dwc3_debugfs_remove_endpoint_dir (dep); +cancel_delayed_work_sync (&dep->nostream_work);kfree (dep); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 413/3318 platform/x86/intel/tpmi: Move TPMI ID definition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit 046d7be6210e7f870e53eb38fd410237e9d1d88f ]
Move TPMI ID definitions to common include file. In this way other feature drivers don't have to redefine.
Stable-dep-of: 574b59bb4b6b ("platform/x86: ISST: Validate parameter for frequency and priority")
--- drivers/platform/x86/intel/tpmi.c | 13 ------------- include/linux/intel_tpmi.h | 13 +++++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-)
drivers/platform/x86/intel/tpmi.c +0 -13
@@ -143,19 +143,6 @@ struct tpmi_info_header { u64 lock:1; } __packed; -/* -* List of supported TMPI IDs. -* Some TMPI IDs are not used by Linux, so the numbers are not consecutive. -*/ -enum intel_tpmi_id { -TPMI_ID_RAPL =0 ,/* Running Average Power Limit */ -TPMI_ID_PEM =1 ,/* Power and Perf excursion Monitor */ -TPMI_ID_UNCORE =2 ,/* Uncore Frequency Scaling */ -TPMI_ID_SST =5 ,/* Speed Select Technology */ -TPMI_CONTROL_ID =0x80 ,/* Special ID for getting feature status */ -TPMI_INFO_ID =0x81 ,/* Special ID for PCI BDF and Package ID information */ -}; -/* * The size from hardware is in u32 units. This size is from a trusted hardware, * but better to verify for pre silicon platforms. Set size to 0, when invalid.
include/linux/intel_tpmi.h +13 -0
@@ -12,6 +12,19 @@#define TPMI_MINOR_VERSION (val) FIELD_GET(GENMASK(4, 0), val)#define TPMI_MAJOR_VERSION (val) FIELD_GET(GENMASK(7, 5), val) +/* +* List of supported TMPI IDs. +* Some TMPI IDs are not used by Linux, so the numbers are not consecutive. +*/ +enum intel_tpmi_id { +TPMI_ID_RAPL =0 ,/* Running Average Power Limit */ +TPMI_ID_PEM =1 ,/* Power and Perf excursion Monitor */ +TPMI_ID_UNCORE =2 ,/* Uncore Frequency Scaling */ +TPMI_ID_SST =5 ,/* Speed Select Technology */ +TPMI_CONTROL_ID =0x80 ,/* Special ID for getting feature status */ +TPMI_INFO_ID =0x81 ,/* Special ID for PCI BDF and Package ID information */ +}; +/** * struct intel_tpmi_plat_info - Platform information for a TPMI device instance * @package_id: CPU Package id
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 414/3318 platform/x86: ISST: Process read/write blocked feature status
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit 8bed9ff7dbcce4d1a436f7839be48c6fd5fac0ce ]
When a feature is read blocked, don't continue to read SST information and register with SST core.
When the feature is write blocked, continue to offer read interface for SST parameters, but don't allow any operation to change state. A state change results from SST level change, feature change or class of service change.
Adapt to this tree: the TPMI core here only exposes a locked/disabled status query, which does not report firmware read/write blocked state, so the status query and the read-blocked early exit are dropped. The write_blocked field and the checks that honor it are kept so that the following change applies; the field stays false until the TPMI core can report it. The existing max_level and feature mask checks are kept next to the new write_blocked checks.
Stable-dep-of: 574b59bb4b6b ("platform/x86: ISST: Validate parameter for frequency and priority")
--- .../x86/intel/speed_select_if/isst_tpmi_core.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +15 -1
@@ -233,6 +233,7 @@ struct perf_level {* @saved_clos_configs: Save SST-CP CLOS configuration to store restore for suspend/resume * @saved_clos_assocs: Save SST-CP CLOS association to store restore for suspend/resume * @saved_pp_control: Save SST-PP control information to store restore for suspend/resume +* @write_blocked: Write operation is blocked, so can't change SST state * * This structure is used store complete SST information for a power_domain. This information * is used to read/write request for any SST IOCTL. Each physical CPU package can have multiple
@@ -258,6 +259,7 @@ struct tpmi_per_power_domain_info {u64 saved_clos_configs[4 ];u64 saved_clos_assocs[4 ];u64 saved_pp_control; +bool write_blocked; };/**
@@ -522,6 +524,9 @@ static long isst_if_clos_param(void __user *argp)return -EINVAL ;if (clos_param.get_set) { +if (power_domain_info->write_blocked) +return -EPERM ; + _write_cp_info("clos.min_freq", clos_param.min_freq_mhz, (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE), SST_CLOS_CONFIG_MIN_START, SST_CLOS_CONFIG_MIN_WIDTH,
@@ -619,6 +624,9 @@ static long isst_if_clos_assoc(void __user *argp) power_domain_info = &sst_inst->power_domain_info[punit_id]; +if (assoc_cmds.get_set && power_domain_info->write_blocked) +return -EPERM ; + offset =SST_CLOS_ASSOC_0_OFFSET + (punit_cpu_no /SST_CLOS_ASSOC_CPUS_PER_REG ) *SST_REG_SIZE ; shift = punit_cpu_no %SST_CLOS_ASSOC_CPUS_PER_REG ;
@@ -773,6 +781,9 @@ static int isst_if_set_perf_level(void __user *argp)if (perf_level.level > power_domain_info->max_level)return -EINVAL ; +if (power_domain_info->write_blocked) +return -EPERM ; +if (!(power_domain_info->pp_header.allowed_level_mask &BIT (perf_level.level)))return -EINVAL ;
@@ -833,6 +844,9 @@ static int isst_if_set_perf_feature(void __user *argp)if (perf_feature.feature & ~SST_PP_FEATURE_STATE_VALID_MASK )return -EINVAL ; +if (power_domain_info->write_blocked) +return -EPERM ; +_write_pp_info ("perf_feature" , perf_feature.feature,SST_PP_CONTROL_OFFSET ,SST_PP_FEATURE_STATE_START ,SST_PP_FEATURE_STATE_WIDTH ,SST_MUL_FACTOR_NONE )
@@ -1342,7 +1356,7 @@ int tpmi_sst_dev_add(struct auxiliary_device *auxdev) tpmi_sst->power_domain_info[i].package_id = pkg; tpmi_sst->power_domain_info[i].power_domain_id = i; tpmi_sst->power_domain_info[i].auxdev = auxdev; - tpmi_sst->power_domain_info[i].sst_base =devm_ioremap_resource (&auxdev->dev, res); + tpmi_sst->power_domain_info[i].sst_base =devm_ioremap_resource (&auxdev->dev, res);if (IS_ERR (tpmi_sst->power_domain_info[i].sst_base))return PTR_ERR (tpmi_sst->power_domain_info[i].sst_base);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 415/3318 platform/x86: ISST: Validate parameter for frequency and priority
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit 574b59bb4b6bfcfd1f639d02f1041b314d43a2e6 ]
Validate range for frequency and proportional priority while setting CLOS parameters.
--- .../x86/intel/speed_select_if/isst_tpmi_core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +12 -0
@@ -508,6 +508,9 @@ static long isst_if_core_power_state(void __user *argp)#define SST_MAX_CLOS 3 +#define SST_MAX_FREQ 0xff +#define SST_CLOS_MAX_PRIORITY 0x0f +static long isst_if_clos_param (void __user *argp) {struct tpmi_per_power_domain_info *power_domain_info;
@@ -527,6 +530,15 @@ static long isst_if_clos_param(void __user *argp)if (power_domain_info->write_blocked)return -EPERM ; +if (!in_range (clos_param.min_freq_mhz /SST_MUL_FACTOR_FREQ ,0 ,SST_MAX_FREQ +1 )) +return -EINVAL ; + +if (!in_range (clos_param.max_freq_mhz /SST_MUL_FACTOR_FREQ ,0 ,SST_MAX_FREQ +1 )) +return -EINVAL ; + +if (!in_range (clos_param.prop_prio,0 ,SST_CLOS_MAX_PRIORITY +1 )) +return -EINVAL ; + _write_cp_info("clos.min_freq", clos_param.min_freq_mhz, (SST_CLOS_CONFIG_0_OFFSET + clos_param.clos * SST_REG_SIZE), SST_CLOS_CONFIG_MIN_START, SST_CLOS_CONFIG_MIN_WIDTH,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 416/3318 platform/x86: ISST: Use PP level enable mask
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit 9b9026943b19d06ebf520b1f4786621947cf43c8 ]
Add check for enabled levels only when reading MMIO. Some levels can be disabled by BIOS. If the level is not enabled, return an error.
Reset the enable and allowed level masks if there is a failure to add a perf level.
--- .../intel/speed_select_if/isst_tpmi_core.c | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +23 -7
@@ -318,8 +318,11 @@ static int sst_add_perf_profiles(struct auxiliary_device *auxdev, pd_info->perf_levels =devm_kcalloc (&auxdev->dev, levels,sizeof (struct perf_level ),GFP_KERNEL ); -if (!pd_info->perf_levels) +if (!pd_info->perf_levels) { + pd_info->pp_header.allowed_level_mask =0 ; + pd_info->pp_header.level_en_mask =0 ;return 0 ; + } pd_info->ratio_unit = pd_info->pp_header.ratio_unit; pd_info->avx_levels =SST_MAX_AVX_LEVELS ;
@@ -757,12 +760,16 @@ static int isst_if_get_perf_level(void __user *argp) SST_PP_FEATURE_STATE_START, SST_PP_FEATURE_STATE_WIDTH, SST_MUL_FACTOR_NONE) perf_level.enabled = !!(power_domain_info->sst_header.cap_mask &BIT (1 )); -_read_bf_level_info ("bf_support" , perf_level.sst_bf_support,0 ,0 , -SST_BF_FEATURE_SUPPORTED_START ,SST_BF_FEATURE_SUPPORTED_WIDTH , -SST_MUL_FACTOR_NONE ); -_read_tf_level_info ("tf_support" , perf_level.sst_tf_support,0 ,0 , -SST_TF_FEATURE_SUPPORTED_START ,SST_TF_FEATURE_SUPPORTED_WIDTH , -SST_MUL_FACTOR_NONE ); + perf_level.sst_bf_support =0 ; + perf_level.sst_tf_support =0 ; +if (power_domain_info->pp_header.level_en_mask &BIT (0 )) { +_read_bf_level_info ("bf_support" , perf_level.sst_bf_support,0 ,0 , +SST_BF_FEATURE_SUPPORTED_START ,SST_BF_FEATURE_SUPPORTED_WIDTH , +SST_MUL_FACTOR_NONE ); +_read_tf_level_info ("tf_support" , perf_level.sst_tf_support,0 ,0 , +SST_TF_FEATURE_SUPPORTED_START ,SST_TF_FEATURE_SUPPORTED_WIDTH , +SST_MUL_FACTOR_NONE ); + }if (copy_to_user (argp, &perf_level,sizeof (perf_level)))return -EFAULT ;
@@ -1113,6 +1120,9 @@ static int isst_if_get_base_freq_info(void __user *argp)if (base_freq.level > power_domain_info->max_level)return -EINVAL ; +if (!(power_domain_info->pp_header.level_en_mask &BIT (base_freq.level))) +return -EINVAL ; +_read_bf_level_info ("p1_high" , base_freq.high_base_freq_mhz, base_freq.level,SST_BF_INFO_0_OFFSET ,SST_BF_P1_HIGH_START ,SST_BF_P1_HIGH_WIDTH ,SST_MUL_FACTOR_FREQ )
@@ -1152,6 +1162,9 @@ static int isst_if_get_base_freq_mask(void __user *argp)if (cpumask.level > power_domain_info->max_level)return -EINVAL ; +if (!(power_domain_info->pp_header.level_en_mask &BIT (cpumask.level))) +return -EINVAL ; +_read_bf_level_info ("BF-cpumask" , mask, cpumask.level,SST_BF_INFO_1_OFFSET ,P1_HI_CORE_MASK_START ,P1_HI_CORE_MASK_WIDTH ,SST_MUL_FACTOR_NONE )
@@ -1231,6 +1244,9 @@ static int isst_if_get_turbo_freq_info(void __user *argp)if (turbo_freq.level > power_domain_info->max_level)return -EINVAL ; +if (!(power_domain_info->pp_header.level_en_mask &BIT (turbo_freq.level))) +return -EINVAL ; + turbo_freq.max_buckets =TRL_MAX_BUCKETS ; turbo_freq.max_trl_levels =TRL_MAX_LEVELS ; turbo_freq.max_clip_freqs =SST_TF_MAX_LP_CLIP_RATIOS ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 417/3318 platform/x86: ISST: Return error during profile addition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Srinivas Pandruvada <[email protected]>
[ Upstream commit f9a647cb8d90c09633a49a1e766e140e78012444 ]
If sst_add_perf_profiles() fails for memory allocation, it continues to allow SST-CP (core-power) feature. But in practice this is not very useful as to achieve some frequencies via SST-CP, an SST-PP (perf-profile) level change is required.
--- .../x86/intel/speed_select_if/isst_tpmi_core.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/platform/x86/intel/speed_select_if/isst_tpmi_core.c +7 -3
@@ -321,7 +321,7 @@ static int sst_add_perf_profiles(struct auxiliary_device *auxdev,if (!pd_info->perf_levels) { pd_info->pp_header.allowed_level_mask =0 ; pd_info->pp_header.level_en_mask =0 ; -return 0 ; +return -ENOMEM ; } pd_info->ratio_unit = pd_info->pp_header.ratio_unit;
@@ -351,7 +351,7 @@ static int sst_add_perf_profiles(struct auxiliary_device *auxdev,static int sst_main (struct auxiliary_device *auxdev,struct tpmi_per_power_domain_info *pd_info) { -int i, mask, levels; +int i, ret, mask, levels; *((u64 *)&pd_info->sst_header) =readq (pd_info->sst_base); pd_info->sst_header.cp_offset *=8 ;
@@ -379,8 +379,12 @@ static int sst_main(struct auxiliary_device *auxdev, struct tpmi_per_power_domai levels = i; mask <<=1 ; } + + ret =sst_add_perf_profiles (auxdev, pd_info, levels +1 ); +if (ret) +return ret; + pd_info->max_level = levels; -sst_add_perf_profiles (auxdev, pd_info, levels +1 );return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 418/3318 platform/x86: think-lmi: Fix certificate thumbprint sysfs output
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 4f3183f5ae9b8ddfe338d79a96146a05342bbe50 ]
cert_thumbprint() already returns the accumulated output length, but certificate_thumbprint_show() adds that value to count again, making the next line use the wrong offset. Errors returned by cert_thumbprint() are also ignored and their negative values added to count.
Assign the total length to count instead and propagate errors correctly.
--- drivers/platform/x86/think-lmi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/platform/x86/think-lmi.c +9 -3
@@ -680,9 +680,15 @@ static ssize_t certificate_thumbprint_show(struct kobject *kobj, struct kobj_attif (!tlmi_priv.certificate_support || !setting->cert_installed)return -EOPNOTSUPP ; - count +=cert_thumbprint (buf,"Md5" , count); - count +=cert_thumbprint (buf,"Sha1" , count); - count +=cert_thumbprint (buf,"Sha256" , count); + count =cert_thumbprint (buf,"Md5" , count); +if (count <0 ) +return count; + count =cert_thumbprint (buf,"Sha1" , count); +if (count <0 ) +return count; + count =cert_thumbprint (buf,"Sha256" , count); +if (count <0 ) +return count;return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 419/3318 platform/x86: think-lmi: Fix current password length check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
[ Upstream commit 54745d563114b74f6fecebce68cd020d06c1772b ]
current_password_store() checks the password length before removing the trailing newline, which can reject valid passwords that are exactly ->maxlen bytes long.
It also passes ->maxlen to strscpy(), which truncates passwords without a newline.
Use strchrnul() to measure the password length up to the newline, then copy that many bytes and add a trailing NUL terminator using strscpy().
--- drivers/platform/x86/think-lmi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/platform/x86/think-lmi.c +3 -4
@@ -403,14 +403,13 @@ static ssize_t current_password_store(struct kobject *kobj,struct tlmi_pwd_setting *setting =to_tlmi_pwd_setting (kobj);size_t pwdlen; - pwdlen =strlen (buf); +/* Strip newline; setting password won't work if one is present. */ + pwdlen =strchrnul (buf,'\n' ) - buf;/* pwdlen == 0 is allowed to clear the password */ if (pwdlen && ((pwdlen < setting->minlen) || (pwdlen > setting->maxlen)))return -EINVAL ; -strscpy (setting->password, buf, setting->maxlen); -/* Strip out CR if one is present, setting password won't work if it is present */ -strip_cr (setting->password); +strscpy (setting->password, buf, pwdlen +1 );return count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 420/3318 net/mlx5e: do not HW-GRO coalesce small frames
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Glenn Judd <[email protected]>
[ Upstream commit e2466392a0b8496000e12181cb1ee1535eb0da25 ]
When hardware GRO (SHAMPO) coalesces a small IPv4/TCP segment that was padded up to the 60-byte minimum Ethernet frame, the trailing padding is folded into the merged payload causing padding to be delivered to the user as payload.
Detecting and reproducing the issue: the selftest tools/testing/selftests/drivers/net/gro.py subtest hw_ipv4_data_lrg_1byte sends {100, 1} expecting to receive {101}. In current code, it receives {106} (100 + 1 payload + 5 pad) instead.
This patch avoids giving the user padding as payload by simply not coalescing small packets (which fails the subtest; the same approach and behavior as sw gro). This gains code simplicity at the cost of more computation (passing an extra skb up the stack) for small packets that could be coalesced.
The threshold is chosen as ETH_ZLEN + 2 * VLAN_HLEN. This is the largest frame that may still contain minimum-frame padding (+ 2 VLAN tags), so anything larger is safe to consider for coalesce. (We do not include ETH_FCS_LEN in that threshold computation as netdev_fix_features() drops NETIF_F_GRO_HW whenever NETIF_F_RXFCS is set, so retained FCS can't reach this path.)
--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +6 -1
@@ -2376,6 +2376,11 @@ static void mlx5e_handle_rx_cqe_mpwrq_shampo(struct mlx5e_rq *rq, struct mlx5_cq goto mpwrq_cqe_out; } +if (unlikely (cqe_bcnt <=ETH_ZLEN +2 *VLAN_HLEN )) { + match = false; + flush = true; + } + stats->gro_match_packets += match;if (*skb && (!match || !(mlx5e_hw_gro_skb_has_enough_space (*skb, data_bcnt)))) {
@@ -2415,7 +2420,7 @@ static void mlx5e_handle_rx_cqe_mpwrq_shampo(struct mlx5e_rq *rq, struct mlx5_cq }mlx5e_shampo_complete_rx_cqe (rq, cqe, cqe_bcnt, *skb); -if (flush) +if (flush && *skb)mlx5e_shampo_flush_skb (rq, cqe, match); free_hd_entry:if (likely (head_size))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 421/3318 drm/amdgpu: Disable runtime PM for externally attached dGPUs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yang Wang <[email protected]>
[ Upstream commit c52feb4365396b6a881b5e8a95540517ffabb3b7 ]
pci_is_thunderbolt_attached() requires an upstream PCI bridge with is_thunderbolt set from an Intel Thunderbolt VSEC. This does not cover the affected ASM4242 USB4 PCI hierarchy:
00:02.2
\- 0f:00.0 [1b21:2421]
+- 10:01.0 [1b21:2423] -> 45:00.0 -> 46:00.0
| -> 47:00.0 -> 48:00.0 -> 49:00.0 [1002:7590]
\- 10:03.0 -> 76:00.0 [1b21:2425] USB4 Host RouterThe host router is outside the GPU upstream bridge chain, leaving no ancestor with is_thunderbolt set. PCI core propagates DEVICE_REMOVABLE below the external-facing PCIe tunnel. Disable Runtime PM when either pci_is_thunderbolt_attached() or dev_is_removable() is true.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -2
@@ -152,8 +152,12 @@ int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags) } adev->pm.rpm_mode =AMDGPU_RUNPM_NONE ; -if (amdgpu_device_supports_px (dev) && - (amdgpu_runtime_pm !=0 )) {/* enable PX as runtime mode */ +if (pci_is_thunderbolt_attached (adev->pdev) || +dev_is_removable (&adev->pdev->dev)) { +dev_info (adev->dev, +"Runtime PM disabled for externally attached device\n" ); + }else if (amdgpu_device_supports_px (dev) && + (amdgpu_runtime_pm !=0 )) {/* enable PX as runtime mode */ adev->pm.rpm_mode =AMDGPU_RUNPM_PX ;dev_info (adev->dev,"Using ATPX for runtime pm\n" ); } else if (amdgpu_device_supports_boco(dev) &&
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 422/3318 drm/amdgpu: force complete the MES ring fences on reset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jesse Zhang <[email protected]>
[ Upstream commit 48dc279c3010ac8f91b1845b2abb3a1e9943a0f5 ]
The MES scheduler ring has no drm scheduler (no_scheduler = true), so it is skipped by the force-completion loop in amdgpu_device_pre_asic_reset(). It uses a polling fence whose hw value lives in wb (GTT) memory and survives a MODE1 reset, while fence_drv.sync_seq keeps advancing for every packet.
When the reset is triggered because MES itself stopped responding, the timed-out packets advance sync_seq past the last hw fence value MES wrote. After resume the first MES submission polls forever on a seq that is never written back, failing the resume and wedging the box on a second reset:
amdgpu: MES ring buffer is full.
amdgpu: *ERROR* ring gfx_0.0.0 test failed (-110)
amdgpu: resume of IP block <gfx_v11_0> failed -110
amdgpu: GPU reset end with ret = -110
Force complete the MES scheduler ring fences together with the scheduler rings so their hw fence is realigned to sync_seq.
v2: cover all XCCs (one scheduler ring each), not just mes.ring[0].
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +9 -0
@@ -4950,6 +4950,15 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,amdgpu_fence_driver_force_completion (kiq_ring); } +/* +* MES scheduler rings have no drm scheduler, so they are missed by the +* loop above. Realign their polling fence too, otherwise the +* first post-reset submission polls forever on a stale seq. sched.ready is +* only set while the driver owns the ring. +*/ +if (adev->mes.ring.fence_drv.initialized && adev->mes.ring.sched.ready) +amdgpu_fence_driver_force_completion (&adev->mes.ring); +amdgpu_fence_driver_isr_toggle (adev, false);if (job && job->vm)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 423/3318 tracing: Fix logged instance name on creation failure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
[ Upstream commit a9a01be2834a529cbd490ccbab02643f0c1735f2 ]
When boot instance creation fails, the kernel incorrectly logs "(null)" as the instance name because strsep() consumes curr_str entirely during parsing.
Print the properly parsed name variable instead. And while at it log the error code.
--- kernel/trace/trace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
@@ -10437,7 +10437,7 @@ __init static void enable_instances(void) tr =trace_array_get_by_name (tok,NULL );if (!tr) { -pr_warn ("Failed to create instance buffer %s\n" , curr_str); +pr_warn ("Failed to create instance buffer '%s'\n" , tok);continue ; }/* Allow user space to delete it */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 424/3318 ALSA: hda/realtek: Add quirk for TongFang X6xx45xU
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eckhart Mohr <[email protected]>
[ Upstream commit d595255241e5fec0c94adeebf2565524398e37c5 ]
Fix microphone detection on built in headphone jack for some devices.
Stable-dep-of: e72d5659a260 ("ALSA: hda/realtek: Add quirk for TongFang XxAF5xxx")
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10737,6 +10737,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1d05 ,0x300f ,"TongFang X6AR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3019 ,"TongFang X6FR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3031 ,"TongFang X6AR55xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6xx45xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d17 ,0x3288 ,"Haier Boyue G42" ,ALC269VC_FIXUP_ACER_VCOPPERBOX_PINS ),SND_PCI_QUIRK (0x1d72 ,0x1602 ,"RedmiBook" ,ALC255_FIXUP_XIAOMI_HEADSET_MIC ), SND_PCI_QUIRK(0x1d72, 0x1701, "XiaomiNotebook Pro", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 425/3318 ALSA: hda/realtek: Add quirk for TongFang X6SP45xU
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eckhart Mohr <[email protected]>
[ Upstream commit 26a94400ffa4fcbeff32e23abebb83a1a20eb401 ]
TongFang X6KK45xU and X6SP45xU have actually different PCI IDs. This patch Adds the missing PCI ID to fix headphone detection and clarifies the naming.
Stable-dep-of: e72d5659a260 ("ALSA: hda/realtek: Add quirk for TongFang XxAF5xxx")
--- sound/pci/hda/patch_realtek.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/pci/hda/patch_realtek.c +2 -1
@@ -10737,7 +10737,8 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1d05 ,0x300f ,"TongFang X6AR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3019 ,"TongFang X6FR5xxY" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3031 ,"TongFang X6AR55xU" ,ALC2XX_FIXUP_HEADSET_MIC ), -SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6xx45xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x3033 ,"TongFang X6SP45xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6KK45xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d17 ,0x3288 ,"Haier Boyue G42" ,ALC269VC_FIXUP_ACER_VCOPPERBOX_PINS ),SND_PCI_QUIRK (0x1d72 ,0x1602 ,"RedmiBook" ,ALC255_FIXUP_XIAOMI_HEADSET_MIC ), SND_PCI_QUIRK(0x1d72, 0x1701, "XiaomiNotebook Pro", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 426/3318 ALSA: hda/realtek: Add quirk for TongFang XxAF5xxx
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eckhart Mohr <[email protected]>
[ Upstream commit e72d5659a2606056a0c34af212b46a3275a55bbf ]
Fix microphone detection on built in headphone jack for some devices
--- sound/pci/hda/patch_realtek.c | 1 + 1 file changed, 1 insertion(+)
sound/pci/hda/patch_realtek.c +1 -0
@@ -10739,6 +10739,7 @@ static const struct hda_quirk alc269_fixup_tbl[] = {SND_PCI_QUIRK (0x1d05 ,0x3031 ,"TongFang X6AR55xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3033 ,"TongFang X6SP45xU" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d05 ,0x3034 ,"TongFang X6KK45xU" ,ALC2XX_FIXUP_HEADSET_MIC ), +SND_PCI_QUIRK (0x1d05 ,0x30ba ,"TongFang XxAF5xxx" ,ALC2XX_FIXUP_HEADSET_MIC ),SND_PCI_QUIRK (0x1d17 ,0x3288 ,"Haier Boyue G42" ,ALC269VC_FIXUP_ACER_VCOPPERBOX_PINS ),SND_PCI_QUIRK (0x1d72 ,0x1602 ,"RedmiBook" ,ALC255_FIXUP_XIAOMI_HEADSET_MIC ), SND_PCI_QUIRK(0x1d72, 0x1701, "XiaomiNotebook Pro", ALC298_FIXUP_DELL1_MIC_NO_PRESENCE),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 427/3318 mm: mempolicy: fix automatic numa balancing for shmem
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Weiner <[email protected]>
[ Upstream commit d230991493b521eeff39f32434fddcbcdb109eb0 ]
Neha reports that mapped shmem aren't considered for NUMA balancing, noting convergence problems and bandwidth bottlenecking for cachelib based workloads on tiered memory systems.
Looking at the code and going through the git history, this doesn't actually seem intentional:
Commit fc3147245d19 ("mm: numa: Limit NUMA scanning to migrate-on-fault VMAs") added a vma_policy_mof() gate to task_numa_work() so VMAs whose policy lacks MPOL_F_MOF are skipped from NUMA balancing scans. The motivation was a real usecase: Oracle was pinning shared segments with mbind(MPOL_BIND) so trapping faults was both expensive and pointless.
The handling of NULL from vm_ops->get_policy, however, treated "user explicitly opted out" the same as "user never specified anything." For VMAs whose shared policy is absent - the common case for shmem - the scan was disabled too.
This issue is old. It probably hurts less in conventional NUMA. But it's very noticeable on tiered systems, where entire tmpfs workingsets can get stuck on lower-bandwidth memory.
Fix this by having vma_policy_mof() use __get_vma_policy() directly, and thereby handle the fallback to task policy (-> preferred_node_policy() has MPOL_F_MOF per default). Every other consumer of vm_ops->get_policy already handles it this way, the scan-eligibility check was the outlier.
This preserves Mel's intended fix: don't scan stuff the user explicitly pinned. But allow default policy vmas to participate in balancing.
--- mm/mempolicy.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-)
mm/mempolicy.c +5 -14
@@ -1799,23 +1799,14 @@ static struct mempolicy *get_vma_policy(struct vm_area_struct *vma,bool vma_policy_mof (struct vm_area_struct *vma) {struct mempolicy *pol; +bool mof; -if (vma->vm_ops && vma->vm_ops->get_policy) { -bool ret = false; - - pol = vma->vm_ops->get_policy (vma, vma->vm_start); -if (pol && (pol->flags &MPOL_F_MOF )) - ret = true; -mpol_cond_put (pol); - -return ret; - } - - pol = vma->vm_policy; + pol =__get_vma_policy (vma, vma->vm_start);if (!pol) pol =get_task_policy (current); - -return pol->flags &MPOL_F_MOF ; + mof = pol->flags &MPOL_F_MOF ; +mpol_cond_put (pol); +return mof; }bool apply_policy_zone (struct mempolicy *policy,enum zone_type zone)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 428/3318 mm/kmemleak: report RCU-tasks quiescent states during the scan
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 3541a2b06ecd78ba333188df04368dcf97273d6a ]
kmemleak_scan() can run for ages on large debug kernels. It was causing some soft-lockups which I got fixed with commit 3175fcfec8b16baeb ("mm/kmemleak: avoid soft lockup when scanning task stacks") with our beloved cond_resched().
I've got the fix above deployed in the Meta fleet, and now I am seeing:
INFO: rcu_tasks detected stalls on tasks:
task:kmemleak state:R ... nvcsw: 274/274 holdout: 1 idle_cpu: -1/3
scan_block
scan_gray_list
kmemleak_scanand, worse, blocks the callers waiting on that grace period. Here a BPF struct_ops map free, which waits via synchronize_rcu_mult(call_rcu, call_rcu_tasks), is stuck long enough to also trip the hung task check:
INFO: task kworker/...:bpf_map_free_deferred blocked for 122 seconds
__wait_rcu_gp
bpf_struct_ops_map_freeThen I've learned that cond_resched() is not an RCU-tasks quiescent state, so, we need to use stronger primitives.
Use cond_resched_tasks_rcu_qs() at the scan reschedule points so the scan reports an RCU-tasks quiescent state as it proceeds.
Inspired by commit b96285e10aad ("tracing: Have osnoise_main() add a quiescent state for task rcu").
--- mm/kmemleak.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
mm/kmemleak.c +6 -6
@@ -1397,7 +1397,7 @@ static void scan_large_block(void *start, void *end) next =min (start +MAX_SCAN_SIZE , end);scan_block (start, next,NULL ); start = next; - cond_resched(); + cond_resched_tasks_rcu_qs(); } }#endif
@@ -1442,7 +1442,7 @@ static void scan_object(struct kmemleak_object *object)break ;raw_spin_unlock_irqrestore (&object->lock, flags); -cond_resched (); +cond_resched_tasks_rcu_qs ();raw_spin_lock_irqsave (&object->lock, flags); }while (object->flags &OBJECT_ALLOCATED ); }else
@@ -1469,7 +1469,7 @@ static void scan_gray_list(void)*/ object =list_entry (gray_list.next,typeof (*object), gray_list);while (&object->gray_list != &gray_list) { -cond_resched (); +cond_resched_tasks_rcu_qs ();/* may add new objects to the list */ if (!scan_should_stop ())
@@ -1504,7 +1504,7 @@ static void kmemleak_cond_resched(struct kmemleak_object *object)raw_spin_unlock_irq (&kmemleak_lock);rcu_read_unlock (); -cond_resched (); +cond_resched_tasks_rcu_qs ();rcu_read_lock ();raw_spin_lock_irq (&kmemleak_lock);
@@ -1548,7 +1548,7 @@ static void kmemleak_scan_task_stacks(void) }put_task_struct (p); } -cond_resched (); +cond_resched_tasks_rcu_qs (); }while (pid && !scan_should_stop ()); }
@@ -1624,7 +1624,7 @@ static void kmemleak_scan(void)struct page *page =pfn_to_online_page (pfn);if (!(pfn &63 )) -cond_resched (); +cond_resched_tasks_rcu_qs ();if (!page)continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 429/3318 memcg: bypass the reclaim and oom killer for dying tasks once oom_reaper is done
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
[ Upstream commit 6b0d1083364fc8e7cc2f7d1f93ee3ee78f4d52f7 ]
At Meta, we are seeing instances where an OOM killed job is stuck in the exit path for several hours. In one particular case, the job was stuck for more than 8 hours and I had to manually remove the memory.max limits to allow the process to exit.
The job was a single process job and had ~55 GiB memory.max and zswap enabled. It had almost 0 anon in memory and ~111 GiB in zswap compressed to ~51 GiB zswap pool (i.e. almost all of memory.current was zswap). Nothing was left on the LRUs to reclaim.
On further inspection, I observed ~20k threads of that process stuck with the following stack:
[<0>] mem_cgroup_out_of_memory+0x4e/0xa0 [<0>] charge_memcg+0x8bf/0x990 [<0>] mem_cgroup_swapin_charge_folio+0x4e/0x80 [<0>] __read_swap_cache_async+0x10c/0x260 [<0>] swapin_readahead+0x116/0x3f0 [<0>] do_swap_page+0x13c/0x1ce0 [<0>] handle_mm_fault+0x61d/0x11f0 [<0>] do_user_addr_fault+0x3e7/0x6d0 [<0>] exc_page_fault+0x8f/0x110 [<0>] asm_exc_page_fault+0x22/0x30 [<0>] __get_user_8+0x14/0x20 [<0>] futex_cleanup+0x27/0x1c0 [<0>] futex_exit_release+0x47/0x60 [<0>] do_exit+0x107/0x940 [<0>] do_group_exit+0x81/0xa0 [<0>] get_signal+0x2b1/0x6e0 [<0>] arch_do_signal_or_restart+0x1a/0x1c0 [<0>] exit_to_user_mode_loop+0xa8/0x1c0 [<0>] do_syscall_64+0x152/0x250 [<0>] entry_SYSCALL_64_after_hwframe+0x4b/0x53
In addition the dmesg was filled with "Out of memory and no killable processes..." messages.
I have no idea why oom reaper was not able to reap/unmap the process. My guess is that since oom reaper tries to acquire mmap_lock in read mode limited number of times and then gives up, there might be a thread of that process which had mmap_lock in write mode at that time.
My initial suspicion was the futex_cleanup and kernel page fault causing infinite fault and charge retries but that was put to rest in previous discussions happened on similar problem [1].
My current theory is that it is just a simple slow serialization behind the oom_lock. Unlike page allocator, memcg charge code takes the oom_lock without the "try". Though memcg oom code uses mutex_lock_killable(), note that in the call stack get_signal() consumes SIGKILL (or sigdelset(SIGKILL)) before calling do_group_exit(). So this mutex_lock_killable() is just a mutex_lock() here. Therefore 10s of thousands of threads are waiting on oom_lock and one by one they get -EFAULT from get_user() in the futex cleanup code and bails out.
Discussion from [1] led to commit a75ffa26122b ("memcg, oom: do not bypass oom killer for dying tasks") which routes dying tasks into the OOM path precisely so the oom_reaper can reap their mm and free the memory asynchronously. But the reaper is best-effort and one-shot: if it cannot take mmap_lock for read (e.g. a sibling thread holds it for write) it sets MMF_OOM_SKIP and never retries, leaving only the glacial oom_lock-serialized synchronous drain.
Once MMF_OOM_SKIP is set there is no more asynchronous reclaim coming for the mm, so a dying task charging against it has nothing left to wait for:
it frees its memory only once it finishes exiting. Running reclaim and the (no-victim) OOM killer for it is then pointless, and doing it for 10s of thousands of exiting threads is what serializes them behind oom_lock. So before reclaim, if current is an OOM victim whose reaper is done, fail the charge.
Reproduced with 20k threads, each parking a robust futex head on its own zswapped page, OOM-group-killed while a sibling holds mmap_lock for write so the reaper gives up and sets MMF_OOM_SKIP. Tested on next-20260728 and baseline show ~90 seconds exit time while with the patch the exit time reduced to ~3 seconds.
to ~51 GiB zswap pool (i.e. almost all of memory.current was zswap). Nothing was left on the LRUs to reclaim.
On further inspection, I observed ~20k threads of that process stuck with the following stack:
[<0>] mem_cgroup_out_of_memory+0x4e/0xa0 [<0>] charge_memcg+0x8bf/0x990 [<0>] mem_cgroup_swapin_charge_folio+0x4e/0x80 [<0>] __read_swap_cache_async+0x10c/0x260 [<0>] swapin_readahead+0x116/0x3f0 [<0>] do_swap_page+0x13c/0x1ce0 [<0>] handle_mm_fault+0x61d/0x11f0 [<0>] do_user_addr_fault+0x3e7/0x6d0 [<0>] exc_page_fault+0x8f/0x110 [<0>] asm_exc_page_fault+0x22/0x30 [<0>] __get_user_8+0x14/0x20 [<0>] futex_cleanup+0x27/0x1c0 [<0>] futex_exit_release+0x47/0x60 [<0>] do_exit+0x107/0x940 [<0>] do_group_exit+0x81/0xa0 [<0>] get_signal+0x2b1/0x6e0 [<0>] arch_do_signal_or_restart+0x1a/0x1c0 [<0>] exit_to_user_mode_loop+0xa8/0x1c0 [<0>] do_syscall_64+0x152/0x250 [<0>] entry_SYSCALL_64_after_hwframe+0x4b/0x53
In addition the dmesg was filled with "Out of memory and no killable processes..." messages.
I have no idea why oom reaper was not able to reap/unmap the process. My guess is that since oom reaper tries to acquire mmap_lock in read mode limited number of times and then gives up, there might be a thread of that process which had mmap_lock in write mode at that time.
My initial suspicion was the futex_cleanup and kernel page fault causing infinite fault and charge retries but that was put to rest in previous discussions happened on similar problem [1].
My current theory is that it is just a simple slow serialization behind the oom_lock. Unlike page allocator, memcg charge code takes the oom_lock without the "try". Though memcg oom code uses mutex_lock_killable(), note that in the call stack get_signal() consumes SIGKILL (or sigdelset(SIGKILL)) before calling do_group_exit(). So this mutex_lock_killable() is just a mutex_lock() here. Therefore 10s of thousands of threads are waiting on oom_lock and one by one they get -EFAULT from get_user() in the futex cleanup code and bails out.
Discussion from [1] led to commit a75ffa26122b ("memcg, oom: do not bypass oom killer for dying tasks") which routes dying tasks into the OOM path precisely so the oom_reaper can reap their mm and free the memory asynchronously. But the reaper is best-effort and one-shot: if it cannot take mmap_lock for read (e.g. a sibling thread holds it for write) it sets MMF_OOM_SKIP and never retries, leaving only the glacial oom_lock-serialized synchronous drain.
Once MMF_OOM_SKIP is set there is no more asynchronous reclaim coming for the mm, so a dying task charging against it has nothing left to wait for:
it frees its memory only once it finishes exiting. Running reclaim and the (no-victim) OOM killer for it is then pointless, and doing it for 10s of thousands of exiting threads is what serializes them behind oom_lock.
--- mm/memcontrol.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
mm/memcontrol.c +13 -0
@@ -2716,6 +2716,19 @@ static int try_charge_memcg(struct mem_cgroup *memcg, gfp_t gfp_mask,if (!gfpflags_allow_blocking (gfp_mask)) goto nomem; +/* +* OOM victim still needs to charge memory to exit. OOM reaper should +* help but it might fail on mmap_lock contention. If the victim is a +* large thread group then all exiting threads might compete on oom_lock +* just to learn that there is nothing really killable anymore. Bail +* out early and fail the charge to expedite their exit. They are +* considered fully reclaimed by the oom reaper and they shouldn't +* contribute further charges. +*/ +if (tsk_is_oom_victim (current) && +test_bit (MMF_OOM_SKIP , ¤t->signal->oom_mm->flags)) + goto nomem; +memcg_memory_event (mem_over_limit,MEMCG_MAX ); raised_max_event = true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 430/3318 mm/gup: fix always draining LRU caches in collect_longterm_unpinnable_folios()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Hildenbrand (Arm) <[email protected]>
[ Upstream commit 078e1a0fc41a42baaf113383b52dab8874c0b967 ]
folio_may_be_lru_cached() is currently only true for small folios, and for small folios FOLL_PIN adds GUP_PIN_COUNTING_BIAS references instead of 1 in try_grab_folio()/try_grab_folio_fast().
Consequently, our
folio_ref_count(folio) != folio_expected_ref_count(folio) + 1
check in collect_longterm_unpinnable_folios() will currently always identify "reference mismatch" and first drain the local LRU cache to then drain the LRU cache on all CPUs, as collect_longterm_unpinnable_folios() is really called after pinning the folios with FOLL_PIN.
Add a comment because the current code is not quite intuitive: we used to drain only to make sure the folio_isolate_lru() would succeed. But then we also started draining to make later migration more reliable.
We'll refactor that code soon a bit, to also make it usable in other context where we really want to remove any references from LRU caches.
Let's add CC stable, because having an easy way for excessive LRU cache draining on all CPUs does not sound right. In common scenarios we don't expect to ever have to drain.
--- mm/gup.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
mm/gup.c +8 -2
@@ -1957,6 +1957,7 @@ static unsigned long collect_longterm_unpinnable_pages(for (i =0 ; i < nr_pages; i++) {struct folio *folio =page_folio (pages[i]); +const int pin_refs =folio_test_large (folio) ?1 :GUP_PIN_COUNTING_BIAS ;if (folio == prev_folio)continue ;
@@ -1975,15 +1976,20 @@ static unsigned long collect_longterm_unpinnable_pages(continue ; } +/* +* We drain not only to make the folio_isolate_lru() succeed, +* but also to remove any other folio references from LRU +* caches. +*/ if (drained ==0 &&folio_may_be_lru_cached (folio) &&folio_ref_count (folio) != -folio_expected_ref_count (folio) +1 ) { +folio_expected_ref_count (folio) + pin_refs) {lru_add_drain (); drained =1 ; }if (drained ==1 &&folio_may_be_lru_cached (folio) &&folio_ref_count (folio) != -folio_expected_ref_count (folio) +1 ) { +folio_expected_ref_count (folio) + pin_refs) {lru_add_drain_all (); drained =2 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 431/3318 zsmalloc: account for handle size in class lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longlong Xia <[email protected]>
[ Upstream commit f7bf5cd5b5f2b13fe2361860880c4e214c08b440 ]
zs_lookup_class_index() lets zram recompression decide whether a newly compressed object would use a smaller size class. It currently classifies the payload size directly, while zs_malloc() adds ZS_HANDLE_SIZE before selecting the class.
This makes lookup disagree with allocation near size-class boundaries. With 4 KiB pages, CONFIG_ZSMALLOC_CHAIN_SIZE=8, and 64-bit handles, a 1025-to-1024-byte recompression appears to move from class 64 to class 62 although both allocations use class 64. Conversely, a 1049-to-1025-byte recompression appears to stay in class 64 although the allocations move from class 65 to class 64.
As a result, zram can accept replacements with no allocation benefit or reject ones that would save memory, potentially marking the object incompressible.
Factor size-class selection into lookup_size_class(), account for the handle there, and use the helper for both lookup and allocation.
--- mm/zsmalloc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
mm/zsmalloc.c +7 -4
@@ -516,6 +516,11 @@ static int get_size_class_index(int size)return min_t (int,ZS_SIZE_CLASSES -1 , idx); } +static struct size_class *lookup_size_class (struct zs_pool *pool,size_t size) +{ +return pool->size_class[get_size_class_index (size +ZS_HANDLE_SIZE )]; +} +static inline void class_stat_inc (struct size_class *class,int type,unsigned long cnt) {
@@ -1163,7 +1168,7 @@ unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size) {struct size_class *class; - class = pool->size_class[get_size_class_index (size)]; + class =lookup_size_class (pool, size);return class->index; }
@@ -1372,9 +1377,7 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp)if (!handle)return (unsigned long )ERR_PTR (-ENOMEM ); -/* extra space in chunk to keep the handle */ - size +=ZS_HANDLE_SIZE ; - class = pool->size_class[get_size_class_index (size)]; + class =lookup_size_class (pool, size);/* pool->lock effectively protects the zpage migration */ spin_lock (&pool->lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 432/3318 mm, swap: ratelimit bad swap entry reports
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit f9dc428249ed962a70acf301f01eae8578449161 ]
A corrupt page table hands the same bogus entry to get_swap_device() on every access to the mapping, and every rejection is logged. One machine logged 6185620 copies of the same line in a few hours.
swap_dup_entry_direct() prints the same message from the fork path, once per call: the WARN_ON_ONCE() guarding it warns once, the pr_err() inside does not.
Rate limit all three prints.
--- mm/swapfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/swapfile.c +2 -2
@@ -1284,11 +1284,11 @@ struct swap_info_struct *get_swap_device(swp_entry_t entry)return si; bad_nofile: -pr_err ("%s: %s%08lx\n" , __func__, Bad_file, entry.val); +pr_err_ratelimited ("%s: %s%08lx\n" , __func__, Bad_file, entry.val); out:return NULL ; put_out: -pr_err ("%s: %s%08lx\n" , __func__, Bad_offset, entry.val); +pr_err_ratelimited ("%s: %s%08lx\n" , __func__, Bad_offset, entry.val);percpu_ref_put (&si->users);return NULL ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 433/3318 i2c: qcom-cci: Do not check return value of cci_init()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 17c5d247e3e4708cac05ff087c8013c0dda383a2 ]
The cci_init() function is not supposed to fail, and it never returns a non-zero, so it'd make sense to convert its signature to void.
Stable-dep-of: f98d49864821 ("i2c: qcom-cci: fix autosuspend cleanup")
--- drivers/i2c/busses/i2c-qcom-cci.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +2 -6
@@ -247,7 +247,7 @@ static int cci_reset(struct cci *cci)return 0 ; } -static int cci_init (struct cci *cci) +static void cci_init (struct cci *cci) {u32 val =CCI_IRQ_MASK_0_I2C_M0_RD_DONE | CCI_IRQ_MASK_0_I2C_M0_Q0_REPORT |
@@ -288,8 +288,6 @@ static int cci_init(struct cci *cci) val = hw->scl_stretch_en <<8 | hw->trdhld <<4 | hw->tsp;writel (val, cci->base +CCI_I2C_Mm_MISC_CTL (i)); } - -return 0 ; }static int cci_run_queue (struct cci *cci,u8 master,u8 queue)
@@ -634,9 +632,7 @@ static int cci_probe(struct platform_device *pdev)if (ret <0 ) goto error; - ret =cci_init (cci); -if (ret <0 ) - goto error; +cci_init (cci);pm_runtime_set_autosuspend_delay (dev,MSEC_PER_SEC );pm_runtime_use_autosuspend (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 434/3318 i2c: qcom-cci: Remove overcautious disable_irq() calls
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit f0285c286bca5a1e018ba25040cef6c7806c31ef ]
In cci_probe() the controller's interrupt is requested using a devres managed API, and in cci_probe() error path and cci_remove() it'd be safe to rely on devres mechanism to free and shutdown the interrupt, thus explicit disable_irq() calls can be removed as unnecessary ones.
Stable-dep-of: f98d49864821 ("i2c: qcom-cci: fix autosuspend cleanup")
--- drivers/i2c/busses/i2c-qcom-cci.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +1 -4
@@ -630,7 +630,7 @@ static int cci_probe(struct platform_device *pdev) ret =cci_reset (cci);if (ret <0 ) - goto error; + goto disable_clocks;cci_init (cci);
@@ -662,8 +662,6 @@ static int cci_probe(struct platform_device *pdev)of_node_put (cci->master[i].adap.dev.of_node); } } -error: -disable_irq (cci->irq); disable_clocks:cci_disable_clocks (cci);
@@ -683,7 +681,6 @@ static void cci_remove(struct platform_device *pdev) } } -disable_irq (cci->irq);pm_runtime_disable (&pdev->dev);pm_runtime_set_suspended (&pdev->dev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 435/3318 i2c: qcom-cci: fix autosuspend cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit f98d4986482151a835b521a734722fe8dc5ca37d ]
cci_probe() calls pm_runtime_use_autosuspend(), but the remove path does not call the matching pm_runtime_dont_use_autosuspend() before disabling runtime PM.
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without undoing the autosuspend setting during teardown, this reference is not dropped and usage_count remains unbalanced.
Use devm_pm_runtime_set_active_enabled() to manage the runtime PM state. Its managed cleanup disables autosuspend and runtime PM and restores the suspended state on probe failure and driver removal. Remove the now redundant manual runtime PM cleanup.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-qcom-cci.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +4 -7
@@ -635,9 +635,11 @@ static int cci_probe(struct platform_device *pdev)cci_init (cci);pm_runtime_set_autosuspend_delay (dev,MSEC_PER_SEC ); + ret =devm_pm_runtime_set_active_enabled (dev); +if (ret) + goto disable_clocks; +pm_runtime_use_autosuspend (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev);for (i =0 ; i < cci->data->num_masters; i++) {if (!cci->master[i].cci)
@@ -653,8 +655,6 @@ static int cci_probe(struct platform_device *pdev)return 0 ; error_i2c: -pm_runtime_disable (dev); -pm_runtime_dont_use_autosuspend (dev);for (--i ; i >=0 ; i--) {if (cci->master[i].cci) {
@@ -680,9 +680,6 @@ static void cci_remove(struct platform_device *pdev)cci_halt (cci, i); } } - -pm_runtime_disable (&pdev->dev); -pm_runtime_set_suspended (&pdev->dev); }static const struct cci_data cci_v1_data = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 436/3318 iio: admv1013: initialize callback mutex before registering notifier
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit baf7e43b7fb5afb777353bf265ddf9d909f72b9f ]
admv1013_probe() registers a clock notifier whose callback takes st->lock on POST_RATE_CHANGE. Initialize the mutex before devm_clk_notifier_register() so the callback cannot observe an uninitialized lock during probe.
Use devm_mutex_init() so the lock lifetime is tied to the device and cleanup stays paired with the rest of the managed probe resources.
--- drivers/iio/frequency/admv1013.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iio/frequency/admv1013.c +5 -2
@@ -604,11 +604,14 @@ static int admv1013_probe(struct spi_device *spi) "failed to get the LO input clock\n"); st->nb.notifier_call = admv1013_freq_change; - ret =devm_clk_notifier_register (dev, st->clkin, &st->nb); + + ret =devm_mutex_init (dev, &st->lock);if (ret)return ret; -mutex_init (&st->lock); + ret =devm_clk_notifier_register (dev, st->clkin, &st->nb); +if (ret) +return ret; ret =admv1013_init (st, vcm_uv);if (ret) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 437/3318 smb: client: reject SetEA requests that do not fit the request buffer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunpeng Tian <[email protected]>
[ Upstream commit 4aa2c106aef4bf3dfd97c30842db0767b26e8428 ]
CIFSSMBSetEA() copies the caller's extended attribute value into the SMB request buffer without checking that it fits. The requirement is stated in the source but was never implemented:
/*BB add length check to see if it would fit in negotiated SMB buffer size BB */ /* if (ea_value_len > buffer_size - 512 (enough for header)) */ if (ea_value_len) memcpy(parm_data->list.name + name_len + 1, ea_value, ea_value_len);
The only bound applied on the way in is in cifs_xattr_set():
#define MAX_EA_VALUE_SIZE CIFSMaxBufSize ... if (size > MAX_EA_VALUE_SIZE)
CIFSMaxBufSize is the full payload capacity of the buffer, so a value of exactly that size leaves no room for the SMB header, the TRANS2 parameter block, the fealist header and the EA name that are written ahead of it in the same object.
SendReceive() already enforces the correct limit on this very length:
if (in_len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE)
but it is called after the copy has taken place. An unprivileged setxattr(2) on an SMB1 mount with a 250-byte name and a 16384-byte value writes 16384 bytes starting 345 bytes into a 16588-byte cifs_request object, ending 141 bytes past it:
BUG: KASAN: slab-out-of-bounds in CIFSSMBSetEA+0xabc/0xde0 Write of size 16384 at addr ffff888003aa0159 by task init/68 __asan_memcpy+0x3c/0x60 CIFSSMBSetEA+0xabc/0xde0 cifs_xattr_set+0xd3a/0xff0 __vfs_setxattr+0x13e/0x1a0 The buggy address is located 345 bytes inside of allocated 16588-byte region
Apply SendReceive()'s limit to the assembled request before the copy rather than after it, and widen the byte counters so the sum cannot wrap before it is tested.
byte_count is also tested against U16_MAX, because it is stored in the 16-bit pSMB->ByteCount. That becomes reachable when CIFSMaxBufSize is raised at module load, where it may be set as high as 1024*127: with a 5-byte EA name and a 65521-byte value, count is exactly U16_MAX while byte_count is 65556, and cpu_to_le16() would truncate it to 20 and transmit a frame whose ByteCount does not match its length. Testing byte_count covers count as well, since byte_count is the larger of the two and count's only 16-bit consumer is written after this point.
check_add_overflow() is evaluated first so that total_len is assigned before it is reported.
--- fs/smb/client/cifssmb.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
fs/smb/client/cifssmb.c +11 -1
@@ -5896,8 +5896,10 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon,int name_len;int rc =0 ;int bytes_returned =0 ; -__u16 params, param_offset, byte_count, offset, count; +__u16 params, param_offset; +unsigned int byte_count, offset, count;int remap =cifs_remap (cifs_sb); +unsigned int in_len, total_len;cifs_dbg (FYI ,"In SetEA\n" ); SetEARetry:
@@ -5948,6 +5950,14 @@ CIFSSMBSetEA(const unsigned int xid, struct cifs_tcon *tcon, pSMB->Reserved3 =0 ; pSMB->SubCommand =cpu_to_le16 (TRANS2_SET_PATH_INFORMATION ); byte_count =3 /* pad */ + params + count; + in_len =be32_to_cpu (pSMB->hdr.smb_buf_length) +4 ; +if (check_add_overflow (in_len, byte_count, &total_len) || + byte_count >U16_MAX || + total_len > CIFSMaxBufSize +MAX_CIFS_HDR_SIZE ) { +cifs_dbg (VFS ,"EA request too large: %u bytes\n" , total_len); +cifs_buf_release (pSMB); +return -E2BIG ; + } pSMB->DataCount =cpu_to_le16 (count); parm_data->list_len =cpu_to_le32 (count); parm_data->list.EA_flags =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 438/3318 vsock/vmci: validate packet source for connected sockets
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daehyeon Ko <[email protected]>
[ Upstream commit ad9a7da3fa39c2d616ec0dd3cf6e30531d032fe7 ]
vmci_transport_recv_stream_cb() looks up sockets first by the full source and destination tuple, then by destination only in the bound table. The fallback can select a non-listening socket without checking whether the packet came from its stored peer.
This was reproduced with two VMCI contexts. A RST from the context not stored in a TCP_SYN_SENT socket reset that socket after it was selected by the destination-only lookup.
VMCI can process notification packets in bottom-half context when the socket is not owned by user context, or defer packets to a workqueue. Use vsock_check_source() after taking the socket lock in the bottom-half path, and recheck after lock_sock() in the workqueue path. Listening sockets continue to accept packets from any source.
Reply with a RST addressed from the received packet before dropping a source that fails validation. This preserves the existing reset behavior for bound non-listening and concurrently closed sockets without directing the reset to a connected socket's stored peer.
--- net/vmw_vsock/vmci_transport.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-)
net/vmw_vsock/vmci_transport.c +28 -6
@@ -676,11 +676,13 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)struct vmci_transport_packet *pkt;struct vsock_sock *vsk;bool bh_process_pkt; +bool drop_pkt;int err; sk =NULL ; err =VMCI_SUCCESS ; bh_process_pkt = false; + drop_pkt = false;/* Ignore incoming packets from contexts without sockets, or resources * that aren't vsock implementations.
@@ -757,17 +759,29 @@ static int vmci_transport_recv_stream_cb(void *data, struct vmci_datagram *dg)bh_lock_sock (sk);if (!sock_owned_by_user (sk)) { -/* The local context ID may be out of date, update it. */ - vsk->local_addr.svm_cid = dst.svm_cid; +if (sk->sk_state !=TCP_LISTEN && + !vsock_check_source (vsk, &vmci_transport, &src)) { + drop_pkt = true; + err =VMCI_ERROR_NO_ACCESS ; + }else { +/* The local context ID may be out of date, update it. */ + vsk->local_addr.svm_cid = dst.svm_cid; -if (sk->sk_state ==TCP_ESTABLISHED ) -vmci_trans (vsk)->notify_ops->handle_notify_pkt ( - sk, pkt, true, &dst, &src, - &bh_process_pkt); +if (sk->sk_state ==TCP_ESTABLISHED ) +vmci_trans (vsk)->notify_ops->handle_notify_pkt (sk, pkt, true, + &dst, &src, + &bh_process_pkt); + } }bh_unlock_sock (sk); +if (drop_pkt) { +if (vmci_transport_send_reset_bh (&dst, &src, pkt) <0 ) +pr_err ("unable to send reset\n" ); + goto out; + } +if (!bh_process_pkt) {struct vmci_transport_recv_pkt_info *recv_pkt_info;
@@ -892,6 +906,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) {struct vmci_transport_recv_pkt_info *recv_pkt_info;struct vmci_transport_packet *pkt; +struct sockaddr_vm src;struct sock *sk; recv_pkt_info =
@@ -900,6 +915,12 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work) pkt = &recv_pkt_info->pkt;lock_sock (sk); +vsock_addr_init (&src, pkt->dg.src.context, pkt->src_port); +if (sk->sk_state !=TCP_LISTEN && + !vsock_check_source (vsock_sk (sk), &vmci_transport, &src)) { +vmci_transport_reply_reset (pkt); + goto out; + }/* The local context ID may be out of date. */ vsock_sk (sk)->local_addr.svm_cid = pkt->dg.dst.context;
@@ -929,6 +950,7 @@ static void vmci_transport_recv_pkt_work(struct work_struct *work)break ; } +out:release_sock (sk);kfree (recv_pkt_info);/* Release reference obtained in the stream callback when we fetched
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 439/3318 ipv6: Fix redirect exception creation for UDP/RAW sockets
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit cd51b74bdd0b75aedf255dc67306a16dd057f7ee ]
When an ICMP Redirect Message is matched to a socket, both IPv4 and IPv6 verify that the source IP of the ICMP packet is the current gateway for the quoted packet. Both also pass the socket's bound device as the expected nexthop device.
The difference is that IPv4 treats "oif=0" as "any", whereas IPv6 always requires an exact match (see ip6_redirect_nh_match()), since the gateway address is usually a link-local address.
Therefore, when an IPv6 UDP/RAW socket is not bound to a device, the above verification fails and an exception is not created. This also happens when the socket is bound to a VRF, as l3mdev_update_flow() resets the oif to 0.
Fix this by passing the ifindex of the ingress device as the expected nexthop device. This is consistent with the existing callers of ip6_redirect(). Note that for ICMPv6 Redirect Message packets the VRF driver does not reset skb->dev to the VRF device, so skb->dev is correct, even when it is a VRF port.
--- net/ipv6/route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/route.c +1 -1
@@ -3231,7 +3231,7 @@ void ip6_redirect_no_header(struct sk_buff *skb, struct net *net, int oif)void ip6_sk_redirect (struct sk_buff *skb,struct sock *sk) { -ip6_redirect (skb,sock_net (sk), sk->sk_bound_dev_if, +ip6_redirect (skb,sock_net (sk), skb->dev->ifindex,READ_ONCE (sk->sk_mark), sk->sk_uid); }EXPORT_SYMBOL_GPL (ip6_sk_redirect);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 440/3318 ipv6: udp: Create exceptions before socket matching
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ido Schimmel <[email protected]>
[ Upstream commit ac76cab50e899a7346408b8d3c3a4192c2eefb9f ]
Currently, when ICMPv6 Packet Too Big and Redirect Message packets are locally delivered and quote a UDP packet, an exception is only created in the IPv6 exception cache if the kernel can match the UDP packet to an existing socket.
This behavior allows off-path attackers to conduct a side-channel attack on the exception cache in order to discover the ephemeral port used by a connected UDP socket.
Commit 4785305c05b2 ("ipv6: use siphash in rt6_exception_hash()") and commit a00df2caffed ("ipv6: make exception cache less predictible") tried to mitigate such attacks by making it harder for attackers to discover hash collisions in the exception cache and by randomizing the number of exceptions a hash bucket can hold, respectively. Unfortunately, both of the mitigations can be bypassed.
Instead, mitigate such attacks by always creating an exception, even before trying to find a matching socket. Do that by calling ip6_update_pmtu() and ip6_redirect(), the helpers used when the quoted packet did not originate from a socket.
This means that guesses (right or wrong) from an off-path attacker will always result in an exception being created or updated in the cache that the attacker can observe.
Pass the ifindex of the ingress device and the default uid, in a similar fashion to icmpv6_err(). Unlike IPv4, an oif of 0 would not match any nexthop in ip6_redirect_nh_match() and no exception would be created in response to a Redirect Message.
Note that this does not allow attackers to create exceptions that they could not create before, as both helpers can already be reached with little to no validation. For example, by sending an ICMPv6 error that quotes an ICMPv6 Echo Reply or one that quotes a UDP source port that matches a wildcard socket.
Also note that in the good case (matched socket) the above scheme comes at the cost of an extra route lookup, as the no socket helpers perform their own lookup before the one performed by ip6_sk_update_pmtu() / ip6_sk_redirect(). When the two resolve to different nexthops, it also results in two exceptions being created for the same destination IP. One in the exception cache of the nexthop resolved by the no socket helpers and another in the exception cache of the nexthop used by the socket.
--- net/ipv6/udp.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
net/ipv6/udp.c +13 -0
@@ -617,6 +617,17 @@ static struct sock *__udp6_lib_err_encap(struct net *net,return sk; } +static void udpv6_err_update_exception (struct net *net,struct sk_buff *skb, +u8 type,__be32 info) +{ +if (type ==ICMPV6_PKT_TOOBIG ) +ip6_update_pmtu (skb, net, info, skb->dev->ifindex,0 , +sock_net_uid (net,NULL )); +else if (type ==NDISC_REDIRECT ) +ip6_redirect (skb, net, skb->dev->ifindex,0 , +sock_net_uid (net,NULL )); +} +int __udp6_lib_err (struct sk_buff *skb,struct inet6_skb_parm *opt,u8 type,u8 code,int offset,__be32 info,struct udp_table *udptable)
@@ -632,6 +643,8 @@ int __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,int err;struct net *net =dev_net (skb->dev); +udpv6_err_update_exception (net, skb, type, info); + sk =__udp6_lib_lookup (net, daddr, uh->dest, saddr, uh->source,inet6_iif (skb),inet6_sdif (skb), udptable,NULL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 441/3318 xfrm: save input state data before secpath resets
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
[ Upstream commit 3cf5cdecd99c9c186a5ea518d93bbf3045b6e3aa ]
xfrm_input() stores the current xfrm_state in the skb secpath while it continues receive-side processing. Some input paths can reset that secpath before xfrm_input() has finished dereferencing the state.
Receive callback users such as VTI and XFRM interfaces can reset the secpath. The VTI receive path does so before checking whether the packet crosses network namespaces, while the XFRM interface path does so only for cross-network-namespace packets. The XFRM_MAX_DEPTH error path can also reset the secpath before the final drop callback reports the current state's protocol.
If secpath_reset() drops the last state reference while the state is concurrently deleted, xfrm_input() can still dereference the freed state when selecting transport_finish() or reporting the drop callback protocol.
Save the state protocol on the stack while the state is still valid, and use the already saved address family for transport_finish(). A larval XFRM_STATE_ACQ state has no type, so retain nexthdr as its protocol. This preserves the existing drop-path fallback while avoiding the post-reset state dereferences without adding an extra state reference to every received packet.
--- net/xfrm/xfrm_input.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
net/xfrm/xfrm_input.c +7 -3
@@ -462,6 +462,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)struct xfrm_state *x =NULL ;xfrm_address_t *daddr;u32 mark = skb->mark; +u8 xfrm_proto = nexthdr;unsigned int family =AF_UNSPEC ;int decaps =0 ;int async =0 ;
@@ -472,6 +473,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type)if (encap_type <0 || (xo && (xo->flags &XFRM_GRO || encap_type ==0 ))) { x =xfrm_input_state (skb); + xfrm_proto = x->type ? x->type->proto : nexthdr;if (unlikely (x->km.state !=XFRM_STATE_VALID )) {if (x->km.state ==XFRM_STATE_ACQ )
@@ -572,11 +574,13 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) x =xfrm_state_lookup (net, mark, daddr, spi, nexthdr, family);if (x ==NULL ) { + xfrm_proto = nexthdr;secpath_reset (skb);XFRM_INC_STATS (net,LINUX_MIB_XFRMINNOSTATES );xfrm_audit_state_notfound (skb, family, spi, seq); goto drop; } + xfrm_proto = x->type ? x->type->proto : nexthdr; skb->mark =xfrm_smark_get (skb->mark, x);
@@ -696,7 +700,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) crypto_done = false; }while (!err); - err =xfrm_rcv_cb (skb, family, x->type->proto,0 ); + err =xfrm_rcv_cb (skb, family, xfrm_proto,0 );if (err) goto drop;
@@ -719,7 +723,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) err = -EAFNOSUPPORT ;rcu_read_lock (); - afinfo =xfrm_state_afinfo_get_rcu (x->props.family); + afinfo =xfrm_state_afinfo_get_rcu (family);if (likely (afinfo)) err = afinfo->transport_finish (skb, xfrm_gro || async);rcu_read_unlock ();
@@ -743,7 +747,7 @@ int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi, int encap_type) drop:if (async)dev_put (skb->dev); -xfrm_rcv_cb (skb, family, x && x->type ? x->type->proto : nexthdr,-1 ); +xfrm_rcv_cb (skb, family, xfrm_proto,-1 );kfree_skb (skb);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 442/3318 usb: cdnsp: fix wakeup from S3 after controller context loss
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pawel Laszczak <[email protected]>
[ Upstream commit eae6460f617382044c5afe5ef202f4d8b2c099b5 ]
CDNSP controller may lose its runtime register programming across S3 suspend/resume, depending on SoC power domain configuration. After resume the operational and interrupter registers may contain reset values, which prevents the gadget side from recovering correctly and breaks wakeup from S3.
Fix this by detecting whether the controller lost its register context after resume and handling both cases:
- If context was lost (CFG_3XPORT_U1_PIPE_CLK_GATE_EN set or power lost): reset the controller and reprogram the state required for normal operation, including the command ring, DCBAA pointer, doorbell base, event ring, ERST base/size and event ring dequeue pointer.
- If context was retained: restart the controller directly without reprogramming registers. Issue a wakeup if the link was in U3 before suspend.
Move the basic controller register programming out of the one-time memory initialization path and make it reusable from the resume path. Also separate ring allocation from ring initialization so that rings can be reinitialized without reallocating DMA memory.
Always perform the full suspend sequence regardless of the current link state. Previously, if the device was already in U3, the suspend callback returned early without stopping the controller, which could lead to commands being issued on a disabled slot during resume.
--- drivers/usb/cdns3/cdnsp-gadget.c | 110 +++++++++++++++++++++++++++++-- drivers/usb/cdns3/cdnsp-gadget.h | 1 + drivers/usb/cdns3/cdnsp-mem.c | 98 ++++++++++----------------- 3 files changed, 142 insertions(+), 67 deletions(-)
drivers/usb/cdns3/cdnsp-gadget.c +106 -4
@@ -1819,6 +1819,82 @@ static void cdnsp_get_rev_cap(struct cdnsp_device *pdev) readl(&pdev->rev_cap->tx_buff_size)); } +static void cdnsp_set_event_deq (struct cdnsp_device *pdev) +{ +dma_addr_t deq; +u64 temp; + + deq =cdnsp_trb_virt_to_dma (pdev->event_ring->deq_seg, + pdev->event_ring->dequeue); + +/* Update controller event ring dequeue pointer */ + temp =cdnsp_read_64 (&pdev->ir_set->erst_dequeue); + temp &=ERST_PTR_MASK ; + +/* +* Don't clear the EHB bit (which is RW1C) because +* there might be more events to service. +*/ + temp &= ~ERST_EHB ; + +cdnsp_write_64 (((u64 )deq & (u64 )~ERST_PTR_MASK ) | temp, + &pdev->ir_set->erst_dequeue); +} + +static void cdnsp_add_interrupter (struct cdnsp_device *pdev) +{ +u64 erst_base; +u32 erst_size; + +/* Set ERST count with the number of entries in the segment table. */ + erst_size =readl (&pdev->ir_set->erst_size); + erst_size &=ERST_SIZE_MASK ; + erst_size |=ERST_NUM_SEGS ; +writel (erst_size, &pdev->ir_set->erst_size); + +/* Set the segment table base address. */ + erst_base =cdnsp_read_64 (&pdev->ir_set->erst_base); + erst_base &=ERST_PTR_MASK ; + erst_base |= (pdev->erst.erst_dma_addr & (u64 )~ERST_PTR_MASK ); +cdnsp_write_64 (erst_base, &pdev->ir_set->erst_base); + +/* Set the event ring dequeue address. */ +cdnsp_set_event_deq (pdev); +} + +/* Set up basic CDNSP registers */ +static void cdnsp_init (struct cdnsp_device *pdev) +{ +unsigned int val; +u64 val_64; + + val =readl (&pdev->op_regs->config_reg); + val |= ((val & ~MAX_DEVS ) |CDNSP_DEV_MAX_SLOTS ) |CONFIG_U3E ; +writel (val, &pdev->op_regs->config_reg); + +/* Initialize the Command ring */ +cdnsp_ring_init (pdev, pdev->cmd_ring); + +/* Set the address in the Command Ring Control register */ + val_64 =cdnsp_read_64 (&pdev->op_regs->cmd_ring); + val_64 = (val_64 & (u64 )CMD_RING_RSVD_BITS ) | + (pdev->cmd_ring->first_seg->dma & (u64 )~CMD_RING_RSVD_BITS ) | + pdev->cmd_ring->cycle_state; +cdnsp_write_64 (val_64, &pdev->op_regs->cmd_ring); + +/* Set Device Context Base Address Array pointer */ +cdnsp_write_64 (pdev->dcbaa->dma, &pdev->op_regs->dcbaa_ptr); + +/* Set Doorbell array pointer */ + val =readl (&pdev->cap_regs->db_off); + val &=DBOFF_MASK ; + pdev->dba = (void __iomem *)pdev->cap_regs + val; + +/* Initialize the Primary interrupter */ +cdnsp_ring_init (pdev, pdev->event_ring); +cdnsp_add_interrupter (pdev); +} +static int cdnsp_gen_setup (struct cdnsp_device *pdev) {int ret;
@@ -1884,6 +1960,8 @@ static int cdnsp_gen_setup(struct cdnsp_device *pdev)if (ret)return ret; +cdnsp_init (pdev); +/* * Software workaround for U1: after transition * to U1 the controller starts gating clock, and in some cases,
@@ -2014,9 +2092,6 @@ static int cdnsp_gadget_suspend(struct cdns *cdns, bool do_wakeup)struct cdnsp_device *pdev = cdns->gadget_dev;unsigned long flags; -if (pdev->link_state ==XDEV_U3 ) -return 0 ; -spin_lock_irqsave (&pdev->lock, flags);cdnsp_disconnect_gadget (pdev);cdnsp_stop (pdev);
@@ -2030,12 +2105,38 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated)struct cdnsp_device *pdev = cdns->gadget_dev;enum usb_device_speed max_speed;unsigned long flags; +bool context_lost; +u32 val;int ret;if (!pdev->gadget_driver)return 0 ;spin_lock_irqsave (&pdev->lock, flags); + val =readl (&pdev->port3x_regs->mode_2); + context_lost = !!(val &CFG_3XPORT_U1_PIPE_CLK_GATE_EN ) || hibernated; + +if (context_lost) { +cdnsp_halt (pdev); +cdnsp_set_apb_timeout_value (pdev); + +/* Reset the internal controller memory state and registers. */ + ret =cdnsp_reset (pdev); +if (ret) + goto unlock; + + val =readl (&pdev->port3x_regs->mode_2); + val &= ~CFG_3XPORT_U1_PIPE_CLK_GATE_EN ; +writel (val, &pdev->port3x_regs->mode_2); + +cdnsp_clear_cmd_ring (pdev); + +memset (pdev->event_ring->first_seg->trbs,0 , +sizeof (union cdnsp_trb ) * (TRBS_PER_SEGMENT )); + +cdnsp_init (pdev); + } + max_speed = pdev->gadget_driver->max_speed;/* Limit speed if necessary. */
@@ -2043,9 +2144,10 @@ static int cdnsp_gadget_resume(struct cdns *cdns, bool hibernated) ret =cdnsp_run (pdev, max_speed); -if (pdev->link_state ==XDEV_U3 ) +if (!context_lost && pdev->link_state ==XDEV_U3 )__cdnsp_gadget_wakeup (pdev); +unlock:spin_unlock_irqrestore (&pdev->lock, flags);return ret;
drivers/usb/cdns3/cdnsp-gadget.h +1 -0
@@ -1509,6 +1509,7 @@ int cdnsp_endpoint_init(struct cdnsp_device *pdev,int cdnsp_ring_expansion (struct cdnsp_device *pdev,struct cdnsp_ring *ring,unsigned int num_trbs,gfp_t flags); +void cdnsp_ring_init (struct cdnsp_device *pdev,struct cdnsp_ring *ring);struct cdnsp_ring *cdnsp_dma_to_transfer_ring (struct cdnsp_ep *ep,u64 address); int cdnsp_alloc_stream_info(struct cdnsp_device *pdev, struct cdnsp_ep *pep,
drivers/usb/cdns3/cdnsp-mem.c +35 -63
166 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 443/3318 ALSA: rawmidi: Use guard() for locking
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 84bb065b316e8367e14a8824a8f4d21056b10c53 ]
We can simplify the code gracefully with new guard() macro and co for automatic cleanup of locks.
There are a few remaining explicit mutex and spinlock calls, and those are the places where the temporary unlock/relocking happens -- which guard() doens't cover well yet.
Only the code refactoring, and no functional changes.
Stable-dep-of: f4a23e17d84f ("ALSA: rawmidi: Return the error from snd_rawmidi_input_params()")
--- sound/core/rawmidi.c | 253 ++++++++++++++++--------------------------- 1 file changed, 93 insertions(+), 160 deletions(-)
sound/core/rawmidi.c +93 -160
@@ -105,13 +105,8 @@ static inline bool __snd_rawmidi_ready(struct snd_rawmidi_runtime *runtime)static bool snd_rawmidi_ready (struct snd_rawmidi_substream *substream) { -unsigned long flags; -bool ready; - -spin_lock_irqsave (&substream->lock, flags); - ready =__snd_rawmidi_ready (substream->runtime); -spin_unlock_irqrestore (&substream->lock, flags); -return ready; +guard (spinlock_irqsave)(&substream->lock); +return __snd_rawmidi_ready (substream->runtime); } static inline int snd_rawmidi_ready_append(struct snd_rawmidi_substream *substream,
@@ -238,12 +233,9 @@ static void __reset_runtime_ptrs(struct snd_rawmidi_runtime *runtime,static void reset_runtime_ptrs (struct snd_rawmidi_substream *substream,bool is_input) { -unsigned long flags; - -spin_lock_irqsave (&substream->lock, flags); +guard (spinlock_irqsave)(&substream->lock);if (substream->opened && substream->runtime)__reset_runtime_ptrs (substream->runtime, is_input); -spin_unlock_irqrestore (&substream->lock, flags); }int snd_rawmidi_drop_output (struct snd_rawmidi_substream *substream)
@@ -260,33 +252,29 @@ int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)long timeout;struct snd_rawmidi_runtime *runtime; -spin_lock_irq (&substream->lock); - runtime = substream->runtime; -if (!substream->opened || !runtime || !runtime->buffer) { - err = -EINVAL ; - }else { + scoped_guard(spinlock_irq, &substream->lock) { + runtime = substream->runtime; +if (!substream->opened || !runtime || !runtime->buffer) +return -EINVAL ;snd_rawmidi_buffer_ref (runtime); runtime->drain =1 ; } -spin_unlock_irq (&substream->lock); -if (err <0 ) -return err; timeout =wait_event_interruptible_timeout (runtime->sleep, (runtime->avail >= runtime->buffer_size),10 *HZ ); -spin_lock_irq (&substream->lock); -if (signal_pending (current)) - err = -ERESTARTSYS ; -if (runtime->avail < runtime->buffer_size && !timeout) { -rmidi_warn (substream->rmidi, -"rawmidi drain error (avail = %li, buffer_size = %li)\n" , - (long )runtime->avail, (long )runtime->buffer_size); - err = -EIO ; + scoped_guard(spinlock_irq, &substream->lock) { +if (signal_pending (current)) + err = -ERESTARTSYS ; +if (runtime->avail < runtime->buffer_size && !timeout) { +rmidi_warn (substream->rmidi, +"rawmidi drain error (avail = %li, buffer_size = %li)\n" , + (long )runtime->avail, (long )runtime->buffer_size); + err = -EIO ; + } + runtime->drain =0 ; } - runtime->drain =0 ; -spin_unlock_irq (&substream->lock);if (err != -ERESTARTSYS ) {/* we need wait a while to make sure that Tx FIFOs are empty */
@@ -297,9 +285,8 @@ int snd_rawmidi_drain_output(struct snd_rawmidi_substream *substream)snd_rawmidi_drop_output (substream); } -spin_lock_irq (&substream->lock); -snd_rawmidi_buffer_unref (runtime); -spin_unlock_irq (&substream->lock); + scoped_guard(spinlock_irq, &substream->lock) +snd_rawmidi_buffer_unref (runtime);return err; }
@@ -363,14 +350,13 @@ static int open_substream(struct snd_rawmidi *rmidi,snd_rawmidi_runtime_free (substream);return err; } -spin_lock_irq (&substream->lock); +guard (spinlock_irq)(&substream->lock); substream->opened =1 ; substream->active_sensing =0 ;if (mode &SNDRV_RAWMIDI_LFLG_APPEND ) substream->append =1 ; substream->pid =get_pid (task_pid (current)); rmidi->streams[substream->stream].substream_opened++; -spin_unlock_irq (&substream->lock); } substream->use_count++;return 0 ;
@@ -433,9 +419,8 @@ int snd_rawmidi_kernel_open(struct snd_rawmidi *rmidi, int subdevice,if (!try_module_get (rmidi->card->module))return -ENXIO ; -mutex_lock (&rmidi->open_mutex); +guard (mutex)(&rmidi->open_mutex); err =rawmidi_open_priv (rmidi, subdevice, mode, rfile); -mutex_unlock (&rmidi->open_mutex);if (err <0 )module_put (rmidi->card->module);return err;
@@ -568,10 +553,10 @@ static void close_substream(struct snd_rawmidi *rmidi, }snd_rawmidi_buffer_ref_sync (substream); } -spin_lock_irq (&substream->lock); - substream->opened =0 ; - substream->append =0 ; -spin_unlock_irq (&substream->lock); + scoped_guard(spinlock_irq, &substream->lock) { + substream->opened =0 ; + substream->append =0 ; + } substream->ops->close (substream);if (substream->runtime->private_free) substream->runtime->private_free (substream);
@@ -586,7 +571,7 @@ static void rawmidi_release_priv(struct snd_rawmidi_file *rfile)struct snd_rawmidi *rmidi; rmidi = rfile->rmidi; -mutex_lock (&rmidi->open_mutex); +guard (mutex)(&rmidi->open_mutex);if (rfile->input) {close_substream (rmidi, rfile->input,1 ); rfile->input =NULL ;
@@ -596,7 +581,6 @@ static void rawmidi_release_priv(struct snd_rawmidi_file *rfile) rfile->output =NULL ; } rfile->rmidi =NULL ; -mutex_unlock (&rmidi->open_mutex);wake_up (&rmidi->open_wait); }
@@ -698,12 +682,8 @@ static int __snd_rawmidi_info_select(struct snd_card *card,int snd_rawmidi_info_select (struct snd_card *card,struct snd_rawmidi_info *info) { -int ret; - -mutex_lock (®ister_mutex); - ret =__snd_rawmidi_info_select (card, info); -mutex_unlock (®ister_mutex); -return ret; +guard (mutex)(®ister_mutex); +return __snd_rawmidi_info_select (card, info); }EXPORT_SYMBOL (snd_rawmidi_info_select);
@@ -747,9 +727,8 @@ static int resize_runtime_buffer(struct snd_rawmidi_substream *substream, newbuf =kvzalloc (params->buffer_size,GFP_KERNEL );if (!newbuf)return -ENOMEM ; -spin_lock_irq (&substream->lock); +guard (spinlock_irq)(&substream->lock);if (runtime->buffer_ref) { -spin_unlock_irq (&substream->lock);kvfree (newbuf);return -EBUSY ; }
@@ -757,7 +736,6 @@ static int resize_runtime_buffer(struct snd_rawmidi_substream *substream, runtime->buffer = newbuf; runtime->buffer_size = params->buffer_size;__reset_runtime_ptrs (runtime, is_input); -spin_unlock_irq (&substream->lock);kvfree (oldbuf); } runtime->avail_min = params->avail_min;
@@ -770,15 +748,12 @@ int snd_rawmidi_output_params(struct snd_rawmidi_substream *substream,int err;snd_rawmidi_drain_output (substream); -mutex_lock (&substream->rmidi->open_mutex); +guard (mutex)(&substream->rmidi->open_mutex);if (substream->append && substream->use_count >1 ) - err = -EBUSY ; -else - err =resize_runtime_buffer (substream, params, false); - +return -EBUSY ; + err =resize_runtime_buffer (substream, params, false);if (!err) substream->active_sensing = !params->no_active_sensing; -mutex_unlock (&substream->rmidi->open_mutex);return err; }EXPORT_SYMBOL (snd_rawmidi_output_params);
@@ -791,7 +766,7 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream,int err;snd_rawmidi_drain_input (substream); -mutex_lock (&substream->rmidi->open_mutex); +guard (mutex)(&substream->rmidi->open_mutex);if (framing ==SNDRV_RAWMIDI_MODE_FRAMING_NONE && clock_type !=SNDRV_RAWMIDI_MODE_CLOCK_NONE ) err = -EINVAL ;else if (clock_type >SNDRV_RAWMIDI_MODE_CLOCK_MONOTONIC_RAW )
@@ -805,7 +780,6 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, substream->framing = framing; substream->clock_type = clock_type; } -mutex_unlock (&substream->rmidi->open_mutex);return 0 ; }EXPORT_SYMBOL (snd_rawmidi_input_params);
@@ -817,9 +791,8 @@ static int snd_rawmidi_output_status(struct snd_rawmidi_substream *substream,memset (status,0 ,sizeof (*status)); status->stream =SNDRV_RAWMIDI_STREAM_OUTPUT ; -spin_lock_irq (&substream->lock); +guard (spinlock_irq)(&substream->lock); status->avail = runtime->avail; -spin_unlock_irq (&substream->lock);return 0 ; }
@@ -830,11 +803,10 @@ static int snd_rawmidi_input_status(struct snd_rawmidi_substream *substream,memset (status,0 ,sizeof (*status)); status->stream =SNDRV_RAWMIDI_STREAM_INPUT ; -spin_lock_irq (&substream->lock); +guard (spinlock_irq)(&substream->lock); status->avail = runtime->avail; status->xruns = runtime->xruns; runtime->xruns =0 ; -spin_unlock_irq (&substream->lock);return 0 ; }
@@ -1028,19 +1000,19 @@ static int snd_rawmidi_next_device(struct snd_card *card, int __user *argp,return -EFAULT ;if (device >=SNDRV_RAWMIDI_DEVICES )/* next device is -1 */ device =SNDRV_RAWMIDI_DEVICES -1 ; -mutex_lock (®ister_mutex); - device = device <0 ?0 : device +1 ; -for (; device <SNDRV_RAWMIDI_DEVICES ; device++) { - rmidi =snd_rawmidi_search (card, device); -if (!rmidi) -continue ; - is_ump =rawmidi_is_ump (rmidi); -if (find_ump == is_ump) -break ; + scoped_guard(mutex, ®ister_mutex) { + device = device <0 ?0 : device +1 ; +for (; device <SNDRV_RAWMIDI_DEVICES ; device++) { + rmidi =snd_rawmidi_search (card, device); +if (!rmidi) +continue ; + is_ump =rawmidi_is_ump (rmidi); +if (find_ump == is_ump) +break ; + } +if (device ==SNDRV_RAWMIDI_DEVICES ) + device =-1 ; } -if (device ==SNDRV_RAWMIDI_DEVICES ) - device =-1 ; -mutex_unlock (®ister_mutex);if (put_user (device, argp))return -EFAULT ;return 0 ;
@@ -1053,18 +1025,16 @@ static int snd_rawmidi_call_ump_ioctl(struct snd_card *card, int cmd, {struct snd_ump_endpoint_info __user *info = argp;struct snd_rawmidi *rmidi; -int device, ret; +int device;if (get_user (device, &info->device))return -EFAULT ; -mutex_lock (®ister_mutex); +guard (mutex)(®ister_mutex); rmidi =snd_rawmidi_search (card, device);if (rmidi && rmidi->ops && rmidi->ops->ioctl) - ret = rmidi->ops->ioctl (rmidi, cmd, argp); +return rmidi->ops->ioctl (rmidi, cmd, argp);else - ret = -ENXIO ; -mutex_unlock (®ister_mutex); -return ret; +return -ENXIO ; }#endif
@@ -1171,27 +1141,23 @@ static struct timespec64 get_framing_tstamp(struct snd_rawmidi_substream *substrint snd_rawmidi_receive (struct snd_rawmidi_substream *substream,const unsigned char *buffer,int count) { -unsigned long flags;struct timespec64 ts64 =get_framing_tstamp (substream);int result =0 , count1;struct snd_rawmidi_runtime *runtime; -spin_lock_irqsave (&substream->lock, flags); -if (!substream->opened) { - result = -EBADFD ; - goto unlock; - } +guard (spinlock_irqsave)(&substream->lock); +if (!substream->opened) +return -EBADFD ; runtime = substream->runtime;if (!runtime || !runtime->buffer) {rmidi_dbg (substream->rmidi,"snd_rawmidi_receive: input is not active!!!\n" ); - result = -EINVAL ; - goto unlock; +return -EINVAL ; } count =get_aligned_size (runtime, count);if (!count) - goto unlock; +return result;if (substream->framing ==SNDRV_RAWMIDI_MODE_FRAMING_TSTAMP ) { result =receive_with_tstamp_framing (substream, buffer, count, &ts64);
@@ -1214,7 +1180,7 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream, count1 = runtime->buffer_size - runtime->avail; count1 =get_aligned_size (runtime, count1);if (!count1) - goto unlock; +return result;memcpy (runtime->buffer + runtime->hw_ptr, buffer, count1); runtime->hw_ptr += count1; runtime->hw_ptr %= runtime->buffer_size;
@@ -1242,8 +1208,6 @@ int snd_rawmidi_receive(struct snd_rawmidi_substream *substream,else if (__snd_rawmidi_ready (runtime))wake_up (&runtime->sleep); } - unlock: -spin_unlock_irqrestore (&substream->lock, flags);return result; }EXPORT_SYMBOL (snd_rawmidi_receive);
@@ -1365,20 +1329,15 @@ static ssize_t snd_rawmidi_read(struct file *file, char __user *buf, size_t counint snd_rawmidi_transmit_empty (struct snd_rawmidi_substream *substream) {struct snd_rawmidi_runtime *runtime; -int result; -unsigned long flags; -spin_lock_irqsave (&substream->lock, flags); +guard (spinlock_irqsave)(&substream->lock); runtime = substream->runtime;if (!substream->opened || !runtime || !runtime->buffer) {rmidi_dbg (substream->rmidi,"snd_rawmidi_transmit_empty: output is not active!!!\n" ); - result =1 ; - }else { - result = runtime->avail >= runtime->buffer_size; +return 1 ; } -spin_unlock_irqrestore (&substream->lock, flags); -return result; +return (runtime->avail >= runtime->buffer_size); }EXPORT_SYMBOL (snd_rawmidi_transmit_empty);
@@ -1452,16 +1411,10 @@ static int __snd_rawmidi_transmit_peek(struct snd_rawmidi_substream *substream,int snd_rawmidi_transmit_peek (struct snd_rawmidi_substream *substream,unsigned char *buffer,int count) { -int result; -unsigned long flags; - -spin_lock_irqsave (&substream->lock, flags); +guard (spinlock_irqsave)(&substream->lock);if (!substream->opened || !substream->runtime) - result = -EBADFD ; -else - result =__snd_rawmidi_transmit_peek (substream, buffer, count); -spin_unlock_irqrestore (&substream->lock, flags); -return result; +return -EBADFD ; +return __snd_rawmidi_transmit_peek (substream, buffer, count); }EXPORT_SYMBOL (snd_rawmidi_transmit_peek);
@@ -1508,16 +1461,10 @@ static int __snd_rawmidi_transmit_ack(struct snd_rawmidi_substream *substream,*/ int snd_rawmidi_transmit_ack (struct snd_rawmidi_substream *substream,int count) { -int result; -unsigned long flags; - -spin_lock_irqsave (&substream->lock, flags); +guard (spinlock_irqsave)(&substream->lock);if (!substream->opened || !substream->runtime) - result = -EBADFD ; -else - result =__snd_rawmidi_transmit_ack (substream, count); -spin_unlock_irqrestore (&substream->lock, flags); -return result; +return -EBADFD ; +return __snd_rawmidi_transmit_ack (substream, count); }EXPORT_SYMBOL (snd_rawmidi_transmit_ack);
@@ -1534,21 +1481,13 @@ EXPORT_SYMBOL(snd_rawmidi_transmit_ack);int snd_rawmidi_transmit (struct snd_rawmidi_substream *substream,unsigned char *buffer,int count) { -int result; -unsigned long flags; - -spin_lock_irqsave (&substream->lock, flags); +guard (spinlock_irqsave)(&substream->lock);if (!substream->opened) - result = -EBADFD ; -else { - count =__snd_rawmidi_transmit_peek (substream, buffer, count); -if (count <=0 ) - result = count; -else - result =__snd_rawmidi_transmit_ack (substream, count); - } -spin_unlock_irqrestore (&substream->lock, flags); -return result; +return -EBADFD ; + count =__snd_rawmidi_transmit_peek (substream, buffer, count); +if (count <=0 ) +return count; +return __snd_rawmidi_transmit_ack (substream, count); }EXPORT_SYMBOL (snd_rawmidi_transmit);
@@ -1561,17 +1500,15 @@ EXPORT_SYMBOL(snd_rawmidi_transmit);int snd_rawmidi_proceed (struct snd_rawmidi_substream *substream) {struct snd_rawmidi_runtime *runtime; -unsigned long flags;int count =0 ; -spin_lock_irqsave (&substream->lock, flags); +guard (spinlock_irqsave)(&substream->lock); runtime = substream->runtime;if (substream->opened && runtime && runtime->avail < runtime->buffer_size) { count = runtime->buffer_size - runtime->avail;__snd_rawmidi_transmit_ack (substream, count); } -spin_unlock_irqrestore (&substream->lock, flags);return count; }EXPORT_SYMBOL (snd_rawmidi_proceed);
@@ -1775,7 +1712,7 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry, rawmidi_is_ump(rmidi) ? "UMP" : "Legacy");if (rmidi->ops && rmidi->ops->proc_read) rmidi->ops->proc_read (entry, buffer); -mutex_lock (&rmidi->open_mutex); +guard (mutex)(&rmidi->open_mutex);if (rmidi->info_flags &SNDRV_RAWMIDI_INFO_OUTPUT ) { list_for_each_entry(substream, &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams,
@@ -1790,10 +1727,10 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry," Owner PID : %d\n" , pid_vnr(substream->pid)); runtime = substream->runtime; -spin_lock_irq (&substream->lock); - buffer_size = runtime->buffer_size; - avail = runtime->avail; -spin_unlock_irq (&substream->lock); + scoped_guard(spinlock_irq, &substream->lock) { + buffer_size = runtime->buffer_size; + avail = runtime->avail; + }snd_iprintf (buffer," Mode : %s\n" " Buffer size : %lu\n"
@@ -1817,11 +1754,11 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry," Owner PID : %d\n" , pid_vnr(substream->pid)); runtime = substream->runtime; -spin_lock_irq (&substream->lock); - buffer_size = runtime->buffer_size; - avail = runtime->avail; - xruns = runtime->xruns; -spin_unlock_irq (&substream->lock); + scoped_guard(spinlock_irq, &substream->lock) { + buffer_size = runtime->buffer_size; + avail = runtime->avail; + xruns = runtime->xruns; + }snd_iprintf (buffer," Buffer size : %lu\n" " Avail : %lu\n"
@@ -1838,7 +1775,6 @@ static void snd_rawmidi_proc_info_read(struct snd_info_entry *entry, } } } -mutex_unlock (&rmidi->open_mutex); }/*
@@ -2028,12 +1964,12 @@ static int snd_rawmidi_dev_register(struct snd_device *device)if (rmidi->device >=SNDRV_RAWMIDI_DEVICES )return -ENOMEM ; err =0 ; -mutex_lock (®ister_mutex); -if (snd_rawmidi_search (rmidi->card, rmidi->device)) - err = -EBUSY ; -else -list_add_tail (&rmidi->list, &snd_rawmidi_devices); -mutex_unlock (®ister_mutex); + scoped_guard(mutex, ®ister_mutex) { +if (snd_rawmidi_search (rmidi->card, rmidi->device)) + err = -EBUSY ; +else +list_add_tail (&rmidi->list, &snd_rawmidi_devices); + }if (err <0 )return err;
@@ -2106,9 +2042,8 @@ static int snd_rawmidi_dev_register(struct snd_device *device) error_unregister:snd_unregister_device (rmidi->dev); error: -mutex_lock (®ister_mutex); -list_del (&rmidi->list); -mutex_unlock (®ister_mutex); + scoped_guard(mutex, ®ister_mutex) +list_del (&rmidi->list);return err; }
@@ -2117,8 +2052,8 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device)struct snd_rawmidi *rmidi = device->device_data;int dir; -mutex_lock (®ister_mutex); -mutex_lock (&rmidi->open_mutex); +guard (mutex)(®ister_mutex); +guard (mutex)(&rmidi->open_mutex);wake_up (&rmidi->open_wait);list_del_init (&rmidi->list);for (dir =0 ; dir <2 ; dir++) {
@@ -2144,8 +2079,6 @@ static int snd_rawmidi_dev_disconnect(struct snd_device *device) }#endif /* CONFIG_SND_OSSEMUL */ snd_unregister_device (rmidi->dev); -mutex_unlock (&rmidi->open_mutex); -mutex_unlock (®ister_mutex);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 444/3318 ALSA: rawmidi: Return the error from snd_rawmidi_input_params()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
[ Upstream commit f4a23e17d84fd2a152d9e12369761934e1af0ee8 ]
The snd_rawmidi_input_params() computes err for the three invalid mode combinations and for resize_runtime_buffer(), applies the new framing and clock type only when err is zero, and then returns 0 anyway. A caller that asked for parameters the kernel rejected is told the change succeeded, and the substream keeps its old buffer.
The open_mutex conversion turned the early returns into assignments. It handled the output sibling correctly, which still returns err, and left this one behind.
--- sound/core/rawmidi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/rawmidi.c +1 -1
@@ -780,7 +780,7 @@ int snd_rawmidi_input_params(struct snd_rawmidi_substream *substream, substream->framing = framing; substream->clock_type = clock_type; } -return 0 ; +return err; }EXPORT_SYMBOL (snd_rawmidi_input_params);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 445/3318 dm-integrity: fix NULL pointer dereference when the R flag is used
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit 7d4d4f3b668d708d94f62ecdd33ac330a6fd8a84 ]
If the dm-integrity device has the SB_FLAG_DIRTY_BITMAP flag set and the user activates the device in the 'R' mode, a crash in dm_integrity_resume happens because the function attempts to read the journal containing the bitmap.
This patch makes dm-integrity skip any writes to the device in dm_integrity_resume if the device is activated in the 'R' mode.
--- drivers/md/dm-integrity.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/md/dm-integrity.c +5 -0
@@ -3265,6 +3265,10 @@ static void dm_integrity_resume(struct dm_target *ti) r =sync_rw_sb (ic,REQ_OP_READ );if (r)dm_integrity_io_error (ic,"reading superblock" , r); + +if (ic->mode =='R' ) + goto skip_writes; +if ((ic->sb->flags & flags) != flags) { ic->sb->flags |= flags; r =sync_rw_sb (ic,REQ_OP_WRITE |REQ_FUA );
@@ -3374,6 +3378,7 @@ static void dm_integrity_resume(struct dm_target *ti) } } +skip_writes: ic->reboot_notifier.notifier_call = dm_integrity_reboot; ic->reboot_notifier.next =NULL ; ic->reboot_notifier.priority =INT_MAX -1 ;/* be notified after md and before hardware drivers */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 446/3318 s390/vfio-ap: handle hardware checkstop state on queue reset operation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason J. Herne <[email protected]>
[ Upstream commit a681226c675cf4ff4f1ece8f44a7f698c4a6ca6a ]
Update vfio_ap_mdev_reset_queue() to handle an unexpected checkstop (hardware error) the same as the deconfigured case. This prevents unexpected and unhelpful warnings in the event of a hardware error.
We also stop lying about a queue's reset response code. This was originally done so we could force vfio_ap_mdev_filter_matrix to pass a deconfigured device through to the guest for the hotplug scenario. vfio_ap_mdev_filter_matrix is instead modified to allow passthrough for all queues with reset state normal, deconfigured, or checkstopped. In the checkstopped case we choose to pass the device through and let the error state be reflected at the guest level.
Stable-dep-of: 65e05ec252a9 ("s390/vfio-ap: fix KVM GISC and page leak when queue removed from host config")
--- drivers/s390/crypto/vfio_ap_ops.c | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +18 -17
@@ -663,6 +663,21 @@ static bool vfio_ap_mdev_filter_cdoms(struct ap_matrix_mdev *matrix_mdev) AP_DOMAINS); } +static bool _queue_passable (struct vfio_ap_queue *q) +{ +if (!q) +return false; + +switch (q->reset_status.response_code) { +case AP_RESPONSE_NORMAL : +case AP_RESPONSE_DECONFIGURED : +case AP_RESPONSE_CHECKSTOPPED : +return true; +default : +return false; + } +} +/* * vfio_ap_mdev_filter_matrix - filter the APQNs assigned to the matrix mdev * to ensure no queue devices are passed through to
@@ -691,7 +706,6 @@ static bool vfio_ap_mdev_filter_matrix(struct ap_matrix_mdev *matrix_mdev,unsigned long apid, apqi, apqn;DECLARE_BITMAP (prev_shadow_apm,AP_DEVICES );DECLARE_BITMAP (prev_shadow_aqm,AP_DOMAINS ); -struct vfio_ap_queue *q;bitmap_copy (prev_shadow_apm, matrix_mdev->shadow_apcb.apm,AP_DEVICES );bitmap_copy (prev_shadow_aqm, matrix_mdev->shadow_apcb.aqm,AP_DOMAINS );
@@ -720,8 +734,7 @@ static bool vfio_ap_mdev_filter_matrix(struct ap_matrix_mdev *matrix_mdev,* hardware device. */ apqn =AP_MKQID (apid, apqi); - q =vfio_ap_mdev_get_queue (matrix_mdev, apqn); -if (!q || q->reset_status.response_code) { +if (!_queue_passable (vfio_ap_mdev_get_queue (matrix_mdev, apqn))) {clear_bit_inv (apid, matrix_mdev->shadow_apcb.apm);/*
@@ -1709,6 +1722,7 @@ static int apq_status_check(int apqn, struct ap_queue_status *status)switch (status->response_code) {case AP_RESPONSE_NORMAL :case AP_RESPONSE_DECONFIGURED : +case AP_RESPONSE_CHECKSTOPPED :return 0 ;case AP_RESPONSE_RESET_IN_PROGRESS :case AP_RESPONSE_BUSY :
@@ -1765,14 +1779,6 @@ static void apq_reset_check(struct work_struct *reset_work)memcpy (&q->reset_status, &status,sizeof (status));continue ; } -/* -* When an AP adapter is deconfigured, the -* associated queues are reset, so let's set the -* status response code to 0 so the queue may be -* passed through (i.e., not filtered) -*/ -if (status.response_code ==AP_RESPONSE_DECONFIGURED ) - q->reset_status.response_code =0 ;if (q->saved_isc !=VFIO_AP_ISC_INVALID )vfio_ap_free_aqic_resources (q);break ;
@@ -1799,12 +1805,7 @@ static void vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q)queue_work (system_long_wq, &q->reset_work);break ;case AP_RESPONSE_DECONFIGURED : -/* -* When an AP adapter is deconfigured, the associated -* queues are reset, so let's set the status response code to 0 -* so the queue may be passed through (i.e., not filtered). -*/ - q->reset_status.response_code =0 ; +case AP_RESPONSE_CHECKSTOPPED :vfio_ap_free_aqic_resources (q);break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 447/3318 s390/vfio-ap: fix KVM GISC and page leak when queue removed from host config
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
[ Upstream commit 65e05ec252a9b79e75930d3c4dd42d8877db04c5 ]
Three related problems exist in the handling of KVM interrupt and page resources when a queue is removed from the host's AP configuration while assigned to a mediated device (mdev).
Problem 1:
~~~~~~~~~AP_RESPONSE_Q_NOT_AVAIL not handled in vfio_ap_mdev_reset_queue()
When the AP bus removes a queue device whose adapter or domain has been removed from the host's AP configuration, vfio_ap_mdev_remove_queue() is called. If the queue is still in the host's AP configuration at that point, it calls vfio_ap_mdev_reset_queue(), which issues a PQAP(ZAPQ). Since the adapter is already gone from the host configuration, ap_zapq() returns AP_RESPONSE_Q_NOT_AVAIL (0x01). This response code is not handled in vfio_ap_mdev_reset_queue()'s switch statement and falls through to the default case, which issues a WARN but does not call vfio_ap_free_aqic_resources(). As a result, if IRQ handling was enabled for the queue by the guest, the KVM GISC registration and the pinned guest page holding the notification indicator byte (NIB) are both leaked.
This is fixed by adding AP_RESPONSE_Q_NOT_AVAIL to the same case as AP_RESPONSE_DECONFIGURED and AP_RESPONSE_CHECKSTOPPED in vfio_ap_mdev_reset_queue(). Like those response codes, Q_NOT_AVAIL indicates the queue is not operational and no further reset attempts are possible; the correct action is to free the IRQ resources immediately.
Problem 2:
~~~~~~~~~
AP_RESPONSE_Q_NOT_AVAIL not handled in apq_status_check()
In vfio_ap_mdev_reset_queue(), there are four cases that indicate a queue reset has not yet completed, in which case apq_reset_check() is queued to a work queue to verify completion of the reset operation. This function uses the PQAP(TAPQ) function to get the queue's status and calls apq_status_check() to verify whether the reset has completed, failed or needs to be executed again. As described in Problem #1 above, apq_reset_check() does not specifically check for AP_RESPONSE_Q_NOT_AVAIL, thereby potentially leaking KVM GISC registration and the pinned guest page holding the NIB.
This is fixed by adding a case statement for AP_RESPONSE_Q_NOT_AVAIL to apq_status_check() and returning -ENODEV for that case. The caller, apq_reset_check() will then check for this return code and call vfio_ap_free_aqic_resources() to prevent the leak.
Problem 3:
~~~~~~~~~vfio_ap_free_aqic_resources() leaks saved_isc when kvm is NULL
vfio_ap_free_aqic_resources() guards the call tokvm_s390_gisc_unregister() with:
if (q->saved_isc != VFIO_AP_ISC_INVALID &&
!WARN_ON(!(q->matrix_mdev && q->matrix_mdev->kvm)))If matrix_mdev->kvm is NULL -- which can happen when vfio_ap_mdev_unset_kvm() has already run and cleared kvm before a subsequent cleanup path reaches this function -- the WARN_ON fires and the entire block is skipped. This leaves q->saved_isc set to a non-invalid value, creating a potential double-free on any subsequent call to this function.
When kvm is NULL the KVM guest is already torn down, so kvm_s390_gisc_unregister() need not and cannot be called; however, q->saved_isc must always be cleared. Fix this by separating the kvm_s390_gisc_unregister() call from the q->saved_isc reset. The WARN_ON now guards only the genuinely impossible case of matrix_mdev being NULL. A NULL kvm is handled gracefully by skipping only the unregister call, and q->saved_isc = VFIO_AP_ISC_INVALID is set unconditionally whenever saved_isc was not already invalid.
Additionally, add an else clause to the host-config check in vfio_ap_mdev_remove_queue() to call vfio_ap_free_aqic_resources() directly when the queue is not in the host's AP configuration. This serves as a backstop: when the AP bus fires the driver .remove callback after an adapter is removed from the host config, the queue is by definition no longer addressable, so vfio_ap_mdev_reset_queue() would always return Q_NOT_AVAIL. The else clause handles this case directly without the unnecessary ap_zapq() call, and ensures cleanup occurs even if kvm has already been set to NULL by a prior call to vfio_ap_mdev_unset_kvm().
Message-ID: <[email protected]>
--- drivers/s390/crypto/vfio_ap_ops.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +14 -4
@@ -277,9 +277,9 @@ static void vfio_ap_free_aqic_resources(struct vfio_ap_queue *q) {if (!q)return ; -if (q->saved_isc !=VFIO_AP_ISC_INVALID && - !WARN_ON (!(q->matrix_mdev && q->matrix_mdev->kvm))) { -kvm_s390_gisc_unregister (q->matrix_mdev->kvm, q->saved_isc); +if (q->saved_isc !=VFIO_AP_ISC_INVALID ) { +if (!WARN_ON (!q->matrix_mdev) && q->matrix_mdev->kvm) +kvm_s390_gisc_unregister (q->matrix_mdev->kvm, q->saved_isc); q->saved_isc =VFIO_AP_ISC_INVALID ; }if (q->saved_iova && !WARN_ON (!q->matrix_mdev)) {
@@ -1737,6 +1737,8 @@ static int apq_status_check(int apqn, struct ap_queue_status *status)* a value indicating a reset needs to be performed again. */ return -EAGAIN ; +case AP_RESPONSE_Q_NOT_AVAIL : +return -ENODEV ;default : WARN(true, "failed to verify reset of queue %02x.%04x: TAPQ rc=%u\n",
@@ -1763,6 +1765,10 @@ static void apq_reset_check(struct work_struct *reset_work) ret =apq_status_check (q->apqn, &status);if (ret == -EIO )return ; +if (ret == -ENODEV ) { +vfio_ap_free_aqic_resources (q); +return ; + }if (ret == -EBUSY ) { pr_notice_ratelimited(WAIT_MSG, elapsed, AP_QID_CARD(q->apqn),
@@ -1806,6 +1812,7 @@ static void vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q)break ;case AP_RESPONSE_DECONFIGURED :case AP_RESPONSE_CHECKSTOPPED : +case AP_RESPONSE_Q_NOT_AVAIL :vfio_ap_free_aqic_resources (q);break ;default :
@@ -2285,12 +2292,15 @@ void vfio_ap_mdev_remove_queue(struct ap_device *apdev)/* * If the queue is not in the host's AP configuration, then resetting * it will fail with response code 01, (APQN not valid); so, let's make -* sure it is in the host's config. +* sure it is in the host's config. If it is not, free the KVM GISC +* resources. */ if (test_bit_inv (apid, (unsigned long *)matrix_dev->info.apm) &&test_bit_inv (apqi, (unsigned long *)matrix_dev->info.aqm)) {vfio_ap_mdev_reset_queue (q);flush_work (&q->reset_work); + }else { +vfio_ap_free_aqic_resources (q); } done:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 448/3318 drm/amdgpu: Skip accessing psp rum time db for APUs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kanala Ramalingeswara Reddy <[email protected]>
[ Upstream commit a26301203a196a991527f7b1ab884d4dd0e7c95e ]
Psp runtime DB is for dGPUs only.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +6 -0
@@ -335,6 +335,12 @@ static bool psp_get_runtime_db_entry(struct amdgpu_device *adev,bool ret = false;int i; +/* +* Runtime DB is for dGPUs only. +*/ +if (adev->flags &AMD_IS_APU ) +return false; +if (adev->ip_versions[MP0_HWIP ][0 ] ==IP_VERSION (13 ,0 ,6 ))return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 449/3318 tracing/probes: Fix BTF kflag check for anonymous struct member access
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 47e93045a2db80d24f5fef65adecc6b2b32efa23 ]
btf_find_struct_member() traverses into nested anonymous structures and unions to find a struct member. However, get_bitoffset_of_field() in trace_probe.c checked btf_type_kflag(type) using the outer parent type instead of the actual anonymous structure/union that directly contains the found member.
If the parent structure and anonymous structure have mismatched kflags (e.g., the parent has kflag=0 while the anonymous structure has kflag=1 because it contains bitfields), the bitfield size encoded in the upper 8 bits of member->offset is erroneously treated as part of the byte/bit offset, corrupting the resolved offset and failing to set last_bitsize. Similarly, btf_find_struct_member() pushed anonymous member offsets onto anon_stack without masking BTF_MEMBER_BIT_OFFSET() when kflag is set.
To fix this problem, update btf_find_struct_member() to return actual containing structure/union type via member_type, use appropriate __btf_member_bit_offset() to get bit offset, and use member_type for btf_type_kflag() in get_bitoffset_of_field().
--- kernel/trace/trace_btf.c | 19 +++++++++++-------- kernel/trace/trace_btf.h | 3 ++- kernel/trace/trace_probe.c | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-)
kernel/trace/trace_btf.c +11 -8
@@ -61,16 +61,17 @@ struct btf_anon_stack {/* * Find a member of data structure/union by name and return it. -* Return NULL if not found, or -EINVAL if parameter is invalid. -* If the member is an member of anonymous union/structure, the offset -* of that anonymous union/structure is stored into @anon_offset. Caller -* can calculate the correct offset from the root data structure by -* adding anon_offset to the member's offset. +* Return NULL if not found, or ERR_PTR(-EINVAL) if parameter is invalid. +* If the member is a member of an anonymous union/structure, the bit offset +* of that anonymous union/structure is stored into @anon_offset. +* If @member_type is non-NULL, the actual containing structure/union type +* of the found member is stored into @member_type. */ const struct btf_member *btf_find_struct_member (struct btf *btf,const struct btf_type *type,const char *member_name, -u32 *anon_offset) +u32 *anon_offset, +const struct btf_type **member_type) {struct btf_anon_stack *anon_stack;const struct btf_member *member;
@@ -94,14 +95,16 @@ const struct btf_member *btf_find_struct_member(struct btf *btf,if (mtype &&btf_type_is_struct (mtype) && top <BTF_ANON_STACK_MAX ) { anon_stack[top].tid = tid; - anon_stack[top++].offset = - cur_offset + member->offset; + anon_stack[top++].offset = cur_offset + +__btf_member_bit_offset (type, member); } }else { name =btf_name_by_offset (btf, member->name_off);if (name && !strcmp (member_name, name)) {if (anon_offset) *anon_offset = cur_offset; +if (member_type) + *member_type = type; goto out; } }
kernel/trace/trace_btf.h +2 -1
@@ -8,4 +8,5 @@ const struct btf_param *btf_get_func_param(const struct btf_type *func_proto,const struct btf_member *btf_find_struct_member (struct btf *btf,const struct btf_type *type,const char *member_name, -u32 *anon_offset); +u32 *anon_offset, +const struct btf_type **member_type);
kernel/trace/trace_probe.c +3 -2
@@ -533,6 +533,7 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type, {struct fetch_insn *code = *pcode;const struct btf_member *field; +const struct btf_type *mtype;u32 bitoffs, anon_offs;char *next;int is_ptr;
@@ -561,7 +562,7 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type, anon_offs =0 ; field =btf_find_struct_member (ctx->btf, type, fieldname, - &anon_offs); + &anon_offs, &mtype);if (IS_ERR (field)) {trace_probe_log_err (ctx->offset,BAD_BTF_TID );return PTR_ERR (field);
@@ -574,7 +575,7 @@ static int parse_btf_field(char *fieldname, const struct btf_type *type, bitoffs += anon_offs;/* Accumulate the bit-offsets of the dot-connected fields */ -if (btf_type_kflag (type)) { +if (btf_type_kflag (mtype)) { bitoffs +=BTF_MEMBER_BIT_OFFSET (field->offset); ctx->last_bitsize =BTF_MEMBER_BITFIELD_SIZE (field->offset); }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 450/3318 irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ju Nan <[email protected]>
[ Upstream commit d31fbbade43f880b7e59e2b3a72722fe2725d93f ]
HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:
atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
if (atomic_delay > to * 1000)
return -ETIMEDOUT;So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.
The hwspinlock core documents this explicitly:
If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.
--- drivers/irqchip/irq-stm32-exti.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/irqchip/irq-stm32-exti.c +3 -3
@@ -25,7 +25,7 @@#define IRQS_PER_BANK 32 -#define HWSPNLCK_TIMEOUT 1000/* usec */ +#define HWSPNLCK_TIMEOUT_MS 1struct stm32_exti_bank {u32 imr_ofst;
@@ -365,7 +365,7 @@ static int stm32_irq_set_type(struct irq_data *d, unsigned int type)irq_gc_lock (gc);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
@@ -569,7 +569,7 @@ static int stm32_exti_h_set_type(struct irq_data *d, unsigned int type)raw_spin_lock (&chip_data->rlock);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 451/3318 xfs: fix backwards mergeability logic in refcount scrubber
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit e8b01aaafffe6b852325debdf1ef4b13ccea1cd7 ]
When we start the refcount or rtrefcount btree scanners, prev_rec is initialized to all zeroes. This is done so that the record mergeability checks skip the first record because you must have two records to compare. Unfortunately, I got the logic backwards, so scrub has never complained about mergeable refcountbt records. Fix this bug that LOLLM noticed.
--- fs/xfs/scrub/refcount.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/scrub/refcount.c +1 -1
@@ -399,7 +399,7 @@ xchk_refcount_mergeable(const struct xfs_refcount_irec *r1 = &rrc->prev_rec;/* Ignore if prev_rec is not yet initialized. */ -if (r1->rc_blockcount >0 ) +if (r1->rc_blockcount ==0 )return false;if (r1->rc_domain != r2->rc_domain)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 452/3318 xfs: strengthen the "is cow staging" helpers in scrub
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Darrick J. Wong <[email protected]>
[ Upstream commit 0d43368844a75ad13561a1198a3b027940730756 ]
LOLLM pointed out a bug in both of the refcount scrub predicates that determine if a range of blocks is marked as CoW staging in the btree. While it compares blockcount < len, this isn't enough to determine that the CoW staging record is at least as large as the range passed into the helper. Fix both of them.
--- fs/xfs/scrub/refcount.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/xfs/scrub/refcount.c +5 -1
@@ -569,8 +569,12 @@ xchk_xref_is_cow_staging(if (rc.rc_domain !=XFS_REFC_DOMAIN_COW )xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Can't start after bno */ +if (rc.rc_startblock > agbno) +xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); +/* Must be at least as long as what was passed in */ -if (rc.rc_blockcount < len) +if (rc.rc_startblock + rc.rc_blockcount < agbno + len)xchk_btree_xref_set_corrupt (sc, sc->sa.refc_cur,0 ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 453/3318 EDAC/altera: Use ECC manager compatible to select A10/S10 IRQ layout
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Rounak Das <[email protected]>
[ Upstream commit d4486fc3098e176cb4a29fee037216484761f9ca ]
The SDMMC ECC IRQ layout selection uses CONFIG_64BIT to distinguish between Arria10 and Stratix10 paths.
Detect the SoC once at probe via the device match table (.data) store it in struct altr_arria10_edac, and use it instead of CONFIG_64BIT.
This keeps the decision correct for every ECC child device (OCRAM, SD/MMC, etc.) and avoids any runtime compatible lookup.
Stable-dep-of: 9868f5c077df ("EDAC/altera: Use parent device for devres in altr_portb_setup()")
--- drivers/edac/altera_edac.c | 107 +++++++++++++++++++------------------ drivers/edac/altera_edac.h | 1 + 2 files changed, 55 insertions(+), 53 deletions(-)
drivers/edac/altera_edac.c +54 -53
@@ -1517,6 +1517,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)int edac_idx, rc;struct device_node *np;const struct edac_device_prv_data *prv = &a10_sdmmceccb_data; +bool is_s10 = device->edac->is_s10; rc =altr_check_ecc_deps (device);if (rc)
@@ -1558,15 +1559,14 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)/* * Update the PortB IRQs - A10 has 4, S10 has 2, Index accordingly -* -* FIXME: Instead of ifdefs with different architectures the driver -* should properly use compatibles. */ -#ifdef CONFIG_64BIT - altdev->sb_irq =irq_of_parse_and_map (np,1 ); -#else - altdev->sb_irq =irq_of_parse_and_map (np,2 ); -#endif + +/* Using compatibles to determine the IRQ Index */ +if (is_s10) + altdev->sb_irq =irq_of_parse_and_map (np,1 ); +else + altdev->sb_irq =irq_of_parse_and_map (np,2 ); +if (!altdev->sb_irq) {edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB SBIRQ alloc\n" ); rc = -ENODEV ;
@@ -1580,29 +1580,28 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) goto err_release_group_1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Error PortB DBIRQ alloc\n" ); - goto err_release_group_1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,3 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); - rc = -ENODEV ; - goto err_release_group_1; - } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, - prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); - goto err_release_group_1; +if (is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,1 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + goto err_release_group_1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,3 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error PortB DBIRQ alloc\n" ); + rc = -ENODEV ; + goto err_release_group_1; + } + rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"PortB DBERR IRQ error\n" ); + goto err_release_group_1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -1985,29 +1984,29 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac, goto err_release_group1; } -#ifdef CONFIG_64BIT -/* Use IRQ to determine SError origin instead of assigning IRQ */ - rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE , -"Unable to parse DB IRQ index\n" ); - goto err_release_group1; - } -#else - altdev->db_irq =irq_of_parse_and_map (np,1 ); -if (!altdev->db_irq) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); - rc = -ENODEV ; - goto err_release_group1; - } - rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, -IRQF_TRIGGER_HIGH , - ecc_name, altdev); -if (rc) { -edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); - goto err_release_group1; +if (edac->is_s10) { +/* Use IRQ to determine SError origin instead of assigning IRQ */ + rc =of_property_read_u32_index (np,"interrupts" ,0 , &altdev->db_irq); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE , +"Unable to parse DB IRQ index\n" ); + goto err_release_group1; + } + }else { + altdev->db_irq =irq_of_parse_and_map (np,1 ); +if (!altdev->db_irq) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"Error allocating DBIRQ\n" ); + rc = -ENODEV ; + goto err_release_group1; + } + rc =devm_request_irq (edac->dev, altdev->db_irq, prv->ecc_irq_handler, +IRQF_TRIGGER_HIGH , + ecc_name, altdev); +if (rc) { +edac_printk (KERN_ERR ,EDAC_DEVICE ,"No DBERR IRQ resource\n" ); + goto err_release_group1; + } } -#endif rc =edac_device_add_device (dci);if (rc) {
@@ -2133,6 +2132,8 @@ static int altr_edac_a10_probe(struct platform_device *pdev)platform_set_drvdata (pdev, edac);INIT_LIST_HEAD (&edac->a10_ecc_devices); + edac->is_s10 = !!device_get_match_data (&pdev->dev); + edac->ecc_mgr_map =altr_sysmgr_regmap_lookup_by_phandle (pdev->dev.of_node,"altr,sysmgr-syscon" );
@@ -2218,7 +2219,7 @@ static int altr_edac_a10_probe(struct platform_device *pdev)static const struct of_device_id altr_edac_a10_of_match[] = { { .compatible ="altr,socfpga-a10-ecc-manager" }, - { .compatible ="altr,socfpga-s10-ecc-manager" }, + { .compatible ="altr,socfpga-s10-ecc-manager" , .data = (void *)1 }, {}, };MODULE_DEVICE_TABLE (of, altr_edac_a10_of_match);
drivers/edac/altera_edac.h +1 -0
@@ -395,6 +395,7 @@ struct altr_arria10_edac {struct irq_chip irq_chip;struct list_head a10_ecc_devices;struct notifier_block panic_notifier; + bool is_s10; };#endif /* #ifndef _ALTERA_EDAC_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 454/3318 EDAC/altera: Use parent device for devres in altr_portb_setup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dinh Nguyen <[email protected]>
[ Upstream commit 9868f5c077dfe0b606331f2e782484f91a5789a5 ]
Anchor the devres group and the devm-managed IRQ requests in altr_portb_setup() to the actual parent device (device->edac->dev) instead of the embedded struct device inside the copied per-port altr_edac_device_dev.
This keeps devres_open_group(), devm_request_irq(), devres_remove_group() and devres_release_group() all referring to the same long-lived device so the group and the resources allocated inside it are torn down together.
--- drivers/edac/altera_edac.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/edac/altera_edac.c +5 -5
@@ -1544,7 +1544,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) altdev = dci->pvt_info; *altdev = *device; -if (!devres_open_group (&altdev->ddev, altr_portb_setup,GFP_KERNEL )) +if (!devres_open_group (device->edac->dev, altr_portb_setup,GFP_KERNEL ))return -ENOMEM ;/* Update PortB specific values */
@@ -1572,7 +1572,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->sb_irq, + rc =devm_request_irq (device->edac->dev, altdev->sb_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1594,7 +1594,7 @@ static int altr_portb_setup(struct altr_edac_device_dev *device) rc = -ENODEV ; goto err_release_group_1; } - rc =devm_request_irq (&altdev->ddev, altdev->db_irq, + rc =devm_request_irq (device->edac->dev, altdev->db_irq, prv->ecc_irq_handler,IRQF_TRIGGER_HIGH , ecc_name, altdev);if (rc) {
@@ -1614,13 +1614,13 @@ static int altr_portb_setup(struct altr_edac_device_dev *device)list_add (&altdev->next, &altdev->edac->a10_ecc_devices); -devres_remove_group (&altdev->ddev, altr_portb_setup); +devres_remove_group (device->edac->dev, altr_portb_setup);return 0 ; err_release_group_1:edac_device_free_ctl_info (dci); -devres_release_group (&altdev->ddev, altr_portb_setup); +devres_release_group (device->edac->dev, altr_portb_setup);edac_printk (KERN_ERR ,EDAC_DEVICE ,"%s:Error setting up EDAC device: %d\n" , ecc_name, rc);return rc;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 455/3318 s390/crypto: Fix skcipher_walk return code handling in aes_s390
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit 15fa028589c3a2545f0bff355eff06d5844196bf ]
The return codes from skcipher_walk_virt() were not properly checked before entering the processing loops in ecb_aes_crypt() and ctr_aes_crypt(). If skcipher_walk_virt() fails, the walk structure may be in an undefined state, and attempting to process data could lead to incorrect behavior or accessing uninitialized memory.
Add proper return code checking to ensure correct handling of the walk initialization and walk advance and eventually return to the caller with that return code.
--- arch/s390/crypto/aes_s390.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/s390/crypto/aes_s390.c +5 -5
@@ -231,7 +231,7 @@ static int ecb_aes_crypt(struct skcipher_request *req, unsigned long modifier)return fallback_skcipher_crypt (sctx, req, modifier); ret =skcipher_walk_virt (&walk, req, false); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_km(sctx->fc | modifier, sctx->key,
@@ -335,7 +335,7 @@ static int cbc_aes_crypt(struct skcipher_request *req, unsigned long modifier)return ret;memcpy (param.iv, walk.iv,AES_BLOCK_SIZE );memcpy (param.key, sctx->key, sctx->key_len); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_kmc(sctx->fc | modifier, ¶m,
@@ -461,7 +461,7 @@ static int xts_aes_crypt(struct skcipher_request *req, unsigned long modifier)memcpy (xts_param.key + offset, xts_ctx->key, xts_ctx->key_len);memcpy (xts_param.init, pcc_param.xts,16 ); -while ((nbytes = walk.nbytes) !=0 ) { +while (!ret && ((nbytes = walk.nbytes) !=0 )) {/* only use complete blocks */ n = nbytes & ~(AES_BLOCK_SIZE -1 ); cpacf_km(xts_ctx->fc | modifier, xts_param.key + offset,
@@ -577,7 +577,7 @@ static int ctr_aes_crypt(struct skcipher_request *req) locked =mutex_trylock (&ctrblk_lock); ret =skcipher_walk_virt (&walk, req, false); -while ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE ) { +while (!ret && ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE )) { n =AES_BLOCK_SIZE ;if (nbytes >=2 *AES_BLOCK_SIZE && locked)
@@ -596,7 +596,7 @@ static int ctr_aes_crypt(struct skcipher_request *req)/* * final block may be < AES_BLOCK_SIZE, copy only nbytes */ -if (nbytes) { +if (!ret && nbytes) {memset (buf,0 ,AES_BLOCK_SIZE );memcpy (buf, walk.src.virt.addr, nbytes); cpacf_kmctr(sctx->fc, sctx->key, buf, buf,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 456/3318 s390/crypto: Fix use of mutex in atomic context
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harald Freudenberger <[email protected]>
[ Upstream commit d1c44a7d085473173bb360b7218a43699c3f56c7 ]
The AES CTR implementation used a mutex to lock one page of exclusive memory for fast CTR processing. Unfortunately a mutex is not save to use in atomic or interrupt context. So use a binary semaphore instead which is save to use in such environments.
Furthermore rework the code to get rid of conditional locking. So restructure the AES CRT code by extracting the main loop into a separate function and just give in information about the (locked) page can be used or not (is not locked).
--- arch/s390/crypto/aes_s390.c | 63 +++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 24 deletions(-)
arch/s390/crypto/aes_s390.c +39 -24
@@ -28,14 +28,14 @@#include <linux/module.h> #include <linux/cpufeature.h> #include <linux/init.h> -#include <linux/mutex.h> #include <linux/fips.h> +#include <linux/semaphore.h> #include <linux/string.h> #include <crypto/xts.h> #include <asm/cpacf.h> static u8 *ctrblk; -static DEFINE_MUTEX (ctrblk_lock); +static DEFINE_SEMAPHORE(ctrblk_sem, 1);static cpacf_mask_t km_functions, kmc_functions, kmctr_functions, kma_functions;
@@ -562,46 +562,61 @@ static unsigned int __ctrblk_init(u8 *ctrptr, u8 *iv, unsigned int nbytes)return n; } +static int __ctr_aes_crypt (struct s390_aes_ctx *sctx, +struct skcipher_walk *walk,bool locked) +{ +unsigned int n, nbytes; +int ret =0 ; +u8 *ctrptr; + +while (!ret && ((nbytes = walk->nbytes) >=AES_BLOCK_SIZE )) { + n =AES_BLOCK_SIZE ; +if (nbytes >=2 *AES_BLOCK_SIZE && locked) + n =__ctrblk_init (ctrblk, walk->iv, nbytes); + ctrptr = (n >AES_BLOCK_SIZE ) ? ctrblk : walk->iv; +cpacf_kmctr (sctx->fc, sctx->key, walk->dst.virt.addr, + walk->src.virt.addr, n, ctrptr); +if (ctrptr == ctrblk) +memcpy (walk->iv, ctrptr + n -AES_BLOCK_SIZE , +AES_BLOCK_SIZE ); +crypto_inc (walk->iv,AES_BLOCK_SIZE ); + ret =skcipher_walk_done (walk, nbytes - n); + } + +return ret; +} +static int ctr_aes_crypt (struct skcipher_request *req) {struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct s390_aes_ctx *sctx =crypto_skcipher_ctx (tfm); -u8 buf[AES_BLOCK_SIZE ], *ctrptr;struct skcipher_walk walk; -unsigned int n, nbytes; -int ret, locked; +u8 buf[AES_BLOCK_SIZE ]; +int ret;if (unlikely (!sctx->fc))return fallback_skcipher_crypt (sctx, req,0 ); - locked =mutex_trylock (&ctrblk_lock); - ret =skcipher_walk_virt (&walk, req, false); -while (!ret && ((nbytes = walk.nbytes) >=AES_BLOCK_SIZE )) { - n =AES_BLOCK_SIZE ; +if (ret) +return ret; -if (nbytes >=2 *AES_BLOCK_SIZE && locked) - n =__ctrblk_init (ctrblk, walk.iv, nbytes); - ctrptr = (n >AES_BLOCK_SIZE ) ? ctrblk : walk.iv; -cpacf_kmctr (sctx->fc, sctx->key, walk.dst.virt.addr, - walk.src.virt.addr, n, ctrptr); -if (ctrptr == ctrblk) -memcpy (walk.iv, ctrptr + n -AES_BLOCK_SIZE , -AES_BLOCK_SIZE ); -crypto_inc (walk.iv,AES_BLOCK_SIZE ); - ret =skcipher_walk_done (&walk, nbytes - n); +if (down_trylock (&ctrblk_sem) ==0 ) { + ret =__ctr_aes_crypt (sctx, &walk, true); +up (&ctrblk_sem); + }else { + ret =__ctr_aes_crypt (sctx, &walk, false); } -if (locked) -mutex_unlock (&ctrblk_lock); +/* * final block may be < AES_BLOCK_SIZE, copy only nbytes */ -if (!ret && nbytes) { +if (!ret && walk.nbytes >0 ) {memset (buf,0 ,AES_BLOCK_SIZE ); -memcpy (buf, walk.src.virt.addr, nbytes); +memcpy (buf, walk.src.virt.addr, walk.nbytes);cpacf_kmctr (sctx->fc, sctx->key, buf, buf,AES_BLOCK_SIZE , walk.iv); -memcpy (walk.dst.virt.addr, buf, nbytes); +memcpy (walk.dst.virt.addr, buf, walk.nbytes);crypto_inc (walk.iv,AES_BLOCK_SIZE ); ret =skcipher_walk_done (&walk,0 );memzero_explicit (buf,sizeof (buf));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 457/3318 smb: client: fix uid/gid override in getattr with posix extensions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit cf4d35896621b7298eef51b7a465e5c0cb22f670 ]
When mounting with 'multiuser,posix' options, cifs_getattr() overrides the server-provided uid/gid with the current process's fsuid/fsgid. This is because the condition only checks for unix extensions (tcon->unix_ext) but not posix extensions (tcon->posix_extensions).
With SMB3 POSIX extensions, the server provides real uid/gid values just like with unix extensions, so they should be preserved rather than replaced with the caller's credentials.
Add a tcon->posix_extensions check to the condition so that uid/gid from the server are properly reported in stat results.
--- fs/smb/client/inode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/smb/client/inode.c +4 -4
@@ -2838,13 +2838,13 @@ int cifs_getattr(struct mnt_idmap *idmap, const struct path *path, stat->attributes |=STATX_ATTR_ENCRYPTED ;/* -* If on a multiuser mount without unix extensions or cifsacl being -* enabled, and the admin hasn't overridden them, set the ownership -* to the fsuid/fsgid of the current process. +* If on a multiuser mount without unix extensions, posix extensions +* or cifsacl being enabled, and the admin hasn't overridden them, +* set the ownership to the fsuid/fsgid of the current process. */ if ((cifs_sb->mnt_cifs_flags &CIFS_MOUNT_MULTIUSER ) && !(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_CIFS_ACL ) && - !tcon->unix_ext) { + !tcon->unix_ext && !tcon->posix_extensions) {if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_OVERR_UID )) stat->uid =current_fsuid ();if (!(cifs_sb->mnt_cifs_flags &CIFS_MOUNT_OVERR_GID ))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 458/3318 smb: client: fix WSL reparse point uid/gid override
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit cd2b2b57921d4caa7875e83198bb2aa71254328b ]
wsl_to_fattr() unconditionally overwrites cf_uid/cf_gid with values from WSL extended attributes ($LXUID/$LXGID), ignoring the forceuid and forcegid mount options.
Fix this by initializing cf_uid/cf_gid to the mount defaults and gating the $LXUID/$LXGID EA parsing on forceuid/forcegid.
--- fs/smb/client/reparse.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
fs/smb/client/reparse.c +11 -5
@@ -679,11 +679,15 @@ static bool wsl_to_fattr(struct cifs_open_info_data *data,struct cifs_sb_info *cifs_sb, u32 tag, struct cifs_fattr *fattr) { + unsigned int sbflags = cifs_sb->mnt_cifs_flags;struct smb2_file_full_ea_info *ea;bool have_xattr_dev = false;u32 next =0 ; fattr->cf_mode &= ~S_IFMT ; + fattr->cf_uid = cifs_sb->ctx->linux_uid; + fattr->cf_gid = cifs_sb->ctx->linux_gid; +switch (tag) {case IO_REPARSE_TAG_LX_SYMLINK : fattr->cf_mode |=S_IFLNK ;
@@ -720,11 +724,13 @@ static bool wsl_to_fattr(struct cifs_open_info_data *data, nlen = ea->ea_name_length; v = (void *)((u8 *)ea->ea_data + ea->ea_name_length +1 ); -if (!strncmp (name,SMB2_WSL_XATTR_UID , nlen)) - fattr->cf_uid =wsl_make_kuid (cifs_sb, v); -else if (!strncmp (name,SMB2_WSL_XATTR_GID , nlen)) - fattr->cf_gid =wsl_make_kgid (cifs_sb, v); -else if (!strncmp (name,SMB2_WSL_XATTR_MODE , nlen)) { +if (!strncmp (name,SMB2_WSL_XATTR_UID , nlen)) { +if (!(sbflags &CIFS_MOUNT_OVERR_UID )) + fattr->cf_uid =wsl_make_kuid (cifs_sb, v); + }else if (!strncmp (name,SMB2_WSL_XATTR_GID , nlen)) { +if (!(sbflags &CIFS_MOUNT_OVERR_GID )) + fattr->cf_gid =wsl_make_kgid (cifs_sb, v); + }else if (!strncmp (name,SMB2_WSL_XATTR_MODE , nlen)) {/* File type in reparse point tag and in xattr mode must match. */ if (S_DT (fattr->cf_mode) !=S_DT (le32_to_cpu (*(__le32 *)v)))return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 459/3318 cifs: Remove duplicate struct reparse_symlink_data and SYMLINK_FLAG_RELATIVE
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pali Rohár <[email protected]>
[ Upstream commit 2948f0d4db40d839db2c1d141121c2e4e12a6faa ]
In file common/smb2pdu.h is defined struct reparse_symlink_data_buffer which is same as struct reparse_symlink_data and is used in the whole code. So remove duplicate struct reparse_symlink_data from client/cifspdu.h.
In file common/smb2pdu.h is defined also SYMLINK_FLAG_RELATIVE constant, so remove duplication from client/cifspdu.h.
Stable-dep-of: 65d5dbdc089b ("smb: client: fix file type corruption in posix_reparse_to_fattr()")
--- fs/smb/client/cifspdu.h | 16 ---------------- 1 file changed, 16 deletions(-)
fs/smb/client/cifspdu.h +0 -16
@@ -1483,22 +1483,6 @@ struct file_notify_information {__u8 FileName[]; } __attribute__((packed)); -/* For IO_REPARSE_TAG_SYMLINK */ -struct reparse_symlink_data { -__le32 ReparseTag; -__le16 ReparseDataLength; -__u16 Reserved; -__le16 SubstituteNameOffset; -__le16 SubstituteNameLength; -__le16 PrintNameOffset; -__le16 PrintNameLength; -__le32 Flags; -char PathBuffer[]; -} __attribute__((packed)); - -/* Flag above */ -#define SYMLINK_FLAG_RELATIVE 0x00000001 -/* For IO_REPARSE_TAG_NFS */ #define NFS_SPECFILE_LNK 0x00000000014B4E4C#define NFS_SPECFILE_CHR 0x0000000000524843
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 460/3318 cifs: Remove struct reparse_posix_data from struct cifs_open_info_data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pali Rohár <[email protected]>
[ Upstream commit 65ccccee4eb1a8147a3242238f7730bd8359077e ]
Linux SMB client already supports more reparse point types but only the reparse_posix_data is defined in union of struct cifs_open_info_data. This union is currently used as implicit casting between point types.
With this code style, it hides information that union is used for pointer casting, and just in mknod_nfs() and posix_reparse_to_fattr() functions.
Other reparse point buffers do not use this kind of casting. So remove reparse_posix_data from reparse part of struct cifs_open_info_data and for all cases of reparse buffer use just struct reparse_data_buffer *buf.
Stable-dep-of: 65d5dbdc089b ("smb: client: fix file type corruption in posix_reparse_to_fattr()")
--- fs/smb/client/cifsglob.h | 5 +---- fs/smb/client/reparse.c | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-)
fs/smb/client/cifsglob.h +1 -4
@@ -224,10 +224,7 @@ struct cifs_open_info_data {struct kvec iov; } io;__u32 tag; -union { -struct reparse_data_buffer *buf; -struct reparse_posix_data *posix; - }; +struct reparse_data_buffer *buf; } reparse;struct {__u8 eas[SMB2_WSL_MAX_QUERY_EA_RESP_SIZE ];
fs/smb/client/reparse.c +2 -3
@@ -294,7 +294,7 @@ static int mknod_nfs(unsigned int xid, struct inode *inode, data = (struct cifs_open_info_data ) { .reparse_point = true, - .reparse = { .tag =IO_REPARSE_TAG_NFS , .posix = p, }, + .reparse = { .tag =IO_REPARSE_TAG_NFS , .buf = (struct reparse_data_buffer *)p, }, }; new = smb2_get_reparse_inode(&data, inode->i_sb, xid,
@@ -753,8 +753,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr, struct cifs_open_info_data *data) { - struct reparse_posix_data *buf = data->reparse.posix; - + struct reparse_posix_data *buf = (struct reparse_posix_data *)data->reparse.buf;if (buf ==NULL )return true;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 461/3318 cifs: Rename struct reparse_posix_data to reparse_nfs_data_buffer and move to common/smb2pdu.h
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pali Rohár <[email protected]>
[ Upstream commit b6d002f0a345218edbe9de049693004482a81327 ]
Function parse_reparse_posix() parses NFS-style reparse points, which are used only by Windows NFS server since Windows Server 2012 version. This style is not understood by Microsoft POSIX/Interix/SFU/SUA subsystems.
So make it clear that parse_reparse_posix() function and reparse_posix_data structure are not POSIX general, but rather NFS specific.
All reparse buffer structures are defined in common/smb2pdu.h and have _buffer suffix. So move struct reparse_posix_data from client/cifspdu.h to common/smb2pdu.h and rename it to reparse_nfs_data_buffer for consistency. Note that also SMB specification in [MS-FSCC] document, section 2.1.2.6 defines it under name "Network File System (NFS) Reparse Data Buffer". So use this name for consistency.
Having this structure in common/smb2pdu.h can be useful for ksmbd server code as NFS-style reparse points is the preferred way for implementing support for special files.
Stable-dep-of: 65d5dbdc089b ("smb: client: fix file type corruption in posix_reparse_to_fattr()")
--- fs/smb/client/cifspdu.h | 14 -------------- fs/smb/client/reparse.c | 12 ++++++------ fs/smb/common/smb2pdu.h | 14 +++++++++++++- 3 files changed, 19 insertions(+), 21 deletions(-)
fs/smb/client/cifspdu.h +0 -14
@@ -1483,20 +1483,6 @@ struct file_notify_information {__u8 FileName[]; } __attribute__((packed)); -/* For IO_REPARSE_TAG_NFS */ -#define NFS_SPECFILE_LNK 0x00000000014B4E4C -#define NFS_SPECFILE_CHR 0x0000000000524843 -#define NFS_SPECFILE_BLK 0x00000000004B4C42 -#define NFS_SPECFILE_FIFO 0x000000004F464946 -#define NFS_SPECFILE_SOCK 0x000000004B434F53 -struct reparse_posix_data { -__le32 ReparseTag; -__le16 ReparseDataLength; -__u16 Reserved; -__le64 InodeType;/* LNK, FIFO, CHR etc. */ -__u8 DataBuffer[]; -} __attribute__((packed)); -struct cifs_quota_data {__u32 rsrvd1;/* 0 */ __u32 sid_size;
fs/smb/client/reparse.c +6 -6
@@ -242,7 +242,7 @@ static int detect_directory_symlink_target(struct cifs_sb_info *cifs_sb,return 0 ; } -static int nfs_set_reparse_buf (struct reparse_posix_data *buf, +static int nfs_set_reparse_buf (struct reparse_nfs_data_buffer *buf,mode_t mode,dev_t dev,struct kvec *iov) {
@@ -281,13 +281,13 @@ static int mknod_nfs(unsigned int xid, struct inode *inode, const char *full_path, umode_t mode, dev_t dev) { struct cifs_open_info_data data; -struct reparse_posix_data *p; +struct reparse_nfs_data_buffer *p;struct inode *new;struct kvec iov;__u8 buf[sizeof (*p) +sizeof (__le64)];int rc; - p = (struct reparse_posix_data *)buf; + p = (struct reparse_nfs_data_buffer *)buf; rc =nfs_set_reparse_buf (p, mode, dev, &iov);if (rc)return rc;
@@ -474,7 +474,7 @@ int smb2_mknod_reparse(unsigned int xid, struct inode *inode, }/* See MS-FSCC 2.1.2.6 for the 'NFS' style reparse tags */ -static int parse_reparse_posix (struct reparse_posix_data *buf, +static int parse_reparse_nfs (struct reparse_nfs_data_buffer *buf,struct cifs_sb_info *cifs_sb,struct cifs_open_info_data *data) {
@@ -639,7 +639,7 @@ int parse_reparse_point(struct reparse_data_buffer *buf,/* See MS-FSCC 2.1.2 */ switch (le32_to_cpu (buf->ReparseTag)) {case IO_REPARSE_TAG_NFS : -return parse_reparse_posix ((struct reparse_posix_data *)buf, +return parse_reparse_nfs ((struct reparse_nfs_data_buffer *)buf, cifs_sb, data);case IO_REPARSE_TAG_SYMLINK : return parse_reparse_symlink(
@@ -753,7 +753,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,struct cifs_fattr *fattr, struct cifs_open_info_data *data) { - struct reparse_posix_data *buf = (struct reparse_posix_data *)data->reparse.buf; + struct reparse_nfs_data_buffer *buf = (struct reparse_nfs_data_buffer *)data->reparse.buf;if (buf ==NULL )return true;
fs/smb/common/smb2pdu.h +13 -1
@@ -1551,7 +1551,19 @@ struct reparse_symlink_data_buffer {__u8 PathBuffer[];/* Variable Length */ } __packed; -/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */ +/* For IO_REPARSE_TAG_NFS - see MS-FSCC 2.1.2.6 */ +#define NFS_SPECFILE_LNK 0x00000000014B4E4C +#define NFS_SPECFILE_CHR 0x0000000000524843 +#define NFS_SPECFILE_BLK 0x00000000004B4C42 +#define NFS_SPECFILE_FIFO 0x000000004F464946 +#define NFS_SPECFILE_SOCK 0x000000004B434F53 +struct reparse_nfs_data_buffer { +__le32 ReparseTag; +__le16 ReparseDataLength; +__u16 Reserved; +__le64 InodeType;/* NFS_SPECFILE_* */ +__u8 DataBuffer[]; +} __packed;struct validate_negotiate_info_req {__le32 Capabilities;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 462/3318 smb: client: fix file type corruption in posix_reparse_to_fattr()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit 65d5dbdc089be42fc48a6f77bc6b648307f34b17 ]
Setting the file type in cf_mode without clearing the existing S_IFMT bits first is wrong as it corrupts the file type when cf_mode already has type bits set (e.g. S_IFREG | S_IFCHR == S_IFLNK).
Use a local ftype variable to collect the new file type and apply it after validation succeeds, clearing S_IFMT and setting the new type in a single assignment. This avoids stripping cf_mode on malformed reparse points where the function returns false early.
--- fs/smb/client/reparse.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/smb/client/reparse.c +7 -5
@@ -754,6 +754,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb, struct cifs_open_info_data *data) {struct reparse_nfs_data_buffer *buf = (struct reparse_nfs_data_buffer *)data->reparse.buf; +umode_t ftype;if (buf ==NULL )return true;
@@ -769,7 +770,7 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,WARN_ON_ONCE (1 );return false; } - fattr->cf_mode |=S_IFCHR ; + ftype =S_IFCHR ; fattr->cf_rdev =reparse_mkdev (buf->DataBuffer);break ;case NFS_SPECFILE_BLK :
@@ -777,22 +778,23 @@ static bool posix_reparse_to_fattr(struct cifs_sb_info *cifs_sb,WARN_ON_ONCE (1 );return false; } - fattr->cf_mode |=S_IFBLK ; + ftype =S_IFBLK ; fattr->cf_rdev =reparse_mkdev (buf->DataBuffer);break ;case NFS_SPECFILE_FIFO : - fattr->cf_mode |=S_IFIFO ; + ftype =S_IFIFO ;break ;case NFS_SPECFILE_SOCK : - fattr->cf_mode |=S_IFSOCK ; + ftype =S_IFSOCK ;break ;case NFS_SPECFILE_LNK : - fattr->cf_mode |=S_IFLNK ; + ftype =S_IFLNK ;break ;default :WARN_ON_ONCE (1 );return false; } + fattr->cf_mode = (fattr->cf_mode & ~S_IFMT ) | ftype;return true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 463/3318 swiotlb: use the adjusted address for the highmem page lookup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Donggeun Yoo <[email protected]>
[ Upstream commit b7d7914a9ae3097e63d113007e4fb44d33d515b1 ]
swiotlb_bounce() reads the page frame number from the slot's recorded orig_addr, then advances orig_addr by tlb_offset to reach the address the caller asked about. The highmem branch mixes the two: the offset within the page comes from the adjusted address, the page from the value before it.
Once the adjustment crosses a page boundary the pair no longer describes one location, and the whole copy lands one page below the intended one for a positive tlb_offset, one above for a negative one. DMA_FROM_DEVICE writes the device data over the wrong page and leaves the intended one stale, DMA_TO_DEVICE feeds the device from a page the mapping may not cover. Partial syncs through dma_sync_single_range_for_*() are what make tlb_offset non-zero.
The branch test is picked the same way, so a slot recorded in lowmem can be adjusted into highmem and the lowmem path then hands a highmem address to phys_to_virt().
Take both from orig_addr once it is final and keep pfn in the branch that uses it. PhysHighMem() asks the question straight from the address, as dma-debug already does.
--- kernel/dma/swiotlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/dma/swiotlb.c +2 -2
@@ -868,7 +868,6 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t sizeint index = (tlb_addr - mem->start) >>IO_TLB_SHIFT ;phys_addr_t orig_addr = mem->slots[index].orig_addr;size_t alloc_size = mem->slots[index].alloc_size; -unsigned long pfn =PFN_DOWN (orig_addr);unsigned char *vaddr = mem->vaddr + tlb_addr - mem->start;unsigned int tlb_offset, orig_addr_offset;
@@ -902,7 +901,8 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size size = alloc_size; } -if (PageHighMem (pfn_to_page (pfn))) { +if (PageHighMem (pfn_to_page (PFN_DOWN (orig_addr)))) { +unsigned long pfn =PFN_DOWN (orig_addr);unsigned int offset = orig_addr & ~PAGE_MASK ;struct page *page;unsigned int sz =0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 464/3318 fs/ntfs3: use d_instantiate_new() in ntfs_create_inode() and murder syzbots "WARNING in do_new_mount" saga
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Brauner <[email protected]>
[ Upstream commit 1abd643f3783ea8f8e273c18697ff0413aa92dc7 ]
ntfs_create_inode() creates a new inode via ntfs_new_inode(). It hashes it with insert_inode_locked() and so it's marked as I_NEW until unlock_new_inode().
ntfs 3 calls d_instantiate() in between though... Since the dentry was already hashed by the lookup before the create any path walk finds it without touching the parent's i_rwsem and so can lock the inode.
If the inode is a directory unlock_new_inode() calls lockdep_annotate_inode_mutex_key() and marks i_rwsem with the i_mutex_dir_key class.
That resets the count and the owner of a lock somebody else may already hold by now...
syzbot has been spamming us with the same godforsaken bug
"WARNING in do_new_mount"
since 2023. I can't take it anymore so I went looking. Afaict, syzbot's executor chdirs into a freshly mounted ntfs3 image, creates a directory and then mounts some pseudofs on it. Everytime the mkdir() takes longer than syzbot waits mount() runs concurrently:
mkdir("./sys") mount(NULL, "./sys", "sysfs")
ntfs_create_inode()
d_instantiate()
user_path_at() finds the dentry
do_lock_mount()
inode_lock(inode)
namespace_lock()
unlock_new_inode()
lockdep_annotate_inode_mutex_key()
init_rwsem(&inode->i_rwsem)
unlock_mount()
inode_unlock(inode)The mount side then releases a lock that according to the rwsem nobody holds:
DEBUG_RWSEMS_WARN_ON((rwsem_owner(sem) != current) && ...):
count = 0x0, magic = 0xffff888043a854e8, owner = 0x0, curr 0xffff888000244880, list empty
WARNING: CPU: 0 PID: 5346 at kernel/locking/rwsem.c:1368 __up_write Call Trace: inode_unlock include/linux/fs.h:877 [inline] unlock_mount fs/namespace.c:2892 [inline] do_new_mount_fc fs/namespace.c:3828 [inline] do_new_mount+0x777/0xa40 fs/namespace.c:3887
On PREEMPT_RT the same thing shows up as
DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current)
WARNING: kernel/locking/rtmutex_common.h:193 at rt_mutex_slowunlock
The up_write() underflows the reset count. A following inode_lock() on that directory then never returns. A path walk into the new directory racing with the mkdir() corrupts the lock the same way via inode_lock_shared() in lookup_slow().
Switch to d_instantiate_new() and drop the trailing unlock_new_inode(). All error paths bail out before that point with I_NEW still set and keep using discard_new_inode().
May we never see this fscking bug report again.
--- fs/ntfs3/inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/ntfs3/inode.c +2 -4
@@ -1705,10 +1705,10 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir, goto out6;/* -* Call 'd_instantiate' after inode->i_op is set +* Call 'd_instantiate_new' after inode->i_op is set * but before finish_open. */ -d_instantiate (dentry, inode); +d_instantiate_new (dentry, inode);/* Set original time. inode times (i_ctime) may be changed in ntfs_init_acl. */ inode->i_atime = inode->i_mtime =
@@ -1757,8 +1757,6 @@ struct inode *ntfs_create_inode(struct mnt_idmap *idmap, struct inode *dir,if (err)return ERR_PTR (err); -unlock_new_inode (inode); -return inode; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 465/3318 net: macb: initialize PTP state before registering clock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit e1406330d70e56dd44fa6fbafc86e77e5c80c122 ]
gem_ptp_init() registers the PTP clock before initializing bp->tsu_clk_lock and the TSU hardware. Since ptp_clock_register() publishes the PTP character device, userspace may invoke PTP callbacks before the lock and hardware are ready.
In addition, gem_ptp_init() is called from both the interface open and resume paths. Reinitializing tsu_clk_lock there can reset the lock while timestamp processing is using it.
This race is theoretical and has not been observed in practice.
Initialize tsu_clk_lock once during probe and initialize the TSU before registering the PTP clock.
--- drivers/net/ethernet/cadence/macb_main.c | 1 + drivers/net/ethernet/cadence/macb_ptp.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +1 -0
@@ -5218,6 +5218,7 @@ static int macb_probe(struct platform_device *pdev) }spin_lock_init (&bp->lock);spin_lock_init (&bp->stats_lock); +spin_lock_init (&bp->tsu_clk_lock);/* setup capabilities */ macb_configure_caps (bp, macb_config);
drivers/net/ethernet/cadence/macb_ptp.c +1 -4
@@ -341,6 +341,7 @@ void gem_ptp_init(struct net_device *dev) bp->tsu_rate = bp->ptp_info->get_tsu_rate (bp); bp->ptp_clock_info.max_adj = bp->ptp_info->get_ptp_max_adj ();gem_ptp_init_timer (bp); +gem_ptp_init_tsu (bp); bp->ptp_clock =ptp_clock_register (&bp->ptp_clock_info, &dev->dev);if (IS_ERR (bp->ptp_clock)) { pr_err("ptp clock register failed: %ld\n",
@@ -352,10 +353,6 @@ void gem_ptp_init(struct net_device *dev)return ; } -spin_lock_init (&bp->tsu_clk_lock); - -gem_ptp_init_tsu (bp); -dev_info (&bp->pdev->dev,"%s ptp clock registered.\n" ,GEM_PTP_TIMER_NAME ); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 466/3318 drm/amdgpu/pm: add workload profile pause helper
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
[ Upstream commit 7f991dd3641ef52e0a25b43f27cc61440c4bdcb4 ]
To be used for display idle optimizations when
we want to pause non-default profiles.
Stable-dep-of: 1f1d43418d61 ("drm/amdgpu: skip gfx switch_power_profile during GPU reset")
--- .../gpu/drm/amd/include/kgd_pp_interface.h | 1 + drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 19 +++++++++++++++++++ drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 2 ++ 3 files changed, 22 insertions(+)
drivers/gpu/drm/amd/include/kgd_pp_interface.h +1 -0
@@ -347,6 +347,7 @@ struct amd_pm_funcs {int (*set_pp_table)(void *handle,const char *buf,size_t size);void (*debugfs_print_current_performance_level)(void *handle,struct seq_file *m);int (*switch_power_profile)(void *handle,enum PP_SMC_POWER_PROFILE type,bool en); +int (*pause_power_profile)(void *handle,bool pause);/* export to amdgpu */ struct amd_vce_state *(*get_vce_clock_state)(void *handle,u32 idx); int (*dispatch_tasks)(void *handle, enum amd_pp_task task_id,
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +19 -0
@@ -319,6 +319,25 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,return ret; } +int amdgpu_dpm_pause_power_profile (struct amdgpu_device *adev, +bool pause) +{ +const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs; +int ret =0 ; + +if (amdgpu_sriov_vf (adev)) +return 0 ; + +if (pp_funcs && pp_funcs->pause_power_profile) { +mutex_lock (&adev->pm.mutex); + ret = pp_funcs->pause_power_profile ( + adev->powerplay.pp_handle, pause); +mutex_unlock (&adev->pm.mutex); + } + +return ret; +} +int amdgpu_dpm_set_xgmi_pstate (struct amdgpu_device *adev,uint32_t pstate) {
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h +2 -0
@@ -387,6 +387,8 @@ int amdgpu_dpm_set_xgmi_pstate(struct amdgpu_device *adev,int amdgpu_dpm_switch_power_profile (struct amdgpu_device *adev,enum PP_SMC_POWER_PROFILE type,bool en); +int amdgpu_dpm_pause_power_profile (struct amdgpu_device *adev, +bool pause);int amdgpu_dpm_baco_reset (struct amdgpu_device *adev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 467/3318 drm/amdgpu: skip gfx switch_power_profile during GPU reset
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prike Liang <[email protected]>
[ Upstream commit 1f1d43418d61c8511779e0f63a954a78b9433b43 ]
During resume from GPU reset, the gfx idle work may invoke switch_power_profile before the reset completes. This causes the following assert error because the register access occurs without first releasing the GPU reset semaphore:
[ 1576.768935] CR2: 0000559ea133ead0 CR3: 00000002e6c42000 CR4: 0000000000350ef0 [ 1576.768940] Call Trace: [ 1576.768944] <TASK> [ 1576.768953] amdgpu_device_rreg+0x21/0x50 [amdgpu] [ 1576.769158] smu_msg_v1_send_msg+0x1a4/0x6e0 [amdgpu] [ 1576.769437] smu_cmn_send_smc_msg_with_params_ext+0xba/0x120 [amdgpu] [ 1576.769721] smu_cmn_send_smc_msg_with_param+0x33/0x40 [amdgpu] [ 1576.769993] smu_v13_0_0_set_power_profile_mode+0x192/0x2b0 [amdgpu] [ 1576.770267] smu_bump_power_profile_mode+0x5d/0x80 [amdgpu] [ 1576.770538] smu_switch_power_profile+0xa4/0xf0 [amdgpu] [ 1576.770839] amdgpu_dpm_switch_power_profile+0x6f/0x90 [amdgpu] [ 1576.771210] amdgpu_gfx_profile_idle_work_handler+0xe9/0x130 [amdgpu] [ 1576.771460] process_one_work+0x23e/0x6f0 [ 1576.771491] worker_thread+0x1c4/0x380 [ 1576.771506] kthread+0x10c/0x150 [ 1576.771512] ? __pfx_worker_thread+0x10/0x10 [ 1576.771518] ? __pfx_kthread+0x10/0x10 [ 1576.771530] ret_from_fork+0x314/0x390 [ 1576.771537] ? __pfx_kthread+0x10/0x10 [ 1576.771546] ret_from_fork_asm+0x1a/0x30
--- drivers/gpu/drm/amd/pm/amdgpu_dpm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/pm/amdgpu_dpm.c +4 -2
@@ -306,7 +306,8 @@ int amdgpu_dpm_switch_power_profile(struct amdgpu_device *adev,const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;int ret =0 ; -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) || +amdgpu_in_reset (adev))return 0 ;if (pp_funcs && pp_funcs->switch_power_profile) {
@@ -325,7 +326,8 @@ int amdgpu_dpm_pause_power_profile(struct amdgpu_device *adev,const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;int ret =0 ; -if (amdgpu_sriov_vf (adev)) +if (amdgpu_sriov_vf (adev) || +amdgpu_in_reset (adev))return 0 ;if (pp_funcs && pp_funcs->pause_power_profile) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 468/3318 drm/msm: RCU-free the scheduler-containing ring and VM objects
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jonghyuk Kim(MalHyuk) <[email protected]>
[ Upstream commit 01c8d1f385f788f1bbbbb7687c4386d614281218 ]
Both struct msm_ringbuffer and struct msm_gem_vm embed a struct drm_gpu_scheduler. msm_ringbuffer_destroy() and the VM free callback msm_gem_vm_free() call drm_sched_fini() on the embedded scheduler and then free the containing object with plain kfree().
drm_sched_fence_get_timeline_name() returns fence->sched->name, and the scheduler fence keeps a .release callback so it is not ops-detached on signalling. A finished fence exported to userspace (the submit out-fence, or a VM_BIND fence, via sync_file / drm_syncobj) keeps pointing at the embedded scheduler after the ring/VM is freed, so a later get_timeline_name() -- reachable unprivileged through SYNC_IOC_FILE_INFO -- dereferences freed slab memory (KASAN slab-use-after-free read).
Per the dma-fence lifetime contract the exporter must keep the data backing a signalled fence alive for an RCU grace period. Free the scheduler-containing objects with kfree_rcu() instead of kfree().
Patchwork: https://patchwork.freedesktop.org/patch/750234/
Message-ID: <[email protected]>
--- drivers/gpu/drm/msm/msm_ringbuffer.c | 2 +- drivers/gpu/drm/msm/msm_ringbuffer.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/msm/msm_ringbuffer.c +1 -1
@@ -132,5 +132,5 @@ void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)msm_gem_kernel_put (ring->bo, ring->gpu->aspace); -kfree (ring); +kfree_rcu (ring, rcu); }
drivers/gpu/drm/msm/msm_ringbuffer.h +1 -0
@@ -49,6 +49,7 @@ struct msm_ringbuffer {/* * The job scheduler for this ring. */ +struct rcu_head rcu;struct drm_gpu_scheduler sched;bool sched_initialized;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 469/3318 arm64: Use load LSE atomics for the non-return per-CPU atomic operations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Catalin Marinas <[email protected]>
[ Upstream commit 535fdfc5a228524552ee8810c9175e877e127c27 ]
The non-return per-CPU this_cpu_*() atomic operations are implemented as STADD/STCLR/STSET when FEAT_LSE is available. On many microarchitecture implementations, these instructions tend to be executed "far" in the interconnect or memory subsystem (unless the data is already in the L1 cache). This is in general more efficient when there is contention as it avoids bouncing cache lines between CPUs. The load atomics (e.g. LDADD without XZR as destination), OTOH, tend to be executed "near" with the data loaded into the L1 cache.
STADD executed back to back as in srcu_read_{lock,unlock}*() incur an additional overhead due to the default posting behaviour on several CPU implementations. Since the per-CPU atomics are unlikely to be used concurrently on the same memory location, encourage the hardware to to execute them "near" by issuing load atomics - LDADD/LDCLR/LDSET - with the destination register unused (but not XZR).
Stable-dep-of: 8cf2093f5372 ("arm64: percpu: Fix LSE operations on {8,16}-bit types")
--- arch/arm64/include/asm/percpu.h | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
arch/arm64/include/asm/percpu.h +11 -4
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %[ptr]\n" \ +#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -124,9 +124,16 @@ PERCPU_RW_OPS(8) PERCPU_RW_OPS(16) PERCPU_RW_OPS(32)PERCPU_RW_OPS (64 ) -PERCPU_OP(add, add, stadd) -PERCPU_OP(andnot, bic, stclr) -PERCPU_OP(or, orr, stset) + +/* +* Use value-returning atomics for CPU-local ops as they are more likely +* to execute "near" to the CPU (e.g. in L1$). +* +* https://lore.kernel.org/r/e7d539ed-ced0-4b96-8ecd-048a5b803b85@paulmck-laptop + */ +PERCPU_OP(add, add, ldadd) +PERCPU_OP(andnot, bic, ldclr) +PERCPU_OP(or, orr, ldset) PERCPU_RET_OP(add, add, ldadd)#undef PERCPU_RW_OPS
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 470/3318 arm64: percpu: Fix LSE operations on {8,16}-bit types
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mark Rutland <[email protected]>
[ Upstream commit 8cf2093f5372952a9ebc805c418d45df7112cd14 ]
The assembly for __percpu_##name##_case_##sz() and __percpu_##name##_return_case_##sz() doesn't use the 'sfx' macro argument to form the LSE instruction. Without 'sfx', a W register argument will imply a 32-bit memory location, and consequently {8,16}-bit ops will erroneously read and write 32 bits of memory when the LSE instruction is used.
Fix this by appending 'sfx' to 'op_lse' to LSE instruction. It is not necessary (and not valid) to append 'sfx' to 'op_llsc', as 'op_llsc' is a register-register operation which does not access memory (and does not take a size suffix).
--- arch/arm64/include/asm/percpu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/percpu.h +2 -2
@@ -77,7 +77,7 @@ __percpu_##name##_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[tmp], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[tmp], %[ptr]\n" \ __nops(3)) \ : [loop] "=&r" (loop), [tmp] "=&r" (tmp), \ [ptr] "+Q"(*(u##sz *)ptr) \
@@ -98,7 +98,7 @@ __percpu_##name##_return_case_##sz(void *ptr, unsigned long val) \ " stxr" #sfx "\t%w[loop], %" #w "[ret], %[ptr]\n" \ " cbnz %w[loop], 1b", \ /* LSE atomics */ \ -#op_lse "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ +#op_lse #sfx "\t%" #w "[val], %" #w "[ret], %[ptr]\n" \ #op_llsc "\t%" #w "[ret], %" #w "[ret], %" #w "[val]\n" \ __nops(2)) \ : [loop] "=&r" (loop), [ret] "=&r" (ret), \
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 471/3318 tools/bootconfig: Cleanup bootconfig footer size calculations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 26dda57695090e05c1a99c3e8f802f862d1ac474 ]
There are many same pattern of 8 + BOOTCONFIG_MAGIC_LEN for calculating the size of bootconfig footer. Use BOOTCONFIG_FOOTER_SIZE macro to clean up those magic numbers.
Stable-dep-of: 462d0b066b61 ("tools/bootconfig: Fix integer overflow and truncation in size checks")
--- tools/bootconfig/main.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
tools/bootconfig/main.c +11 -8
@@ -16,6 +16,10 @@#define pr_err (fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) +/* Bootconfig footer is [size][csum][BOOTCONFIG_MAGIC]. */ +#define BOOTCONFIG_FOOTER_SIZE \ + (sizeof(uint32_t) * 2 + BOOTCONFIG_MAGIC_LEN) +static int xbc_show_value (struct xbc_node *node,bool semicolon) {const char *val, *eol;
@@ -188,7 +192,7 @@ static int load_xbc_from_initrd(int fd, char **buf)if (ret <0 )return -errno; -if (stat.st_size <8 +BOOTCONFIG_MAGIC_LEN ) +if (stat.st_size <BOOTCONFIG_FOOTER_SIZE )return 0 ;if (lseek (fd, -BOOTCONFIG_MAGIC_LEN ,SEEK_END ) <0 )
@@ -201,7 +205,7 @@ static int load_xbc_from_initrd(int fd, char **buf)if (memcmp (magic,BOOTCONFIG_MAGIC ,BOOTCONFIG_MAGIC_LEN ) !=0 )return 0 ; -if (lseek (fd, -(8 +BOOTCONFIG_MAGIC_LEN ),SEEK_END ) <0 ) +if (lseek (fd, -BOOTCONFIG_FOOTER_SIZE ,SEEK_END ) <0 )return pr_errno ("Failed to lseek for size" , -errno);if (read (fd, &size,sizeof (uint32_t )) <0 )
@@ -213,12 +217,12 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +8 +BOOTCONFIG_MAGIC_LEN ) { +if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; } -if (lseek (fd, stat.st_size - (size +8 +BOOTCONFIG_MAGIC_LEN ), +if (lseek (fd, stat.st_size - (size +BOOTCONFIG_FOOTER_SIZE ),SEEK_SET ) <0 )return pr_errno ("Failed to lseek" , -errno);
@@ -349,7 +353,7 @@ static int delete_xbc(const char *path) ret =fstat (fd, &stat);if (!ret) ret =ftruncate (fd, stat.st_size - - size -8 -BOOTCONFIG_MAGIC_LEN ); + - size -BOOTCONFIG_FOOTER_SIZE );if (ret) ret = -errno; }/* Ignore if there is no boot config in initrd */
@@ -379,8 +383,7 @@ static int apply_xbc(const char *path, const char *xbc_path) csum =xbc_calc_checksum (buf, size);/* Backup the bootconfig data */ - data =calloc (size +BOOTCONFIG_ALIGN + -sizeof (uint32_t ) +sizeof (uint32_t ) +BOOTCONFIG_MAGIC_LEN ,1 ); + data =calloc (size +BOOTCONFIG_ALIGN +BOOTCONFIG_FOOTER_SIZE ,1 );if (!data)return -ENOMEM ;memcpy (data, buf, size);
@@ -428,7 +431,7 @@ static int apply_xbc(const char *path, const char *xbc_path) }/* To align up the total size to BOOTCONFIG_ALIGN, get padding size */ - total_size = stat.st_size + size +sizeof (uint32_t ) *2 +BOOTCONFIG_MAGIC_LEN ; + total_size = stat.st_size + size +BOOTCONFIG_FOOTER_SIZE ; pad = ((total_size +BOOTCONFIG_ALIGN -1 ) & (~BOOTCONFIG_ALIGN_MASK )) - total_size; size += pad;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 472/3318 tools/bootconfig: Fix integer overflow and truncation in size checks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
[ Upstream commit 462d0b066b613103f579793031429db2ca23abc0 ]
Sashiko reported that on 32-bit systems, if an attacker crafts size in the bootconfig footer such that adding BOOTCONFIG_FOOTER_SIZE wraps around (for instance, if size is 0xFFFFFFFF), the size check in load_xbc_from_initrd() can be bypassed:
if (stat.st_size < size + BOOTCONFIG_FOOTER_SIZE) {
pr_err("bootconfig size is too big\n");
return -E2BIG;
}Furthermore, on 64-bit systems with an initrd > 4.29 GB, comparing a corrupted 32-bit size (e.g. 0xFFFFFFFF) against
stat.st_size - BOOTCONFIG_FOOTER_SIZE can also bypass the check if size is not bounded. Similarly, load_xbc_file() passes 64-bit stat.st_size directly into the 32-bit int size parameter of load_xbc_fd(), truncating large standalone files (>= 2GB).
In both cases, passing 0xFFFFFFFF to load_xbc_fd() truncates to -1, resulting in malloc(0), an integer overflow in read(), and an out-of-bounds null-byte write.
Fix this by:
1. Rejecting size > XBC_DATA_MAX or
size > stat.st_size - BOOTCONFIG_FOOTER_SIZE in load_xbc_from_initrd().
2. Rejecting stat.st_size > XBC_DATA_MAX in load_xbc_file() before passing it to load_xbc_fd().
3. Checking size < 0 || size > XBC_DATA_MAX defensively in load_xbc_fd().
--- tools/bootconfig/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
tools/bootconfig/main.c +12 -1
@@ -139,6 +139,9 @@ static int load_xbc_fd(int fd, char **buf, int size) {int ret; +if (size <0 || size >XBC_DATA_MAX ) +return -EINVAL ; + *buf =malloc (size +1 );if (!*buf)return -ENOMEM ;
@@ -167,6 +170,13 @@ static int load_xbc_file(const char *path, char **buf)return ret; } +if (stat.st_size >XBC_DATA_MAX ) { +pr_err ("%s size is too big\n" , path); + ret = -E2BIG ; +close (fd); +return ret; + } + ret =load_xbc_fd (fd, buf, stat.st_size);close (fd);
@@ -217,7 +227,8 @@ static int load_xbc_from_initrd(int fd, char **buf) csum =le32toh (csum);/* Wrong size error */ -if (stat.st_size < size +BOOTCONFIG_FOOTER_SIZE ) { +if (size >XBC_DATA_MAX || + size > stat.st_size -BOOTCONFIG_FOOTER_SIZE ) {pr_err ("bootconfig size is too big\n" );return -E2BIG ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 473/3318 KEYS: encrypted: fix integer overflow of datablob_len
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8697c431e297eb0d0ab13dda6bc172b48a34f05c ]
encrypted_key_alloc() stores datablob_len in a u16. It is computed from multiple string and payload lengths. If the result exceeds U16_MAX, the assignment truncates the allocation size. KASAN reports a 32760-byte slab-out-of-bounds write when __ekey_init() copies the master key description into the undersized buffer.
The total payload length stored in key->datalen is also a u16. Use check_add_overflow() to reject values that do not fit either destination, and use kzalloc_flex() for the flexible-array allocation.
--- security/keys/encrypted-keys/encrypted.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
security/keys/encrypted-keys/encrypted.c +14 -6
@@ -18,6 +18,7 @@#include <linux/parser.h> #include <linux/string.h> #include <linux/err.h> +#include <linux/overflow.h> #include <keys/user-type.h> #include <keys/trusted-type.h> #include <keys/encrypted-type.h>
@@ -606,6 +607,7 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, {struct encrypted_key_payload *epayload =NULL ;unsigned short datablob_len; +unsigned short payload_totallen;unsigned short decrypted_datalen;unsigned short payload_datalen;unsigned int encrypted_datalen;
@@ -659,16 +661,22 @@ static struct encrypted_key_payload *encrypted_key_alloc(struct key *key, encrypted_datalen =roundup (decrypted_datalen, blksize); - datablob_len = format_len +1 +strlen (master_desc) +1 - +strlen (datalen) +1 + ivsize +1 + encrypted_datalen; +if (check_add_overflow (format_len +1 +strlen (master_desc) +1 + +strlen (datalen) +1 + ivsize +1 , + encrypted_datalen, &datablob_len)) +return ERR_PTR (-EINVAL ); + +if (check_add_overflow (datablob_len, + payload_datalen +HASH_SIZE +1 , + &payload_totallen)) +return ERR_PTR (-EINVAL ); - ret =key_payload_reserve (key, payload_datalen + datablob_len - +HASH_SIZE +1 ); + ret =key_payload_reserve (key, payload_totallen);if (ret <0 )return ERR_PTR (ret); - epayload =kzalloc (sizeof (*epayload) + payload_datalen + - datablob_len +HASH_SIZE +1 ,GFP_KERNEL ); + epayload =kzalloc (struct_size (epayload, payload_data, payload_totallen), +GFP_KERNEL );if (!epayload)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 474/3318 ALSA: core: Use guard() for locking
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 742ecf3ce1acdbcd0bc936178e1eaf346a0fd376 ]
We can simplify the code gracefully with new guard() macro and co for automatic cleanup of locks.
Only the code refactoring, and no functional changes.
Stable-dep-of: fd95e68df6fe ("ALSA: core: Fix potential UAF after asynchronous card release")
--- sound/core/init.c | 193 +++++++++++++++++++---------------------- sound/core/sound.c | 28 +++--- sound/core/sound_oss.c | 17 ++-- 3 files changed, 104 insertions(+), 134 deletions(-)
sound/core/init.c +88 -105
@@ -284,30 +284,31 @@ static int snd_card_init(struct snd_card *card, struct device *parent,if (xid)strscpy (card->id, xid,sizeof (card->id)); err =0 ; -mutex_lock (&snd_card_mutex); -if (idx <0 )/* first check the matching module-name slot */ - idx =get_slot_from_bitmask (idx, module_slot_match, module); -if (idx <0 )/* if not matched, assign an empty slot */ - idx =get_slot_from_bitmask (idx, check_empty_slot, module); -if (idx <0 ) - err = -ENODEV ; -else if (idx < snd_ecards_limit) { -if (test_bit (idx, snd_cards_lock)) - err = -EBUSY ;/* invalid */ - }else if (idx >=SNDRV_CARDS ) - err = -ENODEV ; + scoped_guard(mutex, &snd_card_mutex) { +if (idx <0 )/* first check the matching module-name slot */ + idx =get_slot_from_bitmask (idx, module_slot_match, module); +if (idx <0 )/* if not matched, assign an empty slot */ + idx =get_slot_from_bitmask (idx, check_empty_slot, module); +if (idx <0 ) + err = -ENODEV ; +else if (idx < snd_ecards_limit) { +if (test_bit (idx, snd_cards_lock)) + err = -EBUSY ;/* invalid */ + }else if (idx >=SNDRV_CARDS ) + err = -ENODEV ; +if (!err) { +set_bit (idx, snd_cards_lock);/* lock it */ +if (idx >= snd_ecards_limit) + snd_ecards_limit = idx +1 ;/* increase the limit */ + } + }if (err <0 ) { -mutex_unlock (&snd_card_mutex);dev_err (parent,"cannot find the slot for index %d (range 0-%i), error: %d\n" , - idx, snd_ecards_limit -1 , err); + idx, snd_ecards_limit -1 , err);if (!card->managed)kfree (card);/* manually free here, as no destructor called */ return err; } -set_bit (idx, snd_cards_lock);/* lock it */ -if (idx >= snd_ecards_limit) - snd_ecards_limit = idx +1 ;/* increase the limit */ -mutex_unlock (&snd_card_mutex); card->dev = parent; card->number = idx;#ifdef MODULE
@@ -386,11 +387,10 @@ struct snd_card *snd_card_ref(int idx) {struct snd_card *card; -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card)get_device (&card->card_dev); -mutex_unlock (&snd_card_mutex);return card; }EXPORT_SYMBOL_GPL (snd_card_ref);
@@ -398,12 +398,8 @@ EXPORT_SYMBOL_GPL(snd_card_ref);/* return non-zero if a card is already locked */ int snd_card_locked (int card) { -int locked; - -mutex_lock (&snd_card_mutex); - locked =test_bit (card, snd_cards_lock); -mutex_unlock (&snd_card_mutex); -return locked; +guard (mutex)(&snd_card_mutex); +return test_bit (card, snd_cards_lock); }static loff_t snd_disconnect_llseek (struct file *file,loff_t offset,int orig)
@@ -427,15 +423,15 @@ static int snd_disconnect_release(struct inode *inode, struct file *file) {struct snd_monitor_file *df =NULL , *_df; -spin_lock (&shutdown_lock); -list_for_each_entry (_df, &shutdown_files, shutdown_list) { -if (_df->file == file) { - df = _df; -list_del_init (&df->shutdown_list); -break ; + scoped_guard(spinlock, &shutdown_lock) { +list_for_each_entry (_df, &shutdown_files, shutdown_list) { +if (_df->file == file) { + df = _df; +list_del_init (&df->shutdown_list); +break ; + } } } -spin_unlock (&shutdown_lock);if (likely (df)) {if ((file->f_flags &FASYNC ) && df->disconnected_f_op->fasync)
@@ -501,27 +497,24 @@ void snd_card_disconnect(struct snd_card *card)if (!card)return ; -spin_lock (&card->files_lock); -if (card->shutdown) { -spin_unlock (&card->files_lock); -return ; - } - card->shutdown =1 ; + scoped_guard(spinlock, &card->files_lock) { +if (card->shutdown) +return ; + card->shutdown =1 ; -/* replace file->f_op with special dummy operations */ -list_for_each_entry (mfile, &card->files_list, list) { -/* it's critical part, use endless loop */ -/* we have no room to fail */ - mfile->disconnected_f_op = mfile->file->f_op; +/* replace file->f_op with special dummy operations */ +list_for_each_entry (mfile, &card->files_list, list) { +/* it's critical part, use endless loop */ +/* we have no room to fail */ + mfile->disconnected_f_op = mfile->file->f_op; -spin_lock (&shutdown_lock); -list_add (&mfile->shutdown_list, &shutdown_files); -spin_unlock (&shutdown_lock); + scoped_guard(spinlock, &shutdown_lock) +list_add (&mfile->shutdown_list, &shutdown_files); - mfile->file->f_op = &snd_shutdown_f_ops; -fops_get (mfile->file->f_op); + mfile->file->f_op = &snd_shutdown_f_ops; +fops_get (mfile->file->f_op); + } } -spin_unlock (&card->files_lock);#ifdef CONFIG_PM /* wake up sleepers here before other callbacks for avoiding potential
@@ -557,10 +550,10 @@ void snd_card_disconnect(struct snd_card *card) }/* disable fops (user space) operations for ALSA API */ -mutex_lock (&snd_card_mutex); - snd_cards[card->number] =NULL ; -clear_bit (card->number, snd_cards_lock); -mutex_unlock (&snd_card_mutex); + scoped_guard(mutex, &snd_card_mutex) { + snd_cards[card->number] =NULL ; +clear_bit (card->number, snd_cards_lock); + }#ifdef CONFIG_PM snd_power_sync_ref (card);
@@ -581,11 +574,10 @@ void snd_card_disconnect_sync(struct snd_card *card) {snd_card_disconnect (card); -spin_lock_irq (&card->files_lock); +guard (spinlock_irq)(&card->files_lock);wait_event_lock_irq (card->remove_sleep,list_empty (&card->files_list), card->files_lock); -spin_unlock_irq (&card->files_lock); }EXPORT_SYMBOL_GPL (snd_card_disconnect_sync);
@@ -783,9 +775,8 @@ void snd_card_set_id(struct snd_card *card, const char *nid)/* check if user specified own card->id */ if (card->id[0 ] !='\0' )return ; -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex);snd_card_set_id_no_lock (card, nid, nid); -mutex_unlock (&snd_card_mutex); }EXPORT_SYMBOL (snd_card_set_id);
@@ -813,14 +804,11 @@ static ssize_t id_store(struct device *dev, struct device_attribute *attr, }memcpy (buf1, buf, copy); buf1[copy] ='\0' ; -mutex_lock (&snd_card_mutex); -if (!card_id_ok (NULL , buf1)) { -mutex_unlock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); +if (!card_id_ok (NULL , buf1))return -EEXIST ; - }strcpy (card->id, buf1);snd_info_card_id_change (card); -mutex_unlock (&snd_card_mutex);return count; }
@@ -913,26 +901,27 @@ int snd_card_register(struct snd_card *card) err =snd_device_register_all (card);if (err <0 )return err; -mutex_lock (&snd_card_mutex); -if (snd_cards[card->number]) { -/* already registered */ -mutex_unlock (&snd_card_mutex); -return snd_info_card_register (card);/* register pending info */ - } -if (*card->id) { -/* make a unique id name from the given string */ -char tmpid[sizeof (card->id)]; -memcpy (tmpid, card->id,sizeof (card->id)); -snd_card_set_id_no_lock (card, tmpid, tmpid); - }else { -/* create an id from either shortname or longname */ -const char *src; - src = *card->shortname ? card->shortname : card->longname; -snd_card_set_id_no_lock (card, src, -retrieve_id_from_card_name (src)); + scoped_guard(mutex, &snd_card_mutex) { +if (snd_cards[card->number]) { +/* already registered */ +return snd_info_card_register (card);/* register pending info */ + } +if (*card->id) { +/* make a unique id name from the given string */ +char tmpid[sizeof (card->id)]; + +memcpy (tmpid, card->id,sizeof (card->id)); +snd_card_set_id_no_lock (card, tmpid, tmpid); + }else { +/* create an id from either shortname or longname */ +const char *src; + + src = *card->shortname ? card->shortname : card->longname; +snd_card_set_id_no_lock (card, src, +retrieve_id_from_card_name (src)); + } + snd_cards[card->number] = card; } - snd_cards[card->number] = card; -mutex_unlock (&snd_card_mutex); err =snd_info_card_register (card);if (err <0 )return err;
@@ -953,7 +942,7 @@ static void snd_card_info_read(struct snd_info_entry *entry,struct snd_card *card;for (idx = count =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card) { count++;
@@ -965,7 +954,6 @@ static void snd_card_info_read(struct snd_info_entry *entry,snd_iprintf (buffer," %s\n" , card->longname); } -mutex_unlock (&snd_card_mutex); }if (!count)snd_iprintf (buffer,"--- no soundcards ---\n" );
@@ -978,13 +966,12 @@ void snd_card_info_read_oss(struct snd_info_buffer *buffer)struct snd_card *card;for (idx = count =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card) { count++;snd_iprintf (buffer,"%s\n" , card->longname); } -mutex_unlock (&snd_card_mutex); }if (!count) {snd_iprintf (buffer,"--- no soundcards ---\n" );
@@ -1001,12 +988,11 @@ static void snd_card_module_info_read(struct snd_info_entry *entry,struct snd_card *card;for (idx =0 ; idx <SNDRV_CARDS ; idx++) { -mutex_lock (&snd_card_mutex); +guard (mutex)(&snd_card_mutex); card = snd_cards[idx];if (card)snd_iprintf (buffer,"%2i %s\n" , idx, card->module->name); -mutex_unlock (&snd_card_mutex); } }#endif
@@ -1088,15 +1074,13 @@ int snd_card_file_add(struct snd_card *card, struct file *file) mfile->file = file; mfile->disconnected_f_op =NULL ;INIT_LIST_HEAD (&mfile->shutdown_list); -spin_lock (&card->files_lock); +guard (spinlock)(&card->files_lock);if (card->shutdown) { -spin_unlock (&card->files_lock);kfree (mfile);return -ENODEV ; }list_add (&mfile->list, &card->files_list);get_device (&card->card_dev); -spin_unlock (&card->files_lock);return 0 ; }EXPORT_SYMBOL (snd_card_file_add);
@@ -1118,22 +1102,21 @@ int snd_card_file_remove(struct snd_card *card, struct file *file) {struct snd_monitor_file *mfile, *found =NULL ; -spin_lock (&card->files_lock); -list_for_each_entry (mfile, &card->files_list, list) { -if (mfile->file == file) { -list_del (&mfile->list); -spin_lock (&shutdown_lock); -list_del (&mfile->shutdown_list); -spin_unlock (&shutdown_lock); -if (mfile->disconnected_f_op) -fops_put (mfile->disconnected_f_op); - found = mfile; -break ; + scoped_guard(spinlock, &card->files_lock) { +list_for_each_entry (mfile, &card->files_list, list) { +if (mfile->file == file) { +list_del (&mfile->list); + scoped_guard(spinlock, &shutdown_lock) +list_del (&mfile->shutdown_list); +if (mfile->disconnected_f_op) +fops_put (mfile->disconnected_f_op); + found = mfile; +break ; + } } +if (list_empty (&card->files_list)) +wake_up_all (&card->remove_sleep); } -if (list_empty (&card->files_list)) -wake_up_all (&card->remove_sleep); -spin_unlock (&card->files_lock);if (!found) {dev_err (card->dev,"card file remove problem (%p)\n" , file);return -ENOENT ;
sound/core/sound.c +11 -17
@@ -103,7 +103,7 @@ void *snd_lookup_minor_data(unsigned int minor, int type)if (minor >=ARRAY_SIZE (snd_minors))return NULL ; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex); mreg = snd_minors[minor];if (mreg && mreg->type == type) { private_data = mreg->private_data;
@@ -111,7 +111,6 @@ void *snd_lookup_minor_data(unsigned int minor, int type)get_device (&mreg->card_ptr->card_dev); }else private_data =NULL ; -mutex_unlock (&sound_mutex);return private_data; }EXPORT_SYMBOL (snd_lookup_minor_data);
@@ -150,17 +149,15 @@ static int snd_open(struct inode *inode, struct file *file)if (minor >=ARRAY_SIZE (snd_minors))return -ENODEV ; -mutex_lock (&sound_mutex); - mptr = snd_minors[minor]; -if (mptr ==NULL ) { - mptr =autoload_device (minor); -if (!mptr) { -mutex_unlock (&sound_mutex); -return -ENODEV ; + scoped_guard(mutex, &sound_mutex) { + mptr = snd_minors[minor]; +if (mptr ==NULL ) { + mptr =autoload_device (minor); +if (!mptr) +return -ENODEV ; } + new_fops =fops_get (mptr->f_ops); } - new_fops =fops_get (mptr->f_ops); -mutex_unlock (&sound_mutex);if (!new_fops)return -ENODEV ;replace_fops (file, new_fops);
@@ -276,7 +273,7 @@ int snd_register_device(int type, struct snd_card *card, int dev, preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex); minor =snd_find_free_minor (type, card, dev);if (minor <0 ) { err = minor;
@@ -291,7 +288,6 @@ int snd_register_device(int type, struct snd_card *card, int dev, snd_minors[minor] = preg; error: -mutex_unlock (&sound_mutex);if (err <0 )kfree (preg);return err;
@@ -312,7 +308,7 @@ int snd_unregister_device(struct device *dev)int minor;struct snd_minor *preg; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex);for (minor =0 ; minor <ARRAY_SIZE (snd_minors); ++minor) { preg = snd_minors[minor];if (preg && preg->dev == dev) {
@@ -322,7 +318,6 @@ int snd_unregister_device(struct device *dev)break ; } } -mutex_unlock (&sound_mutex);if (minor >=ARRAY_SIZE (snd_minors))return -ENOENT ;return 0 ;
@@ -362,7 +357,7 @@ static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_buint minor;struct snd_minor *mptr; -mutex_lock (&sound_mutex); +guard (mutex)(&sound_mutex);for (minor =0 ; minor <SNDRV_OS_MINORS ; ++minor) { mptr = snd_minors[minor];if (!mptr)
@@ -380,7 +375,6 @@ static void snd_minor_info_read(struct snd_info_entry *entry, struct snd_info_busnd_iprintf (buffer,"%3i: : %s\n" , minor,snd_device_type_name (mptr->type)); } -mutex_unlock (&sound_mutex); }int __init snd_minor_info_init (void )
sound/core/sound_oss.c +5 -12
@@ -29,7 +29,7 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)if (minor >=ARRAY_SIZE (snd_oss_minors))return NULL ; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); mreg = snd_oss_minors[minor];if (mreg && mreg->type == type) { private_data = mreg->private_data;
@@ -37,7 +37,6 @@ void *snd_lookup_oss_minor_data(unsigned int minor, int type)get_device (&mreg->card_ptr->card_dev); }else private_data =NULL ; -mutex_unlock (&sound_oss_mutex);return private_data; }EXPORT_SYMBOL (snd_lookup_oss_minor_data);
@@ -106,7 +105,7 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, preg->f_ops = f_ops; preg->private_data = private_data; preg->card_ptr = card; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); snd_oss_minors[minor] = preg; minor_unit =SNDRV_MINOR_OSS_DEVICE (minor);switch (minor_unit) {
@@ -130,7 +129,6 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev, goto __end; snd_oss_minors[track2] = preg; } -mutex_unlock (&sound_oss_mutex);return 0 ; __end:
@@ -139,7 +137,6 @@ int snd_register_oss_device(int type, struct snd_card *card, int dev,if (register1 >=0 )unregister_sound_special (register1); snd_oss_minors[minor] =NULL ; -mutex_unlock (&sound_oss_mutex);kfree (preg);return -EBUSY ; }
@@ -156,12 +153,10 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)return 0 ;if (minor <0 )return minor; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex); mptr = snd_oss_minors[minor]; -if (mptr ==NULL ) { -mutex_unlock (&sound_oss_mutex); +if (mptr ==NULL )return -ENOENT ; - }switch (SNDRV_MINOR_OSS_DEVICE (minor)) {case SNDRV_MINOR_OSS_PCM : track2 =SNDRV_MINOR_OSS (cidx,SNDRV_MINOR_OSS_AUDIO );
@@ -176,7 +171,6 @@ int snd_unregister_oss_device(int type, struct snd_card *card, int dev)if (track2 >=0 ) snd_oss_minors[track2] =NULL ; snd_oss_minors[minor] =NULL ; -mutex_unlock (&sound_oss_mutex);/* call unregister_sound_special() outside sound_oss_mutex; * otherwise may deadlock, as it can trigger the release of a card
@@ -220,7 +214,7 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,int minor;struct snd_minor *mptr; -mutex_lock (&sound_oss_mutex); +guard (mutex)(&sound_oss_mutex);for (minor =0 ; minor <SNDRV_OSS_MINORS ; ++minor) { mptr = snd_oss_minors[minor];if (!mptr)
@@ -233,7 +227,6 @@ static void snd_minor_info_oss_read(struct snd_info_entry *entry,snd_iprintf (buffer,"%3i: : %s\n" , minor,snd_oss_device_type_name (mptr->type)); } -mutex_unlock (&sound_oss_mutex); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 475/3318 ALSA: core: Fix potential UAF after asynchronous card release
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit fd95e68df6fe66344161a1329cbe5e5805e7b704 ]
Usually a sound driver releases the resources assigned to the card via snd_card_free(), and it synchronizes with the whole release procedure. However, when the card is released asynchronously via snd_card_free_when_closed() like USB-audio driver, the situation is slightly different; although the snd_card_disconnect() call at the disconnection guarantees that any newer accesses will be gated, the in-flight tasks might be still accessing to the underlying card->dev device even after the disconnection, which would cause a use-after-free in the end, as reported by fuzzers.
For addressing the bug above, this patch takes the refcount of card->dev at initialization of the card object, and releases at its
destructor. This assures the availability of the card->dev in its
whole lifecycle.
--- sound/core/init.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
sound/core/init.c +2 -1
@@ -309,7 +309,7 @@ static int snd_card_init(struct snd_card *card, struct device *parent,kfree (card);/* manually free here, as no destructor called */ return err; } - card->dev = parent; + card->dev =get_device (parent); card->number = idx;#ifdef MODULE WARN_ON (!module);
@@ -597,6 +597,7 @@ static int snd_card_do_free(struct snd_card *card)dev_warn (card->dev,"unable to free card info\n" );/* Not fatal error */ } +put_device (card->dev);if (card->release_completion)complete (card->release_completion);if (!managed)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 476/3318 phy: renesas: rcar-gen3-usb2: Avoid long delay in atomic context
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Claudiu Beznea <[email protected]>
[ Upstream commit 48e97c59a49c9e90270f5e3d221db253b76de5da ]
The OTG PHY initialization sequence needs to wait for 20 ms at a specific step, as described in commit 72c0339c115b ("phy: renesas:
rcar-gen3-usb2: follow the hardware manual procedure").
Commit 55a387ebb921 ("phy: renesas: rcar-gen3-usb2: Lock around hardware registers and driver data") tried to address various problems in the rcar-gen3-usb2 driver and converted the mutex protecting HW register accesses to a spin lock, leaving, however, a long delay in the critical section protected by the spin lock. This may become a problem, especially on RT kernels.
To address this, release the spin lock before sleeping for 20 ms as required by the HW manual and reacquire it afterwards. To avoid other threads entering the critical section and configuring the HW while the software is waiting for the OTG initialization to complete, introduce the otg_initializing variable alongside the otg_init_done wait queue. Any other thread trying to configure the HW while the OTG PHY initialization is in progress waits for the wait queue instead of immediately returning errors to PHY users. The IRQs were also disabled while waiting for the OTG PHY initialization to complete, as the interrupt handler may also apply HW settings.
The OTG can only be initialized once. It is initialized by the first PHY that calls struct phy_ops::rcar_gen3_phy_usb2_init().
To avoid failures when multiple PHYs call struct phy_ops::rcar_gen3_phy_usb2_init() simultaneously, and the PHY responsible for initializing the OTG either fails or deinit quiqly and another PHY takes over the PHY init role), the code waiting for the channel->otg_init_done wait queue retries up to NUM_OF_PHYS times.
--- drivers/phy/renesas/phy-rcar-gen3-usb2.c | 302 ++++++++++++++++++++--- 1 file changed, 261 insertions(+), 41 deletions(-)
drivers/phy/renesas/phy-rcar-gen3-usb2.c +261 -41
@@ -23,6 +23,7 @@#include <linux/reset.h> #include <linux/string.h> #include <linux/usb/of.h> +#include <linux/wait.h> #include <linux/workqueue.h> /******* USB2.0 Host registers (original offset is +0x200) *******/
@@ -88,6 +89,13 @@#define USB2_OBINT_IDCHG_EN BIT(0)#define USB2_LINECTRL1_USB2_IDMON BIT(0) +/* +* The OTG initialization is expected to finish in 20ms. Choose a large enough +* timeout to avoid waiters exit prematurely the waiting section under heavy +* CPU load. +*/ +#define USB2_OTG_INIT_TIMEOUT msecs_to_jiffies(120) +#define NUM_OF_PHYS 4enum rcar_gen3_phy_index {PHY_INDEX_BOTH_HC ,
@@ -118,6 +126,7 @@ struct rcar_gen3_chan {struct rcar_gen3_phy rphys[NUM_OF_PHYS ];struct regulator *vbus;struct work_struct work; +wait_queue_head_t otg_init_done;spinlock_t lock;/* protects access to hardware and driver data structure. */ enum usb_dr_mode dr_mode;u32 obint_enable_bits;
@@ -125,6 +134,13 @@ struct rcar_gen3_chan {bool is_otg_channel;bool uses_otg_pins;bool soc_no_adp_ctrl; +/* +* The OTG can be initialized only once and needs to release the spinlock +* and wait for 20 ms due to hardware constraints. If a thread executes +* PHY configuration code while the OTG PHY is waiting for the 20 ms, the +* thread will have to wait for the OTG PHY initialization to complete. +*/ +bool otg_initializing; };struct rcar_gen3_phy_drv_data {
@@ -344,26 +360,58 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,struct rcar_gen3_chan *ch =dev_get_drvdata (dev);bool is_b_device;enum phy_mode cur_mode, new_mode; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret = -EIO ; -guard (spinlock_irqsave)(&ch->lock); +spin_lock_irqsave (&ch->lock, flags); -if (!ch->is_otg_channel || !rcar_gen3_is_any_otg_rphy_initialized (ch)) -return -EIO ; +if (!ch->is_otg_channel) + goto unlock; + +while (retries-- && ch->otg_initializing) { +spin_unlock_irqrestore (&ch->lock, flags); + + ret =wait_event_timeout (ch->otg_init_done, !ch->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto exit; + +spin_lock_irqsave (&ch->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (ch->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + +if (!rcar_gen3_is_any_otg_rphy_initialized (ch)) { + ret = -EIO ; + goto unlock; + } -if (sysfs_streq (buf,"host" )) +if (sysfs_streq (buf,"host" )) { new_mode =PHY_MODE_USB_HOST ; -else if (sysfs_streq (buf,"peripheral" )) + }else if (sysfs_streq (buf,"peripheral" )) { new_mode =PHY_MODE_USB_DEVICE ; -else -return -EINVAL ; + }else { + ret = -EINVAL ; + goto unlock; + }/* is_b_device: true is B-Device. false is A-Device. */ is_b_device =rcar_gen3_check_id (ch); cur_mode =rcar_gen3_get_phy_mode (ch);/* If current and new mode is the same, this returns the error */ -if (cur_mode == new_mode) -return -EINVAL ; +if (cur_mode == new_mode) { + ret = -EINVAL ; + goto unlock; + }if (new_mode ==PHY_MODE_USB_HOST ) {/* And is_host must be false */ if (!is_b_device)/* A-Peripheral */
@@ -377,7 +425,10 @@ static ssize_t role_store(struct device *dev, struct device_attribute *attr,rcar_gen3_init_for_peri (ch); } -return count; +unlock: +spin_unlock_irqrestore (&ch->lock, flags); +exit: +return ret ?: count; } static ssize_t role_show(struct device *dev, struct device_attribute *attr,
@@ -393,14 +444,11 @@ static ssize_t role_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RW (role); -static void rcar_gen3_init_otg (struct rcar_gen3_chan *ch) +static void rcar_gen3_init_otg_phase0 (struct rcar_gen3_chan *ch) {void __iomem *usb2_base = ch->base;u32 val; -if (!ch->is_otg_channel ||rcar_gen3_is_any_otg_rphy_initialized (ch)) -return ; -/* Should not use functions of read-modify-write a register */ val =readl (usb2_base +USB2_LINECTRL1 ); val = (val & ~USB2_LINECTRL1_DP_RPD) | USB2_LINECTRL1_DPRPD_EN |
@@ -414,7 +462,11 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch) val =readl (usb2_base +USB2_ADPCTRL );writel (val |USB2_ADPCTRL_IDPULLUP , usb2_base +USB2_ADPCTRL ); } -mdelay (20 ); +} + +static void rcar_gen3_init_otg_phase1 (struct rcar_gen3_chan *ch) +{ +void __iomem *usb2_base = ch->base;writel (0xffffffff , usb2_base +USB2_OBINTSTA );writel (ch->obint_enable_bits, usb2_base +USB2_OBINTEN );
@@ -428,6 +480,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)void __iomem *usb2_base = ch->base;struct device *dev = ch->dev;irqreturn_t ret =IRQ_NONE ; +unsigned long flags;u32 status;pm_runtime_get_noresume (dev);
@@ -435,29 +488,98 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)if (pm_runtime_suspended (dev)) goto rpm_put; - scoped_guard(spinlock, &ch->lock) { - status =readl (usb2_base +USB2_OBINTSTA ); -if (status & ch->obint_enable_bits) { -dev_vdbg (dev,"%s: %08x\n" , __func__, status); -writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); -rcar_gen3_device_recognition (ch); - ret =IRQ_HANDLED ; - } +spin_lock_irqsave (&ch->lock, flags); + + status =readl (usb2_base +USB2_OBINTSTA ); +if (status & ch->obint_enable_bits) { +dev_vdbg (dev,"%s: %08x\n" , __func__, status); +writel (ch->obint_enable_bits, usb2_base +USB2_OBINTSTA ); + + ret =IRQ_HANDLED ; + +/* This should not happen! */ +if (ch->otg_initializing) + goto unlock; + +rcar_gen3_device_recognition (ch); } +unlock: +spin_unlock_irqrestore (&ch->lock, flags); rpm_put:pm_runtime_put_noidle (dev);return ret; } +static void rcar_gen3_phy_usb2_irqs_mask_all (struct rcar_gen3_chan *channel, +u32 *masked_irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + *masked_irqs_bits = val & bitmask; + val &= ~bitmask; +writel (val, usb2_base +USB2_INT_ENABLE ); + +/* +* Don't report channel->obint_enable_bits IRQs. These are +* unmasked anyway in rcar_gen3_init_otg_phase1(). +*/ + val =readl (usb2_base +USB2_OBINTEN ); + val &= ~channel->obint_enable_bits; +writel (val, usb2_base +USB2_OBINTEN ); +} + +static void rcar_gen3_phy_usb2_irqs_unmask (struct rcar_gen3_chan *channel, +u32 irqs_bits) +{ +u32 val, bitmask =USB2_INT_ENABLE_UCOM_INTEN ; +void __iomem *usb2_base = channel->base; + +for (unsigned int i =0 ; i <NUM_OF_PHYS ; i++) + bitmask |= channel->rphys[i].int_enable_bits; + + val =readl (usb2_base +USB2_INT_ENABLE ); + val &= ~bitmask; + val |= irqs_bits; +writel (val, usb2_base +USB2_INT_ENABLE ); +} +static int rcar_gen3_phy_usb2_init (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }/* Initialize USB2 part */ val =readl (usb2_base +USB2_INT_ENABLE );
@@ -470,12 +592,30 @@ static int rcar_gen3_phy_usb2_init(struct phy *p) }/* Initialize otg part (only if we initialize a PHY with IRQs). */ -if (rphy->int_enable_bits) -rcar_gen3_init_otg (channel); +if (rphy->int_enable_bits && channel->is_otg_channel && + !rcar_gen3_is_any_otg_rphy_initialized (channel)) { +u32 masked_irq_bits =0 ; + +rcar_gen3_init_otg_phase0 (channel); +rcar_gen3_phy_usb2_irqs_mask_all (channel, &masked_irq_bits); + channel->otg_initializing = true; +spin_unlock_irqrestore (&channel->lock, flags); + +fsleep (20000 ); + +spin_lock_irqsave (&channel->lock, flags); +rcar_gen3_phy_usb2_irqs_unmask (channel, masked_irq_bits); +rcar_gen3_init_otg_phase1 (channel); + channel->otg_initializing = false; +wake_up_all (&channel->otg_init_done); + } rphy->initialized = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +return ret; }static int rcar_gen3_phy_usb2_exit (struct phy *p)
@@ -483,9 +623,32 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; +int ret; -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } rphy->initialized = false;
@@ -495,7 +658,9 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p) val &= ~USB2_INT_ENABLE_UCOM_INTEN ;writel (val, usb2_base +USB2_INT_ENABLE ); -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); +return ret; }static int rcar_gen3_phy_usb2_power_on (struct phy *p)
@@ -503,8 +668,10 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch;void __iomem *usb2_base = channel->base; +int retries =NUM_OF_PHYS ; +unsigned long flags;u32 val; -int ret =0 ; +int ret;if (channel->vbus) { ret =regulator_enable (channel->vbus);
@@ -512,7 +679,27 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)return ret; } -guard (spinlock_irqsave)(&channel->lock); +spin_lock_irqsave (&channel->lock, flags); + +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); + + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) + goto disable_regulator; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + }if (!rcar_gen3_are_all_rphys_power_off (channel)) goto out;
@@ -527,27 +714,59 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)/* The powered flag should be set for any other phys anyway */ rphy->powered = true; -return 0 ; +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +disable_regulator: +if (ret && channel->vbus) +regulator_disable (channel->vbus); + +return ret; }static int rcar_gen3_phy_usb2_power_off (struct phy *p) {struct rcar_gen3_phy *rphy =phy_get_drvdata (p);struct rcar_gen3_chan *channel = rphy->ch; -int ret =0 ; +int retries =NUM_OF_PHYS ; +unsigned long flags; +int ret; - scoped_guard(spinlock_irqsave, &channel->lock) { - rphy->powered = false; +spin_lock_irqsave (&channel->lock, flags); -if (rcar_gen3_are_all_rphys_power_off (channel)) { -u32 val =readl (channel->base +USB2_USBCTR ); +while (retries-- && channel->otg_initializing) { +spin_unlock_irqrestore (&channel->lock, flags); - val |=USB2_USBCTR_PLL_RST ; -writel (val, channel->base +USB2_USBCTR ); - } + ret =wait_event_timeout (channel->otg_init_done, !channel->otg_initializing, +USB2_OTG_INIT_TIMEOUT ); + ret = ret ?0 : -ETIMEDOUT ; +if (ret && !retries) +return ret; + +spin_lock_irqsave (&channel->lock, flags); + } + +/* If another thread started a new initialization just return -EBUSY. */ +if (channel->otg_initializing) { + ret = -EBUSY ; + goto unlock; + }else { + ret =0 ; + } + + rphy->powered = false; + +if (rcar_gen3_are_all_rphys_power_off (channel)) { +u32 val =readl (channel->base +USB2_USBCTR ); + + val |=USB2_USBCTR_PLL_RST ; +writel (val, channel->base +USB2_USBCTR ); } -if (channel->vbus) +unlock: +spin_unlock_irqrestore (&channel->lock, flags); + +if (!ret && channel->vbus) ret =regulator_disable (channel->vbus);return ret;
@@ -761,6 +980,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev) channel->obint_enable_bits =USB2_OBINT_IDCHG_EN ;spin_lock_init (&channel->lock); +init_waitqueue_head (&channel->otg_init_done);for (i =0 ; i <NUM_OF_PHYS ; i++) { channel->rphys[i].phy =devm_phy_create (dev,NULL , phy_data->phy_usb2_ops);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 477/3318 Input: hp_sdc - shut down kicker timer on module exit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
[ Upstream commit 309731e95917125bbd13626a7a5600490a5bf44f ]
hp_sdc_kicker() rearms hp_sdc.kicker with mod_timer() after scheduling the tasklet. The module exit path uses timer_delete_sync(). That waits for a callback already running but can still leave the timer rearmed.
A callback can therefore leave the timer pending while hp_sdc_exit() tears down the driver, allowing timer activity to access dismantled driver state.
Use timer_shutdown_sync() for final teardown. It waits for a running callback and prevents rearming after module exit begins.
--- drivers/input/serio/hp_sdc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/serio/hp_sdc.c +1 -1
@@ -980,7 +980,7 @@ static void hp_sdc_exit(void)free_irq (hp_sdc.irq, &hp_sdc);write_unlock_irq (&hp_sdc.lock); -del_timer_sync (&hp_sdc.kicker); +timer_shutdown_sync (&hp_sdc.kicker);tasklet_kill (&hp_sdc.task);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 478/3318 wifi: mac80211: refuse to make a monitor active when it has no queue
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Devin Wittmayer <[email protected]>
[ Upstream commit 2b04d6556964ae9f89819b86a0a7801e39c3aae5 ]
A monitor interface only gets a TXQ if it's created active, and one can't be added later. Setting the flag on a down interface is still allowed, so the driver is handed a monitor with no queue. ath9k dereferences it:
BUG: kernel NULL pointer dereference, address: 0000000000000066 RIP: 0010:ath_tx_node_init+0x49/0x170 [ath9k] ath9k_add_interface+0x10c/0x140 [ath9k] drv_add_interface+0x54/0x250 [mac80211] ieee80211_do_open+0x32f/0x800 [mac80211]
Reached with CAP_NET_ADMIN by "iw dev X set monitor active" followed by "ip link set X up". RTNL is held, so netlink operations block behind it.
Refuse the flag when there is no queue to give.
--- net/mac80211/cfg.c | 4 ++++ 1 file changed, 4 insertions(+)
net/mac80211/cfg.c +4 -0
@@ -104,6 +104,10 @@ static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata,return -EBUSY ; } +/* TXQs are reserved in ieee80211_if_add() and cannot be added later */ +if ((params->flags &MONITOR_FLAG_ACTIVE ) && !sdata->vif.txq) +return -EOPNOTSUPP ; +/* also validate MU-MIMO change */ monitor_sdata =wiphy_dereference (local->hw.wiphy, local->monitor_sdata);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 479/3318 smb: client: fix unaligned access in WSL reparse point parser
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit e1aeaf79dea51e6065da56924bc07e22d59012ac ]
When wsl_to_fattr() parses WSL extended attributes, it computes a payload pointer from ea->ea_data + ea_name_length + 1. Since the smb2_file_full_ea_info struct is __packed and all WSL xattr names are 6 bytes long, the value pointer always lands at an odd byte offset, never satisfying __le32 or __le64 alignment requirements.
The code then casts this pointer to __le32 * or __le64 * and dereferences it directly, which may cause alignment faults on some architectures.
Replace all such casts with get_unaligned_le32() and get_unaligned_le64() in reparse_mkdev(), wsl_make_kuid(), wsl_make_kgid() and wsl_to_fattr().
--- fs/smb/client/reparse.c | 4 ++-- fs/smb/client/reparse.h | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-)
fs/smb/client/reparse.c +2 -2
@@ -732,9 +732,9 @@ static bool wsl_to_fattr(struct cifs_open_info_data *data, fattr->cf_gid =wsl_make_kgid (cifs_sb, v); }else if (!strncmp (name,SMB2_WSL_XATTR_MODE , nlen)) {/* File type in reparse point tag and in xattr mode must match. */ -if (S_DT (fattr->cf_mode) !=S_DT (le32_to_cpu (*(__le32 *)v))) +if (S_DT (fattr->cf_mode) !=S_DT (get_unaligned_le32 (v)))return false; - fattr->cf_mode = (umode_t )le32_to_cpu (*(__le32 *)v); + fattr->cf_mode = (umode_t )get_unaligned_le32 (v); }else if (!strncmp (name,SMB2_WSL_XATTR_DEV , nlen)) { fattr->cf_rdev =reparse_mkdev (v); have_xattr_dev = true;
fs/smb/client/reparse.h +4 -3
@@ -9,6 +9,7 @@#include <linux/fs.h> #include <linux/stat.h> #include <linux/uidgid.h> +#include <asm/unaligned.h> #include "fs_context.h" #include "cifsglob.h"
@@ -22,7 +23,7 @@static inline dev_t reparse_mkdev (void *ptr) { -u64 v =le64_to_cpu (*(__le64 *)ptr); +u64 v =get_unaligned_le64 (ptr);return MKDEV (v &0xffffffff , v >>32 ); }
@@ -30,7 +31,7 @@ static inline dev_t reparse_mkdev(void *ptr)static inline kuid_t wsl_make_kuid (struct cifs_sb_info *cifs_sb,void *ptr) { -u32 uid =le32_to_cpu (*(__le32 *)ptr); +u32 uid =get_unaligned_le32 (ptr);if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_OVERR_UID )return cifs_sb->ctx->linux_uid;
@@ -40,7 +41,7 @@ static inline kuid_t wsl_make_kuid(struct cifs_sb_info *cifs_sb,static inline kgid_t wsl_make_kgid (struct cifs_sb_info *cifs_sb,void *ptr) { -u32 gid =le32_to_cpu (*(__le32 *)ptr); +u32 gid =get_unaligned_le32 (ptr);if (cifs_sb->mnt_cifs_flags &CIFS_MOUNT_OVERR_GID )return cifs_sb->ctx->linux_gid;
Signature · 1 line
2.53.0