Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Qi Zheng <qi.zheng@linux.dev>
To: David Carlier <devnexen@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Dave Chinner <david@fromorbit.com>,
	Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/shrinker: avoid out-of-bounds read in set_shrinker_bit()
Date: Mon, 11 May 2026 10:45:12 +0800	[thread overview]
Message-ID: <874e88a3-414c-4e9f-8bbb-5184fb8516e8@linux.dev> (raw)
In-Reply-To: <20260510183700.102475-1-devnexen@gmail.com>

Hi David,

On 5/11/26 2:37 AM, David Carlier wrote:
> set_shrinker_bit() reads info->unit[shrinker_id_to_index(shrinker_id)]
> before checking shrinker_id against info->map_nr_max, so an id past the
> currently visible map_nr_max reads past the unit[] array before the
> WARN_ON_ONCE() catches it.

Did you run into this problem in practice, of just find it via code
inspection? It's virtually impossible to happened, which is why
WARN_ON_ONCE() was added to catch it.

> 
> Move the load into the bounded branch.
> 
> Fixes: 307bececcd12 ("mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred}")
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---
>   mm/shrinker.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)

Anyway, It LGTM, so:

Reviewed-by: Qi Zheng <qi.zheng@linux.dev>

Thanks,
Qi

> 
> diff --git a/mm/shrinker.c b/mm/shrinker.c
> index 76b3f750cf65..49256f81199f 100644
> --- a/mm/shrinker.c
> +++ b/mm/shrinker.c
> @@ -197,12 +197,13 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id)
>   {
>   	if (shrinker_id >= 0 && memcg && !mem_cgroup_is_root(memcg)) {
>   		struct shrinker_info *info;
> -		struct shrinker_info_unit *unit;
>   
>   		rcu_read_lock();
>   		info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info);
> -		unit = info->unit[shrinker_id_to_index(shrinker_id)];
>   		if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) {
> +			struct shrinker_info_unit *unit;
> +
> +			unit = info->unit[shrinker_id_to_index(shrinker_id)];
>   			/* Pairs with smp mb in shrink_slab() */
>   			smp_mb__before_atomic();
>   			set_bit(shrinker_id_to_offset(shrinker_id), unit->map);



  reply	other threads:[~2026-05-11  2:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-10 18:37 [PATCH] mm/shrinker: avoid out-of-bounds read in set_shrinker_bit() David Carlier
2026-05-11  2:45 ` Qi Zheng [this message]
2026-05-11  2:46   ` David CARLIER
2026-05-11  2:48 ` Muchun Song

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=874e88a3-414c-4e9f-8bbb-5184fb8516e8@linux.dev \
    --to=qi.zheng@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=david@fromorbit.com \
    --cc=devnexen@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    /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