<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/sound/core/seq, branch master</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>ALSA: ump: Drain sequencer callbacks before freeing their client</title>
<updated>2026-10-25T07:55:04+00:00</updated>
<author>
<name>Cen Zhang</name>
<email>zzzccc427@gmail.com</email>
</author>
<published>2026-10-24T08:02:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9b30046de03acb3b3f2135d45af6be7ee0b565b6'/>
<id>9b30046de03acb3b3f2135d45af6be7ee0b565b6</id>
<content type='text'>
seq_ump_client_free() cancels group_notify_work while the endpoint still
publishes seq_ops and seq_client. A received Function Block update can
enter the sequencer callback after cancellation and queue the work again.
Even disabling the work cannot protect a callback that already loaded
seq_client and then resumes after the client has been freed.

A USB UMP endpoint can continue receiving while its sequencer binding
is removed. The following order uses the same endpoint and client:

  Sequencer binding removal             UMP input completion
  -------------------------             --------------------
  cancel_work_sync()
                                        load seq_ops and seq_client
  delete sequencer client
  clear endpoint binding
  kfree(client)
                                        schedule group_notify_work
                                        read client-&gt;seq_client

Cover all calls through seq_ops with SRCU in the UMP core. Withdraw the
operations pointer and wait for those callbacks before canceling work
and deleting the client. No producer can then queue work after the final
cancellation, and both the client and callback code remain available
until the last in-flight callback returns.

Publish seq_ops with release/acquire ordering so the separately stored
seq_client is initialized before any callback uses it. Use SRCU because
sequencer notification delivery can sleep; no callback needs to change
its existing execution context or allocation behavior.

Fixes: 4a16a3af0571 ("ALSA: seq: ump: Handle FB info update")
Assisted-by: LLM
Signed-off-by: Cen Zhang &lt;zzzccc427@gmail.com&gt;
Link: https://patch.msgid.link/pm-pmb-00625126b81966d1bf1d-v2-915f6bbabe1fd458c3ab@gmail.com
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
seq_ump_client_free() cancels group_notify_work while the endpoint still
publishes seq_ops and seq_client. A received Function Block update can
enter the sequencer callback after cancellation and queue the work again.
Even disabling the work cannot protect a callback that already loaded
seq_client and then resumes after the client has been freed.

A USB UMP endpoint can continue receiving while its sequencer binding
is removed. The following order uses the same endpoint and client:

  Sequencer binding removal             UMP input completion
  -------------------------             --------------------
  cancel_work_sync()
                                        load seq_ops and seq_client
  delete sequencer client
  clear endpoint binding
  kfree(client)
                                        schedule group_notify_work
                                        read client-&gt;seq_client

Cover all calls through seq_ops with SRCU in the UMP core. Withdraw the
operations pointer and wait for those callbacks before canceling work
and deleting the client. No producer can then queue work after the final
cancellation, and both the client and callback code remain available
until the last in-flight callback returns.

Publish seq_ops with release/acquire ordering so the separately stored
seq_client is initialized before any callback uses it. Use SRCU because
sequencer notification delivery can sleep; no callback needs to change
its existing execution context or allocation behavior.

Fixes: 4a16a3af0571 ("ALSA: seq: ump: Handle FB info update")
Assisted-by: LLM
Signed-off-by: Cen Zhang &lt;zzzccc427@gmail.com&gt;
Link: https://patch.msgid.link/pm-pmb-00625126b81966d1bf1d-v2-915f6bbabe1fd458c3ab@gmail.com
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: oss: Skip events until fully initialized</title>
<updated>2026-10-17T08:17:08+00:00</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2026-10-16T16:19:29+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=68d4a6ea6cc6091a05836f783bc17d525d266d0b'/>
<id>68d4a6ea6cc6091a05836f783bc17d525d266d0b</id>
<content type='text'>
When an OSS sequencer device is opened, it creates a sequencer port,
then further initializes the internal states like a timer instance,
etc.  Since the sequencer port is published, an event can be already
delivered, and this may hit unexpected event handling, which can
eventually cause a NULL dereference (like the timer start/stop event
triggered before the timer initialization).

For avoiding such a race, introduce a simple guard and skips the event
processing until the port is fully initialized.
At releasing the device, in turn, clear this guard, so that any input
events will be discarded during the teardown.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Link: https://patch.msgid.link/20261016161930.482309-1-tiwai@suse.de
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
When an OSS sequencer device is opened, it creates a sequencer port,
then further initializes the internal states like a timer instance,
etc.  Since the sequencer port is published, an event can be already
delivered, and this may hit unexpected event handling, which can
eventually cause a NULL dereference (like the timer start/stop event
triggered before the timer initialization).

For avoiding such a race, introduce a simple guard and skips the event
processing until the port is fully initialized.
At releasing the device, in turn, clear this guard, so that any input
events will be discarded during the teardown.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Cc: &lt;stable@vger.kernel.org&gt;
Link: https://patch.msgid.link/20261016161930.482309-1-tiwai@suse.de
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: oss: Ignore sync echoes without a write queue</title>
<updated>2026-10-16T08:21:56+00:00</updated>
<author>
<name>Cen Zhang</name>
<email>zzzccc427@gmail.com</email>
</author>
<published>2026-10-16T02:17:58+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=5618f6837ef3314e2c581d4c05ec13b7ed975cb4'/>
<id>5618f6837ef3314e2c581d4c05ec13b7ed975cb4</id>
<content type='text'>
The sync-echo callback needs a write queue before it can wake up a
synchronizing writer. However, snd_seq_oss_open() publishes the session's
port with snd_seq_oss_event_input() as its callback before allocating
and assigning dp-&gt;writeq.

A kernel caller using snd_seq_kernel_client_dispatch() with the OSS
client ID can deliver an ECHO containing SEQ_SYNCTIMER to this port
before the write queue is assigned. The helper stamps the supplied
client ID into the event, so the callback's source-client check accepts
it. Regular userspace events carry their own client ID and are rejected.

The failing ordering is:

    OSS open                          Kernel direct dispatch
    --------                          ----------------------
    Zero-allocate dp
    Set dp-&gt;cseq
    Publish callback port
                                      Dispatch ECHO as the OSS client
                                      Look up and pin that port
                                      Enter snd_seq_oss_event_input()
                                      Pass NULL to writeq_wakeup()
    Allocate and assign dp-&gt;writeq

Dispatch reaches the callback after port publication and before the
queue assignment. OSS register_mutex serializes open and release, but
direct dispatch does not take it. The port use reference keeps dp alive
through the callback; it does not wait for constructor initialization.
The wakeup helper therefore attempts to acquire sync_lock through a
NULL queue pointer, causing a fault.

Sample dp-&gt;writeq once in the SEQ_SYNCTIMER branch and ignore the echo
when the queue is absent, matching the adjacent read-queue check. Pass
the checked pointer to the wakeup helper so a NULL sample cannot reach
the lock access. The existing port reference protects the queue's
lifetime through this call, since port deletion drains callbacks before
free_devinfo() frees the queue.

KASAN report as below:

    Oops: general protection fault, probably for non-canonical address 0xdffffc000000000d: 0000 [#1] SMP KASAN NOPTI
    KASAN: null-ptr-deref in range [0x0000000000000068-0x000000000000006f]
    CPU: 2 UID: 0 PID: 69 Comm: kworker/2:1 Tainted: G        W           7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy)
    Tainted: [W]=WARN
    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 pmbd_dispatch_early_sync_echo
    RIP: 0010:do_raw_spin_lock+0x71/0x270
    Code: d0 60 81 49 8d 14 04 c7 02 f1 f1 f1 f1 c7 42 04 04 f3 f3 f3 65 48 8b 15 05 df 88 09 48 89 54 24 60 31 d2 48 89 fa 48 c1 ea 03 &lt;0f&gt; b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 b9
    RSP: 0018:ffff88810450f878 EFLAGS: 00010013
    RAX: dffffc0000000000 RBX: 0000000000000068 RCX: 0000000000000000
    RDX: 000000000000000d RSI: 0000000000000000 RDI: 000000000000006c
    RBP: 0000000000000293 R08: 0000000000000001 R09: 0000000000000000
    R10: ffffffff8940fe57 R11: 0000000000000000 R12: 1ffff110208a1f10
    R13: 0000000000000068 R14: 0000000000000001 R15: ffff88810450fbee
    FS:  0000000000000000(0000) GS:ffff8881fd885000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000006d2890 CR3: 0000000106cbf002 CR4: 0000000000770ef0
    PKRU: 55555554
    Call Trace:
     &lt;TASK&gt;
     ? pmbd_probe_hit_cookie+0xee/0x1c0
     ? __pfx_do_raw_spin_lock+0x10/0x10
     ? lock_acquire+0x2b8/0x2f0
     ? __pfx_pmbd_probe_hit_cookie+0x10/0x10
     _raw_spin_lock_irqsave+0x44/0x60
     ? snd_seq_oss_writeq_wakeup+0x30/0xf0
     snd_seq_oss_writeq_wakeup+0x30/0xf0
     snd_seq_oss_event_input+0x1e4/0x2a0
     ? do_raw_read_unlock+0x49/0xe0
     ? __pfx_snd_seq_oss_event_input+0x10/0x10
     __snd_seq_deliver_single_event+0x105/0x1a0
     ? snd_seq_port_use_ptr+0x111/0x170
     snd_seq_deliver_single_event+0x2fc/0x770
     ? __pfx_snd_seq_deliver_single_event+0x10/0x10
     ? __pfx_pmbd_hold_maybe+0x10/0x10
     snd_seq_deliver_event+0x45a/0x760
     ? __pfx_do_raw_spin_lock+0x10/0x10
     ? lock_acquire+0x2b8/0x2f0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_snd_seq_deliver_event+0x10/0x10
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? trace_hardirqs_on+0x18/0x160
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     snd_seq_kernel_client_dispatch+0x19c/0x1e0
     pmbd_dispatch_early_sync_echo+0x121/0x1c0
     ? __pfx_pmbd_dispatch_early_sync_echo+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? finish_task_switch.isra.0+0x1dc/0x980
     process_one_work+0x908/0x19c0
     ? __pfx_process_one_work+0x10/0x10
     ? 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
     &lt;/TASK&gt;
    Modules linked in:
    ---[ end trace 0000000000000000 ]---
    RIP: 0010:do_raw_spin_lock+0x71/0x270
    Code: d0 60 81 49 8d 14 04 c7 02 f1 f1 f1 f1 c7 42 04 04 f3 f3 f3 65 48 8b 15 05 df 88 09 48 89 54 24 60 31 d2 48 89 fa 48 c1 ea 03 &lt;0f&gt; b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 b9
    RSP: 0018:ffff88810450f878 EFLAGS: 00010013
    RAX: dffffc0000000000 RBX: 0000000000000068 RCX: 0000000000000000
    RDX: 000000000000000d RSI: 0000000000000000 RDI: 000000000000006c
    RBP: 0000000000000293 R08: 0000000000000001 R09: 0000000000000000
    R10: ffffffff8940fe57 R11: 0000000000000000 R12: 1ffff110208a1f10
    R13: 0000000000000068 R14: 0000000000000001 R15: ffff88810450fbee
    FS:  0000000000000000(0000) GS:ffff8881fd885000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000006d2890 CR3: 0000000106cbf002 CR4: 0000000000770ef0
    PKRU: 55555554
    Kernel panic - not syncing: Fatal exception
    Kernel Offset: disabled
    Rebooting in 1 seconds..

Assisted-by: LLM
Signed-off-by: Cen Zhang &lt;zzzccc427@gmail.com&gt;
Link: https://patch.msgid.link/pm-pmb-3634251be738461947da-v2-64371e8c8d6cbf6956a3@gmail.com
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The sync-echo callback needs a write queue before it can wake up a
synchronizing writer. However, snd_seq_oss_open() publishes the session's
port with snd_seq_oss_event_input() as its callback before allocating
and assigning dp-&gt;writeq.

A kernel caller using snd_seq_kernel_client_dispatch() with the OSS
client ID can deliver an ECHO containing SEQ_SYNCTIMER to this port
before the write queue is assigned. The helper stamps the supplied
client ID into the event, so the callback's source-client check accepts
it. Regular userspace events carry their own client ID and are rejected.

The failing ordering is:

    OSS open                          Kernel direct dispatch
    --------                          ----------------------
    Zero-allocate dp
    Set dp-&gt;cseq
    Publish callback port
                                      Dispatch ECHO as the OSS client
                                      Look up and pin that port
                                      Enter snd_seq_oss_event_input()
                                      Pass NULL to writeq_wakeup()
    Allocate and assign dp-&gt;writeq

Dispatch reaches the callback after port publication and before the
queue assignment. OSS register_mutex serializes open and release, but
direct dispatch does not take it. The port use reference keeps dp alive
through the callback; it does not wait for constructor initialization.
The wakeup helper therefore attempts to acquire sync_lock through a
NULL queue pointer, causing a fault.

Sample dp-&gt;writeq once in the SEQ_SYNCTIMER branch and ignore the echo
when the queue is absent, matching the adjacent read-queue check. Pass
the checked pointer to the wakeup helper so a NULL sample cannot reach
the lock access. The existing port reference protects the queue's
lifetime through this call, since port deletion drains callbacks before
free_devinfo() frees the queue.

KASAN report as below:

    Oops: general protection fault, probably for non-canonical address 0xdffffc000000000d: 0000 [#1] SMP KASAN NOPTI
    KASAN: null-ptr-deref in range [0x0000000000000068-0x000000000000006f]
    CPU: 2 UID: 0 PID: 69 Comm: kworker/2:1 Tainted: G        W           7.2.0-rc6-pmb-bt-functional-v1+ #1 PREEMPT(lazy)
    Tainted: [W]=WARN
    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 pmbd_dispatch_early_sync_echo
    RIP: 0010:do_raw_spin_lock+0x71/0x270
    Code: d0 60 81 49 8d 14 04 c7 02 f1 f1 f1 f1 c7 42 04 04 f3 f3 f3 65 48 8b 15 05 df 88 09 48 89 54 24 60 31 d2 48 89 fa 48 c1 ea 03 &lt;0f&gt; b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 b9
    RSP: 0018:ffff88810450f878 EFLAGS: 00010013
    RAX: dffffc0000000000 RBX: 0000000000000068 RCX: 0000000000000000
    RDX: 000000000000000d RSI: 0000000000000000 RDI: 000000000000006c
    RBP: 0000000000000293 R08: 0000000000000001 R09: 0000000000000000
    R10: ffffffff8940fe57 R11: 0000000000000000 R12: 1ffff110208a1f10
    R13: 0000000000000068 R14: 0000000000000001 R15: ffff88810450fbee
    FS:  0000000000000000(0000) GS:ffff8881fd885000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000006d2890 CR3: 0000000106cbf002 CR4: 0000000000770ef0
    PKRU: 55555554
    Call Trace:
     &lt;TASK&gt;
     ? pmbd_probe_hit_cookie+0xee/0x1c0
     ? __pfx_do_raw_spin_lock+0x10/0x10
     ? lock_acquire+0x2b8/0x2f0
     ? __pfx_pmbd_probe_hit_cookie+0x10/0x10
     _raw_spin_lock_irqsave+0x44/0x60
     ? snd_seq_oss_writeq_wakeup+0x30/0xf0
     snd_seq_oss_writeq_wakeup+0x30/0xf0
     snd_seq_oss_event_input+0x1e4/0x2a0
     ? do_raw_read_unlock+0x49/0xe0
     ? __pfx_snd_seq_oss_event_input+0x10/0x10
     __snd_seq_deliver_single_event+0x105/0x1a0
     ? snd_seq_port_use_ptr+0x111/0x170
     snd_seq_deliver_single_event+0x2fc/0x770
     ? __pfx_snd_seq_deliver_single_event+0x10/0x10
     ? __pfx_pmbd_hold_maybe+0x10/0x10
     snd_seq_deliver_event+0x45a/0x760
     ? __pfx_do_raw_spin_lock+0x10/0x10
     ? lock_acquire+0x2b8/0x2f0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_snd_seq_deliver_event+0x10/0x10
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? trace_hardirqs_on+0x18/0x160
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     snd_seq_kernel_client_dispatch+0x19c/0x1e0
     pmbd_dispatch_early_sync_echo+0x121/0x1c0
     ? __pfx_pmbd_dispatch_early_sync_echo+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? finish_task_switch.isra.0+0x1dc/0x980
     process_one_work+0x908/0x19c0
     ? __pfx_process_one_work+0x10/0x10
     ? 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
     &lt;/TASK&gt;
    Modules linked in:
    ---[ end trace 0000000000000000 ]---
    RIP: 0010:do_raw_spin_lock+0x71/0x270
    Code: d0 60 81 49 8d 14 04 c7 02 f1 f1 f1 f1 c7 42 04 04 f3 f3 f3 65 48 8b 15 05 df 88 09 48 89 54 24 60 31 d2 48 89 fa 48 c1 ea 03 &lt;0f&gt; b6 14 02 48 89 f8 83 e0 07 83 c0 03 38 d0 7c 08 84 d2 0f 85 b9
    RSP: 0018:ffff88810450f878 EFLAGS: 00010013
    RAX: dffffc0000000000 RBX: 0000000000000068 RCX: 0000000000000000
    RDX: 000000000000000d RSI: 0000000000000000 RDI: 000000000000006c
    RBP: 0000000000000293 R08: 0000000000000001 R09: 0000000000000000
    R10: ffffffff8940fe57 R11: 0000000000000000 R12: 1ffff110208a1f10
    R13: 0000000000000068 R14: 0000000000000001 R15: ffff88810450fbee
    FS:  0000000000000000(0000) GS:ffff8881fd885000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00000000006d2890 CR3: 0000000106cbf002 CR4: 0000000000770ef0
    PKRU: 55555554
    Kernel panic - not syncing: Fatal exception
    Kernel Offset: disabled
    Rebooting in 1 seconds..

Assisted-by: LLM
Signed-off-by: Cen Zhang &lt;zzzccc427@gmail.com&gt;
Link: https://patch.msgid.link/pm-pmb-3634251be738461947da-v2-64371e8c8d6cbf6956a3@gmail.com
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: oss: Prevent duplicate MIDI device teardown</title>
<updated>2026-10-14T06:55:18+00:00</updated>
<author>
<name>Cen Zhang</name>
<email>zzzccc427@gmail.com</email>
</author>
<published>2026-10-14T04:06:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=ab669ac2bc418a3ef1a1541ea6e1ef5dc8c87a3f'/>
<id>ab669ac2bc418a3ef1a1541ea6e1ef5dc8c87a3f</id>
<content type='text'>
Each OSS MIDI alias and its coder must have one final-release owner.
find_slot() pins the alias under register_lock, but
snd_seq_oss_midi_check_exit_port() clears its slot in a separate critical
section without checking whether another callback already removed it.
The use counter protects active users, but draining it does not elect a
single remover.

This requires overlapping raw kernel-client port controls for the same
client. snd_seq_kernel_client_ctl() does not take ioctl_mutex, and
snd_seq_delete_port() releases ports_mutex before returning to the
DELETE_PORT handler's PORT_EXIT broadcast. If the old deletion is delayed
before that broadcast, a new port can reuse the vacant address. Its
PORT_START finds and keeps the old alias. Deleting the replacement then
produces a second PORT_EXIT for the same address. Non-atomic subscriber
delivery holds a read rwsem, so the two receive_announce() callbacks can
run concurrently:

  Old-port deletion                 Replacement-port controls
  -----------------                 -------------------------
  Unlink and drain old port
  Delay before PORT_EXIT            Create port at the same address
                                    PORT_START keeps existing alias
                                    Delete port; PORT_EXIT pins mdev
  PORT_EXIT pins the same mdev
  Clear slot; drop pin              Clear slot; drop pin
  Wait for users to drain           Wait for users to drain
                                    Free coder; pause before kfree(mdev)
  Free coder again: read
  freed coder-&gt;buf

Both callbacks can select the same alias before either clears its slot.
After both drop their pins, both waits can return. The second call to
snd_midi_event_free() can then read the freed coder's buffer pointer,
as in the report below, and attempt to release the same objects twice.

Check that the pinned alias still occupies its slot under register_lock
before clearing it. A callback that finds it already removed drops its
pin and returns. Only the callback that removes the alias drains users
and frees the coder and record. The pin keeps the record alive through
this check, and the wait remains outside the spinlock.

KASAN report as below:

    ==================================================================
    BUG: KASAN: slab-use-after-free in snd_midi_event_free+0x53/0x60
    Read of size 8 at addr ffff888107074518 by task alsa-seq-fixtur/492

    CPU: 3 UID: 0 PID: 492 Comm: alsa-seq-fixtur 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:
     &lt;TASK&gt;
     dump_stack_lvl+0x93/0xd0
     print_report+0xce/0x630
     ? snd_midi_event_free+0x53/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __virt_addr_valid+0x20d/0x410
     ? snd_midi_event_free+0x53/0x60
     kasan_report+0xe0/0x110
     ? snd_midi_event_free+0x53/0x60
     snd_midi_event_free+0x53/0x60
     snd_seq_oss_midi_check_exit_port+0x1d8/0x370
     receive_announce+0x1b8/0x370
     ? __pfx_receive_announce+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __lock_acquire+0x466/0x2260
     ? snd_seq_port_use_ptr+0x40/0x170
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? find_held_lock+0x2b/0x80
     ? snd_seq_port_use_ptr+0x10c/0x170
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_release+0xc8/0x280
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_receive_announce+0x10/0x10
     __snd_seq_deliver_single_event+0x105/0x1a0
     ? snd_seq_port_use_ptr+0x111/0x170
     snd_seq_deliver_single_event+0x2fc/0x770
     ? __pfx_snd_seq_deliver_single_event+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_down_read_nested+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? do_raw_read_unlock+0x49/0xe0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? _raw_read_unlock+0x23/0x40
     snd_seq_deliver_event+0x351/0x760
     ? __pfx_snd_seq_deliver_event+0x10/0x10
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? trace_hardirqs_on+0x18/0x160
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     snd_seq_kernel_client_dispatch+0x13f/0x170
     snd_seq_system_broadcast+0x100/0x150
     ? __pfx_snd_seq_system_broadcast+0x10/0x10
     ? mark_held_locks+0x40/0x70
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lockdep_hardirqs_on_prepare+0xea/0x1a0
     ? srso_alias_return_thunk+0x5/0xfbef5
     snd_seq_ioctl_delete_port+0x179/0x4b0
     call_seq_client_ctl+0x90/0x110
     snd_seq_kernel_client_ctl+0x8a/0x100
     pmbd_case_delete_port+0xa6/0xf0
     ? __pfx_pmbd_case_delete_port+0x10/0x10
     ? __might_fault+0xdd/0x190
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __might_fault+0x14e/0x190
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? strim+0x19c/0x200
     pmbd_case_control_write+0x2c5/0x470
     ? __pfx_pmbd_case_control_write+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __debugfs_file_get+0x1bd/0x7f0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_acquire+0x17b/0x2f0
     ? ksys_write+0x111/0x200
     full_proxy_write+0x11f/0x180
     vfs_write+0x25a/0x1010
     ? __pfx_full_proxy_write+0x10/0x10
     ? __pfx___mutex_lock+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_acquire+0x17b/0x2f0
     ? __pfx_vfs_write+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __fget_files+0x1e1/0x370
     ksys_write+0x111/0x200
     ? __pfx_ksys_write+0x10/0x10
     ? rseq_register.isra.0+0x1f3/0x2e0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? exit_to_user_mode_loop+0x3a5/0x570
     ? srso_alias_return_thunk+0x5/0xfbef5
     do_syscall_64+0x115/0x6a0
     entry_SYSCALL_64_after_hwframe+0x77/0x7f
    RIP: 0033:0x7f3532e4e9ee
    Code: 08 0f 85 f5 4b ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 &lt;c3&gt; 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 80 00 00 00 00 48 83 ec 08
    RSP: 002b:00007f3532dafe08 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
    RAX: ffffffffffffffda RBX: 00007f3532db06c0 RCX: 00007f3532e4e9ee
    RDX: 000000000000000a RSI: 000055efbd747156 RDI: 0000000000000003
    RBP: 000055efbd747156 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000a
    R13: 0000000000000000 R14: 00007ffe7894e7f0 R15: 00007f35325b0000
     &lt;/TASK&gt;

    Allocated by task 490:
     kasan_save_stack+0x33/0x60
     kasan_save_track+0x14/0x30
     __kasan_kmalloc+0xaa/0xb0
     __kmalloc_cache_noprof+0x251/0x610
     snd_midi_event_new+0x74/0x210
     snd_seq_oss_midi_check_new_port+0x329/0x610
     receive_announce+0x277/0x370
     __snd_seq_deliver_single_event+0x105/0x1a0
     snd_seq_deliver_single_event+0x2fc/0x770
     snd_seq_deliver_event+0x351/0x760
     snd_seq_kernel_client_dispatch+0x13f/0x170
     snd_seq_system_broadcast+0x100/0x150
     snd_seq_ioctl_create_port+0x39a/0x9d0
     call_seq_client_ctl+0x90/0x110
     snd_seq_kernel_client_ctl+0x8a/0x100
     pmbd_case_create_port+0xcc/0x160
     pmbd_case_control_write+0x21d/0x470
     full_proxy_write+0x11f/0x180
     vfs_write+0x25a/0x1010
     ksys_write+0x111/0x200
     do_syscall_64+0x115/0x6a0
     entry_SYSCALL_64_after_hwframe+0x77/0x7f

    Freed by task 493:
     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_midi_event_free+0x48/0x60
     snd_seq_oss_midi_check_exit_port+0x1d8/0x370
     receive_announce+0x1b8/0x370
     __snd_seq_deliver_single_event+0x105/0x1a0
     snd_seq_deliver_single_event+0x2fc/0x770
     snd_seq_deliver_event+0x351/0x760
     snd_seq_kernel_client_dispatch+0x13f/0x170
     snd_seq_system_broadcast+0x100/0x150
     snd_seq_ioctl_delete_port+0x179/0x4b0
     call_seq_client_ctl+0x90/0x110
     snd_seq_kernel_client_ctl+0x8a/0x100
     pmbd_case_delete_port+0xa6/0xf0
     pmbd_case_control_write+0x398/0x470
     full_proxy_write+0x11f/0x180
     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 ffff888107074500
     which belongs to the cache kmalloc-96 of size 96
    The buggy address is located 24 bytes inside of
     freed 96-byte region [ffff888107074500, ffff888107074560)

    The buggy address belongs to the physical page:
    page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x107074
    flags: 0x200000000000000(node=0|zone=2)
    page_type: f5(slab)
    raw: 0200000000000000 ffff888100042280 dead000000000122 0000000000000000
    raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
    page dumped because: kasan: bad access detected

    Memory state around the buggy address:
     ffff888107074400: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
     ffff888107074480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    &gt;ffff888107074500: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
                                ^
     ffff888107074580: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
     ffff888107074600: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
    ==================================================================

Assisted-by: LLM
Signed-off-by: Cen Zhang &lt;zzzccc427@gmail.com&gt;
Link: https://patch.msgid.link/pm-pmb-7c5128efe2110a87b872-v2-c718183fd693e73d8e95@gmail.com
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Each OSS MIDI alias and its coder must have one final-release owner.
find_slot() pins the alias under register_lock, but
snd_seq_oss_midi_check_exit_port() clears its slot in a separate critical
section without checking whether another callback already removed it.
The use counter protects active users, but draining it does not elect a
single remover.

This requires overlapping raw kernel-client port controls for the same
client. snd_seq_kernel_client_ctl() does not take ioctl_mutex, and
snd_seq_delete_port() releases ports_mutex before returning to the
DELETE_PORT handler's PORT_EXIT broadcast. If the old deletion is delayed
before that broadcast, a new port can reuse the vacant address. Its
PORT_START finds and keeps the old alias. Deleting the replacement then
produces a second PORT_EXIT for the same address. Non-atomic subscriber
delivery holds a read rwsem, so the two receive_announce() callbacks can
run concurrently:

  Old-port deletion                 Replacement-port controls
  -----------------                 -------------------------
  Unlink and drain old port
  Delay before PORT_EXIT            Create port at the same address
                                    PORT_START keeps existing alias
                                    Delete port; PORT_EXIT pins mdev
  PORT_EXIT pins the same mdev
  Clear slot; drop pin              Clear slot; drop pin
  Wait for users to drain           Wait for users to drain
                                    Free coder; pause before kfree(mdev)
  Free coder again: read
  freed coder-&gt;buf

Both callbacks can select the same alias before either clears its slot.
After both drop their pins, both waits can return. The second call to
snd_midi_event_free() can then read the freed coder's buffer pointer,
as in the report below, and attempt to release the same objects twice.

Check that the pinned alias still occupies its slot under register_lock
before clearing it. A callback that finds it already removed drops its
pin and returns. Only the callback that removes the alias drains users
and frees the coder and record. The pin keeps the record alive through
this check, and the wait remains outside the spinlock.

KASAN report as below:

    ==================================================================
    BUG: KASAN: slab-use-after-free in snd_midi_event_free+0x53/0x60
    Read of size 8 at addr ffff888107074518 by task alsa-seq-fixtur/492

    CPU: 3 UID: 0 PID: 492 Comm: alsa-seq-fixtur 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:
     &lt;TASK&gt;
     dump_stack_lvl+0x93/0xd0
     print_report+0xce/0x630
     ? snd_midi_event_free+0x53/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __virt_addr_valid+0x20d/0x410
     ? snd_midi_event_free+0x53/0x60
     kasan_report+0xe0/0x110
     ? snd_midi_event_free+0x53/0x60
     snd_midi_event_free+0x53/0x60
     snd_seq_oss_midi_check_exit_port+0x1d8/0x370
     receive_announce+0x1b8/0x370
     ? __pfx_receive_announce+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __lock_acquire+0x466/0x2260
     ? snd_seq_port_use_ptr+0x40/0x170
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? find_held_lock+0x2b/0x80
     ? snd_seq_port_use_ptr+0x10c/0x170
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_release+0xc8/0x280
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_receive_announce+0x10/0x10
     __snd_seq_deliver_single_event+0x105/0x1a0
     ? snd_seq_port_use_ptr+0x111/0x170
     snd_seq_deliver_single_event+0x2fc/0x770
     ? __pfx_snd_seq_deliver_single_event+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __pfx_down_read_nested+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? do_raw_read_unlock+0x49/0xe0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? _raw_read_unlock+0x23/0x40
     snd_seq_deliver_event+0x351/0x760
     ? __pfx_snd_seq_deliver_event+0x10/0x10
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? trace_hardirqs_on+0x18/0x160
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     snd_seq_kernel_client_dispatch+0x13f/0x170
     snd_seq_system_broadcast+0x100/0x150
     ? __pfx_snd_seq_system_broadcast+0x10/0x10
     ? mark_held_locks+0x40/0x70
     ? _raw_spin_unlock_irqrestore+0x44/0x60
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lockdep_hardirqs_on_prepare+0xea/0x1a0
     ? srso_alias_return_thunk+0x5/0xfbef5
     snd_seq_ioctl_delete_port+0x179/0x4b0
     call_seq_client_ctl+0x90/0x110
     snd_seq_kernel_client_ctl+0x8a/0x100
     pmbd_case_delete_port+0xa6/0xf0
     ? __pfx_pmbd_case_delete_port+0x10/0x10
     ? __might_fault+0xdd/0x190
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __might_fault+0x14e/0x190
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? strim+0x19c/0x200
     pmbd_case_control_write+0x2c5/0x470
     ? __pfx_pmbd_case_control_write+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __debugfs_file_get+0x1bd/0x7f0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_acquire+0x17b/0x2f0
     ? ksys_write+0x111/0x200
     full_proxy_write+0x11f/0x180
     vfs_write+0x25a/0x1010
     ? __pfx_full_proxy_write+0x10/0x10
     ? __pfx___mutex_lock+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? lock_acquire+0x17b/0x2f0
     ? __pfx_vfs_write+0x10/0x10
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? __fget_files+0x1e1/0x370
     ksys_write+0x111/0x200
     ? __pfx_ksys_write+0x10/0x10
     ? rseq_register.isra.0+0x1f3/0x2e0
     ? srso_alias_return_thunk+0x5/0xfbef5
     ? exit_to_user_mode_loop+0x3a5/0x570
     ? srso_alias_return_thunk+0x5/0xfbef5
     do_syscall_64+0x115/0x6a0
     entry_SYSCALL_64_after_hwframe+0x77/0x7f
    RIP: 0033:0x7f3532e4e9ee
    Code: 08 0f 85 f5 4b ff ff 49 89 fb 48 89 f0 48 89 d7 48 89 ce 4c 89 c2 4d 89 ca 4c 8b 44 24 08 4c 8b 4c 24 10 4c 89 5c 24 08 0f 05 &lt;c3&gt; 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 80 00 00 00 00 48 83 ec 08
    RSP: 002b:00007f3532dafe08 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
    RAX: ffffffffffffffda RBX: 00007f3532db06c0 RCX: 00007f3532e4e9ee
    RDX: 000000000000000a RSI: 000055efbd747156 RDI: 0000000000000003
    RBP: 000055efbd747156 R08: 0000000000000000 R09: 0000000000000000
    R10: 0000000000000000 R11: 0000000000000246 R12: 000000000000000a
    R13: 0000000000000000 R14: 00007ffe7894e7f0 R15: 00007f35325b0000
     &lt;/TASK&gt;

    Allocated by task 490:
     kasan_save_stack+0x33/0x60
     kasan_save_track+0x14/0x30
     __kasan_kmalloc+0xaa/0xb0
     __kmalloc_cache_noprof+0x251/0x610
     snd_midi_event_new+0x74/0x210
     snd_seq_oss_midi_check_new_port+0x329/0x610
     receive_announce+0x277/0x370
     __snd_seq_deliver_single_event+0x105/0x1a0
     snd_seq_deliver_single_event+0x2fc/0x770
     snd_seq_deliver_event+0x351/0x760
     snd_seq_kernel_client_dispatch+0x13f/0x170
     snd_seq_system_broadcast+0x100/0x150
     snd_seq_ioctl_create_port+0x39a/0x9d0
     call_seq_client_ctl+0x90/0x110
     snd_seq_kernel_client_ctl+0x8a/0x100
     pmbd_case_create_port+0xcc/0x160
     pmbd_case_control_write+0x21d/0x470
     full_proxy_write+0x11f/0x180
     vfs_write+0x25a/0x1010
     ksys_write+0x111/0x200
     do_syscall_64+0x115/0x6a0
     entry_SYSCALL_64_after_hwframe+0x77/0x7f

    Freed by task 493:
     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_midi_event_free+0x48/0x60
     snd_seq_oss_midi_check_exit_port+0x1d8/0x370
     receive_announce+0x1b8/0x370
     __snd_seq_deliver_single_event+0x105/0x1a0
     snd_seq_deliver_single_event+0x2fc/0x770
     snd_seq_deliver_event+0x351/0x760
     snd_seq_kernel_client_dispatch+0x13f/0x170
     snd_seq_system_broadcast+0x100/0x150
     snd_seq_ioctl_delete_port+0x179/0x4b0
     call_seq_client_ctl+0x90/0x110
     snd_seq_kernel_client_ctl+0x8a/0x100
     pmbd_case_delete_port+0xa6/0xf0
     pmbd_case_control_write+0x398/0x470
     full_proxy_write+0x11f/0x180
     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 ffff888107074500
     which belongs to the cache kmalloc-96 of size 96
    The buggy address is located 24 bytes inside of
     freed 96-byte region [ffff888107074500, ffff888107074560)

    The buggy address belongs to the physical page:
    page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x107074
    flags: 0x200000000000000(node=0|zone=2)
    page_type: f5(slab)
    raw: 0200000000000000 ffff888100042280 dead000000000122 0000000000000000
    raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
    page dumped because: kasan: bad access detected

    Memory state around the buggy address:
     ffff888107074400: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
     ffff888107074480: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
    &gt;ffff888107074500: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
                                ^
     ffff888107074580: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
     ffff888107074600: fa fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc
    ==================================================================

Assisted-by: LLM
Signed-off-by: Cen Zhang &lt;zzzccc427@gmail.com&gt;
Link: https://patch.msgid.link/pm-pmb-7c5128efe2110a87b872-v2-c718183fd693e73d8e95@gmail.com
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: Wait for one RCU grace period when deleting all ports</title>
<updated>2026-10-11T08:48:26+00:00</updated>
<author>
<name>Ali Ahmet Memiş</name>
<email>aliamemis@disroot.org</email>
</author>
<published>2026-10-10T22:25:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7ca1731b8a129cafe258c578fa87b7c414c6d004'/>
<id>7ca1731b8a129cafe258c578fa87b7c414c6d004</id>
<content type='text'>
Since the port list was converted to RCU, snd_seq_delete_all_ports()
calls synchronize_rcu() once per port under register_mutex. Closing a
client with 254 ports now takes about 1.6s and every other client
open or close waits for it.

Unlink all ports first, wait for a single grace period and then free
them.

Fixes: 4c252fbc06d6 ("ALSA: seq: Use RCU for the client port list")
Signed-off-by: Ali Ahmet Memiş &lt;aliamemis@disroot.org&gt;
Link: https://patch.msgid.link/20261010222543.1470723-1-aliamemis@disroot.org
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Since the port list was converted to RCU, snd_seq_delete_all_ports()
calls synchronize_rcu() once per port under register_mutex. Closing a
client with 254 ports now takes about 1.6s and every other client
open or close waits for it.

Unlink all ports first, wait for a single grace period and then free
them.

Fixes: 4c252fbc06d6 ("ALSA: seq: Use RCU for the client port list")
Signed-off-by: Ali Ahmet Memiş &lt;aliamemis@disroot.org&gt;
Link: https://patch.msgid.link/20261010222543.1470723-1-aliamemis@disroot.org
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: Don't lose partial read failure</title>
<updated>2026-10-08T06:47:47+00:00</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2026-10-07T17:25:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7e1f297fcef8fc3376774ed40e5f2b5ad9098e43'/>
<id>7e1f297fcef8fc3376774ed40e5f2b5ad9098e43</id>
<content type='text'>
snd_seq_read() returns an error even if one or more events have been
successfully read before the error (except for -EAGAIN case), but this
rather doesn't follow the POSIX standard that wants the processed
bytes.  Change the behavior to return the processed bytes when it's
positive, instead.

Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20261007172533.14667-8-tiwai@suse.de
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
snd_seq_read() returns an error even if one or more events have been
successfully read before the error (except for -EAGAIN case), but this
rather doesn't follow the POSIX standard that wants the processed
bytes.  Change the behavior to return the processed bytes when it's
positive, instead.

Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20261007172533.14667-8-tiwai@suse.de
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: Fix missing direction and ump_group handling in 32bit compat ioctl</title>
<updated>2026-10-08T06:47:47+00:00</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2026-10-07T17:25:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9d3e19c192b97b4c4c0abcafdbf1edb1e56cee88'/>
<id>9d3e19c192b97b4c4c0abcafdbf1edb1e56cee88</id>
<content type='text'>
I forgot to cover the two new fields, direction and ump_group, in
struct snd_seq_port_info for the 32bit compat ioctls of
SNDRV_SEQ_IOCTL_GET_PORT_INFO &amp; co, which ended up with the garbage
copies in those fields.  Add the handling of those two fields in the
compat layer.

Also, avoid over-copying the 64bit snd_seq_port_info but only the first
part (before the field kernel); this avoids the copy of kernel-space
garbage value in the reserved field.

Fixes: ff166a9d19fa ("ALSA: seq: Add port direction to snd_seq_port_info")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20261007172533.14667-2-tiwai@suse.de
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
I forgot to cover the two new fields, direction and ump_group, in
struct snd_seq_port_info for the 32bit compat ioctls of
SNDRV_SEQ_IOCTL_GET_PORT_INFO &amp; co, which ended up with the garbage
copies in those fields.  Add the handling of those two fields in the
compat layer.

Also, avoid over-copying the 64bit snd_seq_port_info but only the first
part (before the field kernel); this avoids the copy of kernel-space
garbage value in the reserved field.

Fixes: ff166a9d19fa ("ALSA: seq: Add port direction to snd_seq_port_info")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20261007172533.14667-2-tiwai@suse.de
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: Drop the bogus RCU guard from clientptr()</title>
<updated>2026-10-08T06:47:06+00:00</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2026-10-07T17:20:37+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=8bd561f8a6051f4e287dd0d076f17a1af5bff009'/>
<id>8bd561f8a6051f4e287dd0d076f17a1af5bff009</id>
<content type='text'>
In the recent refactoring with RCU, clientptr() takes guard(rcu)()
around the client table lookup, but the RCU read-side section ends as
soon as the function returns, so the returned pointer isn't protected
at all.  This gives a false impression as if that the callers were
safe, and confuse reviewers including Sashiko.

Actually, the callers (snd_seq_delete_kernel_client(),
snd_seq_kernel_client_ctl() and snd_seq_kernel_client_write_poll())
never relied on any lock; the caller is the owner of the client (a
kernel client passing its own id, or a user client via its opened
file), hence the client can't be released concurrently by others.

So just drop the confusing and useless RCU guard, read the table via
rcu_dereference_protected(), and document the lifetime rule.  Along
with it, fold __clientptr() into its only user client_use_ptr(); the
id range is already checked there, and it's never called with
clients_lock held, so a plain rcu_dereference() suffices.

Fixes: 7a287e4615d6 ("ALSA: seq: Use RCU for the client table")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20261007172051.13240-2-tiwai@suse.de
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
In the recent refactoring with RCU, clientptr() takes guard(rcu)()
around the client table lookup, but the RCU read-side section ends as
soon as the function returns, so the returned pointer isn't protected
at all.  This gives a false impression as if that the callers were
safe, and confuse reviewers including Sashiko.

Actually, the callers (snd_seq_delete_kernel_client(),
snd_seq_kernel_client_ctl() and snd_seq_kernel_client_write_poll())
never relied on any lock; the caller is the owner of the client (a
kernel client passing its own id, or a user client via its opened
file), hence the client can't be released concurrently by others.

So just drop the confusing and useless RCU guard, read the table via
rcu_dereference_protected(), and document the lifetime rule.  Along
with it, fold __clientptr() into its only user client_use_ptr(); the
id range is already checked there, and it's never called with
clients_lock held, so a plain rcu_dereference() suffices.

Fixes: 7a287e4615d6 ("ALSA: seq: Use RCU for the client table")
Reported-by: Sashiko &lt;sashiko-bot@kernel.org&gt;
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20261007172051.13240-2-tiwai@suse.de
</pre>
</div>
</content>
</entry>
<entry>
<title>Merge branch 'for-linus' into for-next</title>
<updated>2026-09-28T12:44:10+00:00</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2026-09-28T12:44:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=767b90004dd2952bcefb2570a494e253b9a3da69'/>
<id>767b90004dd2952bcefb2570a494e253b9a3da69</id>
<content type='text'>
Pull 7.3 devel branch for applying the further HD-audio quirks more
cleanly.

Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Pull 7.3 devel branch for applying the further HD-audio quirks more
cleanly.

Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>ALSA: seq: Mark OSS sequencer emulation as deprecated</title>
<updated>2026-09-28T10:55:29+00:00</updated>
<author>
<name>Takashi Iwai</name>
<email>tiwai@suse.de</email>
</author>
<published>2026-09-12T12:49:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=a5af82f2077dd1af7cfebd718eb5c77902f032c4'/>
<id>a5af82f2077dd1af7cfebd718eb5c77902f032c4</id>
<content type='text'>
OSS sequencer API emulation has been implemented as a client of ALSA
sequencer, decades ago, at the time where OSS was still use.  But the
API itself became very niche, and almost noone using it for a real
purpose any longer -- only exceptions are AI and fuzzers, who have
been causing significant maintenance burden for issues they hit &amp;
found.

Meanwhile, the most features of OSS sequencer API emulation can be
achieved in user-space, either by ALSA-OSS layer (aoss) or oss-seq-emu
program:
  https://github.com/alsa-project/alsa-oss
  https://github.com/tiwai/oss-seq-emu
where the former is LD_PRELOAD wrapper and the latter is a CUSE-based
daemon.  So we can drop the stuff from the kernel sooner or later.

Now, let's mark the OSS sequencer emulation as deprecated and give a
warning when loaded, so that we can drop it later actually.

Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20260912124951.416761-1-tiwai@suse.de
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
OSS sequencer API emulation has been implemented as a client of ALSA
sequencer, decades ago, at the time where OSS was still use.  But the
API itself became very niche, and almost noone using it for a real
purpose any longer -- only exceptions are AI and fuzzers, who have
been causing significant maintenance burden for issues they hit &amp;
found.

Meanwhile, the most features of OSS sequencer API emulation can be
achieved in user-space, either by ALSA-OSS layer (aoss) or oss-seq-emu
program:
  https://github.com/alsa-project/alsa-oss
  https://github.com/tiwai/oss-seq-emu
where the former is LD_PRELOAD wrapper and the latter is a CUSE-based
daemon.  So we can drop the stuff from the kernel sooner or later.

Now, let's mark the OSS sequencer emulation as deprecated and give a
warning when loaded, so that we can drop it later actually.

Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
Link: https://patch.msgid.link/20260912124951.416761-1-tiwai@suse.de
Signed-off-by: Takashi Iwai &lt;tiwai@suse.de&gt;
</pre>
</div>
</content>
</entry>
</feed>
