Commit 16cebfda authored by Khalid Masum's avatar Khalid Masum Committed by Yongqiang Liu
Browse files

xfrm: Update ipcomp_scratches with NULL when freed

stable inclusion
from stable-v4.19.262
commit 1e8abde895b3ac6a368cbdb372e8800c49e73a28
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5ZXGL


CVE: NA

--------------------------------

[ Upstream commit 8a04d2fc ]

Currently if ipcomp_alloc_scratches() fails to allocate memory
ipcomp_scratches holds obsolete address. So when we try to free the
percpu scratches using ipcomp_free_scratches() it tries to vfree non
existent vm area. Described below:

static void * __percpu *ipcomp_alloc_scratches(void)
{
        ...
        scratches = alloc_percpu(void *);
        if (!scratches)
                return NULL;
ipcomp_scratches does not know about this allocation failure.
Therefore holding the old obsolete address.
        ...
}

So when we free,

static void ipcomp_free_scratches(void)
{
        ...
        scratches = ipcomp_scratches;
Assigning obsolete address from ipcomp_scratches

        if (!scratches)
                return;

        for_each_possible_cpu(i)
               vfree(*per_cpu_ptr(scratches, i));
Trying to free non existent page, causing warning: trying to vfree
existent vm area.
        ...
}

Fix this breakage by updating ipcomp_scrtches with NULL when scratches
is freed

Suggested-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Reported-by: default avatar <syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com>
Tested-by: default avatar <syzbot+5ec9bb042ddfe9644773@syzkaller.appspotmail.com>
Signed-off-by: default avatarKhalid Masum <khalid.masum.92@gmail.com>
Acked-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarYongqiang Liu <liuyongqiang13@huawei.com>
parent e68b9f9b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment