From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796181945; b=NaJQMHL7pKN8/5YsEWNasvKpsUJQ9Qa/CUoiAyxqgMagVbc35Piou5RrSFz+gdi8B1t2 cnX5Dgu/eZ1VJeyX+48DwoRRsIxVOpKLBR3/FqOq/dMUvUrlxeAwQ3Q1I8miF2iCQQHEO +X7kGuT/XpXuGfx6EgeqohzySenDl9b8vwlb7MvZArB/lgLA17R4N4TI4Saq2BI837fCY 47ZshW6gqNLmWIn8xq7JeQnXt/AO7VjBdsJyuryvrJ1uD2dDa7x4gX9W/f7iV5/PIiL1q oikXUXV+p1RdaBtxIWtr1DboyXKVMqfIvsSCoQ4gy9rYXgjlf5YYZ+9eKWgX8hEoNTQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181945; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Fhd2NcnbvjdLLnklxvzIQuv+UgOj+N4+U20g1Z5SmjE=; b=mYNf/nGZFV2IG34/2gBbKvhAELmaHEfAK4s4/iGCBWhTLrizUpv/OrHoZYlPf4uqRTaV 7r1PT/m6IGds9R0eeZISNHIBeYPNyd6OpDDw65ThlfEwB8Yt5JHN59ufQPAXZyoOwAc3r om+Wp73fRjo7ok1PLLqbH/w6EkQoQwYjyqJAsqX/pivbn2fuNbvxE+GSR25JaxD49fIhq uPFyFGEwrgMw3OvOdaZdDQeLfkqo5TfgZhFgM1QgQ3L/wKiyb4YSX9m8APn7h6H48UdgZ iRE06JdRIrtwMOqJ1UeazgwoRCnRMxFM/HXKEpX0ovOWiXnG0I4hYi71BpwNhOJbvBQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AcC4bI9b; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE1F8606A31A for ; Wed, 2 Dec 2026 03:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AcC4bI9b Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CE641F00893; Wed, 2 Dec 2026 03:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181945; bh=Fhd2NcnbvjdLLnklxvzIQuv+UgOj+N4+U20g1Z5SmjE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=AcC4bI9bzDNmOUoXb+nj3A61eGq1rWq6gLT3FQD0xEqfhu1pY0a7QYH/eFw8maN/Z FLBRr/T0lqYSIoqoJRq+JP3pmlW41wZDQAHMeH9iPA4XUhVQhp6lIrGrK2/rcl8MHv l+fdDamA7toHkKhQPoKpGFopqlJCLikIIVuu+j56quXZItJHZjEXurx3V8pL2N1Yee Fyml32bx9XZ2DZ13/pDE+dlDuy40gUSD/+EEbIOzACfdyQLfwWLGThaqFXXQ2oNu1C /NME5bBYVl9J5yt0gW2XWh/tX9iu6o9bMJAbMQngLB3K85pl+TjKNya1n7lSfEnUwJ lELHeM39n+lGQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: sb: wait for the period timer before freeing the pcm private data Reply-To: sashiko-reviews@lists.linux.dev To: "Hanxiang Xu" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202101107.1-1-xuhx@hust.edu.cn> References: <20261202101107.1-1-xuhx@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:25:45 +0000 X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] ALSA: sb: incomplete timer sync and re-arm race in emu8k_pcm_timer_func() -- commit 16e83ea6e63d3c55432a440185c92457f6a2eb84 Author: Hanxiang Xu ALSA: sb: wait for the period timer before freeing the pcm private data This commit adds a timer_shutdown_sync() call in emu8k_pcm_close() before freeing the struct snd_emu8k_pcm instance. > diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c > index d2ca70aad1621..3aeef313665e8 100644 > --- a/sound/isa/sb/emu8000_pcm.c > +++ b/sound/isa/sb/emu8000_pcm.c > @@ -246,6 +246,7 @@ static int emu8k_pcm_open(struct snd_pcm_substream *s= ubs) > static int emu8k_pcm_close(struct snd_pcm_substream *subs) > { > struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; > + timer_shutdown_sync(&rec->timer); > kfree(rec); > subs->runtime->private_data =3D NULL; > return 0; [Severity: High] Does synchronizing the timer only in emu8k_pcm_close() leave emu8k_pcm_timer_func() racing with stop_voice(), emu8k_pcm_hw_free() and driver removal? emu8k_pcm_timer_func() unconditionally calls mod_timer() under rec->timer_lock without checking rec->timer_running: CPU0 CPU1 emu8k_pcm_trigger(STOP) emu8k_pcm_timer_func() stop_voice() spin_lock(&rec->timer_lock) spin_lock_irqsave(&rec->timer_lock) (waits for lock) timer_delete(&rec->timer) rec->timer_running =3D 0 spin_unlock_irqrestore(...) mod_timer(&rec->timer, ...) spin_unlock(&rec->timer_lock) snd_pcm_period_elapsed(...) emu8k_pcm_hw_free() stop_voice() if (rec->timer_running) <-- false! emu8k_close_dram(rec->emu) snd_util_mem_free(..., rec->block) Once rec->timer is re-armed with rec->timer_running set to 0, later stop_voice() calls skip timer_delete(&rec->timer). The 1-jiffy timer keeps firing and polling EMU8000_CCCA_READ while the stream is stopped, and runs concurrently with emu8k_pcm_hw_free() (which runs before emu8k_pcm_close() even during snd_pcm_release_substream()) and emu8k_pcm_prepare(). In addition, if the driver is removed while userspace holds an open PCM file descriptor, snd_emu8000_remove() -> snd_device_free() runs snd_pcm_dev_disconnect() (which calls snd_pcm_stop() and snd_pcm_sync_stop(), not emu8k_pcm_close()) and then frees the substream in snd_pcm_free_stream(), so an in-flight or self-rearmed emu8k_pcm_timer_func() still hits a use-after-free on rec->substream. Checking rec->timer_running before mod_timer() in emu8k_pcm_timer_func() and wiring up a .sync_stop callback in emu8k_pcm_ops that calls timer_delete_sync(&rec->timer) would cover non-closing stops, hw_free, and device disconnect as well. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202101107.1-1-= xuhx@hust.edu.cn?part=3D1