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=1796180274; b=TQYO7+kT5hdWv602dylLZL7u6Vuq1A9MXrp1nW8Ua6aov56npZs7ZVLc0cAn41sX1PJJ tQmj7RxE/MOmHhs2c0kLLDcQIc4HgdNb73EI7eEcSLy9uD44Das7RKMt/l9x//DLQdrqX 2x6nUn89SVqN/s8Xv0NTnHgNrkBv2udLZxYQidHxk3hODdEZZe6bgVMP80pHiMGcmUV+I 58WH/R3+UkDXGuV+vs27mMHWt5U67HqD5cS5l+XBAb5+CrxKhs2ZTRC+dM1wCcWnJTaqC w7PxdVyHkS3qis0iU6vSymBzs60CuyV3Ky3jqEy3K3Exg3DpOliHFXl98QSaECJKUBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796180274; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=HL357zlyTDq7grHIV8fGzSx906Z/5UU2dIDw9bi2xQ4=; b=GpJklnhnYiHCFLpyxBGqTtVtLyCqIzo1EEMesheTd8RPfJSozSWOX5j4vS0XFAOE1c11 fN6s0zfC23yoriDH0vlyqu0aeRSxv+g0NUvLBGvij0+UyFnCAZl/7ExgpIAY1DV0cASM1 BZC/2SHCL5jfDzobXox2N+J1cNCHjjCG4RsTY1q8ecFWtTVA0sJ7kxMXAK23eAHok8xsK k5sQfDRp1FEZjdTuellQxwMHBeGrkydo4yVHVztfyb+EYN8rFVsH+zLC3xEavU116SsVP dbseRgvLMfARpKUaUOiSnaPODAQYJwVrw9hDYiSW9aDkVjqmS743mrfUTvbhR4zzsOw== 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=hK5ATJ3P; 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 697EA606A31A for ; Wed, 2 Dec 2026 02:57:54 +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=hK5ATJ3P Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E70B1F000C1; Wed, 2 Dec 2026 02:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796180274; bh=HL357zlyTDq7grHIV8fGzSx906Z/5UU2dIDw9bi2xQ4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=hK5ATJ3PU1T/gZUAfH7LLJzt8Y089MFgYaPG8xcBcomisXN5yxzGZY0xMuib6+Img QvqEgpwkdMkWSr4BUI2brnhY+SjiM17ad86MqHJTUtVQM4cq5Zx/LHjtte+UW5fKeH xIA6A/6tVHWK7lFFm1fv1si0KuXcGHqQlG9rr5jdmf5wRIEndX/6DIEPGghMmM9ehO ADJvCoweEaxAM2ZdN0KF9c7Iu2hxQS6kixPNYw7/NRqQFSPjXfgEra3nDT5hV2Wo2n jftTFtlu8b88dQA3OscL/399W0L2Dz2pP79JtcvsLfVx1JAL4uTG8l+1YEViq5sv6c pS8bT7Tt6tWFQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: emu8000: pin the module while an emu8k PCM runtime exists Reply-To: sashiko-reviews@lists.linux.dev To: "Hanxiang Xu" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202021939.1-1-xuhx@hust.edu.cn> References: <20261202021939.1-1-xuhx@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 02:57:53 +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: emu8000: use-after-free of struct snd_pcm on open, close, and unbind -- commit a5f6e5f5f054a120cdd33733be1293b7529d5132 Author: Hanxiang Xu ALSA: emu8000: pin the module while an emu8k PCM runtime exists This commit pins THIS_MODULE in emu8k_pcm_open() and drops the reference in emu8k_pcm_close() to prevent snd-emu8000-synth from being unloaded while a PCM substream is open. > diff --git a/sound/isa/sb/emu8000_pcm.c b/sound/isa/sb/emu8000_pcm.c > index d2ca70aad1621..22203b072b930 100644 > --- a/sound/isa/sb/emu8000_pcm.c > +++ b/sound/isa/sb/emu8000_pcm.c > @@ -232,6 +232,11 @@ static int emu8k_pcm_open(struct snd_pcm_substream *= subs) > spin_lock_init(&rec->timer_lock); > timer_setup(&rec->timer, emu8k_pcm_timer_func, 0); > =20 > + if (!try_module_get(THIS_MODULE)) { > + kfree(rec); > + return -ENODEV; > + } > + > runtime->hw =3D emu8k_pcm_hw; > runtime->hw.buffer_bytes_max =3D emu->mem_size - LOOP_BLANK_SIZE * 3; > runtime->hw.period_bytes_max =3D runtime->hw.buffer_bytes_max / 2; > @@ -248,6 +253,7 @@ static int emu8k_pcm_close(struct snd_pcm_substream *= subs) > struct snd_emu8k_pcm *rec =3D subs->runtime->private_data; > kfree(rec); > subs->runtime->private_data =3D NULL; > + module_put(THIS_MODULE); > return 0; > } [Severity: High] Can struct snd_pcm still be freed while snd_pcm_release() or snd_pcm_open() is using it? snd_pcm_release() calls substream->ops->close() while holding pcm->open_mutex, and still accesses pcm after releasing that mutex: sound/core/pcm_native.c:snd_pcm_release() { ... scoped_guard(mutex, &pcm->open_mutex) { snd_pcm_release_substream(substream); kfree(pcm_file); } wake_up(&pcm->open_wait); module_put(pcm->card->module); snd_card_file_remove(pcm->card, file); return 0; } Dropping THIS_MODULE inside emu8k_pcm_close() lets a concurrent rmmod free hw->pcm as soon as pcm->open_mutex is unlocked: CPU0 CPU1 snd_pcm_release() mutex_lock(&pcm->open_mutex) snd_pcm_release_substream() emu8k_pcm_close() module_put(THIS_MODULE) delete_module() snd_emu8000_remove() snd_device_free(..., hw->pcm) snd_pcm_dev_disconnect() mutex_lock(&pcm->open_mutex) mutex_unlock(&pcm->open_mutex) mutex_unlock(&pcm->open_mutex) snd_pcm_dev_free() kfree(pcm) wake_up(&pcm->open_wait) <-- use-after-free module_put(pcm->card->module) <-- use-after-free On the open side, snd_pcm_open() looks up pcm and only pins pcm->card->module before acquiring pcm->open_mutex and calling emu8k_pcm_open(). If try_module_get(THIS_MODULE) fails during module unload, snd_pcm_open() unlocks pcm->open_mutex and then dereferences pcm->card after snd_emu8000_remove() has freed pcm. Unbinding the driver via /sys/bus/snd_seq/drivers/snd_emu8000_synth/unbind also runs snd_emu8000_remove() regardless of the module reference count and frees hw->pcm while a file descriptor is open. Disconnecting hw->pcm with snd_device_disconnect(dev->card, hw->pcm) and waiting for open files with snd_card_file_sync(dev->card, hw->pcm) in snd_emu8000_remove() before freeing hw->pcm (as hda_codec_driver_remove() does) would cover open, close and unbind. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202021939.1-1-= xuhx@hust.edu.cn?part=3D1