Skip to content

Commit 2dc183e

Browse files
Jakub Kicinskigregkh
authored andcommitted
net/tls: take into account that bpf_exec_tx_verdict() may free the record
[ Upstream commit c329ef9 ] bpf_exec_tx_verdict() may free the record if tls_push_record() fails, or if the entire record got consumed by BPF. Re-check ctx->open_rec before touching the data. Fixes: d3b18ad ("tls: add bpf support to sk_msg handling") Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: Simon Horman <simon.horman@netronome.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent cf8d9ad commit 2dc183e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎net/tls/tls_sw.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
979979
num_async++;
980980
else if (ret == -ENOMEM)
981981
goto wait_for_memory;
982-
else if (ret == -ENOSPC)
982+
else if (ctx->open_rec && ret == -ENOSPC)
983983
goto rollback_iter;
984984
else if (ret != -EAGAIN)
985985
goto send_end;
@@ -1048,11 +1048,12 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
10481048
ret = sk_stream_wait_memory(sk, &timeo);
10491049
if (ret) {
10501050
trim_sgl:
1051-
tls_trim_both_msgs(sk, orig_size);
1051+
if (ctx->open_rec)
1052+
tls_trim_both_msgs(sk, orig_size);
10521053
goto send_end;
10531054
}
10541055

1055-
if (msg_en->sg.size < required_size)
1056+
if (ctx->open_rec && msg_en->sg.size < required_size)
10561057
goto alloc_encrypted;
10571058
}
10581059

@@ -1185,11 +1186,13 @@ static int tls_sw_do_sendpage(struct sock *sk, struct page *page,
11851186
wait_for_memory:
11861187
ret = sk_stream_wait_memory(sk, &timeo);
11871188
if (ret) {
1188-
tls_trim_both_msgs(sk, msg_pl->sg.size);
1189+
if (ctx->open_rec)
1190+
tls_trim_both_msgs(sk, msg_pl->sg.size);
11891191
goto sendpage_end;
11901192
}
11911193

1192-
goto alloc_payload;
1194+
if (ctx->open_rec)
1195+
goto alloc_payload;
11931196
}
11941197

11951198
if (num_async) {

0 commit comments

Comments
 (0)