In test_per_memcg_writeback(), zw_allocation is allocated via
malloc() but its return value is not checked before being used in
the subsequent memset() loop. If malloc() fails, this leads to a
NULL pointer dereference.

Add the missing NULL check and jump to the existing error cleanup
path. This is consistent with the wb_allocation check two lines
below.

Fixes: a19b47492751 ("selftest/cgroup: fix zswap test_no_invasive_cgroup_shrink 
on large pagesize system")
Signed-off-by: longlong yan <[email protected]>
---
 tools/testing/selftests/cgroup/test_zswap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/testing/selftests/cgroup/test_zswap.c 
b/tools/testing/selftests/cgroup/test_zswap.c
index 49b36ee79160..9c2ff1b3c320 100644
--- a/tools/testing/selftests/cgroup/test_zswap.c
+++ b/tools/testing/selftests/cgroup/test_zswap.c
@@ -479,6 +479,8 @@ static int test_no_invasive_cgroup_shrink(const char *root)
        if (cg_enter_current(zw_group))
                goto out;
        zw_allocation = malloc(allocation_size);
+       if (!zw_allocation)
+               goto out;
        for (int i = 0; i < nr_pages; i++) {
                off = (unsigned long)i * page_size;
                memset(&zw_allocation[off], 0, page_size);
-- 
2.43.0


Reply via email to