6.6.163-rc1 review
Subsystems (6)
Greg Kroah-Hartman
maintainerPATCH 2884/3318 Bluetooth: Add missing newline to bt_dev_{err,warn}_ratelimited()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hitalo Souza <[email protected]>
[ Upstream commit f51ee3bb5fbe9c2019c31befe330bddd3aee39c2 ]
bt_dev_err_ratelimited() and bt_dev_warn_ratelimited() pass the format string to bt_err_ratelimited()/bt_warn_ratelimited() without appending a newline, unlike bt_dev_err() and bt_dev_warn(), which go through BT_ERR()/BT_WARN() and add one. Only 2 of the 22 in-tree callers (both in virtio_bt) put the newline in their own format string.
A printk record without a trailing newline is stored with prb_commit() instead of prb_final_commit(), and readers of the log buffer (/dev/kmsg, syslog) do not see it until it is finalized, which only happens when the next record is reserved. These messages therefore stay invisible until some unrelated message is printed, and journald, which timestamps a record when it reads it, logs them with the time of that later message.
This was observed with a MediaTek MT7921 controller (USB 04ca:3802):
when an eSCO link is closed, the host still receives a few SCO packets for the handle after Disconnection Complete, so hci_scodata_packet() logs "SCO packet for unknown connection handle". Comparing the record's kernel timestamp (_SOURCE_MONOTONIC_TIMESTAMP) with the time journald received it, over one capture:
emitted logged delay 15:36:52.896 15:37:00.214 7.3 s 15:37:03.410 15:39:05.574 122.2 s 15:39:05.574 15:39:12.506 6.9 s 15:39:19.791 15:40:54.109 94.3 s 15:41:22.021 15:41:24.647 2.6 s
Each message showed up together with the next kernel message; the 94 s one looked as if it had been logged in the middle of a later, healthy eSCO connection.
bt_dev_err_ratelimited() lost its newline in commit 657cc646475b ("Bluetooth: Remove usage of BT_ERR_RATELIMITED macro"), which replaced BT_ERR_RATELIMITED(), the variant that appended "\n", with a direct call to bt_err_ratelimited(). bt_dev_warn_ratelimited() never had one.
Append the newline in both macros, as BT_ERR() and BT_WARN() do, and drop it from the two virtio_bt format strings so that their messages do not gain an empty line.
--- drivers/bluetooth/virtio_bt.c | 4 ++-- include/net/bluetooth/bluetooth.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/bluetooth/virtio_bt.c +2 -2
@@ -228,7 +228,7 @@ static void virtbt_rx_handle(struct virtio_bluetooth *vbt, struct sk_buff *skb)if (skb->len < min_hdr) {bt_dev_err_ratelimited (vbt->hdev, -"rx pkt_type 0x%02x payload %u < hdr %zu\n" , +"rx pkt_type 0x%02x payload %u < hdr %zu" , pkt_type, skb->len, min_hdr);kfree_skb (skb);return ;
@@ -251,7 +251,7 @@ static void virtbt_rx_work(struct work_struct *work)if (!len || len >VIRTBT_RX_BUF_SIZE ) {bt_dev_err_ratelimited (vbt->hdev, -"rx reply len %u outside [1, %u]\n" , +"rx reply len %u outside [1, %u]" , len,VIRTBT_RX_BUF_SIZE );kfree_skb (skb); }else {
include/net/bluetooth/bluetooth.h +2 -2
@@ -281,9 +281,9 @@ void bt_err_ratelimited(const char *fmt, ...); BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)#define bt_dev_warn_ratelimited (hdev, fmt, ...) \ - bt_warn_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) + bt_warn_ratelimited("%s: " fmt "\n", bt_dev_name(hdev), ##__VA_ARGS__)#define bt_dev_err_ratelimited (hdev, fmt, ...) \ - bt_err_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__) + bt_err_ratelimited("%s: " fmt "\n", bt_dev_name(hdev), ##__VA_ARGS__)/* Connection and socket states */ enum {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2885/3318 Bluetooth: hci_core: Keep RCU protection through LTK filtering
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 817cbcab91fe870e5b69c835cbd708242c9f8c8e ]
The LTK selected by hci_find_ltk() must remain allocated while its value is checked against the blocked-key list. The finder releases RCU before passing k->val to hci_is_blocked_key(). The helper's own RCU section protects the blocked-key list, but the selected LTK may already have been reclaimed before that section starts.
An LE ATT socket security request can reach smp_ltk_encrypt() without holding hdev->lock. With a matching stored LTK and an LTK-type blocked-key entry present, a concurrent MGMT_OP_LOAD_LONG_TERM_KEYS can remove the selected LTK in the following order:
Socket security Management / RCU reclamation
hci_find_ltk()
rcu_read_lock()
select k
rcu_read_unlock()
load_long_term_keys()
hci_dev_lock(hdev)
hci_smp_ltks_clear(hdev)
list_del_rcu(&k->list)
kfree_rcu(k, rcu)
grace period ends; k is freed
hci_is_blocked_key(..., k->val)
memcmp(b->val, val, ...)The final comparison reads freed LTK bytes. Entering a new RCU section in hci_is_blocked_key() cannot protect a pointer obtained before the completed grace period.
Keep the finder's RCU read-side section active through the blocked-key comparison and the warning that reads k->bdaddr. Release it before returning on either matched-key path. This delays reclamation until the finder has finished using the selected record, following the existing IRK lookup pattern.
KFENCE report as below:
==================================================================
BUG: KFENCE: use-after-free read in hci_is_blocked_key+0xdf/0x240
Use-after-free read at 0x00000000b9ee38e4 (in kfence-#249):
hci_is_blocked_key+0xdf/0x240
blocked_key_wrapper+0xc5/0x140 [pmbd_ltk_probe]
hci_find_ltk+0x1aa/0x3e0
smp_ltk_encrypt.isra.0+0xad/0x340
smp_conn_security+0x3b8/0x8c0
l2cap_sock_setsockopt+0x1c4b/0x2270
do_sock_setsockopt+0x1fb/0x430
__sys_setsockopt+0x106/0x180
__x64_sys_setsockopt+0xc2/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
kfence-#249: 0x00000000121f2ad9-0x000000005b5bfb3d, size=72, cache=kmalloc-96
allocated by task 495 on cpu 0 at 36.722380s (2.603973s ago):
hci_add_ltk+0x1f5/0x3a0
load_long_term_keys+0x6d0/0x860
hci_sock_sendmsg+0x128b/0x22e0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
freed by task 533 on cpu 0 at 36.993097s (2.339769s ago):
__rcu_free_sheaf_prepare+0x261/0x2a0
rcu_free_sheaf+0x1f/0xe0
rcu_core+0x661/0x1d10
handle_softirqs+0x201/0x930
__irq_exit_rcu+0x110/0x1e0
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x6c/0x80
asm_sysvec_apic_timer_interrupt+0x1a/0x20
srso_alias_return_thunk+0x0/0xfbef5
__asan_memcpy+0x23/0x60
create_monitor_ctrl_event+0x1a2/0x460
mgmt_cmd_complete+0x2da/0x580
load_long_term_keys+0x741/0x860
hci_sock_sendmsg+0x128b/0x22e0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
CPU: 1 UID: 0 PID: 495 Comm: python3 Tainted: G O 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy)
Tainted: [O]=OOT_MODULE
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
==================================================================--- net/bluetooth/hci_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/bluetooth/hci_core.c +2 -2
@@ -1183,16 +1183,16 @@ struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,continue ;if (smp_ltk_is_sc (k) ||ltk_role (k->type) == role) { -rcu_read_unlock (); -if (hci_is_blocked_key (hdev,HCI_BLOCKED_KEY_TYPE_LTK , k->val)) {bt_dev_warn_ratelimited (hdev,"LTK blocked for %pMR" , &k->bdaddr); +rcu_read_unlock ();return NULL ; } +rcu_read_unlock ();return k; } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2886/3318 Bluetooth: hci_sync: Serialize devcoredump reset during device open
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 6d91353f6dbcc5c4fbb47bbd0c7f885453cfc939 ]
An ACTIVE devcoredump's buffer cursors must remain valid from the packet handler's state check through its copy. hci_devcd_rx() holds hdev->lock across that interval, and hci_devcd_reset() requires the same lock. However, hci_dev_open_sync() invokes reset without taking it.
A registered VHCI controller can collect a dump through its debugfs interface while the controller is down. If a successful open overlaps with handling a nonempty dump packet, reset can run after the receiver's ACTIVE check and before its copy:
hci_devcd_rx() hci_dev_open_sync()
dequeue nonempty skb
hci_dev_lock(hdev)
handler observes ACTIVE
hdev->open(hdev) succeeds hci_devcd_reset(hdev)
dump.tail = NULL dump.state = IDLE
hci_devcd_copy()
compare against old dump.end
memcpy(NULL, ..., skb->len)
hci_dev_unlock(hdev)
Reset leaves dump.end pointing at the old buffer and purges only queued packets, so it cannot discard the skb already dequeued by the receiver. The bounds check can pass with a NULL tail, leading to a nonempty copy to address zero. KASAN reported a 24-byte NULL write in hci_devcd_rx().
Take hdev->lock around the open-time reset. The receiver then finishes its state check and copy using valid cursors before reset, or observes IDLE after reset and skips the copy.
KASAN report as below:
BUG: KASAN: null-ptr-deref in hci_devcd_rx+0x5d5/0x1a80
Write of size 24 at addr 0000000000000000 by task kworker/u17:0/496
CPU: 0 UID: 0 PID: 496 Comm: kworker/u17:0 Not tainted
7.2.0-rc6-pmb-bt-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: hci0 hci_devcd_rx
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
kasan_report+0xe0/0x110
? hci_devcd_rx+0x5d5/0x1a80
kasan_check_range+0x105/0x1b0
__asan_memcpy+0x3c/0x60
hci_devcd_rx+0x5d5/0x1a80
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_hci_devcd_rx+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/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/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
==================================================================
Disabling lock debugging due to kernel taint--- net/bluetooth/hci_sync.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_sync.c +2 -0
@@ -5287,7 +5287,9 @@ int hci_dev_open_sync(struct hci_dev *hdev) goto done; } +hci_dev_lock (hdev);hci_devcd_reset (hdev); +hci_dev_unlock (hdev);set_bit (HCI_RUNNING , &hdev->flags);hci_sock_dev_event (hdev,HCI_DEV_OPEN );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2887/3318 Bluetooth: ISO: Hold the listener during disconnect notification
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 b4a00dedc5cc6f6f98c07ec1b54d24a817d9fc88 ]
An ISO listener must remain alive until a queued child's disconnect notification completes. bt_accept_enqueue() retains only the child and stores a raw parent pointer; iso_conn_ready() drops its temporary listener reference after setup. iso_chan_del() saves that pointer, unlinks the child and then calls parent->sk_data_ready() without holding a listener reference.
With an incoming CIS child still queued, disconnect and listener release can proceed in this order:
HCI disconnect Listener release
iso_conn_del(): lock child
iso_chan_del(): save parent bt_accept_unlink(child)
iso_sock_cleanup_listen():
drain empty accept queue
iso_sock_release():
orphan and kill listener final sock_put(listener)
parent->sk_data_ready(parent)
After unlink, listener cleanup no longer has to take the child socket lock. The listener can therefore be freed before iso_chan_del() reads sk_data_ready, causing a use-after-free.
Take a temporary parent reference before bt_accept_unlink() and drop it after the notification. The child lock excludes accept dequeue while the child is still queued, so listener cleanup cannot complete before sock_hold(). The reference then keeps the listener alive across unlink and through the callback without changing lock order.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in iso_chan_del+0x302/0x320
Read of size 8 at addr ffff888105ca2188 by task kworker/2:1/50
CPU: 2 UID: 0 PID: 50 Comm: kworker/2:1 Not tainted
7.2.0-rc6-pmb-bt-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 iso_fixture_disconnect_work
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? iso_chan_del+0x302/0x320
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? iso_chan_del+0x302/0x320
kasan_report+0xe0/0x110
? iso_chan_del+0x302/0x320
iso_chan_del+0x302/0x320
iso_conn_del+0x19d/0x3c0
? __pfx_iso_disconn_cfm+0x10/0x10
iso_disconn_cfm+0x78/0x120
hci_disconn_complete_evt+0x319/0xa30
? find_held_lock+0x2b/0x80
hci_test_iso_disconn_event+0x85/0xb0
? __pfx_hci_test_iso_disconn_event+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? _raw_read_unlock+0x23/0x40
? srso_alias_return_thunk+0x5/0xfbef5
? __hci_dev_get+0x15d/0x280
iso_fixture_disconnect_work+0x67/0x290
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? srso_alias_return_thunk+0x5/0xfbef5
? __kthread_parkme+0x175/0x220
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/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/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 521:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_noprof+0x2d7/0x770
sk_prot_alloc+0x13e/0x260
sk_alloc+0x37/0xb40
bt_sock_alloc+0x40/0x3b0
iso_sock_alloc.constprop.0+0x3a/0x360
iso_sock_create+0xc7/0x160
bt_sock_create+0x171/0x330
__sock_create+0x2c4/0x730
__sys_socket+0x141/0x210
__x64_sys_socket+0x77/0xc0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 521:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
__sk_destruct+0x64f/0x790
sk_destruct+0xb3/0xd0
__sk_free+0xdd/0x370
sk_free+0x51/0x80
iso_sock_release+0x46d/0x5b0
__sock_release+0xb8/0x270
sock_close+0x21/0x30
__fput+0x39f/0xa60
task_work_run+0x144/0x230
do_exit+0x834/0x2830
do_group_exit+0xc7/0x280
get_signal+0x20a9/0x2400
arch_do_signal_or_restart+0x94/0x6f0
exit_to_user_mode_loop+0xcf/0x570
do_syscall_64+0x4f0/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888105ca2000
which
belongs to the cache kmalloc-2k of size
2048
The buggy address is located 392 bytes inside of
freed
2048-byte region [ffff888105ca2000,
ffff888105ca2800)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000
index:0xffff888105ca5000 pfn:0x105ca0
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000240(workingset|head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000240 ffff888100042f00 ffffea00042cd010
ffffea00042c9210
raw: ffff888105ca5000 0000000000080005 00000000f5000000
0000000000000000
head: 0200000000000240 ffff888100042f00 ffffea00042cd010
ffffea00042c9210
head: ffff888105ca5000 0000000000080005 00000000f5000000
0000000000000000
head: 0200000000000003 fffffffffffffe01 00000000ffffffff
00000000ffffffff
head: ffff888105ca1000 0000000000000000 00000000ffffffff
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888105ca2080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888105ca2100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888105ca2180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888105ca2200: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888105ca2280: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================--- net/bluetooth/iso.c | 3 +++ 1 file changed, 3 insertions(+)
net/bluetooth/iso.c +3 -0
@@ -196,8 +196,11 @@ static void iso_chan_del(struct sock *sk, int err) parent =bt_sk (sk)->parent;if (parent) { +/* Unlinking the child allows the parent to be freed. */ +sock_hold (parent);bt_accept_unlink (sk); parent->sk_data_ready (parent); +sock_put (parent); }else { sk->sk_state_change (sk); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2888/3318 Bluetooth: MGMT: Reject quality report requests during unregister
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 213e7a99bea19e2f29f394321b86c792eec73a24 ]
A quality report request must not call a driver callback after its module text has been released. hci_mgmt_cmd() holds an hci_dev reference through set_exp_feature(), but that reference only preserves the device allocation. set_quality_report_func() takes req_lock and invokes hdev->set_quality_report without checking HCI_UNREGISTER.
This is unsafe when a SET_EXP_FEATURE request for an Intel controller would change HCI_QUALITY_REPORT and is delayed before taking req_lock while the controller is removed. With btintel_pcie and btintel built as modules and no other btintel dependents, the following order is possible:
Management request Removal and module unload
------------------ -------------------------
hci_mgmt_cmd(): retain hdev
hci_unregister_dev():
set HCI_UNREGISTER remove hdev from lookup close under req_lock release req_lock
btintel_pcie_remove(): return unload btintel_pcie, then btintel
set_quality_report_func():
take req_lock
call hdev->set_quality_reportWhen the request resumes after btintel unload, the indirect call targets released module text and can cause an instruction-fetch page fault. The close operation serializes with a running callback but does not prevent a delayed management handler from invoking it afterwards.
Check HCI_UNREGISTER immediately after acquiring the existing req_lock and return MGMT_STATUS_INVALID_INDEX via the common unlock path. If unregister passed its close section first, the request now rejects the removed controller before accessing the callback. If the request passes the check first, hci_dev_do_close() must wait for req_lock until the callback has returned, so unregister cannot finish before the use.
Oops report as below:
BUG: unable to handle page fault for address: ffffffffc0408e10
#PF: supervisor instruction fetch in kernel mode
#PF: error_code(0x0010) - not-present page
PGD 80a9067 P4D 80a9067 PUD 80ab067 PMD 0
Oops: Oops: 0010 [#1] SMP KASAN NOPTI
CPU: 1 UID: 0 PID: 439 Comm: btmgmt Tainted: G O 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy)
Tainted: [O]=OOT_MODULE
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
RIP: 0010:0xffffffffc0408e10
Code: Unable to access opcode bytes at 0xffffffffc0408de6.
RSP: 0018:ffff888110927838 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 1ffff11022124f0c RCX: ffffffff85b1a1b6
RDX: ffff888117511d00 RSI: 0000000000000001 RDI: ffff888117598000
RBP: ffff888110927950 R08: 0000000000000001 R09: 0000000000000001
R10: ffffffff893d3057 R11: ffff888117511d00 R12: ffff888117598000
R13: 0000000000000001 R14: ffffffffc0408e10 R15: ffff888117599970
FS: 00007f15453f2040(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffc0408de6 CR3: 000000010b832005 CR4: 0000000000770ef0
PKRU: 55555554
Call Trace:
<TASK>
? set_quality_report_func+0x232/0x660
? __pfx_set_quality_report_func+0x10/0x10
? pmbd_gate_maybe+0x47/0x60
? srso_alias_return_thunk+0x5/0xfbef5
? pmbd_probe_hit_cookie+0xe7/0x1c0
? srso_alias_return_thunk+0x5/0xfbef5
? pmbd_probe_hit_cookie+0xee/0x1c0
set_exp_feature+0xf7/0x260
? set_exp_feature+0xf7/0x260
? hci_sock_sendmsg+0x12b2/0x2400
? __pfx_hci_sock_sendmsg+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? selinux_socket_sendmsg+0x160/0x280
? sock_write_iter+0x4c0/0x550
? __pfx_hci_sock_sendmsg+0x10/0x10
? __pfx_sock_write_iter+0x10/0x10
? __file_has_perm+0x25e/0x420
? __pfx___file_has_perm+0x10/0x10
? do_iter_readv_writev+0x59c/0x860
? __pfx_do_iter_readv_writev+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? security_file_permission+0x26/0x80
? vfs_writev+0x30e/0xc10
? __pfx_vfs_writev+0x10/0x10
? __pfx_do_epoll_wait+0x10/0x10
? __pfx_do_epoll_ctl+0x10/0x10
? do_writev+0x241/0x2f0
? srso_alias_return_thunk+0x5/0xfbef5
? do_writev+0x241/0x2f0
? __pfx_do_writev+0x10/0x10
? irqentry_exit+0xbe/0x820
? do_syscall_64+0x115/0x6a0
? entry_SYSCALL_64_after_hwframe+0x77/0x7f
</TASK>
Modules linked in: [last unloaded: btintel(O)]
CR2: ffffffffc0408e10
---[ end trace 0000000000000000 ]---
RIP: 0010:0xffffffffc0408e10
Code: Unable to access opcode bytes at 0xffffffffc0408de6.
RSP: 0018:ffff888110927838 EFLAGS: 00010293
RAX: 0000000000000000 RBX: 1ffff11022124f0c RCX: ffffffff85b1a1b6
RDX: ffff888117511d00 RSI: 0000000000000001 RDI: ffff888117598000
RBP: ffff888110927950 R08: 0000000000000001 R09: 0000000000000001
R10: ffffffff893d3057 R11: ffff888117511d00 R12: ffff888117598000
R13: 0000000000000001 R14: ffffffffc0408e10 R15: ffff888117599970
FS: 00007f15453f2040(0000) GS:ffff8881fd852000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: ffffffffc0408de6 CR3: 000000010b832005 CR4: 0000000000770ef0
PKRU: 55555554
Kernel panic - not syncing: Fatal exception
Kernel Offset: disabled
Rebooting in 1 seconds..--- net/bluetooth/mgmt.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/bluetooth/mgmt.c +7 -0
@@ -4917,6 +4917,13 @@ static int set_quality_report_func(struct sock *sk, struct hci_dev *hdev,hci_req_sync_lock (hdev); +if (hci_dev_test_flag (hdev,HCI_UNREGISTER )) { + err =mgmt_cmd_status (sk, hdev->id, +MGMT_OP_SET_EXP_FEATURE , +MGMT_STATUS_INVALID_INDEX ); + goto unlock_quality_report; + } + val = !!cp->param[0 ]; changed = (val !=hci_dev_test_flag (hdev,HCI_QUALITY_REPORT ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2889/3318 Bluetooth: msft: Lock failed probe cleanup against feature readers
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 21895f20fedc4504474bcb1022850b532ea4358e ]
The MSFT data must remain allocated while msft_get_features() reads its features. read_adv_mon_features() protects that access with hdev->lock, but msft_do_open() clears hdev->msft_data and frees the object without that lock when read_supported_features() fails.
After a successful probe, the data survives a normal close. A later open can fail the probe while a management feature request is running. hci_mgmt_cmd() permits requests during HCI_INIT, and the opener's hdev->req_lock does not serialize the management reader:
Management feature request HCI open
hold hdev->req_lock
msft_do_open()
hold hdev->lock
msft_get_features(): save msft
read_supported_features() fails
hdev->msft_data = NULL
kfree(msft) read msft->features
release hdev->lock release hdev->req_lock
The saved pointer then refers to freed memory, causing a use-after-free read. Advertisement reporting through mgmt_device_found() also reads the features with hdev->lock held.
Take hdev->lock around clearing and freeing msft_data in the failure branch. An existing feature reader finishes before the free, while a reader starting after cleanup sees NULL. Keep the synchronous probe outside this critical section, following the existing req_lock to hdev->lock ordering.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in msft_monitor_supported+0xa9/0xb0
Read of size 8 at addr ffff88811573ee00 by task mgmt-read-adv-m/532
CPU: 2 UID: 0 PID: 532 Comm: mgmt-read-adv-m Not tainted
7.2.0-rc6-pmb-bt-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
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? msft_monitor_supported+0xa9/0xb0
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? msft_monitor_supported+0xa9/0xb0
kasan_report+0xe0/0x110
? msft_monitor_supported+0xa9/0xb0
msft_monitor_supported+0xa9/0xb0
read_adv_mon_features+0xdf/0x640
? trace_hardirqs_on+0x18/0x160
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_read_adv_mon_features+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? do_raw_read_unlock+0x49/0xe0
? srso_alias_return_thunk+0x5/0xfbef5
? _raw_read_unlock+0x23/0x40
hci_sock_sendmsg+0x12b5/0x2270
? __pfx_hci_sock_sendmsg+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? selinux_socket_sendmsg+0x160/0x280
__sys_sendto+0x425/0x470
? __pfx_hci_sock_sendmsg+0x10/0x10
? __pfx___sys_sendto+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? __sys_setsockopt+0x119/0x180
__x64_sys_sendto+0xe5/0x1c0
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f9ceb04a687
Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48
83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b>
c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffe6ab96a70 EFLAGS: 00000202 ORIG_RAX: 000000000000002c
RAX: ffffffffffffffda RBX: 00007f9ceafb8780 RCX: 00007f9ceb04a687
RDX: 0000000000000006 RSI: 00007ffe6ab96aea RDI: 0000000000000003
RBP: 0000000000000002 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000003
R13: 00007ffe6ab96d50 R14: 00007f9ceb1f6000 R15: 00005625e427dd68
</TASK>
Allocated by task 506:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
msft_register+0x54/0x260
hci_register_dev+0x6b7/0xc80
__vhci_create_device+0x330/0x840
vhci_write+0x287/0x440
vfs_write+0x637/0x1010
ksys_write+0x111/0x200
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 529:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
msft_do_open+0x604/0x9e0
hci_dev_open_sync+0x94a/0x2110
hci_dev_do_open+0x2f/0xb0
hci_dev_open+0x17d/0x300
hci_sock_ioctl+0x3c6/0x710
sock_do_ioctl+0x120/0x2b0
sock_ioctl+0x41b/0x670
__x64_sys_ioctl+0x163/0x1d0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff88811573ee00
which belongs to the cache kmalloc-256 of size 256
The buggy address is located 0 bytes inside of
freed 256-byte region [ffff88811573ee00, ffff88811573ef00)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0
pfn:0x11573e
head: order:1 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff888100042b40 dead000000000100
dead000000000122
raw: 0000000000000000 0000000000100010 00000000f5000000
0000000000000000
head: 0200000000000040 ffff888100042b40 dead000000000100
dead000000000122
head: 0000000000000000 0000000000100010 00000000f5000000
0000000000000000
head: 0200000000000001 ffffffffffffff81 00000000ffffffff
00000000ffffffff
head: 0000000000000000 0000000000000000 00000000ffffffff
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88811573ed00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88811573ed80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88811573ee00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88811573ee80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88811573ef00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================--- net/bluetooth/msft.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/msft.c +2 -0
@@ -655,8 +655,10 @@ void msft_do_open(struct hci_dev *hdev) msft->features =0 ;if (!read_supported_features (hdev, msft)) { +hci_dev_lock (hdev); hdev->msft_data =NULL ;kfree (msft); +hci_dev_unlock (hdev);return ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2890/3318 Bluetooth: 6lowpan: Drain RCU readers on registration failure
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 ebba800d140b580540ad55f670d943e4a7edaffd ]
A lowpan_btle_dev is embedded in its net_device allocation and must remain alive until readers of bt_6lowpan_devices have left their RCU sections. setup_netdev() publishes it before registration, but its error path only unlinks it before calling free_netdev().
If a second controller's registration fails while multicast is sent on an existing 6LoWPAN interface, send_mcast_pkt() can already have selected the new entry. It reads entry->netdev before checking which interface owns it. An early failure, such as allocating the device's name node, leaves NETREG_UNINITIALIZED, so free_netdev() releases the storage immediately.
The following ordering frees the selected entry before the reader loads its netdev field:
Adapter creation (controller B) Multicast on controller A
setup_netdev()
list_add_rcu()
rcu_read_lock()
select B's entry
lowpan_register_netdev() fails
list_del_rcu()
free_netdev()
read entry->netdev
rcu_read_unlock()Removing the list node does not wait for that reader, and devices_lock does not serialize the multicast reader. The subsequent field load is a use-after-free, reported by KASAN in bt_xmit().
Wait for an RCU grace period after dropping devices_lock and before free_netdev(). This keeps the failed adapter allocated until traversals that could have selected it complete. The callback is already sleepable, and the wait happens outside the list spinlock.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in bt_xmit+0x1d06/0x21e0
Read of size 8 at addr ffff88810ef45030 by task python3/556
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? bt_xmit+0x1d06/0x21e0
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? bt_xmit+0x1d06/0x21e0
kasan_report+0xe0/0x110
? bt_xmit+0x1d06/0x21e0
bt_xmit+0x1d06/0x21e0
? __pfx_bt_xmit+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_acquire+0x17b/0x2f0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? dev_hard_start_xmit+0x187/0x660
? __pfx_bt_xmit+0x10/0x10
dev_hard_start_xmit+0x187/0x660
sch_direct_xmit+0x153/0x850
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_sch_direct_xmit+0x10/0x10
? do_raw_spin_lock+0x130/0x270
? __pfx_do_raw_spin_lock+0x10/0x10
? lock_is_held_type+0x8f/0x100
__dev_queue_xmit+0x3111/0x3aa0
? srso_alias_return_thunk+0x5/0xfbef5
? look_up_lock_class+0x59/0x130
? register_lock_class+0x41/0x790
? __pfx___dev_queue_xmit+0x10/0x10
? __lock_acquire+0x466/0x2260
? find_held_lock+0x2b/0x80
? ___neigh_create+0x1690/0x2540
? __local_bh_enable_ip+0xa6/0x120
? srso_alias_return_thunk+0x5/0xfbef5
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_acquire+0x17b/0x2f0
? srso_alias_return_thunk+0x5/0xfbef5
? find_held_lock+0x2b/0x80
? ip6_finish_output2+0x8be/0x1840
? srso_alias_return_thunk+0x5/0xfbef5
? neigh_connected_output+0x39f/0x4e0
? srso_alias_return_thunk+0x5/0xfbef5
neigh_connected_output+0x33f/0x4e0
ip6_finish_output2+0x8be/0x1840
ip6_finish_output+0x424/0xd50
ip6_output+0x210/0x640
? __pfx_ip6_mr_output+0x10/0x10
ip6_local_out+0x193/0x1c0
ip6_send_skb+0xfb/0x3e0
udp_v6_send_skb+0x6e1/0x1180
udpv6_sendmsg+0x1f9b/0x2a00
? get_random_u32+0xaf/0x640
? __pfx_udpv6_sendmsg+0x10/0x10
? lock_release+0xc8/0x280
? srso_alias_return_thunk+0x5/0xfbef5
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
? srso_alias_return_thunk+0x5/0xfbef5
? __local_bh_enable_ip+0xa6/0x120
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_udpv6_sendmsg+0x10/0x10
? inet6_sendmsg+0xff/0x140
inet6_sendmsg+0xff/0x140
__sys_sendto+0x320/0x470
? __pfx___sys_sendto+0x10/0x10
? exc_page_fault+0x5c/0xc0
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
? handle_mm_fault+0x12e/0x580
__x64_sys_sendto+0xe5/0x1c0
? lockdep_hardirqs_on_prepare+0xea/0x1a0
? srso_alias_return_thunk+0x5/0xfbef5
? trace_hardirqs_on+0x18/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Allocated by task 502:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kvmalloc_node_noprof+0x353/0x930
alloc_netdev_mqs+0xa0/0x1250
chan_ready_cb+0x198/0x1110
l2cap_recv_frame+0x6dc0/0x8830
l2cap_recv_acldata+0xe9f/0x10e0
hci_rx_work+0x5a6/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
Freed by task 502:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
free_netdev+0x6ca/0x8f0
chan_ready_cb+0xd91/0x1110
l2cap_recv_frame+0x6dc0/0x8830
l2cap_recv_acldata+0xe9f/0x10e0
hci_rx_work+0x5a6/0xf00
process_one_work+0x908/0x19c0
worker_thread+0x65c/0xe40
kthread+0x34f/0x460
ret_from_fork+0x659/0x940
ret_from_fork_asm+0x1a/0x30
The buggy address belongs to the object at ffff88810ef44000
which
belongs to the cache kmalloc-8k of size
8192
The buggy address is located 4144 bytes inside of
freed
8192-byte region [ffff88810ef44000,
ffff88810ef46000)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0
pfn:0x10ef40
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x200000000000040(head|node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000040 ffff888100043180 dead000000000100
dead000000000122
raw: 0000000000000000 0000000000020002 00000000f5000000
0000000000000000
head: 0200000000000040 ffff888100043180 dead000000000100
dead000000000122
head: 0000000000000000 0000000000020002 00000000f5000000
0000000000000000
head: 0200000000000003 fffffffffffffe01 00000000ffffffff
00000000ffffffff
head: ffff88810ef41a80 0000000000000000 00000000ffffffff
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88810ef44f00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810ef44f80: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88810ef45000: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88810ef45080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88810ef45100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
Disabling lock debugging due to kernel taint--- net/bluetooth/6lowpan.c | 1 + 1 file changed, 1 insertion(+)
net/bluetooth/6lowpan.c +1 -0
@@ -705,6 +705,7 @@ static int setup_netdev(struct l2cap_chan *chan, struct lowpan_btle_dev **dev)spin_lock (&devices_lock);list_del_rcu (&(*dev)->list);spin_unlock (&devices_lock); +synchronize_rcu ();free_netdev (netdev); goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2891/3318 Bluetooth: hci_sync: Protect IRK identity reads with RCU
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 4b76fa362110cf1b74a0263c14406b71de99894c ]
hci_le_set_privacy_mode_sync() needs the IRK returned by hci_find_irk_by_addr() to remain allocated until its identity address and type have been copied into the command. The finder drops its RCU read lock before returning this borrowed pointer, leaving the later field reads unprotected.
When a privacy-capable controller has a pending peer with address resolution and device privacy enabled, accept-list programming can reach this helper while management reloads the IRKs. The request worker holds hdev->req_lock, whereas load_irks() takes hdev->lock, allowing the following ordering:
Request worker Management / RCU reclaim
hci_le_set_privacy_mode_sync()
hci_find_irk_by_addr()
rcu_read_lock()
find matching IRK
rcu_read_unlock()
return borrowed IRK
load_irks()
hci_dev_lock(hdev)
hci_smp_irks_clear()
list_del_rcu()
kfree_rcu()
hci_dev_unlock(hdev)
RCU grace period and IRK free
read irk->addr_type
copy irk->bdaddrThe request then accesses a freed IRK. KASAN reports a one-byte use-after-free read of addr_type on this path.
Keep an outer RCU read-side critical section across the lookup and both identity-field copies. The finder's nested unlock then leaves the IRK protected until the caller finishes copying it. Release RCU on a lookup miss and after copying the fields, before the synchronous HCI command can sleep.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in
hci_le_add_accept_list_sync+0x90f/0x940
Read of size 1 at addr ffff88810aa6072c by task kworker/u17:0/493
Workqueue: hci0 hci_cmd_sync_work
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? hci_le_add_accept_list_sync+0x90f/0x940
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? hci_le_add_accept_list_sync+0x90f/0x940
kasan_report+0xe0/0x110
? hci_le_add_accept_list_sync+0x90f/0x940
hci_le_add_accept_list_sync+0x90f/0x940
? __pfx_hci_le_add_accept_list_sync+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? conn_params_copy+0x3a0/0x650
hci_passive_scan_sync+0x8c9/0x1e80
? __pfx_hci_passive_scan_sync+0x10/0x10
? find_held_lock+0x2b/0x80
? hci_lookup_le_connect+0x181/0x3c0
? srso_alias_return_thunk+0x5/0xfbef5
? find_held_lock+0x2b/0x80
? hci_update_passive_scan_sync+0x437/0x950
? srso_alias_return_thunk+0x5/0xfbef5
? lock_release+0xc8/0x280
hci_update_passive_scan_sync+0x461/0x950
hci_cmd_sync_work+0x1b3/0x450
? srso_alias_return_thunk+0x5/0xfbef5
process_one_work+0x908/0x19c0
? __pfx_process_one_work+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? lock_is_held_type+0x8f/0x100
? srso_alias_return_thunk+0x5/0xfbef5
worker_thread+0x65c/0xe40
? __pfx_worker_thread+0x10/0x10
kthread+0x34f/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/0xf80
? __pfx_kthread+0x10/0x10
ret_from_fork_asm+0x1a/0x30
</TASK>
Allocated by task 507:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
hci_add_irk+0xb6/0x220
load_irks+0x5ef/0x7e0
hci_sock_sendmsg+0x128b/0x22e0
__sys_sendto+0x425/0x470
__x64_sys_sendto+0xe5/0x1c0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 0:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
__rcu_free_sheaf_prepare+0x65/0x2a0
rcu_free_sheaf+0x1f/0xe0
rcu_core+0x661/0x1d10
handle_softirqs+0x201/0x930
__irq_exit_rcu+0x110/0x1e0
irq_exit_rcu+0xe/0x20
sysvec_apic_timer_interrupt+0x6c/0x80
asm_sysvec_apic_timer_interrupt+0x1a/0x20
The buggy address belongs to the object at ffff88810aa60700
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 44 bytes inside of
freed 64-byte region [ffff88810aa60700, ffff88810aa60740)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0
pfn:0x10aa60
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000428c0 dead000000000100
dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000
0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88810aa60600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810aa60680: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff88810aa60700: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff88810aa60780: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff88810aa60800: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================
Disabling lock debugging due to kernel taint--- net/bluetooth/hci_sync.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/bluetooth/hci_sync.c +7 -1
@@ -2619,13 +2619,19 @@ static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev,if (!(params->flags &HCI_CONN_FLAG_DEVICE_PRIVACY ))return 0 ; +rcu_read_lock (); + irk =hci_find_irk_by_addr (hdev, ¶ms->addr, params->addr_type); -if (!irk) +if (!irk) { +rcu_read_unlock ();return 0 ; + }memset (&cp,0 ,sizeof (cp)); cp.bdaddr_type = irk->addr_type;bacpy (&cp.bdaddr, &irk->bdaddr); +rcu_read_unlock (); + cp.mode =HCI_DEVICE_PRIVACY ;/* Note: params->privacy_mode is not updated since it is a copy */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2892/3318 Bluetooth: btintel: propagate version TLV parsing errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laxman Acharya Padhya <[email protected]>
[ Upstream commit 3a74624b5deae7f5e2b98e638687fbf9594a9781 ]
btintel_read_version_tlv() ignores the parser return value, so setup continues with partially initialized version data after a malformed TLV causes parsing to stop.
Return the parser error to the caller so an invalid response fails setup instead of being treated as successful. Keep this behavioral change separate from the bounds checks so it can be reverted independently if an existing controller sends malformed data.
Stable-dep-of: cf87709d7ff8 ("Bluetooth: btintel: Zero version data before parsing TLVs")
--- drivers/bluetooth/btintel.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/bluetooth/btintel.c +3 -2
@@ -693,6 +693,7 @@ static int btintel_read_version_tlv(struct hci_dev *hdev, {struct sk_buff *skb;const u8 param[1 ] = {0xFF }; +int err;if (!version)return -EINVAL ;
@@ -711,10 +712,10 @@ static int btintel_read_version_tlv(struct hci_dev *hdev,return -EIO ; } -btintel_parse_version_tlv (hdev, version, skb); + err =btintel_parse_version_tlv (hdev, version, skb);kfree_skb (skb); -return 0 ; +return err; }/* ------- REGMAP IBT SUPPORT ------- */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2893/3318 Bluetooth: btintel: Zero version data before parsing TLVs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kiran K <[email protected]>
[ Upstream commit cf87709d7ff83b4de5d42b61e4a9806fe374cb9d ]
Firmware may omit optional TLVs, leaving their corresponding fields unset in the caller-supplied struct intel_version_tlv. Since the structure is typically stack-allocated and not cleared beforehand, fields for which no TLV is received retain uninitialized stack memory. This stale data can be logged via btintel_version_info_tlv() and copied back to the caller, leaking kernel stack contents.
Clear the structure in btintel_read_version_tlv() before parsing so that fields with no corresponding TLV are deterministically zero instead of containing garbage.
--- drivers/bluetooth/btintel.c | 1 + 1 file changed, 1 insertion(+)
drivers/bluetooth/btintel.c +1 -0
@@ -712,6 +712,7 @@ static int btintel_read_version_tlv(struct hci_dev *hdev,return -EIO ; } +memset (version,0 ,sizeof (*version)); err =btintel_parse_version_tlv (hdev, version, skb);kfree_skb (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2894/3318 Bluetooth: MSFT: Serialize handle map cleanup with event processing
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 56e20c3d8ad340bbfc90221c4aae1c870485fb57 ]
MSFT monitor handle mappings must remain valid while vendor events look up and use them under hdev->lock. msft_do_close() removes and frees the mappings without that lock.
hci_dev_close_sync() clears HCI_UP and drains the RX workqueue before MSFT cleanup. However, a transport callback that already passed hci_recv_frame()'s state check can queue a vendor event after the drain returns, if no earlier shutdown callback has quiesced reception. The driver close callback runs after MSFT cleanup, so event processing can overlap the unlocked removal. msft_monitor_device_evt() can then traverse freed list entries or read handle_data->mgmt_handle after it is freed.
Take hdev->lock while resetting monitor states and removing handle mappings in msft_do_close(), as normal monitor cancellation already does. An active event reader then finishes before its mapping is freed, and later lookups see an empty handle map.
An instrumented kernel produced this KASAN report (timestamps removed and unrelated frames omitted):
BUG: KASAN: slab-use-after-free in msft_vendor_evt+0x1906/0x1990
Read of size 2 at addr ffff888104df3602 by task kworker/u17:2/502
Workqueue: hci0 hci_rx_work
Call Trace:
[...]
msft_vendor_evt+0x1906/0x1990
hci_vendor_evt+0x6f/0x90
hci_event_packet+0x894/0xc70
[...]
hci_rx_work+0x3f8/0xfa0
[...]
Allocated by task 499:
[...]
msft_add_monitor_sync+0x6a8/0x10a0
msft_add_monitor_pattern+0x7f/0xb0
hci_add_adv_monitor+0x1fa/0x2e0
[...]
Freed by task 499:
[...]
kfree+0x307/0x580
msft_do_close+0x238/0x750
hci_dev_close_sync+0x546/0x1380
[...]
The buggy address belongs to the object at ffff888104df3600
which belongs to the cache kmalloc-32 of size 32
The buggy address is located 2 bytes inside of
freed 32-byte region [ffff888104df3600, ffff888104df3620)
[...]--- net/bluetooth/msft.c | 4 ++++ 1 file changed, 4 insertions(+)
net/bluetooth/msft.c +4 -0
@@ -684,6 +684,8 @@ void msft_do_close(struct hci_dev *hdev)bt_dev_dbg (hdev,"Cleanup of MSFT extension" ); +hci_dev_lock (hdev); +/* The controller will silently remove all monitors on power off. * Therefore, remove handle_data mapping and reset monitor state. */
@@ -698,6 +700,8 @@ void msft_do_close(struct hci_dev *hdev)kfree (handle_data); } +hci_dev_unlock (hdev); +mutex_lock (&msft->filter_lock);list_for_each_entry_safe (address_filter, n, &msft->address_filters, list) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2895/3318 net: selftests: use skb_share_check() in the loopback receive hook
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit fbd3a301b1378423a5cfc23a42e3c0b04e26192c ]
The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_unshare() does not unshare it, so skb_linearize() on a non-linear frame hits BUG_ON(skb_shared()).
Use skb_share_check() instead.
--- net/core/selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/selftests.c +1 -1
@@ -190,7 +190,7 @@ static int net_test_loopback_validate(struct sk_buff *skb,struct tcphdr *thdr;struct iphdr *ihdr; - skb =skb_unshare (skb,GFP_ATOMIC ); + skb =skb_share_check (skb,GFP_ATOMIC );if (!skb) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2896/3318 net: stmmac: selftests: use skb_share_check() in the loopback receive hook
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit a7a89019bac0e8810bde7f1419f4adf9adc23d41 ]
The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_unshare() does not unshare it, so skb_linearize() on a non-linear frame hits BUG_ON(skb_shared()).
Use skb_share_check() instead.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -1
@@ -262,7 +262,7 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb,struct tcphdr *thdr;struct iphdr *ihdr; - skb =skb_unshare (skb,GFP_ATOMIC ); + skb =skb_share_check (skb,GFP_ATOMIC );if (!skb) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2897/3318 net/mlx5e: use skb_share_check() in the loopback selftest hook
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolai Buchwitz <[email protected]>
[ Upstream commit 16fb7aa6955a0af9f67ca42a61d9be58dfc9382a ]
The loopback hook gets a shared skb when another ETH_P_IP handler is bound to the device. skb_linearize() on a non-linear frame then hits BUG_ON(skb_shared()).
Call skb_share_check() before linearizing the skb.
--- drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/en_selftest.c +4 -0
@@ -165,6 +165,10 @@ mlx5e_test_loopback_validate(struct sk_buff *skb,struct udphdr *udph;struct iphdr *iph; + skb =skb_share_check (skb,GFP_ATOMIC ); +if (!skb) + goto out; +if (skb_linearize (skb)) goto out;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2898/3318 scsi: libsas: Fix out-of-bounds memcpy() in sas_ssp_task_response()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xingui Yang <[email protected]>
[ Upstream commit 4d7f9c3fdce773f6c69d17c1d4a05bd5e17f4b99 ]
The min_t(int, ...) clamp of the device-provided sense_data_len turns negative for values >= 0x80000000 and is then used as the memcpy() length, reading and writing out of bounds. Compare as u32 instead. Well-formed responses are unaffected.
--- drivers/scsi/libsas/sas_task.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/libsas/sas_task.c +1 -1
@@ -25,7 +25,7 @@ void sas_ssp_task_response(struct device *dev, struct sas_task *task,case SAS_DATAPRES_SENSE_DATA : tstat->stat =SAS_SAM_STAT_CHECK_CONDITION ; tstat->buf_valid_size = -min_t (int,SAS_STATUS_BUF_SIZE , +min_t (u32,SAS_STATUS_BUF_SIZE ,be32_to_cpu (iu->sense_data_len));memcpy (tstat->buf, iu->sense_data, tstat->buf_valid_size);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2899/3318 scsi: hisi_sas: Fix incorrect delay values from magic-number cleanup
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xingui Yang <[email protected]>
[ Upstream commit 7307109c92f702434669bfcd29fb8058ccc07b45 ]
Commit 4ca7fe99fc84 ("scsi: hisi_sas: Use macro instead of magic number") replaced several delay constants with a single macro of value
100. However, three sites originally used different values:
- reset_hw_v3_hw: udelay(50) -> udelay(100) [doubled]
- disable_phy_v3_hw: mdelay(50) -> mdelay(100) [doubled]
- disable_host_v3_hw: mdelay(10) -> mdelay(100) [10x longer]
The overly long delays on the PHY disable and host shutdown paths increase boot and shutdown time for all local PHYs.
Add separate macros for each delay to restore the original values while still avoiding magic numbers.
--- drivers/scsi/hisi_sas/hisi_sas_v3_hw.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/scsi/hisi_sas/hisi_sas_v3_hw.c +6 -3
@@ -546,6 +546,9 @@ struct hisi_sas_err_record_v3 {#define IRQ_AXI_INDEX 11#define DELAY_FOR_RESET_HW 100 +#define STOP_PHY_DELAY_US 50 +#define DISABLE_PHY_DELAY_MS 50 +#define DISABLE_HOST_PHY_DELAY_MS 10#define HDR_SG_MOD 0x2#define LUN_SIZE 8#define ATTR_PRIO_REGION 9
@@ -980,7 +983,7 @@ static int reset_hw_v3_hw(struct hisi_hba *hisi_hba)/* Disable all of the PHYs */ hisi_sas_stop_phys (hisi_hba); -udelay (HISI_SAS_DELAY_FOR_PHY_DISABLE ); +udelay (STOP_PHY_DELAY_US );/* Ensure axi bus idle */ ret = hisi_sas_read32_poll_timeout(AXI_CFG, val, !val,
@@ -1069,7 +1072,7 @@ static void disable_phy_v3_hw(struct hisi_hba *hisi_hba, int phy_no) cfg &= ~PHY_CFG_ENA_MSK ;hisi_sas_phy_write32 (hisi_hba, phy_no,PHY_CFG , cfg); -mdelay (HISI_SAS_DELAY_FOR_PHY_DISABLE ); +mdelay (DISABLE_PHY_DELAY_MS ); state =hisi_sas_read32 (hisi_hba,PHY_STATE );if (state &BIT (phy_no)) {
@@ -2757,7 +2760,7 @@ static int disable_host_v3_hw(struct hisi_hba *hisi_hba)hisi_sas_stop_phys (hisi_hba); -mdelay (HISI_SAS_DELAY_FOR_PHY_DISABLE ); +mdelay (DISABLE_HOST_PHY_DELAY_MS ); reg_val =hisi_sas_read32 (hisi_hba,AXI_MASTER_CFG_BASE +AM_CTRL_GLOBAL );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2900/3318 dt-bindings: vendor-prefixes: add Ambarella
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Long Zhao <[email protected]>
[ Upstream commit 5ef299ffb56531b3a4f2b311000da76beed403ee ]
Document the Ambarella, Inc. vendor prefix so Ambarella DT bindings can be applied without waiting for the SoC series.
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -95,6 +95,8 @@ patternProperties: description: Amarula Solutions "^amazon,.*": description: Amazon.com, Inc. + "^ambarella,.*": + description: Ambarella, Inc. "^amcc,.*": description: Applied Micro Circuits Corporation (APM, formally AMCC) "^amd,.*":
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2901/3318 ata: libahci: re-enable FBS after error handling on a port multiplier
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kyrylo Biryuk <[email protected]>
[ Upstream commit 23eab9e877497397a0e2394ee9174d576816209e ]
ahci_do_softreset() disables FBS before resetting a device behind a port multiplier, as required by AHCI 1.2 section 9.3.9, and re-enables it only when that softreset succeeds. If it fails, for example because a hot-plugged drive is still spinning up ("softreset failed (device not ready)"), EH escalates to a hardreset of the PMP link, and nothing turns FBS back on: only ahci_pmp_attach() does, which runs at the next boot. The port keeps working with command-based switching until then.
Seen on a Marvell 88SE9235 (1b4b:9235) with Marvell 88SM9705 port multipliers (1b4b:9705, in a Synology DX1222 expansion unit): after hot-plugging a drive, the kernel logged "FBS is disabled" followed by "softreset failed (device not ready)" and a PMP hardreset, and never "FBS is enabled" again (twice, on two different ports).
At the end of ahci_error_handler(), re-enable FBS if a PMP is still attached and FBS is supported but disabled.
--- drivers/ata/libahci.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/ata/libahci.c +15 -0
@@ -2238,6 +2238,21 @@ void ahci_error_handler(struct ata_port *ap)sata_pmp_error_handler (ap); +/* +* ahci_do_softreset() turns FBS off before resetting a fan-out link +* and turns it back on only if that reset succeeds. When it fails +* (e.g. a hot-plugged drive is still spinning up), EH escalates to a +* PMP hardreset, which never re-enables FBS, so the port would keep +* command-based switching until the PMP is attached again (reboot). +* Restore FBS once recovery is done and the PMP is still attached. +*/ +if (sata_pmp_attached (ap) &&ata_dev_enabled (ap->link.device)) { +struct ahci_port_priv *pp = ap->private_data; + +if (pp->fbs_supported && !pp->fbs_enabled) +ahci_enable_fbs (ap); + } +if (!ata_dev_enabled (ap->link.device)) hpriv->stop_engine (ap); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2902/3318 net: axienet: free outstanding TX buffers in axienet_dma_bd_release()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sagi Maimon <[email protected]>
[ Upstream commit 0c20cb4cfb40cf270d6c4c2c2ff5e5d72322644a ]
axienet_dma_bd_release() walks the RX ring to unmap and free every receive buffer before releasing it, but frees the TX descriptor ring with dma_free_coherent() alone. Any descriptor that axienet_free_tx_chain() had not yet reclaimed still holds its skb and its streaming DMA mapping, and both are lost.
axienet_stop() disables TX NAPI and stops the DMA engine before calling it, so nothing reclaims those descriptors afterwards. Bringing the interface down while frames are in flight therefore leaks up to lp->tx_bd_num skbs and mappings each time.
axienet_dma_err_handler() already walks the TX ring this way before it restarts the DMA engine: it unmaps every descriptor whose cntrl is still set - axienet_free_tx_chain() clears it on reclaim - frees any skb still attached, and clears the descriptor. Move that loop into a helper, axienet_free_tx_bufs(), and call it from axienet_dma_bd_release() too. This relies on axienet_stop() having stopped the DMA engine first, as the RX walk in the same function already does. The helper frees the skbs with dev_kfree_skb_any(), as drops: in the error handler, which runs from a workqueue, that frees them directly rather than deferring them to softirq as dev_kfree_skb_irq() did.
The walk must not run on a ring that is not there. axienet_open() does not check the result of the reset that runs axienet_dma_bd_init(), so when that reset fails tx_bd_v is either still NULL or, after an earlier close, points at the ring that close freed. Clear tx_bd_v and rx_bd_v once their rings are freed, and skip the walk when tx_bd_v is NULL. That also ends the second dma_free_coherent() of a stale ring which the same path already did. On the axienet_dma_bd_init() error path the TX ring has just been allocated zeroed, so the walk does nothing.
This was reported by the Sashiko AI review bot.
Tested on the AXI Ethernet MAC of an ADVA TimeCard X2 (PCIe card, with the built-in AXI DMA): traffic passes, and after each of ten down/up cycles and five module reloads, all made with traffic running and each running axienet_dma_bd_release(), traffic resumes and nothing is logged. The leak itself was not measured, and neither the failed-reset paths nor axienet_dma_err_handler() were exercised.
--- .../net/ethernet/xilinx/xilinx_axienet_main.c | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +50 -24
@@ -153,6 +153,46 @@ static dma_addr_t desc_get_phys_addr(struct axienet_local *lp,return ret; } +/** +* axienet_free_tx_bufs - Release the buffers still held by the TX ring +* @lp: Pointer to the axienet_local structure +* +* Unmap every descriptor whose mapping is still live, free any skb still +* attached, and clear the descriptor for reuse. axienet_free_tx_chain() +* clears cntrl when it reclaims a descriptor, so a non-zero value means +* the mapping is live. The DMA engine must be stopped. +*/ +static void axienet_free_tx_bufs (struct axienet_local *lp) +{ +struct axidma_bd *cur_p; +u32 i; + +for (i =0 ; i < lp->tx_bd_num; i++) { + cur_p = &lp->tx_bd_v[i]; +if (cur_p->cntrl) { +dma_addr_t addr =desc_get_phys_addr (lp, cur_p); + +dma_unmap_single (lp->dev, addr, + (cur_p->cntrl & +XAXIDMA_BD_CTRL_LENGTH_MASK ), +DMA_TO_DEVICE ); + } +/* not reclaimed by axienet_free_tx_chain(), so a drop */ +if (cur_p->skb) +dev_kfree_skb_any (cur_p->skb); + cur_p->phys =0 ; + cur_p->phys_msb =0 ; + cur_p->cntrl =0 ; + cur_p->status =0 ; + cur_p->app0 =0 ; + cur_p->app1 =0 ; + cur_p->app2 =0 ; + cur_p->app3 =0 ; + cur_p->app4 =0 ; + cur_p->skb =NULL ; + } +} +/** * axienet_dma_bd_release - Release buffer descriptor rings * @ndev: Pointer to the net_device structure
@@ -166,11 +206,18 @@ static void axienet_dma_bd_release(struct net_device *ndev)int i;struct axienet_local *lp =netdev_priv (ndev); -/* If we end up here, tx_bd_v must have been DMA allocated. */ +/* tx_bd_v is NULL if axienet_dma_bd_init() did not get as far as +* allocating it, and is cleared below once the ring is freed; +* dma_free_coherent() accepts NULL. +*/ +if (lp->tx_bd_v) +axienet_free_tx_bufs (lp); +dma_free_coherent (lp->dev,sizeof (*lp->tx_bd_v) * lp->tx_bd_num, lp->tx_bd_v, lp->tx_bd_p); + lp->tx_bd_v =NULL ;if (!lp->rx_bd_v)return ;
@@ -201,6 +248,7 @@ static void axienet_dma_bd_release(struct net_device *ndev)sizeof (*lp->rx_bd_v) * lp->rx_bd_num, lp->rx_bd_v, lp->rx_bd_p); + lp->rx_bd_v =NULL ; }/**
@@ -1792,29 +1840,7 @@ static void axienet_dma_err_handler(struct work_struct *work)axienet_dma_stop (lp); -for (i =0 ; i < lp->tx_bd_num; i++) { - cur_p = &lp->tx_bd_v[i]; -if (cur_p->cntrl) { -dma_addr_t addr =desc_get_phys_addr (lp, cur_p); - -dma_unmap_single (lp->dev, addr, - (cur_p->cntrl & -XAXIDMA_BD_CTRL_LENGTH_MASK ), -DMA_TO_DEVICE ); - } -if (cur_p->skb) -dev_kfree_skb_irq (cur_p->skb); - cur_p->phys =0 ; - cur_p->phys_msb =0 ; - cur_p->cntrl =0 ; - cur_p->status =0 ; - cur_p->app0 =0 ; - cur_p->app1 =0 ; - cur_p->app2 =0 ; - cur_p->app3 =0 ; - cur_p->app4 =0 ; - cur_p->skb =NULL ; - } +axienet_free_tx_bufs (lp);for (i =0 ; i < lp->rx_bd_num; i++) { cur_p = &lp->rx_bd_v[i];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2903/3318 IB/IPoIB: Cancel normal flush work on device stop
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Carolina Jubran <[email protected]>
[ Upstream commit 66196a559be5963b1ced18418c876caf9bfb76e6 ]
ipoib_ib_dev_flush_normal() can race with ipoib_stop() because the normal flush work does not run under RTNL.
Before commit a77a57a1a22a ("IPoIB: Fix deadlock on RTNL in ipoib_stop()"), ipoib_stop() flushed ipoib_workqueue after clearing IPOIB_FLAG_ADMIN_UP and before calling ipoib_ib_dev_down(). This ensured that any in-flight flush work completed before ipoib_ib_dev_down() performed the final clear of IPOIB_FLAG_OPER_UP.
After that commit removed the workqueue flush to avoid a deadlock with workqueue tasks taking RTNL, a normal flush can continue running concurrently with ipoib_stop() after IPOIB_FLAG_ADMIN_UP has been cleared.
The flush may observe IPOIB_FLAG_ADMIN_UP set and continue running while ipoib_stop() clears IPOIB_FLAG_ADMIN_UP and brings the device down. The flush can then call ipoib_ib_dev_up() and set IPOIB_FLAG_OPER_UP again after the device has already been stopped:
flush_normal (ipoib_workqueue) ipoib_stop() (RTNL held)
------------------------------ ------------------------
test_bit(ADMIN_UP) == 1
clear_bit(ADMIN_UP)
ipoib_ib_dev_down()
clear_bit(OPER_UP) ipoib_ib_dev_up()
set_bit(OPER_UP)
This leaves the interface with ADMIN_UP clear and OPER_UP set. During device removal, ipoib_ndo_uninit() waits in destroy_workqueue() while holding RTNL, while ipoib_mcast_carrier_on_task() may keep retrying rtnl_trylock() as long as OPER_UP remains set, resulting in a deadlock.
Cancel the normal flush work from ipoib_stop() after clearing IPOIB_FLAG_ADMIN_UP and before bringing the device down. A pending normal flush is canceled, while an already running flush is allowed to finish before ipoib_ib_dev_down() performs the final transition to OPER_UP clear.
Only the normal flush needs this synchronization. The heavy flush is already serialized with ipoib_stop() by RTNL, while the light flush does not bring the device back up and therefore cannot recreate this race.
--- drivers/infiniband/ulp/ipoib/ipoib_main.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/infiniband/ulp/ipoib/ipoib_main.c +7 -0
@@ -189,6 +189,13 @@ static int ipoib_stop(struct net_device *dev)clear_bit (IPOIB_FLAG_ADMIN_UP , &priv->flags); +/* Normal flush runs without RTNL and may bring the device back +* up. Cancel it before the device down transition. +* Heavy flush is already serialized by RTNL and must not be +* waited on here while RTNL is held. +*/ +cancel_work_sync (&priv->flush_normal); +netif_stop_queue (dev);ipoib_ib_dev_down (dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2904/3318 rxrpc: Revert "rxrpc: rxperf: Fix missing decoding of terminal magic cookie"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Howells <[email protected]>
[ Upstream commit 870143cfdac1cad166d1dc03fbef915fac0c229a ]
Revert commit c34d999ca3145d9fe858258cc3342ec493f47d2e:
The rxperf RPCs seem to have a magic cookie at the end of the request that was failing to be taken account of by the unmarshalling of the request. Fix the rxperf code to expect this.
Actually, this isn't true; it's just that other Rx implementations ignore the extra data in the request and so my test programs are sending too much data without noticeable consequence.
--- net/rxrpc/rxperf.c | 12 ------------ 1 file changed, 12 deletions(-)
net/rxrpc/rxperf.c +0 -12
@@ -494,18 +494,6 @@ static int rxperf_deliver_request(struct rxperf_call *call) call->unmarshal++; fallthrough;case 2 : - ret =rxperf_extract_data (call, true); -if (ret <0 ) -return ret; - -/* Deal with the terminal magic cookie. */ - call->iov_len =4 ; - call->kvec[0 ].iov_len = call->iov_len; - call->kvec[0 ].iov_base = call->tmp; -iov_iter_kvec (&call->iter,READ , call->kvec,1 , call->iov_len); - call->unmarshal++; - fallthrough; -case 3 : ret =rxperf_extract_data (call, false);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2905/3318 irqchip/gic-v3-its: Clear vpt_page after freeing the pending table
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 0d604b1e4617d18dbb5573290ba447d7369251d1 ]
its_vpe_teardown() frees vpt_page without clearing it, so its vpt_page == NULL guard only holds the first time it runs on a vPE. struct its_vpe outlives a failed KVM_DEV_ARM_VGIC_CTRL_INIT, so a retry that fails again frees the pending table and the vPE ID a second time.
--- drivers/irqchip/irq-gic-v3-its.c | 1 + 1 file changed, 1 insertion(+)
drivers/irqchip/irq-gic-v3-its.c +1 -0
@@ -4485,6 +4485,7 @@ static void its_vpe_teardown(struct its_vpe *vpe)its_vpe_db_proxy_unmap (vpe);its_vpe_id_free (vpe->vpe_id);its_free_pending_table (vpe->vpt_page); + vpe->vpt_page =NULL ; } static void its_vpe_irq_domain_free(struct irq_domain *domain,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2906/3318 irqchip/gic-v3-its: Share ITS tables with a non-trusted hypervisor
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Price <[email protected]>
[ Upstream commit b08e2f42e86b5848add254da45b56fc672e2bced ]
Within a realm guest the ITS is emulated by the host. This means the allocations must have been made available to the host by a call to set_memory_decrypted(). Introduce an allocation function which performs this extra call.
For the ITT use a custom genpool-based allocator that calls set_memory_decrypted() for each page allocated, but then suballocates the size needed for each ITT. Note that there is no mechanism implemented to return pages from the genpool, but it is unlikely that the peak number of devices will be much larger than the normal level - so this isn't expected to be an issue.
Stable-dep-of: 32e056cc1d15 ("irqchip/gic-v3-its: Don't free a vPE table shared with another ITS")
--- drivers/irqchip/irq-gic-v3-its.c | 138 +++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 23 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +115 -23
@@ -12,12 +12,14 @@#include <linux/crash_dump.h> #include <linux/delay.h> #include <linux/efi.h> +#include <linux/genalloc.h> #include <linux/interrupt.h> #include <linux/iommu.h> #include <linux/iopoll.h> #include <linux/irqdomain.h> #include <linux/list.h> #include <linux/log2.h> +#include <linux/mem_encrypt.h> #include <linux/memblock.h> #include <linux/mm.h> #include <linux/msi.h>
@@ -27,6 +29,7 @@#include <linux/of_pci.h> #include <linux/of_platform.h> #include <linux/percpu.h> +#include <linux/set_memory.h> #include <linux/slab.h> #include <linux/syscore_ops.h>
@@ -163,6 +166,7 @@ struct its_device {struct its_node *its;struct event_lpi_map event_map;void *itt; +u32 itt_sz;u32 nr_ites;u32 device_id;bool shared;
@@ -198,6 +202,87 @@ static DEFINE_IDA(its_vpeid_ida);#define gic_data_rdist_rd_base () (gic_data_rdist()->rd_base)#define gic_data_rdist_vlpi_base () (gic_data_rdist_rd_base() + SZ_128K) +static struct page *its_alloc_pages_node (int node,gfp_t gfp, +unsigned int order) +{ +struct page *page; +int ret =0 ; + + page =alloc_pages_node (node, gfp, order); + +if (!page) +return NULL ; + + ret =set_memory_decrypted ((unsigned long )page_address (page), +1 << order); +/* +* If set_memory_decrypted() fails then we don't know what state the +* page is in, so we can't free it. Instead we leak it. +* set_memory_decrypted() will already have WARNed. +*/ +if (ret) +return NULL ; + +return page; +} + +static struct page *its_alloc_pages (gfp_t gfp,unsigned int order) +{ +return its_alloc_pages_node (NUMA_NO_NODE , gfp, order); +} + +static void its_free_pages (void *addr,unsigned int order) +{ +/* +* If the memory cannot be encrypted again then we must leak the pages. +* set_memory_encrypted() will already have WARNed. +*/ +if (set_memory_encrypted ((unsigned long )addr,1 << order)) +return ; +free_pages ((unsigned long )addr, order); +} + +static struct gen_pool *itt_pool; + +static void *itt_alloc_pool (int node,int size) +{ +unsigned long addr; +struct page *page; + +if (size >=PAGE_SIZE ) { + page =its_alloc_pages_node (node,GFP_KERNEL | __GFP_ZERO,get_order (size)); + +return page ?page_address (page) :NULL ; + } + +do { + addr =gen_pool_alloc (itt_pool, size); +if (addr) +break ; + + page =its_alloc_pages_node (node,GFP_KERNEL | __GFP_ZERO,1 ); +if (!page) +break ; + +gen_pool_add (itt_pool, (unsigned long )page_address (page),PAGE_SIZE , node); + }while (!addr); + +return (void *)addr; +} + +static void itt_free_pool (void *addr,int size) +{ +if (!addr) +return ; + +if (size >=PAGE_SIZE ) { +its_free_pages (addr,get_order (size)); +return ; + } + +gen_pool_free (itt_pool, (unsigned long )addr, size); +} +/* * Skip ITSs that have no vLPIs mapped, unless we're on GICv4.1, as we * always have vSGIs mapped.
@@ -2193,7 +2278,8 @@ static struct page *its_allocate_prop_table(gfp_t gfp_flags) {struct page *prop_page; - prop_page =alloc_pages (gfp_flags,get_order (LPI_PROPBASE_SZ )); + prop_page =its_alloc_pages (gfp_flags, +get_order (LPI_PROPBASE_SZ ));if (!prop_page)return NULL ;
@@ -2204,8 +2290,7 @@ static struct page *its_allocate_prop_table(gfp_t gfp_flags)static void its_free_prop_table (struct page *prop_page) { -free_pages ((unsigned long )page_address (prop_page), -get_order (LPI_PROPBASE_SZ )); +its_free_pages (page_address (prop_page),get_order (LPI_PROPBASE_SZ )); }static bool gic_check_reserved_range (phys_addr_t addr,unsigned long size)
@@ -2327,7 +2412,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser, order =get_order (GITS_BASER_PAGES_MAX * psz); } - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, order); + page =its_alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, order);if (!page)return -ENOMEM ;
@@ -2340,7 +2425,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,/* 52bit PA is supported only when PageSize=64K */ if (psz !=SZ_64K ) {pr_err ("ITS: no 52bit PA support when psz=%d\n" , psz); -free_pages ((unsigned long )base, order); +its_free_pages (base, order);return -ENXIO ; }
@@ -2396,7 +2481,7 @@ static int its_setup_baser(struct its_node *its, struct its_baser *baser,pr_err ("ITS@%pa: %s doesn't stick: %llx %llx\n" , &its->phys_base, its_base_type_string[type], val, tmp); -free_pages ((unsigned long )base, order); +its_free_pages (base, order);return -ENXIO ; }
@@ -2535,8 +2620,7 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -free_pages ((unsigned long )its->tables[i].base, - its->tables[i].order); +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2802,7 +2886,7 @@ static bool allocate_vpe_l2_table(int cpu, u32 id)/* Allocate memory for 2nd level table */ if (!table[idx]) { - page =alloc_pages (GFP_KERNEL | __GFP_ZERO,get_order (psz)); + page =its_alloc_pages (GFP_KERNEL | __GFP_ZERO,get_order (psz));if (!page)return false;
@@ -2921,7 +3005,7 @@ static int allocate_vpe_l1_table(void)pr_debug ("np = %d, npg = %lld, psz = %d, epp = %d, esz = %d\n" , np, npg, psz, epp, esz); - page =alloc_pages (GFP_ATOMIC | __GFP_ZERO,get_order (np *PAGE_SIZE )); + page =its_alloc_pages (GFP_ATOMIC | __GFP_ZERO,get_order (np *PAGE_SIZE ));if (!page)return -ENOMEM ;
@@ -2967,8 +3051,7 @@ static struct page *its_allocate_pending_table(gfp_t gfp_flags) {struct page *pend_page; - pend_page =alloc_pages (gfp_flags | __GFP_ZERO, -get_order (LPI_PENDBASE_SZ )); + pend_page =its_alloc_pages (gfp_flags | __GFP_ZERO,get_order (LPI_PENDBASE_SZ ));if (!pend_page)return NULL ;
@@ -2980,7 +3063,7 @@ static struct page *its_allocate_pending_table(gfp_t gfp_flags)static void its_free_pending_table (struct page *pt) { -free_pages ((unsigned long )page_address (pt),get_order (LPI_PENDBASE_SZ )); +its_free_pages (page_address (pt),get_order (LPI_PENDBASE_SZ )); }/*
@@ -3313,8 +3396,8 @@ static bool its_alloc_table_entry(struct its_node *its,/* Allocate memory for 2nd level table */ if (!table[idx]) { - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, -get_order (baser->psz)); + page =its_alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, +get_order (baser->psz));if (!page)return false;
@@ -3410,7 +3493,6 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id,if (WARN_ON (!is_power_of_2 (nvecs))) nvecs =roundup_pow_of_two (nvecs); - dev =kzalloc (sizeof (*dev),GFP_KERNEL );/* * Even if the device wants a single LPI, the ITT must be * sized as a power of two (and you need at least one bit...).
@@ -3421,7 +3503,11 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, nr_ites =max (2 , nvecs); sz = nr_ites * (FIELD_GET (GITS_TYPER_ITT_ENTRY_SIZE , its->typer) +1 ); sz =max (sz,ITS_ITT_ALIGN ) +ITS_ITT_ALIGN -1 ; - itt =kzalloc_node (sz,GFP_KERNEL , its->numa_node); + + itt =itt_alloc_pool (its->numa_node, sz); + + dev =kzalloc (sizeof (*dev),GFP_KERNEL ); +if (alloc_lpis) { lpi_map =its_lpi_alloc (nvecs, &lpi_base, &nr_lpis);if (lpi_map)
@@ -3433,9 +3519,9 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, lpi_base =0 ; } -if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) { +if (!dev || !itt || !col_map || (!lpi_map && alloc_lpis)) {kfree (dev); -kfree (itt); +itt_free_pool (itt, sz);bitmap_free (lpi_map);kfree (col_map);return NULL ;
@@ -3445,6 +3531,7 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, dev->its = its; dev->itt = itt; + dev->itt_sz = sz; dev->nr_ites = nr_ites; dev->event_map.lpi_map = lpi_map; dev->event_map.col_map = col_map;
@@ -3472,7 +3559,7 @@ static void its_free_device(struct its_device *its_dev)list_del (&its_dev->entry);raw_spin_unlock_irqrestore (&its_dev->its->lock, flags);kfree (its_dev->event_map.col_map); -kfree (its_dev->itt); +itt_free_pool (its_dev->itt, its_dev->itt_sz);kfree (its_dev); }
@@ -5125,8 +5212,9 @@ static int __init its_probe_one(struct its_node *its) } } - page =alloc_pages_node (its->numa_node,GFP_KERNEL | __GFP_ZERO, -get_order (ITS_CMD_QUEUE_SZ )); + page =its_alloc_pages_node (its->numa_node, +GFP_KERNEL | __GFP_ZERO, +get_order (ITS_CMD_QUEUE_SZ ));if (!page) { err = -ENOMEM ; goto out_unmap_sgir;
@@ -5192,7 +5280,7 @@ static int __init its_probe_one(struct its_node *its) out_free_tables:its_free_tables (its); out_free_cmd: -free_pages ((unsigned long )its->cmd_base,get_order (ITS_CMD_QUEUE_SZ )); +its_free_pages (its->cmd_base,get_order (ITS_CMD_QUEUE_SZ )); out_unmap_sgir:if (its->sgir_base)iounmap (its->sgir_base);
@@ -5678,6 +5766,10 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,bool has_v4_1 = false;int err; + itt_pool =gen_pool_create (get_order (ITS_ITT_ALIGN ),-1 ); +if (!itt_pool) +return -ENOMEM ; + gic_rdists = rdists; its_parent = parent_domain;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2907/3318 irqchip/gic-v3-its: Dont free a vPE table shared with another ITS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit 32e056cc1d1582951f981113ca8b98914f29c32a ]
On GICv4.1, its_alloc_tables() copies a sibling's vPE table baser rather than allocating one, but its_free_tables() frees it like the rest. A probe failure on the copying ITS then frees pages the enabled sibling still points GITS_BASER2 at, and the kernel comes up running on that sibling.
Mark a shared table so its_free_tables() skips it.
--- drivers/irqchip/irq-gic-v3-its.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3-its.c +5 -1
@@ -83,6 +83,8 @@ struct its_baser {u64 val;u32 order;u32 psz; +/* Inherited from a sibling ITS, not freed here */ +bool shared; };struct its_device ;
@@ -2620,7 +2622,8 @@ static void its_free_tables(struct its_node *its)for (i =0 ; i <GITS_BASER_NR_REGS ; i++) {if (its->tables[i].base) { -its_free_pages (its->tables[i].base, its->tables[i].order); +if (!its->tables[i].shared) +its_free_pages (its->tables[i].base, its->tables[i].order); its->tables[i].base =NULL ; } }
@@ -2719,6 +2722,7 @@ static int its_alloc_tables(struct its_node *its)WARN_ON (i !=2 );if ((sibling =find_sibling_its (its))) { *baser = sibling->tables[2 ]; + baser->shared = true;its_write_baser (its, baser, baser->val);continue ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2908/3318 irqchip/gic-v3-its: Dont free the tables of an enabled ITS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
[ Upstream commit d09b36d8e0e60f35bd1cd7d63aadc6dfad61700c ]
its_probe_one() enables the ITS before its_init_domain(), the last step that can fail, and the unwind from there frees the tables and the command queue without disabling it. The kernel comes up with an enabled ITS pointing at freed pages.
Enable the ITS last. Nothing reaches the new domain before then: this runs from init_IRQ(), and the ITS joins its_nodes only after the enable.
--- drivers/irqchip/irq-gic-v3-its.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/irqchip/irq-gic-v3-its.c +6 -4
@@ -5263,16 +5263,18 @@ static int __init its_probe_one(struct its_node *its) }gits_write_cwriter (0 , its->base +GITS_CWRITER ); + + err =its_init_domain (its); +if (err) + goto out_free_collection; + +/* Enable last: the unwind frees memory an enabled ITS may access */ ctlr =readl_relaxed (its->base +GITS_CTLR ); ctlr |=GITS_CTLR_ENABLE ;if (is_v4 (its)) ctlr |= GITS_CTLR_ImDe;writel_relaxed (ctlr, its->base +GITS_CTLR ); - err =its_init_domain (its); -if (err) - goto out_free_collection; -raw_spin_lock (&its_lock);list_add (&its->entry, &its_nodes);raw_spin_unlock (&its_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2909/3318 irqchip/gic(v3): Replace gic_irq() with irqd_to_hwirq()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dawei Li <[email protected]>
[ Upstream commit d22083a5f09b2066728a91f3abb71284451247b1 ]
GIC & GIC-v3 share same gic_irq() implementations, both of which serve exact same purpose as irqd_to_hwirq(). irqd_to_hwirq() is a generic and top level API of the interrupt subsystem, it's independent of any chip implementation.
Replace gic_irq() with irqd_to_hwirq() and convert struct irq_data::hwirq to irq_hw_number_t explicitly.
Stable-dep-of: 13ce14ca41a3 ("irqchip/gic: Fix UBSAN shift-out-of-bounds in GIC helpers")
--- drivers/irqchip/irq-gic-v3.c | 19 +++++++------------ drivers/irqchip/irq-gic.c | 27 ++++++++++++--------------- include/linux/irq.h | 2 +- 3 files changed, 20 insertions(+), 28 deletions(-)
drivers/irqchip/irq-gic-v3.c +7 -12
@@ -174,11 +174,6 @@ static enum gic_intid_range get_intid_range(struct irq_data *d)return __get_intid_range (d->hwirq); } -static inline unsigned int gic_irq (struct irq_data *d) -{ -return d->hwirq; -} -static inline bool gic_irq_in_rdist (struct irq_data *d) {switch (get_intid_range (d)) {
@@ -547,7 +542,7 @@ static int gic_irq_nmi_setup(struct irq_data *d)* A secondary irq_chip should be in charge of LPI request, * it should not be possible to get there */ -if (WARN_ON (gic_irq (d) >=8192 )) +if (WARN_ON (irqd_to_hwirq (d) >=8192 ))return -EINVAL ;/* desc lock should already be held */
@@ -584,7 +579,7 @@ static void gic_irq_nmi_teardown(struct irq_data *d)* A secondary irq_chip should be in charge of LPI request, * it should not be possible to get there */ -if (WARN_ON (gic_irq (d) >=8192 )) +if (WARN_ON (irqd_to_hwirq (d) >=8192 ))return ;/* desc lock should already be held */
@@ -622,7 +617,7 @@ static bool gic_arm64_erratum_2941627_needed(struct irq_data *d)static void gic_eoi_irq (struct irq_data *d) { -write_gicreg (gic_irq (d),ICC_EOIR1_EL1 ); +write_gicreg (irqd_to_hwirq (d),ICC_EOIR1_EL1 );isb ();if (gic_arm64_erratum_2941627_needed (d)) {
@@ -642,19 +637,19 @@ static void gic_eoimode1_eoi_irq(struct irq_data *d)* No need to deactivate an LPI, or an interrupt that * is is getting forwarded to a vcpu. */ -if (gic_irq (d) >=8192 ||irqd_is_forwarded_to_vcpu (d)) +if (irqd_to_hwirq (d) >=8192 ||irqd_is_forwarded_to_vcpu (d))return ;if (!gic_arm64_erratum_2941627_needed (d)) -gic_write_dir (gic_irq (d)); +gic_write_dir (irqd_to_hwirq (d));else gic_poke_irq (d,GICD_ICACTIVER ); }static int gic_set_type (struct irq_data *d,unsigned int type) { +irq_hw_number_t irq =irqd_to_hwirq (d);enum gic_intid_range range; -unsigned int irq =gic_irq (d);void __iomem *base;u32 offset, index;int ret;
@@ -680,7 +675,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type) ret =gic_configure_irq (index, type, base + offset,NULL );if (ret && (range ==PPI_RANGE || range ==EPPI_RANGE )) {/* Misconfigured PPIs are usually not fatal */ -pr_warn ("GIC: PPI INTID%d is secure or misconfigured\n" , irq); +pr_warn ("GIC: PPI INTID%ld is secure or misconfigured\n" , irq); ret =0 ; }
drivers/irqchip/irq-gic.c +12 -15
@@ -162,11 +162,6 @@ static inline void __iomem *gic_cpu_base(struct irq_data *d)return gic_data_cpu_base (gic_data); } -static inline unsigned int gic_irq (struct irq_data *d) -{ -return d->hwirq; -} -static inline bool cascading_gic_irq (struct irq_data *d) {void *data =irq_data_get_irq_handler_data (d);
@@ -183,14 +178,16 @@ static inline bool cascading_gic_irq(struct irq_data *d)*/ static void gic_poke_irq (struct irq_data *d,u32 offset) { -u32 mask =1 << (gic_irq (d) %32 ); -writel_relaxed (mask,gic_dist_base (d) + offset + (gic_irq (d) /32 ) *4 ); +u32 mask =1 << (irqd_to_hwirq (d) %32 ); + +writel_relaxed (mask,gic_dist_base (d) + offset + (irqd_to_hwirq (d) /32 ) *4 ); }static int gic_peek_irq (struct irq_data *d,u32 offset) { -u32 mask =1 << (gic_irq (d) %32 ); -return !!(readl_relaxed (gic_dist_base (d) + offset + (gic_irq (d) /32 ) *4 ) & mask); +u32 mask =1 << (irqd_to_hwirq (d) %32 ); + +return !!(readl_relaxed (gic_dist_base (d) + offset + (irqd_to_hwirq (d) /32 ) *4 ) & mask); }static void gic_mask_irq (struct irq_data *d)
@@ -220,7 +217,7 @@ static void gic_unmask_irq(struct irq_data *d)static void gic_eoi_irq (struct irq_data *d) { -u32 hwirq =gic_irq (d); +irq_hw_number_t hwirq =irqd_to_hwirq (d);if (hwirq <16 ) hwirq =this_cpu_read (sgi_intid);
@@ -230,7 +227,7 @@ static void gic_eoi_irq(struct irq_data *d)static void gic_eoimode1_eoi_irq (struct irq_data *d) { -u32 hwirq =gic_irq (d); +irq_hw_number_t hwirq =irqd_to_hwirq (d);/* Do not deactivate an IRQ forwarded to a vcpu. */ if (irqd_is_forwarded_to_vcpu (d))
@@ -293,8 +290,8 @@ static int gic_irq_get_irqchip_state(struct irq_data *d,static int gic_set_type (struct irq_data *d,unsigned int type) { +irq_hw_number_t gicirq =irqd_to_hwirq (d);void __iomem *base =gic_dist_base (d); -unsigned int gicirq =gic_irq (d);int ret;/* Interrupt configuration for SGIs can't be changed */
@@ -309,7 +306,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type) ret =gic_configure_irq (gicirq, type, base +GIC_DIST_CONFIG ,NULL );if (ret && gicirq <32 ) {/* Misconfigured PPIs are usually not fatal */ -pr_warn ("GIC: PPI%d is secure or misconfigured\n" , gicirq -16 ); +pr_warn ("GIC: PPI%ld is secure or misconfigured\n" , gicirq -16 ); ret =0 ; }
@@ -319,7 +316,7 @@ static int gic_set_type(struct irq_data *d, unsigned int type)static int gic_irq_set_vcpu_affinity (struct irq_data *d,void *vcpu) {/* Only interrupts on the primary GIC can be forwarded to a vcpu. */ -if (cascading_gic_irq (d) ||gic_irq (d) <16 ) +if (cascading_gic_irq (d) ||irqd_to_hwirq (d) <16 )return -EINVAL ;if (vcpu)
@@ -796,7 +793,7 @@ static void rmw_writeb(u8 bval, void __iomem *addr)static int gic_set_affinity (struct irq_data *d,const struct cpumask *mask_val,bool force) { -void __iomem *reg =gic_dist_base (d) +GIC_DIST_TARGET +gic_irq (d); +void __iomem *reg =gic_dist_base (d) +GIC_DIST_TARGET +irqd_to_hwirq (d);struct gic_chip_data *gic =irq_data_get_irq_chip_data (d);unsigned int cpu;
include/linux/irq.h +1 -1
@@ -179,7 +179,7 @@ struct irq_common_data {struct irq_data {u32 mask;unsigned int irq; -unsigned long hwirq; +irq_hw_number_t hwirq;struct irq_common_data *common;struct irq_chip *chip;struct irq_domain *domain;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2910/3318 irqchip/gic: Fix UBSAN shift-out-of-bounds in GIC helpers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhu Ling <[email protected]>
[ Upstream commit 13ce14ca41a35f5ee90b77ffa57da91ce6048a2d ]
When running with UBSAN enabled, enabling a GPIO controller that uses a GIC interrupt as its parent triggers several shift-out-of-bounds warnings:
shift-out-of-bounds in drivers/irqchip/irq-gic-common.c:50:21 left shift of 2 by 30 places cannot be represented in type 'int'
Similar reports are emitted from gic_poke_irq() and gic_peek_irq() in drivers/irqchip/irq-gic-v3.c. The corresponding GICv2 helpers use the same signed-shift pattern. These masks are generated by shifting signed integer constants, which invokes undefined behavior when bit 31 is selected.
Use BIT() to generate the masks with an unsigned type and make their intent explicit.
--- drivers/irqchip/irq-gic-common.c | 2 +- drivers/irqchip/irq-gic-v3.c | 4 ++-- drivers/irqchip/irq-gic.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/irqchip/irq-gic-common.c +1 -1
@@ -47,7 +47,7 @@ void gic_enable_quirks(u32 iidr, const struct gic_quirk *quirks,int gic_configure_irq (unsigned int irq,unsigned int type,void __iomem *base,void (*sync_access)(void )) { -u32 confmask =0x2 << ((irq %16 ) *2 ); +u32 confmask =BIT (((irq %16 ) *2 ) +1 );u32 confoff = (irq /16 ) *4 ;u32 val, oldval;int ret =0 ;
drivers/irqchip/irq-gic-v3.c +2 -2
@@ -372,7 +372,7 @@ static int gic_peek_irq(struct irq_data *d, u32 offset)u32 index, mask; offset =convert_offset_index (d, offset, &index); - mask =1 << (index %32 ); + mask =BIT (index %32 );if (gic_irq_in_rdist (d)) base =gic_data_rdist_sgi_base ();
@@ -388,7 +388,7 @@ static void gic_poke_irq(struct irq_data *d, u32 offset)u32 index, mask; offset =convert_offset_index (d, offset, &index); - mask =1 << (index %32 ); + mask =BIT (index %32 );if (gic_irq_in_rdist (d)) base =gic_data_rdist_sgi_base ();
drivers/irqchip/irq-gic.c +2 -2
@@ -178,14 +178,14 @@ static inline bool cascading_gic_irq(struct irq_data *d)*/ static void gic_poke_irq (struct irq_data *d,u32 offset) { -u32 mask =1 << (irqd_to_hwirq (d) %32 ); +u32 mask =BIT (irqd_to_hwirq (d) %32 );writel_relaxed (mask,gic_dist_base (d) + offset + (irqd_to_hwirq (d) /32 ) *4 ); }static int gic_peek_irq (struct irq_data *d,u32 offset) { -u32 mask =1 << (irqd_to_hwirq (d) %32 ); +u32 mask =BIT (irqd_to_hwirq (d) %32 );return !!(readl_relaxed (gic_dist_base (d) + offset + (irqd_to_hwirq (d) /32 ) *4 ) & mask); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2911/3318 ALSA: Add simple refcount helper functions
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 dcca9b6064c33c84fbeb9f09814178a206321249 ]
There are many open-code to manage the same pattern for refcount + wakeup sync at closing. Let's provide the common helper functions to replace the open-code.
- The recount is kept in struct snd_refcount, where it's initialized by snd_refcount_init().
- The user can simply reference or unreference via snd_refcount_get() and snd_refcount_put() functions
- The user can wait for the all usages gone by snd_refcount_sync()
Note that here we use atomic_t instead of refcount_t since the current users allow reusing the refcount after sync again. The design of refcount_t prevents exactly this behavior, so it doesn't fit.
Stable-dep-of: 91d0048a97e0 ("ALSA: pcm: Add refcount for races between drain and unlink")
--- include/sound/core.h | 21 +++++++++++++++++++++ sound/core/misc.c | 24 ++++++++++++++++++++++++ 2 files changed, 45 insertions(+)
include/sound/core.h +21 -0
@@ -75,6 +75,27 @@ struct snd_device {#define snd_device (n) list_entry(n, struct snd_device, list) +/* +* A simple reference counter with a wait queue; +* typically used for usage counts, and you can synchronize at finishing +* via snd_refcount_sync(), which is woken up when the refcount reaches to +* zero again. +*/ +struct snd_refcount { +atomic_t count; +wait_queue_head_t waiter; +}; + +void snd_refcount_init (struct snd_refcount *ref); + +static inline void snd_refcount_get (struct snd_refcount *ref) +{ +atomic_inc (&ref->count); +} + +void snd_refcount_put (struct snd_refcount *ref); +void snd_refcount_sync (struct snd_refcount *ref); +/* main structure for soundcard */ struct snd_card {
sound/core/misc.c +24 -0
@@ -245,3 +245,27 @@ void snd_fasync_free(struct snd_fasync *fasync)kfree (fasync); }EXPORT_SYMBOL_GPL (snd_fasync_free); + +/* +* generic refcount helper +*/ + +void snd_refcount_init (struct snd_refcount *ref) +{ +atomic_set (&ref->count,0 ); +init_waitqueue_head (&ref->waiter); +} +EXPORT_SYMBOL_GPL (snd_refcount_init); + +void snd_refcount_put (struct snd_refcount *ref) +{ +if (atomic_dec_and_test (&ref->count)) +wake_up (&ref->waiter); +} +EXPORT_SYMBOL_GPL (snd_refcount_put); + +void snd_refcount_sync (struct snd_refcount *ref) +{ +wait_event (ref->waiter, !atomic_read (&ref->count)); +} +EXPORT_SYMBOL_GPL (snd_refcount_sync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2912/3318 ALSA: pcm: Add refcount for races between drain and unlink
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 91d0048a97e0fdc0a071caa0ba59e659bc6f84df ]
We added a workaround for the case where a linked substream gets unlinked during the drain operation by another substream of the same linked group in the commit 9b1dbd69ba6f ("ALSA: pcm: fix use-after-free on linked stream runtime in snd_pcm_drain()"). There, we just cached the parameters of the draining substream for avoiding UAF.
Then, we check the draining substream (to_check) again in the loop and remove it from the queue only when it's still present. It means, however, that the wait queue entry won't be removed if the substream went out of the link beforehand, hence a stale wq entry remains. Later on, this can be woken up, and this may hit a UAF, too. The problem surfaced more due to the recent change to call snd_pcm_unlink() earlier.
For properly handling both cases above, in this patch, we introduce a refcount to the snd_pcm_runtime that indicates the substream is being accessed / used, then at snd_pcm_release_substream(), it's synced before the actual resource release via snd_refcount_sync(). This guarantees that the accessors are finished, and safe to release memories. Along with the introduction of a refcount, the comments and the code changes by the former fix were partially reverted as they don't fit with the updated code flow any longer.
Last but not least, the setup of wait queue entry and prepare_to_wait() call are moved before the group unref. With this change, we can avoid the race between the enqueue and the wakeup, too.
--- include/sound/pcm.h | 2 ++ sound/core/pcm.c | 1 + sound/core/pcm_native.c | 54 ++++++++++++++++------------------------- 3 files changed, 24 insertions(+), 33 deletions(-)
include/sound/pcm.h +2 -0
@@ -8,6 +8,7 @@* Abramo Bagnara <[email protected]> */ +#include <sound/core.h> #include <sound/asound.h> #include <sound/memalloc.h> #include <sound/minors.h>
@@ -399,6 +400,7 @@ struct snd_pcm_runtime {snd_pcm_uframes_t twake;/* do transfer (!poll) wakeup if non-zero */ wait_queue_head_t sleep;/* poll sleep */ wait_queue_head_t tsleep;/* transfer sleep */ +struct snd_refcount refcnt;/* refcount for draining, etc */ struct snd_fasync *fasync;bool stop_operating;/* sync_stop will be called */ struct mutex buffer_mutex;/* protect for buffer changes */
sound/core/pcm.c +1 -0
@@ -973,6 +973,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,init_waitqueue_head (&runtime->sleep);init_waitqueue_head (&runtime->tsleep); +snd_refcount_init (&runtime->refcnt);__snd_pcm_set_state (runtime,SNDRV_PCM_STATE_OPEN );mutex_init (&runtime->buffer_mutex);
sound/core/pcm_native.c +21 -33
81 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2913/3318 spi: Introduce internal spi_xfer_is_dma_mapped() helper
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 0535cf64e4b1ead224fbbe1c25c81221a298c5e4 ]
There are few drivers that use the same pattern to check if the transfer is DMA mapped or not. Provide a helper.
Stable-dep-of: c126e07bde21 ("spi: omap2-mcspi: handle DMA setup failures")
--- drivers/spi/internals.h | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/spi/internals.h +8 -0
@@ -40,4 +40,12 @@ static inline void spi_unmap_buf(struct spi_controller *ctlr, }#endif /* CONFIG_HAS_DMA */ +static inline bool spi_xfer_is_dma_mapped (struct spi_controller *ctlr, +struct spi_device *spi, +struct spi_transfer *xfer) +{ +return ctlr->can_dma && ctlr->can_dma (ctlr, spi, xfer) && + ctlr->cur_msg_mapped; +} +#endif /* __LINUX_SPI_INTERNALS_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2914/3318 spi: omap2-mcspi: Use new spi_xfer_is_dma_mapped() helper
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 6361b4e4f7a43dd5d8e3f2d2ece8148f30b55cb3 ]
Replace a few lines of code by calling a spi_xfer_is_dma_mapped() helper.
Stable-dep-of: c126e07bde21 ("spi: omap2-mcspi: handle DMA setup failures")
--- drivers/spi/spi-omap2-mcspi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/spi/spi-omap2-mcspi.c +4 -4
@@ -27,6 +27,8 @@#include <linux/spi/spi.h> +#include "internals.h" +#include <linux/platform_data/spi-omap2-mcspi.h> #define OMAP2_MCSPI_MAX_FREQ 48000000
@@ -1204,8 +1206,7 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr,unsigned count;if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && - ctlr->cur_msg_mapped && - ctlr->can_dma (ctlr, spi, t)) +spi_xfer_is_dma_mapped (ctlr, spi, t))omap2_mcspi_set_fifo (spi, t,1 );omap2_mcspi_set_enable (spi,1 );
@@ -1216,8 +1217,7 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr, + OMAP2_MCSPI_TX0);if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && - ctlr->cur_msg_mapped && - ctlr->can_dma (ctlr, spi, t)) +spi_xfer_is_dma_mapped (ctlr, spi, t)) count =omap2_mcspi_txrx_dma (spi, t);else count =omap2_mcspi_txrx_pio (spi, t);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2915/3318 spi: omap2-mcspi: handle DMA setup failures
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sahaj Chaudhari <[email protected]>
[ Upstream commit c126e07bde21c518f1356937ac240500d1bc81c0 ]
The DMA paths ignore failures from dmaengine_slave_config(), descriptor preparation and dmaengine_submit(), and carry FIXME comments about falling back to PIO. A failed setup can leave a half-started transfer or wait for a completion that never arrives.
Check each step and clean up with dmaengine_terminate_sync() on error. Prepare both descriptors before issuing either channel. Fall back to PIO only for host-mode transfers that have a TX buffer, when no DMA has been started and cleanup succeeded. RX-only and target-mode transfers return the error instead, since the bus may already be clocking.
The FIFO is enabled before the DMA attempt, but the PIO path polls per-word TXS/RXS and does not expect FIFO mode. Disable the FIFO, with the channel off while its bits change, before falling back.
Tested on an AM642 board with a TI 6.12.57 vendor kernel built with this patch and booted from RAM. On a McSPI bus using DMA, 200 iterations of 4096-byte TX and 1024-byte RX spidev transfers completed with no errors, timeouts or kernel warnings. With a temporary change that fails every DMA-sized TX setup, 60 spidev writes fell back to PIO with no errors or timeouts. That test used a bus with no device attached and did not show a difference with and without the FIFO disable, which is based on reading the code.
--- drivers/spi/spi-omap2-mcspi.c | 236 ++++++++++++++++++++++++---------- 1 file changed, 167 insertions(+), 69 deletions(-)
drivers/spi/spi-omap2-mcspi.c +167 -69
@@ -403,10 +403,11 @@ static void omap2_mcspi_tx_callback(void *data)complete (&mcspi_dma->dma_tx_completion); } -static void omap2_mcspi_tx_dma (struct spi_device *spi, -struct spi_transfer *xfer, -struct dma_slave_config cfg) +static int omap2_mcspi_tx_dma (struct spi_device *spi, +struct spi_transfer *xfer, +struct dma_slave_config cfg) { +int ret;struct omap2_mcspi *mcspi;struct omap2_mcspi_dma *mcspi_dma;struct dma_async_tx_descriptor *tx;
@@ -414,31 +415,31 @@ static void omap2_mcspi_tx_dma(struct spi_device *spi, mcspi =spi_controller_get_devdata (spi->controller); mcspi_dma = &mcspi->dma_channels[spi_get_chipselect (spi,0 )]; -dmaengine_slave_config (mcspi_dma->dma_tx, &cfg); + ret =dmaengine_slave_config (mcspi_dma->dma_tx, &cfg); +if (ret) +return ret; tx =dmaengine_prep_slave_sg (mcspi_dma->dma_tx, xfer->tx_sg.sgl, xfer->tx_sg.nents,DMA_MEM_TO_DEV ,DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); -if (tx) { - tx->callback = omap2_mcspi_tx_callback; - tx->callback_param = spi; -dmaengine_submit (tx); - }else { -/* FIXME: fall back to PIO? */ - } -dma_async_issue_pending (mcspi_dma->dma_tx); -omap2_mcspi_set_dma_req (spi,0 ,1 ); +if (!tx) +return -EIO ; + + tx->callback = omap2_mcspi_tx_callback; + tx->callback_param = spi; + +return dma_submit_error (dmaengine_submit (tx)); } -static unsigned +static int omap2_mcspi_rx_dma (struct spi_device *spi,struct spi_transfer *xfer, -struct dma_slave_config cfg, -unsigned es) +struct dma_slave_config cfg,unsigned int es, +unsigned int *count,bool *rx_submitted,bool *dma_started) {struct omap2_mcspi *mcspi;struct omap2_mcspi_dma *mcspi_dma; -unsigned int count, transfer_reduction =0 ; +unsigned int transfer_reduction =0 ;struct scatterlist *sg_out[2 ];int nb_sizes =0 , out_mapped_nents[2 ], ret, x;size_t sizes[2 ];
@@ -451,7 +452,8 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, mcspi =spi_controller_get_devdata (spi->controller); mcspi_dma = &mcspi->dma_channels[spi_get_chipselect (spi,0 )]; - count = xfer->len; + *count = xfer->len; + *rx_submitted = false;/* * In the "End-of-Transfer Procedure" section for DMA RX in OMAP35x TRM
@@ -465,14 +467,16 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, l =mcspi_cached_chconf0 (spi);if (word_len <=8 ) - element_count = count; + element_count = *count;else if (word_len <=16 ) - element_count = count >>1 ; + element_count = *count >>1 ;else /* word_len <= 32 */ - element_count = count >>2 ; + element_count = *count >>2 ; -dmaengine_slave_config (mcspi_dma->dma_rx, &cfg); + ret =dmaengine_slave_config (mcspi_dma->dma_rx, &cfg); +if (ret) +return ret;/* * Reduce DMA transfer length by one more if McSPI is
@@ -483,7 +487,7 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,if (transfer_reduction) {/* Split sgl into two. The second sgl won't be used. */ - sizes[0 ] = count - transfer_reduction; + sizes[0 ] = *count - transfer_reduction; sizes[1 ] = transfer_reduction; nb_sizes =2 ; }else {
@@ -491,44 +495,56 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer,* Don't bother splitting the sgl. This essentially * clones the original sgl. */ - sizes[0 ] = count; + sizes[0 ] = *count; nb_sizes =1 ; } ret =sg_split (xfer->rx_sg.sgl, xfer->rx_sg.nents,0 , nb_sizes, sizes, sg_out, out_mapped_nents,GFP_KERNEL ); -if (ret <0 ) { +if (ret) {dev_err (&spi->dev,"sg_split failed\n" ); -return 0 ; +return ret; } tx =dmaengine_prep_slave_sg (mcspi_dma->dma_rx, sg_out[0 ], out_mapped_nents[0 ],DMA_DEV_TO_MEM ,DMA_PREP_INTERRUPT |DMA_CTRL_ACK ); -if (tx) { - tx->callback = omap2_mcspi_rx_callback; - tx->callback_param = spi; -dmaengine_submit (tx); - }else { -/* FIXME: fall back to PIO? */ +if (!tx) { + ret = -EIO ; + goto out_free_sg; } + tx->callback = omap2_mcspi_rx_callback; + tx->callback_param = spi; + ret =dma_submit_error (dmaengine_submit (tx)); +if (ret) + goto out_free_sg; + + *rx_submitted = true; +if (mcspi->target_aborted) { + ret = -EINTR ; + goto out_free_sg; + } + *dma_started = true; +if (xfer->tx_buf) { +if (spi_controller_is_target (mcspi->ctlr)) +mcspi_write_reg (mcspi->ctlr,OMAP2_MCSPI_IRQENABLE , +OMAP2_MCSPI_IRQSTATUS_EOW ); +dma_async_issue_pending (mcspi_dma->dma_tx); +omap2_mcspi_set_dma_req (spi,0 ,1 ); + }dma_async_issue_pending (mcspi_dma->dma_rx);omap2_mcspi_set_dma_req (spi,1 ,1 ); - ret =mcspi_wait_for_completion (mcspi, &mcspi_dma->dma_rx_completion); -if (ret || mcspi->target_aborted) { -dmaengine_terminate_sync (mcspi_dma->dma_rx); -omap2_mcspi_set_dma_req (spi,1 ,0 ); -return 0 ; - } +if (ret || mcspi->target_aborted) + goto out_free_sg;for (x =0 ; x < nb_sizes; x++)kfree (sg_out[x]);if (mcspi->fifo_depth >0 ) -return count; +return 0 ;/* * Due to the DMA transfer length reduction the missing bytes must
@@ -555,9 +571,9 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, }else {int bytes_per_word =mcspi_bytes_per_word (word_len);dev_err (&spi->dev,"DMA RX penultimate word empty\n" ); - count -= (bytes_per_word <<1 ); + *count -= (bytes_per_word <<1 );omap2_mcspi_set_enable (spi,1 ); -return count; +return 0 ; } }if (!mcspi_wait_for_reg_bit (chstat_reg,OMAP2_MCSPI_CHSTAT_RXS )) {
@@ -572,19 +588,27 @@ omap2_mcspi_rx_dma(struct spi_device *spi, struct spi_transfer *xfer, ((u32 *)xfer->rx_buf)[elements] = w; }else {dev_err (&spi->dev,"DMA RX last word empty\n" ); - count -=mcspi_bytes_per_word (word_len); + *count -=mcspi_bytes_per_word (word_len); }omap2_mcspi_set_enable (spi,1 ); -return count; +return 0 ; + +out_free_sg: +if (!ret) + ret = -EINTR ; +for (x =0 ; x < nb_sizes; x++) +kfree (sg_out[x]); +return ret; } -static unsigned -omap2_mcspi_txrx_dma (struct spi_device *spi,struct spi_transfer *xfer) +static int omap2_mcspi_txrx_dma (struct spi_device *spi, +struct spi_transfer *xfer, +unsigned int *count, +bool *pio_fallback) {struct omap2_mcspi *mcspi;struct omap2_mcspi_cs *cs = spi->controller_state;struct omap2_mcspi_dma *mcspi_dma; -unsigned int count;u8 *rx;const u8 *tx;struct dma_slave_config cfg;
@@ -592,10 +616,13 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)unsigned es;void __iomem *chstat_reg;void __iomem *irqstat_reg; -int wait_res; +bool tx_submitted = false, rx_submitted = false; +bool dma_started = false, terminate_failed = false; +int ret, wait_res; mcspi =spi_controller_get_devdata (spi->controller); mcspi_dma = &mcspi->dma_channels[spi_get_chipselect (spi,0 )]; + *pio_fallback = false;if (cs->word_len <=8 ) { width =DMA_SLAVE_BUSWIDTH_1_BYTE ;
@@ -608,7 +635,7 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer) es =4 ; } - count = xfer->len; + *count = xfer->len;memset (&cfg,0 ,sizeof (cfg)); cfg.src_addr = cs->phys +OMAP2_MCSPI_RX0 ;
@@ -626,31 +653,39 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)reinit_completion (&mcspi_dma->dma_rx_completion);reinit_completion (&mcspi->txdone);if (tx) { -/* Enable EOW IRQ to know end of tx in target mode */ + ret =omap2_mcspi_tx_dma (spi, xfer, cfg); +if (ret) + goto out; + tx_submitted = true; + } + +if (rx) { + ret =omap2_mcspi_rx_dma (spi, xfer, cfg, es, count, + &rx_submitted, &dma_started); +if (ret) + goto out; + }else if (tx) { +if (mcspi->target_aborted) { + ret = -EINTR ; + goto out; + }if (spi_controller_is_target (spi->controller)) -mcspi_write_reg (spi->controller, -OMAP2_MCSPI_IRQENABLE , +mcspi_write_reg (spi->controller,OMAP2_MCSPI_IRQENABLE ,OMAP2_MCSPI_IRQSTATUS_EOW ); -omap2_mcspi_tx_dma (spi, xfer, cfg); + dma_started = true; +dma_async_issue_pending (mcspi_dma->dma_tx); +omap2_mcspi_set_dma_req (spi,0 ,1 ); } -if (rx !=NULL ) - count =omap2_mcspi_rx_dma (spi, xfer, cfg, es); - -if (tx !=NULL ) { -int ret; - +if (tx) { ret =mcspi_wait_for_completion (mcspi, &mcspi_dma->dma_tx_completion); -if (ret || mcspi->target_aborted) { -dmaengine_terminate_sync (mcspi_dma->dma_tx); -omap2_mcspi_set_dma_req (spi,0 ,0 ); -return 0 ; - } +if (ret || mcspi->target_aborted) + goto out;if (spi_controller_is_target (mcspi->ctlr)) { ret =mcspi_wait_for_completion (mcspi, &mcspi->txdone);if (ret || mcspi->target_aborted) -return 0 ; + goto out; }if (mcspi->fifo_depth >0 ) {
@@ -684,7 +719,43 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)dev_err (&spi->dev,"EOT timed out\n" ); } } -return count; +return 0 ; + +out: +if (!ret) + ret = -EINTR ; +if (rx_submitted) { + wait_res =dmaengine_terminate_sync (mcspi_dma->dma_rx); +if (wait_res) { +dev_err (&spi->dev,"failed to terminate RX DMA: %d\n" , + wait_res); + terminate_failed = true; + ret = wait_res; + } +omap2_mcspi_set_dma_req (spi,1 ,0 ); + } +if (tx_submitted) { + wait_res =dmaengine_terminate_sync (mcspi_dma->dma_tx); +if (wait_res) { +dev_err (&spi->dev,"failed to terminate TX DMA: %d\n" , + wait_res); + terminate_failed = true; + ret = wait_res; + } +omap2_mcspi_set_dma_req (spi,0 ,0 ); + } +if (spi_controller_is_target (mcspi->ctlr)) +mcspi_write_reg (mcspi->ctlr,OMAP2_MCSPI_IRQENABLE ,0 ); + + *pio_fallback = !dma_started && !terminate_failed; +return ret; +} + +static bool omap2_mcspi_can_pio_fallback (bool cleanup_ok, +const struct spi_transfer *xfer, +bool is_target) +{ +return cleanup_ok && xfer->tx_buf && !is_target; } static unsigned
@@ -1204,6 +1275,8 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr,if (t->len) {unsigned count; +bool pio_fallback; +int ret;if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) &&spi_xfer_is_dma_mapped (ctlr, spi, t))
@@ -1217,10 +1290,31 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr, + OMAP2_MCSPI_TX0);if ((mcspi_dma->dma_rx && mcspi_dma->dma_tx) && -spi_xfer_is_dma_mapped (ctlr, spi, t)) - count =omap2_mcspi_txrx_dma (spi, t); -else +spi_xfer_is_dma_mapped (ctlr, spi, t)) { + ret =omap2_mcspi_txrx_dma (spi, t, &count, + &pio_fallback); +if (ret) { +bool is_target =spi_controller_is_target (ctlr); +bool fallback; + + fallback =omap2_mcspi_can_pio_fallback (pio_fallback, t, + is_target); +if (!fallback) { + status = ret; + goto out; + } + +dev_warn (&spi->dev, +"DMA setup failed, falling back to PIO\n" ); +/* PIO does not use the FIFO enabled for DMA */ +omap2_mcspi_set_enable (spi,0 ); +omap2_mcspi_set_fifo (spi, t,0 ); +omap2_mcspi_set_enable (spi,1 ); + count =omap2_mcspi_txrx_pio (spi, t); + } + }else { count =omap2_mcspi_txrx_pio (spi, t); + }if (count != t->len) { status = -EIO ;
@@ -1236,8 +1330,12 @@ static int omap2_mcspi_transfer_one(struct spi_controller *ctlr, out:/* Restore defaults if they were overriden */ if (par_override) { +int restore_status; + par_override =0 ; - status =omap2_mcspi_setup_transfer (spi,NULL ); + restore_status =omap2_mcspi_setup_transfer (spi,NULL ); +if (!status) + status = restore_status; }if (cd && cd->cs_per_word) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2916/3318 RDMA/rxe: refuse to destroy a QP with type 2 MWs still bound
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit 9e61a2ac6590e9c42d2eeef687749781334b300f ]
Binding a type 2 memory window takes a reference on the QP:rxe_do_bind_mw() does rxe_get(qp) and stores it in mw->qp. That reference is released only when the window is invalidated (rxe_do_invalidate_mw() on IB_WR_LOCAL_INV) or the window itself is destroyed (rxe_mw_cleanup()).
rxe_qp_chk_destroy() does not account for those references -- it only refuses when qp->mcg_num is non-zero. So an unprivileged user can bind a type 2 MW to a QP and then destroy the QP while the binding is still live. __rxe_cleanup() cannot drop the QP refcount to zero (the MW still holds a reference), hits its -ETIMEDOUT path, and frees the QP anyway; mw->qp is left dangling. When the MW is later invalidated or deallocated, rxe_mw_cleanup()/rxe_do_invalidate_mw() do rxe_put(mw->qp) on the freed struct rxe_qp -- a use-after-free write (refcount_dec, and complete()/list work if it reaches zero) reachable from userspace. IB_WR_BIND_MW is a local operation, so no peer is required.
Track the number of type 2 MWs bound to a QP and refuse to destroy the QP while that count is non-zero, returning -EBUSY exactly as the existing multicast-attachment check does. The window must be invalidated or deallocated, which drops the reference and the count, before the QP can be destroyed.
--- drivers/infiniband/sw/rxe/rxe_mw.c | 3 +++ drivers/infiniband/sw/rxe/rxe_qp.c | 10 ++++++++++ drivers/infiniband/sw/rxe/rxe_verbs.h | 1 + 3 files changed, 14 insertions(+)
drivers/infiniband/sw/rxe/rxe_mw.c +3 -0
@@ -161,6 +161,7 @@ static void rxe_do_bind_mw(struct rxe_qp *qp, struct rxe_send_wqe *wqe,if (mw->ibmw.type ==IB_MW_TYPE_2 ) {rxe_get (qp); +atomic_inc (&qp->mw_bind_num); mw->qp = qp; } }
@@ -245,6 +246,7 @@ static void rxe_do_invalidate_mw(struct rxe_mw *mw)/* valid type 2 MW will always have a QP pointer */ qp = mw->qp; mw->qp =NULL ; +atomic_dec (&qp->mw_bind_num);rxe_put (qp);/* valid type 2 MW will always have an MR pointer */
@@ -332,6 +334,7 @@ void rxe_mw_cleanup(struct rxe_pool_elem *elem)struct rxe_qp *qp = mw->qp; mw->qp =NULL ; +atomic_dec (&qp->mw_bind_num);rxe_put (qp); }
drivers/infiniband/sw/rxe/rxe_qp.c +10 -0
@@ -810,6 +810,16 @@ int rxe_qp_chk_destroy(struct rxe_qp *qp)return -EBUSY ; } +/* An attempt to destroy a QP while it still holds references for +* bound type 2 memory windows will fail immediately. Otherwise the +* QP is freed with those references outstanding and the windows are +* left pointing at freed memory (use-after-free). +*/ +if (atomic_read (&qp->mw_bind_num)) { +rxe_dbg_qp (qp,"Attempt to destroy while type 2 MWs are bound\n" ); +return -EBUSY ; + } +return 0 ; }
drivers/infiniband/sw/rxe/rxe_verbs.h +1 -0
@@ -222,6 +222,7 @@ struct rxe_qp {struct rxe_av alt_av;atomic_t mcg_num; +atomic_t mw_bind_num;struct sk_buff_head req_pkts;struct sk_buff_head resp_pkts;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2917/3318 RDMA/rxe: reject IB_WR_REG_MR from user QPs in rxe_reg_fast_mr()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit 33afe9909f213d8bb8e80f0b93382dde0f56e2c7 ]
IB_WR_REG_MR is documented as kernel-only ("can not be issued by userspace"), but nothing enforces it. rxe_wr_opcode_info[IB_WR_REG_MR] sets WR_LOCAL_OP_MASK for IB_QPT_RC, a QP type userspace can create, so a user QP that writes opcode = IB_WR_REG_MR into its mmap'd SQ ring reaches rxe_do_local_ops() -> rxe_reg_fast_mr(). That function then trusts the ring-supplied fields:
struct rxe_mr *mr = to_rmr(wqe->wr.wr.reg.mr); ... if (unlikely(mr->state != RXE_MR_STATE_FREE)) /* deref */ ... mr->access = access; /* write */
For a user QP wqe->wr.wr.reg.mr is a fully attacker-chosen pointer, so this is an arbitrary-kernel-address dereference (arbitrary read confirmed, oops). No existing check distinguishes a user QP on this path.
Reject IB_WR_REG_MR for user QPs before dereferencing the supplied pointer.
--- drivers/infiniband/sw/rxe/rxe_mr.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/infiniband/sw/rxe/rxe_mr.c +4 -0
@@ -781,6 +781,10 @@ int rxe_reg_fast_mr(struct rxe_qp *qp, struct rxe_send_wqe *wqe)u32 key = wqe->wr.wr.reg.key;u32 access = wqe->wr.wr.reg.access; +/* IB_WR_REG_MR is a kernel-only op; a user QP must not reach here. */ +if (qp->is_user) +return -EOPNOTSUPP ; +/* user can only register MR in free state */ if (unlikely (mr->state !=RXE_MR_STATE_FREE )) {rxe_dbg_mr (mr,"mr->lkey = 0x%x not free\n" , mr->lkey);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2918/3318 RDMA/rxe: validate inline sge_offset in finish_packet() before indexing inline_data[]
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit 47a9c0338f2e0d4178d77b0d2f529fe1fde84642 ]
For a user QP, rxe_post_send() takes the qp->is_user branch and never runs init_send_wqe(), so dma.length/resid/num_sge/cur_sge/sge_offset all come straight from the mmap'd SQ ring. In the inline send path finish_packet() uses sge_offset directly as an index:
u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset]; memcpy(payload_addr(pkt), tmp, payload);
inline_data is a flex array whose capacity is qp->sq.max_inline, but sge_offset is a u32 from user space, so the source pointer is
displaced arbitrarily past the WQE and the memcpy reads out of
bounds.
commit 126c757e4cd4 ("RDMA/rxe: Validate num_sge/cur_sge before indexing wqe->dma.sge[]") added num_sge/cur_sge checks on the send path but not sge_offset, the
third attacker-controlled index in the same struct.
Read sge_offset once with READ_ONCE() and bound it (and the payload that follows it) by qp->sq.max_inline before indexing, so the value that is validated is the value that is used.
--- drivers/infiniband/sw/rxe/rxe_req.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_req.c +8 -1
@@ -511,7 +511,14 @@ static int finish_packet(struct rxe_qp *qp, struct rxe_av *av,if (pkt->mask &RXE_WRITE_OR_SEND_MASK ) {if (wqe->wr.send_flags &IB_SEND_INLINE ) { -u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset]; +u32 sge_offset =READ_ONCE (wqe->dma.sge_offset); +u8 *tmp; + +if (unlikely (sge_offset > (u32 )qp->sq.max_inline || + payload > (u32 )qp->sq.max_inline - sge_offset)) +return -EINVAL ; + + tmp = &wqe->dma.inline_data[sge_offset];memcpy (payload_addr (pkt), tmp, payload);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2919/3318 RDMA/rxe: Make rxe_loopback match rxe_send behavior
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit 55bec1c440e6852e907c47cd33fbbf63fcc5f1ba ]
The rxe send path currently counts the number of skbs outstanding between the rxe driver and the ethernet driver to prevent too many packets to accumulate waiting to send. This patch makes the local loopback path behave the same way. The loopback path forwards the packets to the receive path which will eventually call kfree_skb on all packets and drop the qp references. This makes the loopback path more useful for software testing.
Stable-dep-of: 56a27df6cedd ("RDMA/rxe: Fix out-of-range unsigned-to-signed conversion for RDMA message in 2GiB size")
--- drivers/infiniband/sw/rxe/rxe_net.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/infiniband/sw/rxe/rxe_net.c +6 -0
@@ -386,6 +386,12 @@ static int rxe_loopback(struct sk_buff *skb, struct rxe_pkt_info *pkt) {memcpy (SKB_TO_PKT (skb), pkt,sizeof (*pkt)); + skb->destructor = rxe_skb_tx_dtor; + skb->sk = pkt->qp->sk->sk; + +rxe_get (pkt->qp); +atomic_inc (&pkt->qp->skb_out); +if (skb->protocol ==htons (ETH_P_IP ))skb_pull (skb,sizeof (struct iphdr ));else
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2920/3318 RDMA/rxe: Let destroy qp succeed with stuck packet
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bob Pearson <[email protected]>
[ Upstream commit 1a633bdc8fd9e9e4a9f9a668ae122edfc5aacc86 ]
In some situations a sent packet may get queued in the NIC longer than than timeout of a ULP. Currently if this happens the ULP may try to reset the link by destroying the qp and setting up an alternate connection but will fail because the rxe driver is waiting for the packet to finish getting sent and be returned to the skb destructor function where the qp reference holding things up will be dropped. This patch modifies the way that the qp is passed to the destructor to pass the qp index and not a qp pointer. Then the destructor will attempt to lookup the qp from its index and if it fails exit early. This requires taking a reference on the struct sock rather than the qp allowing the qp to be destroyed while the sk is still around waiting for the packet to finish.
Stable-dep-of: 56a27df6cedd ("RDMA/rxe: Fix out-of-range unsigned-to-signed conversion for RDMA message in 2GiB size")
--- drivers/infiniband/sw/rxe/rxe_net.c | 42 +++++++++++++++++++++-------- drivers/infiniband/sw/rxe/rxe_qp.c | 2 +- 2 files changed, 32 insertions(+), 12 deletions(-)
drivers/infiniband/sw/rxe/rxe_net.c +31 -11
@@ -345,25 +345,44 @@ int rxe_prepare(struct rxe_av *av, struct rxe_pkt_info *pkt,static void rxe_skb_tx_dtor (struct sk_buff *skb) { -struct sock *sk = skb->sk; -struct rxe_qp *qp = sk->sk_user_data; -int skb_out =atomic_dec_return (&qp->skb_out); +struct net_device *ndev = skb->dev; +struct rxe_dev *rxe; +unsigned int qp_index; +struct rxe_qp *qp; +int skb_out; + + rxe =rxe_get_dev_from_net (ndev); +if (!rxe &&is_vlan_dev (ndev)) + rxe =rxe_get_dev_from_net (vlan_dev_real_dev (ndev)); +if (WARN_ON (!rxe)) +return ; -if (unlikely (qp->need_req_skb && - skb_out <RXE_INFLIGHT_SKBS_PER_QP_LOW )) + qp_index = (int )(uintptr_t )skb->sk->sk_user_data; +if (!qp_index) +return ; + + qp =rxe_pool_get_index (&rxe->qp_pool, qp_index); +if (!qp) + goto put_dev; + + skb_out =atomic_dec_return (&qp->skb_out); +if (qp->need_req_skb && skb_out <RXE_INFLIGHT_SKBS_PER_QP_LOW )rxe_sched_task (&qp->send_task);rxe_put (qp); +put_dev: +ib_device_put (&rxe->ib_dev); +sock_put (skb->sk); }static int rxe_send (struct sk_buff *skb,struct rxe_pkt_info *pkt) {int err; +struct sock *sk = pkt->qp->sk->sk; +sock_hold (sk); + skb->sk = sk; skb->destructor = rxe_skb_tx_dtor; - skb->sk = pkt->qp->sk->sk; - -rxe_get (pkt->qp);atomic_inc (&pkt->qp->skb_out);if (skb->protocol ==htons (ETH_P_IP ))
@@ -384,12 +403,13 @@ static int rxe_send(struct sk_buff *skb, struct rxe_pkt_info *pkt)*/ static int rxe_loopback (struct sk_buff *skb,struct rxe_pkt_info *pkt) { +struct sock *sk = pkt->qp->sk->sk; +memcpy (SKB_TO_PKT (skb), pkt,sizeof (*pkt)); +sock_hold (sk); + skb->sk = sk; skb->destructor = rxe_skb_tx_dtor; - skb->sk = pkt->qp->sk->sk; - -rxe_get (pkt->qp);atomic_inc (&pkt->qp->skb_out);if (skb->protocol ==htons (ETH_P_IP ))
drivers/infiniband/sw/rxe/rxe_qp.c +1 -1
@@ -245,7 +245,7 @@ static int rxe_qp_init_req(struct rxe_dev *rxe, struct rxe_qp *qp, err =sock_create_kern (&init_net,AF_INET ,SOCK_DGRAM ,0 , &qp->sk);if (err <0 )return err; - qp->sk->sk->sk_user_data = qp; + qp->sk->sk->sk_user_data = (void *)(uintptr_t )qp->elem.index;/* pick a source UDP port number for this QP based on * the source QPN. this spreads traffic for different QPs
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2921/3318 RDMA/rxe: Hold netdev reference for transmit skbs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: xiongweimin <[email protected]>
[ Upstream commit 19881618ffa454c63e6b6bf34acd7cac28c695dc ]
rxe_init_packet() assigns skb->dev from an RCU-protected GID attribute without holding a netdev reference. If the netdev is unregistered before the skb is freed, subsequent accesses to skb->dev are unsafe.
Hold a reference with dev_hold() when the skb is initialized and release it from the transmit destructor or via rxe_put_skb() on error paths that run before the destructor is installed.
skb->dev can change on the TX path (VLAN/bond/tunnel, ip_finish_output2, etc.), so put must use the same netdev that was held. Stash that pointer in skb_shinfo()->destructor_arg: skb->cb is already used by rxe_pkt_info and is rewritten by IP control blocks.
To avoid blocking netdev unregistration on held skbs, flush all QPs to the error state on NETDEV_GOING_DOWN and NETDEV_UNREGISTER so pending TX work is drained and references can be dropped.
Stable-dep-of: 56a27df6cedd ("RDMA/rxe: Fix out-of-range unsigned-to-signed conversion for RDMA message in 2GiB size")
--- drivers/infiniband/sw/rxe/rxe_loc.h | 1 + drivers/infiniband/sw/rxe/rxe_net.c | 68 ++++++++++++++++++++++++++-- drivers/infiniband/sw/rxe/rxe_req.c | 2 +- drivers/infiniband/sw/rxe/rxe_resp.c | 4 +- 4 files changed, 68 insertions(+), 7 deletions(-)
drivers/infiniband/sw/rxe/rxe_loc.h +1 -0
@@ -91,6 +91,7 @@ void rxe_mw_cleanup(struct rxe_pool_elem *elem);/* rxe_net.c */ struct sk_buff *rxe_init_packet (struct rxe_dev *rxe,struct rxe_av *av,int paylen,struct rxe_pkt_info *pkt); +void rxe_put_skb (struct sk_buff *skb);int rxe_prepare (struct rxe_av *av,struct rxe_pkt_info *pkt,struct sk_buff *skb); int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt,
drivers/infiniband/sw/rxe/rxe_net.c +64 -4
111 lines not on this page · raw message
drivers/infiniband/sw/rxe/rxe_req.c +1 -1
@@ -853,7 +853,7 @@ int rxe_requester(struct rxe_qp *qp) wqe->status =IB_WC_LOC_PROT_ERR ; else wqe->status = IB_WC_LOC_QP_OP_ERR; -kfree_skb (skb); +rxe_put_skb (skb);if (ah)rxe_put (ah); goto err;
drivers/infiniband/sw/rxe/rxe_resp.c +2 -2
@@ -849,7 +849,7 @@ static struct sk_buff *prepare_ack_packet(struct rxe_qp *qp, err =rxe_prepare (&qp->pri_av, ack, skb);if (err) { -kfree_skb (skb); +rxe_put_skb (skb);return NULL ; }
@@ -977,7 +977,7 @@ static enum resp_states read_reply(struct rxe_qp *qp, err =rxe_mr_copy (mr, res->read.va,payload_addr (&ack_pkt), payload,RXE_FROM_MR_OBJ );if (err) { -kfree_skb (skb); +rxe_put_skb (skb); state =RESPST_ERR_RKEY_VIOLATION ; goto err_out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2922/3318 RDMA/rxe: Fix out-of-range unsigned-to-signed conversion for RDMA message in 2GiB size
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Honggang LI <[email protected]>
[ Upstream commit 56a27df6cedd4f3918969d61c7b9d3cc177b2d1b ]
When RDMA READ request for 2GiB in single WR, res->read.resid is u32 0x80000000, which is INT_MIN (-2147483648).
payload = min_t(int, res->read.resid, mtu);
The min_t function will return -2147483648 for payload. The wrong size is propagated through call chain, read_reply -> prepare_ack_packet -> rxe_init_packet -> alloc_skb . alloc_skb failed because of invalid size. The passive side failed to emit response packet for RDMA READ request.
After fixed it, the active side of RDMA READ failed with error code "IB_WC_LOC_PROT_ERR". When RDMA_READ_RESPONSE_FIRST packet recived by the active side, do_read call copy_data. dma->resid is u32 0x80000000.
int resid = dma->resid;
This conversion set resid to -2147483648. copy_data abort as length greater than resid.
RDMA SEND and WRITE 2GiB message works too, after fixed these two bugs.
--- drivers/infiniband/sw/rxe/rxe_loc.h | 4 ++-- drivers/infiniband/sw/rxe/rxe_mr.c | 8 ++++---- drivers/infiniband/sw/rxe/rxe_net.c | 2 +- drivers/infiniband/sw/rxe/rxe_resp.c | 17 +++++++++-------- 4 files changed, 16 insertions(+), 15 deletions(-)
drivers/infiniband/sw/rxe/rxe_loc.h +2 -2
@@ -66,7 +66,7 @@ int rxe_flush_pmem_iova(struct rxe_mr *mr, u64 iova, unsigned int length);int rxe_mr_copy (struct rxe_mr *mr,u64 iova,void *addr,unsigned int length,enum rxe_mr_copy_dir dir);int copy_data (struct rxe_pd *pd,int access,struct rxe_dma_info *dma, -void *addr,int length,enum rxe_mr_copy_dir dir); +void *addr,u32 length,enum rxe_mr_copy_dir dir);int rxe_map_mr_sg (struct ib_mr *ibmr,struct scatterlist *sg,int sg_nents,unsigned int *sg_offset); int rxe_mr_do_atomic_op(struct rxe_mr *mr, u64 iova, int opcode,
@@ -90,7 +90,7 @@ void rxe_mw_cleanup(struct rxe_pool_elem *elem);/* rxe_net.c */ struct sk_buff *rxe_init_packet (struct rxe_dev *rxe,struct rxe_av *av, -int paylen,struct rxe_pkt_info *pkt); +u32 paylen,struct rxe_pkt_info *pkt);void rxe_put_skb (struct sk_buff *skb);int rxe_prepare (struct rxe_av *av,struct rxe_pkt_info *pkt,struct sk_buff *skb);
drivers/infiniband/sw/rxe/rxe_mr.c +4 -4
@@ -417,13 +417,13 @@ int copy_data(int access, struct rxe_dma_info *dma, void *addr, - int length, + u32 length, enum rxe_mr_copy_dir dir) { - int bytes; + u32 bytes;struct rxe_sge *sge = &dma->sge[dma->cur_sge]; -int offset = dma->sge_offset; -int resid = dma->resid; +u32 offset = dma->sge_offset; +u32 resid = dma->resid;struct rxe_mr *mr =NULL ;u64 iova;int err;
drivers/infiniband/sw/rxe/rxe_net.c +1 -1
@@ -510,7 +510,7 @@ int rxe_xmit_packet(struct rxe_qp *qp, struct rxe_pkt_info *pkt, }struct sk_buff *rxe_init_packet (struct rxe_dev *rxe,struct rxe_av *av, -int paylen,struct rxe_pkt_info *pkt) +u32 paylen,struct rxe_pkt_info *pkt) {unsigned int hdr_len;struct sk_buff *skb =NULL ;
drivers/infiniband/sw/rxe/rxe_resp.c +9 -8
@@ -610,7 +610,7 @@ static enum resp_states check_rkey(struct rxe_qp *qp, }static enum resp_states send_data_in (struct rxe_qp *qp,void *data_addr, -int data_len) +u32 data_len) {int err;
@@ -810,20 +810,21 @@ static enum resp_states atomic_write_reply(struct rxe_qp *qp,static struct sk_buff *prepare_ack_packet (struct rxe_qp *qp,struct rxe_pkt_info *ack,int opcode, -int payload, +u32 payload,u32 psn,u8 syndrome) {struct rxe_dev *rxe =to_rdev (qp->ibqp.device);struct sk_buff *skb; -int paylen; -int pad; +u32 paylen; +u32 pad =0 ;int err;/* * allocate packet */ - pad = (-payload) &0x3 ; +if (payload %4 ) + pad =4 - payload %4 ; paylen = rxe_opcode[opcode].length + payload + pad +RXE_ICRC_SIZE ; skb =rxe_init_packet (rxe, &qp->pri_av, paylen, ack);
@@ -917,9 +918,9 @@ static enum resp_states read_reply(struct rxe_qp *qp, {struct rxe_pkt_info ack_pkt;struct sk_buff *skb; -int mtu = qp->mtu; +u32 mtu = qp->mtu;enum resp_states state; -int payload; +u32 payload;int opcode;int err;struct resp_res *res = qp->resp.res;
@@ -965,7 +966,7 @@ static enum resp_states read_reply(struct rxe_qp *qp, res->state = rdatm_res_state_next; - payload =min_t (int, res->read.resid, mtu); + payload =min (res->read.resid, mtu); skb =prepare_ack_packet (qp, &ack_pkt, opcode, payload, res->cur_psn,AETH_ACK_UNLIMITED );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2923/3318 RDMA/rxe: bound the WQE opcode before indexing rxe_wr_opcode_info[]
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngsung Ahn <[email protected]>
[ Upstream commit c887e53e1c852b88bd5442d1bf4717ee3e7aadda ]
wr_opcode_mask() indexes the global rxe_wr_opcode_info[] array with a caller-supplied opcode and no bounds check. For a user QP the WQE comes from an mmap'd SQ ring, so wqe->wr.opcode is an attacker-controlled __u32 read back by the requester (req_next_wqe() -> rxe_requester()); rxe_post_send() takes the qp->is_user branch and never runs validate_send_wr(), whose only opcode check is itself !wr_opcode_mask() (it indexes before it checks). rxe_wr_opcode_info[] has entries only up to IB_WR_REG_MR, so an out-of-range opcode reads out of bounds and the result is used as a mask and dereferenced; observed as a KASAN global-out-of-bounds "Read of size 4" and a wild-pointer oops.
Return a zero mask for an out-of-range opcode, matching how validate_send_wr() already treats a zero mask (an invalid WR), so no path indexes the array out of bounds.
--- drivers/infiniband/sw/rxe/rxe_loc.h | 3 +++ 1 file changed, 3 insertions(+)
drivers/infiniband/sw/rxe/rxe_loc.h +3 -0
@@ -179,6 +179,9 @@ void rxe_comp_queue_pkt(struct rxe_qp *qp, struct sk_buff *skb);static inline unsigned int wr_opcode_mask (int opcode,struct rxe_qp *qp) { +if (unlikely (opcode <0 || opcode >IB_WR_REG_MR )) +return 0 ; +return rxe_wr_opcode_info[opcode].mask[qp->ibqp.qp_type]; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2924/3318 selftests/ftrace: Avoid unlink error on first run
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaewon Jung <[email protected]>
[ Upstream commit 0abfa9ad5c6917cb9a509276f32009d944b3c269 ]
On the first run, ftracetest tries to unlink a symlink that does not exist.
Use rm -f to avoid the "No such file or directory" error.
--- tools/testing/selftests/ftrace/ftracetest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/ftrace/ftracetest +1 -1
@@ -223,7 +223,7 @@ else mkdir -p $LOG_DIR || errexit "Failed to make a log directory: $LOG_DIR" date > $LOG_FILE if [ "x-$LINK_PTR" != "x-" ]; then - unlink $LINK_PTR + rm -f $LINK_PTR ln -fs $LOG_DATE $LINK_PTR fi fi
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2925/3318 selftests/bpf: Create the vxlan devices of test_tunnel with their MAC
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 33cbc5c2cadfe3b43f024e89880dd8fe2efb3a2e ]
The vxlan tests of test_tunnel create a tunnel device in the initial netns with "ip link add", and then give it the MAC address that the static neighbor entry at the other end points to with "ip link set".
systemd-udevd assigns new devices of the initial netns a MAC address of its own, following its MACAddressPolicy, when it handles their uevent. When it gets to that after the test set the address, the replies sent to the configured MAC are dropped as meant for another host, and the ping of vxlan_tunnel fails after 10 seconds.
Pass the address to "ip link add". udevd leaves alone the address of a device that was created with one.
--- .../testing/selftests/bpf/prog_tests/test_tunnel.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
tools/testing/selftests/bpf/prog_tests/test_tunnel.c +6 -7
@@ -132,9 +132,9 @@ static int add_vxlan_tunnel(void) IP4_ADDR2_VETH1, MAC_VETH1);/* root namespace */ -SYS (fail,"ip link add dev %s type vxlan external gbp dstport 4789" , -VXLAN_TUNL_DEV1 ); -SYS (fail,"ip link set dev %s address %s up" ,VXLAN_TUNL_DEV1 ,MAC_TUNL_DEV1 ); +SYS (fail,"ip link add dev %s address %s type vxlan external gbp dstport 4789" , +VXLAN_TUNL_DEV1 ,MAC_TUNL_DEV1 ); +SYS (fail,"ip link set dev %s up" ,VXLAN_TUNL_DEV1 );SYS (fail,"ip addr add dev %s %s/24" ,VXLAN_TUNL_DEV1 ,IP4_ADDR_TUNL_DEV1 );SYS (fail,"ip neigh add %s lladdr %s dev %s" ,IP4_ADDR_TUNL_DEV0 ,MAC_TUNL_DEV0 ,VXLAN_TUNL_DEV1 );
@@ -169,11 +169,10 @@ static int add_ip6vxlan_tunnel(void) IP6VXLAN_TUNL_DEV0, MAC_TUNL_DEV0);/* root namespace */ -SYS (fail,"ip link add dev %s type vxlan external dstport 4789" , -IP6VXLAN_TUNL_DEV1 ); -SYS (fail,"ip addr add dev %s %s/24" ,IP6VXLAN_TUNL_DEV1 ,IP4_ADDR_TUNL_DEV1 ); -SYS (fail,"ip link set dev %s address %s up" , +SYS (fail,"ip link add dev %s address %s type vxlan external dstport 4789" ,IP6VXLAN_TUNL_DEV1 ,MAC_TUNL_DEV1 ); +SYS (fail,"ip addr add dev %s %s/24" ,IP6VXLAN_TUNL_DEV1 ,IP4_ADDR_TUNL_DEV1 ); +SYS (fail,"ip link set dev %s up" ,IP6VXLAN_TUNL_DEV1 );return 0 ; fail:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2926/3318 ALSA: core: Serialize snd_refcount put and sync
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 6904743ab77e0684dff319f3806ef982e5eea6cf ]
When a thread tries to sync-and-destroy the resource with snd_refcount_sync(), it might lead to a UAF in a very slight time window. Namely, snd_refount_put() calls wake_up() after atomic_dec_and_test(), but wait_event() in snd_refcount_sync() checks the condition via atomic_test() without serialization, hence the thread that called snd_refcount_sync() can continue immediately to release the resource before another thread calls wake_up().
For avoiding the race above, introduce the spinlock and take it at snd_refcount_put() and snd_refcount_sync() in order to serialize the operations.
--- include/sound/core.h | 1 + sound/core/misc.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-)
include/sound/core.h +1 -0
@@ -84,6 +84,7 @@ struct snd_device {struct snd_refcount {atomic_t count;wait_queue_head_t waiter; +spinlock_t lock; };void snd_refcount_init (struct snd_refcount *ref);
sound/core/misc.c +4 -1
@@ -254,11 +254,13 @@ void snd_refcount_init(struct snd_refcount *ref) {atomic_set (&ref->count,0 );init_waitqueue_head (&ref->waiter); +spin_lock_init (&ref->lock); }EXPORT_SYMBOL_GPL (snd_refcount_init);void snd_refcount_put (struct snd_refcount *ref) { +guard (spinlock_irqsave)(&ref->lock);if (atomic_dec_and_test (&ref->count))wake_up (&ref->waiter); }
@@ -266,6 +268,7 @@ EXPORT_SYMBOL_GPL(snd_refcount_put);void snd_refcount_sync (struct snd_refcount *ref) { -wait_event (ref->waiter, !atomic_read (&ref->count)); +guard (spinlock_irq)(&ref->lock); +wait_event_lock_irq (ref->waiter, !atomic_read (&ref->count), ref->lock); }EXPORT_SYMBOL_GPL (snd_refcount_sync);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2927/3318 kselftest/arm64: signal: copy each test binary only once
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 7b3b147c4104f8211ad356a78cff9a2dcd966312 ]
The signal tests are built in testcases/ and then copied to the output directory. The copy rule lists every generated program as a target and copies all of them in each recipe:
$(TEST_GEN_PROGS): $(PROGS)
cp $(PROGS) $(OUTPUT)/In a parallel build make runs that recipe once for each program, so several cp processes write the same destination files at the same time. cp then fails with "cannot create regular file ...: File exists", which fails the arm64 build even though every test compiled. A cross build of the arm64 signal tests at -j8 hit this in all of 8 runs.
Use a static pattern rule so that each output depends on, and copies, only its own binary.
--- tools/testing/selftests/arm64/signal/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/arm64/signal/Makefile +2 -2
@@ -17,8 +17,8 @@ TEST_GEN_PROGS := $(notdir $(PROGS)) # the toplevel makefile include ../../lib.mk -$(TEST_GEN_PROGS): $(PROGS) - cp $(PROGS) $(OUTPUT)/ +$(TEST_GEN_PROGS): $(OUTPUT)/%: testcases/% + cp $< $@ # Common test-unit targets to build common-layout test-cases executables # Needs secondary expansion to properly include the testcase c-file in pre-reqs
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2928/3318 IB/rdmavt: Fix error unwind path for qp_priv_init() in rvt_create_qp()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Serhat Kumral <[email protected]>
[ Upstream commit dd36137b218ad6f18ed15e6279412d7fc160980c ]
If driver_f.qp_priv_init() fails, execution jumps to bail_rq_wq, which bypasses bail_qpn. Because alloc_qpn() has already succeeded at this point, the allocated QP number is left unreleased.
Jump to bail_qpn instead to ensure the QPN is properly freed via rvt_free_qpn().
--- drivers/infiniband/sw/rdmavt/qp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rdmavt/qp.c +1 -1
@@ -1175,7 +1175,7 @@ int rvt_create_qp(struct ib_qp *ibqp, struct ib_qp_init_attr *init_attr,if (rdi->driver_f.qp_priv_init) { ret = rdi->driver_f.qp_priv_init (rdi, qp, init_attr);if (ret) - goto bail_rq_wq; + goto bail_qpn; }break ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2929/3318 RDMA/irdma: Fix FRWR IRDMAQPSQ_PBLADDR field population
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jacob Moroni <[email protected]>
[ Upstream commit 59df57262e6fa9e6f4aa76d6d324134777c702a0 ]
Previously, the IRDMAQPSQ_PBLADDR FRWR WQE field was being populated using a mask that was right-shifted, whereas it should have been the address being right-shifted.
This ended up working fine in many cases because the lowermost 12 bits are always zero (the addresses are page aligned) and the uppermost 12 bits are usually zero too, but it could break for DMA addresses that are wider than 52 bits.
Fix this by right-shifting the address instead of the mask, similar to how it was done in the original i40iw driver.
Tested with NFS over RDMA with some added debug logs to ensure it was hitting both the direct (single page) path as well as multi page (< 512).
--- drivers/infiniband/hw/irdma/ctrl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/irdma/ctrl.c +1 -1
@@ -1326,7 +1326,7 @@ int irdma_sc_mr_fast_register(struct irdma_sc_qp *qp, info->first_pm_pbl_index >> 16);set_64bit_val (wqe,8 ,FIELD_PREP (IRDMAQPSQ_FIRSTPMPBLIDXHI , temp) | -FIELD_PREP (IRDMAQPSQ_PBLADDR >>IRDMA_HW_PAGE_SHIFT , info->reg_addr_pa)); +FIELD_PREP (IRDMAQPSQ_PBLADDR , info->reg_addr_pa >>IRDMA_HW_PAGE_SHIFT ));set_64bit_val (wqe,16 , info->total_len |FIELD_PREP (IRDMAQPSQ_FIRSTPMPBLIDXLO , info->first_pm_pbl_index));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2930/3318 ASoC: intel: avs: convert not to use asoc_xxx()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuninori Morimoto <[email protected]>
[ Upstream commit 5d2d1a48a2f7734aee273303fadbb5929b5b8d37 ]
ASoC is now unified asoc_xxx() into snd_soc_xxx(). This patch convert asoc_xxx() to snd_soc_xxx().
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- sound/soc/intel/avs/boards/da7219.c | 4 +-- sound/soc/intel/avs/boards/es8336.c | 8 ++--- sound/soc/intel/avs/boards/i2s_test.c | 2 +- sound/soc/intel/avs/boards/max98373.c | 2 +- sound/soc/intel/avs/boards/max98927.c | 2 +- sound/soc/intel/avs/boards/nau8825.c | 8 ++--- sound/soc/intel/avs/boards/rt274.c | 4 +-- sound/soc/intel/avs/boards/rt286.c | 8 ++--- sound/soc/intel/avs/boards/rt298.c | 8 ++--- sound/soc/intel/avs/boards/rt5663.c | 8 ++--- sound/soc/intel/avs/boards/rt5682.c | 8 ++--- sound/soc/intel/avs/boards/ssm4567.c | 4 +-- sound/soc/intel/avs/pcm.c | 44 +++++++++++++-------------- 13 files changed, 55 insertions(+), 55 deletions(-)
sound/soc/intel/avs/boards/da7219.c +2 -2
@@ -90,7 +90,7 @@ static const struct snd_soc_jack_pin card_headset_pins[] = {static int avs_da7219_codec_init (struct snd_soc_pcm_runtime *runtime) { -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );struct snd_soc_component *component = codec_dai->component;struct snd_soc_card *card = runtime->card;struct snd_soc_jack_pin *pins;
@@ -140,7 +140,7 @@ static int avs_da7219_codec_init(struct snd_soc_pcm_runtime *runtime)static void avs_da7219_codec_exit (struct snd_soc_pcm_runtime *rtd) { -snd_soc_component_set_jack (asoc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); } static int
sound/soc/intel/avs/boards/es8336.c +4 -4
@@ -97,7 +97,7 @@ static struct snd_soc_jack_pin card_headset_pins[] = {static int avs_es8336_codec_init (struct snd_soc_pcm_runtime *runtime) { -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );struct snd_soc_component *component = codec_dai->component;struct snd_soc_card *card = runtime->card;struct snd_soc_jack_pin *pins;
@@ -138,7 +138,7 @@ static int avs_es8336_codec_init(struct snd_soc_pcm_runtime *runtime)static void avs_es8336_codec_exit (struct snd_soc_pcm_runtime *runtime) {struct avs_card_drvdata *data =snd_soc_card_get_drvdata (runtime->card); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );snd_soc_component_set_jack (codec_dai->component,NULL ,NULL );gpiod_put (data->gpiod);
@@ -147,8 +147,8 @@ static void avs_es8336_codec_exit(struct snd_soc_pcm_runtime *runtime)static int avs_es8336_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *runtime =asoc_substream_to_rtd (substream); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_pcm_runtime *runtime =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );int clk_freq;int ret;
sound/soc/intel/avs/boards/i2s_test.c +1 -1
@@ -32,7 +32,7 @@ static int avs_create_dai_link(struct device *dev, const char *platform_name, inreturn -ENOMEM ; dl->cpus->dai_name =devm_kasprintf (dev,GFP_KERNEL ,"SSP%d Pin" , ssp_port); - dl->codecs = &asoc_dummy_dlc; + dl->codecs = &snd_soc_dummy_dlc;if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)return -ENOMEM ;
sound/soc/intel/avs/boards/max98373.c +1 -1
@@ -66,7 +66,7 @@ avs_max98373_be_fixup(struct snd_soc_pcm_runtime *runrime, struct snd_pcm_hw_parstatic int avs_max98373_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *runtime =asoc_substream_to_rtd (substream); +struct snd_soc_pcm_runtime *runtime =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *codec_dai;int ret, i;
sound/soc/intel/avs/boards/max98927.c +1 -1
@@ -66,7 +66,7 @@ avs_max98927_be_fixup(struct snd_soc_pcm_runtime *runrime, struct snd_pcm_hw_parstatic int avs_max98927_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *runtime =asoc_substream_to_rtd (substream); +struct snd_soc_pcm_runtime *runtime =snd_soc_substream_to_rtd (substream);struct snd_soc_dai *codec_dai;int ret =0 ;int i;
sound/soc/intel/avs/boards/nau8825.c +4 -4
@@ -106,12 +106,12 @@ static int avs_nau8825_codec_init(struct snd_soc_pcm_runtime *runtime)snd_jack_set_key (jack->jack,SND_JACK_BTN_2 ,KEY_VOLUMEUP );snd_jack_set_key (jack->jack,SND_JACK_BTN_3 ,KEY_VOLUMEDOWN ); -return snd_soc_component_set_jack (asoc_rtd_to_codec (runtime,0 )->component, jack,NULL ); +return snd_soc_component_set_jack (snd_soc_rtd_to_codec (runtime,0 )->component, jack,NULL ); }static void avs_nau8825_codec_exit (struct snd_soc_pcm_runtime *rtd) { -snd_soc_component_set_jack (asoc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); } static int
@@ -138,8 +138,8 @@ avs_nau8825_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcm_hw_parastatic int avs_nau8825_trigger (struct snd_pcm_substream *substream,int cmd) {struct snd_pcm_runtime *runtime = substream->runtime; -struct snd_soc_pcm_runtime *rtm =asoc_substream_to_rtd (substream); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (rtm,0 ); +struct snd_soc_pcm_runtime *rtm =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtm,0 );int ret =0 ;switch (cmd) {
sound/soc/intel/avs/boards/rt274.c +2 -2
@@ -87,7 +87,7 @@ static struct snd_soc_jack_pin card_headset_pins[] = {static int avs_rt274_codec_init (struct snd_soc_pcm_runtime *runtime) { -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );struct snd_soc_component *component = codec_dai->component;struct snd_soc_jack_pin *pins;struct snd_soc_jack *jack;
@@ -121,7 +121,7 @@ static int avs_rt274_codec_init(struct snd_soc_pcm_runtime *runtime)static void avs_rt274_codec_exit (struct snd_soc_pcm_runtime *rtd) { -snd_soc_component_set_jack (asoc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); }static int avs_rt274_be_fixup (struct snd_soc_pcm_runtime *runtime,struct snd_pcm_hw_params *params)
sound/soc/intel/avs/boards/rt286.c +4 -4
@@ -67,12 +67,12 @@ static int avs_rt286_codec_init(struct snd_soc_pcm_runtime *runtime)if (ret)return ret; -return snd_soc_component_set_jack (asoc_rtd_to_codec (runtime,0 )->component, jack,NULL ); +return snd_soc_component_set_jack (snd_soc_rtd_to_codec (runtime,0 )->component, jack,NULL ); }static void avs_rt286_codec_exit (struct snd_soc_pcm_runtime *rtd) { -snd_soc_component_set_jack (asoc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); }static int avs_rt286_be_fixup (struct snd_soc_pcm_runtime *runtime,struct snd_pcm_hw_params *params)
@@ -98,8 +98,8 @@ static int avs_rt286_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcstatic int avs_rt286_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *runtime =asoc_substream_to_rtd (substream); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_pcm_runtime *runtime =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );int ret; ret =snd_soc_dai_set_sysclk (codec_dai,RT286_SCLK_S_PLL ,24000000 ,SND_SOC_CLOCK_IN );
sound/soc/intel/avs/boards/rt298.c +4 -4
@@ -78,12 +78,12 @@ static int avs_rt298_codec_init(struct snd_soc_pcm_runtime *runtime)if (ret)return ret; -return snd_soc_component_set_jack (asoc_rtd_to_codec (runtime,0 )->component, jack,NULL ); +return snd_soc_component_set_jack (snd_soc_rtd_to_codec (runtime,0 )->component, jack,NULL ); }static void avs_rt298_codec_exit (struct snd_soc_pcm_runtime *rtd) { -snd_soc_component_set_jack (asoc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); }static int avs_rt298_be_fixup (struct snd_soc_pcm_runtime *runtime,struct snd_pcm_hw_params *params)
@@ -109,8 +109,8 @@ static int avs_rt298_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcstatic int avs_rt298_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *rtd =asoc_substream_to_rtd (substream); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (rtd,0 ); +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 );unsigned int clk_freq;int ret;
sound/soc/intel/avs/boards/rt5663.c +4 -4
@@ -79,14 +79,14 @@ static int avs_rt5663_codec_init(struct snd_soc_pcm_runtime *runtime)snd_jack_set_key (jack->jack,SND_JACK_BTN_2 ,KEY_VOLUMEUP );snd_jack_set_key (jack->jack,SND_JACK_BTN_3 ,KEY_VOLUMEDOWN ); -snd_soc_component_set_jack (asoc_rtd_to_codec (runtime,0 )->component, jack,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (runtime,0 )->component, jack,NULL );return 0 ; }static void avs_rt5663_codec_exit (struct snd_soc_pcm_runtime *runtime) { -snd_soc_component_set_jack (asoc_rtd_to_codec (runtime,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (runtime,0 )->component,NULL ,NULL ); } static int
@@ -113,8 +113,8 @@ avs_rt5663_be_fixup(struct snd_soc_pcm_runtime *runtime, struct snd_pcm_hw_paramstatic int avs_rt5663_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *rtd =asoc_substream_to_rtd (substream); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (rtd,0 ); +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (rtd,0 );int ret;/* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
sound/soc/intel/avs/boards/rt5682.c +4 -4
@@ -92,7 +92,7 @@ static struct snd_soc_jack_pin card_jack_pins[] = {static int avs_rt5682_codec_init (struct snd_soc_pcm_runtime *runtime) { -struct snd_soc_component *component =asoc_rtd_to_codec (runtime,0 )->component; +struct snd_soc_component *component =snd_soc_rtd_to_codec (runtime,0 )->component;struct snd_soc_card *card = runtime->card;struct snd_soc_jack_pin *pins;struct snd_soc_jack *jack;
@@ -137,14 +137,14 @@ static int avs_rt5682_codec_init(struct snd_soc_pcm_runtime *runtime)static void avs_rt5682_codec_exit (struct snd_soc_pcm_runtime *rtd) { -snd_soc_component_set_jack (asoc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); +snd_soc_component_set_jack (snd_soc_rtd_to_codec (rtd,0 )->component,NULL ,NULL ); }static int avs_rt5682_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *params) { -struct snd_soc_pcm_runtime *runtime =asoc_substream_to_rtd (substream); -struct snd_soc_dai *codec_dai =asoc_rtd_to_codec (runtime,0 ); +struct snd_soc_pcm_runtime *runtime =snd_soc_substream_to_rtd (substream); +struct snd_soc_dai *codec_dai =snd_soc_rtd_to_codec (runtime,0 );int pll_source, freq_in, freq_out;int ret;
sound/soc/intel/avs/boards/ssm4567.c +2 -2
@@ -50,12 +50,12 @@ static int avs_ssm4567_codec_init(struct snd_soc_pcm_runtime *runtime)int ret;/* Slot 1 for left */ - ret =snd_soc_dai_set_tdm_slot (asoc_rtd_to_codec (runtime,0 ),0x01 ,0x01 ,2 ,48 ); + ret =snd_soc_dai_set_tdm_slot (snd_soc_rtd_to_codec (runtime,0 ),0x01 ,0x01 ,2 ,48 );if (ret <0 )return ret;/* Slot 2 for right */ - ret =snd_soc_dai_set_tdm_slot (asoc_rtd_to_codec (runtime,1 ),0x02 ,0x02 ,2 ,48 ); + ret =snd_soc_dai_set_tdm_slot (snd_soc_rtd_to_codec (runtime,1 ),0x02 ,0x02 ,2 ,48 );if (ret <0 )return ret;
sound/soc/intel/avs/pcm.c +22 -22
174 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2931/3318 ALSA: pcm: Introduce MSBITS subformat interface
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jaroslav Kysela <[email protected]>
[ Upstream commit 2112aa034907c428785e1a5730927181276ee45b ]
Improve granularity of format selection for S32/U32 formats by adding constants representing 20, 24 and MAX most significant bits.
The MAX means the maximum number of significant bits which can the physical format hold. For 32-bit formats, MAX is related to 32 bits. For 8-bit formats, MAX is related to 8 bits etc.
As there is only one user currently (format S32_LE), subformat is represented by a simple u32 and stores flags only for that one user alone. The approach of subformat being part of struct snd_pcm_hardware is a compromise between ALSA and ASoC allowing for hw_params-intersection code to be alloc/free-less while not adding any new responsibilities to ASoC runtime structures.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- include/sound/pcm.h | 7 ++++ include/uapi/sound/asound.h | 7 ++-- sound/core/pcm.c | 3 ++ sound/core/pcm_native.c | 55 +++++++++++++++++++++++++++++-- tools/include/uapi/sound/asound.h | 7 ++-- 5 files changed, 73 insertions(+), 6 deletions(-)
include/sound/pcm.h +7 -0
@@ -33,6 +33,7 @@struct snd_pcm_hardware {unsigned int info;/* SNDRV_PCM_INFO_* */ u64 formats;/* SNDRV_PCM_FMTBIT_* */ +u32 subformats;/* for S32_LE, SNDRV_PCM_SUBFMTBIT_* */ unsigned int rates;/* SNDRV_PCM_RATE_* */ unsigned int rate_min;/* min rate */ unsigned int rate_max;/* max rate */
@@ -218,6 +219,12 @@ struct snd_pcm_ops {#define SNDRV_PCM_FMTBIT_U20 SNDRV_PCM_FMTBIT_U20_BE#endif +#define _SNDRV_PCM_SUBFMTBIT (fmt) BIT((__force int)SNDRV_PCM_SUBFORMAT_##fmt) +#define SNDRV_PCM_SUBFMTBIT_STD _SNDRV_PCM_SUBFMTBIT(STD) +#define SNDRV_PCM_SUBFMTBIT_MSBITS_MAX _SNDRV_PCM_SUBFMTBIT(MSBITS_MAX) +#define SNDRV_PCM_SUBFMTBIT_MSBITS_20 _SNDRV_PCM_SUBFMTBIT(MSBITS_20) +#define SNDRV_PCM_SUBFMTBIT_MSBITS_24 _SNDRV_PCM_SUBFMTBIT(MSBITS_24) +struct snd_pcm_file {struct snd_pcm_substream *substream;int no_compat_mmap;
include/uapi/sound/asound.h +5 -2
@@ -142,7 +142,7 @@ struct snd_hwdep_dsp_image {* * *****************************************************************************/ -#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 15) +#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 16)typedef unsigned long snd_pcm_uframes_t ;typedef signed long snd_pcm_sframes_t ;
@@ -267,7 +267,10 @@ typedef int __bitwise snd_pcm_format_t;typedef int __bitwise snd_pcm_subformat_t ;#define SNDRV_PCM_SUBFORMAT_STD ((__force snd_pcm_subformat_t) 0) -#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_STD +#define SNDRV_PCM_SUBFORMAT_MSBITS_MAX ((__force snd_pcm_subformat_t) 1) +#define SNDRV_PCM_SUBFORMAT_MSBITS_20 ((__force snd_pcm_subformat_t) 2) +#define SNDRV_PCM_SUBFORMAT_MSBITS_24 ((__force snd_pcm_subformat_t) 3) +#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_MSBITS_24#define SNDRV_PCM_INFO_MMAP 0x00000001/* hardware supports mmap */ #define SNDRV_PCM_INFO_MMAP_VALID 0x00000002/* period data are valid during transfer */
sound/core/pcm.c +3 -0
@@ -266,6 +266,9 @@ static const char * const snd_pcm_access_names[] = {static const char *const snd_pcm_subformat_names[] = {SUBFORMAT (STD ), +SUBFORMAT (MSBITS_MAX ), +SUBFORMAT (MSBITS_20 ), +SUBFORMAT (MSBITS_24 ), };static const char *const snd_pcm_tstamp_mode_names[] = {
sound/core/pcm_native.c +53 -2
79 lines not on this page · raw message
tools/include/uapi/sound/asound.h +5 -2
@@ -142,7 +142,7 @@ struct snd_hwdep_dsp_image {* * *****************************************************************************/ -#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 15) +#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 16)typedef unsigned long snd_pcm_uframes_t ;typedef signed long snd_pcm_sframes_t ;
@@ -267,7 +267,10 @@ typedef int __bitwise snd_pcm_format_t;typedef int __bitwise snd_pcm_subformat_t ;#define SNDRV_PCM_SUBFORMAT_STD ((__force snd_pcm_subformat_t) 0) -#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_STD +#define SNDRV_PCM_SUBFORMAT_MSBITS_MAX ((__force snd_pcm_subformat_t) 1) +#define SNDRV_PCM_SUBFORMAT_MSBITS_20 ((__force snd_pcm_subformat_t) 2) +#define SNDRV_PCM_SUBFORMAT_MSBITS_24 ((__force snd_pcm_subformat_t) 3) +#define SNDRV_PCM_SUBFORMAT_LAST SNDRV_PCM_SUBFORMAT_MSBITS_24#define SNDRV_PCM_INFO_MMAP 0x00000001/* hardware supports mmap */ #define SNDRV_PCM_INFO_MMAP_VALID 0x00000002/* period data are valid during transfer */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2932/3318 ALSA: hda: Upgrade stream-format infrastructure
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit d24f1a090d3f2a5c86a8782afeda71c2d2539966 ]
Introduce a set of functions that ultimately facilite SDxFMT-related calculations in atomic manner:
First, introduce snd_pcm_subformat_width() and snd_pcm_hw_params_bits() helpers that separate the base functionality from the HDAudio-specific one.
snd_hdac_format_normalize() - format converter. S20_LE, S24_LE and their unsigned and BE friends are invalid from HDAudio perspective but still can be specified as function argument due to compatibility reasons.
snd_hdac_stream_format_bits() - obtain just the bits-per-sample value. Does not ignore subformat and msbits parameters.
snd_hdac_stream_format() and snd_hdac_spdif_stream_format() - obtain the SDxFMT value given the audio format parameters. The former is stripped away of spdif-related information. Useful for users that do not care about them.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- include/sound/hdaudio.h | 5 ++ include/sound/pcm_params.h | 2 + sound/core/pcm_lib.c | 34 ++++++++++ sound/hda/hdac_device.c | 124 +++++++++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+)
include/sound/hdaudio.h +5 -0
@@ -140,6 +140,11 @@ int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid, hda_nid_t *conn_list, int max_conns);int snd_hdac_get_sub_nodes (struct hdac_device *codec,hda_nid_t nid,hda_nid_t *start_id); +unsigned int snd_hdac_stream_format_bits (snd_pcm_format_t format,snd_pcm_subformat_t subformat, +unsigned int maxbits); +unsigned int snd_hdac_stream_format (unsigned int channels,unsigned int bits,unsigned int rate); +unsigned int snd_hdac_spdif_stream_format (unsigned int channels,unsigned int bits, +unsigned int rate,unsigned short spdif_ctls); unsigned int snd_hdac_calc_stream_format(unsigned int rate, unsigned int channels, snd_pcm_format_t format,
include/sound/pcm_params.h +2 -0
@@ -362,6 +362,8 @@ static inline int params_physical_width(const struct snd_pcm_hw_params *p)return snd_pcm_format_physical_width (params_format (p)); } +int snd_pcm_hw_params_bits (const struct snd_pcm_hw_params *p); +static inline void params_set_format (struct snd_pcm_hw_params *p,snd_pcm_format_t fmt) {
sound/core/pcm_lib.c +34 -0
@@ -1706,6 +1706,40 @@ int snd_pcm_hw_param_last(struct snd_pcm_substream *pcm, }EXPORT_SYMBOL (snd_pcm_hw_param_last); +/** +* snd_pcm_hw_params_bits - Get the number of bits per the sample. +* @p: hardware parameters +* +* Return: The number of bits per sample based on the format, +* subformat and msbits the specified hw params has. +*/ +int snd_pcm_hw_params_bits (const struct snd_pcm_hw_params *p) +{ +snd_pcm_subformat_t subformat =params_subformat (p); +snd_pcm_format_t format =params_format (p); + +switch (format) { +case SNDRV_PCM_FORMAT_S32_LE : +case SNDRV_PCM_FORMAT_U32_LE : +case SNDRV_PCM_FORMAT_S32_BE : +case SNDRV_PCM_FORMAT_U32_BE : +switch (subformat) { +case SNDRV_PCM_SUBFORMAT_MSBITS_20 : +return 20 ; +case SNDRV_PCM_SUBFORMAT_MSBITS_24 : +return 24 ; +case SNDRV_PCM_SUBFORMAT_MSBITS_MAX : +case SNDRV_PCM_SUBFORMAT_STD : +default : +break ; + } + fallthrough; +default : +return snd_pcm_format_width (format); + } +} +EXPORT_SYMBOL (snd_pcm_hw_params_bits); +static int snd_pcm_lib_ioctl_reset (struct snd_pcm_substream *substream,void *arg) {
sound/hda/hdac_device.c +124 -0
136 lines not on this page · raw message
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2933/3318 ASoC: Intel: avs: Switch to new stream-format interface
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 615d13cb4f3e499fb5c270a7db66917286f7d0ec ]
To provide option for selecting different bit-per-sample than just the maximum one, use the new format calculation mechanism.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- sound/soc/intel/avs/loader.c | 4 ++-- sound/soc/intel/avs/path.c | 2 +- sound/soc/intel/avs/pcm.c | 19 ++++++++++++++----- sound/soc/intel/avs/probes.c | 3 +-- 4 files changed, 18 insertions(+), 10 deletions(-)
sound/soc/intel/avs/loader.c +2 -2
@@ -371,7 +371,7 @@ int avs_hda_load_basefw(struct avs_dev *adev, struct firmware *fw) hstream =hdac_stream (estream);/* code loading performed with default format */ - sdfmt =snd_hdac_calc_stream_format (48000 ,1 ,SNDRV_PCM_FORMAT_S32_LE ,32 ,0 ); + sdfmt =snd_hdac_stream_format (1 ,32 ,48000 ); ret =snd_hdac_dsp_prepare (hstream, sdfmt, fw->size, &dmab);if (ret <0 ) goto release_stream;
@@ -438,7 +438,7 @@ int avs_hda_load_library(struct avs_dev *adev, struct firmware *lib, u32 id) stream =hdac_stream (estream);/* code loading performed with default format */ - sdfmt =snd_hdac_calc_stream_format (48000 ,1 ,SNDRV_PCM_FORMAT_S32_LE ,32 ,0 ); + sdfmt =snd_hdac_stream_format (1 ,32 ,48000 ); ret =snd_hdac_dsp_prepare (stream, sdfmt, lib->size, &dmab);if (ret <0 ) goto release_stream;
sound/soc/intel/avs/path.c +1 -1
@@ -87,7 +87,7 @@ static bool avs_test_hw_params(struct snd_pcm_hw_params *params,return (params_rate (params) == fmt->sampling_freq &¶ms_channels (params) == fmt->num_channels &¶ms_physical_width (params) == fmt->bit_depth && -params_width (params) == fmt->valid_bit_depth); +snd_pcm_hw_params_bits (params) == fmt->valid_bit_depth); } static struct avs_tplg_path *
sound/soc/intel/avs/pcm.c +14 -5
@@ -335,20 +335,25 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct sn {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct snd_pcm_runtime *runtime = substream->runtime; -struct hdac_ext_stream *link_stream = runtime->private_data; +struct snd_soc_pcm_stream *stream_info; +struct hdac_ext_stream *link_stream;struct hdac_ext_link *link;struct hda_codec *codec;struct hdac_bus *bus;unsigned int format_val; +unsigned int bits;int ret; + link_stream = runtime->private_data;if (link_stream->link_prepared)return 0 ; codec =dev_to_hda_codec (snd_soc_rtd_to_codec (rtd,0 )->dev); bus = &codec->bus->core; - format_val =snd_hdac_calc_stream_format (runtime->rate, runtime->channels, runtime->format, - runtime->sample_bits,0 ); + stream_info =snd_soc_dai_get_pcm_stream (dai, substream->stream); + bits =snd_hdac_stream_format_bits (runtime->format, runtime->subformat, + stream_info->sig_bits); + format_val =snd_hdac_stream_format (runtime->channels, bits, runtime->rate);snd_hdac_ext_stream_decouple (bus, link_stream, true);snd_hdac_ext_stream_reset (link_stream);
@@ -601,11 +606,13 @@ static int avs_dai_fe_hw_free(struct snd_pcm_substream *substream, struct snd_sostatic int avs_dai_fe_prepare (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) {struct snd_pcm_runtime *runtime = substream->runtime; +struct snd_soc_pcm_stream *stream_info;struct avs_dma_data *data;struct avs_dev *adev =to_avs_dev (dai->dev);struct hdac_ext_stream *host_stream;struct hdac_bus *bus;unsigned int format_val; +unsigned int bits;int ret; data =snd_soc_dai_get_dma_data (dai, substream);
@@ -620,8 +627,10 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_sosnd_hdac_ext_stream_decouple (bus, data->host_stream, true);snd_hdac_stream_reset (hdac_stream (host_stream)); - format_val =snd_hdac_calc_stream_format (runtime->rate, runtime->channels, runtime->format, - runtime->sample_bits,0 ); + stream_info =snd_soc_dai_get_pcm_stream (dai, substream->stream); + bits =snd_hdac_stream_format_bits (runtime->format, runtime->subformat, + stream_info->sig_bits); + format_val =snd_hdac_stream_format (runtime->channels, bits, runtime->rate); ret =snd_hdac_stream_set_params (hdac_stream (host_stream), format_val);if (ret <0 )
sound/soc/intel/avs/probes.c +1 -2
@@ -144,8 +144,7 @@ static int avs_probe_compr_set_params(struct snd_compr_stream *cstream, bps =snd_pcm_format_physical_width (format);if (bps <0 )return bps; - format_val =snd_hdac_calc_stream_format (params->codec.sample_rate, params->codec.ch_out, - format, bps,0 ); + format_val =snd_hdac_stream_format (params->codec.ch_out, bps, params->codec.sample_rate); ret =snd_hdac_stream_set_params (hdac_stream (host_stream), format_val);if (ret <0 )return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2934/3318 ASoC: Intel: avs: Relocate HDA BE DAI specific operations
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 140df6d4d5f541e950a35cad2e3dffb49186ed74 ]
DAI's startup()/shutdown() shall deal with allocation and freeing of resources needed to facilitate streaming over it. Currently for HDAudio BE DAIs some of that task is done in component->open()/close(). Relocate the relevant pieces to address that.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- sound/soc/intel/avs/pcm.c | 55 ++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 29 deletions(-)
sound/soc/intel/avs/pcm.c +26 -29
@@ -276,12 +276,36 @@ static const struct snd_soc_dai_ops avs_dai_hda_be_ops;static int avs_dai_hda_be_startup (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { -return avs_dai_startup (substream, dai, false, &avs_dai_hda_be_ops); +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct hdac_ext_stream *link_stream; +struct hda_codec *codec; +int ret; + + ret =avs_dai_startup (substream, dai, false, &avs_dai_hda_be_ops); +if (ret) +return ret; + + codec =dev_to_hda_codec (snd_soc_rtd_to_codec (rtd,0 )->dev); + link_stream =snd_hdac_ext_stream_assign (&codec->bus->core, substream, +HDAC_EXT_STREAM_TYPE_LINK ); +if (!link_stream) { +avs_dai_nonhda_be_shutdown (substream, dai); +return -EBUSY ; + } + + substream->runtime->private_data = link_stream; +return 0 ; }static void avs_dai_hda_be_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { -return avs_dai_nonhda_be_shutdown (substream, dai); +struct hdac_ext_stream *link_stream; + + link_stream = substream->runtime->private_data; +snd_hdac_ext_stream_release (link_stream,HDAC_EXT_STREAM_TYPE_LINK ); + substream->runtime->private_data =NULL ; + +avs_dai_nonhda_be_shutdown (substream, dai); } static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream,
@@ -1446,8 +1470,6 @@ static int avs_component_hda_open(struct snd_soc_component *component, struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct hdac_ext_stream *link_stream; -struct hda_codec *codec;if (!rtd->dai_link->no_pcm) {struct snd_pcm_hardware hwparams = avs_pcm_hardware;
@@ -1479,30 +1501,6 @@ static int avs_component_hda_open(struct snd_soc_component *component,return snd_soc_set_runtime_hwparams (substream, &hwparams); } - codec =dev_to_hda_codec (snd_soc_rtd_to_codec (rtd,0 )->dev); - link_stream =snd_hdac_ext_stream_assign (&codec->bus->core, substream, -HDAC_EXT_STREAM_TYPE_LINK ); -if (!link_stream) -return -EBUSY ; - - substream->runtime->private_data = link_stream; -return 0 ; -} - -static int avs_component_hda_close (struct snd_soc_component *component, -struct snd_pcm_substream *substream) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct hdac_ext_stream *link_stream; - -/* only BE DAI links are handled here */ -if (!rtd->dai_link->no_pcm) -return 0 ; - - link_stream = substream->runtime->private_data; -snd_hdac_ext_stream_release (link_stream,HDAC_EXT_STREAM_TYPE_LINK ); - substream->runtime->private_data =NULL ; -return 0 ; }
@@ -1513,7 +1511,6 @@ static const struct snd_soc_component_driver avs_hda_component_driver = { .suspend = avs_component_suspend, .resume = avs_component_resume, .open = avs_component_hda_open, - .close = avs_component_hda_close, .pointer = avs_component_pointer, .mmap = avs_component_mmap, .pcm_construct = avs_component_construct,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2935/3318 ASoC: Intel: avs: Remove redundancy around DAI shutdown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit b9d59f970ea7772957f6da02ca1ba272ef4495b8 ]
Move avs_dai_nonhda_be_shutdown() to avs_dai_shutdown() as the function is common for all transfer types, not just non-HDAudio ones. Use it to simplify avs_dai_fe_shutdown().
While at it, fix explicit kfree(data) and use the destructor instead.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- sound/soc/intel/avs/pcm.c | 44 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-)
sound/soc/intel/avs/pcm.c +19 -25
@@ -84,6 +84,21 @@ static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dreturn 0 ; } +static void avs_dai_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) +{ +struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); +struct avs_dev *adev =to_avs_dev (dai->dev); +struct avs_dma_data *data; + + data =snd_soc_dai_get_dma_data (dai, substream); + +if (rtd->dai_link->ignore_suspend) + adev->num_lp_paths--; + +snd_soc_dai_set_dma_data (dai, substream,NULL ); +kfree (data); +} + static int avs_dai_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *fe_hw_params, struct snd_pcm_hw_params *be_hw_params, struct snd_soc_dai *dai,
@@ -165,21 +180,6 @@ static int avs_dai_nonhda_be_startup(struct snd_pcm_substream *substream, structreturn avs_dai_startup (substream, dai, false, &avs_dai_nonhda_be_ops); } -static void avs_dai_nonhda_be_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) -{ -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct avs_dev *adev =to_avs_dev (dai->dev); -struct avs_dma_data *data; - -if (rtd->dai_link->ignore_suspend) - adev->num_lp_paths--; - - data =snd_soc_dai_get_dma_data (dai, substream); - -snd_soc_dai_set_dma_data (dai, substream,NULL ); -kfree (data); -} -static int avs_dai_nonhda_be_hw_params (struct snd_pcm_substream *substream,struct snd_pcm_hw_params *hw_params,struct snd_soc_dai *dai) {
@@ -265,7 +265,7 @@ static int avs_dai_nonhda_be_trigger(struct snd_pcm_substream *substream, int cmstatic const struct snd_soc_dai_ops avs_dai_nonhda_be_ops = { .startup = avs_dai_nonhda_be_startup, - .shutdown = avs_dai_nonhda_be_shutdown, + .shutdown = avs_dai_shutdown, .hw_params = avs_dai_nonhda_be_hw_params, .hw_free = avs_dai_nonhda_be_hw_free, .prepare = avs_dai_nonhda_be_prepare,
@@ -289,7 +289,7 @@ static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct sn link_stream =snd_hdac_ext_stream_assign (&codec->bus->core, substream,HDAC_EXT_STREAM_TYPE_LINK );if (!link_stream) { -avs_dai_nonhda_be_shutdown (substream, dai); +avs_dai_shutdown (substream, dai);return -EBUSY ; }
@@ -305,7 +305,7 @@ static void avs_dai_hda_be_shutdown(struct snd_pcm_substream *substream, structsnd_hdac_ext_stream_release (link_stream,HDAC_EXT_STREAM_TYPE_LINK ); substream->runtime->private_data =NULL ; -avs_dai_nonhda_be_shutdown (substream, dai); +avs_dai_shutdown (substream, dai); } static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream,
@@ -529,18 +529,12 @@ static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_sostatic void avs_dai_fe_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { -struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct avs_dev *adev =to_avs_dev (dai->dev);struct avs_dma_data *data; -if (rtd->dai_link->ignore_suspend) - adev->num_lp_paths--; - data =snd_soc_dai_get_dma_data (dai, substream); -snd_soc_dai_set_dma_data (dai, substream,NULL );snd_hdac_ext_stream_release (data->host_stream,HDAC_EXT_STREAM_TYPE_HOST ); -kfree (data); +avs_dai_shutdown (substream, dai); } static int avs_dai_fe_hw_params(struct snd_pcm_substream *substream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2936/3318 ASoC: Intel: avs: Store pointer to adev in DAI dma_data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit c303a994e5d0f7d297cb6ac56052dce8f412ee67 ]
Reduce the number of to_avs_dev() casts by storing the driver context in DAI's dma_data.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- sound/soc/intel/avs/pcm.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
sound/soc/intel/avs/pcm.c +8 -9
@@ -21,6 +21,7 @@struct avs_dma_data {struct avs_tplg_path_template *template;struct avs_path *path; +struct avs_dev *adev;/* * link stream is stored within substream's runtime * private_data to fulfill the needs of codec BE path
@@ -59,7 +60,7 @@ static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_d const struct snd_soc_dai_ops *ops) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct avs_dev *adev =to_avs_dev (dai->dev); +struct avs_dev *adev =to_avs_dev (dai->component->dev);struct avs_tplg_path_template *template;struct avs_dma_data *data;
@@ -76,6 +77,7 @@ static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_d data->substream = substream; data->template = template; + data->adev = adev;snd_soc_dai_set_dma_data (dai, substream, data);if (rtd->dai_link->ignore_suspend)
@@ -87,13 +89,12 @@ static int avs_dai_startup(struct snd_pcm_substream *substream, struct snd_soc_dstatic void avs_dai_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct avs_dev *adev =to_avs_dev (dai->dev);struct avs_dma_data *data; data =snd_soc_dai_get_dma_data (dai, substream);if (rtd->dai_link->ignore_suspend) - adev->num_lp_paths--; + data->adev->num_lp_paths--;snd_soc_dai_set_dma_data (dai, substream,NULL );kfree (data);
@@ -106,7 +107,6 @@ static int avs_dai_hw_params(struct snd_pcm_substream *substream, {struct avs_dma_data *data;struct avs_path *path; -struct avs_dev *adev =to_avs_dev (dai->dev);int ret; data =snd_soc_dai_get_dma_data (dai, substream);
@@ -123,7 +123,7 @@ static int avs_dai_hw_params(struct snd_pcm_substream *substream,params_rate (be_hw_params),params_channels (be_hw_params), params_width(be_hw_params), params_physical_width(be_hw_params)); - path =avs_path_create (adev, dma_id, data->template, fe_hw_params, be_hw_params); + path =avs_path_create (data->adev, dma_id, data->template, fe_hw_params, be_hw_params);if (IS_ERR (path)) { ret =PTR_ERR (path);dev_err (dai->dev,"create path failed: %d\n" , ret);
@@ -484,8 +484,7 @@ static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_so {struct snd_pcm_runtime *runtime = substream->runtime;struct avs_dma_data *data; -struct avs_dev *adev =to_avs_dev (dai->dev); -struct hdac_bus *bus = &adev->base.core; +struct hdac_bus *bus;struct hdac_ext_stream *host_stream;int ret;
@@ -494,6 +493,7 @@ static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_soreturn ret; data =snd_soc_dai_get_dma_data (dai, substream); + bus = &data->adev->base.core; host_stream =snd_hdac_ext_stream_assign (bus, substream,HDAC_EXT_STREAM_TYPE_HOST );if (!host_stream) {
@@ -626,7 +626,6 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_sostruct snd_pcm_runtime *runtime = substream->runtime;struct snd_soc_pcm_stream *stream_info;struct avs_dma_data *data; -struct avs_dev *adev =to_avs_dev (dai->dev);struct hdac_ext_stream *host_stream;struct hdac_bus *bus;unsigned int format_val;
@@ -658,7 +657,7 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_soif (ret <0 )return ret; - ret =avs_dai_prepare (adev, substream, dai); + ret =avs_dai_prepare (data->adev, substream, dai);if (ret)return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2937/3318 ASoC: Intel: avs: Store pointer to link_stream in dma_data
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit cdcb770a60e8e6b9fbb737ebe21b2daadaba1744 ]
While the HDAudio codec driver expectations must be met - store valid pointer to HDAudio LINK stream in substream->runtime->private_data - the code is more readable and easier to maintain if dma_data stores pointers to both HOST and LINK stream.
DAI BE operations can refer to the LINK stream with data->link_stream, similarly to how DAI FE operations access the HOST stream with data->host_stream.
Stable-dep-of: 85bc213f96ac ("ASoC: Intel: avs: Unprepare a stream when recovery occurs")
--- sound/soc/intel/avs/pcm.c | 40 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 21 deletions(-)
sound/soc/intel/avs/pcm.c +19 -21
@@ -22,13 +22,12 @@ struct avs_dma_data {struct avs_tplg_path_template *template;struct avs_path *path;struct avs_dev *adev; -/* -* link stream is stored within substream's runtime -* private_data to fulfill the needs of codec BE path -* -* host stream assigned -*/ -struct hdac_ext_stream *host_stream; + +/* LINK-stream utilized in BE operations while HOST in FE ones. */ +union { +struct hdac_ext_stream *link_stream; +struct hdac_ext_stream *host_stream; + };struct snd_pcm_substream *substream; };
@@ -278,6 +277,7 @@ static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct sn {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream);struct hdac_ext_stream *link_stream; +struct avs_dma_data *data;struct hda_codec *codec;int ret;
@@ -293,18 +293,18 @@ static int avs_dai_hda_be_startup(struct snd_pcm_substream *substream, struct snreturn -EBUSY ; } + data =snd_soc_dai_get_dma_data (dai, substream); + data->link_stream = link_stream; substream->runtime->private_data = link_stream;return 0 ; }static void avs_dai_hda_be_shutdown (struct snd_pcm_substream *substream,struct snd_soc_dai *dai) { -struct hdac_ext_stream *link_stream; +struct avs_dma_data *data =snd_soc_dai_get_dma_data (dai, substream); - link_stream = substream->runtime->private_data; -snd_hdac_ext_stream_release (link_stream,HDAC_EXT_STREAM_TYPE_LINK ); +snd_hdac_ext_stream_release (data->link_stream,HDAC_EXT_STREAM_TYPE_LINK ); substream->runtime->private_data =NULL ; -avs_dai_shutdown (substream, dai); }
@@ -312,16 +312,13 @@ static int avs_dai_hda_be_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *dai) { struct avs_dma_data *data; -struct hdac_ext_stream *link_stream; data =snd_soc_dai_get_dma_data (dai, substream);if (data->path)return 0 ; - link_stream = substream->runtime->private_data; -return avs_dai_be_hw_params (substream, hw_params, dai, -hdac_stream (link_stream)->stream_tag -1 ); +hdac_stream (data->link_stream)->stream_tag -1 ); }static int avs_dai_hda_be_hw_free (struct snd_pcm_substream *substream,struct snd_soc_dai *dai)
@@ -338,7 +335,7 @@ static int avs_dai_hda_be_hw_free(struct snd_pcm_substream *substream, struct snif (!data->path)return 0 ; - link_stream = substream->runtime->private_data; + link_stream = data->link_stream; link_stream->link_prepared = false;avs_path_free (data->path); data->path =NULL ;
@@ -362,13 +359,16 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct snstruct snd_soc_pcm_stream *stream_info;struct hdac_ext_stream *link_stream;struct hdac_ext_link *link; +struct avs_dma_data *data;struct hda_codec *codec;struct hdac_bus *bus;unsigned int format_val;unsigned int bits;int ret; - link_stream = runtime->private_data; + data =snd_soc_dai_get_dma_data (dai, substream); + link_stream = data->link_stream; +if (link_stream->link_prepared)return 0 ;
@@ -402,14 +402,12 @@ static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) {struct snd_soc_pcm_runtime *rtd =snd_soc_substream_to_rtd (substream); -struct hdac_ext_stream *link_stream;struct avs_dma_data *data;int ret =0 ;dev_dbg (dai->dev,"entry %s cmd=%d\n" , __func__, cmd); data =snd_soc_dai_get_dma_data (dai, substream); - link_stream = substream->runtime->private_data;switch (cmd) {case SNDRV_PCM_TRIGGER_RESUME :
@@ -418,7 +416,7 @@ static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd, fallthrough;case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : -snd_hdac_ext_stream_start (link_stream); +snd_hdac_ext_stream_start (data->link_stream); ret =avs_path_pause (data->path);if (ret <0 ) {
@@ -441,7 +439,7 @@ static int avs_dai_hda_be_trigger(struct snd_pcm_substream *substream, int cmd,if (ret <0 )dev_err (dai->dev,"pause BE path failed: %d\n" , ret); -snd_hdac_ext_stream_clear (link_stream); +snd_hdac_ext_stream_clear (data->link_stream); ret =avs_path_reset (data->path);if (ret <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2938/3318 ASoC: Intel: avs: Unprepare a stream when recovery occurs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 85bc213f96ac03d74a3e531968c68861e5598281 ]
Recovery on alsa-lib side is handled with either:
1) snd_pcm_prepare(state=XRUN)
2) snd_pcm_drop/drain() -> snd_pcm_prepare(state=SETUP)
before starting the PCM anew. Relying solely on state=XRUN leaves 2) unaccounted for. sound/core/pcm_native.c ensures correctness of the state machine so plain state!=PREPARED check suffices.
This is the BE equivalent of job done previously for FE side only with commit cfca1637bc2b ("ASoC: Intel: avs: Unprepare a stream when XRUN occurs") and its follow up titled: ("ASoC: Intel: avs: Reset the stream unless it is already prepared").
--- sound/soc/intel/avs/pcm.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/intel/avs/pcm.c +2 -0
@@ -369,6 +369,8 @@ static int avs_dai_hda_be_prepare(struct snd_pcm_substream *substream, struct sn data =snd_soc_dai_get_dma_data (dai, substream); link_stream = data->link_stream; +if (substream->runtime->state !=SNDRV_PCM_STATE_PREPARED ) + link_stream->link_prepared = false;if (link_stream->link_prepared)return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2939/3318 ASoC: Intel: avs: Prevent module info underflow
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cezary Rojewski <[email protected]>
[ Upstream commit 05c2975b4267246219e7aead0467626107e204e9 ]
Typically modules information is first initialized when loading the base AudioDSP base firmware and then expanded when loadable DSP modules are requested by platform-components, see avs_component_load_libraries().
While theoretically not possible in a production scenario, there is no reason to continue the IDAs preparation if an event caused the newly obtained module information to be smaller or equal than the existing information.
--- sound/soc/intel/avs/utils.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/intel/avs/utils.c +4 -2
@@ -118,9 +118,11 @@ avs_module_ida_alloc(struct avs_dev *adev, struct avs_mods_info *newinfo, bool pint i;if (!purge && oldinfo) { -if (oldinfo->count >= newinfo->count) -dev_warn (adev->dev,"refreshing %d modules info with %d\n" , +if (oldinfo->count >= newinfo->count) { +dev_warn (adev->dev,"modules info underflow, old: %d, new: %d\n" , oldinfo->count, newinfo->count); +return -EPROTO ; + } tocopy_count = oldinfo->count; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2940/3318 ASoC: qcom: sdm845: add handling of secondary MI2S clock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Klimov <[email protected]>
[ Upstream commit 8bfb66c75cdace542dabe87841152614fd5b8d91 ]
Add handling of clock related to secondary MI2S_RX in startup, shutdown and hw params routines. The handing of MI2S_TX and SEC_MI2S clock is already there so this requires only placing SECONDARY_MI2S_RX in the correct switch-case choices.
Stable-dep-of: cef5d087d681 ("ASoC: qcom: sdm845: Disable the quaternary MI2S bit clock on shutdown")
--- sound/soc/qcom/sdm845.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/qcom/sdm845.c +3 -2
@@ -218,6 +218,7 @@ static int sdm845_snd_hw_params(struct snd_pcm_substream *substream, ret =sdm845_slim_snd_hw_params (substream, params);break ;case QUATERNARY_MI2S_RX : +case SECONDARY_MI2S_RX :break ;default :pr_err ("%s: invalid dai id 0x%x\n" , __func__, cpu_dai->id);
@@ -359,6 +360,7 @@ static int sdm845_snd_startup(struct snd_pcm_substream *substream)snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ; +case SECONDARY_MI2S_RX :case SECONDARY_MI2S_TX : codec_dai_fmt |=SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_I2S ;if (++(data->sec_mi2s_clk_count) ==1 ) {
@@ -374,8 +376,6 @@ static int sdm845_snd_startup(struct snd_pcm_substream *substream)Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , MI2S_BCLK_RATE, SNDRV_PCM_STREAM_PLAYBACK);snd_soc_dai_set_fmt (cpu_dai, fmt); - -break ;case QUATERNARY_TDM_RX_0 :
@@ -443,6 +443,7 @@ static void sdm845_snd_shutdown(struct snd_pcm_substream *substream) }break ; +case SECONDARY_MI2S_RX :case SECONDARY_MI2S_TX :if (--(data->sec_mi2s_clk_count) ==0 ) { snd_soc_dai_set_sysclk(cpu_dai,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2941/3318 ASoC: qcom: sdm845: set quaternary MI2S codec DAI to I2S format
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Robert Oscilowski <[email protected]>
[ Upstream commit 20c734cb678332883d317b17bf8fe7361648e170 ]
We configure the codec DAI format for primary and secondary but not the quaternery MI2S path. Add the missing configuration to enable speaker codecs on the quaternary MI2S like the MAX9827 found on the OnePlus 6.
Stable-dep-of: cef5d087d681 ("ASoC: qcom: sdm845: Disable the quaternary MI2S bit clock on shutdown")
--- sound/soc/qcom/sdm845.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/qcom/sdm845.c +2 -0
@@ -372,10 +372,12 @@ static int sdm845_snd_startup(struct snd_pcm_substream *substream)snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ;case QUATERNARY_MI2S_RX : + codec_dai_fmt |=SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_I2S ;snd_soc_dai_set_sysclk (cpu_dai,Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT ,MI2S_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK );snd_soc_dai_set_fmt (cpu_dai, fmt); +snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ;case QUATERNARY_TDM_RX_0 :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2942/3318 ASoC: qcom: sdm845: Disable the quaternary MI2S bit clock on shutdown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Auer <[email protected]>
[ Upstream commit cef5d087d6813d4c15847d0b71ecbd6c47c5f1d4 ]
sdm845_snd_startup() enables the quaternary MI2S bit clock in the ADSP, but sdm845_snd_shutdown() never disables it. After the first stream on this port the clock stays on.
On the OnePlus 6 the speaker amplifier is on this port. After the first playback the ADSP no longer power collapses: it slept under 9 s in 5 hours. With this change it sleeps again when audio is idle (about 40 s of 45 s).
Refcount the clock like the other MI2S and TDM ports and disable it when the last user is gone.
--- sound/soc/qcom/sdm845.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
sound/soc/qcom/sdm845.c +15 -4
@@ -38,6 +38,7 @@ struct sdm845_snd_data {struct snd_soc_card *card;uint32_t pri_mi2s_clk_count;uint32_t sec_mi2s_clk_count; +uint32_t quat_mi2s_clk_count;uint32_t quat_tdm_clk_count;struct sdw_stream_runtime *sruntime[AFE_PORT_MAX ]; };
@@ -373,9 +374,11 @@ static int sdm845_snd_startup(struct snd_pcm_substream *substream)break ;case QUATERNARY_MI2S_RX : codec_dai_fmt |=SND_SOC_DAIFMT_NB_NF |SND_SOC_DAIFMT_I2S ; -snd_soc_dai_set_sysclk (cpu_dai, -Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , -MI2S_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); +if (++(data->quat_mi2s_clk_count) ==1 ) { +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , +MI2S_BCLK_RATE ,SNDRV_PCM_STREAM_PLAYBACK ); + }snd_soc_dai_set_fmt (cpu_dai, fmt);snd_soc_dai_set_fmt (codec_dai, codec_dai_fmt);break ;
@@ -462,8 +465,16 @@ static void sdm845_snd_shutdown(struct snd_pcm_substream *substream) 0, SNDRV_PCM_STREAM_PLAYBACK); }break ; - case SLIMBUS_0_RX...SLIMBUS_6_TX: +case QUATERNARY_MI2S_RX : +if (--(data->quat_mi2s_clk_count) ==0 ) { +snd_soc_dai_set_sysclk (cpu_dai, +Q6AFE_LPASS_CLK_ID_QUAD_MI2S_IBIT , +0 ,SNDRV_PCM_STREAM_PLAYBACK ); + } +break ; + + case SLIMBUS_0_RX...SLIMBUS_6_TX:break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2943/3318 selftests: keep the build status from wrapping to success
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit 907d138279ee3747efedc9f7403d8b0edb52aca2 ]
The top-level all and install rules return failure only when every selected target fails, which commit cad6f32665cb ("selftests: Deescalate error reporting") deliberately kept as the default. They implement this by multiplying the exit statuses of the targets:
ret=$$((ret * $$?))
A failing recursive make exits with status 2, so eight failing targets produce 256, and "exit 256" reports success. Building eight or more targets that all fail therefore succeeds, and install goes on to package an empty installation.
Record a successful target instead of multiplying statuses. The rules still fail only when no target succeeds, and FORCE_TARGETS still stops at the first failure.
--- tools/testing/selftests/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/Makefile +2 -2
@@ -177,7 +177,7 @@ all: $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ - ret=$$((ret * $$?)); \ + [ $$? -eq 0 ] && ret=0; \ done; exit $$ret; run_tests: all
@@ -242,7 +242,7 @@ ifdef INSTALL_PATH OBJ_PATH=$(INSTALL_PATH) \ O=$(abs_objtree) \ $(if $(FORCE_TARGETS),|| exit); \ - ret=$$((ret * $$?)); \ + [ $$? -eq 0 ] && ret=0; \ done; exit $$ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2944/3318 spi: tegra114: initialize native chip selects inactive
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abraham Zukor <[email protected]>
[ Upstream commit f8334fdfd858c27f090ce597806794e4a08c9f4f ]
tegra_spi_probe() initializes SPI_COMMAND1 with only SPI_M_S, leaving CS_POL_INACTIVE clear for every chip select. This drives every native active-low chip select low until tegra_spi_setup() runs for that device.
SPI children are registered and probed one at a time. A synchronous probe of an earlier child can therefore transfer while a later child's chip select is still asserted. On a Tegra234 system with active-low devices on CS0 and CS1, this caused both devices to be selected when the CS1 device probed first. Its initialization then intermittently failed. A logic analyzer showed CS0 remained low throughout the CS1 transfer and went high only after the CS1 probe failed.
Walk the controller's device tree children before SPI_COMMAND1 is written and set CS_POL_INACTIVE for each valid chip select without spi-cs-high. That way the line is already deasserted when the first child transfers and does not change level when setup runs.
Disabled children are walked too. The core only registers available children, so tegra_spi_setup() never runs for a disabled one and probe is the only chance to park its chip select at the level its hardware needs.
If an enabled child shares a chip select with disabled ones, its polarity takes priority. If only disabled children use a chip select and they disagree, warn and leave the line inactive high.
--- drivers/spi/spi-tegra114.c | 49 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+)
drivers/spi/spi-tegra114.c +49 -0
@@ -1308,6 +1308,9 @@ static int tegra_spi_probe(struct platform_device *pdev)struct resource *r;int ret, spi_irq;int bus_num; +u32 conflicting_cs; +u32 enabled_child_cs_polarity =0 , disabled_child_cs_low =0 , disabled_child_cs_high =0 ; +u32 enabled_cs_mask =0 ; master =spi_alloc_master (&pdev->dev,sizeof (*tspi));if (!master) {
@@ -1407,6 +1410,52 @@ static int tegra_spi_probe(struct platform_device *pdev)udelay (2 );reset_control_deassert (tspi->rst); tspi->def_command1_reg =SPI_M_S ; + +/* +* SPI_COMMAND1 is written before any child is registered, so a chip +* select with CS_POL_INACTIVE clear stays asserted until +* tegra_spi_setup() runs for that device. Program the level the +* device tree asks for up front instead. +* +* Disabled children are included deliberately. The core never +* registers them, so this is the only chance to park their chip +* select at the level their hardware needs. An enabled child on the +* same CS takes priority. +*/ +for_each_child_of_node_scoped (pdev->dev.of_node, np) { +u32 cs; +u32 polarity_bitmask; +u32 cs_polarity =0 ; + +if (of_property_read_u32 (np,"reg" , &cs)) +continue ; + +if (cs >=MAX_CHIP_SELECT ) +continue ; + + polarity_bitmask =SPI_CS_POL_INACTIVE (cs); +if (!of_property_read_bool (np,"spi-cs-high" )) + cs_polarity = polarity_bitmask; + +if (of_device_is_available (np)) { + enabled_cs_mask |= polarity_bitmask; + enabled_child_cs_polarity |= cs_polarity; + }else { +if (cs_polarity) + disabled_child_cs_low |= polarity_bitmask; +else + disabled_child_cs_high |= polarity_bitmask; + } + } + conflicting_cs = disabled_child_cs_low & disabled_child_cs_high & ~enabled_cs_mask; +for (u32 cs =0 ; cs <MAX_CHIP_SELECT ; cs++) { +if (SPI_CS_POL_INACTIVE (cs) & conflicting_cs) +dev_warn (&pdev->dev, +"Conflicting CS polarity on disabled nodes at cs %u\n" , cs); + } + + tspi->def_command1_reg |= enabled_child_cs_polarity | + (disabled_child_cs_low & ~enabled_cs_mask);tegra_spi_writel (tspi, tspi->def_command1_reg,SPI_COMMAND1 ); tspi->spi_cs_timing1 =tegra_spi_readl (tspi,SPI_CS_TIMING1 ); tspi->spi_cs_timing2 =tegra_spi_readl (tspi,SPI_CS_TIMING2 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2945/3318 ASoC: remove unused substream in macro soc_link_mark_pop
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongbo Li <[email protected]>
[ Upstream commit 2f12d0de77b99f0f35755d16efeb12e6f45e5710 ]
The soc_link_mark_pop don't need substream, therefore we can remove it.
Stable-dep-of: 7ef99fcfbbac ("ASoC: soc-link: Correct stream stop operations in snd_soc_link_trigger")
--- sound/soc/soc-link.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/soc-link.c +5 -5
@@ -35,7 +35,7 @@ static inline int _soc_link_ret(struct snd_soc_pcm_runtime *rtd,* In such case, we can update these macros. */ #define soc_link_mark_push (rtd, substream, tgt) ((rtd)->mark_##tgt = substream) -#define soc_link_mark_pop (rtd, substream, tgt) ((rtd)->mark_##tgt = NULL) +#define soc_link_mark_pop (rtd, tgt) ((rtd)->mark_##tgt = NULL)#define soc_link_mark_match (rtd, substream, tgt) ((rtd)->mark_##tgt == substream)int snd_soc_link_init (struct snd_soc_pcm_runtime *rtd)
@@ -94,7 +94,7 @@ void snd_soc_link_shutdown(struct snd_pcm_substream *substream, rtd->dai_link->ops->shutdown (substream);/* remove marked substream */ -soc_link_mark_pop (rtd, substream, startup); +soc_link_mark_pop (rtd, startup); }int snd_soc_link_prepare (struct snd_pcm_substream *substream)
@@ -138,7 +138,7 @@ void snd_soc_link_hw_free(struct snd_pcm_substream *substream, int rollback) rtd->dai_link->ops->hw_free (substream);/* remove marked substream */ -soc_link_mark_pop (rtd, substream, hw_params); +soc_link_mark_pop (rtd, hw_params); }static int soc_link_trigger (struct snd_pcm_substream *substream,int cmd)
@@ -175,7 +175,7 @@ int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd,break ; ret =soc_link_trigger (substream, cmd); -soc_link_mark_pop (rtd, substream, startup); +soc_link_mark_pop (rtd, startup); }return ret;
@@ -209,7 +209,7 @@ void snd_soc_link_compr_shutdown(struct snd_compr_stream *cstream, rtd->dai_link->compr_ops->shutdown) rtd->dai_link->compr_ops->shutdown (cstream); -soc_link_mark_pop (rtd, cstream, compr_startup); +soc_link_mark_pop (rtd, compr_startup); }EXPORT_SYMBOL_GPL (snd_soc_link_compr_shutdown);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2946/3318 ASoC: soc-link: Correct stream stop operations in snd_soc_link_trigger
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 7ef99fcfbbac20ebec10d21a37aeaf8321de7829 ]
When snd_soc_link_trigger() is called to stop, pause push or suspend stream it should call soc_link_mark_pop() on proper target to reverse operation from trigger start, pause release or resume.
--- sound/soc/soc-link.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/soc-link.c +1 -1
@@ -175,7 +175,7 @@ int snd_soc_link_trigger(struct snd_pcm_substream *substream, int cmd,break ; ret =soc_link_trigger (substream, cmd); -soc_link_mark_pop (rtd, startup); +soc_link_mark_pop (rtd, trigger); }return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2947/3318 ASoC: ops: Fix return value in snd_soc_limit_volume()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 223ec2a93bec6c5ee859094c826fec78516a0bb3 ]
As documented snd_soc_limit_volume() should return 0 on success, however at some point in time this promise was broken when snd_soc_clip_to_platform_max() was refactored, refactor it once again using __free() to automatically free struct snd_ctl_elem_value and return proper value.
--- sound/soc/soc-ops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/soc-ops.c +5 -5
@@ -641,7 +641,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);static int snd_soc_clip_to_platform_max (struct snd_kcontrol *kctl) {struct soc_mixer_control *mc = (struct soc_mixer_control *)kctl->private_value; -struct snd_ctl_elem_value *uctl; + struct snd_ctl_elem_value *uctl __free(kfree) = NULL;int ret;if (!mc->platform_max)
@@ -653,7 +653,7 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl) ret = kctl->get (kctl, uctl);if (ret <0 ) - goto out; +return ret;if (uctl->value.integer.value[0 ] > mc->platform_max) uctl->value.integer.value[0 ] = mc->platform_max;
@@ -663,10 +663,10 @@ static int snd_soc_clip_to_platform_max(struct snd_kcontrol *kctl) uctl->value.integer.value[1 ] = mc->platform_max; ret = kctl->put (kctl, uctl); +if (ret <0 ) +return ret; -out: -kfree (uctl); -return ret; +return 0 ; }/**
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2948/3318 ASoC: soc-ac97: Fix error handling in snd_soc_new_ac97_component()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit fc081cdfc6b370f6b6853cdeb4313f92561770d1 ]
If call to snd_soc_ac97_init_gpio() fails, proper removal procedure should mirror snd_soc_free_ac97_component() behaviour and call device_del() before put_device().
--- sound/soc/soc-ac97.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/soc-ac97.c +3 -1
@@ -234,10 +234,12 @@ struct snd_ac97 *snd_soc_new_ac97_component(struct snd_soc_component *component, ret =snd_soc_ac97_init_gpio (ac97, component);if (ret) - goto err_put_device; + goto err_del_device;return ac97; +err_del_device: +device_del (&ac97->dev); err_put_device:put_device (&ac97->dev);return ERR_PTR (ret);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2949/3318 ASoC: soc-component: Fix return type of snd_soc_pcm_component_pointer()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amadeusz Sławiński <[email protected]>
[ Upstream commit 9df30adce80dd6b0646e58c12a4cf7c6c88d0778 ]
Both caller and pointer callback expect the return value to be snd_pcm_uframes_t, however it was defined incorrectly leading to potential truncation of returned value.
--- include/sound/soc-component.h | 2 +- sound/soc/soc-component.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/sound/soc-component.h +1 -1
@@ -505,7 +505,7 @@ int snd_soc_component_compr_set_metadata(struct snd_compr_stream *cstream,int snd_soc_component_compr_get_metadata (struct snd_compr_stream *cstream,struct snd_compr_metadata *metadata); -int snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream); +snd_pcm_uframes_t snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream);int snd_soc_pcm_component_ioctl (struct snd_pcm_substream *substream,unsigned int cmd,void *arg);int snd_soc_pcm_component_sync_stop (struct snd_pcm_substream *substream);
sound/soc/soc-component.c +1 -1
@@ -961,7 +961,7 @@ int snd_soc_component_test_bits(struct snd_soc_component *component, }EXPORT_SYMBOL_GPL (snd_soc_component_test_bits); -int snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream) +snd_pcm_uframes_t snd_soc_pcm_component_pointer (struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *rtd =asoc_substream_to_rtd (substream);struct snd_soc_component *component;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2950/3318 ASoC: mediatek: mt8195: Fix tuner clock error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 8e5a2eabb0d7cbd6db0b94f7f30e1ca2c0a8994f ]
Check and propagate errors from mt8195_afe_enable_clk(). If enabling the tuner clock fails, disable the previously enabled APLL clock.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 24 +++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +19 -5
@@ -241,21 +241,35 @@ static int mt8195_afe_enable_tuner_clk(struct mtk_base_afe *afe, unsigned int id) {struct mt8195_afe_private *afe_priv = afe->platform_priv; +int ret;switch (id) {case MT8195_AUD_PLL1 : -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER ]); + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); +if (ret) +return ret; + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL1_TUNER ]); +if (ret) { +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL ]); +return ret; + }break ;case MT8195_AUD_PLL2 : -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); -mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER ]); + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); +if (ret) +return ret; + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2_TUNER ]); +if (ret) { +mt8195_afe_disable_clk (afe, afe_priv->clk[MT8195_CLK_AUD_APLL2 ]); +return ret; + }break ;default : + ret =0 ;break ; } -return 0 ; +return ret; } static int mt8195_afe_disable_tuner_clk(struct mtk_base_afe *afe,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2951/3318 ASoC: mediatek: mt8195: Fix register access clock error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit c23390ecf5c068976f25d9c8bfa8e298fa12ea3d ]
Check the return value of mt8195_afe_enable_clk() when enabling the register access clocks.
If enabling a clock fails, disable the clocks that were already enabled and propagate the error to the caller
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +12 -3
@@ -608,7 +608,7 @@ static int mt8195_afe_disable_top_cg(struct mtk_base_afe *afe, unsigned int cg_tint mt8195_afe_enable_reg_rw_clk (struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv; -int i; +int i, ret;static const unsigned int clk_array[] = {MT8195_CLK_SCP_ADSP_AUDIODSP ,/* bus clock for infra */ MT8195_CLK_TOP_AUDIO_H_SEL ,/* clock for ADSP bus */
@@ -620,10 +620,19 @@ int mt8195_afe_enable_reg_rw_clk(struct mtk_base_afe *afe) MT8195_CLK_AUD_A1SYS, /* AFE HW clock */ }; -for (i =0 ; i <ARRAY_SIZE (clk_array); i++) -mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +for (i =0 ; i <ARRAY_SIZE (clk_array); i++) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +if (ret) + goto err_disable_clk; + }return 0 ; + +err_disable_clk: +while (--i >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[clk_array[i]]); + +return ret; }int mt8195_afe_disable_reg_rw_clk (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2952/3318 ASoC: mediatek: mt8195: Fix timing system clock error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit f18c0a8e528eb8844ee362324220ab8df3664afe ]
Check the return value of mt8195_afe_enable_clk() when enabling the timing system clocks.
If enabling a clock fails, disable the clocks that were already enabled and propagate the error to the caller. In mt8195_afe_enable_main_clock(), return the error instead of continuing with AFE clock enable.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +12 -3
@@ -671,7 +671,7 @@ static int mt8195_afe_disable_afe_on(struct mtk_base_afe *afe)static int mt8195_afe_enable_timing_sys (struct mtk_base_afe *afe) {struct mt8195_afe_private *afe_priv = afe->platform_priv; -int i; +int i, ret;static const unsigned int clk_array[] = {MT8195_CLK_AUD_A1SYS ,MT8195_CLK_AUD_A2SYS ,
@@ -682,13 +682,22 @@ static int mt8195_afe_enable_timing_sys(struct mtk_base_afe *afe) MT8195_TOP_CG_26M_TIMING, }; -for (i =0 ; i <ARRAY_SIZE (clk_array); i++) -mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +for (i =0 ; i <ARRAY_SIZE (clk_array); i++) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[clk_array[i]]); +if (ret) + goto err_disable_clk; + }for (i =0 ; i <ARRAY_SIZE (cg_array); i++)mt8195_afe_enable_top_cg (afe, cg_array[i]);return 0 ; + +err_disable_clk: +while (--i >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[clk_array[i]]); + +return ret; }static int mt8195_afe_disable_timing_sys (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2953/3318 ASoC: mediatek: mt8195: Fix main clock error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 9f1b48c658ac38be81c04fbc29ed1522f89fb0c9 ]
Check the return values of clock enable functions and propagate errors to the caller.
Disable previously enabled clocks on failure to match the main clock disable sequence.
--- sound/soc/mediatek/mt8195/mt8195-afe-clk.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-clk.c +20 -3
@@ -725,14 +725,31 @@ static int mt8195_afe_disable_timing_sys(struct mtk_base_afe *afe)int mt8195_afe_enable_main_clock (struct mtk_base_afe *afe) { -mt8195_afe_enable_timing_sys (afe); +int ret; + + ret =mt8195_afe_enable_timing_sys (afe); +if (ret) +return ret;mt8195_afe_enable_afe_on (afe); -mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL1 ); -mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL2 ); + ret =mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL1 ); +if (ret) + goto err_disable_afe_on; + + ret =mt8195_afe_enable_apll_tuner (afe,MT8195_AUD_PLL2 ); +if (ret) + goto err_disable_apll1_tuner;return 0 ; + +err_disable_apll1_tuner: +mt8195_afe_disable_apll_tuner (afe,MT8195_AUD_PLL1 ); +err_disable_afe_on: +mt8195_afe_disable_afe_on (afe); +mt8195_afe_disable_timing_sys (afe); + +return ret; }int mt8195_afe_disable_main_clock (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2954/3318 ASoC: mediatek: mt8195: Fix paired memif clock error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit c0ec135cf3fd7c7c7cdefd234111e5d4f069a7e6 ]
Check and propagate errors when preparing and enabling the paired DL8/DL10 memif clocks.
If enabling the second clock fails, undo the clock that was already prepared or enabled to keep the clock state balanced.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 24 ++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +20 -4
@@ -286,15 +286,23 @@ mt8195_afe_paired_memif_clk_prepare(struct snd_pcm_substream *substream,struct mt8195_afe_private *afe_priv = afe->platform_priv;int id =asoc_rtd_to_cpu (rtd,0 )->id;int clk_id; +int ret;if (id !=MT8195_AFE_MEMIF_DL8 && id !=MT8195_AFE_MEMIF_DL10 )return 0 ;if (enable) { clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; -mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); +if (ret) +return ret; clk_id =MT8195_CLK_AUD_MEMIF_DL8 ; -mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_prepare_clk (afe, afe_priv->clk[clk_id]); +if (ret) { + clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; +mt8195_afe_unprepare_clk (afe, afe_priv->clk[clk_id]); +return ret; + } }else { clk_id =MT8195_CLK_AUD_MEMIF_DL8 ;mt8195_afe_unprepare_clk (afe, afe_priv->clk[clk_id]);
@@ -315,6 +323,7 @@ mt8195_afe_paired_memif_clk_enable(struct snd_pcm_substream *substream,struct mt8195_afe_private *afe_priv = afe->platform_priv;int id =asoc_rtd_to_cpu (rtd,0 )->id;int clk_id; +int ret;if (id !=MT8195_AFE_MEMIF_DL8 && id !=MT8195_AFE_MEMIF_DL10 )return 0 ;
@@ -322,11 +331,18 @@ mt8195_afe_paired_memif_clk_enable(struct snd_pcm_substream *substream,if (enable) {/* DL8_DL10_MEM */ clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; -mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); +if (ret) +return ret;udelay (1 );/* DL8_DL10_AGENT */ clk_id =MT8195_CLK_AUD_MEMIF_DL8 ; -mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); + ret =mt8195_afe_enable_clk_atomic (afe, afe_priv->clk[clk_id]); +if (ret) { + clk_id =MT8195_CLK_AUD_MEMIF_DL10 ; +mt8195_afe_disable_clk_atomic (afe, afe_priv->clk[clk_id]); +return ret; + } }else {/* DL8_DL10_AGENT */ clk_id =MT8195_CLK_AUD_MEMIF_DL8 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2955/3318 ASoC: mediatek: mt8195: Fix FE startup error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit b1db7408c8e0761d17b49b74f8f2d60c0c1929e8 ]
Check and propagate errors from paired memif clock preparation and PCM hardware constraints during FE startup.
Unprepare the paired memif clocks and shut down the FE when a later startup step fails to avoid leaving resources enabled on error.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 40 +++++++++++++++------- 1 file changed, 27 insertions(+), 13 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +27 -13
@@ -364,24 +364,38 @@ static int mt8195_afe_fe_startup(struct snd_pcm_substream *substream,int id =asoc_rtd_to_cpu (rtd,0 )->id;int ret =0 ; -mt8195_afe_paired_memif_clk_prepare (substream, dai,1 ); + ret =mt8195_afe_paired_memif_clk_prepare (substream, dai,1 ); +if (ret) +return ret; ret =mtk_afe_fe_startup (substream, dai); +if (ret <0 ) + goto err_clk_unprepare; -snd_pcm_hw_constraint_step (runtime,0 , -SNDRV_PCM_HW_PARAM_BUFFER_BYTES , -MT8195_MEMIF_BUFFER_BYTES_ALIGN ); + ret =snd_pcm_hw_constraint_step (runtime,0 , +SNDRV_PCM_HW_PARAM_BUFFER_BYTES , +MT8195_MEMIF_BUFFER_BYTES_ALIGN ); +if (ret) + goto err_fe_shutdow; + +if (id ==MT8195_AFE_MEMIF_DL7 ) { + ret =snd_pcm_hw_constraint_minmax (runtime, +SNDRV_PCM_HW_PARAM_PERIOD_SIZE , +1 , +MT8195_MEMIF_DL7_MAX_PERIOD_SIZE ); +if (ret <0 ) { +dev_dbg (afe->dev,"hw_constraint_minmax failed\n" ); + goto err_fe_shutdow; + } + } -if (id !=MT8195_AFE_MEMIF_DL7 ) - goto out; +return 0 ; + +err_fe_shutdow: +mtk_afe_fe_shutdown (substream, dai); +err_clk_unprepare: +mt8195_afe_paired_memif_clk_prepare (substream, dai,0 ); - ret =snd_pcm_hw_constraint_minmax (runtime, -SNDRV_PCM_HW_PARAM_PERIOD_SIZE , -1 , -MT8195_MEMIF_DL7_MAX_PERIOD_SIZE ); -if (ret <0 ) -dev_dbg (afe->dev,"hw_constraint_minmax failed\n" ); -out:return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2956/3318 ASoC: mediatek: mt8195: Check paired MEMIF clock enable in FE trigger
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit a2ae972c75a18ecbdcbf331ddaab21e1a08333fb ]
Check the return value of mt8195_afe_paired_memif_clk_enable() on START/RESUME. On failure, stop the MEMIF and disable the channel merge before returning the error.
Also skip enabling the paired clock if mtk_afe_fe_trigger() fails.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +8 -1
@@ -466,7 +466,14 @@ static int mt8195_afe_fe_trigger(struct snd_pcm_substream *substream, int cmd,switch (cmd) {case SNDRV_PCM_TRIGGER_START :case SNDRV_PCM_TRIGGER_RESUME : -mt8195_afe_paired_memif_clk_enable (substream, dai,1 ); +if (ret) +break ; + + ret =mt8195_afe_paired_memif_clk_enable (substream, dai,1 ); +if (ret) { +mtk_afe_fe_trigger (substream,SNDRV_PCM_TRIGGER_STOP , dai); +mt8195_afe_enable_cm (afe, cm, false); + }break ;case SNDRV_PCM_TRIGGER_STOP :case SNDRV_PCM_TRIGGER_SUSPEND :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2957/3318 ASoC: mediatek: mt8195: Fix runtime resume error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 933fbfb6648850e003a1fc47b7bcc08fe3687961 ]
Check and propagate errors when enabling the register access and main clocks during runtime resume.
If regcache_sync() or main clock enable fails, restore regmap cache-only mode and disable the register access clocks before returning the error.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +18 -5
@@ -2967,18 +2967,31 @@ static int mt8195_afe_runtime_resume(struct device *dev) {struct mtk_base_afe *afe =dev_get_drvdata (dev);struct mt8195_afe_private *afe_priv = afe->platform_priv; +int ret; -mt8195_afe_enable_reg_rw_clk (afe); + ret =mt8195_afe_enable_reg_rw_clk (afe); +if (ret) +return ret;if (!afe->regmap || afe_priv->pm_runtime_bypass_reg_ctl) - goto skip_regmap; +return 0 ;regcache_cache_only (afe->regmap, false); -regcache_sync (afe->regmap); + ret =regcache_sync (afe->regmap); +if (ret) + goto err_restore_cache; + + ret =mt8195_afe_enable_main_clock (afe); +if (ret) + goto err_restore_cache; -mt8195_afe_enable_main_clock (afe); -skip_regmap:return 0 ; + +err_restore_cache: +regcache_cache_only (afe->regmap, true); +mt8195_afe_disable_reg_rw_clk (afe); + +return ret; }static int init_memif_priv_data (struct mtk_base_afe *afe)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2958/3318 ASoC: mediatek: mt8195: Propagate IRQ lookup errors
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 9d5dedb285fb61a40e04f337d9e06fc59c065857 ]
Propagate the error returned by platform_get_irq() instead of replacing it with -ENXIO.
This preserves errors such as -EPROBE_DEFER for proper handling by the caller.
--- sound/soc/mediatek/mt8195/mt8195-afe-pcm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/mediatek/mt8195/mt8195-afe-pcm.c +1 -1
@@ -3134,7 +3134,7 @@ static int mt8195_afe_pcm_dev_probe(struct platform_device *pdev)/* request irq */ irq_id =platform_get_irq (pdev,0 );if (irq_id <0 ) -return -ENXIO ; +return irq_id; ret =devm_request_irq (dev, irq_id, mt8195_afe_irq_handler,IRQF_TRIGGER_NONE ,"asys-isr" , (void *)afe);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2959/3318 ASoC: mediatek: mt8195: Fix ETDM MCLK error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 91dce9c7eec25e95b5ca32e17e60e2c27333d411 ]
Propagate errors from mt8195_afe_enable_clk() when enabling the ETDM MCLK instead of always returning success.
This allows callers to properly handle failures when enabling the MCLK.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +1 -3
@@ -1554,9 +1554,7 @@ static int mtk_dai_etdm_enable_mclk(struct mtk_base_afe *afe, int dai_id)if (clkdiv_id <0 )return -EINVAL ; -mt8195_afe_enable_clk (afe, afe_priv->clk[clkdiv_id]); - -return 0 ; +return mt8195_afe_enable_clk (afe, afe_priv->clk[clkdiv_id]); }static int mtk_dai_etdm_disable_mclk (struct mtk_base_afe *afe,int dai_id)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2960/3318 ASoC: mediatek: mt8195: Fix ETDM startup error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 8e67c67f3fd2505b8b7a9dd38d8dabe47273490d ]
Check and propagate errors when enabling the ETDM MCLK and clock gates during startup.
If enabling a clock fails, disable the clocks that were already enabled to keep the clock state balanced.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 50 ++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +40 -10
@@ -1580,36 +1580,66 @@ static int mtk_dai_etdm_startup(struct snd_pcm_substream *substream,int cg_id;int mst_dai_id;int slv_dai_id; -int i; +int i, ret;if (is_cowork_mode (dai)) { mst_dai_id =get_etdm_cowork_master_id (dai);if (!mt8195_afe_etdm_is_valid (mst_dai_id))return -EINVAL ; -mtk_dai_etdm_enable_mclk (afe, mst_dai_id); + ret =mtk_dai_etdm_enable_mclk (afe, mst_dai_id); +if (ret) +return ret; cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (mst_dai_id); -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (ret) + goto err_disable_mclk; + } mst_etdm_data = afe_priv->dai_priv[mst_dai_id];for (i =0 ; i < mst_etdm_data->cowork_slv_count; i++) { slv_dai_id = mst_etdm_data->cowork_slv_id[i]; cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (slv_dai_id); -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, - afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, + afe_priv->clk[cg_id]); +if (ret) + goto err_disable_slv_clk; + } } }else { -mtk_dai_etdm_enable_mclk (afe, dai->id); + ret =mtk_dai_etdm_enable_mclk (afe, dai->id); +if (ret) +return ret; cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (dai->id); -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (ret) + goto err_disable_mclk; + } }return 0 ; + +err_disable_slv_clk: +while (--i >=0 ) { + slv_dai_id = mst_etdm_data->cowork_slv_id[i]; + cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (slv_dai_id); +if (cg_id >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[cg_id]); + } + + cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (mst_dai_id); +if (cg_id >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[cg_id]); + +err_disable_mclk: +mtk_dai_etdm_disable_mclk (afe,is_cowork_mode (dai) ? mst_dai_id : dai->id); + +return ret; } static void mtk_dai_etdm_shutdown(struct snd_pcm_substream *substream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2961/3318 ASoC: mediatek: mt8195: Fix HDMI TX startup error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 1d6f1785d90334b66809a57ebfc40a5b1cfa80ec ]
Check and propagate errors when enabling the clock gate and MCLK during HDMI TX/DP TX startup.
If MCLK enabling fails, disable the clock gate that was already enabled before returning the error.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +15 -3
@@ -2326,13 +2326,25 @@ static int mtk_dai_hdmitx_dptx_startup(struct snd_pcm_substream *substream,struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv;int cg_id =mtk_dai_etdm_get_cg_id_by_dai_id (dai->id); +int ret; -if (cg_id >=0 ) -mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (cg_id >=0 ) { + ret =mt8195_afe_enable_clk (afe, afe_priv->clk[cg_id]); +if (ret) +return ret; + } -mtk_dai_etdm_enable_mclk (afe, dai->id); + ret =mtk_dai_etdm_enable_mclk (afe, dai->id); +if (ret) + goto err_disable_cg_clk;return 0 ; + +err_disable_cg_clk: +if (cg_id >=0 ) +mt8195_afe_disable_clk (afe, afe_priv->clk[cg_id]); + +return ret; } static void mtk_dai_hdmitx_dptx_shutdown(struct snd_pcm_substream *substream,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2962/3318 ASoC: mediatek: mt8195: Fix ETDM probe error handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit ca3ac9a7eec1884bfff2d2dd92caf30f86a9eea7 ]
Use pm_runtime_resume_and_get() to properly handle runtime PM errors during ETDM probe.
Propagate errors from MCLK configuration and enabling instead of ignoring them.
--- sound/soc/mediatek/mt8195/mt8195-dai-etdm.c | 27 ++++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-)
sound/soc/mediatek/mt8195/mt8195-dai-etdm.c +18 -9
@@ -2508,6 +2508,7 @@ static int mtk_dai_etdm_probe(struct snd_soc_dai *dai)struct mtk_base_afe *afe =snd_soc_dai_get_drvdata (dai);struct mt8195_afe_private *afe_priv = afe->platform_priv;struct mtk_dai_etdm_priv *etdm_data; +int ret;dev_dbg (dai->dev,"%s id %d\n" , __func__, dai->id);
@@ -2515,15 +2516,23 @@ static int mtk_dai_etdm_probe(struct snd_soc_dai *dai)return -EINVAL ; etdm_data = afe_priv->dai_priv[dai->id]; -if (etdm_data->mclk_freq) { -dev_dbg (afe->dev,"MCLK always on, rate %d\n" , - etdm_data->mclk_freq); -pm_runtime_get_sync (afe->dev); -mtk_dai_etdm_mclk_configure (afe, dai->id); -mtk_dai_etdm_enable_mclk (afe, dai->id); -pm_runtime_put_sync (afe->dev); - } -return 0 ; +if (!etdm_data->mclk_freq) +return 0 ; + +dev_dbg (afe->dev,"MCLK always on, rate %d\n" , + etdm_data->mclk_freq); + ret =pm_runtime_resume_and_get (afe->dev); +if (ret) +return ret; + ret =mtk_dai_etdm_mclk_configure (afe, dai->id); +if (ret) + goto err_put_pm; + ret =mtk_dai_etdm_enable_mclk (afe, dai->id); + +err_put_pm: +pm_runtime_put_sync (afe->dev); + +return ret; }static const struct snd_soc_dai_ops mtk_dai_hdmitx_dptx_ops = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2963/3318 tracing: Print the bucket size as unsigned
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 387945e8d2f29fa8a28d219af5416e6d3bedc314 ]
A key's bucket size reads back negative once it exceeds LONG_MAX:
# echo 'hist:keys=next_pid.buckets=18446744073709551615' > trigger # cat trigger hist:keys=next_pid.buckets=-1:vals=hitcount:...
parse_field() takes the size with kstrtoul() and rejects only zero, so the whole unsigned long range is accepted and stored, but hist_field_print() renders it with %ld.
Print it with %lu.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -6184,7 +6184,7 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) } }if (hist_field->buckets) -seq_printf (m,"=%ld" , hist_field->buckets); +seq_printf (m,"=%lu" , hist_field->buckets); } static int event_hist_trigger_print(struct seq_file *m,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2964/3318 tracing: Only report the stacktrace modifier on a real field
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 18bb005845b78e0c0eb44b7f231c29d138552438 ]
get_hist_field_flags() returns "stacktrace" for any field carrying HIST_FIELD_FL_STACKTRACE, including the common_stacktrace pseudo-field, which has no ftrace_event_field behind it. parse_field() no longer takes the modifier there:
if (stack_modifier &&
(!field || field->filter_type != FILTER_STACKTRACE)) {
hist_err(tr, HIST_ERR_BAD_FIELD_MODIFIER, errpos(field_str));so expr_field_str() renders "common_stacktrace.stacktrace", a spelling that cannot be parsed back.
Report the modifier only when there is a field to report it for.
hist_field_print(), the other caller of get_hist_field_flags(), excludes HIST_FIELD_FL_STACKTRACE before it calls, so this is confined to expr_field_str(), whose only key renderer arrives in the next patch.
--- kernel/trace/trace_events_hist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
@@ -1718,7 +1718,7 @@ static const char *get_hist_field_flags(struct hist_field *hist_field) flags_str ="percent" ; else if (hist_field->flags & HIST_FIELD_FL_GRAPH) flags_str ="graph" ; - else if (hist_field->flags & HIST_FIELD_FL_STACKTRACE) + else if (hist_field->flags & HIST_FIELD_FL_STACKTRACE && hist_field->field) flags_str ="stacktrace" ;return flags_str;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2965/3318 tracing: Clamp the printed end of a histogram bucket at U64_MAX
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 289e2a775de434ccab2d107076bc78362ce288bd ]
A key with the ".buckets=N" modifier is stored as the start of its bucket, and hist_trigger_print_key() prints the range it covers as start to start + N - 1. That addition overflows once the start is within N of U64_MAX:
# echo 'hist:keys=offset.buckets=10' >> \
events/syscalls/sys_enter_lseek/trigger
# ./seeker 5 -1 # lseek(0, 5) and lseek(0, -1)
# cat events/syscalls/sys_enter_lseek/hist
...
{ offset: ~ 18446744073709551610-3 } hitcount: 1
{ offset: ~ 0-9 } hitcount: 1
...18446744073709551610 + 10 - 1 does not fit in 64 bits, so the range ends below where it starts.
The bucket does end at U64_MAX: it holds every value hist_field_bucket() maps onto its start, and there is no value above U64_MAX. Clamp the printed end there. Printed honestly the group is shorter than the size asked for, which histogram.rst does not mention, so say it there.
--- Documentation/trace/histogram.rst | 3 +++ kernel/trace/trace_events_hist.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
Documentation/trace/histogram.rst +3 -0
@@ -1943,6 +1943,9 @@ the ".buckets" modifier and specify a size (in this case groups of 10):: Entries: 16 Dropped: 0 +Keys are 64-bit, so the group holding the largest values is truncated where +that range ends and can be smaller than the size asked for. + To save stacktraces, create a synthetic event with a field of type "unsigned long[]" or even just "long[]". For example, to see how long a task is blocked in an uninterruptible state::
kernel/trace/trace_events_hist.c +6 -1
@@ -5548,9 +5548,14 @@ static void hist_trigger_print_key(struct seq_file *m, *(u64 *)(key + key_field->offset)); }else if (key_field->flags &HIST_FIELD_FL_BUCKET ) {unsigned long buckets = key_field->buckets; +u64 end; + uval = *(u64 *)(key + key_field->offset); + end = uval + buckets -1 ; +if (end < uval) + end =U64_MAX ;seq_printf (m,"%s: ~ %llu-%llu" , field_name, - uval, uval + buckets -1 ); + uval, end); }else if (key_field->flags &HIST_FIELD_FL_STRING ) {seq_printf (m,"%s: %-50s" , field_name, (char *)(key + key_field->offset));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2966/3318 tracing: Avoid BTF lookup in atomic context
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: pengdonglin <[email protected]>
[ Upstream commit 42643ba35deb8ad1821acfc0577b445ee7ad7548 ]
The function graph trace formatter can be called from ftrace_dump_one() with interrupts disabled. When ftrace_dump_on_oops is enabled, the trace panic notifier can reach ftrace_dump() from the panic path, including the nmi_panic() path used by the hard lockup detector.
btf_find_func_proto() calls bpf_find_btf_id(), which may initialize vmlinux BTF under a mutex. Skip the BTF lookup when running in an atomic context or with interrupts disabled, and fall back to the existing return value formatting.
--- kernel/trace/trace_btf.c | 3 +++ 1 file changed, 3 insertions(+)
kernel/trace/trace_btf.c +3 -0
@@ -15,6 +15,9 @@ const struct btf_type *btf_find_func_proto(const char *func_name, struct btf **bconst struct btf_type *t;s32 id; +if (unlikely (in_atomic () ||irqs_disabled ())) +return NULL ; + id =bpf_find_btf_id (func_name,BTF_KIND_FUNC , btf_p);if (id <0 )return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2967/3318 net/smc: hold a reference on net_device returned by pnet_find_base_ndev()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Atharva Vartak <[email protected]>
[ Upstream commit e6435b2cc5fdf008cdb67ad9a811a266e8ac9c1e ]
pnet_find_base_ndev() resolves the base net_device for stacked devices under RTNL, then drops the lock and returns the raw pointer without taking a reference. All three callers dereference the pointer after RTNL has been released, creating a use-after-free window if the device is concurrently unregistered.
Take a reference with netdev_hold() before dropping RTNL and add the matching netdev_put() in every return path of the three callers:
- smc_pnet_add_eth()
- smc_pnet_find_roce_by_pnetid()
- smc_pnet_find_ism_by_pnetid()
Found by code analysis, confirmed with a proof-of-concept that triggers a KASAN slab-use-after-free report.
--- net/smc/smc_pnet.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
net/smc/smc_pnet.c +22 -7
@@ -30,7 +30,8 @@#include "smc_core.h" static struct net_device *__pnet_find_base_ndev (struct net_device *ndev); -static struct net_device *pnet_find_base_ndev (struct net_device *ndev); +static struct net_device *pnet_find_base_ndev (struct net_device *ndev, +netdevice_tracker *tracker);static const struct nla_policy smc_pnet_policy[SMC_PNETID_MAX +1 ] = { [SMC_PNETID_NAME ] = {
@@ -348,6 +349,7 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net,struct smc_pnetentry *tmp_pe, *new_pe;struct net_device *ndev, *base_ndev;u8 ndev_pnetid[SMC_MAX_PNETID_LEN ]; +netdevice_tracker base_tracker;bool new_netdev;int rc;
@@ -357,10 +359,13 @@ static int smc_pnet_add_eth(struct smc_pnettable *pnettable, struct net *net, rc = -EEXIST ; ndev =dev_get_by_name (net, eth_name);/* dev_hold() */ if (ndev) { - base_ndev =pnet_find_base_ndev (ndev); + base_ndev =pnet_find_base_ndev (ndev, &base_tracker);if (!smc_pnetid_by_dev_port (base_ndev->dev.parent, - base_ndev->dev_port, ndev_pnetid)) + base_ndev->dev_port, ndev_pnetid)) { +netdev_put (base_ndev, &base_tracker); goto out_put; + } +netdev_put (base_ndev, &base_tracker); }/* add a new netdev entry to the pnet table if there isn't one */
@@ -943,10 +948,13 @@ static struct net_device *__pnet_find_base_ndev(struct net_device *ndev)* (for instance with bonding slaves), just the first device * is used to reach a base device. */ -static struct net_device *pnet_find_base_ndev (struct net_device *ndev) +static struct net_device *pnet_find_base_ndev (struct net_device *ndev, +netdevice_tracker *tracker) {rtnl_lock (); ndev =__pnet_find_base_ndev (ndev); +/* keep ndev alive after dropping RTNL, callers must netdev_put() */ +netdev_hold (ndev, tracker,GFP_KERNEL );rtnl_unlock ();return ndev; }
@@ -1085,17 +1093,20 @@ static void smc_pnet_find_roce_by_pnetid(struct net_device *ndev, {u8 ndev_pnetid[SMC_MAX_PNETID_LEN ];struct net_device *base_ndev; +netdevice_tracker base_tracker;struct net *net; - base_ndev =pnet_find_base_ndev (ndev); + base_ndev =pnet_find_base_ndev (ndev, &base_tracker); net =dev_net (ndev);if (smc_pnetid_by_dev_port (base_ndev->dev.parent, base_ndev->dev_port, ndev_pnetid) &&smc_pnet_find_ndev_pnetid_by_table (base_ndev, ndev_pnetid) &&smc_pnet_find_ndev_pnetid_by_table (ndev, ndev_pnetid)) {smc_pnet_find_rdma_dev (base_ndev, ini); +netdev_put (base_ndev, &base_tracker);return ;/* pnetid could not be determined */ } +netdev_put (base_ndev, &base_tracker);_smc_pnet_find_roce_by_pnetid (ndev_pnetid, ini,NULL , net); }
@@ -1103,13 +1114,16 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, struct smc_init_info *ini) {u8 ndev_pnetid[SMC_MAX_PNETID_LEN ]; +netdevice_tracker base_tracker;struct smcd_dev *ismdev; - ndev =pnet_find_base_ndev (ndev); + ndev =pnet_find_base_ndev (ndev, &base_tracker);if (smc_pnetid_by_dev_port (ndev->dev.parent, ndev->dev_port, ndev_pnetid) && -smc_pnet_find_ndev_pnetid_by_table (ndev, ndev_pnetid)) +smc_pnet_find_ndev_pnetid_by_table (ndev, ndev_pnetid)) { +netdev_put (ndev, &base_tracker);return ;/* pnetid could not be determined */ + }mutex_lock (&smcd_dev_list.mutex);list_for_each_entry (ismdev, &smcd_dev_list.list, list) {
@@ -1123,6 +1137,7 @@ static void smc_pnet_find_ism_by_pnetid(struct net_device *ndev, } }mutex_unlock (&smcd_dev_list.mutex); +netdev_put (ndev, &base_tracker); }/* PNET table analysis for a given sock:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2968/3318 tracing: Print a signed histogram key as signed
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 d3e0dfc1ba49a0ab6aeddbb4bcde4bfc0e171a02 ]
A histogram sorts its rows by the key named in sort=, and for a key over a signed event field it sorts them signed: create_tracing_map_fields() picks the comparison function with
else cmp_fn = tracing_map_cmp_num(field->size, field->is_signed);
hist_trigger_print_key() does not look at is_signed at all. Every numeric key is printed with %llu, so a sorted histogram over a signed field comes out looking unsorted. syscalls/sys_exit_lseek carries "long ret", which SYSCALL_FIELD() marks signed and which is negative on every error:
# echo 'hist:keys=ret:sort=ret' > events/syscalls/sys_exit_lseek/trigger # echo 1 > events/syscalls/sys_exit_lseek/enable # (five lseek(2) calls returning -ESPIPE, -EINVAL, -EBADF, 0 and 100) # cat events/syscalls/sys_exit_lseek/hist
{ ret: 18446744073709551587 } hitcount: 1
{ ret: 18446744073709551594 } hitcount: 1
{ ret: 18446744073709551607 } hitcount: 1 { ret: 0 } hitcount: 1
{ ret: 100 } hitcount: 1
The rows are in ascending order and the numbers are not, because the three leading ones are -29, -22 and -9 rendered as their two's complement.
Take the rendering from the same place the sort order comes from: the event field when the key has one, and the hist_field itself when it does not. The same histogram then reads
{ ret: -29 } hitcount: 1
{ ret: -22 } hitcount: 1
{ ret: -9 } hitcount: 1
{ ret: 0 } hitcount: 1
{ ret: 100 } hitcount: 1A ".buckets" key stays unsigned here, and not because it is right. hist_field_bucket() divides as unsigned, so the group holding S64_MAX also holds S64_MIN, reported at
https://lore.kernel.org/all/[email protected]/
Printing that group signed would name a range that does not contain S64_MIN, so the grouping has to be fixed with it, in a patch of its own.
--- kernel/trace/trace_events_hist.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +13 -1
@@ -272,6 +272,14 @@ static u64 hist_field_pstring(struct hist_field *hist_field,return (u64 )(unsigned long )*addr; } +static bool hist_field_is_signed (struct hist_field *hist_field) +{ +if (hist_field->field) +return hist_field->field->is_signed; + +return hist_field->is_signed; +} + static u64 hist_field_log2(struct hist_field *hist_field, struct tracing_map_elt *elt, struct trace_buffer *buffer,
@@ -5561,7 +5569,11 @@ static void hist_trigger_print_key(struct seq_file *m, (char *)(key + key_field->offset)); }else { uval = *(u64 *)(key + key_field->offset); -seq_printf (m,"%s: %10llu" , field_name, uval); +if (hist_field_is_signed (key_field)) +seq_printf (m,"%s: %10lld" , field_name, + (s64 )uval); +else +seq_printf (m,"%s: %10llu" , field_name, uval); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2969/3318 selftests/bpf: Fix prog_tests framework subtest count checks
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: KaFai Wan <[email protected]>
[ Upstream commit c87652656a55e5e8cf994364314a75fa95fb2d69 ]
The hardcoded expected skip_cnt/error_cnt in test_prog_tests_framework() mismatch the real count when the binary is run with -t or -n filters, since some subtests are not selected. Count the executed subtests and compare against that value instead.
--- .../selftests/bpf/prog_tests/prog_tests_framework.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/prog_tests/prog_tests_framework.c +8 -2
@@ -13,6 +13,7 @@ static void clear_test_state(struct test_state *state)void test_prog_tests_framework (void ) {struct test_state *state = env.test_state; +int subtest_cnt;/* in all the ASSERT calls below we need to return on the first * error due to the fact that we are cleaning the test state after
@@ -30,25 +31,30 @@ void test_prog_tests_framework(void)return ;clear_test_state (state); + subtest_cnt =0 ;if (test__start_subtest ("test_skip_subtest" )) {test__skip ();test__end_subtest (); + subtest_cnt++; }if (test__start_subtest ("test_skip_subtest" )) {test__skip ();test__end_subtest (); + subtest_cnt++; } -if (!ASSERT_EQ (state->skip_cnt,2 ,"skip_cnt_check" )) +if (!ASSERT_EQ (state->skip_cnt, subtest_cnt,"skip_cnt_check" ))return ;if (!ASSERT_EQ (state->subtest_num,3 ,"subtest_num_check" ))return ;clear_test_state (state); + subtest_cnt =0 ;if (test__start_subtest ("test_fail_subtest" )) {test__fail ();test__end_subtest (); + subtest_cnt++; } -if (!ASSERT_EQ (state->error_cnt,1 ,"error_cnt_check" )) +if (!ASSERT_EQ (state->error_cnt, subtest_cnt,"error_cnt_check" ))return ;if (!ASSERT_EQ (state->subtest_num,4 ,"subtest_num_check" ))return ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2970/3318 macsec: prevent AES-GCM nonce reuse after packet number wrap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jérémy Jean <[email protected]>
[ Upstream commit 94d51c59f0a872c57cb8daa1964ec033d77a79fb ]
After allocating the last valid packet number, MACsec wraps next_pn to zero and deactivates the transmit SA. This happens for both 32- and 64-bit types of packet numbers (at values 0xffffffff and 0xffffffffffffffff, respectively).
TX packets that were still getting processed during deactivation keep being processed and then receive packet numbers. The first gets 0 and is correctly dropped, but next_pn is incremented to 1, which makes the next packet take number 1. It then does not get dropped and may induce a reuse of the AES-GCM nonce corresponding to value 1.
This race affects TX packets that have already passed the SA activity
check: packets that observe the inactive SA are correctly dropped. Reactivating the SA after PN wrap without a packet number can also cause nonce reuse. Keep next_pn at 0 after wrap, even if the SA is reactivated, so further packet number allocations return 0 and the corresponding packets are dropped.
--- drivers/net/macsec.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/macsec.c +5 -0
@@ -478,6 +478,9 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,spin_lock_bh (&tx_sa->lock); pn = tx_sa->next_pn_halves; +if (unlikely (pn.full64 ==0 )) + goto out; +if (secy->xpn) tx_sa->next_pn++;else
@@ -485,6 +488,8 @@ static pn_t tx_sa_update_pn(struct macsec_tx_sa *tx_sa,if (tx_sa->next_pn ==0 )__macsec_pn_wrapped (secy, tx_sa); + +out:spin_unlock_bh (&tx_sa->lock);return pn;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2971/3318 net: usb: lan78xx: reject invalid EEPROM write requests
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stefano Munari <[email protected]>
[ Upstream commit 9272297df14124fe603c81e40b52ff0c5dd88652 ]
The runtime PM handling removed the -EINVAL return for invalid EEPROM/OTP write requests. These requests now return zero from a successful usb_autopm_get_interface() call, even though no data is written.
Set ret to -EINVAL for invalid requests while preserving the runtime PM reference release.
--- drivers/net/usb/lan78xx.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/net/usb/lan78xx.c +6 -3
@@ -1745,13 +1745,16 @@ static int lan78xx_ethtool_set_eeprom(struct net_device *netdev,/* Invalid EEPROM_INDICATOR at offset zero will result in a failure * to load data from EEPROM */ -if (ee->magic ==LAN78XX_EEPROM_MAGIC ) +if (ee->magic ==LAN78XX_EEPROM_MAGIC ) { ret =lan78xx_write_raw_eeprom (dev, ee->offset, ee->len, data); -else if ((ee->magic ==LAN78XX_OTP_MAGIC ) && + }else if ((ee->magic ==LAN78XX_OTP_MAGIC ) && (ee->offset ==0 ) && (ee->len ==512 ) && - (data[0 ] ==OTP_INDICATOR_1 )) + (data[0 ] ==OTP_INDICATOR_1 )) { ret =lan78xx_write_raw_otp (dev, ee->offset, ee->len, data); + }else { + ret = -EINVAL ; + }usb_autopm_put_interface (dev->intf);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2972/3318 bnx2x: fix header length calculation for encapsulated TSO
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: George Melikov <[email protected]>
[ Upstream commit 4fc1d5bb448dfab391a96f949d02ad03ad8cda5c ]
Commit 80bfab79b835 ("net: adopt skb_network_offset() and similar helpers") replaced the difference between the inner transport header and the outer network header with skb_inner_transport_offset().
The helper is relative to skb->data, so the new calculation incorrectly includes the outer Ethernet header in fw_ip_hdr_to_payload_w.
On a BCM57810 transmitting TCP over VXLAN with an outer MTU of 1500, hardware segmentation emits packets declaring an outer IPv4 total length of 1514 while the actual IP packet is only 1500 bytes long. The receiver drops these malformed packets, severely degrading TCP connectivity.
Subtract skb_network_offset() to restore the original calculation of the length from the outer network header to the inner TCP payload.
Reproduced with plain kernel VXLAN and one TCP flow on kernel 7.0.0-31-generic: 50 of 200 captured packets had an invalid outer IP length with the original driver, versus none with this fix. Disabling TSO/GSO on the test VXLAN device also eliminated the error with the original driver.
--- drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.c +2 -1
@@ -3667,7 +3667,8 @@ static void bnx2x_update_pbds_gso_enc(struct sk_buff *skb,u8 outerip_off, outerip_len =0 ;/* from outer IP to transport */ - hlen_w =skb_inner_transport_offset (skb) >>1 ; + hlen_w = (skb_inner_transport_offset (skb) - +skb_network_offset (skb)) >>1 ;/* transport len */ hlen_w +=inner_tcp_hdrlen (skb) >>1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2973/3318 net: use the full socket in sk_mc_loop()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Theodor Arsenij Larionov Trichkine <[email protected]>
[ Upstream commit 31b564f70d8819a1c11d0fd504fe582fc0e0f0cf ]
sk_mc_loop() is called from ip_mc_output() and ip6_finish_output2() with skb->sk, which is not always a full socket:
- Since commit ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener"), a SYNACK is attached to its request socket.
- Since commit 79636038d37e ("ipv4: tcp: give socket pointer to control skbs"), an ACK or RST sent by ip_send_unicast_reply() on behalf of a TIME_WAIT socket is attached to the timewait socket.
When such a packet uses a multicast route, inet_test_bit(MC_LOOP, sk) reads inet_flags past the end of the request or timewait socket.
This happens for instance when a SYN with a multicast source address reaches a listener, after being looped back with its dst attached, so that ip_rcv_finish_core() skips the martian source check. A raw IP_HDRINCL socket sending to a local address does this, as does re-injection by nft dup or the iptables TEE target. The destination can also come from a source route option, or from a route of type multicast covering a unicast prefix.
BUG: KASAN: slab-out-of-bounds in sk_mc_loop+0x111/0x170 Read of size 8 at addr ffff88800f2b7f10 by task repro-raw/470 Call Trace: <IRQ> sk_mc_loop+0x111/0x170 ip_mc_output+0x355/0x930 ip_build_and_send_pkt+0xb87/0xc50 tcp_v4_send_synack+0x500/0x6f0 tcp_conn_request+0x2135/0x2d90 tcp_v4_conn_request+0xa5/0x210 tcp_rcv_state_process+0x136e/0x6920 tcp_v4_do_rcv+0x339/0xb10 tcp_v4_rcv+0x34ab/0x3ab0 ip_protocol_deliver_rcu+0x6e/0x3e0 ip_local_deliver_finish+0x34d/0x510 ip_local_deliver+0x1bc/0x310 ip_rcv+0x390/0x410 __netif_receive_skb_one_core+0x199/0x1e0 process_backlog+0x239/0x680 __napi_poll+0xb5/0x650 net_rx_action+0x980/0xd60 handle_softirqs+0x17f/0x590 do_softirq+0x3f/0x60 </IRQ> The buggy address belongs to the object at ffff88800f2b7d60 which belongs to the cache request_sock_TCP of size 312
The buggy address is located 120 bytes to the right of
allocated 312-byte region [ffff88800f2b7d60, ffff88800f2b7e98)
Use sk_const_to_full_sk(), which restores the behavior from before the two commits above: a request socket uses the setting of its listener, and a timewait socket gets the default (loop back), as the per-cpu control socket used before had.
--- net/core/sock.c | 1 + 1 file changed, 1 insertion(+)
net/core/sock.c +1 -0
@@ -765,6 +765,7 @@ bool sk_mc_loop(const struct sock *sk) {if (dev_recursion_level ())return false; + sk =sk_const_to_full_sk (sk);if (!sk)return true;/* IPV6_ADDRFORM can change sk->sk_family under us. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2974/3318 selftests/bpf: Keep the bpffs of cgroup_hierarchical_stats private
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit 3c824dfd17e6e918e45a6a96bda0d020ddec8287 ]
setup_hierarchy() mounts a bpffs on /sys/fs/bpf with setup_bpffs(), and then sets up the cgroups with setup_cgroups(), which moves the test into a private mount namespace.
The bpffs thus lands in the mount namespace that test_progs shares with the tests running in parallel, on top of the bpffs already there, and hides what they pin. cleanup_bpffs() later runs in the private mount namespace and can't unmount it, so it stays there for good. bpftool_maps_access then fails to pin an iterator because /sys/fs/bpf/test_bpftool_map doesn't exist anymore, and bpftool_metadata can't find the program it pinned in /sys/fs/bpf/test_metadata.
Set up the cgroups first, so that the bpffs is mounted in the private mount namespace.
--- .../selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c +1 -1
@@ -151,7 +151,7 @@ static void cleanup_cgroups(void)/* Sets up cgroup hiearchary, returns 0 on success. */ static int setup_hierarchy (void ) { -return setup_bpffs () ||setup_cgroups (); +return setup_cgroups () ||setup_bpffs (); }static void destroy_hierarchy (void )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2975/3318 selftests/bpf: Unmount the bpffs that cgroup_hierarchical_stats mounted
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qiliang Yuan <[email protected]>
[ Upstream commit e0645cfd0e1b2ae7b8ad989bef00a30016b16b5f ]
setup_bpffs() mounts a bpffs on /sys/fs/bpf and records in mounted_bpffs whether it did, so that cleanup_bpffs() unmounts only a bpffs that the test mounted itself.
cleanup_bpffs() checks the flag the other way around. As mounting on /sys/fs/bpf succeeds even when a bpffs is already there, the test never unmounts the bpffs it mounted, and every run leaves another one stacked on /sys/fs/bpf of the mount namespace that the test_progs worker keeps running later tests in.
Unmount the bpffs only when setup_bpffs() mounted it.
--- .../selftests/bpf/prog_tests/cgroup_hierarchical_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/bpf/prog_tests/cgroup_hierarchical_stats.c +1 -1
@@ -110,7 +110,7 @@ static void cleanup_bpffs(void)ASSERT_OK (rmdir (BPFFS_ATTACH_COUNTERS ),"rmdir " BPFFS_ATTACH_COUNTERS );/* Unmount bpffs, if it wasn't already mounted when we started */ -if (mounted_bpffs) +if (!mounted_bpffs)return ;ASSERT_OK (umount (BPFFS_ROOT ),"unmount bpffs" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2976/3318 ALSA: vmaster: Protect follower lookup and setup
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 db2db2dec96e24d067cc5692ac5eec35830ee8d9 ]
A control selected by snd_ctl_add_followers() must remain alive until _snd_ctl_add_follower() has copied it and installed its wrapper. The lookup returns a raw pointer without retaining the control, and neither the short-lived list lookup lock nor the fast lookup protects later use.
If a kernel client adds followers to a live virtual master while another client removes or replaces a published follower, the following order is possible, with the card and master kept alive:
Follower setup Control removal
snd_ctl_add_followers()
snd_ctl_find_id_mixer()
return follower
snd_ctl_remove()
down_write(controls_rwsem)
__snd_ctl_remove()
unlink follower
snd_ctl_free_one(follower)
up_write(controls_rwsem)
_snd_ctl_add_follower()
read follower->countRemoval completes after lookup returns and before setup reads the control. Since setup holds neither controls_rwsem nor a reference, the count read and subsequent control copies can access freed memory.
Hold controls_rwsem for writing across the lookup and follower setup. This prevents removal or replacement from freeing the selected control until wrapper installation is complete. Write ownership also excludes control callbacks while setup changes the callback and private fields.
KASAN report as below:
BUG: KASAN: slab-use-after-free in _snd_ctl_add_follower+0x452/0x520
Read of size 4 at addr ffff888107957d50 by task loadmodule/491
CPU: 3 UID: 0 PID: 491 Comm: loadmodule Tainted: G O 7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy)
Tainted: [O]=OOT_MODULE
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
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? _snd_ctl_add_follower+0x452/0x520
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? _snd_ctl_add_follower+0x452/0x520
kasan_report+0xe0/0x110
? _snd_ctl_add_follower+0x452/0x520
_snd_ctl_add_follower+0x452/0x520
snd_ctl_add_followers+0x153/0x2b0
? srso_alias_return_thunk+0x5/0xfbef5
? __pfx_snd_ctl_add_followers+0x10/0x10
? __might_fault+0x135/0x190
? srso_alias_return_thunk+0x5/0xfbef5
? __might_fault+0x14e/0x190
? __pfx_fixture_write+0x10/0x10 [pmbd_vmaster_fixture]
fixture_write+0x174/0x1f0 [pmbd_vmaster_fixture]
? __pfx_fixture_write+0x10/0x10 [pmbd_vmaster_fixture]
? __pfx___might_resched+0x10/0x10
proc_reg_write+0x1fb/0x2d0
vfs_write+0x25a/0x1010
? __pfx_proc_reg_write+0x10/0x10
? kmem_cache_free+0x242/0x580
? __pfx_vfs_write+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? putname+0x93/0xe0
? srso_alias_return_thunk+0x5/0xfbef5
? do_sys_openat2+0x12a/0x1b0
? __pfx_do_sys_openat2+0x10/0x10
ksys_write+0x111/0x200
? __pfx_ksys_write+0x10/0x10
? irqentry_exit+0xbe/0x820
? srso_alias_return_thunk+0x5/0xfbef5
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f0b835a9687
Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007ffc82ea0360 EFLAGS: 00000202 ORIG_RAX: 0000000000000001
RAX: ffffffffffffffda RBX: 00007f0b83517780 RCX: 00007f0b835a9687
RDX: 0000000000000005 RSI: 0000564f8a21d074 RDI: 0000000000000003
RBP: 0000000000000003 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 0000000000000000
R13: 00007ffc82ea04f0 R14: 00007f0b83755000 R15: 0000564f8a21ed78
</TASK>
Allocated by task 485:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_noprof+0x2d7/0x770
snd_ctl_new+0x51/0x190
snd_ctl_new1+0x13c/0x650
0xffffffffc04011b5
do_one_initcall+0xf3/0x4e0
do_init_module+0x281/0x8e0
load_module+0x658c/0x7cc0
init_module_from_file+0x15b/0x180
idempotent_init_module+0x22d/0x770
__x64_sys_finit_module+0xd2/0x160
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 492:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
__snd_ctl_remove+0x2ac/0x3d0
snd_ctl_remove+0x46/0x70
fixture_write+0x1ae/0x1f0 [pmbd_vmaster_fixture]
proc_reg_write+0x1fb/0x2d0
vfs_write+0x25a/0x1010
ksys_write+0x111/0x200
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888107957d00
which belongs to the cache kmalloc-192 of size 192
The buggy address is located 80 bytes inside of
freed 192-byte region [ffff888107957d00, ffff888107957dc0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x107957
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000423c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000100010 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888107957c00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff888107957c80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff888107957d00: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff888107957d80: fb fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888107957e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
==================================================================--- sound/core/vmaster.c | 3 +++ 1 file changed, 3 insertions(+)
sound/core/vmaster.c +3 -0
@@ -288,6 +288,8 @@ EXPORT_SYMBOL(_snd_ctl_add_follower);* * Adds the multiple follower kcontrols with the given names. * Returns 0 for success or a negative error code. +* +* Note that this function takes card->controls_rwsem lock internally. */ int snd_ctl_add_followers (struct snd_card *card,struct snd_kcontrol *master,const char *const *list)
@@ -295,6 +297,7 @@ int snd_ctl_add_followers(struct snd_card *card, struct snd_kcontrol *master,struct snd_kcontrol *follower;int err; +guard (rwsem_write)(&card->controls_rwsem);for (; *list; list++) { follower =snd_ctl_find_id_mixer (card, *list);if (follower) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2977/3318 HID: wacom: fix wacom_intuos_irq NULL pen_input deref
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matheus Alves de Almeida <[email protected]>
[ Upstream commit 2f985de0afbe9366af9d322ea20589712c1dc8fe ]
Currently, wacom_intuos_irq() passes the parent of wacom_wac's pen_input to the dev_dbg() in the unknown report path. However, pen_input can be NULL on interfaces without a pen, causing a NULL pointer dereference.
Get the HID device from the enclosing struct wacom and use hid_dbg() instead.
--- drivers/hid/wacom_wac.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/hid/wacom_wac.c +7 -7
@@ -1073,10 +1073,10 @@ static int wacom_intuos_general(struct wacom_wac *wacom)return 2 ; } -static int wacom_intuos_irq (struct wacom_wac *wacom) +static int wacom_intuos_irq (struct wacom_wac *wacom_wac) { -unsigned char *data = wacom->data; -struct input_dev *input = wacom->pen_input; +unsigned char *data = wacom_wac->data; + struct wacom *wacom = container_of(wacom_wac, struct wacom, wacom_wac);int result; if (data[0] != WACOM_REPORT_PENABLED &&
@@ -1087,23 +1087,23 @@ static int wacom_intuos_irq(struct wacom_wac *wacom) data[0] != WACOM_REPORT_CINTIQ && data[0] != WACOM_REPORT_CINTIQPAD && data[0] != WACOM_REPORT_INTUOS5PAD) { -dev_dbg (input->dev.parent, +hid_dbg (wacom->hdev,"%s: received unknown report #%d\n" , __func__, data[0 ]);return 0 ; }/* process pad events */ - result =wacom_intuos_pad (wacom); + result =wacom_intuos_pad (wacom_wac);if (result)return result;/* process in/out prox events */ - result =wacom_intuos_inout (wacom); + result =wacom_intuos_inout (wacom_wac);if (result)return result -1 ;/* process general packets */ - result =wacom_intuos_general (wacom); + result =wacom_intuos_general (wacom_wac);if (result)return result -1 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2978/3318 bpftool: Fix inverted tracefs validation when scanning /proc/mounts
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 21c755efaab1f40c2588ae5acbfa319a6d7d3638 ]
The /proc/mounts fallback in get_tracefs_pipe() accepts only non-tracefs mount points, so a tracefs mounted outside the default locations is
ignored: bpftool prog tracelog then mounts a second tracefs, or exits silently with --nomount. Negate the condition.
--- tools/bpf/bpftool/tracelog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/tracelog.c +1 -1
@@ -88,7 +88,7 @@ static bool get_tracefs_pipe(char *mnt)fclose (fp);/* The string from fscanf() might be truncated, check mnt is valid */ -if (found &&validate_tracefs_mnt (mnt,TRACEFS_MAGIC )) +if (found && !validate_tracefs_mnt (mnt,TRACEFS_MAGIC )) goto exit_found;if (block_mount)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2979/3318 blk-iocost: charge zone appends as writes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit febdbf5682fa7e8f325b07a2c115e7632c4252bd ]
Zone append is a primary write operation for zoned devices; zoned xfs and btrfs use it for data writes. It is priced at zero, so the zone append portion of zoned workloads runs outside the controller: a 1%-weight cgroup issued 16000 appends at zero cost on a zoned null_blk.
Treat REQ_OP_ZONE_APPEND the same as REQ_OP_WRITE so it goes through the existing seq/rand classification and charging.
--- block/blk-iocost.c | 1 + 1 file changed, 1 insertion(+)
block/blk-iocost.c +1 -0
@@ -2548,6 +2548,7 @@ static void calc_vtime_cost_builtin(struct bio *bio, struct ioc_gq *iocg, coef_randio = ioc->params.lcoefs[LCOEF_RRANDIO ]; coef_page = ioc->params.lcoefs[LCOEF_RPAGE ];break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : coef_seqio = ioc->params.lcoefs[LCOEF_WSEQIO ]; coef_randio = ioc->params.lcoefs[LCOEF_WRANDIO ];
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2980/3318 blk-iocost: account zone append completions in latency stats
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Cui <[email protected]>
[ Upstream commit c38975c427cc3d3f6eb66a36143893be5cdf4ebd ]
ioc_rqos_done() only accounts READ and WRITE completions, so zone append completions are excluded from the latency window: the vrate feedback loop cannot see ZA-induced latency, leaving it unable to respond to device saturation caused by zone appends. Similarly, calc_size_vtime_cost_builtin() does not classify zone append as a write operation.
Charging (the cost model) and feedback (the latency window) are separate mechanisms, so this is not covered by the previous patch that prices zone appends.
Treat zone append as WRITE for both latency accounting and cost classification.
--- block/blk-iocost.c | 2 ++ 1 file changed, 2 insertions(+)
block/blk-iocost.c +2 -0
@@ -2592,6 +2592,7 @@ static void calc_size_vtime_cost_builtin(struct request *rq, struct ioc *ioc,case REQ_OP_READ : *costp = pages * ioc->params.lcoefs[LCOEF_RPAGE ];break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : *costp = pages * ioc->params.lcoefs[LCOEF_WPAGE ];break ;
@@ -2828,6 +2829,7 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) pidx =QOS_RLAT ; rw =READ ;break ; +case REQ_OP_ZONE_APPEND :case REQ_OP_WRITE : pidx =QOS_WLAT ; rw =WRITE ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2981/3318 ima: reject a kexec buffer whose declared size exceeds the buffer
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fabrice Derepas <[email protected]>
[ Upstream commit ceb24c7052cc4649e3b52a51a7cca7dfe4896cec ]
ima_restore_measurement_list() parses the measurement list persisted across kexec. It computes the parse end directly from the blob:
bufendp = buf + khdr->buffer_size;
khdr->buffer_size is a u64 read straight from the persisted buffer. The only length checks in the function are size >= sizeof(*khdr), version == 1 and count -- none relates buffer_size to size, the actual buffer size the caller (ima_load_kexec_buffer()) obtained from the ima-kexec-buffer region. ima_parse_buf() bounds every field read to bufendp, so a blob whose internal buffer_size exceeds the real size makes the parse loop read past the end of the buffer (CWE-125).
The buffer's memory range is validated against addressable RAM by commit cbf9c4b9617b ("of: check previous kernel's ima-kexec-buffer against memory bounds") and commit c5489d04337b ("x86/kexec: add a sanity check on previous kernel's ima kexec buffer"), but the blob's own declared size is never clamped to it. Reject a buffer_size larger than size before the loop.
This is on the boot-time kexec-restore path (__init) and the buffer comes from the previous kernel, so triggering it requires control of the persisted buffer; it is an out-of-bounds read only.
--- security/integrity/ima/ima_template.c | 5 +++++ 1 file changed, 5 insertions(+)
security/integrity/ima/ima_template.c +5 -0
@@ -449,6 +449,11 @@ int ima_restore_measurement_list(loff_t size, void *buf)return -EINVAL ; } +if (khdr->buffer_size > size) { +pr_err ("attempting to restore a corrupted measurement list" ); +return -EINVAL ; + } +bitmap_zero (hdr_mask,HDR__LAST );bitmap_set (hdr_mask,HDR_PCR ,1 );bitmap_set (hdr_mask,HDR_DIGEST ,1 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2982/3318 usbnet: fix smp_processor_id() use in preemptible context
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ömer Mete Kaya <[email protected]>
[ Upstream commit 95a5c641fc7becab441bf244baa73b0b0f8b7dea ]
tx_complete() calls this_cpu_ptr() before disabling preemption, which triggers a BUG when running with CONFIG_DEBUG_PREEMPT:
BUG: using smp_processor_id() in preemptible code in tx_complete
Fix by using get_cpu_ptr()/put_cpu_ptr() which disable preemption and return the per-CPU pointer atomically. The usbnet_skb_return() hunk is a hardening change: that path runs in softirq context so no warning fires there, but the same fix is applied for consistency.
--- drivers/net/usb/usbnet.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/net/usb/usbnet.c +6 -2
@@ -328,7 +328,7 @@ static void __usbnet_status_stop_force(struct usbnet *dev)*/ void usbnet_skb_return (struct usbnet *dev,struct sk_buff *skb) { -struct pcpu_sw_netstats *stats64 =this_cpu_ptr (dev->net->tstats); +struct pcpu_sw_netstats *stats64;unsigned long flags;int status;
@@ -341,10 +341,12 @@ void usbnet_skb_return (struct usbnet *dev, struct sk_buff *skb)if (skb->protocol ==0 ) skb->protocol =eth_type_trans (skb, dev->net); + stats64 =get_cpu_ptr (dev->net->tstats); flags =u64_stats_update_begin_irqsave (&stats64->syncp);u64_stats_inc (&stats64->rx_packets);u64_stats_add (&stats64->rx_bytes, skb->len);u64_stats_update_end_irqrestore (&stats64->syncp, flags); +put_cpu_ptr (dev->net->tstats);netif_dbg (dev, rx_status, dev->net,"< rx, len %zu, type 0x%x\n" , skb->len +sizeof (struct ethhdr ), skb->protocol);
@@ -1277,13 +1279,15 @@ static void tx_complete (struct urb *urb)struct usbnet *dev = entry->dev;if (urb->status ==0 ) { -struct pcpu_sw_netstats *stats64 =this_cpu_ptr (dev->net->tstats); +struct pcpu_sw_netstats *stats64;unsigned long flags; + stats64 =get_cpu_ptr (dev->net->tstats); flags =u64_stats_update_begin_irqsave (&stats64->syncp);u64_stats_add (&stats64->tx_packets, entry->packets);u64_stats_add (&stats64->tx_bytes, entry->length);u64_stats_update_end_irqrestore (&stats64->syncp, flags); +put_cpu_ptr (dev->net->tstats); }else { dev->net->stats.tx_errors++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2983/3318 ALSA: 6fire: take stream_mutex in the Digital Thru control
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Piotr Gliźniewicz <[email protected]>
[ Upstream commit d030561d53cb272bb55ba2dd11aaa609e8240b7e ]
usb6fire_control_digital_thru_put() calls usb6fire_control_streaming_update(), which on an idle card with Digital Thru on selects altsetting 2 and writes the clock register for 96 kHz through usb6fire_control_set_rate(). usb6fire_pcm_prepare() calls both functions through usb6fire_pcm_set_rate() under rt->stream_mutex. The put does not take stream_mutex, so the two can run at the same time.
500 runs of a 0.2 s aplay at 48 kHz while a second loop toggled "Digital Thru Playback Route" with amixer (12693 on/off cycles, kernel 7.2.9): in 216 cases the two usb_set_interface() calls ran at the same time and the kernel logged "sysfs: cannot create duplicate filename '.../3-2:1.1/ep_82'" with a stack dump. 27 of the aplay runs failed, and for each of them the kernel logged "could not start pcm stream".
Take stream_mutex in the put. The pcm runtime is created before the controls and freed with the card, so chip->pcm is valid whenever the put runs. The put waits for a running prepare, which makes synchronous USB transfers under stream_mutex; on a card that responds late the wait can reach about 12 s, or 24 s with Digital Thru on, and during the wait the other controls of the card can be neither read nor written, because snd_ctl_elem_write() holds controls_rwsem around the put. Before this patch the put already made transfers of the same kind under controls_rwsem. No code that holds stream_mutex takes controls_rwsem.
The same test on kernel 7.2.10 with this patch (12863 cycles) gave no failed aplay run and no "duplicate filename" message.
--- sound/usb/6fire/control.c | 7 +++++++ 1 file changed, 7 insertions(+)
sound/usb/6fire/control.c +7 -0
@@ -20,6 +20,7 @@#include "control.h" #include "comm.h" #include "chip.h" +#include "pcm.h" static const char *const opt_coax_texts[2 ] = {"Optical" ,"Coax" };static const char *const line_phono_texts[2 ] = {"Line" ,"Phono" };
@@ -383,6 +384,12 @@ static int usb6fire_control_digital_thru_put(struct snd_kcontrol *kcontrol,struct control_runtime *rt =snd_kcontrol_chip (kcontrol);int changed =0 ; +/* +* with Digital Thru on, streaming_update() selects the altsetting and +* writes the clock register of an idle card; prepare does the same +* under stream_mutex +*/ +guard (mutex)(&rt->chip->pcm->stream_mutex);if (rt->digital_thru_switch != ucontrol->value.integer.value[0 ]) { rt->digital_thru_switch = ucontrol->value.integer.value[0 ];usb6fire_control_streaming_update (rt);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2984/3318 ARC: Strip libgcc debug information when generating BTF
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit ca201ad6e92a1924138e83ff966f7a091e3bbe6e ]
ARC links against the compiler's libgcc archive. The ARC GNU 2023.03 toolchain ships this library with debug information, including complex floating-point types in integer arithmetic helpers such as __udivdi3. These types reach vmlinux even though the kernel does not use complex floating-point arithmetic.
When floating-point BTF encoding is enabled, pahole rejects those types:
Complex, interval and imaginary float types are not supported Error while encoding BTF.
FAILED: load BTF from .tmp_vmlinux1.BTF.1: No such file or directory
KernelCI's upgrade to pahole 1.31 exposed this long-standing problem as failed ARC builds. As of 1.32, pahole still rejects these types, and older versions will stay in use, so the kernel build has to keep them out of vmlinux. Commit f122668ddcce ("ARC: Add eBPF JIT support") documented the same failure along with a workaround of disabling floating-point BTF encoding, but that also discards supported floating-point types from kernel BTF.
For CONFIG_DEBUG_INFO_BTF, generate a debug-stripped copy of the selected libgcc archive in the output tree and link that copy. Preserve the archive structure so that only needed helpers are linked, and use the normal Kbuild objcopy rule to track input and command changes. The trade-off is that vmlinux in BTF-enabled builds no longer carries DWARF for the libgcc helpers. Debug information for kernel code, the installed toolchain and non-BTF builds stay unchanged.
Reproduced and tested with ARC GCC 12.2.1 and pahole 1.31 and 1.32 using an ARCv2 tinyconfig with BPF_SYSCALL and DWARF4/BTF enabled. Before and after vmlinux.o files are identical after stripping debug information.
--- arch/arc/Makefile | 9 ++++++++- arch/arc/lib/Makefile | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
arch/arc/Makefile +8 -1
@@ -90,7 +90,14 @@ core-$(CONFIG_ARC_PLAT_TB10X) += arch/arc/plat-tb10x/ core-$(CONFIG_ARC_PLAT_AXS10X) += arch/arc/plat-axs10x/ core-$(CONFIG_ARC_SOC_HSDK) += arch/arc/plat-hsdk/ -libs-y += arch/arc/lib/ $(LIBGCC) +libs-y += arch/arc/lib/ + +ifdef CONFIG_DEBUG_INFO_BTF +export LIBGCC := $(LIBGCC) +libs-y += arch/arc/lib/libgcc.a +else +libs-y += $(LIBGCC) +endif boot := arch/arc/boot
arch/arc/lib/Makefile +8 -0
@@ -13,3 +13,11 @@ lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs-unaligned.o else lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs.o endif + +# libgcc can contain complex floating-point debug types unsupported by BTF. +# Strip only the debug information from a local copy of the selected archive. +always-$(CONFIG_DEBUG_INFO_BTF) += libgcc.a +OBJCOPYFLAGS_libgcc.a := --strip-debug + +$(obj)/libgcc.a: $(LIBGCC) FORCE + $(call if_changed,objcopy)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2985/3318 ASoC: codecs: da732x: Fix definition of ADC2 EQ Overall Volume control
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 ebef9212cb469706e28002a20f9d48307d1fd867 ]
The ADC2 EQ overall volume is in DA732X_REG_ADC2_EQ5 (0x9F), not in DA732X_REG_ADC1_EQ5 (0x97), which holds the ADC1 one.
--- sound/soc/codecs/da732x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/da732x.c +1 -1
@@ -511,7 +511,7 @@ static const struct snd_kcontrol_new da732x_snd_controls[] = {SOC_SINGLE_TLV ("ACD2 EQ Band 5 Volume" ,DA732X_REG_ADC2_EQ5 ,DA732X_EQ_BAND5_SHIFT ,DA732X_EQ_VOL_VAL_MAX ,DA732X_INVERT , eq_band_pga_tlv), -SOC_SINGLE_TLV ("ADC2 EQ Overall Volume" ,DA732X_REG_ADC1_EQ5 , +SOC_SINGLE_TLV ("ADC2 EQ Overall Volume" ,DA732X_REG_ADC2_EQ5 ,DA732X_EQ_OVERALL_SHIFT ,DA732X_EQ_OVERALL_VOL_VAL_MAX , DA732X_INVERT, eq_overall_tlv),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2986/3318 ASoC: codecs: tlv320adc3xxx: Fix definition of AGC Target Level control
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 0a9efcb663b5a4d468cbb90de29c6dd3794af124 ]
The right channel AGC target level is in RIGHT_CHN_AGC_1, as on the left, not in RIGHT_CHN_AGC_2, which holds the right noise threshold and hysteresis.
--- sound/soc/codecs/tlv320adc3xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tlv320adc3xxx.c +1 -1
@@ -690,7 +690,7 @@ static const struct snd_kcontrol_new adc3xxx_snd_controls[] = {SOC_DOUBLE_R ("AGC Capture Switch" ,ADC3XXX_LEFT_CHN_AGC_1 ,ADC3XXX_RIGHT_CHN_AGC_1 ,7 ,1 ,0 ),SOC_DOUBLE_R_TLV ("AGC Target Level Capture Volume" ,ADC3XXX_LEFT_CHN_AGC_1 , -ADC3XXX_RIGHT_CHN_AGC_2 ,4 ,0x07 ,1 , agc_target_tlv), +ADC3XXX_RIGHT_CHN_AGC_1 ,4 ,0x07 ,1 , agc_target_tlv),SOC_DOUBLE_R_TLV ("AGC Noise Threshold Capture Volume" ,ADC3XXX_LEFT_CHN_AGC_2 ,ADC3XXX_RIGHT_CHN_AGC_2 ,1 ,0x1f ,1 , agc_thresh_tlv), SOC_DOUBLE_R_TLV("AGC Hysteresis Capture Volume", ADC3XXX_LEFT_CHN_AGC_2,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2987/3318 ASoC: codecs: sta32x: Fix definition of Ch2 and Ch3 Volume Bypass controls
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 ea53ab9003d8655cf7e94428de3006e86fbd06a0 ]
Each channel's master volume bypass (CxVBP) is in its own configuration register, C2CFG and C3CFG, not in C1CFG, which holds the channel 1 bit.
--- sound/soc/codecs/sta32x.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/sta32x.c +2 -2
@@ -465,8 +465,8 @@ SOC_SINGLE("Ch2 Tone Control Bypass Switch", STA32X_C2CFG, STA32X_CxCFG_TCB_SHIFSOC_SINGLE ("Ch1 EQ Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_EQBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch2 EQ Bypass Switch" ,STA32X_C2CFG , STA32X_CxCFG_EQBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch1 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), -SOC_SINGLE ("Ch2 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), -SOC_SINGLE ("Ch3 Master Volume Bypass Switch" ,STA32X_C1CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), +SOC_SINGLE ("Ch2 Master Volume Bypass Switch" ,STA32X_C2CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ), +SOC_SINGLE ("Ch3 Master Volume Bypass Switch" ,STA32X_C3CFG , STA32X_CxCFG_VBP_SHIFT,1 ,0 ),SOC_ENUM ("Ch1 Limiter Select" , sta32x_limiter_ch1_enum),SOC_ENUM ("Ch2 Limiter Select" , sta32x_limiter_ch2_enum), SOC_ENUM("Ch3 Limiter Select", sta32x_limiter_ch3_enum),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2988/3318 ASoC: codecs: sta350: Fix definition of Ch2 and Ch3 Volume Bypass controls
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 7308ce7c8459e994a36a22607e974e3e132a9275 ]
Each channel's master volume bypass (CxVBP) is in its own configuration register, C2CFG and C3CFG, not in C1CFG, which holds the channel 1 bit.
--- sound/soc/codecs/sta350.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/sta350.c +2 -2
@@ -482,9 +482,9 @@ SOC_SINGLE("Ch2 EQ Bypass Switch",SOC_SINGLE ("Ch1 Master Volume Bypass Switch" ,STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch2 Master Volume Bypass Switch" , -STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ), +STA350_C2CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_SINGLE ("Ch3 Master Volume Bypass Switch" , -STA350_C1CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ), +STA350_C3CFG , STA350_CxCFG_VBP_SHIFT,1 ,0 ),SOC_ENUM ("Ch1 Binary Output Select" , sta350_binary_output_ch1_enum),SOC_ENUM ("Ch2 Binary Output Select" , sta350_binary_output_ch2_enum), SOC_ENUM("Ch3 Binary Output Select", sta350_binary_output_ch3_enum),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2989/3318 calipso: update payload_len when removing the CALIPSO option
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit 00accbd9d5021b942a16078bd5717d7865f6971c ]
calipso_skbuff_delattr() removes the CALIPSO option from the hop-by-hop extension header, or the whole extension header if CALIPSO is its only option, and pulls the skb by the removed length. It never updates ipv6hdr->payload_len, so after a successful removal the header still claims the original length.
calipso_skbuff_setattr() already adjusts payload_len by the length it adds; the delete path was missed.
This is reached on the forward path when a packet carrying CALIPSO is sent to a destination mapped to an unlabeled NetLabel domain. The forwarded packet then has a payload_len larger than its real payload by the removed length (8 to 264 bytes), and the receiver drops it as truncated. So removing the label on the forward path has been broken for every packet that is not resegmented later (SYN, UDP, ICMPv6...).
Adjust payload_len after the header is moved. BIG TCP packets carry payload_len == 0 (see ipv6_set_payload_len()), and ipv6_payload_len() then falls back to skb->len, so leave them alone.
Tested with client, router and server network namespaces on one kernel (arm64, QEMU): SELinux permissive with a minimal mdp-generated policy (network_peer_controls=1), "netlabelctl calipso add pass doi:16", the default NetLabel mapping left unlabeled, IPv6 forwarding on the router. The client sends 5 UDP datagrams with a CALIPSO hop-by-hop option (DOI 16, set through IPV6_HOPOPTS) to the server through the router:
before: router Ip6OutForwDatagrams 5, server receives 0,
server Ip6InTruncatedPkts 5
after: router Ip6OutForwDatagrams 5, server receives 5,
server Ip6InTruncatedPkts 0
--- net/ipv6/calipso.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv6/calipso.c +4 -0
@@ -1432,6 +1432,10 @@ static int calipso_skbuff_delattr(struct sk_buff *skb)skb_pull (skb, delta);memmove ((char *)ip6_hdr + delta, ip6_hdr, size);skb_reset_network_header (skb); + ip6_hdr =ipv6_hdr (skb); +/* BIG TCP packets have payload_len == 0 */ +if (ip6_hdr->payload_len) +be16_add_cpu (&ip6_hdr->payload_len, -delta); }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2990/3318 gre: keep the UDP tunnel GSO type when completing GRO
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Brad Fitzpatrick <[email protected]>
[ Upstream commit 718f364a20ecee4f25986789c25550cf4da73b4c ]
gre_gro_complete() assigns SKB_GSO_GRE to gso_type rather than OR-ing it in. When GRE is carried over UDP by FOU or GUE, udp_gro_complete() has already set SKB_GSO_UDP_TUNNEL{,_CSUM} before calling into the FOU or GUE gro_complete handler and then gre_gro_complete(), so that bit is lost.
That has broken forwarding of such packets since FOU gained GRO: if a host with a FOU or GUE socket on the tunnel's port merges transit packets and then forwards them out a device that can't segment them itself, udp4_ufo_fragment() finds neither tunnel bit and fails, and the packets are dropped. Since commit 3d010c8031e3 ("udp: do not accept non-tunnel GSO skbs landing in a tunnel"), local receive is broken too:udp_unexpected_gso() considers the merged skb, which reaches the encapsulation socket without either UDP tunnel bit, unexpected and hands it to udp_rcv_segment(). Segmenting fails, so the packet is freed and counted in UdpInErrors. Either way, only packets GRO didn't merge get through, so TCP over FOU or GUE GRE tunnels slows to about one segment per round trip whenever the receiving device has GRO enabled.
OR in SKB_GSO_GRE instead, as ipip_gro_complete() and sit_gro_complete() do for SKB_GSO_IPXIP4. For plain GRE, gso_type is still zero at this point unless the driver set it, so nothing changes there in the usual case.
The assignment dates to commit bf5a755f5e91 ("net-gre-gro: Add GRE support to the GRO stack"), but nothing set gso_type before it until FOU GRO came along, so the Fixes tag points there.
Tested under virtme-ng with bulk TCP over a GRE tunnel between two network namespaces joined by a veth, with GRO on the receiving veth and segmentation off on the sending one, so GRO sees wire-sized packets. 32 MiB took:
before after FOU over IPv4 26.0s, 9658 UDP errors 0.28s, 0 errors GUE over IPv4 26.1s, 9686 UDP errors 0.39s, 0 errors FOU over IPv6 26.4s, 9860 UDP errors 0.16s, 0 errors plain GRE 0.17s 0.15s
Forwarding the same FOU traffic through a third namespace with its own FOU socket on the port, GRO on its ingress and segmentation off on its egress, took 26.0s with 4826 egress drops before and 0.31s with none after. On v6.8, before 3d010c8031e3, local receive was fine but forwarding failed the same way (25.7s, 4764 drops).
With GRO off on the receiver, all took under 0.2s both before and after. The gre_gso.sh and fou_mcast_encap.sh selftests give the same results before and after.
--- net/ipv4/gre_offload.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/gre_offload.c +1 -1
@@ -242,7 +242,7 @@ static int gre_gro_complete(struct sk_buff *skb, int nhoff)__be16 type; skb->encapsulation =1 ; -skb_shinfo (skb)->gso_type =SKB_GSO_GRE ; +skb_shinfo (skb)->gso_type |=SKB_GSO_GRE ; type = greh->protocol;if (greh->flags &GRE_KEY )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2991/3318 bpf: Fix verifier WARN on narrow read of bpf_tcp_sock u64 fields
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit af873495cbcb066ab029f7f63b94410d4db47628 ]
A BPF program can read the middle of a u64 field in struct bpf_tcp_sock:
tp = bpf_tcp_sock(listener); /* +0x54 is in the middle of the u64 bytes_received */ unsigned hi = *(unsigned *)((char *)tp + 0x54);
bpf_tcp_sock_is_valid_access() allows this 4-byte read (the default case only checks size == 4), but bpf_tcp_sock_convert_ctx_access() only knows the field starts and has no idea how to handle such an offset. It emits no instruction, cnt stays 0 and the fixup pass trips verifier_bug():
verifier bug: error during ctx access conversion (0)
Just disallow the narrower access by matching the whole u64 range of the two fields, so it is turned down at check time:
invalid tcp_sock access off=84 size=4
--- net/core/filter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/filter.c +2 -2
@@ -7172,8 +7172,8 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, enum bpf_access_type type,return false;switch (off) { -case offsetof(struct bpf_tcp_sock , bytes_received): -case offsetof(struct bpf_tcp_sock , bytes_acked): + case bpf_ctx_range(struct bpf_tcp_sock, bytes_received): + case bpf_ctx_range(struct bpf_tcp_sock, bytes_acked):return size ==sizeof (__u64);default :return size ==sizeof (__u32);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2992/3318 power: supply: qcom_battmgr: report the USB type from USB_ADAP_TYPE
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit a49f86cd1333c6e12fd37bc0b3234ace10072553 ]
On SM8350 and SM8550 class firmware the USB power supply reads its usb_type from the USB_TYPE property. On a Kaanapali (SM8850) tablet that property is 1 (SDP) whatever is plugged in, while USB_ADAP_TYPE reports the adapter, using the same numbering as POWER_SUPPLY_USB_TYPE_*:
PC port USB_TYPE 1 USB_ADAP_TYPE 1 (SDP) USB-C dock, 5 V PD USB_TYPE 1 USB_ADAP_TYPE 6 (PD) 65 W PPS charger USB_TYPE 1 USB_ADAP_TYPE 8 (PD_PPS)
Qualcomm's downstream qti_battery_charger driver also maps USB_ADAP_TYPE to POWER_SUPPLY_PROP_USB_TYPE.
Request USB_ADAP_TYPE for POWER_SUPPLY_PROP_USB_TYPE instead.
Tested on a Lenovo Legion Tab Y700 gen 5 (qcom,kaanapali-pmic-glink, which uses the SM8550 path). Only tested on this device; the SM8350 variant shares the property map and was not tested.
--- drivers/power/supply/qcom_battmgr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/power/supply/qcom_battmgr.c +2 -2
@@ -721,7 +721,7 @@ static const u8 sm8350_usb_prop_map[] = { [POWER_SUPPLY_PROP_CURRENT_NOW] = USB_CURR_NOW, [POWER_SUPPLY_PROP_CURRENT_MAX] = USB_CURR_MAX, [POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT] = USB_INPUT_CURR_LIMIT, - [POWER_SUPPLY_PROP_USB_TYPE] = USB_TYPE, + [POWER_SUPPLY_PROP_USB_TYPE] = USB_ADAP_TYPE, }; static int qcom_battmgr_usb_sm8350_update(struct qcom_battmgr *battmgr,
@@ -1237,7 +1237,7 @@ static void qcom_battmgr_sm8350_callback(struct qcom_battmgr *battmgr,case USB_INPUT_CURR_LIMIT : battmgr->usb.current_limit =le32_to_cpu (resp->intval.value);break ; -case USB_TYPE : +case USB_ADAP_TYPE : battmgr->usb.usb_type =le32_to_cpu (resp->intval.value);break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2993/3318 net: Helper to move packet data and metadata after skb_push/pull
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Sitnicki <[email protected]>
[ Upstream commit 8989d328dfe7c7a3b9f4b9f0ef60006d277f81cc ]
Lay groundwork for fixing BPF helpers available to TC(X) programs.
When skb_push() or skb_pull() is called in a TC(X) ingress BPF program, the skb metadata must be kept in front of the MAC header. Otherwise, BPF programs using the __sk_buff->data_meta pseudo-pointer lose access to it.
Introduce a helper that moves both metadata and a specified number of packet data bytes together, suitable as a drop-in replacement for memmove().
Stable-dep-of: 12d07c38e1b0 ("bpf: Don't let bpf_skb_adjust_room() use up the MSS")
--- include/linux/skbuff.h | 75 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
include/linux/skbuff.h +75 -0
@@ -4409,6 +4409,81 @@ static inline void skb_metadata_clear(struct sk_buff *skb)skb_metadata_set (skb,0 ); } +/** +* skb_data_move - Move packet data and metadata after skb_push() or skb_pull(). +* @skb: packet to operate on +* @len: number of bytes pushed or pulled from &sk_buff->data +* @n: number of bytes to memmove() from pre-push/pull &sk_buff->data +* +* Moves @n bytes of packet data, can be zero, and all bytes of skb metadata. +* +* Assumes metadata is located immediately before &sk_buff->data prior to the +* push/pull, and that sufficient headroom exists to hold it after an +* skb_push(). Otherwise, metadata is cleared and a one-time warning is issued. +* +* Prefer skb_postpull_data_move() or skb_postpush_data_move() to calling this +* helper directly. +*/ +static inline void skb_data_move (struct sk_buff *skb,const int len, +const unsigned int n) +{ +const u8 meta_len =skb_metadata_len (skb); +u8 *meta, *meta_end; + +if (!len || (!n && !meta_len)) +return ; + +if (!meta_len) + goto no_metadata; + + meta_end =skb_metadata_end (skb); + meta = meta_end - meta_len; + +if (WARN_ON_ONCE (meta_end + len != skb->data || + meta_len >skb_headroom (skb))) { +skb_metadata_clear (skb); + goto no_metadata; + } + +memmove (meta + len, meta, meta_len + n); +return ; + +no_metadata: +memmove (skb->data, skb->data - len, n); +} + +/** +* skb_postpull_data_move - Move packet data and metadata after skb_pull(). +* @skb: packet to operate on +* @len: number of bytes pulled from &sk_buff->data +* @n: number of bytes to memmove() from pre-pull &sk_buff->data +* +* See skb_data_move() for details. +*/ +static inline void skb_postpull_data_move (struct sk_buff *skb, +const unsigned int len, +const unsigned int n) +{ +DEBUG_NET_WARN_ON_ONCE (len >INT_MAX ); +skb_data_move (skb, len, n); +} + +/** +* skb_postpush_data_move - Move packet data and metadata after skb_push(). +* @skb: packet to operate on +* @len: number of bytes pushed onto &sk_buff->data +* @n: number of bytes to memmove() from pre-push &sk_buff->data +* +* See skb_data_move() for details. +*/ +static inline void skb_postpush_data_move (struct sk_buff *skb, +const unsigned int len, +const unsigned int n) +{ +DEBUG_NET_WARN_ON_ONCE (len >INT_MAX ); +skb_data_move (skb, -len, n); +} +struct sk_buff *skb_clone_sk (struct sk_buff *skb);#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2994/3318 bpf: Make bpf_skb_adjust_room metadata-safe
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Sitnicki <[email protected]>
[ Upstream commit be83105d38ab99737ac0488600efd59ddd57b74c ]
bpf_skb_adjust_room() may push or pull bytes from skb->data. In both cases, skb metadata must be moved accordingly to stay accessible.
Replace existing memmove() calls, which only move payload, with a helper that also handles metadata. Reserve enough space for metadata to fit after skb_push.
Stable-dep-of: 12d07c38e1b0 ("bpf: Don't let bpf_skb_adjust_room() use up the MSS")
--- net/core/filter.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
net/core/filter.c +5 -4
@@ -3294,11 +3294,11 @@ static void bpf_skb_change_protocol(struct sk_buff *skb, u16 proto)static int bpf_skb_generic_push (struct sk_buff *skb,u32 off,u32 len) { -/* Caller already did skb_cow() with len as headroom, +/* Caller already did skb_cow() with meta_len+len as headroom, * so no need to do it here. */ skb_push (skb, len); -memmove (skb->data, skb->data + len, off); +skb_postpush_data_move (skb, len, off);memset (skb->data + off,0 , len);/* No skb_postpush_rcsum(skb, skb->data + off, len)
@@ -3322,7 +3322,7 @@ static int bpf_skb_generic_pop(struct sk_buff *skb, u32 off, u32 len) old_data = skb->data;__skb_pull (skb, len);skb_postpull_rcsum (skb, old_data + off, len); -memmove (skb->data, old_data, off); +skb_postpull_data_move (skb, len, off);return 0 ; }
@@ -3532,6 +3532,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,u8 inner_mac_len = flags >>BPF_ADJ_ROOM_ENCAP_L2_SHIFT ;bool encap = flags &BPF_F_ADJ_ROOM_ENCAP_L3_MASK ;u16 mac_len =0 , inner_net =0 , inner_trans =0 ; +const u8 meta_len =skb_metadata_len (skb);unsigned int gso_type =SKB_GSO_DODGY ;int ret;
@@ -3542,7 +3543,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,return -ENOTSUPP ; } - ret =skb_cow_head (skb, len_diff); + ret =skb_cow_head (skb, meta_len + len_diff);if (unlikely (ret <0 ))return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2995/3318 bpf: Dont let bpf_skb_adjust_room() use up the MSS
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 12d07c38e1b0f79e48a37abd7103194212f2da8c ]
When bpf_skb_adjust_room() grows a TCP GSO packet without BPF_F_ADJ_ROOM_FIXED_GSO, gso_size is lowered by the number of bytes added. Nothing looks at how large it is.
gso_size is the size of the segments the peer has sent if the packet comes out of GRO, and what the sender has written into the virtio header if it comes from a tun device or a packet socket. If it equals len_diff the result is 0, and a packet of up to 64 KB is no GSO packet any more. If it is smaller, the 16 bit value wraps around.
One less than len_diff gives GSO_BY_FRAGS. skb_segment() then takes the length of each segment from the frag_list. A packet with more than 64 KB of payload gets that far, and one from a tun device has no frag_list:
BUG: KASAN: null-ptr-deref in skb_segment+0xcf1/0x1a90 BUG: kernel NULL pointer dereference, address: 0000000000000070 tcp_gso_segment+0x1be/0x9f0 inet_gso_segment+0x288/0x740 inet_gso_segment+0x288/0x740 skb_mac_gso_segment+0x179/0x2e0
What is left must not be less than TCP_MIN_GSO_SIZE either. The stack relies on that for the number of segments to fit into gso_segs, see commit c27c449d455a ("virtio-net: Ensure that TCP packets don't overflow gso_segs").
Refuse to grow a packet that would end up with less, with the error that other packets which cannot be adjusted get.
--- net/core/filter.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/core/filter.c +8 -0
@@ -3543,6 +3543,14 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,return -ENOTSUPP ; } +/* +* The MSS is lowered by len_diff. Leave the least that the stack lets a +* TCP GSO packet have, or gso_segs can overflow. +*/ +if (skb_is_gso (skb) && !(flags &BPF_F_ADJ_ROOM_FIXED_GSO ) && +skb_shinfo (skb)->gso_size < len_diff +TCP_MIN_GSO_SIZE ) +return -ENOTSUPP ; + ret =skb_cow_head (skb, meta_len + len_diff);if (unlikely (ret <0 ))return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2996/3318 bpf: Add show_fdinfo for perf_event
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tao Chen <[email protected]>
[ Upstream commit 97ebac58865dec1bca31140252386daefef1654f ]
After commit 1b715e1b0ec5 ("bpf: Support ->fill_link_info for perf_event") add perf_event info, we can also show the info with the method of cat /proc/[fd]/fdinfo.
kprobe fdinfo:link_type: perflink_id: 10prog_tag: bcf7977d3b93787cprog_id: 20
name: bpf_fentry_test1
offset: 0x0
missed: 0
addr: 0xffffffffa28a2904event_type: kprobe
cookie: 3735928559
uprobe fdinfo:link_type: perflink_id: 13prog_tag: bcf7977d3b93787cprog_id: 21
name: /proc/self/exe
offset: 0x63dce4ref_ctr_offset: 0x33eee2aevent_type: uprobe
cookie: 3735928559
tracepoint fdinfo:link_type: perflink_id: 11prog_tag: bcf7977d3b93787cprog_id: 22tp_name: sched_switchevent_type: tracepoint
cookie: 3735928559
perf_event fdinfo:link_type: perflink_id: 12prog_tag: bcf7977d3b93787cprog_id: 23
type: 1
config: 2event_type: event
cookie: 3735928559
Stable-dep-of: 3ccd700543f1 ("bpf: Read the probe of a perf event under event_mutex")
--- kernel/bpf/syscall.c | 120 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+)
kernel/bpf/syscall.c +120 -0
@@ -3546,6 +3546,32 @@ static int bpf_perf_link_fill_kprobe(const struct perf_event *event, info->perf_event.kprobe.cookie = event->bpf_cookie; return 0; } + +static void bpf_perf_link_fdinfo_kprobe (const struct perf_event *event, +struct seq_file *seq) +{ +const char *name; +int err; +u32 prog_id, type; +u64 offset, addr; +unsigned long missed; + + err =bpf_get_perf_event_info (event, &prog_id, &type, &name, + &offset, &addr, &missed); +if (err) +return ; + +seq_printf (seq, +"name:\t%s\n" +"offset:\t%#llx\n" +"missed:\t%lu\n" +"addr:\t%#llx\n" +"event_type:\t%s\n" +"cookie:\t%llu\n" , + name, offset, missed, addr, + type ==BPF_FD_TYPE_KRETPROBE ?"kretprobe" :"kprobe" , + event->bpf_cookie); +}#endif #ifdef CONFIG_UPROBE_EVENTS
@@ -3573,6 +3599,31 @@ static int bpf_perf_link_fill_uprobe(const struct perf_event *event, info->perf_event.uprobe.cookie = event->bpf_cookie;return 0 ; } + +static void bpf_perf_link_fdinfo_uprobe (const struct perf_event *event, +struct seq_file *seq) +{ +const char *name; +int err; +u32 prog_id, type; +u64 offset, ref_ctr_offset; +unsigned long missed; + + err =bpf_get_perf_event_info (event, &prog_id, &type, &name, + &offset, &ref_ctr_offset, &missed); +if (err) +return ; + +seq_printf (seq, +"name:\t%s\n" +"offset:\t%#llx\n" +"ref_ctr_offset:\t%#llx\n" +"event_type:\t%s\n" +"cookie:\t%llu\n" , + name, offset, ref_ctr_offset, + type ==BPF_FD_TYPE_URETPROBE ?"uretprobe" :"uprobe" , + event->bpf_cookie); +}#endif static int bpf_perf_link_fill_probe(const struct perf_event *event,
@@ -3641,10 +3692,79 @@ static int bpf_perf_link_fill_link_info(const struct bpf_link *link, } } +static void bpf_perf_event_link_show_fdinfo (const struct perf_event *event, +struct seq_file *seq) +{ +seq_printf (seq, +"type:\t%u\n" +"config:\t%llu\n" +"event_type:\t%s\n" +"cookie:\t%llu\n" , + event->attr.type, event->attr.config, +"event" , event->bpf_cookie); +} + +static void bpf_tracepoint_link_show_fdinfo (const struct perf_event *event, +struct seq_file *seq) +{ +int err; +const char *name; +u32 prog_id; + + err =bpf_get_perf_event_info (event, &prog_id,NULL , &name,NULL , +NULL ,NULL ); +if (err) +return ; + +seq_printf (seq, +"tp_name:\t%s\n" +"event_type:\t%s\n" +"cookie:\t%llu\n" , + name,"tracepoint" , event->bpf_cookie); +} + +static void bpf_probe_link_show_fdinfo (const struct perf_event *event, +struct seq_file *seq) +{ +#ifdef CONFIG_KPROBE_EVENTS +if (event->tp_event->flags &TRACE_EVENT_FL_KPROBE ) +return bpf_perf_link_fdinfo_kprobe (event, seq); +#endif + +#ifdef CONFIG_UPROBE_EVENTS +if (event->tp_event->flags &TRACE_EVENT_FL_UPROBE ) +return bpf_perf_link_fdinfo_uprobe (event, seq); +#endif +} + +static void bpf_perf_link_show_fdinfo (const struct bpf_link *link, +struct seq_file *seq) +{ +struct bpf_perf_link *perf_link; +const struct perf_event *event; + + perf_link = container_of(link, struct bpf_perf_link, link); + event =perf_get_event (perf_link->perf_file); +if (IS_ERR (event)) +return ; + +switch (event->prog->type) { +case BPF_PROG_TYPE_PERF_EVENT : +return bpf_perf_event_link_show_fdinfo (event, seq); +case BPF_PROG_TYPE_TRACEPOINT : +return bpf_tracepoint_link_show_fdinfo (event, seq); +case BPF_PROG_TYPE_KPROBE : +return bpf_probe_link_show_fdinfo (event, seq); +default : +return ; + } +} +static const struct bpf_link_ops bpf_perf_link_lops = { .release = bpf_perf_link_release, .dealloc = bpf_perf_link_dealloc, .fill_link_info = bpf_perf_link_fill_link_info, + .show_fdinfo = bpf_perf_link_show_fdinfo, };static int bpf_perf_link_attach (const union bpf_attr *attr,struct bpf_prog *prog)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2997/3318 bpf: Read the probe of a perf event under event_mutex
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 3ccd700543f16a2b2ab656f35dcaeb6bd7c45e22 ]
For a perf event on a kprobe or uprobe event which was made in tracefs, bpf_get_kprobe_info() and bpf_get_uprobe_info() look the probe up by name in the list of dynamic events, and hand a pointer to its symbol or file name back to the caller. None of the callers holds event_mutex.
The perf event keeps its trace event alive, nothing else. Other dynamic events are removed from the list and freed during the walk. And a probe which shares its event with other probes can be deleted while the event is in use, so even the probe which is found can be freed, together with the string, before the caller has measured and copied it. The result is a use-after-free in the walk, in strlen() and in the copy to user space, or a NULL pointer dereference.
The readers are BPF_OBJ_GET_INFO_BY_FD and fdinfo of a perf link, for whoever holds a descriptor of the link, and BPF_TASK_FD_QUERY. The other side is anybody who may write to dynamic_events, kprobe_events or uprobe_events.
Take event_mutex in bpf_get_perf_event_info() and give the caller a copy of the name, which it has to free.
--- kernel/bpf/syscall.c | 17 +++++++++++------ kernel/trace/bpf_trace.c | 13 +++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-)
kernel/bpf/syscall.c +11 -6
@@ -3502,19 +3502,19 @@ static int bpf_perf_link_fill_common(const struct perf_event *event, *ulenp =1 ; }if (!uname) -return 0 ; + goto out;if (buf) { err =bpf_copy_to_user (uname, buf, ulen, len); -if (err) -return err; }else {char zero ='\0' ;if (put_user (zero, uname)) -return -EFAULT ; + err = -EFAULT ; } -return 0 ; +out: +kfree_const (buf); +return err; }#ifdef CONFIG_KPROBE_EVENTS
@@ -3571,6 +3571,7 @@ static void bpf_perf_link_fdinfo_kprobe(const struct perf_event *event, name, offset, missed, addr, type ==BPF_FD_TYPE_KRETPROBE ?"kretprobe" :"kprobe" , event->bpf_cookie); + kfree_const(name); }#endif
@@ -3623,6 +3624,7 @@ static void bpf_perf_link_fdinfo_uprobe(const struct perf_event *event, name, offset, ref_ctr_offset, type ==BPF_FD_TYPE_URETPROBE ?"uretprobe" :"uprobe" , event->bpf_cookie); + kfree_const(name); }#endif
@@ -3721,6 +3723,7 @@ static void bpf_tracepoint_link_show_fdinfo(const struct perf_event *event,"event_type:\t%s\n" "cookie:\t%llu\n" , name, "tracepoint", event->bpf_cookie); +kfree_const (name); } static void bpf_probe_link_show_fdinfo(const struct perf_event *event,
@@ -5083,11 +5086,13 @@ static int bpf_task_fd_query(const union bpf_attr *attr, err =bpf_get_perf_event_info (event, &prog_id, &fd_type, &buf, &probe_offset, &probe_addr,NULL ); -if (!err) +if (!err) { err =bpf_task_fd_query_copy (attr, uattr, prog_id, fd_type, buf, probe_offset, probe_addr); +kfree_const (buf); + } goto put_file; }
kernel/trace/bpf_trace.c +13 -0
@@ -2398,6 +2398,7 @@ int bpf_probe_unregister(struct bpf_raw_event_map *btp, struct bpf_prog *prog)return tracepoint_probe_unregister (btp->tp, (void *)btp->bpf_func, prog); } +/* On success the caller releases *buf with kfree_const() */ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id, u32 *fd_type, const char **buf, u64 *probe_offset, u64 *probe_addr,
@@ -2407,6 +2408,12 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,struct bpf_prog *prog;int flags, err =0 ; +/* +* The list of dynamic events is walked, and a probe which has siblings +* can be deleted, with its strings, while its event is in use. +*/ +guard (mutex)(&event_mutex); + prog = event->prog;if (!prog)return -ENOENT ;
@@ -2447,6 +2454,12 @@ int bpf_get_perf_event_info(const struct perf_event *event, u32 *prog_id,#endif } +if (!err && *buf) { + *buf =kstrdup_const (*buf,GFP_KERNEL ); +if (!*buf) + err = -ENOMEM ; + } +return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2998/3318 bpf: Validate the SRH which End.DT6 uncovers in End.BPF
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit e8b084646b946cc6f7976365588035947a296184 ]
input_action_end_bpf() validates the SRH of a packet and pulls it into the head before the program runs. If the program decapsulates the packet with bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6), bpf_update_srh_state() looks for a routing header in the inner packet and takes it for the new SRH as it is.
Nobody has looked at that header, and whoever has sent the packet has written it. ipv6_find_hdr() finds it in a fragment of the skb as well, but hdrlen is then read at that offset from skb->data, past the end of the head. The header need not be an SRH, and its hdrlen need not fit into the packet, but it is marked as valid, and bpf_lwt_seg6_adjust_srh() and bpf_lwt_seg6_store_bytes() check their offsets against it.
A program which then adds a TLV at the end of the SRH, where hdrlen has it, makes bpf_lwt_seg6_adjust_srh() move and write memory behind the head of the skb, as far as the sender likes within the 2 KB that hdrlen can say:
BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x185/0x240 Read of size 2088 at addr ffff888107d6f09e by task srh/102 BUG: KASAN: slab-out-of-bounds in bpf_skb_net_hdr_push+0x1b5/0x240 Write of size 8 at addr ffff888107d6f8be by task srh/102
Use seg6_get_srh(), which pulls and validates the header. Without a valid SRH the state says that there is none, and the packet goes its way as before. The pull can move the head, so compute the data pointers behind it.
--- net/core/filter.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
net/core/filter.c +5 -5
@@ -6583,15 +6583,15 @@ static void bpf_update_srh_state(struct sk_buff *skb) {struct seg6_bpf_srh_state *srh_state =this_cpu_ptr (&seg6_bpf_srh_states); -int srhoff =0 ; -if (ipv6_find_hdr (skb, &srhoff,IPPROTO_ROUTING ,NULL ,NULL ) <0 ) { - srh_state->srh =NULL ; - }else { - srh_state->srh = (struct ipv6_sr_hdr *)(skb->data + srhoff); +/* Behind a decapsulation this is a header that nobody has looked at */ + srh_state->srh =seg6_get_srh (skb,0 ); +if (srh_state->srh) { srh_state->hdrlen = srh_state->srh->hdrlen <<3 ; srh_state->valid = true; } +/* it may have been pulled into the head */ +bpf_compute_data_pointers (skb); } BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 2999/3318 bpf: Pull the inner header for End.DT6 in End.BPF
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 434324c611a98bc76dc850d45d67756dae5622cf ]
bpf_lwt_seg6_action(SEG6_LOCAL_ACTION_END_DT6) pulls the outer headers off the packet and hands it to seg6_lookup_nexthop(), which reads the inner IPv6 header at skb->data. Nothing says that this header is in the head of the skb, or that there is one. If the head ends with the outer headers, the route is looked up for whatever lies behind the head, and the packet is dropped or leaves by the wrong route. If the program then pushes an SRH with SEG6_LOCAL_ACTION_END_B6, seg6_do_srh_inline() pulls an IPv6 header off a head which has none, and __skb_pull() hits its BUG(): the kernel panics on a packet from the network.
GRO pulls the inner header of a plain IPv6 in IPv6 packet into the head. It takes a packet which GRO does not look into that far, one with a fragment header in front of the inner header for example, or a device without GRO, and a driver which leaves the inner header in a fragment.
Make sure of the inner header together with the outer ones. The program goes on behind an error of the helper, so do it before the packet is changed. A pull which fails can still have moved the head, so look for the SRH again.
--- net/core/filter.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/core/filter.c +6 -1
@@ -6623,9 +6623,14 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,if (ipv6_find_hdr (skb, &hdroff,IPPROTO_IPV6 ,NULL ,NULL ) <0 )return -EBADMSG ; -if (!pskb_pull (skb, hdroff)) +/* As long as nothing has been changed, the program goes on */ +if (!pskb_may_pull (skb, hdroff +sizeof (struct ipv6hdr ))) { +/* but the head may have moved */ +bpf_update_srh_state (skb);return -EBADMSG ; + } +__skb_pull (skb, hdroff);skb_postpull_rcsum (skb,skb_network_header (skb), hdroff);skb_reset_network_header (skb);skb_reset_transport_header (skb);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3000/3318 bpf: Update the SRH state if End.B6 fails late
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 427e751a231aa781441d51c42e716905ee348099 ]
For SEG6_LOCAL_ACTION_END_B6 and END_B6_ENCAP bpf_lwt_seg6_action() looks for the SRH again only if bpf_push_seg6_encap() has succeeded. That function pushes the new header, for which the head of the skb is reallocated if it has not got the room, and then looks up the route to the first segment. If there is none, it returns an error, and the pointer to the SRH in seg6_bpf_srh_states still points into the old head, which has been freed.
The program goes on behind the error. bpf_lwt_seg6_store_bytes() and bpf_lwt_seg6_adjust_srh() read the SRH through that pointer.
Look for the SRH whatever bpf_push_seg6_encap() says.
--- net/core/filter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/filter.c +4 -4
@@ -6644,8 +6644,8 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,return -EBADMSG ; err =bpf_push_seg6_encap (skb,BPF_LWT_ENCAP_SEG6_INLINE , param, param_len); -if (!err) -bpf_update_srh_state (skb); +/* The header can be in place although err says otherwise */ +bpf_update_srh_state (skb);return err;case SEG6_LOCAL_ACTION_END_B6_ENCAP :
@@ -6653,8 +6653,8 @@ BPF_CALL_4(bpf_lwt_seg6_action, struct sk_buff *, skb,return -EBADMSG ; err =bpf_push_seg6_encap (skb,BPF_LWT_ENCAP_SEG6 , param, param_len); -if (!err) -bpf_update_srh_state (skb); +/* The header can be in place although err says otherwise */ +bpf_update_srh_state (skb);return err;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3001/3318 bpf: Clear sk_refcnt of a clone before its storage is linked
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 22f100bd013458836c3d0eaf8050b854d7534a66 ]
sk_clone() sets sk_refcnt of the new socket some lines behind bpf_sk_storage_clone(). But the elements which that function copies are linked to their maps at once, and an element leads to its owner: the iterator over a sk_storage map hands the owner to its program. bpf_sk_storage_get() with BPF_SK_STORAGE_GET_F_CREATE and bpf_sk_storage_delete() rely on refcount_inc_not_zero() to tell whether they may touch the socket.
sk_refcnt is in the part of struct sock which sock_copy() leaves out, and sk_prot_alloc() does not clear a clone unless init_on_alloc is on. It is zero in an object which has been a socket before, and anything in one which has not. If it is not zero, a helper gets a reference which refcount_set() wipes out, and the helper's sock_put() then drops one of the two references of the new socket, which is freed too early:
IPv4: Attempt to release TCP socket in state 1
BUG: KASAN: slab-use-after-free in __raw_spin_lock_init+0x47/0x90
In the meantime the helper changes a storage which bpf_sk_storage_clone() fills without taking its lock.
Nothing else can find the clone at this point. Say that it is not alive yet, before the first element is linked. Sockets whose parent has no storage are left alone.
--- net/core/bpf_sk_storage.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/core/bpf_sk_storage.c +7 -0
@@ -163,6 +163,13 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)if (!sk_storage ||hlist_empty (&sk_storage->list)) goto out; +/* +* The maps lead to newsk as soon as an element is linked, but +* sk_clone() sets sk_refcnt only later. Until then it holds whatever +* the slab object held before: no reference can be had yet. +*/ +refcount_set (&newsk->sk_refcnt,0 ); +hlist_for_each_entry_rcu (selem, &sk_storage->list, snode) {struct bpf_local_storage_elem *copy_selem;struct bpf_local_storage_map *smap;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3002/3318 bpf: Bound the nesting that the BTF show code follows
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 13ac7c05bc45d3445b580da186548dd3487fae4e ]
btf_struct_show() and btf_array_show() recurse for every nested struct and array. MAX_RESOLVE_DEPTH bounds one resolve walk when BTF is loaded, not the nesting: a member whose type is resolved already is not walked again, so BTF that defines its types from the inside out can nest them as deep as it has types.
Whoever may load BTF, with CAP_BPF or a BPF token, can give such a type to the value of a map. Reading the file of that map in bpffs then overruns the kernel stack: with a few hundred levels the stack guard page is hit and the kernel panics.
Stop at 32 levels. That is MAX_RESOLVE_DEPTH, and __btf_show_indent() has as many columns. Nothing is shown for a member that lies deeper, and the status becomes -E2BIG, which bpf_snprintf_btf() and bpf_seq_printf_btf() return. The types of an x86_64 defconfig kernel nest 14 deep.
--- kernel/bpf/btf.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
kernel/bpf/btf.c +13 -1
@@ -913,6 +913,8 @@ static const struct btf_type *btf_type_skip_qualifiers(const struct btf *btf, }#define BTF_SHOW_MAX_ITER 10 +/* nested structs and arrays shown; __btf_show_indent() has as many columns */ +#define BTF_SHOW_MAX_DEPTH 32#define BTF_KIND_BIT (kind) (1ULL << kind)
@@ -1306,8 +1308,18 @@ static void *btf_show_start_aggr_type(struct btf_show *show,const struct btf_type *t, u32 type_id, void *data) { - void *safe_data = btf_show_start_type(show, t, type_id, data); + void *safe_data; +/* +* Structs and arrays are shown by recursion. BTF loading bounds the +* depth of one resolve walk, not how deep resolved types may nest. +*/ +if (show->state.depth >=BTF_SHOW_MAX_DEPTH ) { + show->state.status = -E2BIG ; +return NULL ; + } + + safe_data =btf_show_start_type (show, t, type_id, data);if (!safe_data)return safe_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3003/3318 bpf: Fix stale offload->prog pointer after realloc
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 8e83d53596445fcf5b0385e5fbe8bcd971e06d06 ]
bpf_prog_realloc() moves a program that the rewrites of the verifier make outgrow its pages. It updates aux->prog, but not the offload->prog of a device-bound program. When the device is unregistered, __bpf_offload_dev_netdev_unregister() hands the stale pointer to __bpf_prog_offload_destroy(), which faults on the freed program:
BUG: unable to handle page fault for address: ffffc90000071050 RIP: 0010:__bpf_prog_offload_destroy+0x3f/0x310
It takes the right to load a device-bound XDP program, CAP_BPF and CAP_NET_ADMIN or a BPF token, and a device that can be removed.
Commit a1aa9ef47c29 ("bpf: Fix stale offload->prog pointer after constant blinding") repaired the other place that replaces a program. Do the same here.
Nothing keeps the device while a program is loaded, so it can also be unregistered at that very moment. That frees the offload, and it may have read offload->prog already when the old copy of the program is freed. In both places update the pointer under bpf_devs_lock, before the old copy goes.
--- include/linux/bpf.h | 5 +++++ kernel/bpf/core.c | 4 ++-- kernel/bpf/offload.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-)
include/linux/bpf.h +5 -0
@@ -2865,6 +2865,7 @@ int bpf_dev_bound_kfunc_check(struct bpf_verifier_log *log,void *bpf_dev_bound_resolve_kfunc (struct bpf_prog *prog,u32 func_id);int bpf_prog_dev_bound_init (struct bpf_prog *prog,union bpf_attr *attr);int bpf_prog_dev_bound_inherit (struct bpf_prog *new_prog,struct bpf_prog *old_prog); +void bpf_prog_dev_bound_moved (struct bpf_prog *prog);void bpf_dev_bound_netdev_unregister (struct net_device *dev);static inline bool bpf_prog_is_dev_bound (const struct bpf_prog_aux *aux)
@@ -2925,6 +2926,10 @@ static inline int bpf_prog_dev_bound_inherit(struct bpf_prog *new_prog,return -EOPNOTSUPP ; } +static inline void bpf_prog_dev_bound_moved (struct bpf_prog *prog) +{ +} +static inline void bpf_dev_bound_netdev_unregister (struct net_device *dev) { }
kernel/bpf/core.c +2 -2
@@ -253,6 +253,7 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,memcpy (fp, fp_old, fp_old->pages *PAGE_SIZE ); fp->pages = pages; fp->aux->prog = fp; +bpf_prog_dev_bound_moved (fp);/* We keep fp->aux from fp_old around in the new * reallocated structure.
@@ -1478,8 +1479,7 @@ void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other)* know whether fp here is the clone or the original. */ fp->aux->prog = fp; -if (fp->aux->offload) - fp->aux->offload->prog = fp; +bpf_prog_dev_bound_moved (fp);bpf_prog_clone_free (fp_other); }
kernel/bpf/offload.c +16 -0
@@ -105,6 +105,22 @@ static int __bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev,return err; } +/* +* @prog takes the place of a copy that the caller is about to free. Nothing +* keeps the netdev while a program is loaded: once the lock is dropped, no +* unregistration is left that has got the old copy from offload->prog. +*/ +void bpf_prog_dev_bound_moved (struct bpf_prog *prog) +{ +if (!bpf_prog_is_dev_bound (prog->aux)) +return ; + +down_read (&bpf_devs_lock); +if (prog->aux->offload) + prog->aux->offload->prog = prog; +up_read (&bpf_devs_lock); +} +static void __bpf_prog_offload_destroy (struct bpf_prog *prog) {struct bpf_prog_offload *offload = prog->aux->offload;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3004/3318 bpf: Dont bind a program to a netdev that goes away
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit af929bc938e0d0ecd839e6fed9a2ce5eb5185e5c ]
bpf_prog_dev_bound_init() looks the device up, takes bpf_devs_lock and registers the device for the program. The reference it holds does not keep the device registered. If bpf_dev_bound_netdev_unregister() has run by the time the lock is taken, nobody takes the program off the device any
more: the bpf_offload_netdev and offload->netdev point to a net_device that is freed as soon as the reference is dropped. bpf_dev_bound_resolve_kfunc() dereferences it while the program is verified, and a new device at the same address finds the old entry.
unregister_netdevice_many_notify() leaves NETREG_REGISTERED before it calls bpf_dev_bound_netdev_unregister(), which takes bpf_devs_lock. Look at reg_state under that lock, and treat a device that goes like one that is not there.
--- kernel/bpf/offload.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/bpf/offload.c +8 -1
@@ -268,7 +268,14 @@ int bpf_prog_dev_bound_init(struct bpf_prog *prog, union bpf_attr *attr) prog->aux->offload_requested = !(attr->prog_flags &BPF_F_XDP_DEV_BOUND_ONLY );down_write (&bpf_devs_lock); - err =__bpf_prog_dev_bound_init (prog, netdev); +/* +* Behind bpf_dev_bound_netdev_unregister() nobody would take the +* program off the device, which goes once the reference is dropped. +*/ +if (READ_ONCE (netdev->reg_state) ==NETREG_REGISTERED ) + err =__bpf_prog_dev_bound_init (prog, netdev); +else + err = -EINVAL ;up_write (&bpf_devs_lock); out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3005/3318 bpf: Dont take an extension for an iterator program
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 7cc639dc45c5d3b69acb2a2fc834e9eec51e0214 ]
An extension inherits the expected_attach_type of the program it extends. If that is BPF_TRACE_ITER, check_attach_btf_id() hands the extension to bpf_iter_prog_supported(), which goes by the name of the attach function. For an extension that is the name of the subprogram it replaces, so the load fails with -EINVAL, unless that subprogram is called like the function of a target, bpf_iter_bpf_map_elem for example.
Then the extension gets the context of that target. If the subprogram has as many arguments, it can use the key and the value as buffers, but how far it reaches is noted in the extension, where the test of the iterator link does not look: it reads and writes behind the elements of the map. And the id of the subprogram in the BTF of the program is cached as the id of the target, so that programs of that target which are loaded already cannot be attached.
Refuse all extensions here.
--- kernel/bpf/bpf_iter.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/bpf/bpf_iter.c +7 -0
@@ -344,6 +344,13 @@ bool bpf_iter_prog_supported(struct bpf_prog *prog)const char *prefix =BPF_ITER_FUNC_PREFIX ;int prefix_len =strlen (prefix); +/* +* The attach function of an extension is a subprogram of the iterator +* program that it extends, whatever its name is. +*/ +if (prog->type ==BPF_PROG_TYPE_EXT ) +return -EINVAL ; +if (strncmp (attach_fname, prefix, prefix_len))return false;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3006/3318 bpf: Dont take an extension for a writable raw tracepoint program
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 7fe348f18b37b3f4c8beb981ef3f84564047380a ]
bpf_probe_register() compares max_tp_access of the program that is attached with the size of the buffer that the tracepoint lets programs write to. An extension of that program, or of one of its global functions, gets the same context and the same pointer to the buffer. What it accesses is noted in its own max_tp_access, which nobody looks at. So it reads and writes behind the buffer, of a tracepoint that may have none:
BUG: KASAN: stack-out-of-bounds in bpf_prog_5843f2b820eb4929_tr26_ext_far+0xf4/0x10c Write of size 4 at addr ffffc90000d8f894 by task wext/103
Refuse such extensions.
--- kernel/bpf/verifier.c | 9 +++++++++ 1 file changed, 9 insertions(+)
kernel/bpf/verifier.c +9 -0
@@ -20365,6 +20365,15 @@ int bpf_check_attach_target(struct bpf_verifier_log *log, "Extension programs should be JITed\n");return -EINVAL ; } +/* +* How much of the buffer of the tracepoint is used +* is checked for the program that is attached to it. +*/ +if (tgt_prog->type ==BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE ) { +bpf_log (log, +"Cannot extend a writable raw tracepoint program\n" ); +return -EINVAL ; + } tgt_changes_pkt_data = aux->func ? aux->func[subprog]->aux->changes_pkt_data : aux->changes_pkt_data;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3007/3318 power: supply: qcom_battmgr: report full batteries
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit 6c8098e04ee4d233399e40e7311715844910f8f8 ]
The SC8280XP battery-status response has no explicit full state. When a battery reaches its full capacity on external power, neither the charging nor discharging bit is set. The driver consequently reports "Not charging", which can make userspace show the system as battery powered.
Use the response's power-online bit and the reported capacity to identify a battery that is full while externally powered. Preserve "Not charging" for a battery whose charging is inhibited below its full capacity.
--- drivers/power/supply/qcom_battmgr.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/power/supply/qcom_battmgr.c +11 -5
@@ -1017,6 +1017,7 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr, size_t len) {unsigned int opcode =le32_to_cpu (resp->hdr.opcode); +unsigned int power_state;unsigned int source;unsigned int state;size_t payload_len = len -sizeof (struct pmic_glink_hdr );
@@ -1065,19 +1066,24 @@ static void qcom_battmgr_sc8280xp_callback(struct qcom_battmgr *battmgr,return ; } + battmgr->status.capacity =le32_to_cpu (resp->status.capacity) *1000 ; + battmgr->status.power_now =le32_to_cpu (resp->status.rate) *1000 ; + battmgr->status.voltage_now =le32_to_cpu (resp->status.battery_voltage) *1000 ; + battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); + state =le32_to_cpu (resp->status.battery_state); + power_state =le32_to_cpu (resp->status.power_state);if (state &BIT (0 )) battmgr->status.status =POWER_SUPPLY_STATUS_DISCHARGING ;else if (state &BIT (1 )) battmgr->status.status =POWER_SUPPLY_STATUS_CHARGING ; +else if ((power_state &BIT (0 )) && + battmgr->info.last_full_capacity && + battmgr->status.capacity >= battmgr->info.last_full_capacity) + battmgr->status.status =POWER_SUPPLY_STATUS_FULL ;else battmgr->status.status =POWER_SUPPLY_STATUS_NOT_CHARGING ; - battmgr->status.capacity =le32_to_cpu (resp->status.capacity) *1000 ; - battmgr->status.power_now =le32_to_cpu (resp->status.rate) *1000 ; - battmgr->status.voltage_now =le32_to_cpu (resp->status.battery_voltage) *1000 ; - battmgr->status.temperature =qcom_battmgr_sc8280xp_convert_temp (le32_to_cpu (resp->status.temperature)); - source =le32_to_cpu (resp->status.charging_source);qcom_battmgr_sc8280xp_set_online (battmgr->ac_psy, &battmgr->ac.online, source ==BATTMGR_CHARGING_SOURCE_AC );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3008/3318 netfilter: conntrack: fix unlikely UaF in gc worker
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 9836164821a46af07428bb2a5e14137bf0c7bd6e ]
When early-drop scan is enabled, gc_worker() reads tmp->ct_net, resolves cnet with nf_ct_pernet(), and reads cnet->count with RCU read lock held but before acquiring a reference to tmp.
Its unlikely but possible that the worker gets preempted before reading cnet->count while nf_conntrack_cleanup_net_list manages to unlink all conntracks and returns in the mean time.
This allows for the pernet memory to get free'd.
On resume, use after free would occur when the worker reads cnet->count.
This can be solved either via another synchronize_rcu() in nf_conntrack_cleanup_net_list or via cheaper flush_work(). If work wasn't running no race can happen as next call cannot observe already-unlinked conntrack objects.
This is an LLM finding with no reproducer, but it appears to be correct.
--- net/netfilter/nf_conntrack_core.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nf_conntrack_core.c +5 -0
@@ -2554,6 +2554,11 @@ void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list) goto i_see_dead_people; } +/* must wait for current scan loop, worker also looks at +* struct nf_conntrack_net, which is about to be free'd. +*/ +flush_work (&conntrack_gc_work.dwork.work); +list_for_each_entry (net, net_exit_list, exit_list) {nf_conntrack_ecache_pernet_fini (net);nf_conntrack_expect_pernet_fini (net);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3009/3318 selftests: netfilter: conntrack_vrf.sh: move to lib.sh infra
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 954398b4d83759244656d37b4b626e912dc0969c ]
swap test for "ip" with "conntrack", former is already accounted for via setup_ns helper. Also switch to bash.
Stable-dep-of: a20a01ae8981 ("selftests: netfilter: fix return value in zone subtest")
--- .../selftests/netfilter/conntrack_vrf.sh | 101 +++++++----------- 1 file changed, 39 insertions(+), 62 deletions(-)
tools/testing/selftests/netfilter/conntrack_vrf.sh +39 -62
@@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # This script demonstrates interaction of conntrack and vrf. # The vrf driver calls the netfilter hooks again, with oif/iif
@@ -28,84 +28,65 @@ # that was supposed to be fixed by the commit mentioned above to make sure # that any fix to test case 1 won't break masquerade again. -ksft_skip=4 +source lib.sh IP0=172.30.30.1 IP1=172.30.30.2 PFXL=30 ret=0 -sfx=$(mktemp -u "XXXXXXXX") -ns0="ns0-$sfx" -ns1="ns1-$sfx" - cleanup() { ip netns pids $ns0 | xargs kill 2>/dev/null ip netns pids $ns1 | xargs kill 2>/dev/null - ip netns del $ns0 $ns1 + cleanup_all_ns } -nft --version > /dev/null 2>&1 -if [ $? -ne 0 ];then +if ! nft --version > /dev/null 2>&1;then echo "SKIP: Could not run test without nft tool" exit $ksft_skip fi -ip -Version > /dev/null 2>&1 -if [ $? -ne 0 ];then - echo "SKIP: Could not run test without ip tool" - exit $ksft_skip -fi - -ip netns add "$ns0" -if [ $? -ne 0 ];then - echo "SKIP: Could not create net namespace $ns0" +if ! conntrack --version > /dev/null 2>&1;then + echo "SKIP: Could not run test without conntrack tool" exit $ksft_skip fi -ip netns add "$ns1" trap cleanup EXIT -ip netns exec $ns0 sysctl -q -w net.ipv4.conf.default.rp_filter=0 -ip netns exec $ns0 sysctl -q -w net.ipv4.conf.all.rp_filter=0 -ip netns exec $ns0 sysctl -q -w net.ipv4.conf.all.rp_filter=0 +setup_ns ns0 ns1 -ip link add veth0 netns "$ns0" type veth peer name veth0 netns "$ns1" > /dev/null 2>&1 -if [ $? -ne 0 ];then +ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.default.rp_filter=0 +ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.rp_filter=0 +ip netns exec "$ns0" sysctl -q -w net.ipv4.conf.all.rp_filter=0 + +if ! ip link add veth0 netns "$ns0" type veth peer name veth0 netns "$ns1" > /dev/null 2>&1; then echo "SKIP: Could not add veth device" exit $ksft_skip fi -ip -net $ns0 li add tvrf type vrf table 9876 -if [ $? -ne 0 ];then +if ! ip -net "$ns0" li add tvrf type vrf table 9876; then echo "SKIP: Could not add vrf device" exit $ksft_skip fi -ip -net $ns0 li set lo up - -ip -net $ns0 li set veth0 master tvrf -ip -net $ns0 li set tvrf up -ip -net $ns0 li set veth0 up -ip -net $ns1 li set veth0 up +ip -net "$ns0" li set veth0 master tvrf +ip -net "$ns0" li set tvrf up +ip -net "$ns0" li set veth0 up +ip -net "$ns1" li set veth0 up -ip -net $ns0 addr add $IP0/$PFXL dev veth0 -ip -net $ns1 addr add $IP1/$PFXL dev veth0 +ip -net "$ns0" addr add $IP0/$PFXL dev veth0 +ip -net "$ns1" addr add $IP1/$PFXL dev veth0 -ip netns exec $ns1 iperf3 -s > /dev/null 2>&1& -if [ $? -ne 0 ];then - echo "SKIP: Could not start iperf3" - exit $ksft_skip -fi +ip netns exec "$ns1" iperf3 -s > /dev/null 2>&1 & # test vrf ingress handling. # The incoming connection should be placed in conntrack zone 1, # as decided by the first iteration of the ruleset. test_ct_zone_in() { -ip netns exec $ns0 nft -f - <<EOF +ip netns exec "$ns0" nft -f - <<EOF table testct { chain rawpre { type filter hook prerouting priority raw;
@@ -126,21 +107,21 @@ table testct { } } EOF - ip netns exec $ns1 ping -W 1 -c 1 -I veth0 $IP0 > /dev/null + ip netns exec "$ns1" ping -W 1 -c 1 -I veth0 "$IP0" > /dev/null # should be in zone 1, not zone 2 - count=$(ip netns exec $ns0 conntrack -L -s $IP1 -d $IP0 -p icmp --zone 1 2>/dev/null | wc -l) - if [ $count -eq 1 ]; then + count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 1 2>/dev/null | wc -l) + if [ "$count" -eq 1 ]; then echo "PASS: entry found in conntrack zone 1" else echo "FAIL: entry not found in conntrack zone 1" - count=$(ip netns exec $ns0 conntrack -L -s $IP1 -d $IP0 -p icmp --zone 2 2> /dev/null | wc -l) - if [ $count -eq 1 ]; then + count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 2 2> /dev/null | wc -l) + if [ "$count" -eq 1 ]; then echo "FAIL: entry found in zone 2 instead" else echo "FAIL: entry not in zone 1 or 2, dumping table" - ip netns exec $ns0 conntrack -L - ip netns exec $ns0 nft list ruleset + ip netns exec "$ns0" conntrack -L + ip netns exec "$ns0" nft list ruleset fi fi }
@@ -153,12 +134,12 @@ test_masquerade_vrf() local qdisc=$1 if [ "$qdisc" != "default" ]; then - tc -net $ns0 qdisc add dev tvrf root $qdisc + tc -net "$ns0" qdisc add dev tvrf root "$qdisc" fi - ip netns exec $ns0 conntrack -F 2>/dev/null + ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec $ns0 nft -f - <<EOF +ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain rawout {
@@ -179,17 +160,15 @@ table ip nat { } } EOF - ip netns exec $ns0 ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null - if [ $? -ne 0 ]; then + if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null; then echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on vrf device" ret=1 return fi # must also check that nat table was evaluated on second (lower device) iteration. - ip netns exec $ns0 nft list table ip nat |grep -q 'counter packets 2' && - ip netns exec $ns0 nft list table ip nat |grep -q 'untracked counter packets [1-9]' - if [ $? -eq 0 ]; then + ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2' && + if ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then echo "PASS: iperf3 connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" else echo "FAIL: vrf rules have unexpected counter value"
@@ -197,7 +176,7 @@ EOF fi if [ "$qdisc" != "default" ]; then - tc -net $ns0 qdisc del dev tvrf root + tc -net "$ns0" qdisc del dev tvrf root fi }
@@ -206,8 +185,8 @@ EOF # oifname is the lower device (veth0 in this case). test_masquerade_veth() { - ip netns exec $ns0 conntrack -F 2>/dev/null -ip netns exec $ns0 nft -f - <<EOF + ip netns exec "$ns0" conntrack -F 2>/dev/null +ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain postrouting {
@@ -216,16 +195,14 @@ table ip nat { } } EOF - ip netns exec $ns0 ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null - if [ $? -ne 0 ]; then + if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null; then echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on veth device" ret=1 return fi # must also check that nat table was evaluated on second (lower device) iteration. - ip netns exec $ns0 nft list table ip nat |grep -q 'counter packets 2' - if [ $? -eq 0 ]; then + if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2'; then echo "PASS: iperf3 connect with masquerade + sport rewrite on veth device" else echo "FAIL: vrf masq rule has unexpected counter value"
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3010/3318 selftests: netfilter: conntrack_vrf.sh: prefer socat, not iperf3
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit 99bc5950ebd4f84e48b5d1c53c13cf117031de82 ]
Use socat, like most of the other scripts already do. This also makes the script complete slightly faster (3s -> 1s).
iperf3 establishes two connections (1 control connection, and 1+x depending on test), so adjust expected counter values as well.
Stable-dep-of: a20a01ae8981 ("selftests: netfilter: fix return value in zone subtest")
--- .../selftests/netfilter/conntrack_vrf.sh | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-)
tools/testing/selftests/netfilter/conntrack_vrf.sh +21 -19
@@ -43,15 +43,9 @@ cleanup() cleanup_all_ns } -if ! nft --version > /dev/null 2>&1;then - echo "SKIP: Could not run test without nft tool" - exit $ksft_skip -fi - -if ! conntrack --version > /dev/null 2>&1;then - echo "SKIP: Could not run test without conntrack tool" - exit $ksft_skip -fi +checktool "nft --version" "run test without nft" +checktool "conntrack --version" "run test without conntrack" +checktool "socat -h" "run test without socat" trap cleanup EXIT
@@ -79,7 +73,15 @@ ip -net "$ns1" li set veth0 up ip -net "$ns0" addr add $IP0/$PFXL dev veth0 ip -net "$ns1" addr add $IP1/$PFXL dev veth0 -ip netns exec "$ns1" iperf3 -s > /dev/null 2>&1 & +listener_ready() +{ + local ns="$1" + + ss -N "$ns" -l -n -t -o "sport = :55555" | grep -q "55555" +} + +ip netns exec "$ns1" socat -u -4 TCP-LISTEN:55555,reuseaddr,fork STDOUT > /dev/null & +busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1" # test vrf ingress handling. # The incoming connection should be placed in conntrack zone 1,
@@ -160,16 +162,16 @@ table ip nat { } } EOF - if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 >/dev/null; then - echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on vrf device" + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then + echo "FAIL: connect failure with masquerade + sport rewrite on vrf device" ret=1 return fi # must also check that nat table was evaluated on second (lower device) iteration. - ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2' && - if ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then - echo "PASS: iperf3 connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" + if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 1' && + ip netns exec "$ns0" nft list table ip nat |grep -q 'untracked counter packets [1-9]'; then + echo "PASS: connect with masquerade + sport rewrite on vrf device ($qdisc qdisc)" else echo "FAIL: vrf rules have unexpected counter value" ret=1
@@ -195,15 +197,15 @@ table ip nat { } } EOF - if ! ip netns exec "$ns0" ip vrf exec tvrf iperf3 -t 1 -c $IP1 > /dev/null; then - echo "FAIL: iperf3 connect failure with masquerade + sport rewrite on veth device" + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then + echo "FAIL: connect failure with masquerade + sport rewrite on veth device" ret=1 return fi # must also check that nat table was evaluated on second (lower device) iteration. - if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 2'; then - echo "PASS: iperf3 connect with masquerade + sport rewrite on veth device" + if ip netns exec "$ns0" nft list table ip nat |grep -q 'counter packets 1'; then + echo "PASS: connect with masquerade + sport rewrite on veth device" else echo "FAIL: vrf masq rule has unexpected counter value" ret=1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3011/3318 selftests: netfilter: fix return value in zone subtest
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit a20a01ae89813ef493dc416d69f2b2ad17afb54c ]
zone subtest prints FAIL, but did not set 'ret=1', so kselftest framework reports success.
While at it, also fail when "nft -f" returns an error.
Noticed thanks to a (broken) local patch that should have caused this selftest (resp. the kselftest framework) to report a failure.
--- .../selftests/netfilter/conntrack_vrf.sh | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
tools/testing/selftests/netfilter/conntrack_vrf.sh +22 -3
@@ -88,7 +88,7 @@ busywait $BUSYWAIT_TIMEOUT listener_ready "$ns1" # as decided by the first iteration of the ruleset. test_ct_zone_in() { -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF table testct { chain rawpre { type filter hook prerouting priority raw;
@@ -109,6 +109,12 @@ table testct { } } EOF + then + echo "FAIL: cannot load testct nft ruleset" + ret=1 + return + fi + ip netns exec "$ns1" ping -W 1 -c 1 -I veth0 "$IP0" > /dev/null # should be in zone 1, not zone 2
@@ -117,6 +123,7 @@ EOF echo "PASS: entry found in conntrack zone 1" else echo "FAIL: entry not found in conntrack zone 1" + ret=1 count=$(ip netns exec "$ns0" conntrack -L -s $IP1 -d $IP0 -p icmp --zone 2 2> /dev/null | wc -l) if [ "$count" -eq 1 ]; then echo "FAIL: entry found in zone 2 instead"
@@ -141,7 +148,7 @@ test_masquerade_vrf() ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain rawout {
@@ -162,6 +169,12 @@ table ip nat { } } EOF + then + echo "FAIL: cannot load ip nat nft ruleset" + ret=1 + return + fi + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on vrf device" ret=1
@@ -188,7 +201,7 @@ EOF test_masquerade_veth() { ip netns exec "$ns0" conntrack -F 2>/dev/null -ip netns exec "$ns0" nft -f - <<EOF +if ! ip netns exec "$ns0" nft -f - <<EOF flush ruleset table ip nat { chain postrouting {
@@ -197,6 +210,12 @@ table ip nat { } } EOF + then + echo "FAIL: cannot load ip nat postrouting ruleset" + ret=1 + return + fi + if ! ip netns exec "$ns0" ip vrf exec tvrf socat -u -4 STDIN TCP:"$IP1":55555 < /dev/null > /dev/null;then echo "FAIL: connect failure with masquerade + sport rewrite on veth device" ret=1
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3012/3318 netfilter: nft_compat: restrict raw table targets/matches
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Florian Westphal <[email protected]>
[ Upstream commit ac364eb4d6d747b15df17e5fc9e442c318afaaac ]
xt targets and matches declaring .table = "raw" (CT, NOTRACK) rely on only ever running in the legacy raw table's prerouting/output chains, ahead of conntrack. nft_compat_chain_validate_dependency() already enforces this kind of correspondence for "nat" by requiring the chain type to actually be NAT, but did nothing for "raw": a rule wrapping the CT target could be loaded into any hook and any priority via nft_compat, including after the real conntrack hook has already run.
The CT target attaches a conntrack template to the skb when none is set yet.
Require that a "raw" table dependency actually matches what xtables enforces via the implict/builtin table dependency.
--- net/netfilter/nft_compat.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
net/netfilter/nft_compat.c +15 -0
@@ -14,6 +14,7 @@#include <linux/netfilter/nf_tables.h> #include <linux/netfilter/nf_tables_compat.h> #include <linux/netfilter/x_tables.h> +#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4/ip_tables.h> #include <linux/netfilter_ipv6/ip6_tables.h> #include <linux/netfilter_bridge/ebtables.h>
@@ -45,6 +46,20 @@ static int nft_compat_chain_validate_dependency(const struct nft_ctx *ctx, type =NFT_CHAIN_T_NAT ;if (basechain->type->type != type)return -EINVAL ; + }else if (strcmp (tablename,"raw" ) ==0 ) { +/* iptables-nft emulates the legacy raw table, which only +* ever has prerouting/output chains at this exact priority. +*/ +if (ctx->family !=NFPROTO_IPV4 && + ctx->family !=NFPROTO_IPV6 ) +return -EINVAL ; + +if (basechain->ops.hooknum !=NF_INET_PRE_ROUTING && + basechain->ops.hooknum !=NF_INET_LOCAL_OUT ) +return -EINVAL ; + +if (basechain->ops.priority !=NF_IP_PRI_RAW ) +return -EINVAL ; }return 0 ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3013/3318 bpf: Dont take a program with a target program for an iterator
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit b83bacf2161d0f8583e3f1e9c90402638992ad82 ]
bpf_iter_prog_supported() goes by the name of the attach function. Commit 7cc639dc45c5 ("bpf: Don't take an extension for an iterator program") keeps out extensions, for which that is the name of a function of another program. A tracing program with BPF_TRACE_ITER that is loaded with attach_prog_fd gets there as well: unlike for BPF_TRACE_RAW_TP, bpf_check_attach_target() does not mind the target program.
If the function is called like that of an iterator target, bpf_iter_bpf_map for example, its id in the BTF of the program is cached as the id of the target, even if the load fails later. Programs of that target which are loaded already cannot be attached any more. And the program itself can be attached as an iterator of that target, with a context that the verifier has taken from the prototype of that function:
BUG: KASAN: stack-out-of-bounds in bpf_prog_66d4234e2e50f5b6_ts26_forged+0x12a/0x20b Read of size 8 at addr ffffc90000d9fc48 by task ts26/104
Refuse every program that has a target program. That covers extensions.
--- kernel/bpf/bpf_iter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/bpf/bpf_iter.c +3 -3
@@ -345,10 +345,10 @@ bool bpf_iter_prog_supported(struct bpf_prog *prog)int prefix_len =strlen (prefix);/* -* The attach function of an extension is a subprogram of the iterator -* program that it extends, whatever its name is. +* The attach function of a program that has a target program is a +* function of that program, whatever its name is. */ -if (prog->type ==BPF_PROG_TYPE_EXT ) +if (prog->aux->dst_prog)return -EINVAL ;if (strncmp (attach_fname, prefix, prefix_len))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3014/3318 bpf: fix cgroup_skb prog test run direct packet access
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mahe Tardy <[email protected]>
[ Upstream commit ed3e469d021cba343a3b32f0876f8f28b1d9bfdd ]
This is needed in the context of Tetragon to test cgroup_skb programs using BPF_PROG_TEST_RUN with direct packet access.
Commit b39b5f411dcf ("bpf: add cg_skb_is_valid_access for BPF_PROG_TYPE_CGROUP_SKB") added direct packet access for cgroup_skb programs and following commit 2cb494a36c98 ("bpf: add tests for direct packet access from CGROUP_SKB") added tests to the verifier to ensure that access to skb fields was possible and also fixed bpf_prog_test_run_skb. However, is_direct_pkt_access was never set to true for this program type, so data pointers were not computed when using prog_test_run, making data_end always equal to zero (data_meta is not accessible for cgroup_skb).
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 1 + 1 file changed, 1 insertion(+)
net/bpf/test_run.c +1 -0
@@ -993,6 +993,7 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,case BPF_PROG_TYPE_LWT_IN :case BPF_PROG_TYPE_LWT_OUT :case BPF_PROG_TYPE_LWT_XMIT : +case BPF_PROG_TYPE_CGROUP_SKB : is_direct_pkt_access = true;break ;default :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3015/3318 bpf: Refactor cleanup of bpf_prog_test_run_skb
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
[ Upstream commit d8accf661fcf3088ef4c349ab56ecd19a5071b19 ]
This bit of refactoring aims to simplify how we free memory in bpf_prog_test_run_skb to avoid code duplication.
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-)
net/bpf/test_run.c +14 -12
@@ -959,10 +959,10 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,u32 size = kattr->test.data_size_in;u32 repeat = kattr->test.repeat;struct __sk_buff *ctx =NULL ; +struct sk_buff *skb =NULL ; +struct sock *sk =NULL ;u32 retval, duration;int hh_len =ETH_HLEN ; -struct sk_buff *skb; -struct sock *sk;void *data;int ret;
@@ -981,8 +981,9 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, ctx =bpf_ctx_init (kattr,sizeof (struct __sk_buff ));if (IS_ERR (ctx)) { -kfree (data); -return PTR_ERR (ctx); + ret =PTR_ERR (ctx); + ctx =NULL ; + goto out; }switch (prog->type) {
@@ -1002,21 +1003,20 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, sk =sk_alloc (net,AF_UNSPEC ,GFP_USER , &bpf_dummy_proto,1 );if (!sk) { -kfree (data); -kfree (ctx); -return -ENOMEM ; + ret = -ENOMEM ; + goto out; }sock_init_data (NULL , sk); skb =slab_build_skb (data);if (!skb) { -kfree (data); -kfree (ctx); -sk_free (sk); -return -ENOMEM ; + ret = -ENOMEM ; + goto out; } skb->sk = sk; + data =NULL ;/* data released via kfree_skb */ +skb_reserve (skb,NET_SKB_PAD +NET_IP_ALIGN );__skb_put (skb, size);
@@ -1136,7 +1136,9 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,if (dev && dev != net->loopback_dev)dev_put (dev);kfree_skb (skb); -sk_free (sk); +kfree (data); +if (sk) +sk_free (sk);kfree (ctx);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3016/3318 bpf: Reorder bpf_prog_test_run_skb initialization
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
[ Upstream commit 57bb2f6717930a5e670da179c316159719b724a2 ]
This patch reorders the initialization of bpf_prog_test_run_skb to simplify the subsequent patch. Program types are checked first, followed by the ctx init, and finally the data init. With the subsequent patch, program types and the ctx init provide information that is used in the data init. Thus, we need the data init to happen last.
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
net/bpf/test_run.c +13 -13
@@ -973,19 +973,6 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,if (size <ETH_HLEN )return -EINVAL ; - data =bpf_test_init (kattr, kattr->test.data_size_in, - size,NET_SKB_PAD +NET_IP_ALIGN , -SKB_DATA_ALIGN (sizeof (struct skb_shared_info ))); -if (IS_ERR (data)) -return PTR_ERR (data); - - ctx =bpf_ctx_init (kattr,sizeof (struct __sk_buff )); -if (IS_ERR (ctx)) { - ret =PTR_ERR (ctx); - ctx =NULL ; - goto out; - } -switch (prog->type) {case BPF_PROG_TYPE_SCHED_CLS :case BPF_PROG_TYPE_SCHED_ACT :
@@ -1001,6 +988,19 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,break ; } + ctx =bpf_ctx_init (kattr,sizeof (struct __sk_buff )); +if (IS_ERR (ctx)) +return PTR_ERR (ctx); + + data =bpf_test_init (kattr, kattr->test.data_size_in, + size,NET_SKB_PAD +NET_IP_ALIGN , +SKB_DATA_ALIGN (sizeof (struct skb_shared_info ))); +if (IS_ERR (data)) { + ret =PTR_ERR (data); + data =NULL ; + goto out; + } + sk =sk_alloc (net,AF_UNSPEC ,GFP_USER , &bpf_dummy_proto,1 );if (!sk) { ret = -ENOMEM ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3017/3318 bpf: Craft non-linear skbs in BPF_PROG_TEST_RUN
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paul Chaignon <[email protected]>
[ Upstream commit 838baa351cee86526973fb3ef49c0f4c1b2f3b0c ]
This patch adds support for crafting non-linear skbs in BPF test runs for tc programs. The size of the linear area is given by ctx->data_end, with a minimum of ETH_HLEN always pulled in the linear area. If ctx or ctx->data_end are null, a linear skb is used.
This is particularly useful to test support for non-linear skbs in large codebases such as Cilium. We've had multiple bugs in the past few years where we were missing calls to bpf_skb_pull_data(). This support in BPF_PROG_TEST_RUN would allow us to automatically cover this case in our BPF tests.
LWT program types are currently excluded in this patch. Allowing non-linear skbs for these programs would require a bit more care because they are able to call helpers (ex., bpf_clone_redirect, bpf_redirect) that themselves call eth_type_trans(). eth_type_trans() assumes there are at least ETH_HLEN bytes in the linear area. That may not be true for LWT programs as we already pulled the L2 header via the eth_type_trans() call in bpf_prog_test_run_skb().
In addition to the selftests introduced later in the series, this patch was tested by enabling non-linear skbs for all tc selftests programs and checking test failures were expected.
Stable-dep-of: 6aff0129f327 ("bpf: Use the socket of a sk_lookup test run under RCU")
--- net/bpf/test_run.c | 103 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 21 deletions(-)
net/bpf/test_run.c +82 -21
@@ -435,7 +435,7 @@ static int bpf_test_run(struct bpf_prog *prog, void *ctx, u32 repeat,static int bpf_test_finish (const union bpf_attr *kattr,union bpf_attr __user *uattr,const void *data, -struct skb_shared_info *sinfo,u32 size, +struct skb_shared_info *sinfo,u32 size,u32 frag_size,u32 retval,u32 duration) {void __user *data_out =u64_to_user_ptr (kattr->test.data_out);
@@ -452,7 +452,7 @@ static int bpf_test_finish(const union bpf_attr *kattr, }if (data_out) { -int len = sinfo ? copy_size - sinfo->xdp_frags_size : copy_size; +int len = sinfo ? copy_size - frag_size : copy_size;if (len <0 ) { err = -ENOSPC ;
@@ -874,6 +874,12 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)/* cb is allowed */ if (!range_is_zero(__skb, offsetofend(struct __sk_buff, cb), + offsetof(struct __sk_buff , data_end))) +return -EINVAL ; + +/* data_end is allowed, but not copied to skb */ + + if (!range_is_zero(__skb, offsetofend(struct __sk_buff, data_end), offsetof(struct __sk_buff , tstamp)))return -EINVAL ;
@@ -953,34 +959,39 @@ static struct proto bpf_dummy_proto = {int bpf_prog_test_run_skb (struct bpf_prog *prog,const union bpf_attr *kattr,union bpf_attr __user *uattr) { -bool is_l2 = false, is_direct_pkt_access = false; +bool is_l2 = false, is_direct_pkt_access = false, is_lwt = false; +u32 tailroom =SKB_DATA_ALIGN (sizeof (struct skb_shared_info ));struct net *net = current->nsproxy->net_ns;struct net_device *dev = net->loopback_dev; -u32 size = kattr->test.data_size_in; +u32 headroom =NET_SKB_PAD +NET_IP_ALIGN ; +u32 linear_sz = kattr->test.data_size_in;u32 repeat = kattr->test.repeat;struct __sk_buff *ctx =NULL ;struct sk_buff *skb =NULL ;struct sock *sk =NULL ;u32 retval, duration;int hh_len =ETH_HLEN ; -void *data; +void *data =NULL ;int ret;if ((kattr->test.flags & ~BPF_F_TEST_SKB_CHECKSUM_COMPLETE ) || kattr->test.cpu || kattr->test.batch_size)return -EINVAL ; -if (size <ETH_HLEN ) +if (kattr->test.data_size_in <ETH_HLEN )return -EINVAL ;switch (prog->type) {case BPF_PROG_TYPE_SCHED_CLS :case BPF_PROG_TYPE_SCHED_ACT : + is_direct_pkt_access = true; is_l2 = true; - fallthrough; +break ;case BPF_PROG_TYPE_LWT_IN :case BPF_PROG_TYPE_LWT_OUT :case BPF_PROG_TYPE_LWT_XMIT : + is_lwt = true; + fallthrough;case BPF_PROG_TYPE_CGROUP_SKB : is_direct_pkt_access = true;break ;
@@ -992,9 +1003,24 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,if (IS_ERR (ctx))return PTR_ERR (ctx); - data =bpf_test_init (kattr, kattr->test.data_size_in, - size,NET_SKB_PAD +NET_IP_ALIGN , -SKB_DATA_ALIGN (sizeof (struct skb_shared_info ))); +if (ctx) { +if (ctx->data_end > kattr->test.data_size_in || ctx->data || ctx->data_meta) { + ret = -EINVAL ; + goto out; + } +if (ctx->data_end) { +/* Non-linear LWT test_run is unsupported for now. */ +if (is_lwt) { + ret = -EINVAL ; + goto out; + } + linear_sz =max (ETH_HLEN , ctx->data_end); + } + } + + linear_sz =min_t (u32, linear_sz,PAGE_SIZE - headroom - tailroom); + + data =bpf_test_init (kattr, linear_sz, linear_sz, headroom, tailroom);if (IS_ERR (data)) { ret =PTR_ERR (data); data =NULL ;
@@ -1018,7 +1044,43 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr, data =NULL ;/* data released via kfree_skb */ skb_reserve (skb,NET_SKB_PAD +NET_IP_ALIGN ); -__skb_put (skb, size); +__skb_put (skb, linear_sz); + +if (unlikely (kattr->test.data_size_in > linear_sz)) { +void __user *data_in =u64_to_user_ptr (kattr->test.data_in); +struct skb_shared_info *sinfo =skb_shinfo (skb); +u32 copied = linear_sz; + +while (copied < kattr->test.data_size_in) { +struct page *page; +u32 data_len; + +if (sinfo->nr_frags ==MAX_SKB_FRAGS ) { + ret = -ENOMEM ; + goto out; + } + + page =alloc_page (GFP_KERNEL ); +if (!page) { + ret = -ENOMEM ; + goto out; + } + + data_len =min_t (u32, kattr->test.data_size_in - copied, +PAGE_SIZE ); +skb_fill_page_desc (skb, sinfo->nr_frags, page,0 , data_len); + +if (copy_from_user (page_address (page), data_in + copied, + data_len)) { + ret = -EFAULT ; + goto out; + } + skb->data_len += data_len; + skb->truesize +=PAGE_SIZE ; + skb->len += data_len; + copied += data_len; + } + }if (ctx && ctx->ifindex >1 ) { dev =dev_get_by_index (net, ctx->ifindex);
@@ -1123,12 +1185,11 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,convert_skb_to___skb (skb, ctx); - size = skb->len; -/* bpf program can never convert linear skb to non-linear */ -if (WARN_ON_ONCE (skb_is_nonlinear (skb))) - size =skb_headlen (skb); - ret =bpf_test_finish (kattr, uattr, skb->data,NULL , size, retval, - duration); +if (skb_is_nonlinear (skb)) +/* bpf program can never convert linear skb to non-linear */ +WARN_ON_ONCE (linear_sz == kattr->test.data_size_in); + ret =bpf_test_finish (kattr, uattr, skb->data,skb_shinfo (skb), skb->len, + skb->data_len, retval, duration);if (!ret) ret =bpf_ctx_finish (kattr, uattr, ctx,sizeof (struct __sk_buff ));
@@ -1345,7 +1406,7 @@ int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr, goto out; size = xdp.data_end - xdp.data_meta + sinfo->xdp_frags_size; - ret =bpf_test_finish (kattr, uattr, xdp.data_meta, sinfo, size, + ret =bpf_test_finish (kattr, uattr, xdp.data_meta, sinfo, size, sinfo->xdp_frags_size, retval, duration);if (!ret) ret = bpf_ctx_finish(kattr, uattr, ctx,
@@ -1436,7 +1497,7 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, goto out; ret =bpf_test_finish (kattr, uattr, &flow_keys,NULL , -sizeof (flow_keys), retval, duration); +sizeof (flow_keys),0 , retval, duration);if (!ret) ret =bpf_ctx_finish (kattr, uattr, user_ctx,sizeof (struct bpf_flow_keys ));
@@ -1537,7 +1598,7 @@ int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kat user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); } - ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 , retval, duration); + ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration);if (!ret) ret =bpf_ctx_finish (kattr, uattr, user_ctx,sizeof (*user_ctx));
@@ -1737,7 +1798,7 @@ int bpf_prog_test_run_nf(struct bpf_prog *prog,if (ret) goto out; - ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 , retval, duration); + ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration); out:kfree (user_ctx);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3018/3318 bpf: Use the socket of a sk_lookup test run under RCU
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 6aff0129f327b159c86a54e6bea64a027630ff6b ]
bpf_sk_lookup_assign() accepts only sockets which are freed by RCU, and takes no reference. bpf_prog_test_run_sk_lookup() looks at sk_reuseport of the selected socket and generates its cookie, which is a write, behind bpf_test_timer_leave(), that is outside of the RCU read side critical section in which the program ran. If the socket is closed in the meantime it may be gone.
Do both before the section ends.
--- net/bpf/test_run.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
net/bpf/test_run.c +9 -10
@@ -1583,20 +1583,19 @@ int bpf_prog_test_run_sk_lookup(struct bpf_prog *prog, const union bpf_attr *kat ctx.selected_sk =NULL ; retval =BPF_PROG_SK_LOOKUP_RUN_ARRAY (progs, ctx, bpf_prog_run); }while (bpf_test_timer_continue (&t,1 , repeat, &ret, &duration)); -bpf_test_timer_leave (&t); - -if (ret <0 ) - goto out; +/* Nothing but RCU keeps the selected socket */ user_ctx->cookie =0 ; -if (ctx.selected_sk) { -if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) { +if (!ret && ctx.selected_sk) { +if (ctx.selected_sk->sk_reuseport && !ctx.no_reuseport) ret = -EOPNOTSUPP ; - goto out; - } - - user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); +else + user_ctx->cookie =sock_gen_cookie (ctx.selected_sk); } +bpf_test_timer_leave (&t); + +if (ret <0 ) + goto out; ret =bpf_test_finish (kattr, uattr,NULL ,NULL ,0 ,0 , retval, duration);if (!ret)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 3019/3318 bpf: Use memmove() to store bytes in an skb
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
[ Upstream commit 1db084f42884c5af881fedf3df4777fe2095b20b ]
Through bpf_dynptr_write() and bpf_dynptr_copy() the source of bpf_skb_store_bytes() can be a slice of the same skb which overlaps the destination. memcpy() then reads bytes which it has overwritten already. On x86 with FSRM it repeats the first bytes of the source instead of copying it. Local, ringbuf and skb metadata dynptrs are written with memmove() for that reason.
--- net/core/filter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/core/filter.c +2 -1
@@ -1724,7 +1724,8 @@ BPF_CALL_5(bpf_skb_store_bytes, struct sk_buff *, skb, u32, offset,if (flags &BPF_F_RECOMPUTE_CSUM )__skb_postpull_rcsum (skb, ptr, len, offset); -memcpy (ptr, from, len); +/* through a dynptr the source may be an overlapping slice of the skb */ +memmove (ptr, from, len);if (flags &BPF_F_RECOMPUTE_CSUM )__skb_postpush_rcsum (skb, ptr, len, offset);
Signature · 1 line
2.53.0