Skip to content

Commit

Permalink
bpf, sockmap: Fix bug that strp_done cannot be called
Browse files Browse the repository at this point in the history
strp_done is only called when psock->progs.stream_parser is not NULL,
but stream_parser was set to NULL by sk_psock_stop_strp(), called
by sk_psock_drop() earlier. So, strp_done can never be called.

Introduce SK_PSOCK_RX_ENABLED to mark whether there is strp on psock.
Change the condition for calling strp_done from judging whether
stream_parser is set to judging whether this flag is set. This flag is
only set once when strp_init() succeeds, and will never be cleared later.

Fixes: c0d95d3 ("bpf, sockmap: Re-evaluate proto ops when psock is removed from sockmap")
Signed-off-by: Xu Kuohai <[email protected]>
Reviewed-by: John Fastabend <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Martin KaFai Lau <[email protected]>
  • Loading branch information
Xu Kuohai authored and Martin KaFai Lau committed Aug 10, 2023
1 parent 7e96ec0 commit 809e4dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/linux/skmsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct sk_psock_progs {

enum sk_psock_state_bits {
SK_PSOCK_TX_ENABLED,
SK_PSOCK_RX_STRP_ENABLED,
};

struct sk_psock_link {
Expand Down
10 changes: 8 additions & 2 deletions net/core/skmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,13 +1120,19 @@ static void sk_psock_strp_data_ready(struct sock *sk)

int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock)
{
int ret;

static const struct strp_callbacks cb = {
.rcv_msg = sk_psock_strp_read,
.read_sock_done = sk_psock_strp_read_done,
.parse_msg = sk_psock_strp_parse,
};

return strp_init(&psock->strp, sk, &cb);
ret = strp_init(&psock->strp, sk, &cb);
if (!ret)
sk_psock_set_state(psock, SK_PSOCK_RX_STRP_ENABLED);

return ret;
}

void sk_psock_start_strp(struct sock *sk, struct sk_psock *psock)
Expand Down Expand Up @@ -1154,7 +1160,7 @@ void sk_psock_stop_strp(struct sock *sk, struct sk_psock *psock)
static void sk_psock_done_strp(struct sk_psock *psock)
{
/* Parser has been stopped */
if (psock->progs.stream_parser)
if (sk_psock_test_state(psock, SK_PSOCK_RX_STRP_ENABLED))
strp_done(&psock->strp);
}
#else
Expand Down

0 comments on commit 809e4dc

Please sign in to comment.