Skip to content

Commit

Permalink
bpf, sockmap: Fix sk_msg_reset_curr
Browse files Browse the repository at this point in the history
Found in the test_txmsg_pull in test_sockmap,
```
txmsg_cork = 512;
opt->iov_length = 3;
opt->iov_count = 1;
opt->rate = 512;
```
The first sendmsg will send an sk_msg with size 3, and bpf_msg_pull_data
will be invoked the first time. sk_msg_reset_curr will reset the copybreak
from 3 to 0, then the second sendmsg will write into copybreak starting at
0 which overwrites the first sendmsg. The same problem happens in push and
pop test. Thus, fix sk_msg_reset_curr to restore the correct copybreak.

Fixes: bb9aefd ("bpf: sockmap, updating the sg structure should also update curr")
Signed-off-by: Zijian Zhang <[email protected]>
  • Loading branch information
Zijian Zhang authored and Kernel Patches Daemon committed Nov 4, 2024
1 parent 215c66f commit bd18abd
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2604,18 +2604,16 @@ BPF_CALL_2(bpf_msg_cork_bytes, struct sk_msg *, msg, u32, bytes)

static void sk_msg_reset_curr(struct sk_msg *msg)
{
u32 i = msg->sg.start;
u32 len = 0;

do {
len += sk_msg_elem(msg, i)->length;
sk_msg_iter_var_next(i);
if (len >= msg->sg.size)
break;
} while (i != msg->sg.end);
if (!msg->sg.size) {
msg->sg.curr = msg->sg.start;
msg->sg.copybreak = 0;
} else {
u32 i = msg->sg.end;

msg->sg.curr = i;
msg->sg.copybreak = 0;
sk_msg_iter_var_prev(i);
msg->sg.curr = i;
msg->sg.copybreak = msg->sg.data[i].length;
}
}

static const struct bpf_func_proto bpf_msg_cork_bytes_proto = {
Expand Down

0 comments on commit bd18abd

Please sign in to comment.