From: Adrian Hunter <adrian.hunter@intel.com>
To: Kees Cook <kees@kernel.org>, Ulf Hansson <ulfh@kernel.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Shawn Lin <shawn.lin@rock-chips.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
<linux-mmc@vger.kernel.org>, <linux-hardening@vger.kernel.org>,
<stable@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] mmc: mmc_test: Set "cnt" to the allocated size explicitly
Date: Sun, 29 Nov 2026 18:17:30 +0200 [thread overview]
Message-ID: <a8b55eef-6ddf-4afd-83ec-b6c5f201dc34@intel.com> (raw)
In-Reply-To: <20261113065859.i.967-kees@kernel.org>
On 13/11/2026 08:59, Kees Cook wrote:
> Since commit c35fac6481a1d ("mmc: mmc_test: Fix __counted_by handling
> after kzalloc_flex() conversion"), mmc_test_alloc_mem() bounds its fill
> loop with mem->cnt, relying on kzalloc_flex() to have set it to
> "max_segs". kzalloc_flex() only sets the __counted_by() counter when the
> compiler supports __builtin_counted_by_ref(). Otherwise mem->cnt is still
> zero after the first segment is stored.
>
> Set mem->cnt after the allocation, as that commit's description intends.
>
> Build tested ARCH=x86_64 defconfig with CONFIG_MMC_TEST=m and W=1, with
> GCC 16.2.0.
>
> Fixes: c35fac6481a1d ("mmc: mmc_test: Fix __counted_by handling after kzalloc_flex() conversion")
> Cc: stable@vger.kernel.org
> Signed-off-by: Kees Cook <kees@kernel.org>
The kzalloc_flex() and mem->cnt usage is confusing, but this fix
works so:
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
> drivers/mmc/core/mmc_test.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mmc/core/mmc_test.c b/drivers/mmc/core/mmc_test.c
> index 4dc16649e61d..aa30df9d33d8 100644
> --- a/drivers/mmc/core/mmc_test.c
> +++ b/drivers/mmc/core/mmc_test.c
> @@ -357,6 +357,7 @@ static struct mmc_test_mem *mmc_test_alloc_mem(unsigned long min_sz,
> mem = kzalloc_flex(*mem, arr, max_segs);
> if (!mem)
> return NULL;
> + mem->cnt = max_segs;
>
> while (max_page_cnt) {
> struct page *page;
prev parent reply other threads:[~2026-11-29 16:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 6:59 Kees Cook
2026-11-29 16:17 ` Adrian Hunter [this message]
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=a8b55eef-6ddf-4afd-83ec-b6c5f201dc34@intel.com \
--to=adrian.hunter@intel.com \
--cc=geert+renesas@glider.be \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=shawn.lin@rock-chips.com \
--cc=stable@vger.kernel.org \
--cc=ulfh@kernel.org \
--cc=wsa+renesas@sang-engineering.com \
/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
all inboxes | Powered by JetHome®