lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 8 Sep 2023 09:52:14 -0700
From:   Yosry Ahmed <yosryahmed@...gle.com>
To:     Liu Shixin <liushixin2@...wei.com>
Cc:     Sachin Sant <sachinp@...ux.ibm.com>,
        Michael Ellerman <michaele@....ibm.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Huang Ying <ying.huang@...el.com>,
        Kefeng Wang <wangkefeng.wang@...wei.com>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm: vmscan: fix NULL pointer dereference in can_reclaim_anon_pages

On Fri, Sep 8, 2023 at 1:37 AM Liu Shixin <liushixin2@...wei.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@...ux.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@...wei.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
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ