Skip to content

Commit 809e4dc

Browse files
Xu KuohaiMartin KaFai Lau
authored andcommitted
bpf, sockmap: Fix bug that strp_done cannot be called
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]>
1 parent 7e96ec0 commit 809e4dc

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

include/linux/skmsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct sk_psock_progs {
6262

6363
enum sk_psock_state_bits {
6464
SK_PSOCK_TX_ENABLED,
65+
SK_PSOCK_RX_STRP_ENABLED,
6566
};
6667

6768
struct sk_psock_link {

net/core/skmsg.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,19 @@ static void sk_psock_strp_data_ready(struct sock *sk)
11201120

11211121
int sk_psock_init_strp(struct sock *sk, struct sk_psock *psock)
11221122
{
1123+
int ret;
1124+
11231125
static const struct strp_callbacks cb = {
11241126
.rcv_msg = sk_psock_strp_read,
11251127
.read_sock_done = sk_psock_strp_read_done,
11261128
.parse_msg = sk_psock_strp_parse,
11271129
};
11281130

1129-
return strp_init(&psock->strp, sk, &cb);
1131+
ret = strp_init(&psock->strp, sk, &cb);
1132+
if (!ret)
1133+
sk_psock_set_state(psock, SK_PSOCK_RX_STRP_ENABLED);
1134+
1135+
return ret;
11301136
}
11311137

11321138
void sk_psock_start_strp(struct sock *sk, struct sk_psock *psock)
@@ -1154,7 +1160,7 @@ void sk_psock_stop_strp(struct sock *sk, struct sk_psock *psock)
11541160
static void sk_psock_done_strp(struct sk_psock *psock)
11551161
{
11561162
/* Parser has been stopped */
1157-
if (psock->progs.stream_parser)
1163+
if (sk_psock_test_state(psock, SK_PSOCK_RX_STRP_ENABLED))
11581164
strp_done(&psock->strp);
11591165
}
11601166
#else

0 commit comments

Comments
 (0)