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=1796055102; b=KTmwl4qKcXB1avSwZPBR3BHXGk/s5EBJEyeBmQy6RjXP+981vPXvTpPBBK4lnUGNoEU5 +da7+OCSW5oGD3aYuz835uswRDJUQsh0geD9jGpA++ByJgbe2SmAQe0PeD60dp2+oMq75 QED8wVwotT4IW4whemokN3xCTiIXBGxJiY0WjAMJYCIzO8FDKzTbnB8TeMaMyReVAyQxj hXVnxCCPa4vTBKJfLMGzxFv3ab1l5sIFQvFH+gXq2L/SFnvc6qf34T/l8AdHielzZLWe+ Zpb4/H+bbSI9J8kL5a6rbStw+djXg2Pxur/Ut3ajp0zZ7Y18LivRs3wCjNUhwhCgBPA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796055102; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=BLyEZyzoG+jcCrS0BtRXIhBXtj0QW6BI0iWCzHttgSM=; b=PZ6znpWpc6Xf6l2tVveoSThA/UYqb3v3icmxSUW0tc3i7AqCEk1cImNgJ5645PHEz6my oUSb3drJqBR+qU3IQ+1n1ZWSof0+mcifLT68VKTBTnnP2gBaPXLEzJ8Rd/W3fifzvSaml nGYYnWm0VEzkFLky6R/EG36H6RM1vOkuFRRmE0kuDMCu1wNgRgcDykyv3PfTwjh8FJTIB yjl3ay44d/QeViokU8PJyq3DdAaSZXW73eX+W0zTX6mgrEY7RpVOYyEiTc0wToospLXTX 8iaLpVxqMkcs7VQqTzhJSYxlLO7fEfpsbfvMuKV0/bO//e2JHuV7wPJfPHpLuaYIykg== 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="k8zYmql/"; 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 4FB5A606A31C for ; Mon, 30 Nov 2026 16:11:42 +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=k8zYmql/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 996861F000C1; Mon, 30 Nov 2026 16:11:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796055101; bh=BLyEZyzoG+jcCrS0BtRXIhBXtj0QW6BI0iWCzHttgSM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=k8zYmql/8U1EgKRwt9ztqmGqXp9ipkB5VakUIReIxgBDOtxGyRa0I4SJfuGMZFIp8 pacSMVgy/xup/w0Zki7kgZlNF/cEM/LAgApL9vL20U8boDw/GcG/CVF0/KrdW7RVIF a0XrQOJiMgbC3ceRz1RdBPTQbMptQFVNElxecpIDZGMWr1L9rhs0lLGxI7ez0sxBLA M5P1GMUVcMBTSbOFmERAfTiaXV/S/KkEnKUbMBArYQdZzKY12QWFEXGObOt3zyVx+u 2bPsKPwXYEyS2/nMjlKaKjfWA7aUk+Vy2NwKsRRM5s89y7RezTHO4ozrpNoZBWkutF 6Na0FHJq8lIVw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] ALSA: Add driver for SGI RAD1 audio Reply-To: sashiko-reviews@lists.linux.dev To: "Imre Kaloz" Cc: linux-sound@vger.kernel.org In-Reply-To: <20261130154427.17604-1-kaloz@kernel.org> References: <20261130154427.17604-1-kaloz@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 16:11:41 +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: rad1: unlocked ring teardown and unprepared rec handling in snd_rad1_pcm_ack() -- commit 10fddb039778896fba936b5a79d001b4e23fb5ff Author: Imre Kaloz ALSA: Add driver for SGI RAD1 audio This commit adds an ALSA PCI audio driver for the SGI RAD1 controller found in SGI Octane workstations, supporting analog and AES3 I/O. > diff --git a/sound/pci/rad1.c b/sound/pci/rad1.c > new file mode 100644 > index 0000000000000..1521557a64a7f > --- /dev/null > +++ b/sound/pci/rad1.c [ ... ] > +static int snd_rad1_pcm_hw_free(struct snd_pcm_substream *substream) > +{ > + struct snd_rad1_pipe *pipe =3D snd_pcm_substream_chip(substream); > + > + /* .ack may run before the next prepare sets rec up for a new ring */ > + memset(&pipe->rec, 0, sizeof(pipe->rec)); > + if (pipe->ring.area) { > + snd_dma_free_pages(&pipe->ring); > + pipe->ring.area =3D NULL; > + } > + > + return 0; > +} > + > +static int snd_rad1_pcm_hw_params(struct snd_pcm_substream *substream, > + struct snd_pcm_hw_params *params) > +{ > + struct snd_rad1_pipe *pipe =3D snd_pcm_substream_chip(substream); > + > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE) > + return 0; > + > + snd_rad1_pcm_hw_free(substream); > + > + return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, substream->pcm->card->de= v, > + params_buffer_bytes(params), &pipe->ring); > +} > + > +static int snd_rad1_pcm_prepare(struct snd_pcm_substream *substream) > +{ > + struct snd_rad1_pipe *pipe =3D snd_pcm_substream_chip(substream); > + struct snd_rad1 *chip =3D pipe->chip; > + struct snd_pcm_runtime *runtime =3D substream->runtime; > + const struct snd_rad1_pcm_desc *desc =3D pipe->desc; > + dma_addr_t addr =3D runtime->dma_addr; > + u32 ctl; > + > + pipe->buffer_bytes =3D snd_pcm_lib_buffer_bytes(substream); > + pipe->period_bytes =3D snd_pcm_lib_period_bytes(substream); > + pipe->period =3D 0; > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_PLAYBACK) { > + addr =3D pipe->ring.addr; > + memset(pipe->ring.area, 0, pipe->buffer_bytes); > + memset(&pipe->rec, 0, sizeof(pipe->rec)); > + pipe->rec.hw_buffer_size =3D pipe->buffer_bytes; > + pipe->rec.sw_buffer_size =3D pipe->buffer_bytes; > + } [ ... ] > +static void snd_rad1_pcm_resync(struct snd_rad1_pipe *pipe, > + snd_pcm_uframes_t hw_ptr) > +{ > + unsigned int start =3D pipe->rec.hw_io; > + unsigned int bytes =3D max(pipe->rec.hw_ready, 0); > + > + if (start + bytes > pipe->buffer_bytes) { > + memset(pipe->ring.area, 0, start + bytes - pipe->buffer_bytes); > + bytes =3D pipe->buffer_bytes - start; > + } > + memset(pipe->ring.area + start, 0, bytes); > + > + pipe->rec.appl_ptr =3D hw_ptr; > + pipe->rec.hw_data =3D pipe->rec.hw_io; > + pipe->rec.sw_data =3D pipe->rec.sw_io; > + pipe->rec.hw_ready =3D 0; > + pipe->rec.sw_ready =3D 0; > +} > + > +static int snd_rad1_pcm_ack(struct snd_pcm_substream *substream) > +{ > + struct snd_rad1_pipe *pipe =3D snd_pcm_substream_chip(substream); > + struct snd_pcm_runtime *runtime =3D substream->runtime; > + struct snd_pcm_indirect *rec =3D &pipe->rec; > + snd_pcm_uframes_t appl_ptr =3D runtime->control->appl_ptr; > + snd_pcm_uframes_t frames; > + > + if (substream->stream =3D=3D SNDRV_PCM_STREAM_CAPTURE) > + return 0; > + > + /* a rewind moves appl_ptr back over samples already in the ring */ > + frames =3D appl_ptr - rec->appl_ptr; > + if (appl_ptr < rec->appl_ptr) > + frames +=3D runtime->boundary; > + if (frames > runtime->buffer_size) > + snd_rad1_pcm_resync(pipe, runtime->status->hw_ptr); > + > + return snd_pcm_indirect_playback_transfer(substream, rec,\n> + s= nd_rad1_pcm_copy); > +} [Severity: High] Can snd_rad1_pcm_ack() race with snd_rad1_pcm_hw_free() or run when pipe->rec is not prepared, causing a use-after-free or NULL pointer dereference on pipe->ring.area? snd_pcm_hw_free(), snd_pcm_hw_params() and snd_pcm_prepare() hold runtime->buffer_mutex without acquiring the PCM stream lock, while snd_pcm_sync_ptr() without SNDRV_PCM_SYNC_PTR_HWSYNC acquires only the PCM stream lock before calling snd_rad1_pcm_ack(): CPU0 CPU1 snd_pcm_sync_ptr() snd_pcm_stream_lock_irq() pcm_lib_apply_appl_ptr() snd_rad1_pcm_ack() snd_pcm_indirect_playback_transfer() snd_pcm_hw_free() snd_rad1_pcm_hw_free() memset(&pipe->rec, 0, ...) snd_dma_free_pages(&pipe->ring) pipe->ring.area =3D NULL snd_rad1_pcm_copy() dst[i] =3D ... <-- use-after-free or NULL deref on pipe->ring.ar= ea Even without a concurrent caller, if SNDRV_PCM_IOCTL_SYNC_PTR runs after hw_params or hw_free before prepare (when rec->hw_buffer_size is 0) with frames > runtime->buffer_size, snd_rad1_pcm_ack() calls snd_rad1_pcm_resync(), which passes a NULL pipe->ring.area to memset() after hw_free and sets rec->appl_ptr to a potentially non-zero runtime->status->hw_ptr left over from an earlier run, causing snd_pcm_indirect_playback_transfer() to fail with -EPIPE. Acquiring pcm_stream_lock_irqsave(substream) when resetting pipe->rec in snd_rad1_pcm_hw_free() and snd_rad1_pcm_prepare() (before freeing pipe->ring) and returning 0 from snd_rad1_pcm_ack() when !rec->hw_buffer_size would avoid both issues. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130154427.1760= 4-1-kaloz@kernel.org?part=3D1