]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: Sockmap, skmsg helper overestimates push, pull, and pop bounds
authorJohn Fastabend <john.fastabend@gmail.com>
Sat, 11 Jan 2020 06:12:02 +0000 (06:12 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 15 Jan 2020 22:26:13 +0000 (23:26 +0100)
commit774eb6a92b50a72b4af1cd2089f54d4e7dd6d8e8
tree0e79287aa56874db12b7a7dff266d0cab47c067f
parentee05b1acf8a60807fae3dcd6d0e9c41107a5ca1d
bpf: Sockmap, skmsg helper overestimates push, pull, and pop bounds

In the push, pull, and pop helpers operating on skmsg objects to make
data writable or insert/remove data we use this bounds check to ensure
specified data is valid,

 /* Bounds checks: start and pop must be inside message */
 if (start >= offset + l || last >= msg->sg.size)
     return -EINVAL;

The problem here is offset has already included the length of the
current element the 'l' above. So start could be past the end of
the scatterlist element in the case where start also points into an
offset on the last skmsg element.

To fix do the accounting slightly different by adding the length of
the previous entry to offset at the start of the iteration. And
ensure its initialized to zero so that the first iteration does
nothing.

Fixes: eaf66302e4568 ("bpf, sockmap: convert to generic sk_msg interface")
Fixes: bd18eeb1713ef ("bpf: sk_msg program helper bpf_msg_push_data")
Fixes: 490c0a9dc8781 ("bpf: helper to pop data from messages")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/bpf/20200111061206.8028-5-john.fastabend@gmail.com
net/core/filter.c