Skip to content
Snippets Groups Projects
  1. May 24, 2021
  2. May 22, 2021
  3. May 21, 2021
  4. May 18, 2021
    • Daniel Borkmann's avatar
      bpf: Fix leakage of uninitialized bpf stack under speculation · 1fdb52d9
      Daniel Borkmann authored
      
      mainline inclusion
      from mainline-v5.13-rc1
      commit 801c6058d14a82179a7ee17a4b532cac6fad067f
      category: bugfix
      bugzilla: NA
      CVE: CVE-2021-31829
      
      --------------------------------
      
      The current implemented mechanisms to mitigate data disclosure under
      speculation mainly address stack and map value oob access from the
      speculative domain. However, Piotr discovered that uninitialized BPF
      stack is not protected yet, and thus old data from the kernel stack,
      potentially including addresses of kernel structures, could still be
      extracted from that 512 bytes large window. The BPF stack is special
      compared to map values since it's not zero initialized for every
      program invocation, whereas map values /are/ zero initialized upon
      their initial allocation and thus cannot leak any prior data in either
      domain. In the non-speculative domain, the verifier ensures that every
      stack slot read must have a prior stack slot write by the BPF program
      to avoid such data leaking issue.
      
      However, this is not enough: for example, when the pointer arithmetic
      operation moves the stack pointer from the last valid stack offset to
      the first valid offset, the sanitation logic allows for any intermediate
      offsets during speculative execution, which could then be used to
      extract any restricted stack content via side-channel.
      
      Given for unprivileged stack pointer arithmetic the use of unknown
      but bounded scalars is generally forbidden, we can simply turn the
      register-based arithmetic operation into an immediate-based arithmetic
      operation without the need for masking. This also gives the benefit
      of reducing the needed instructions for the operation. Given after
      the work in 7fedb63a8307 ("bpf: Tighten speculative pointer arithmetic
      mask"), the aux->alu_limit already holds the final immediate value for
      the offset register with the known scalar. Thus, a simple mov of the
      immediate to AX register with using AX as the source for the original
      instruction is sufficient and possible now in this case.
      
      Reported-by: default avatarPiotr Krysiuk <piotras@gmail.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarPiotr Krysiuk <piotras@gmail.com>
      Reviewed-by: default avatarPiotr Krysiuk <piotras@gmail.com>
      Reviewed-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Conflicts:
        kernel/bpf/verifier.c
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
      Reviewed-by: default avatarKuohai Xu <xukuohai@huawei.com>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      1fdb52d9
    • Daniel Borkmann's avatar
      bpf: Fix masking negation logic upon negative dst register · f8eafed4
      Daniel Borkmann authored
      
      stable inclusion
      from linux-4.19.190
      commit 0e2dfdc74a7f4036127356d42ea59388f153f42c
      
      --------------------------------
      
      commit b9b34ddbe2076ade359cd5ce7537d5ed019e9807 upstream.
      
      The negation logic for the case where the off_reg is sitting in the
      dst register is not correct given then we cannot just invert the add
      to a sub or vice versa. As a fix, perform the final bitwise and-op
      unconditionally into AX from the off_reg, then move the pointer from
      the src to dst and finally use AX as the source for the original
      pointer arithmetic operation such that the inversion yields a correct
      result. The single non-AX mov in between is possible given constant
      blinding is retaining it as it's not an immediate based operation.
      
      Fixes: 979d63d5 ("bpf: prevent out of bounds speculation on pointer arithmetic")
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Tested-by: default avatarPiotr Krysiuk <piotras@gmail.com>
      Reviewed-by: default avatarPiotr Krysiuk <piotras@gmail.com>
      Reviewed-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Acked-by: default avatarAlexei Starovoitov <ast@kernel.org>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
      f8eafed4
  5. May 17, 2021
  6. May 14, 2021