From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5408451D523; Wed, 30 Sep 2026 17:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790788386; cv=none; b=km+72/E0jpvAiFSf8NBItD8vBjuR3VUGD8kLs2NTxG4FCcMPz7ABxj5Em7LNoUIOo7r1RlBahAABlSHadcxKT4M+2rPF5YOSpxOoTFOwvUi5VQ/dQ1bMDsmyXVPjlTCWUgLvMVGlLuVbccNrxriBxrlIyi86JpdoKJ+VGYs2380= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790788386; c=relaxed/simple; bh=N7E4Yd6Bl+bAuSSk4Er6eeKvagoVLkc3ZafFAZI1sBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jPBGW20zhlr4pindEEfG0akOezWzvmizXL+6+1ArjDZe7R4daFjMYLcU9StWU5yr9x3W2fmR7DiaUrOgO/mjIJe69GuP8xWeTjYREjeQ6ptGpldh+JxAdIGDafXcnQUq60XUXJdMety+GB362E5+aUnCHFSHF1UyoeW2UUx6q74= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OPeSTzXI; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="OPeSTzXI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A62F01F000FF; Wed, 30 Sep 2026 17:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790788385; bh=og91m+g5PZIdcaE0JAS1dDHY75d07TMc8mdX9exZXUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OPeSTzXIjMgglciuE5+414zurLOBiW/8qtNah5FuKaS18RvkSAxl5tybhPyysjBQa RbXjcyae5yaC62UbgfX0vfcZuCO9a9yylpwrT7rMpE2m69IjVh+ZcVsit6wWkTW1PC d6/KESan2hKa26wbJwKVGY309JRcnLHZkHuxNCUc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+19da64013c46df87f971@syzkaller.appspotmail.com, Nguyen Ngoc Thang , Takashi Iwai , Sasha Levin Subject: [PATCH 6.12 104/877] ALSA: pcm: set timer->private_data before registering the PCM timer Date: Wed, 30 Sep 2026 17:16:55 +0200 Message-ID: <20260930152416.984335809@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152414.738996857@linuxfoundation.org> References: <20260930152414.738996857@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nguyen Ngoc Thang [ Upstream commit 1e713f9bb2ac583521f06b0eb4e22440b1e3d078 ] snd_pcm_timer_init() calls snd_device_register() to link the new struct snd_timer into the global timer list while it still carries hw.c_resolution = snd_pcm_timer_resolution (and hw.start/hw.stop), and only afterwards sets timer->private_data = substream. Once the timer is on the list under register_mutex, a concurrent reader can already reach it through the same mutex and invoke these callbacks. /proc/asound/timers does this via c_resolution(), and snd_timer_open()+snd_timer_start() reach start()/stop() the same way. All three dereference timer->private_data, which for this brief window is NULL, giving a NULL-pointer dereference: substream = timer->private_data; return substream->runtime ? ... // substream is NULL Move the private_data/private_free assignment before snd_device_register() so the timer is never visible on the list without its private_data set. On the snd_device_register() failure path, private_free() (snd_pcm_timer_free()) can now run, but it only does substream->timer = NULL, which is already NULL at that point since substream->timer is set to the new timer just once, after a successful registration -- so the failure path stays safe. Reported-by: syzbot+19da64013c46df87f971@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=19da64013c46df87f971 Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Nguyen Ngoc Thang Link: https://patch.msgid.link/20260913134446.114724-1-ngocthang2710.1999@gmail.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/core/pcm_timer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sound/core/pcm_timer.c b/sound/core/pcm_timer.c index ab0e5bd70f8fa..18bedd66435dc 100644 --- a/sound/core/pcm_timer.c +++ b/sound/core/pcm_timer.c @@ -111,12 +111,15 @@ void snd_pcm_timer_init(struct snd_pcm_substream *substream) snd_pcm_direction_name(substream->stream), tid.card, tid.device, tid.subdevice); timer->hw = snd_pcm_timer; + /* Set before registering: a concurrent reader can invoke our hw + * callbacks as soon as the timer is on the global list. + */ + timer->private_data = substream; + timer->private_free = snd_pcm_timer_free; if (snd_device_register(timer->card, timer) < 0) { snd_device_free(timer->card, timer); return; } - timer->private_data = substream; - timer->private_free = snd_pcm_timer_free; substream->timer = timer; } -- 2.53.0