The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Emanuele Ghidoli <ghidoliemanuele@gmail.com>
Cc: Takashi Iwai <tiwai@suse.de>, Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Emanuele Ghidoli <emanuele.ghidoli@toradex.com>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-sound@vger.kernel.org, linux-hardening@vger.kernel.org,
	linux-kernel@vger.kernel.org, wenst@chromium.org,
	angelogioacchino.delregno@collabora.com
Subject: Re: [PATCH] ASoC: soc-core: reset rtd->num_components after allocation
Date: Thu, 12 Nov 2026 09:27:06 -0800	[thread overview]
Message-ID: <202611120924.2058DD59@keescook> (raw)
In-Reply-To: <a64e2fa1-6670-4018-80b8-b6856709ad5f@gmail.com>

On Wed, Nov 11, 2026 at 11:28:52AM +0100, Emanuele Ghidoli wrote:
> 
> 
> On 11/11/26 06:59, Kees Cook wrote:
> > 
> > 
> > On November 10, 2026 9:50:08 PM PST, Kees Cook <kees@kernel.org> wrote:
> > 
> > For example, what keeps snd_soc_rtd_add_component() from overflowing
> > that array? If you want to protect the array, add another member,
> > say max_component, and use that for the counter, which gets set at
> > allocation time and protects the array from indexing beyond the actual
> > allocation size.
> 
> Hello Kees,
> 
> Mark has already applied the fix to for-7.4 (d00ba321499c). I agree that
> your proposal is far better, but the applied patch was meant as the
> minimal change to fix the regression.

Yes, totally correct. :) I was just looking at it from a root-cause
perspective. Each time we hit issues with counted_by I try to understand
what the problem was, since the goal is to make it "easy to use". :P

> On your question about what keeps snd_soc_rtd_add_component() from
> overflowing the array: nothing, and it already seems possible today.
> 
> From an LLM-assisted review of the code: the platform loop in
> snd_soc_add_pcm_runtime() adds every component that matches the platform
> dai_link_component, while components[] has one entry per
> platform. On mt8173, for example, the AFE registers three components on the
> same device and the front-end links use it as platform, so four components go
> into three entries. The extra store has gone unnoticed in the slab slack, but
> with max_components as the counter UBSAN_BOUNDS would report it.
> 
> I can't work on a follow-up. If someone picks it up, components[] probably
> needs to be sized by the matching components before the counter is switched to
> max_components.

Yeah, I think we need some better documentation about best practices for
counted_by, as there is clearly 2 very distinct cases it's getting
applied to, and the "usage count" case is the most fragile.

-- 
Kees Cook

  reply	other threads:[~2026-11-12 17:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-09 10:25 [PATCH] ASoC: soc-core: reset rtd->num_components after allocation Emanuele Ghidoli
2026-11-09 11:07 ` Takashi Iwai
2026-11-10 11:47   ` Takashi Iwai
2026-11-11  5:50   ` Kees Cook
2026-11-11  5:59     ` Kees Cook
2026-11-11 10:28       ` Emanuele Ghidoli
2026-11-12 17:27         ` Kees Cook [this message]
2026-11-11 13:09       ` Mark Brown
2026-11-12 17:33         ` Kees Cook
2026-11-10  9:57 ` Jan Remes
2026-11-10 17:45 ` Mark Brown
2026-11-11 10:06 ` Alexander Stein
2026-11-11 12:26 ` Cosmin-Gabriel Tanislav
  -- strict thread matches above, loose matches on Subject: below --
2026-11-10 22:01 Rujbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202611120924.2058DD59@keescook \
    --to=kees@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=broonie@kernel.org \
    --cc=emanuele.ghidoli@toradex.com \
    --cc=ghidoliemanuele@gmail.com \
    --cc=gustavoars@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=wenst@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox