]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: btf: Fix a missing check bug
authorWenwen Wang <wang6495@umn.edu>
Sun, 7 Oct 2018 20:23:15 +0000 (15:23 -0500)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 10 Oct 2018 04:42:51 +0000 (21:42 -0700)
commitd6b3100575318de0847a6a674e1081cceb11b0ef
tree3b709f98cf912d49850b1f45f05f3b4da910c524
parentb93d747ac1791570288423efe7ed9c8f551a6abf
bpf: btf: Fix a missing check bug

In btf_parse_hdr(), the length of the btf data header is firstly copied
from the user space to 'hdr_len' and checked to see whether it is larger
than 'btf_data_size'. If yes, an error code EINVAL is returned. Otherwise,
the whole header is copied again from the user space to 'btf->hdr'.
However, after the second copy, there is no check between
'btf->hdr->hdr_len' and 'hdr_len' to confirm that the two copies get the
same value. Given that the btf data is in the user space, a malicious user
can race to change the data between the two copies. By doing so, the user
can provide malicious data to the kernel and cause undefined behavior.

This patch adds a necessary check after the second copy, to make sure
'btf->hdr->hdr_len' has the same value as 'hdr_len'. Otherwise, an error
code EINVAL will be returned.

Signed-off-by: Wenwen Wang <wang6495@umn.edu>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/btf.c