From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (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 C9BF429ACDD for ; Wed, 24 Jun 2026 10:50:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782298205; cv=none; b=YoTGy+R3j1BN+wSCpqM5idTpgBojH9/gOkRLCXFQbHDyj6Cyb2bvwqcpMICY4ifDpDRlexlS2UCBp5OLA/4U4S4IH8Z+NEzXQW0hcLCDSzWVU0ukva38ZgSOVLZ9DD7hKdKy8rNwuXDwBzPC5lEUUrcFcLDPG6p10irBAINCePU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782298205; c=relaxed/simple; bh=nZKmAo7RG6UnefBPYADJoiStxXY34F2F2v94t6VALSU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gRKtsgTTuVdUwMguPONAlf0scws/lcYd5kfJRXpawtV8bYQMkWS+DSoxj6NL8RP1FnzIFmjuBhDSI4PO/MNPa1+PJVuYOWSpoDEi64TooV3RU9ad2tm05zGS7IIs6rpuAcZbTmqkZq+gKRRoNzWB2CCqU3//y5Iz6INkJBV8ooM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dodVbHfz; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dodVbHfz" Message-ID: <923f391a-d760-4d78-92d4-2e765aa226f3@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782298201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mrZgZAxK/d8Sr7imB6CtH4WhUFTzUDkZdoGNYzzUyeY=; b=dodVbHfzsffqK+xwGay6rvpUQ3RM3hjjHpwBjl0gzpexVQVl7fz+nhe7gKMCPR12z+XqsY 3LcbU2ZuvnzGOEYepJhj1hTnJwufgOrwpCDeozFjkRStF5eoGRQunfWMM9CRbUzxFR5ijn zosh6UlIA51uG5ZxAvPFX59g+Js+aIY= Date: Wed, 24 Jun 2026 18:49:07 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH 1/1] mm/shrinker: add NULL checks after rcu_dereference() in shrinker bit functions To: fffsqian@163.com, Andrew Morton , Dave Chinner , Roman Gushchin , Muchun Song Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Qingshuang Fu References: <20260624095527.277586-1-fffsqian@163.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <20260624095527.277586-1-fffsqian@163.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Hi Qingshuang, On 6/24/26 5:55 PM, fffsqian@163.com wrote: > From: Qingshuang Fu > > The functions set_shrinker_bit(), xchg_nr_deferred_memcg(), and > add_nr_deferred_memcg() access shrinker_info fields immediately > after rcu_dereference() without checking for NULL. > > This is inconsistent with shrink_slab_memcg() which properly checks > "if (unlikely(!info)) goto unlock;" before accessing info fields. > > The shrinker_info can be NULL during memcg initialization or after > shrinker_info expansion failure. Directly accessing info->map_nr_max > or info->unit[] without NULL validation could cause kernel NULL > pointer dereference and panic. Really? Did you actually hit this issue, or are you able to reproduce it? Or is it just spotted via code inspection? The callers in all three of these places should guarantee that `info` can not possibly be NULL. :( Thanks, Qi > > Fix this by adding proper NULL checks in all three functions to > ensure consistent RCU protection and prevent potential crashes in > the shrinker subsystem. > > Fixes: 307bececcd1205bcb ("mm: shrinker: add a secondary array for shrinker_info::{map, nr_deferred}") > Cc: Andrew Morton > Cc: Dave Chinner > Cc: Qi Zheng > Cc: Roman Gushchin > Cc: Muchun Song > Cc: linux-mm@kvack.org > Signed-off-by: Qingshuang Fu > --- > mm/shrinker.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/mm/shrinker.c b/mm/shrinker.c > index 7082d01c8c9d..ecde3cc44459 100644 > --- a/mm/shrinker.c > +++ b/mm/shrinker.c > @@ -200,6 +200,8 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) > > rcu_read_lock(); > info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); > + if (unlikely(!info)) > + goto unlock; > if (!WARN_ON_ONCE(shrinker_id >= info->map_nr_max)) { > struct shrinker_info_unit *unit; > > @@ -208,6 +210,7 @@ void set_shrinker_bit(struct mem_cgroup *memcg, int nid, int shrinker_id) > smp_mb__before_atomic(); > set_bit(shrinker_id_to_offset(shrinker_id), unit->map); > } > +unlock: > rcu_read_unlock(); > } > } > @@ -258,6 +261,10 @@ static long xchg_nr_deferred_memcg(int nid, struct shrinker *shrinker, > > rcu_read_lock(); > info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); > + if (unlikely(!info)) { > + rcu_read_unlock(); > + return 0; > + } > unit = info->unit[shrinker_id_to_index(shrinker->id)]; > nr_deferred = atomic_long_xchg(&unit->nr_deferred[shrinker_id_to_offset(shrinker->id)], 0); > rcu_read_unlock(); > @@ -274,6 +281,10 @@ static long add_nr_deferred_memcg(long nr, int nid, struct shrinker *shrinker, > > rcu_read_lock(); > info = rcu_dereference(memcg->nodeinfo[nid]->shrinker_info); > + if (unlikely(!info)) { > + rcu_read_unlock(); > + return 0; > + } > unit = info->unit[shrinker_id_to_index(shrinker->id)]; > nr_deferred = > atomic_long_add_return(nr, &unit->nr_deferred[shrinker_id_to_offset(shrinker->id)]); > > base-commit: 840ef6c78e6a2f694b578ecb9063241c992aaa9e