Re: [PATCH] mm: swap_cgroup: fix NULL deref in lookup_swap_cgroup_id on swapless host

From: mambaxin

Date: Sun Aug 16 2026 - 23:28:03 EST


> On Fri, Aug 14, 2026 at 07:23:41PM +0800, Barry Song wrote:
> > On Fri, Aug 14, 2026 at 3:48â?¯PM <mambaxin@xxxxxxx> wrote:
> > >
> > > From: "Jose Fernandez (Anthropic)" <jose.fernandez@xxxxxxxxx>
> > >
> > > [ Upstream commit 63b02a9409cb5180398491b093e48bcb5315f5fb ]
> > >
> > > lookup_swap_cgroup_id() passes swap_cgroup_ctrl[type].map to
> > > __swap_cgroup_id_lookup() without checking that the type was ever
> > > registered via swap_cgroup_swapon(). On a swapless host every ctrl->map
> > > is NULL, so __swap_cgroup_id_lookup() dereferences NULL + a scaled
> > > swp_offset().
> > >
> > > Since commit bea67dcc5eea ("mm: attempt to batch free swap entries for
> > > zap_pte_range()"), zap_pte_range() -> swap_pte_batch() calls
> > > lookup_swap_cgroup_id() on any non-present, non-none PTE that decodes as a
> > > real swap entry, without first validating it against swap_info[]. A
> > > single PTE corrupted into a type-0 swap entry takes the host down at
> > > process exit.
> >
> > Thanks for the patch. However, we have a strict check to ensure that
> > this is only done for valid swap entries:
>
> This patch is already in the upstream linus tree.
>
> Mambaxin, what do you want to do with this patch? Are you requesting to backport
> this to stable tree? Which one? It already had stable CCed, so I would expect
> the stable tree maintainers would pick this up automatically.

Hi Shakeel,Yes, we would like to backport this patch to the 6.6.y stable tree.
We have encountered the same issue on a product running the Android GKI 6.6 kernel.
We are still investigating the underlying PTE corruption using various debugging approaches,
but the reproduction rate is low. Given the constraints of our product release schedule,
we would like to first bring in this fix from upstream so that we can subsequently pull it into the Android GKI kernel.