linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosryahmed@google.com>
To: Liu Shixin <liushixin2@huawei.com>
Cc: Sachin Sant <sachinp@linux.ibm.com>,
	Michael Ellerman <michaele@au1.ibm.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Huang Ying <ying.huang@intel.com>,
	 Kefeng Wang <wangkefeng.wang@huawei.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: vmscan: fix NULL pointer dereference in can_reclaim_anon_pages
Date: Fri, 8 Sep 2023 09:52:14 -0700	[thread overview]
Message-ID: <CAJD7tkafz_2XAuqE8tGLPEcpLngewhUo=5US14PAtSM9tLBUQg@mail.gmail.com> (raw)
In-Reply-To: <20230908093103.2620512-1-liushixin2@huawei.com>

On Fri, Sep 8, 2023 at 1:37 AM Liu Shixin <liushixin2@huawei.com> wrote:
>
> The variable sc is NULL pointer in can_reclaim_anon_pages() when called
> from zone_reclaimable_pages(). Check it before setting swapcache_only.
>
> Reported-by: Sachin Sant <sachinp@linux.ibm.com>
> Link: https://lore.kernel.org/linux-mm/F00144DE-2A3F-4463-8203-45E0D57E313E@linux.ibm.com/T/
> Fixes: 92039ae85e8d("mm: vmscan: try to reclaim swapcache pages if no swap space")
> Signed-off-by: Liu Shixin <liushixin2@huawei.com>
> ---
>  mm/vmscan.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index f1dc0dbf1cdb..5eb85ddf403f 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -617,7 +617,7 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg,
>                 if (get_nr_swap_pages() > 0)
>                         return true;
>                 /* Is there any swapcache pages to reclaim? */
> -               if (total_swapcache_pages() > 0) {
> +               if (sc && total_swapcache_pages() > 0) {

If sc is NULL, we will not return true even if we have pages in the
swapcache. This will make can_reclaim_anon_pages() return differently
based on whether sc is passed in. Is this the needed behavior?

I thought the sc NULL check should be used only to guard the setting
of sc->swapcache_only, not the return value as well?

>                         sc->swapcache_only = 1;
>                         return true;
>                 }
> @@ -626,7 +626,7 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg,
>                 if (mem_cgroup_get_nr_swap_pages(memcg) > 0)
>                         return true;
>                 /* Is there any swapcache pages in memcg to reclaim? */
> -               if (mem_cgroup_get_nr_swapcache_pages(memcg) > 0) {
> +               if (sc && mem_cgroup_get_nr_swapcache_pages(memcg) > 0) {
>                         sc->swapcache_only = 1;
>                         return true;
>                 }
> --
> 2.25.1
>


      parent reply	other threads:[~2023-09-08 16:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08  9:31 [PATCH] mm: vmscan: fix NULL pointer dereference in can_reclaim_anon_pages Liu Shixin
2023-09-08 12:56 ` Sachin Sant
2023-09-15 10:11   ` Liu Shixin
2023-09-08 16:52 ` Yosry Ahmed [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='CAJD7tkafz_2XAuqE8tGLPEcpLngewhUo=5US14PAtSM9tLBUQg@mail.gmail.com' \
    --to=yosryahmed@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liushixin2@huawei.com \
    --cc=michaele@au1.ibm.com \
    --cc=sachinp@linux.ibm.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=ying.huang@intel.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;
as well as URLs for NNTP newsgroup(s).