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=1796181381; b=UOfysOFxgY+lX8V88xjG3wpDN5YGtwtNjOfn2+LC18COZN/pdoEMw7jT88v9wIM2z64g 9HJx8kHkFda0JIHDQDmk5WHmgvm1EiG9asrJ/aWmuGJ1fL/NNpStDqS7gyJbOl16V2c1b EdOE81K/SE5Zi24jurq/G/U/IzYftZtfSQ7xermfibDOXpKxHLgFl3kgpLwf6b6gHWlhn d+TMGXn7MkpdXbqdyl2dYX+Q2M/Jt4Op2rQpYLYzxFgUlIyd3fk9++gygVHbT8BqgEAT8 m+w+bCuO5CZNx+XOvtbgNJzmTOSs/DjXYR7KvvSenvlbRIISFWIkj+g/nY5luxCld7A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796181381; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=oeHdwplLN8bHZcZF5HQwSCCSgHEzIV17NPuUDgmi9E8=; b=VdXUrotbXppFw5dkaW251p6QsUhGhmoKaJL+61e38iqIYvMaZ3rD30cQn7eK+yJLTALR ULe3pntIhhPJ6POlTsa6rtNMR1VXJqjdBwE2Nu8twUYfA2AkHeMY8rXeeRYc6WascbNSX hc98NpvskYo3yjACZmeq4fj2Chh9m/OHX1f3gYGbfpBGO5A36SXJWFJwJ0tN9o7MuPOkU ABwNRZSIO/94vc797NJ8AW03wKxAo4IArpUvdJrK8E08E3lBeltdtSU/5SRzkrHAtvoGM WSasu0mQGZ0LwU5LnKbbH3s3lpOAasv4Y5DWJQakQz6GkWHOh2fzKMZmluygdHlGyQg== 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=YRc4pVrF; 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 0F07D606A681 for ; Wed, 2 Dec 2026 03:16:20 +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=YRc4pVrF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84AE31F0092A; Wed, 2 Dec 2026 03:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796181380; bh=oeHdwplLN8bHZcZF5HQwSCCSgHEzIV17NPuUDgmi9E8=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=YRc4pVrFAvR0v/Q7ckM1zy9sRftvz4qvHbeuQOAwNe/g4i/j5CnRkO98wzf4ew9fi vEcsU04vRWJDfsZCt7rzPdENwTcPNmUSuDFusTHY1qeUtfbDjh9moqngBxgY7NJ/u3 IDkpq4EROE0EyagHketoEcQcir02VXm35xIUfO33qs5YuOe32vbFKOrarImk3nTcuB lxo9+zEUgp9YhNkI8FBYNTsd7auwViLWZuPdzMsweHKM8QyjARZM+CFz+l/nS1ub6U +XpoWf3C2TmUqN2wqBEA7Z8+HBdpIsCuQ8zoxcYC0FmojpEM8TlWmPhopof5vNBh2e d7Z/vQdfP5zIw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] ALSA: opl3: serialize patch_table access with opl3->voice_lock Reply-To: sashiko-reviews@lists.linux.dev To: "Hanxiang Xu" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261202100501.1-1-xuhx@hust.edu.cn> References: <20261202100501.1-1-xuhx@hust.edu.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 03:16:19 +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 3 potential issues to consider: - [High] ALSA: opl3: GFP_KERNEL allocation under voice_lock in snd_opl3_load_patch() - [High] ALSA: opl3: uninitialized or reinitialized voice_lock in patch table paths - [Low] ALSA: opl3: missing Fixes trailer for patch_table serialization fix -- commit d1b6b14cc692f61065a86fe44ac2106bb9a023aa Author: Hanxiang Xu > ALSA: opl3: serialize patch_table access with opl3->voice_lock > > The OPL3 patch table is manipulated with no serialization: > snd_opl3_clear_patches() kfrees every struct fm_patch and only clears > the bucket heads afterwards, and snd_opl3_load_patch() inserts into and > fills the same objects via snd_opl3_find_patch(create=3D1), while > snd_opl3_note_on() walks them under opl3->voice_lock. Two > SNDRV_DM_FM_IOCTL_CLEAR_PATCHES ioctls sharing one hwdep fd double-free > the same nodes, and a concurrent write() writes through freed memory > (patch->type/inst/name), leaving the hash chain corrupted for later > lookups. > > Hold opl3->voice_lock across the lookup and the fill in > snd_opl3_load_patch(), and unlink the whole table under the lock in > snd_opl3_clear_patches(), freeing the detached chain after the unlock. > The sequencer reader already holds the same lock, so the three contexts > are now pairwise serialized. > > Cc: > Signed-off-by: Hanxiang Xu [Severity: Low] Should this bug fix include a Fixes tag for the commit that introduced the unlocked patch_table helpers? Fixes: 224a033252bb ("[ALSA] opl3 - Use hwdep for patch loading") > diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_sy= nth.c > index 47a2486be46d5..311c63863d6e3 100644 > --- a/sound/drivers/opl3/opl3_synth.c > +++ b/sound/drivers/opl3/opl3_synth.c > @@ -244,10 +244,14 @@ int snd_opl3_load_patch(struct snd_opl3 *opl3, > { > struct fm_patch *patch; > int i; > + unsigned long flags; > =20 > + spin_lock_irqsave(&opl3->voice_lock, flags); > patch =3D snd_opl3_find_patch(opl3, prog, bank, 1); [Severity: High] Does calling snd_opl3_find_patch(..., 1) under opl3->voice_lock sleep in atomic context when a new (prog, bank) entry is loaded? When create_patch is set and no entry exists, snd_opl3_find_patch() allocates the patch with kzalloc_obj(*patch), which defaults to GFP_KERNEL and can sleep while interrupts are disabled and opl3->voice_lock is held. [ ... ] > @@ -330,14 +335,24 @@ EXPORT_SYMBOL(snd_opl3_find_patch); > void snd_opl3_clear_patches(struct snd_opl3 *opl3) > { > int i; > + struct fm_patch *patch, *next, *free_list =3D NULL; > + unsigned long flags; > + > + spin_lock_irqsave(&opl3->voice_lock, flags); [Severity: High] Is opl3->voice_lock guaranteed to be initialized when snd_opl3_clear_patches() or snd_opl3_load_patch() acquires it? snd_opl3_new() initializes opl3->reg_lock and opl3->timer_lock, while spin_lock_init(&opl3->voice_lock) only runs in snd_opl3_seq_probe() in the separate snd-opl3-synth module: sound/drivers/opl3/opl3_lib.c:snd_opl3_new() { ... spin_lock_init(&opl3->reg_lock); spin_lock_init(&opl3->timer_lock); err =3D snd_device_new(card, SNDRV_DEV_CODEC, opl3, &ops); if (err < 0) { snd_opl3_free(opl3); return err; } ... } If snd_opl3_free() -> snd_opl3_clear_patches() runs on probe failure, on teardown without snd-opl3-synth bound, or if userspace accesses the hwdep device before snd_opl3_seq_probe() runs, spin_lock_irqsave() operates on an uninitialized spinlock_t, and a later snd_opl3_seq_probe() reinitializes the lock while hwdep callers may already be using it. Initializing opl3->voice_lock in snd_opl3_new() instead of snd_opl3_seq_probe() would avoid both issues. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202100501.1-1-= xuhx@hust.edu.cn?part=3D1