]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mm/zswap: fix error pointer free in zswap_cpu_comp_prepare()
authorPavel Butsykin <pbutsykin@cloudlinux.com>
Wed, 31 Dec 2025 07:46:38 +0000 (11:46 +0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 Jan 2026 10:21:29 +0000 (11:21 +0100)
commit 590b13669b813d55844fecd9142c56abd567914d upstream.

crypto_alloc_acomp_node() may return ERR_PTR(), but the fail path checks
only for NULL and can pass an error pointer to crypto_free_acomp().  Use
IS_ERR_OR_NULL() to only free valid acomp instances.

Link: https://lkml.kernel.org/r/20251231074638.2564302-1-pbutsykin@cloudlinux.com
Fixes: 779b9955f643 ("mm: zswap: move allocations during CPU init outside the lock")
Signed-off-by: Pavel Butsykin <pbutsykin@cloudlinux.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Acked-by: Yosry Ahmed <yosry.ahmed@linux.dev>
Acked-by: Nhat Pham <nphamcs@gmail.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/zswap.c

index c1af782e54ec60a2296e2f3dccd19fdca8a21cda..12fb0e3954129c7e38b8623fc8ef8175e6855047 100644 (file)
@@ -787,7 +787,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node)
        return 0;
 
 fail:
-       if (acomp)
+       if (!IS_ERR_OR_NULL(acomp))
                crypto_free_acomp(acomp);
        kfree(buffer);
        return ret;