Commit 9db39f4d authored by Tushar Dave's avatar Tushar Dave Committed by Daniel Borkmann

bpf: Fix bpf_msg_pull_data()

Helper bpf_msg_pull_data() mistakenly reuses variable 'offset' while
linearizing multiple scatterlist elements. Variable 'offset' is used
to find first starting scatterlist element
    i.e. msg->data = sg_virt(&sg[first_sg]) + start - offset"

Use different variable name while linearizing multiple scatterlist
elements so that value contained in variable 'offset' won't get
overwritten.

Fixes: 015632bb ("bpf: sk_msg program helper bpf_sk_msg_pull_data")
Signed-off-by: default avatarTushar Dave <tushar.n.dave@oracle.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent 93bbadd6
...@@ -2292,7 +2292,7 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = { ...@@ -2292,7 +2292,7 @@ static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
BPF_CALL_4(bpf_msg_pull_data, BPF_CALL_4(bpf_msg_pull_data,
struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags) struct sk_msg_buff *, msg, u32, start, u32, end, u64, flags)
{ {
unsigned int len = 0, offset = 0, copy = 0; unsigned int len = 0, offset = 0, copy = 0, poffset = 0;
int bytes = end - start, bytes_sg_total; int bytes = end - start, bytes_sg_total;
struct scatterlist *sg = msg->sg_data; struct scatterlist *sg = msg->sg_data;
int first_sg, last_sg, i, shift; int first_sg, last_sg, i, shift;
...@@ -2348,16 +2348,15 @@ BPF_CALL_4(bpf_msg_pull_data, ...@@ -2348,16 +2348,15 @@ BPF_CALL_4(bpf_msg_pull_data,
if (unlikely(!page)) if (unlikely(!page))
return -ENOMEM; return -ENOMEM;
p = page_address(page); p = page_address(page);
offset = 0;
i = first_sg; i = first_sg;
do { do {
from = sg_virt(&sg[i]); from = sg_virt(&sg[i]);
len = sg[i].length; len = sg[i].length;
to = p + offset; to = p + poffset;
memcpy(to, from, len); memcpy(to, from, len);
offset += len; poffset += len;
sg[i].length = 0; sg[i].length = 0;
put_page(sg_page(&sg[i])); put_page(sg_page(&sg[i]));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment