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]
Message-ID: <bc75c9c5-7479-5021-58ea-ed8cf53fb331@huawei.com>
Date:   Fri, 9 Jul 2021 19:11:25 +0800
From:   He Fengqing <hefengqing@...wei.com>
To:     Alexei Starovoitov <alexei.starovoitov@...il.com>
CC:     Song Liu <song@...nel.org>, Alexei Starovoitov <ast@...nel.org>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Martin KaFai Lau <kafai@...com>,
        Song Liu <songliubraving@...com>, Yonghong Song <yhs@...com>,
        John Fastabend <john.fastabend@...il.com>,
        KP Singh <kpsingh@...nel.org>,
        "David S . Miller" <davem@...emloft.net>,
        Jakub Kicinski <kuba@...nel.org>,
        Networking <netdev@...r.kernel.org>, bpf <bpf@...r.kernel.org>,
        open list <linux-kernel@...r.kernel.org>
Subject: Re: [bpf-next 3/3] bpf: Fix a use after free in bpf_check()



在 2021/7/8 11:09, Alexei Starovoitov 写道:
> On Wed, Jul 7, 2021 at 8:00 PM He Fengqing <hefengqing@...wei.com> wrote:
>>
>> Ok, I will change this in next version.
> 
> before you spam the list with the next version
> please explain why any of these changes are needed?
> I don't see an explanation in the patches and I don't see a bug in the code.
> Did you check what is the prog clone ?
> When is it constructed? Why verifier has anything to do with it?
> .
> 


I'm sorry, I didn't describe these errors clearly.

bpf_check(bpf_verifier_env)
     |
     |->do_misc_fixups(env)
     |    |
     |    |->bpf_patch_insn_data(env)
     |    |    |
     |    |    |->bpf_patch_insn_single(env->prog)
     |    |    |    |
     |    |    |    |->bpf_prog_realloc(env->prog)
     |    |    |    |    |
     |    |    |    |    |->construct new_prog
     |    |    |    |    |    free old_prog(env->prog)
     |    |    |    |    |
     |    |    |    |    |->return new_prog;
     |    |    |    |
     |    |    |    |->return new_prog;
     |    |    |
     |    |    |->adjust_insn_aux_data
     |    |    |    |
     |    |    |    |->return ENOMEM;
     |    |    |
     |    |    |->return NULL;
     |    |
     |    |->return ENOMEM;

bpf_verifier_env->prog had been freed in bpf_prog_realloc function.


There are two errors here, the first is memleak in the 
bpf_patch_insn_data function, and the second is use after free in the 
bpf_check function.

memleak in bpf_patch_insn_data:

Look at the call chain above, if adjust_insn_aux_data function return 
ENOMEM, bpf_patch_insn_data will return NULL, but we do not free the 
new_prog.

So in the patch 2, before bpf_patch_insn_data return NULL, we free the 
new_prog.

use after free in bpf_check:

If bpf_patch_insn_data function return NULL, we will not assign new_prog 
to the bpf_verifier_env->prog, but bpf_verifier_env->prog has been freed 
in the bpf_prog_realloc function. Then in bpf_check function, we will 
use bpf_verifier_env->prog after do_misc_fixups function.

In the patch 3, I added a free_old parameter to bpf_prog_realloc, in 
this scenario we don't free old_prog. Instead, we free it in the 
do_misc_fixups function when bpf_patch_insn_data return a valid new_prog.

Thanks for your reviews.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ