Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Cen Zhang <zzzccc427@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com
Subject: Re: [PATCH v2 1/2] ALSA: seq: oss: Serialize readq reset state with q->lock
Date: Sun, 14 Jun 2026 10:58:08 +0200	[thread overview]
Message-ID: <87y0ghmrbz.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260614004801.3507773-1-zzzccc427@gmail.com>

On Sun, 14 Jun 2026 02:48:00 +0200,
Cen Zhang wrote:
> 
> snd_seq_oss_readq_clear() resets qlen, head, and tail without
> q->lock even though the normal reader and producer paths serialize the
> same ring state under that spinlock. A reset can therefore race
> snd_seq_oss_readq_free() or snd_seq_oss_readq_put_event() and leave
> stale records in the queue, drop freshly queued ones, or report the
> wrong readiness after wakeup. KCSAN reports a data race between
> snd_seq_oss_readq_clear() and snd_seq_oss_readq_free().
> 
> Take q->lock while clearing the ring and resetting input_time. Factor
> the enqueue logic into a caller-locked helper so
> snd_seq_oss_readq_put_timestamp() updates its suppression state under
> the same lock instead of racing the reset path.
> 
> The buggy scenario involves two paths, with each column showing the
> order within that path:
> 
> reset path:                      locked readq updater:
> 1. snd_seq_oss_reset() or        1. A reader or callback producer
>    release reaches                  takes q->lock on the same queue.
>    snd_seq_oss_readq_clear().
> 2. snd_seq_oss_readq_clear()     2. The updater tests or modifies
>    resets qlen, head, tail,         qlen, head, and tail.
>    and input_time.
> 3. snd_seq_oss_readq_clear()     3. The updater completes its
>    wakes sleepers on                read-modify-write sequence.
>    q->midi_sleep.
> 4. Without q->lock, the reset    4. The resulting ring state drives
>    can overlap the locked           later reads and readiness.
>    update.
> 
> KCSAN reports:
> 
> BUG: KCSAN: data-race in snd_seq_oss_readq_clear /
> snd_seq_oss_readq_free
> 
> write to 0xffff8881069fe608 of 4 bytes by task 120516 on cpu 0:
>   snd_seq_oss_readq_free+0x6c/0x80
>   snd_seq_oss_read+0xcb/0x250
>   odev_read+0x38/0x60
>   vfs_read+0xff/0x600
>   ksys_read+0xb4/0x140
>   __x64_sys_read+0x46/0x60
>   do_syscall_64+0xbb/0x2f0
>   entry_SYSCALL_64_after_hwframe+0x77/0x7f
> 
> read to 0xffff8881069fe608 of 4 bytes by task 120517 on cpu 1:
>   snd_seq_oss_readq_clear+0x1f/0x90
>   snd_seq_oss_reset+0xa7/0xf0
>   snd_seq_oss_ioctl+0x6f6/0x7e0
>   odev_ioctl+0x56/0xc0
>   __x64_sys_ioctl+0xd1/0x120
>   do_syscall_64+0xbb/0x2f0
>   entry_SYSCALL_64_after_hwframe+0x77/0x7f
> 
> value changed: 0x00000001 -> 0x00000000
> 
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
> 
> Signed-off-by: Cen Zhang <zzzccc427@gmail.com>

Applied both patches now to for-next branch.  Thanks.


Takashi

      parent reply	other threads:[~2026-06-14  8:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-14  0:48 [PATCH v2 1/2] ALSA: seq: oss: Serialize readq reset state with q->lock Cen Zhang
2026-06-14  0:48 ` [PATCH v2 2/2] ALSA: seq: avoid stale FIFO cells during resize Cen Zhang
2026-06-14  8:58 ` Takashi Iwai [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y0ghmrbz.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=baijiaju1990@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=zzzccc427@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox