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] [day] [month] [year] [list]
Date:   Tue, 4 Jan 2022 10:19:25 -0800
From:   Alexei Starovoitov <alexei.starovoitov@...il.com>
To:     Kris Van Hees <kris.van.hees@...cle.com>
Cc:     "David S. Miller" <davem@...emloft.net>,
        Daniel Borkmann <daniel@...earbox.net>,
        Andrii Nakryiko <andrii@...nel.org>,
        Network Development <netdev@...r.kernel.org>,
        bpf <bpf@...r.kernel.org>, Kernel Team <kernel-team@...com>
Subject: Re: [PATCH v7 bpf-next 08/11] bpf: Implement verifier support for
 validation of async callbacks.

On Tue, Jan 4, 2022 at 9:16 AM Kris Van Hees <kris.van.hees@...cle.com> wrote:
>
> I ran into a problem due to this patch.  Specifically, the test in the
> __check_func_call() function is flaweed because it can actually mis-interpret
> a regular BPF-to-BPF pseudo-call as a callback call.
>
> Consider the conditional in the code:
>
>         if (insn->code == (BPF_JMP | BPF_CALL) &&
>             insn->imm == BPF_FUNC_timer_set_callback) {
>
> The BPF_FUNC_timer_set_callback has value 170.  This means that if you have
> a BPF program that contains a pseudo-call with an instruction delta of 170,
> this conditional will be found to be true by the verifier, and it will
> interpret the pseudo-call as a callback.  This leads to a mess with the
> verification of the program because it makes the wrong assumptions about the
> nature of this call.
>
> As far as I can see, the solution is simple.  Include an explicit check to
> ensure that src_reg is not a pseudo-call.  I.e. make the conditional:
>
>         if (insn->code == (BPF_JMP | BPF_CALL) &&
>             insn->src_reg != BPF_PSEUDO_CALL &&
>             insn->imm == BPF_FUNC_timer_set_callback) {
>
> It is of course a pretty rare case that this would go wrong, but since my
> code makes extensive use of BPF-to-BPF pseudo-calls, it was only a matter of
> time before I would run into a call with instruction delta 170.

Great catch. All makes sense.
Could you please submit an official patch ?
Checking for insn->src_reg == 0 is probably better,
since src_reg can be BPF_PSEUDO_KFUNC_CALL as well
though __check_func_call is not called for it.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ